Search in sources :

Example 1 with EntityTreeModel

use of org.apache.cayenne.modeler.util.EntityTreeModel in project cayenne by apache.

the class SQLTemplatePrefetchTab method createBrowserModel.

protected TreeModel createBrowserModel(Entity entity) {
    EntityTreeModel treeModel = new EntityTreeModel(entity);
    treeModel.setFilter(new EntityTreeFilter() {

        public boolean attributeMatch(Object node, Attribute attr) {
            return false;
        }

        public boolean relationshipMatch(Object node, Relationship rel) {
            return true;
        }
    });
    return treeModel;
}
Also used : EntityTreeFilter(org.apache.cayenne.modeler.util.EntityTreeFilter) EntityTreeModel(org.apache.cayenne.modeler.util.EntityTreeModel) Attribute(org.apache.cayenne.map.Attribute) Relationship(org.apache.cayenne.map.Relationship)

Example 2 with EntityTreeModel

use of org.apache.cayenne.modeler.util.EntityTreeModel in project cayenne by apache.

the class SelectQueryPrefetchTab method createBrowserModel.

protected TreeModel createBrowserModel(Entity entity) {
    EntityTreeModel treeModel = new EntityTreeModel(entity);
    treeModel.setFilter(new EntityTreeFilter() {

        public boolean attributeMatch(Object node, Attribute attr) {
            return false;
        }

        public boolean relationshipMatch(Object node, Relationship rel) {
            return true;
        }
    });
    return treeModel;
}
Also used : EntityTreeFilter(org.apache.cayenne.modeler.util.EntityTreeFilter) EntityTreeModel(org.apache.cayenne.modeler.util.EntityTreeModel) Attribute(org.apache.cayenne.map.Attribute) Relationship(org.apache.cayenne.map.Relationship)

Example 3 with EntityTreeModel

use of org.apache.cayenne.modeler.util.EntityTreeModel 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 4 with EntityTreeModel

use of org.apache.cayenne.modeler.util.EntityTreeModel in project cayenne by apache.

the class ObjRelationshipInfo method initFromModel.

void initFromModel() {
    if (view.pathBrowser.getModel() == null) {
        EntityTreeModel treeModel = new EntityTreeModel(getStartEntity());
        treeModel.setFilter(new EntityTreeRelationshipFilter());
        view.pathBrowser.setModel(treeModel);
        setSelectionPath(getSavedDbRelationships());
    }
}
Also used : EntityTreeModel(org.apache.cayenne.modeler.util.EntityTreeModel) EntityTreeRelationshipFilter(org.apache.cayenne.modeler.util.EntityTreeRelationshipFilter)

Example 5 with EntityTreeModel

use of org.apache.cayenne.modeler.util.EntityTreeModel in project cayenne by apache.

the class ObjAttributeInfoDialog method initController.

