use of org.apache.cayenne.map.EmbeddableAttribute in project cayenne by apache.
the class EmbeddableAttributeTab method processExistingSelection.
public void processExistingSelection(EventObject e) {
if (e instanceof ChangeEvent) {
table.clearSelection();
}
EmbeddableAttribute[] attrs = new EmbeddableAttribute[0];
if (table.getSelectedRow() >= 0) {
EmbeddableAttributeTableModel model = (EmbeddableAttributeTableModel) table.getModel();
int[] sel = table.getSelectedRows();
attrs = new EmbeddableAttribute[sel.length];
for (int i = 0; i < sel.length; i++) {
attrs[i] = model.getEmbeddableAttribute(sel[i]);
}
if (sel.length == 1) {
UIUtil.scrollToSelectedRow(table);
}
}
EmbeddableAttributeDisplayEvent ev = new EmbeddableAttributeDisplayEvent(this, mediator.getCurrentEmbeddable(), attrs, mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode());
mediator.fireEmbeddableAttributeDisplayEvent(ev);
}
use of org.apache.cayenne.map.EmbeddableAttribute in project cayenne by apache.
the class EmbeddableAttributeTableModel method setUpdatedValueAt.
@Override
public void setUpdatedValueAt(Object value, int row, int col) {
EmbeddableAttribute attribute = getEmbeddableAttribute(row);
EmbeddableAttributeEvent event = new EmbeddableAttributeEvent(eventSource, embeddable, attribute);
String path = null;
Collection<String> nameAttr = null;
if (col == OBJ_ATTRIBUTE) {
event.setOldName(attribute.getName());
ProjectUtil.setEmbeddableAttributeName(attribute, value != null ? value.toString().trim() : null);
fireTableCellUpdated(row, col);
} else if (col == OBJ_ATTRIBUTE_TYPE) {
attribute.setType(value != null ? value.toString() : null);
fireTableCellUpdated(row, col);
} else if (col == DB_ATTRIBUTE) {
attribute.setDbAttributeName(value != null ? value.toString() : null);
fireTableCellUpdated(row, col);
}
mediator.fireEmbeddableAttributeEvent(event);
}
use of org.apache.cayenne.map.EmbeddableAttribute in project cayenne by apache.
the class PasteAction method paste.
/**
* Pastes single object
*/
public void paste(Object where, Object content, DataChannelDescriptor dataChannelDescriptor, DataMap map) {
final ProjectController mediator = getProjectController();
/**
* Add a little intelligence - if a tree leaf is selected, we can paste to a
* parent datamap
*/
if (isTreeLeaf(where) && isTreeLeaf(content)) {
where = mediator.getCurrentDataMap();
}
if ((where instanceof DataChannelDescriptor || where instanceof DataNodeDescriptor) && content instanceof DataMap) {
// paste DataMap to DataDomain or DataNode
DataMap dataMap = ((DataMap) content);
dataMap.setName(NameBuilder.builder(dataMap, dataChannelDescriptor).baseName(dataMap.getName()).dupesPattern(COPY_PATTERN).name());
/**
* Update all names in the new DataMap, so that they would not conflict with
* names from other datamaps of this domain
*/
// add some intelligence - if we rename an entity, we should rename all links
// to it as well
Map<String, String> renamedDbEntities = new HashMap<>();
Map<String, String> renamedObjEntities = new HashMap<>();
Map<String, String> renamedEmbeddables = new HashMap<>();
for (DbEntity dbEntity : dataMap.getDbEntities()) {
String oldName = dbEntity.getName();
dbEntity.setName(NameBuilder.builder(dbEntity, dataMap).baseName(dbEntity.getName()).dupesPattern(COPY_PATTERN).name());
if (!oldName.equals(dbEntity.getName())) {
renamedDbEntities.put(oldName, dbEntity.getName());
}
}
for (ObjEntity objEntity : dataMap.getObjEntities()) {
String oldName = objEntity.getName();
objEntity.setName(NameBuilder.builder(objEntity, dataMap).baseName(objEntity.getName()).dupesPattern(COPY_PATTERN).name());
if (!oldName.equals(objEntity.getName())) {
renamedObjEntities.put(oldName, objEntity.getName());
}
}
for (Embeddable embeddable : dataMap.getEmbeddables()) {
String oldName = embeddable.getClassName();
embeddable.setClassName(NameBuilder.builder(embeddable, dataMap).baseName(embeddable.getClassName()).dupesPattern(COPY_PATTERN).name());
if (!oldName.equals(embeddable.getClassName())) {
renamedEmbeddables.put(oldName, embeddable.getClassName());
}
}
for (Procedure procedure : dataMap.getProcedures()) {
procedure.setName(NameBuilder.builder(procedure, dataMap).baseName(procedure.getName()).dupesPattern(COPY_PATTERN).name());
}
for (QueryDescriptor query : dataMap.getQueryDescriptors()) {
query.setName(NameBuilder.builder(query, dataMap).baseName(query.getName()).dupesPattern(COPY_PATTERN).name());
}
// if an entity was renamed, we rename all links to it too
for (DbEntity dbEntity : dataMap.getDbEntities()) {
for (DbRelationship rel : dbEntity.getRelationships()) {
if (renamedDbEntities.containsKey(rel.getTargetEntityName())) {
rel.setTargetEntityName(renamedDbEntities.get(rel.getTargetEntityName()));
}
}
}
for (ObjEntity objEntity : dataMap.getObjEntities()) {
if (renamedDbEntities.containsKey(objEntity.getDbEntityName())) {
objEntity.setDbEntityName(renamedDbEntities.get(objEntity.getDbEntityName()));
}
if (renamedObjEntities.containsKey(objEntity.getSuperEntityName())) {
objEntity.setSuperEntityName(renamedDbEntities.get(objEntity.getSuperEntityName()));
}
for (ObjRelationship rel : objEntity.getRelationships()) {
if (renamedObjEntities.containsKey(rel.getTargetEntityName())) {
rel.setTargetEntityName(renamedObjEntities.get(rel.getTargetEntityName()));
}
}
}
mediator.addDataMap(this, dataMap);
} else if (where instanceof DataMap) {
// paste DbEntity to DataMap
final DataMap dataMap = ((DataMap) where);
// clear data map parent cache
clearDataMapCache(dataMap);
if (content instanceof DbEntity) {
DbEntity dbEntity = (DbEntity) content;
dbEntity.setName(NameBuilder.builder(dbEntity, dataMap).baseName(dbEntity.getName()).dupesPattern(COPY_PATTERN).name());
dataMap.addDbEntity(dbEntity);
CreateDbEntityAction.fireDbEntityEvent(this, mediator, dbEntity);
} else if (content instanceof ObjEntity) {
// paste ObjEntity to DataMap
ObjEntity objEntity = (ObjEntity) content;
objEntity.setName(NameBuilder.builder(objEntity, dataMap).baseName(objEntity.getName()).dupesPattern(COPY_PATTERN).name());
dataMap.addObjEntity(objEntity);
CreateObjEntityAction.fireObjEntityEvent(this, mediator, dataMap, objEntity);
} else if (content instanceof Embeddable) {
// paste Embeddable to DataMap
Embeddable embeddable = (Embeddable) content;
embeddable.setClassName(NameBuilder.builder(embeddable, dataMap).baseName(embeddable.getClassName()).dupesPattern(COPY_PATTERN).name());
dataMap.addEmbeddable(embeddable);
CreateEmbeddableAction.fireEmbeddableEvent(this, mediator, dataMap, embeddable);
} else if (content instanceof QueryDescriptor) {
QueryDescriptor query = (QueryDescriptor) content;
query.setName(NameBuilder.builder(query, dataMap).dupesPattern(COPY_PATTERN).baseName(query.getName()).name());
query.setDataMap(dataMap);
dataMap.addQueryDescriptor(query);
QueryType.fireQueryEvent(this, mediator, dataMap, query);
} else if (content instanceof Procedure) {
// paste Procedure to DataMap
Procedure procedure = (Procedure) content;
procedure.setName(NameBuilder.builder(procedure, dataMap).dupesPattern(COPY_PATTERN).baseName(procedure.getName()).name());
dataMap.addProcedure(procedure);
CreateProcedureAction.fireProcedureEvent(this, mediator, dataMap, procedure);
}
} else if (where instanceof DbEntity) {
final DbEntity dbEntity = (DbEntity) where;
if (content instanceof DbAttribute) {
DbAttribute attr = (DbAttribute) content;
attr.setName(NameBuilder.builder(attr, dbEntity).dupesPattern(COPY_PATTERN).baseName(attr.getName()).name());
dbEntity.addAttribute(attr);
CreateAttributeAction.fireDbAttributeEvent(this, mediator, mediator.getCurrentDataMap(), dbEntity, attr);
} else if (content instanceof DbRelationship) {
DbRelationship rel = (DbRelationship) content;
rel.setName(NameBuilder.builder(rel, dbEntity).baseName(rel.getName()).dupesPattern(COPY_PATTERN).name());
dbEntity.addRelationship(rel);
CreateRelationshipAction.fireDbRelationshipEvent(this, mediator, dbEntity, rel);
}
} else if (where instanceof ObjEntity) {
ObjEntity objEntity = (ObjEntity) where;
if (content instanceof ObjAttribute) {
ObjAttribute attr = (ObjAttribute) content;
attr.setName(NameBuilder.builder(attr, objEntity).baseName(attr.getName()).dupesPattern(COPY_PATTERN).name());
objEntity.addAttribute(attr);
CreateAttributeAction.fireObjAttributeEvent(this, mediator, mediator.getCurrentDataMap(), objEntity, attr);
} else if (content instanceof ObjRelationship) {
ObjRelationship rel = (ObjRelationship) content;
rel.setName(NameBuilder.builder(rel, objEntity).baseName(rel.getName()).dupesPattern(COPY_PATTERN).name());
objEntity.addRelationship(rel);
CreateRelationshipAction.fireObjRelationshipEvent(this, mediator, objEntity, rel);
} else if (content instanceof ObjCallbackMethod) {
ObjCallbackMethod method = (ObjCallbackMethod) content;
method.setName(NameBuilder.builderForCallbackMethod(objEntity).baseName(method.getName()).dupesPattern(COPY_PATTERN).name());
objEntity.getCallbackMap().getCallbackDescriptor(mediator.getCurrentCallbackType().getType()).addCallbackMethod(method.getName());
CallbackMethodEvent ce = new CallbackMethodEvent(this, null, method.getName(), MapEvent.ADD);
getProjectController().fireCallbackMethodEvent(ce);
}
} else if (where instanceof Embeddable) {
final Embeddable embeddable = (Embeddable) where;
if (content instanceof EmbeddableAttribute) {
EmbeddableAttribute attr = (EmbeddableAttribute) content;
attr.setName(NameBuilder.builder(attr, embeddable).baseName(attr.getName()).dupesPattern(COPY_PATTERN).name());
embeddable.addAttribute(attr);
CreateAttributeAction.fireEmbeddableAttributeEvent(this, mediator, embeddable, attr);
}
} else if (where instanceof Procedure) {
// paste param to procedure
final Procedure procedure = (Procedure) where;
if (content instanceof ProcedureParameter) {
ProcedureParameter param = (ProcedureParameter) content;
param.setName(NameBuilder.builder(param, procedure).baseName(param.getName()).dupesPattern(COPY_PATTERN).name());
procedure.addCallParameter(param);
CreateProcedureParameterAction.fireProcedureParameterEvent(this, mediator, procedure, param);
}
}
}
use of org.apache.cayenne.map.EmbeddableAttribute in project cayenne by apache.
the class RemoveAction method removeEmbAttributes.
private void removeEmbAttributes(ProjectController mediator, ConfirmRemoveDialog dialog, EmbeddableAttribute[] embAttrs) {
if (embAttrs != null && embAttrs.length > 0) {
if ((embAttrs.length == 1 && dialog.shouldDelete("DbAttribute", embAttrs[0].getName())) || (embAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
Embeddable embeddable = mediator.getCurrentEmbeddable();
application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(embeddable, embAttrs));
for (EmbeddableAttribute attrib : embAttrs) {
embeddable.removeAttribute(attrib.getName());
EmbeddableAttributeEvent e = new EmbeddableAttributeEvent(Application.getFrame(), attrib, embeddable, MapEvent.REMOVE);
mediator.fireEmbeddableAttributeEvent(e);
}
ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
}
}
}
use of org.apache.cayenne.map.EmbeddableAttribute in project cayenne by apache.
the class RemoveAttributeAction method performAction.
@Override
public void performAction(ActionEvent e, boolean allowAsking) {
ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
ProjectController mediator = getProjectController();
EmbeddableAttribute[] embAttrs = getProjectController().getCurrentEmbAttributes();
ObjAttribute[] objAttrs = getProjectController().getCurrentObjAttributes();
DbAttribute[] dbAttrs = getProjectController().getCurrentDbAttributes();
if (embAttrs != null && embAttrs.length > 0) {
if ((embAttrs.length == 1 && dialog.shouldDelete("Embeddable Attribute", embAttrs[0].getName())) || (embAttrs.length > 1 && dialog.shouldDelete("selected EmbAttributes"))) {
Embeddable embeddable = mediator.getCurrentEmbeddable();
application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(embeddable, embAttrs));
removeEmbeddableAttributes(embeddable, embAttrs);
}
} else if (objAttrs != null && objAttrs.length > 0) {
if ((objAttrs.length == 1 && dialog.shouldDelete("ObjAttribute", objAttrs[0].getName())) || (objAttrs.length > 1 && dialog.shouldDelete("selected ObjAttributes"))) {
ObjEntity entity = mediator.getCurrentObjEntity();
application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, objAttrs));
removeObjAttributes(entity, objAttrs);
}
} else if (dbAttrs != null && dbAttrs.length > 0) {
if ((dbAttrs.length == 1 && dialog.shouldDelete("DbAttribute", dbAttrs[0].getName())) || (dbAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
DbEntity entity = mediator.getCurrentDbEntity();
application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, dbAttrs));
removeDbAttributes(mediator.getCurrentDataMap(), entity, dbAttrs);
}
}
}
Aggregations