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.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.

Author(s):
Andrus Adamchik
 
 public abstract class CodeGeneratorControllerBase extends CayenneController {
 
     public static final String SELECTED_PROPERTY = "selected";
 
     protected DataMap dataMap;
 
     protected ValidationResult validation;
 
     protected List entities;
     protected Set selectedEntities;
 
     protected transient ObjEntity currentEntity;
 
     public CodeGeneratorControllerBase(CayenneController parent, DataMap dataMap) {
         super(parent);
 
         this. = dataMap;
         this. = new ArrayList(dataMap.getObjEntities());
         this. = new HashSet();
     }
 
     public abstract Component getView();
 
     public void validate(GeneratorController validator) {
 
         ValidationResult validationBuffer = new ValidationResult();
 
         if (validator != null) {
             Iterator it = .iterator();
             while (it.hasNext()) {
                 validator.validateEntity(validationBuffer, (ObjEntity) it.next(), false);
             }
         }
 
         this. = validationBuffer;
     }
 
     public boolean updateSelection(Predicate predicate) {
 
         boolean modified = false;
 
         Iterator it = .iterator();
         while (it.hasNext()) {
             ObjEntity entity = (ObjEntity) it.next();
 
             boolean select = predicate.evaluate(entity);
 
             if (select) {
                 if (.add(entity.getName())) {
                     modified = true;
                 }
             }
             else {
                 if (.remove(entity.getName())) {
                     modified = true;
                 }
             }
         }
        if (modified) {
            firePropertyChange(nullnull);
        }
        return modified;
    }
    public List getSelectedEntities() {
        List selected = new ArrayList(.size());
        Iterator it = .iterator();
        while (it.hasNext()) {
            ObjEntity e = (ObjEntity) it.next();
            if (.contains(e.getName())) {
                selected.add(e);
            }
        }
        return selected;
    }
    public int getSelectedEntitiesSize() {
        return .size();
    }
    public List getEntities() {
        return ;
    }

    
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(String entityName) {
        if ( == null) {
            return null;
        }
        List failures = .getFailures(entityName);
        if (failures.isEmpty()) {
            return null;
        }
        return ((ValidationFailure) failures.get(0)).getDescription();
    }
    public boolean isSelected() {
        return  != null
                ? .contains(.getName())
                : false;
    }
    public void setSelected(boolean selectedFlag) {
        if ( == null) {
            return;
        }
        if (selectedFlag) {
            if (.add(.getName())) {
                firePropertyChange(nullnull);
            }
        }
        else {
            if (.remove(.getName())) {
                firePropertyChange(nullnull);
            }
        }
    }
    public ObjEntity getCurrentEntity() {
        return ;
    }
    public void setCurrentEntity(ObjEntity currentEntity) {
        this. = currentEntity;
    }
    public DataMap getDataMap() {
        return ;
    }
New to GrepCode? Check out our FAQ X