use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.
the class DbEntitySyncAction method syncDbEntity.
protected void syncDbEntity() {
ProjectController mediator = getProjectController();
DbEntity dbEntity = mediator.getCurrentDbEntity();
if (dbEntity != null) {
Collection<ObjEntity> entities = dbEntity.getDataMap().getMappedEntities(dbEntity);
if (entities.isEmpty()) {
return;
}
EntityMergeSupport merger = new EntitySyncController(Application.getInstance().getFrameController(), dbEntity).createMerger();
if (merger == null) {
return;
}
merger.setNameGenerator(new PreserveRelationshipNameGenerator());
DbEntitySyncUndoableEdit undoableEdit = new DbEntitySyncUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap());
// filter out inherited entities, as we need to add attributes only to the roots
filterInheritedEntities(entities);
for (ObjEntity entity : entities) {
DbEntitySyncUndoableEdit.EntitySyncUndoableListener listener = undoableEdit.new EntitySyncUndoableListener(entity);
merger.addEntityMergeListener(listener);
// we should not be trying to introspect the merger
if (merger.isRemovingMeaningfulFKs()) {
undoableEdit.addEdit(undoableEdit.new MeaningfulFKsUndoableEdit(entity, merger.getMeaningfulFKs(entity)));
}
if (merger.synchronizeWithDbEntity(entity)) {
mediator.fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
}
merger.removeEntityMergeListener(listener);
}
application.getUndoManager().addEdit(undoableEdit);
}
}
use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.
the class DbEntityTab method setQualifier.
void setQualifier(String qualifier) {
if (qualifier != null && qualifier.trim().length() == 0) {
qualifier = null;
}
DbEntity ent = mediator.getCurrentDbEntity();
if (ent != null && !Util.nullSafeEquals(ent.getQualifier(), qualifier)) {
ExpressionConvertor convertor = new ExpressionConvertor();
try {
String oldQualifier = convertor.valueAsString(ent.getQualifier());
if (!Util.nullSafeEquals(oldQualifier, qualifier)) {
Expression exp = (Expression) convertor.stringAsValue(qualifier);
ent.setQualifier(exp);
mediator.fireDbEntityEvent(new EntityEvent(this, ent));
}
} catch (IllegalArgumentException ex) {
// unparsable qualifier
throw new ValidationException(ex.getMessage());
}
}
}
use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.
the class DbEntityTab method setCatalog.
void setCatalog(String text) {
if (text != null && text.trim().length() == 0) {
text = null;
}
DbEntity ent = mediator.getCurrentDbEntity();
if (ent != null && !Util.nullSafeEquals(ent.getCatalog(), text)) {
ent.setCatalog(text);
mediator.fireDbEntityEvent(new EntityEvent(this, ent));
}
}
use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.
the class PKDBGeneratorPanel method updateView.
void updateView(final DbEntity entity) {
for (ItemListener listener : attributes.getItemListeners()) {
attributes.removeItemListener(listener);
}
Collection<DbAttribute> pkAttributes = entity.getPrimaryKeys();
if (pkAttributes.isEmpty()) {
attributes.removeAllItems();
attributes.addItem("<Entity has no PK columns>");
attributes.setSelectedIndex(0);
attributes.setEnabled(false);
} else {
attributes.setEnabled(true);
MutableComboBoxModel model = new DefaultComboBoxModel(pkAttributes.toArray());
String noSelection = "<Select Generated Column>";
model.insertElementAt(noSelection, 0);
model.setSelectedItem(noSelection);
attributes.setModel(model);
for (DbAttribute a : pkAttributes) {
if (a.isGenerated()) {
model.setSelectedItem(a);
break;
}
}
// listen for selection changes of the new entity
attributes.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
Object item = e.getItem();
if (item instanceof DbAttribute) {
boolean generated = e.getStateChange() == ItemEvent.SELECTED;
DbAttribute a = (DbAttribute) item;
if (a.isGenerated() != generated) {
a.setGenerated(generated);
mediator.fireDbEntityEvent(new EntityEvent(this, entity));
}
}
}
});
}
// revalidate as children layout has changed...
revalidate();
}
use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.
the class PKDBGeneratorPanel method onInitInternal.
protected void onInitInternal(DbEntity entity) {
resetStrategy(entity, true, false);
Collection pkAttributes = entity.getPrimaryKeys();
// by default check the only numeric PK
if (pkAttributes.size() == 1) {
DbAttribute pk = (DbAttribute) pkAttributes.iterator().next();
if (TypesMapping.isNumeric(pk.getType()) && !pk.isGenerated()) {
pk.setGenerated(true);
mediator.fireDbEntityEvent(new EntityEvent(this, entity));
}
}
updateView(entity);
}
Aggregations