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);
}
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);
}
Aggregations