use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class RemoveEntityAction method performAction.
@Override
public void performAction(ActionEvent e, boolean allowAsking) {
ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
Entity entity = builder.getSelectedEntity();
if (entity == null) {
return;
}
if (entity instanceof ObjEntity) {
if (dialog.shouldDelete("ObjEntity", entity.getName())) {
application.getUndoManager().addEdit(new RemoveUndoableEdit(entity.getDataMap(), (ObjEntity) entity));
removeObjEntity(entity.getDataMap(), (ObjEntity) entity);
}
} else {
if (dialog.shouldDelete("DbEntity", entity.getName())) {
application.getUndoManager().addEdit(new RemoveUndoableEdit(entity.getDataMap(), (DbEntity) entity));
removeDbEntity(entity.getDataMap(), (DbEntity) entity);
}
}
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class ShowGraphEntityAction method performAction.
@Override
public void performAction(ActionEvent e) {
Entity entity = null;
ProjectController mediator = getProjectController();
if (mediator.getCurrentDbEntity() != null) {
entity = mediator.getCurrentDbEntity();
} else if (mediator.getCurrentObjEntity() != null) {
entity = mediator.getCurrentObjEntity();
}
if (entity != null) {
showEntity(entity);
}
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class FindAction method jumpToResult.
/**
* Navigate to search result
* Used also in {@link org.apache.cayenne.modeler.graph.action.EntityDisplayAction}
*/
public static void jumpToResult(FindAction.SearchResultEntry searchResultEntry) {
EditorView editor = ((CayenneModelerFrame) Application.getInstance().getFrameController().getView()).getView();
DataChannelDescriptor domain = (DataChannelDescriptor) Application.getInstance().getProject().getRootNode();
if (searchResultEntry.getObject() instanceof Entity) {
jumpToEntityResult((Entity) searchResultEntry.getObject(), editor, domain);
} else if (searchResultEntry.getObject() instanceof QueryDescriptor) {
jumpToQueryResult((QueryDescriptor) searchResultEntry.getObject(), editor, domain);
} else if (searchResultEntry.getObject() instanceof Embeddable) {
jumpToEmbeddableResult((Embeddable) searchResultEntry.getObject(), editor, domain);
} else if (searchResultEntry.getObject() instanceof EmbeddableAttribute) {
jumpToEmbeddableAttributeResult((EmbeddableAttribute) searchResultEntry.getObject(), editor, domain);
} else if (searchResultEntry.getObject() instanceof Attribute || searchResultEntry.getObject() instanceof Relationship) {
jumpToAttributeResult(searchResultEntry, editor, domain);
}
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class FindAction method jumpToAttributeResult.
private static void jumpToAttributeResult(SearchResultEntry searchResultEntry, EditorView editor, DataChannelDescriptor domain) {
DataMap map;
Entity entity;
if (searchResultEntry.getObject() instanceof Attribute) {
map = ((Attribute) searchResultEntry.getObject()).getEntity().getDataMap();
entity = ((Attribute) searchResultEntry.getObject()).getEntity();
} else {
map = ((Relationship) searchResultEntry.getObject()).getSourceEntity().getDataMap();
entity = ((Relationship) searchResultEntry.getObject()).getSourceEntity();
}
buildAndSelectTreePath(map, entity, editor);
if (searchResultEntry.getObject() instanceof Attribute) {
AttributeDisplayEvent event = new AttributeDisplayEvent(editor.getProjectTreeView(), (Attribute) searchResultEntry.getObject(), entity, map, domain);
event.setMainTabFocus(true);
if (searchResultEntry.getObject() instanceof DbAttribute) {
editor.getDbDetailView().currentDbAttributeChanged(event);
} else {
editor.getObjDetailView().currentObjAttributeChanged(event);
}
} else if (searchResultEntry.getObject() instanceof Relationship) {
RelationshipDisplayEvent event = new RelationshipDisplayEvent(editor.getProjectTreeView(), (Relationship) searchResultEntry.getObject(), entity, map, domain);
event.setMainTabFocus(true);
if (searchResultEntry.getObject() instanceof DbRelationship) {
editor.getDbDetailView().currentDbRelationshipChanged(event);
} else {
editor.getObjDetailView().currentObjRelationshipChanged(event);
}
}
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class DbAttributePathComboBoxEditor method createTreeModelForComboBox.
@Override
protected EntityTreeModel createTreeModelForComboBox(int attributeIndexInTable) {
ObjAttribute attribute = model.getAttribute(attributeIndexInTable).getValue();
Entity firstEntity = null;
if (attribute.getDbAttribute() == null) {
if (attribute.getParent() instanceof ObjEntity) {
DbEntity dbEnt = ((ObjEntity) attribute.getParent()).getDbEntity();
if (dbEnt != null) {
Collection<DbAttribute> attributes = dbEnt.getAttributes();
Collection<DbRelationship> rel = dbEnt.getRelationships();
if (!attributes.isEmpty()) {
Iterator<DbAttribute> iterator = attributes.iterator();
firstEntity = iterator.next().getEntity();
} else if (!rel.isEmpty()) {
Iterator<DbRelationship> iterator = rel.iterator();
firstEntity = iterator.next().getSourceEntity();
}
}
}
} else {
firstEntity = getFirstEntity(attribute);
}
if (firstEntity != null) {
EntityTreeModel treeModel = new EntityTreeModel(firstEntity);
treeModel.setFilter(new EntityTreeAttributeRelationshipFilter());
return treeModel;
}
return null;
}
Aggregations