Search in sources :

Example 1 with ResolveDbRelationshipDialog

use of org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog in project cayenne by apache.

the class RelationshipUndoableEdit method redo.

@Override
public void redo() throws CannotRedoException {
    super.redo();
    ResolveDbRelationshipDialog dialog = new ResolveDbRelationshipDialog(relationship, false);
    dialog.setVisible(true);
}
Also used : ResolveDbRelationshipDialog(org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog)

Example 2 with ResolveDbRelationshipDialog

use of org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog in project cayenne by apache.

the class ObjRelationshipInfo method createRelationship.

/**
 * Creates a new relationship connecting currently selected source entity
 * with ObjRelationship target entity. User is allowed to edit the
 * relationship, change its name, and create joins.
 */
protected void createRelationship() {
    DbRelationship dbRel = getLastRelationship();
    DbEntity source = dbRel != null ? dbRel.getTargetEntity() : null;
    DbRelationshipTarget targetModel = new DbRelationshipTarget(mediator, getStartEntity(), source);
    targetModel.startupAction();
    if (!targetModel.isSavePressed()) {
        return;
    }
    DbRelationship dbRelationship = new DbRelationship();
    dbRelationship.setSourceEntity(targetModel.getSource());
    dbRelationship.setTargetEntityName(targetModel.getTarget());
    dbRelationship.setToMany(targetModel.isToMany());
    dbRelationship.setName(createNamingStrategy(NameGeneratorPreferences.getInstance().getLastUsedStrategies().get(0)).relationshipName(dbRelationship));
    targetModel.getSource().addRelationship(dbRelationship);
    // TODO: creating relationship outside of ResolveDbRelationshipDialog
    // confuses it to send incorrect event - CHANGE instead of ADD
    ResolveDbRelationshipDialog dialog = new ResolveDbRelationshipDialog(dbRelationship);
    dialog.setVisible(true);
    if (dialog.isCancelPressed()) {
        targetModel.getSource().removeRelationship(dbRelationship.getName());
    } else {
        MultiColumnBrowser pathBrowser = getPathBrowser();
        Object[] oldPath = targetModel.isSource1Selected() ? new Object[] { getStartEntity() } : pathBrowser.getSelectionPath().getPath();
        /**
         * Update the view
         */
        EntityTreeModel treeModel = (EntityTreeModel) pathBrowser.getModel();
        treeModel.invalidate();
        pathBrowser.setSelectionPath(new TreePath(new Object[] { getStartEntity() }));
        pathBrowser.repaint();
        Object[] path = new Object[oldPath.length + 1];
        System.arraycopy(oldPath, 0, path, 0, path.length - 1);
        path[path.length - 1] = dbRelationship;
        pathBrowser.setSelectionPath(new TreePath(path));
    }
    dialog.dispose();
}
Also used : ResolveDbRelationshipDialog(org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog) MultiColumnBrowser(org.apache.cayenne.modeler.util.MultiColumnBrowser) DbEntity(org.apache.cayenne.map.DbEntity) TreePath(javax.swing.tree.TreePath) EntityTreeModel(org.apache.cayenne.modeler.util.EntityTreeModel) DbRelationship(org.apache.cayenne.map.DbRelationship)

Example 3 with ResolveDbRelationshipDialog

use of org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog in project cayenne by apache.

the class DbEntityRelationshipPanel method initController.

private void initController() {
    this.mediator.addDbEntityDisplayListener(this);
    this.mediator.addDbEntityListener(this);
    this.mediator.addDbRelationshipListener(this);
    resolver = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int row = table.getSelectedRow();
            if (row < 0) {
                return;
            }
            // Get DbRelationship
            DbRelationshipTableModel model = (DbRelationshipTableModel) table.getModel();
            DbRelationship rel = model.getRelationship(row);
            ResolveDbRelationshipDialog dialog = new ResolveDbRelationshipDialog(rel);
            dialog.setVisible(true);
            dialog.dispose();
        }
    };
    resolveMenu.addActionListener(resolver);
    table.getSelectionModel().addListSelectionListener(new DbRelationshipListSelectionListener());
    mediator.getApplication().getActionManager().setupCutCopyPaste(table, CutAttributeRelationshipAction.class, CopyAttributeRelationshipAction.class);
}
Also used : ResolveDbRelationshipDialog(org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) DbRelationship(org.apache.cayenne.map.DbRelationship)

Example 4 with ResolveDbRelationshipDialog

use of org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog in project cayenne by apache.

the class RelationshipUndoableEdit method undo.

@Override
public void undo() throws CannotUndoException {
    super.undo();
    ResolveDbRelationshipDialog dialog = new ResolveDbRelationshipDialog(relationship, false);
    dialog.setVisible(true);
}
Also used : ResolveDbRelationshipDialog(org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog)

Aggregations

ResolveDbRelationshipDialog (org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog)4 DbRelationship (org.apache.cayenne.map.DbRelationship)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 TreePath (javax.swing.tree.TreePath)1 DbEntity (org.apache.cayenne.map.DbEntity)1 EntityTreeModel (org.apache.cayenne.modeler.util.EntityTreeModel)1 MultiColumnBrowser (org.apache.cayenne.modeler.util.MultiColumnBrowser)1