use of org.apache.cayenne.map.ObjRelationship 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.ObjRelationship in project cayenne by apache.
the class WarningDialogByDbTargetChange method showWarningDialog.
/*
Check the situation, when targetEntity in DbRelationship was changed.
After we have two cases:
- the user agrees to accept changes (all ObjRelationships and ObjAttributes),
that are related to current targetEntity and set new targetEntity.
- the user doesn't agree and wanna return back.
*/
public static boolean showWarningDialog(ProjectController mediator, DbRelationship relationship) {
Collection<ObjRelationship> objRelationshipsForDbRelationship = ProjectUtil.findObjRelationshipsForDbRelationship(mediator, relationship);
Collection<ObjAttribute> fObjAttributesForDbRelationship = ProjectUtil.findObjAttributesForDbRelationship(mediator, relationship);
if (fObjAttributesForDbRelationship.isEmpty() && objRelationshipsForDbRelationship.isEmpty()) {
return true;
}
JPanel dialogPanel = new JPanel();
dialogPanel.setLayout(new BorderLayout());
JLabel textLabel = new JLabel(String.format("<html><p>Following ObjAttributes and ObjRelationships " + "<br>will be affected by change of DbRelationship <br> '%s'" + " target and must be fixed manually. " + "<br>Are you sure you want to proceed?</p><br></html>", relationship.getName()));
dialogPanel.add(textLabel, BorderLayout.NORTH);
DefaultListModel<String> model = new DefaultListModel<>();
JList<String> objects = new JList<>(model);
JScrollPane scrollPane = new JScrollPane(objects);
if (!objRelationshipsForDbRelationship.isEmpty()) {
model.addElement("Relationships: ");
for (ObjRelationship objRelationship : objRelationshipsForDbRelationship) {
model.addElement(objRelationship.getSourceEntity().getName() + "." + objRelationship.getName());
}
}
if (!fObjAttributesForDbRelationship.isEmpty()) {
model.addElement("Attributes: ");
for (ObjAttribute objAttribute : fObjAttributesForDbRelationship) {
model.addElement(objAttribute.getEntity().getName() + "." + objAttribute.getName());
}
}
dialogPanel.add(scrollPane, BorderLayout.SOUTH);
int result = JOptionPane.showConfirmDialog(Application.getFrame(), dialogPanel, "Warning", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
return (result == JOptionPane.OK_OPTION);
}
use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class ObjRelationshipInfo method valueChanged.
/**
* Sets list of DB Relationships current ObjRelationship is mapped to
*/
public void valueChanged(TreeSelectionEvent e) {
TreePath selectedPath = e.getPath();
// at least two elements to constitute a valid ordering path
if (selectedPath == null || selectedPath.getPathCount() < 2) {
return;
}
Relationship rel = (Relationship) selectedPath.getLastPathComponent();
DbEntity target = (DbEntity) rel.getTargetEntity();
/**
* Initialize root with one of mapped ObjEntities.
*/
Collection<ObjEntity> objEntities = target.getDataMap().getMappedEntities(target);
List<DbRelationship> relPath = new Vector<DbRelationship>(selectedPath.getPathCount() - 1);
for (int i = 1; i < selectedPath.getPathCount(); i++) {
relPath.add((DbRelationship) selectedPath.getPathComponent(i));
}
setDbRelationships(relPath);
updateCollectionChoosers();
}
use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class DeleteRulesIT method changeDeleteRule.
private int changeDeleteRule(int deleteRule) {
ObjEntity entity = context.getEntityResolver().getObjEntity(DeleteRuleFlatA.class);
ObjRelationship relationship = entity.getRelationship(DeleteRuleFlatA.FLAT_B.getName());
int oldRule = relationship.getDeleteRule();
relationship.setDeleteRule(deleteRule);
return oldRule;
}
use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class DeleteRulesIT method restoreReverse.
private void restoreReverse(ObjRelationship reverse) {
ObjEntity entity = context.getEntityResolver().getObjEntity(DeleteRuleFlatA.class);
ObjRelationship relationship = entity.getRelationship(DeleteRuleFlatA.FLAT_B.getName());
relationship.getTargetEntity().addRelationship(reverse);
context.getEntityResolver().getClassDescriptorMap().removeDescriptor("DeleteRuleFlatA");
context.getEntityResolver().getClassDescriptorMap().removeDescriptor("DeleteRuleFlatB");
}
Aggregations