private void initController(ObjAttribute attr) {
    for (String embeddableName : embeddableNames) {
        ((DefaultComboBoxModel) view.getTypeComboBox().getModel()).addElement(embeddableName);
    }
    this.attribute = attr;
    if (attribute instanceof EmbeddedAttribute || embeddableNames.contains(attribute.getType())) {
        this.attributeSaved = new EmbeddedAttribute();
    } else {
        this.attributeSaved = new ObjAttribute();
    }
    copyObjAttribute(attributeSaved, attribute);
    relTargets = new ArrayList<DbEntity>(attribute.getEntity().getDataMap().getDbEntities());
    /*
		 * Register auto-selection of the target
		 */
    view.getPathBrowser().addTreeSelectionListener(this);
    view.getAttributeName().setText(attribute.getName());
    if (attribute.getDbAttributePath() != null) {
        if (attribute.getDbAttributePath().contains(".")) {
            String path = attribute.getDbAttributePath();
            view.getCurrentPathLabel().setText(path.replace(".", " -> "));
        } else {
            view.getCurrentPathLabel().setText(attribute.getDbAttributePath());
        }
    } else {
        view.getCurrentPathLabel().setText("");
    }
    view.getSourceEntityLabel().setText(attribute.getEntity().getName());
    view.getTypeComboBox().setSelectedItem(attribute.getType());
    BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
    builder.bindToAction(view.getCancelButton(), "closeAction()");
    builder.bindToAction(view.getSelectPathButton(), "setPath(true)");
    builder.bindToAction(view.getSaveButton(), "saveMapping()");
    /*
		 * set filter for ObjAttributePathBrowser
		 */
    if (view.getPathBrowser().getModel() == null) {
        Entity firstEntity = null;
        if (attribute.getDbAttribute() == null) {
            if (attribute.getParent() instanceof ObjEntity) {
                DbEntity dbEnt = ((ObjEntity) attribute.getParent()).getDbEntity();
                if (dbEnt != null) {
                    Collection<DbAttribute> attrib = dbEnt.getAttributes();
                    Collection<DbRelationship> rel = dbEnt.getRelationships();
                    if (attrib.size() > 0) {
                        Iterator<DbAttribute> iter = attrib.iterator();
                        firstEntity = iter.next().getEntity();
                    } else if (rel.size() > 0) {
                        Iterator<DbRelationship> iter = rel.iterator();
                        firstEntity = iter.next().getSourceEntity();
                    }
                }
            }
        } else {
            firstEntity = getFirstEntity();
        }
        if (firstEntity != null) {
            EntityTreeModel treeModel = new EntityTreeModel(firstEntity);
            treeModel.setFilter(new EntityTreeAttributeRelationshipFilter());
            view.getPathBrowser().setModel(treeModel);
        }
    }
    if (attribute.getDbAttribute() != null) {
        setSelectionPath();
    }
    view.getTypeComboBox().addItemListener(e -> {
        if (lastObjectType != null) {
            if (!lastObjectType.equals(e.getItemSelectable())) {
                if (embeddableNames.contains(e.getItemSelectable().getSelectedObjects()[0].toString())) {
                    if (attributeSaved instanceof ObjAttribute) {
                        EmbeddedAttribute copyAttrSaved = new EmbeddedAttribute();
                        copyObjAttribute(copyAttrSaved, attributeSaved);
                        attributeSaved = copyAttrSaved;
                    }
                } else {
                    if (attributeSaved instanceof EmbeddedAttribute) {
                        ObjAttribute copyAttrSaved = new ObjAttribute();
                        copyObjAttribute(copyAttrSaved, attributeSaved);
                        attributeSaved = copyAttrSaved;
                    }
                }
                attributeSaved.setType(e.getItemSelectable().getSelectedObjects()[0].toString());
                rebuildTable();
                setEnabledSaveButton();
            }
        }
    });
    view.getAttributeName().addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (!view.getAttributeName().getText().equals(attribute.getName())) {
                setEnabledSaveButton();
            }
        }

        public void keyReleased(KeyEvent e) {
            if (!view.getAttributeName().getText().equals(attribute.getName())) {
                setEnabledSaveButton();
            }
        }

        public void keyTyped(KeyEvent e) {
        }
    });
    rebuildTable();
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) BindingBuilder(org.apache.cayenne.swing.BindingBuilder) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddedAttribute(org.apache.cayenne.map.EmbeddedAttribute) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) KeyEvent(java.awt.event.KeyEvent) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) EntityTreeModel(org.apache.cayenne.modeler.util.EntityTreeModel) DbRelationship(org.apache.cayenne.map.DbRelationship) EntityTreeAttributeRelationshipFilter(org.apache.cayenne.modeler.util.EntityTreeAttributeRelationshipFilter) Iterator(java.util.Iterator) KeyListener(java.awt.event.KeyListener)

Aggregations

EntityTreeModel (org.apache.cayenne.modeler.util.EntityTreeModel)5 Attribute (org.apache.cayenne.map.Attribute)2 DbEntity (org.apache.cayenne.map.DbEntity)2 DbRelationship (org.apache.cayenne.map.DbRelationship)2 Relationship (org.apache.cayenne.map.Relationship)2 EntityTreeFilter (org.apache.cayenne.modeler.util.EntityTreeFilter)2 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 Iterator (java.util.Iterator)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 TreePath (javax.swing.tree.TreePath)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 EmbeddedAttribute (org.apache.cayenne.map.EmbeddedAttribute)1 Entity (org.apache.cayenne.map.Entity)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 ResolveDbRelationshipDialog (org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog)1 EntityTreeAttributeRelationshipFilter (org.apache.cayenne.modeler.util.EntityTreeAttributeRelationshipFilter)1 EntityTreeRelationshipFilter (org.apache.cayenne.modeler.util.EntityTreeRelationshipFilter)1 MultiColumnBrowser (org.apache.cayenne.modeler.util.MultiColumnBrowser)1