Search in sources :

Example 16 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class ObjEntityAttributePanel method initComboBoxes.

public void initComboBoxes() {
    List<String> embeddableNames = new ArrayList<>();
    List<String> typeNames = new ArrayList<>();
    for (DataMap dataMap : ((DataChannelDescriptor) mediator.getProject().getRootNode()).getDataMaps()) {
        for (Embeddable emb : dataMap.getEmbeddables()) {
            embeddableNames.add(emb.getClassName());
        }
    }
    String[] registeredTypes = ModelerUtil.getRegisteredTypeNames();
    Collections.addAll(typeNames, registeredTypes);
    typeNames.addAll(embeddableNames);
    TableColumn typeColumn = table.getColumnModel().getColumn(ObjAttributeTableModel.OBJ_ATTRIBUTE_TYPE);
    JComboBox javaTypesCombo = Application.getWidgetFactory().createComboBox(typeNames.toArray(), false);
    AutoCompletion.enable(javaTypesCombo, false, true);
    typeColumn.setCellEditor(Application.getWidgetFactory().createCellEditor(javaTypesCombo));
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) JComboBox(javax.swing.JComboBox) ArrayList(java.util.ArrayList) TableColumn(javax.swing.table.TableColumn) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable)

Example 17 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class CodeGeneratorControllerBase method validate.

public void validate(GeneratorController validator) {
    ValidationResult validationBuffer = new ValidationResult();
    if (validator != null) {
        for (Object classObj : classes) {
            if (classObj instanceof ObjEntity) {
                validator.validateEntity(validationBuffer, (ObjEntity) classObj, false);
            } else if (classObj instanceof Embeddable) {
                validator.validateEmbeddable(validationBuffer, (Embeddable) classObj);
            }
        }
    }
    this.validation = validationBuffer;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ValidationResult(org.apache.cayenne.validation.ValidationResult) Embeddable(org.apache.cayenne.map.Embeddable)

Example 18 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class CodeGeneratorControllerBase method getProblem.

/**
 * 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 (validation == null) {
        return null;
    }
    List failures = validation.getFailures(name);
    if (failures.isEmpty()) {
        return null;
    }
    return ((ValidationFailure) failures.get(0)).getDescription();
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ArrayList(java.util.ArrayList) List(java.util.List) Embeddable(org.apache.cayenne.map.Embeddable) ValidationFailure(org.apache.cayenne.validation.ValidationFailure)

Example 19 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class GeneratorController method createGenerator.

/**
 * Creates a class generator for provided selections.
 */
public Collection<ClassGenerationAction> createGenerator() {
    File outputDir = getOutputDir();
    // no destination folder
    if (outputDir == null) {
        JOptionPane.showMessageDialog(this.getView(), "Select directory for source files.");
        return null;
    }
    // no such folder
    if (!outputDir.exists() && !outputDir.mkdirs()) {
        JOptionPane.showMessageDialog(this.getView(), "Can't create directory " + outputDir + ". Select a different one.");
        return null;
    }
    // not a directory
    if (!outputDir.isDirectory()) {
        JOptionPane.showMessageDialog(this.getView(), outputDir + " is not a valid directory.");
        return null;
    }
    // remove generic entities...
    Collection<ObjEntity> selectedEntities = new ArrayList<>(getParentController().getSelectedEntities());
    selectedEntities.removeIf(ObjEntity::isGeneric);
    Collection<ClassGenerationAction> generators = new ArrayList<>();
    Collection<StandardPanelComponent> dataMapLines = ((GeneratorControllerPanel) getView()).getDataMapLines();
    for (DataMap map : getParentController().getDataMaps()) {
        try {
            ClassGenerationAction generator = newGenerator();
            generator.setArtifactsGenerationMode(mode);
            generator.setDataMap(map);
            LinkedList<ObjEntity> objEntities = new LinkedList<>(map.getObjEntities());
            objEntities.retainAll(selectedEntities);
            generator.addEntities(objEntities);
            LinkedList<Embeddable> embeddables = new LinkedList<>(map.getEmbeddables());
            embeddables.retainAll(getParentController().getSelectedEmbeddables());
            generator.addEmbeddables(embeddables);
            generator.addQueries(map.getQueryDescriptors());
            Preferences preferences = application.getPreferencesNode(GeneralPreferences.class, "");
            if (preferences != null) {
                generator.setEncoding(preferences.get(GeneralPreferences.ENCODING_PREFERENCE, null));
            }
            generator.setDestDir(outputDir);
            generator.setMakePairs(true);
            generator.setForce(true);
            for (StandardPanelComponent dataMapLine : dataMapLines) {
                if (dataMapLine.getDataMap() == map && !Util.isEmptyString(dataMapLine.getSuperclassPackage().getText())) {
                    generator.setSuperPkg(dataMapLine.getSuperclassPackage().getText());
                    break;
                }
            }
            generators.add(generator);
        } catch (CayenneRuntimeException exception) {
            JOptionPane.showMessageDialog(this.getView(), exception.getUnlabeledMessage());
            return null;
        }
    }
    return generators;
}
Also used : ArrayList(java.util.ArrayList) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) LinkedList(java.util.LinkedList) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable) ObjEntity(org.apache.cayenne.map.ObjEntity) GeneralPreferences(org.apache.cayenne.modeler.dialog.pref.GeneralPreferences) Preferences(java.util.prefs.Preferences) File(java.io.File) ClassGenerationAction(org.apache.cayenne.gen.ClassGenerationAction)

