use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class BoxCellRenderer method setUpdatedValueAt.
@Override
public void setUpdatedValueAt(Object value, int row, int col) {
EmbeddableAttribute attribute = getEmbeddableAttribute(row);
if (col == DB_ATTRIBUTE) {
attribute.setDbAttributeName(value != null ? value.toString() : null);
fireTableCellUpdated(row, col);
this.isAttributeOverrideChange = true;
((ObjAttributeInfoDialogView) ((ObjAttributeInfoDialog) eventSource).getView()).getSaveButton().setEnabled(true);
if (value != null) {
DbEntity currentEnt = ((ObjEntity) attr.getEntity()).getDbEntity();
if (currentEnt != null) {
DbAttribute dbAttr = (DbAttribute) currentEnt.getAttribute(value.toString());
if (dbAttr != null) {
fireTableCellUpdated(DB_ATTRIBUTE_TYPE, col);
}
}
}
fireTableRowsUpdated(row, row);
}
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class AttributeErrorMsg method displayField.
public void displayField(ProjectController mediator, JFrame frame) {
AttributeDisplayEvent event = new AttributeDisplayEvent(frame, attribute, entity, map, domain);
// twice
if (entity instanceof ObjEntity) {
mediator.fireObjEntityDisplayEvent(event);
mediator.fireObjAttributeDisplayEvent(event);
} else if (entity instanceof DbEntity) {
mediator.fireDbEntityDisplayEvent(event);
mediator.fireDbAttributeDisplayEvent(event);
}
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class CreateAttributeAction method performAction.
/**
* Creates ObjAttribute, DbAttribute depending on context.
*/
@Override
public void performAction(ActionEvent e) {
ProjectController mediator = getProjectController();
if (getProjectController().getCurrentEmbeddable() != null) {
Embeddable embeddable = mediator.getCurrentEmbeddable();
EmbeddableAttribute attr = new EmbeddableAttribute();
attr.setName(NameBuilder.builder(attr, embeddable).name());
createEmbAttribute(embeddable, attr);
application.getUndoManager().addEdit(new CreateEmbAttributeUndoableEdit(embeddable, new EmbeddableAttribute[] { attr }));
}
if (getProjectController().getCurrentObjEntity() != null) {
ObjEntity objEntity = mediator.getCurrentObjEntity();
ObjAttribute attr = new ObjAttribute();
attr.setName(NameBuilder.builder(attr, objEntity).name());
createObjAttribute(mediator.getCurrentDataMap(), objEntity, attr);
application.getUndoManager().addEdit(new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap(), objEntity, attr));
} else if (getProjectController().getCurrentDbEntity() != null) {
DbEntity dbEntity = getProjectController().getCurrentDbEntity();
DbAttribute attr = new DbAttribute();
attr.setName(NameBuilder.builder(attr, dbEntity).name());
attr.setType(TypesMapping.NOT_DEFINED);
attr.setEntity(dbEntity);
createDbAttribute(mediator.getCurrentDataMap(), dbEntity, attr);
application.getUndoManager().addEdit(new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap(), dbEntity, attr));
}
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class CreateDbEntityAction method performAction.
/**
* Creates new DbEntity, adds it to the current DataMap, fires DbEntityEvent and DbEntityDisplayEvent.
*/
public void performAction(ActionEvent e) {
ProjectController mediator = getProjectController();
DataMap map = mediator.getCurrentDataMap();
DbEntity entity = new DbEntity();
entity.setName(NameBuilder.builder(entity, map).name());
createEntity(map, entity);
application.getUndoManager().addEdit(new CreateDbEntityUndoableEdit(map, entity));
}
use of org.apache.cayenne.map.DbEntity 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);
}
}
Aggregations