use of org.apache.cayenne.map.DbRelationship 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.DbRelationship in project cayenne by apache.
the class RemoveRelationshipAction method removeDbRelationships.
public void removeDbRelationships(DbEntity entity, DbRelationship[] rels) {
ProjectController mediator = getProjectController();
for (DbRelationship rel : rels) {
entity.removeRelationship(rel.getName());
RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
mediator.fireDbRelationshipEvent(e);
}
ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class RemoveRelationshipAction method performAction.
@Override
public void performAction(ActionEvent e, boolean allowAsking) {
ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
ProjectController mediator = getProjectController();
ObjRelationship[] rels = getProjectController().getCurrentObjRelationships();
if (rels != null && rels.length > 0) {
if ((rels.length == 1 && dialog.shouldDelete("ObjRelationship", rels[0].getName())) || (rels.length > 1 && dialog.shouldDelete("selected ObjRelationships"))) {
ObjEntity entity = mediator.getCurrentObjEntity();
removeObjRelationships(entity, rels);
Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, rels));
}
} else {
DbRelationship[] dbRels = getProjectController().getCurrentDbRelationships();
if (dbRels != null && dbRels.length > 0) {
if ((dbRels.length == 1 && dialog.shouldDelete("DbRelationship", dbRels[0].getName())) || (dbRels.length > 1 && dialog.shouldDelete("selected DbRelationships"))) {
DbEntity entity = mediator.getCurrentDbEntity();
removeDbRelationships(entity, dbRels);
Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, dbRels));
}
}
}
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class InferRelationshipsControllerBase method createReversRelationship.
public void createReversRelationship(DbEntity eSourse, DbEntity eTarget) {
InferredRelationship myir = new InferredRelationship();
for (DbRelationship relationship : eSourse.getRelationships()) {
for (DbJoin join : relationship.getJoins()) {
if (((DbEntity) join.getSource().getEntity()).equals(eSourse) && ((DbEntity) join.getTarget().getEntity()).equals(eTarget)) {
return;
}
}
}
myir.setSource(eSourse);
myir.setTarget(eTarget);
inferredRelationships.add(myir);
}
use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.
the class ObjAttributeInfoDialog method setPath.
public boolean setPath(boolean isChange) {
if (isChange()) {
attributeSaved.setType(view.getTypeComboBox().getSelectedItem().toString());
attributeSaved.setName(view.getAttributeName().getText());
}
if (!(attributeSaved instanceof EmbeddedAttribute) || isRegistredType(attributeSaved.getType())) {
StringBuilder attributePath = new StringBuilder();
StringBuilder pathStr = new StringBuilder();
if (attribute.getEntity().getDbEntity() != null) {
TreePath path = view.getPathBrowser().getSelectionPath();
if (path.getLastPathComponent() instanceof DbAttribute) {
Object[] pathComponents = path.getPath();
for (int i = 0; i < pathComponents.length; i++) {
boolean attrOrRel = true;
if (pathComponents[i] instanceof DbAttribute) {
pathStr.append(((DbAttribute) pathComponents[i]).getName());
attributePath.append(((DbAttribute) pathComponents[i]).getName());
} else if (pathComponents[i] instanceof DbRelationship) {
pathStr.append(((DbRelationship) pathComponents[i]).getName());
attributePath.append(((DbRelationship) pathComponents[i]).getName());
} else {
attrOrRel = false;
}
if (i != pathComponents.length - 1 && attrOrRel) {
pathStr.append(" -> ");
attributePath.append(".");
}
}
}
} else {
view.getCurrentPathLabel().setText("");
}
view.getCurrentPathLabel().setText(pathStr.toString());
if (attribute.getDbAttributePath() != null && !embeddableNames.contains(view.getTypeComboBox().getSelectedItem().toString())) {
if (!attribute.getDbAttributePath().equals(attributePath.toString())) {
attributeSaved.setDbAttributePath(attributePath.toString());
if (!attribute.getDbAttributePath().equals(attributePath.toString()) && isChange) {
model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
}
return true;
}
} else {
if (attributePath.length() > 0 || (attribute instanceof EmbeddedAttribute && !(attributeSaved instanceof EmbeddedAttribute))) {
attributeSaved.setDbAttributePath(attributePath.toString());
if (attributePath.length() == 0) {
model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
return false;
}
return true;
}
}
}
return false;
}
Aggregations