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));
}
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;
}
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();
}
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;
}
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;
};
}
}
Aggregations