Example 20 with Embeddable

use of org.apache.cayenne.map.Embeddable in project cayenne by apache.

the class GeneratorController method getDefaultClassFilter.

/**
 * Returns a predicate for default entity selection in a given mode.
 */
public Predicate getDefaultClassFilter() {
    final ObjEntity selectedEntity = Application.getInstance().getFrameController().getProjectController().getCurrentObjEntity();
    final Embeddable selectedEmbeddable = Application.getInstance().getFrameController().getProjectController().getCurrentEmbeddable();
    if (selectedEntity != null) {
        // select a single entity
        final boolean hasProblem = getParentController().getProblem(selectedEntity.getName()) != null;
        return object -> !hasProblem && object == selectedEntity;
    } else if (selectedEmbeddable != null) {
        // select a single embeddable
        final boolean hasProblem = getParentController().getProblem(selectedEmbeddable.getClassName()) != null;
        return object -> !hasProblem && object == selectedEmbeddable;
    } else {
        // select all entities
        return object -> {
            if (object instanceof ObjEntity) {
                return getParentController().getProblem(((ObjEntity) object).getName()) == null;
            }
            if (object instanceof Embeddable) {
                return getParentController().getProblem(((Embeddable) object).getClassName()) == null;
            }
            return false;
        };
    }
}
Also used : SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) ObjEntity(org.apache.cayenne.map.ObjEntity) ValidationResult(org.apache.cayenne.validation.ValidationResult) JTextField(javax.swing.JTextField) CayenneController(org.apache.cayenne.modeler.util.CayenneController) DataMapDefaults(org.apache.cayenne.modeler.pref.DataMapDefaults) ValidationFailure(org.apache.cayenne.validation.ValidationFailure) ArrayList(java.util.ArrayList) ClassGenerationAction(org.apache.cayenne.gen.ClassGenerationAction) FSPath(org.apache.cayenne.modeler.pref.FSPath) Map(java.util.Map) CodeValidationUtil(org.apache.cayenne.modeler.util.CodeValidationUtil) JFileChooser(javax.swing.JFileChooser) LinkedList(java.util.LinkedList) Application(org.apache.cayenne.modeler.Application) Util(org.apache.cayenne.util.Util) JButton(javax.swing.JButton) Iterator(java.util.Iterator) GeneralPreferences(org.apache.cayenne.modeler.dialog.pref.GeneralPreferences) ArtifactsGenerationMode(org.apache.cayenne.gen.ArtifactsGenerationMode) Predicate(java.util.function.Predicate) BindingBuilder(org.apache.cayenne.swing.BindingBuilder) Collection(java.util.Collection) ObjAttribute(org.apache.cayenne.map.ObjAttribute) Set(java.util.Set) JOptionPane(javax.swing.JOptionPane) File(java.io.File) Preferences(java.util.prefs.Preferences) Embeddable(org.apache.cayenne.map.Embeddable) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) EmbeddedAttribute(org.apache.cayenne.map.EmbeddedAttribute) ObjRelationship(org.apache.cayenne.map.ObjRelationship) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) BeanValidationFailure(org.apache.cayenne.validation.BeanValidationFailure) DataMap(org.apache.cayenne.map.DataMap) ObjEntity(org.apache.cayenne.map.ObjEntity) Embeddable(org.apache.cayenne.map.Embeddable)

Aggregations

Embeddable (org.apache.cayenne.map.Embeddable)33 DataMap (org.apache.cayenne.map.DataMap)14 ObjEntity (org.apache.cayenne.map.ObjEntity)14 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)11 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)11 DbEntity (org.apache.cayenne.map.DbEntity)8 ArrayList (java.util.ArrayList)7 ObjAttribute (org.apache.cayenne.map.ObjAttribute)7 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)6 DbAttribute (org.apache.cayenne.map.DbAttribute)5 Procedure (org.apache.cayenne.map.Procedure)5 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 ProjectController (org.apache.cayenne.modeler.ProjectController)4 HashMap (java.util.HashMap)3 DbRelationship (org.apache.cayenne.map.DbRelationship)3 EmbeddableDisplayEvent (org.apache.cayenne.modeler.event.EmbeddableDisplayEvent)3 RemoveAttributeUndoableEdit (org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit)3 File (java.io.File)2 LinkedList (java.util.LinkedList)2