Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 package org.apache.cayenne.modeler.dialog.codegen;
 
 import java.util.List;
 import java.util.Set;
 
 
 import  org.apache.cayenne.map.DataMap;
 import  org.apache.cayenne.map.Embeddable;
 import  org.apache.cayenne.map.ObjEntity;
 import  org.apache.cayenne.validation.ValidationFailure;
 import  org.apache.cayenne.validation.ValidationResult;
A base superclass of a top controller for the code generator. Defines all common model parts used in class generation.
 
 public abstract class CodeGeneratorControllerBase extends CayenneController {
 
     public static final String SELECTED_PROPERTY = "selected";
 
     protected DataMap dataMap;
 
     protected ValidationResult validation;
 
     protected List<Objectclasses;
 
     protected Set selectedEntities;
     protected Set selectedEmbeddables;
 
     protected transient Object currentClass;
 
     public CodeGeneratorControllerBase(CayenneController parent, DataMap dataMap) {
         super(parent);
 
         this. = dataMap;
         this. = new ArrayList(dataMap.getObjEntities());
         this..addAll(new ArrayList(dataMap.getEmbeddables()));
         this. = new HashSet();
         this. = new HashSet();
     }
 
     public List<ObjectgetClasses() {
         return ;
     }
 
     public abstract Component getView();
 
     public void validate(GeneratorController validator) {
 
         ValidationResult validationBuffer = new ValidationResult();
 
         if (validator != null) {
             for (Object classObj : ) {
                 if (classObj instanceof ObjEntity) {
                     validator.validateEntity(
                             validationBuffer,
                             (ObjEntity) classObj,
                             false);
                 }
                 else if (classObj instanceof Embeddable) {
                     validator.validateEmbeddable(validationBuffer, (Embeddable) classObj);
                 }
             }
 
         }
 
         this. = validationBuffer;
     }
 
     public boolean updateSelection(Predicate predicate) {
        boolean modified = false;
        for (Object classObj : ) {
            boolean select = predicate.evaluate(classObj);
            if (classObj instanceof ObjEntity) {
                if (select) {
                    if (.add(((ObjEntity) classObj).getName())) {
                        modified = true;
                    }
                }
                else {
                    if (.remove(((ObjEntity) classObj).getName())) {
                        modified = true;
                    }
                }
            }
            else if (classObj instanceof Embeddable) {
                if (select) {
                    if (.add(((Embeddable) classObj).getClassName())) {
                        modified = true;
                    }
                }
                else {
                    if (
                            .remove(((Embeddable) classObj).getClassName())) {
                        modified = true;
                    }
                }
            }
        }
        if (modified) {
            firePropertyChange(nullnull);
        }
        return modified;
    }
    public List<Embeddable> getSelectedEmbeddables() {
        List<Embeddable> selected = new ArrayList<Embeddable>(.size());
        for (Object classObj : ) {
            if (classObj instanceof Embeddable
                    && .contains(((Embeddable) classObj)
                            .getClassName())) {
                selected.add((Embeddable) classObj);
            }
        }
        return selected;
    }
    public List<ObjEntity> getSelectedEntities() {
        List<ObjEntity> selected = new ArrayList<ObjEntity>(.size());
        for (Object classObj : ) {
            if (classObj instanceof ObjEntity
                    && .contains(((ObjEntity) classObj).getName())) {
                selected.add(((ObjEntity) classObj));
            }
        }
        return selected;
    }
    public int getSelectedEntitiesSize() {
        return .size();
    }
    public int getSelectedEmbeddablesSize() {
        return .size();
    }

    
Returns the first encountered validation problem for an antity matching the name or null if the entity is valid or the entity is not present.
    public String getProblem(Object obj) {
        String name = null;
        
        if (obj instanceof ObjEntity) {
            name = ((ObjEntity) obj).getName();
        }
        else if (obj instanceof Embeddable) {
            name = ((Embeddable) obj).getClassName();
        }
        
        if ( == null) {
            return null;
        }
        List failures = .getFailures(name);
        if (failures.isEmpty()) {
            return null;
        }
        return ((ValidationFailure) failures.get(0)).getDescription();
    }
    public boolean isSelected() {
        if ( instanceof ObjEntity) {
            return  != null ? 
                    .contains(((ObjEntity) ).getName()) : false;
        }
        if ( instanceof Embeddable) {
            return  != null ? 
                    .contains(((Embeddable) ).getClassName()) : false;
        }
        return false;
    }
    public void setSelected(boolean selectedFlag) {
        if ( == null) {
            return;
        }
        if ( instanceof ObjEntity) {
            if (selectedFlag) {
                if (.add(((ObjEntity) ).getName())) {
                    firePropertyChange(nullnull);
                }
            }
            else {
                if (.remove(((ObjEntity) ).getName())) {
                    firePropertyChange(nullnull);
                }
            }
        }
        if ( instanceof Embeddable) {
            if (selectedFlag) {
                if (.add(((Embeddable) ).getClassName())) {
                    firePropertyChange(nullnull);
                }
            }
            else {
                if (
                        .remove(((Embeddable) ).getClassName())) {
                    firePropertyChange(nullnull);
                }
            }
        }
    }
    public Object getCurrentClass() {
        return ;
    }
    public void setCurrentClass(Object currentClass) {
        this. = currentClass;
    }
    public DataMap getDataMap() {
        return ;
    }
    public JLabel getItemName(Object obj) {
        String className;
        Icon icon = null;
        if (obj instanceof Embeddable) {
            className = ((Embeddable) obj).getClassName();
            icon = CellRenderers.iconForObject(new Embeddable());
        } else {
            className = ((ObjEntity) obj).getName();
            icon = CellRenderers.iconForObject(new ObjEntity());
        }
        JLabel labelIcon = new JLabel();
        labelIcon.setIcon(icon);
        labelIcon.setVisible(true);
        labelIcon.setText(className);
        return labelIcon;
    }
New to GrepCode? Check out our FAQ X