Search in sources :

Example 1 with MultipleObjectsDisplayEvent

use of org.apache.cayenne.modeler.event.MultipleObjectsDisplayEvent in project cayenne by apache.

the class ProjectTreeView method initTreeSelectionListener.

private void initTreeSelectionListener() {
    treeSelectionListener = new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            TreePath[] paths = getSelectionPaths();
            if (paths != null) {
                if (paths.length > 1) {
                    ConfigurationNode projectParentPath = null;
                    ConfigurationNode[] projectPaths = new ConfigurationNode[paths.length];
                    boolean commonParentPath = true;
                    for (int i = 0; i < paths.length; i++) {
                        projectPaths[i] = createProjectPath(paths[i]);
                        TreePath parentPath = paths[i].getParentPath();
                        if (i > 0 && parentPath != null && !parentPath.equals(paths[i - 1].getParentPath())) {
                            commonParentPath = false;
                        }
                    }
                    if (commonParentPath) {
                        TreePath parentPath = paths[0].getParentPath();
                        projectParentPath = createProjectPath(parentPath);
                    }
                    mediator.fireMultipleObjectsDisplayEvent(new MultipleObjectsDisplayEvent(this, projectPaths, projectParentPath));
                } else if (paths.length == 1) {
                    processSelection(paths[0]);
                }
            }
        }

        /**
         * Converts TreePath to Object
         */
        private ConfigurationNode createProjectPath(TreePath treePath) {
            Object[] path = treePath.getPath();
            DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) path[path.length - 1];
            return (ConfigurationNode) treeNode.getUserObject();
        }
    };
    addTreeSelectionListener(treeSelectionListener);
}
Also used : MultipleObjectsDisplayEvent(org.apache.cayenne.modeler.event.MultipleObjectsDisplayEvent) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 2 with MultipleObjectsDisplayEvent

use of org.apache.cayenne.modeler.event.MultipleObjectsDisplayEvent in project cayenne by apache.

the class MultipleObjectsDisplayEventType method fireLastDisplayEvent.

@Override
public void fireLastDisplayEvent() {
    DataChannelDescriptor dataChannel = (DataChannelDescriptor) controller.getProject().getRootNode();
    String parentObjectName = preferences.getParentObject();
    ConfigurationNode parentObject;
    ConfigurationNode[] multipleObjects;
    if (dataChannel.getDataMap(parentObjectName) != null) {
        DataMap dataMap = dataChannel.getDataMap(parentObjectName);
        parentObject = dataMap;
        multipleObjects = getLastMultipleObjects(dataMap);
    } else if (dataChannel.getNodeDescriptor(parentObjectName) != null) {
        DataNodeDescriptor dataNode = dataChannel.getNodeDescriptor(parentObjectName);
        parentObject = dataNode;
        multipleObjects = getLastMultipleObjects(dataNode);
    } else {
        parentObject = dataChannel;
        multipleObjects = getLastMultipleObjects(dataChannel);
    }
    MultipleObjectsDisplayEvent multipleDisplayEvent = new MultipleObjectsDisplayEvent(this, multipleObjects, parentObject);
    controller.fireMultipleObjectsDisplayEvent(multipleDisplayEvent);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) MultipleObjectsDisplayEvent(org.apache.cayenne.modeler.event.MultipleObjectsDisplayEvent) ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

ConfigurationNode (org.apache.cayenne.configuration.ConfigurationNode)2 MultipleObjectsDisplayEvent (org.apache.cayenne.modeler.event.MultipleObjectsDisplayEvent)2 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreePath (javax.swing.tree.TreePath)1 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)1 DataMap (org.apache.cayenne.map.DataMap)1