Cleaning up
diff --git a/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorer.java b/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorer.java
index 0d8c3a5..df768b7 100644
--- a/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorer.java
+++ b/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorer.java
@@ -20,6 +20,21 @@
******************************************************************************/
package net.sf.taverna.t2.workbench.ui.workflowexplorer;
+import static java.awt.BorderLayout.CENTER;
+import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
+import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
+import static javax.swing.SwingUtilities.invokeLater;
+import static javax.swing.SwingUtilities.isEventDispatchThread;
+import static net.sf.taverna.t2.lang.ui.ShadedLabel.GREEN;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.inputIcon;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.minusIcon;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.outputIcon;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.plusIcon;
+import static net.sf.taverna.t2.workbench.ui.workflowexplorer.WorkflowExplorerTreeModel.INPUTS;
+import static net.sf.taverna.t2.workbench.ui.workflowexplorer.WorkflowExplorerTreeModel.OUTPUTS;
+import static net.sf.taverna.t2.workbench.ui.workflowexplorer.WorkflowExplorerTreeModel.PROCESSORS;
+import static net.sf.taverna.t2.workbench.ui.workflowexplorer.WorkflowExplorerTreeModel.getPathForObject;
+
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
@@ -37,7 +52,6 @@
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTree;
-import javax.swing.SwingUtilities;
import javax.swing.border.EtchedBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
@@ -58,7 +72,6 @@
import net.sf.taverna.t2.workbench.file.FileManager;
import net.sf.taverna.t2.workbench.file.events.ClosedDataflowEvent;
import net.sf.taverna.t2.workbench.file.events.FileManagerEvent;
-import net.sf.taverna.t2.workbench.icons.WorkbenchIcons;
import net.sf.taverna.t2.workbench.report.ReportManager;
import net.sf.taverna.t2.workbench.selection.DataflowSelectionModel;
import net.sf.taverna.t2.workbench.selection.SelectionManager;
@@ -82,59 +95,49 @@
*/
@SuppressWarnings("serial")
public class WorkflowExplorer extends JPanel implements UIComponentSPI {
-
- /* Purple colour for shaded label on pop up menus */
+ /** Purple colour for shaded label on pop up menus */
public static final Color PURPLISH = new Color(0x8070ff);
-
- /* Manager of all opened workflows */
+ /** Manager of all opened workflows */
private SelectionManager selectionManager;
-
private MenuManager menuManager;
-
- /* Currently selected workflow (to be displayed in the Workflow Explorer). */
+ /** Currently selected workflow (to be displayed in the Workflow Explorer). */
private Workflow workflow;
-
- /* Map of trees for all opened workflows. */
+ /** Map of trees for all opened workflows. */
private Map<Workflow, JTree> openedWorkflowsTrees = new HashMap<>();
-
- /* Tree representation of the currently selected workflow. */
+ /** Tree representation of the currently selected workflow. */
private JTree wfTree;
-
- /*
- * Current workflow's selection model event observer - telling us what is the currently selected
- * object in the current workflow.
+ /**
+ * Current workflow's selection model event observer - telling us what is
+ * the currently selected object in the current workflow.
*/
private Observer<DataflowSelectionMessage> workflowSelectionListener = new DataflowSelectionListener();
-
- /* Scroll pane containing the workflow tree. */
+ /** Scroll pane containing the workflow tree. */
private JScrollPane scrollPane;
-
protected FileManager fileManager;
protected FileManagerObserver fileManagerObserver = new FileManagerObserver();
-
protected EditManager editManager;
protected EditManagerObserver editManagerObserver = new EditManagerObserver();
private final ReportManager reportManager;
-
private final ActivityIconManager activityIconManager;
-
private final ServiceRegistry serviceRegistry;
+ @Override
public ImageIcon getIcon() {
return null;
}
+ @Override
public String getName() {
return "Workflow Explorer";
}
+ @Override
public void onDisplay() {
- // TODO Auto-generated method stub
}
+ @Override
public void onDispose() {
- // TODO Auto-generated method stub
}
/**
@@ -154,21 +157,25 @@
this.setTransferHandler(new ServiceTransferHandler(editManager, menuManager,
selectionManager, serviceRegistry));
- // Create a tree that will represent a view over the current workflow
- // Initially, there is no workflow opened, so we create an empty tree,
- // but immediately after all visual components of the Workbench are
- // created (including Workflow Explorer) a new empty workflow is
- // created, which is represented with a NON-empty JTree with four nodes
- // (Inputs, Outputs, Processors, and Data links) that themselves have no
- // children.
+ /*
+ * Create a tree that will represent a view over the current workflow.
+ * Initially, there is no workflow opened, so we create an empty tree,
+ * but immediately after all visual components of the Workbench are
+ * created (including Workflow Explorer) a new empty workflow is
+ * created, which is represented with a NON-empty JTree with four nodes
+ * (Inputs, Outputs, Processors, and Data links) that themselves have no
+ * children.
+ */
assignWfTree(new JTree(new DefaultMutableTreeNode("No workflow open")));
// Start observing workflow switching or closing events on File Manager
fileManager.addObserver(fileManagerObserver);
selectionManager.addObserver(new SelectionManagerObserver());
- // Start observing events on Edit Manager when current workflow is
- // edited (e.g. a node added, deleted or updated)
+ /*
+ * Start observing events on Edit Manager when current workflow is
+ * edited (e.g. a node added, deleted or updated)
+ */
editManager.addObserver(editManagerObserver);
// Draw visual components
@@ -177,39 +184,38 @@
private void assignWfTree(JTree tree) {
wfTree = tree;
- wfTree.setTransferHandler(new ServiceTransferHandler(editManager, menuManager,
- selectionManager, serviceRegistry));
+ wfTree.setTransferHandler(new ServiceTransferHandler(editManager,
+ menuManager, selectionManager, serviceRegistry));
}
/**
* Lays out the swing components.
*/
public void initComponents() {
-
setLayout(new BorderLayout());
// Workflow tree scroll pane
- scrollPane = new JScrollPane(wfTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
- JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ scrollPane = new JScrollPane(wfTree, VERTICAL_SCROLLBAR_AS_NEEDED,
+ HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setBorder(new EtchedBorder());
- // Title - not needed as it is now located on a tab labelled 'Workflow
- // Explorer'
+ /*
+ * Title - not needed as it is now located on a tab labelled 'Workflow
+ * Explorer'
+ */
// JLabel wfExplorerLabel = new JLabel("Workflow Explorer");
// wfExplorerLabel.setMinimumSize(new Dimension(0, 0)); // so that it
// can shrink completely
// wfExplorerLabel.setBorder(new EmptyBorder(0, 0, 5, 0));
// add(wfExplorerLabel, BorderLayout.NORTH);
- add(scrollPane, BorderLayout.CENTER);
-
+ add(scrollPane, CENTER);
}
/**
* Gets called when a workflow is opened or a new (empty) one created.
*/
public void createWorkflowTree(Workflow df) {
-
// Set the current workflow
workflow = df;
@@ -223,6 +229,7 @@
expandAll(wfTree);
Runnable expandWorkflowTreeRunnable = new Runnable() {
+ @Override
public void run() {
// Repaint the scroll pane containing the tree
scrollPane.setViewportView(wfTree);
@@ -231,12 +238,11 @@
}
};
- if (SwingUtilities.isEventDispatchThread()) {
+ if (isEventDispatchThread()) {
expandWorkflowTreeRunnable.run();
} else {
- SwingUtilities.invokeLater(expandWorkflowTreeRunnable);
+ invokeLater(expandWorkflowTreeRunnable);
}
-
}
/**
@@ -260,12 +266,11 @@
}
/**
- * Gets called when the current workflow is edited, or when a parent workflow of a nested
- * workflow is edited due to saved changes in the nested workflow (which is the current
- * workflow).
+ * Gets called when the current workflow is edited, or when a parent
+ * workflow of a nested workflow is edited due to saved changes in the
+ * nested workflow (which is the current workflow).
*/
public void updateWorkflowTree(Workflow df) {
-
// Create the new tree from the updated workflow
JTree newTree = createTreeFromWorkflow(df);
@@ -275,23 +280,31 @@
// Update the tree in the list of opened workflow trees
openedWorkflowsTrees.put(df, newTree);
- // Update the new tree's expansion state based on the old tree
- // i.e. all nodes in the old tree that have been expanded/collapsed
- // should also be expanded/collapsed in the new tree (unless an
- // expanded node has been removed)
- copyExpansionState(oldTree, (DefaultMutableTreeNode) oldTree.getModel().getRoot(), newTree,
- (DefaultMutableTreeNode) newTree.getModel().getRoot());
+ /*
+ * Update the new tree's expansion state based on the old tree i.e. all
+ * nodes in the old tree that have been expanded/collapsed should also
+ * be expanded/collapsed in the new tree (unless an expanded node has
+ * been removed)
+ */
+ copyExpansionState(oldTree, (DefaultMutableTreeNode) oldTree.getModel()
+ .getRoot(), newTree, (DefaultMutableTreeNode) newTree
+ .getModel().getRoot());
- // Get the current workflow from FileManager.
- // If current workflow is different from the workflow df passed through
- // this method then this means that the current workflow is the nested
- // workflow (whose parent is workflow df) and that the nested workflow has been
- // previously edited and then saved which triggered the update on the parent
- // workflow df.
- // In this case, we should just update the parent workflow tree but keep
- // the nested workflow as the current workflow. On the other hand, if the current
- // workflow is the same as workflow df then this is just an update to the current
- // workflow so we have to update and redraw the workflow tree.
+ /*
+ * Get the current workflow from FileManager.
+ *
+ * If current workflow is different from the workflow df passed through
+ * this method then this means that the current workflow is the nested
+ * workflow (whose parent is workflow df) and that the nested workflow
+ * has been previously edited and then saved which triggered the update
+ * on the parent workflow df.
+ *
+ * In this case, we should just update the parent workflow tree but keep
+ * the nested workflow as the current workflow. On the other hand, if
+ * the current workflow is the same as workflow df then this is just an
+ * update to the current workflow so we have to update and redraw the
+ * workflow tree.
+ */
if (df.equals(selectionManager.getSelectedWorkflow())) {
// this was an update on the current workflow
@@ -311,26 +324,32 @@
scrollPane.revalidate();
scrollPane.repaint();
} else {
- // just update the parent tree (already done above) but do not switch the trees
- // Do not revalidate/repaint as we are not switching to the
- // new tree but keep showing the nested wf that has not changed
+ /*
+ * just update the parent tree (already done above) but do not
+ * switch the trees. Do not revalidate/repaint as we are not
+ * switching to the new tree but keep showing the nested wf that has
+ * not changed.
+ */
}
}
/**
- * Copies the expansion state of the old tree starting from the given node in the old tree to
- * the new tree starting from the new node. We normally use it starting from the root nodes of
- * both trees when an update has happened to the tree and we want to preserve the expansion
- * state in the updated tree.
+ * Copies the expansion state of the old tree starting from the given node
+ * in the old tree to the new tree starting from the new node. We normally
+ * use it starting from the root nodes of both trees when an update has
+ * happened to the tree and we want to preserve the expansion state in the
+ * updated tree.
*/
@SuppressWarnings("unchecked")
- private void copyExpansionState(JTree oldTree, DefaultMutableTreeNode oldNode, JTree newTree,
+ private void copyExpansionState(JTree oldTree,
+ DefaultMutableTreeNode oldNode, JTree newTree,
DefaultMutableTreeNode newNode) {
-
boolean expandParentNode = false;
- // Do the children on the node first (so we can set the node's children
- // to be expanded even if the node itself is collapsed)
+ /*
+ * Do the children on the node first (so we can set the node's children
+ * to be expanded even if the node itself is collapsed)
+ */
Enumeration<DefaultMutableTreeNode> children = newNode.children();
while (children.hasMoreElements()) {
DefaultMutableTreeNode newChild = children.nextElement();
@@ -338,31 +357,34 @@
DefaultMutableTreeNode oldChild = findChildWithUserObject(oldNode,
newChild.getUserObject());
- if (oldChild != null) { // corresponding node found in the old tree
+ if (oldChild != null) // corresponding node found in the old tree
// Recursively do the same for each child
copyExpansionState(oldTree, oldChild, newTree, newChild);
- } else { // corresponding node not found in the old tree -
- // a new node has been added or a node had been edited
- // in the new tree so
- // make that node visible now by expanding the parent
- // node
+ else
+ /*
+ * corresponding node not found in the old tree - a new node has
+ * been added or a node had been edited in the new tree so make
+ * that node visible now by expanding the parent node
+ */
expandParentNode = true;
- }
}
// Now do the node
if (expandParentNode) {
- // Order matters - we first check if a new child was inserted to
- // this node
- // (that means that the old node might have been a leaf before)
+ /*
+ * Order matters - we first check if a new child was inserted to
+ * this node (that means that the old node might have been a leaf
+ * before)
+ */
int row = newTree.getRowForPath(new TreePath(newNode.getPath()));
newTree.expandRow(row);
- } else if (oldNode.isLeaf()) { // if it is a leaf - expand/collapse does
- // not work, so use
- // isVisible/makeVisible
- if (oldTree.isVisible(new TreePath(oldNode.getPath()))) {
+ } else if (oldNode.isLeaf()) {
+ /*
+ * if it is a leaf - expand/collapse does not work, so use
+ * isVisible/makeVisible
+ */
+ if (oldTree.isVisible(new TreePath(oldNode.getPath())))
newTree.makeVisible(new TreePath(newNode.getPath()));
- }
} else if (oldTree.isExpanded(new TreePath(oldNode.getPath()))) {
int row = newTree.getRowForPath(new TreePath(newNode.getPath()));
newTree.expandRow(row);
@@ -373,17 +395,17 @@
}
/**
- * Returns a child of a given node that contains the same user object as the one passed to the
- * method.
+ * Returns a child of a given node that contains the same user object as the
+ * one passed to the method.
*/
@SuppressWarnings("unchecked")
- private DefaultMutableTreeNode findChildWithUserObject(DefaultMutableTreeNode node, Object userObject) {
+ private DefaultMutableTreeNode findChildWithUserObject(
+ DefaultMutableTreeNode node, Object userObject) {
Enumeration<DefaultMutableTreeNode> children = node.children();
while (children.hasMoreElements()) {
DefaultMutableTreeNode child = children.nextElement();
- if (child.getUserObject().equals(userObject)) {
+ if (child.getUserObject().equals(userObject))
return child;
- }
}
return null;
}
@@ -397,10 +419,11 @@
tree.setExpandsSelectedPaths(true);
tree.setDragEnabled(false);
tree.setScrollsOnExpand(false);
- tree.setCellRenderer(new WorkflowExplorerTreeCellRenderer(workflow, reportManager, activityIconManager));
+ tree.setCellRenderer(new WorkflowExplorerTreeCellRenderer(workflow,
+ reportManager, activityIconManager));
// tree.setSelectionModel(new WorkflowExplorerTreeSelectionModel());
tree.addTreeSelectionListener(new TreeSelectionListener() {
-
+ @Override
public void valueChanged(TreeSelectionEvent e) {
TreePath selectionPath = e.getNewLeadSelectionPath();
if (selectionPath != null) {
@@ -410,191 +433,209 @@
DataflowSelectionModel selectionModel = selectionManager
.getDataflowSelectionModel(workflow.getParent());
- // If the node that was clicked on was inputs,
- // outputs, services, data links, control links or
- // merges in the main workflow then just make it selected
- // and clear the selection model (as these are just
- // containers for the 'real' workflow components).
+ /*
+ * If the node that was clicked on was inputs, outputs,
+ * services, data links, control links or merges in the main
+ * workflow then just make it selected and clear the
+ * selection model (as these are just containers for the
+ * 'real' workflow components).
+ */
if ((selectedNode.getUserObject() instanceof String)
&& (selectionPath.getPathCount() == 2)) {
selectionModel.clearSelection();
tree.getSelectionModel().setSelectionPath(selectionPath);
+ } else {
+ /*
+ * a 'real' workflow component or the 'whole' workflow
+ * (i.e. the tree root) was clicked on
+ */
- } else { // a 'real' workflow component or the 'whole'
- // workflow (i.e. the tree root) was clicked on
+ /*
+ * We want to disable selection of any nested workflow
+ * components (apart from input and output ports in the
+ * wrapping DataflowActivity)
+ */
+ TreePath path = getPathForObject(selectedNode
+ .getUserObject(), (DefaultMutableTreeNode) tree
+ .getModel().getRoot());
- // We want to disable selection of any nested workflow
- // components (apart from
- // input and output ports in the wrapping
- // DataflowActivity)
- TreePath path = WorkflowExplorerTreeModel.getPathForObject(selectedNode
- .getUserObject(), (DefaultMutableTreeNode) tree.getModel()
- .getRoot());
-
- // The getPathForObject() method will return null in a
- // node is inside
- // a nested workflow and should not be selected
- if (path == null) {
+ /*
+ * The getPathForObject() method will return null in a
+ * node is inside a nested workflow and should not be
+ * selected
+ */
+ if (path == null)
// Just return
return;
- } else {
- // Add it to selection model so it is also selected
- // on the graph as well
- // that listens to the selection model
- selectionModel.addSelection(selectedNode.getUserObject());
- }
+
+ /*
+ * Add it to selection model so it is also selected
+ * on the graph as well that listens to the
+ * selection model
+ */
+ selectionModel.addSelection(selectedNode.getUserObject());
}
}
}
-
});
tree.addMouseListener(new MouseAdapter() {
-
+ @Override
public void mousePressed(MouseEvent evt) {
handleMouseEvent(evt);
}
+ @Override
public void mouseReleased(MouseEvent evt) {
handleMouseEvent(evt);
}
private void handleMouseEvent(MouseEvent evt) {
-
- if (!evt.isPopupTrigger()) {
+ if (!evt.isPopupTrigger())
return;
- }
-
// Discover the tree row that was clicked on
int selRow = tree.getRowForLocation(evt.getX(), evt.getY());
- if (selRow != -1) {
- // Get the selection path for the row
- TreePath selectionPath = tree.getPathForLocation(evt.getX(), evt.getY());
- if (selectionPath != null) {
- // Get the selected node
- final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selectionPath
- .getLastPathComponent();
+ if (selRow == -1)
+ return;
- // For both left and right click - add the workflow
- // object to selection model
- // This will cause the node to become selected (from
- // the selection listener's code)
- DataflowSelectionModel selectionModel = selectionManager
- .getDataflowSelectionModel(workflow.getParent());
+ // Get the selection path for the row
+ TreePath selectionPath = tree.getPathForLocation(evt.getX(),
+ evt.getY());
+ if (selectionPath == null)
+ return;
- // If the node that was clicked on was inputs,
- // outputs, services, data links, control links or
- // merges in the main workflow then just make it
- // selected
- // and clear the selection model (as these are just
- // containers for the 'real' workflow components).
- if ((selectedNode.getUserObject() instanceof String)
- && (selectionPath.getPathCount() == 2)) {
- selectionModel.clearSelection();
- tree.getSelectionModel().setSelectionPath(selectionPath);
+ // Get the selected node
+ final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selectionPath
+ .getLastPathComponent();
- if (selectedNode.getUserObject().equals(
- WorkflowExplorerTreeModel.PROCESSORS)) {
- JPopupMenu menu = new JPopupMenu();
- menu.add(new ShadedLabel("Tree", PURPLISH));
- menu.add(new JMenuItem(new AbstractAction("Expand",
- WorkbenchIcons.plusIcon) {
- public void actionPerformed(ActionEvent evt) {
- expandAscendants(tree, selectedNode);
- }
- }));
- menu.add(new JMenuItem(new AbstractAction("Collapse",
- WorkbenchIcons.minusIcon) {
- public void actionPerformed(ActionEvent evt) {
- collapseAscendants(tree, selectedNode);
- }
- }));
- menu.show(evt.getComponent(), evt.getX(), evt.getY());
- } else if (selectedNode.getUserObject().equals(
- WorkflowExplorerTreeModel.INPUTS)) {
- JPopupMenu menu = new JPopupMenu();
- menu.add(new ShadedLabel("Workflow input ports", ShadedLabel.GREEN));
- menu.add(new JMenuItem(new AbstractAction(
- "Add workflow input port", WorkbenchIcons.inputIcon) {
+ /*
+ * For both left and right click - add the workflow object to
+ * selection model. This will cause the node to become selected
+ * (from the selection listener's code)
+ */
+ DataflowSelectionModel selectionModel = selectionManager
+ .getDataflowSelectionModel(workflow.getParent());
- public void actionPerformed(ActionEvent evt) {
- new AddDataflowInputAction(
- (Workflow) ((DefaultMutableTreeNode) tree
- .getModel().getRoot()).getUserObject(),
- wfTree.getParent(), editManager,
- selectionManager).actionPerformed(evt);
- }
- }));
- menu.show(evt.getComponent(), evt.getX(), evt.getY());
- } else if (selectedNode.getUserObject().equals(
- WorkflowExplorerTreeModel.OUTPUTS)) {
- JPopupMenu menu = new JPopupMenu();
- menu.add(new ShadedLabel("Workflow output ports", ShadedLabel.GREEN));
- menu.add(new JMenuItem(new AbstractAction(
- "Add workflow output port", WorkbenchIcons.outputIcon) {
- public void actionPerformed(ActionEvent evt) {
- new AddDataflowOutputAction(
- (Workflow) ((DefaultMutableTreeNode) tree
- .getModel().getRoot()).getUserObject(),
- wfTree.getParent(), editManager,
- selectionManager).actionPerformed(evt);
- }
- }));
- menu.show(evt.getComponent(), evt.getX(), evt.getY());
+ /*
+ * If the node that was clicked on was inputs, outputs,
+ * services, data links, control links or merges in the main
+ * workflow then just make it selected and clear the selection
+ * model (as these are just containers for the 'real' workflow
+ * components).
+ */
+ if ((selectedNode.getUserObject() instanceof String)
+ && selectionPath.getPathCount() == 2) {
+ selectionModel.clearSelection();
+ tree.getSelectionModel().setSelectionPath(selectionPath);
+
+ Object userObject = selectedNode.getUserObject();
+ if (userObject.equals(PROCESSORS)) {
+ JPopupMenu menu = new JPopupMenu();
+ menu.add(new ShadedLabel("Tree", PURPLISH));
+ menu.add(new JMenuItem(new AbstractAction("Expand",
+ plusIcon) {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ expandAscendants(tree, selectedNode);
}
-
- } else { // a 'real' workflow component or the 'whole'
- // workflow (i.e. the tree root) was clicked
- // on
-
- // We want to disable selection of any nested
- // workflow components (apart from
- // input and output ports in the wrapping
- // DataflowActivity)
- TreePath path = WorkflowExplorerTreeModel.getPathForObject(selectedNode
- .getUserObject(), (DefaultMutableTreeNode) tree.getModel()
- .getRoot());
-
- // The getPathForObject() method will return null in
- // a node is inside
- // a nested workflow and should not be selected
- if (path == null) {
- // Just return
- return;
- } else {
- // Add it to selection model so it is also
- // selected on the graph as well
- // that listens to the selection model
- selectionModel.addSelection(selectedNode.getUserObject());
-
- // Show a contextual pop-up menu
- JPopupMenu menu = menuManager.createContextMenu(workflow,
- selectedNode.getUserObject(), wfTree.getParent());
- if (menu == null) {
- menu = new JPopupMenu();
- }
- if (selectedNode.getUserObject() instanceof Workflow) {
- menu.add(new ShadedLabel("Tree", PURPLISH));
- // Action to expand the whole tree
- menu.add(new JMenuItem(new AbstractAction("Expand all",
- WorkbenchIcons.plusIcon) {
- public void actionPerformed(ActionEvent evt) {
- expandAll(tree);
- }
- }));
- // Action to collapse the whole tree
- menu.add(new JMenuItem(new AbstractAction("Collapse all",
- WorkbenchIcons.minusIcon) {
- public void actionPerformed(ActionEvent evt) {
- collapseAll(tree);
- }
- }));
- }
-
- menu.show(evt.getComponent(), evt.getX(), evt.getY());
+ }));
+ menu.add(new JMenuItem(new AbstractAction("Collapse",
+ minusIcon) {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ collapseAscendants(tree, selectedNode);
}
- }
+ }));
+ menu.show(evt.getComponent(), evt.getX(), evt.getY());
+ } else if (userObject.equals(INPUTS)) {
+ JPopupMenu menu = new JPopupMenu();
+ menu.add(new ShadedLabel("Workflow input ports", GREEN));
+ menu.add(new JMenuItem(new AbstractAction(
+ "Add workflow input port", inputIcon) {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ new AddDataflowInputAction(
+ (Workflow) ((DefaultMutableTreeNode) tree
+ .getModel().getRoot())
+ .getUserObject(), wfTree
+ .getParent(), editManager,
+ selectionManager).actionPerformed(evt);
+ }
+ }));
+ menu.show(evt.getComponent(), evt.getX(), evt.getY());
+ } else if (userObject.equals(OUTPUTS)) {
+ JPopupMenu menu = new JPopupMenu();
+ menu.add(new ShadedLabel("Workflow output ports", GREEN));
+ menu.add(new JMenuItem(new AbstractAction(
+ "Add workflow output port", outputIcon) {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ new AddDataflowOutputAction(
+ (Workflow) ((DefaultMutableTreeNode) tree
+ .getModel().getRoot())
+ .getUserObject(), wfTree
+ .getParent(), editManager,
+ selectionManager).actionPerformed(evt);
+ }
+ }));
+ menu.show(evt.getComponent(), evt.getX(), evt.getY());
}
+ } else {
+ /*
+ * a 'real' workflow component or the 'whole' workflow (i.e.
+ * the tree root) was clicked on
+ */
+
+ /*
+ * We want to disable selection of any nested workflow
+ * components (apart from input and output ports in the
+ * wrapping DataflowActivity)
+ */
+ TreePath path = getPathForObject(
+ selectedNode.getUserObject(),
+ (DefaultMutableTreeNode) tree.getModel().getRoot());
+
+ /*
+ * The getPathForObject() method will return null in a node
+ * is inside a nested workflow and should not be selected
+ */
+ if (path == null)
+ // Just return
+ return;
+
+ /*
+ * Add it to selection model so it is also selected on the
+ * graph as well that listens to the selection model
+ */
+ selectionModel.addSelection(selectedNode.getUserObject());
+
+ // Show a contextual pop-up menu
+ JPopupMenu menu = menuManager.createContextMenu(workflow,
+ selectedNode.getUserObject(), wfTree.getParent());
+ if (menu == null)
+ menu = new JPopupMenu();
+
+ if (selectedNode.getUserObject() instanceof Workflow) {
+ menu.add(new ShadedLabel("Tree", PURPLISH));
+ // Action to expand the whole tree
+ menu.add(new JMenuItem(new AbstractAction("Expand all",
+ plusIcon) {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ expandAll(tree);
+ }
+ }));
+ // Action to collapse the whole tree
+ menu.add(new JMenuItem(new AbstractAction(
+ "Collapse all", minusIcon) {
+ @Override
+ public void actionPerformed(ActionEvent evt) {
+ collapseAll(tree);
+ }
+ }));
+ }
+
+ menu.show(evt.getComponent(), evt.getX(), evt.getY());
}
}
});
@@ -603,8 +644,9 @@
}
/**
- * Sets the currently selected node(s) based on the workflow selection model, i.e. the node(s)
- * currently selected in the workflow graph view also become selected in the tree view.
+ * Sets the currently selected node(s) based on the workflow selection
+ * model, i.e. the node(s) currently selected in the workflow graph view
+ * also become selected in the tree view.
*/
private void setSelectedNodes(JTree tree, Workflow wf) {
DataflowSelectionModel selectionModel = selectionManager
@@ -612,19 +654,21 @@
// List of all selected objects in the graph view
Set<Object> selection = selectionModel.getSelection();
- if (!selection.isEmpty()) {
- // Selection path(s) - can be multiple if more objects are selected
- int i = selection.size();
- TreePath[] paths = new TreePath[i];
+ if (selection.isEmpty())
+ return;
- for (Object selected : selection) {
- TreePath path = WorkflowExplorerTreeModel.getPathForObject(selected,
- (DefaultMutableTreeNode) tree.getModel().getRoot());
- paths[--i] = path;
- }
- tree.setSelectionPaths(paths);
- tree.scrollPathToVisible(paths[0]);
+ // Selection path(s) - can be multiple if more objects are selected
+ int i = selection.size();
+ TreePath[] paths = new TreePath[i];
+
+ for (Object selected : selection) {
+ TreePath path = WorkflowExplorerTreeModel.getPathForObject(
+ selected, (DefaultMutableTreeNode) tree.getModel()
+ .getRoot());
+ paths[--i] = path;
}
+ tree.setSelectionPaths(paths);
+ tree.scrollPathToVisible(paths[0]);
}
/**
@@ -652,24 +696,23 @@
/**
* Expands all ascendants of a node in the tree.
*/
- @SuppressWarnings("unchecked")
private void expandAscendants(JTree tree, DefaultMutableTreeNode node) {
+ @SuppressWarnings("unchecked")
Enumeration<DefaultMutableTreeNode> children = node.children();
while (children.hasMoreElements()) {
DefaultMutableTreeNode child = children.nextElement();
- if (child.isLeaf()) {
+ if (child.isLeaf())
tree.makeVisible(new TreePath(child.getPath()));
- } else {
+ else
expandAscendants(tree, child);
- }
}
}
/**
* Collapses all direct ascendants of a node in the tree.
*/
- @SuppressWarnings("unchecked")
private void collapseAscendants(JTree tree, DefaultMutableTreeNode node) {
+ @SuppressWarnings("unchecked")
Enumeration<DefaultMutableTreeNode> children = node.children();
while (children.hasMoreElements()) {
DefaultMutableTreeNode child = children.nextElement();
@@ -680,85 +723,99 @@
/**
* Update workflow explorer when current dataflow changes or closes.
- *
*/
- public class FileManagerObserver extends SwingAwareObserver<FileManagerEvent> {
+ public class FileManagerObserver extends
+ SwingAwareObserver<FileManagerEvent> {
@Override
- public void notifySwing(Observable<FileManagerEvent> sender, FileManagerEvent message) {
- if (message instanceof ClosedDataflowEvent) {
- // Remove the closed workflow tree from the map of opened workflow trees
- openedWorkflowsTrees.remove(((ClosedDataflowEvent) message).getDataflow());
+ public void notifySwing(Observable<FileManagerEvent> sender,
+ FileManagerEvent message) {
+ if (message instanceof ClosedDataflowEvent) {
+ /*
+ * Remove the closed workflow tree from the map of opened
+ * workflow trees
+ */
+ openedWorkflowsTrees.remove(((ClosedDataflowEvent) message)
+ .getDataflow());
}
}
}
- private final class SelectionManagerObserver extends SwingAwareObserver<SelectionManagerEvent> {
+ private final class SelectionManagerObserver extends
+ SwingAwareObserver<SelectionManagerEvent> {
@Override
- public void notifySwing(Observable<SelectionManagerEvent> sender, SelectionManagerEvent message) {
+ public void notifySwing(Observable<SelectionManagerEvent> sender,
+ SelectionManagerEvent message) {
if (message instanceof WorkflowBundleSelectionEvent) {
WorkflowBundleSelectionEvent workflowBundleSelectionEvent = (WorkflowBundleSelectionEvent) message;
- WorkflowBundle oldWorkflowBundle = workflowBundleSelectionEvent.getPreviouslySelectedWorkflowBundle();
- WorkflowBundle newWorkflowBundle = workflowBundleSelectionEvent.getSelectedWorkflowBundle();
- Workflow selectedWorkflow = selectionManager.getSelectedWorkflow();
+ WorkflowBundle oldWorkflowBundle = workflowBundleSelectionEvent
+ .getPreviouslySelectedWorkflowBundle();
+ WorkflowBundle newWorkflowBundle = workflowBundleSelectionEvent
+ .getSelectedWorkflowBundle();
+ Workflow selectedWorkflow = selectionManager
+ .getSelectedWorkflow();
- // Remove the workflow selection model listener from the
- // previous (if any) and add to the new workflow (if any)
- if (oldWorkflowBundle != null) {
- selectionManager.getDataflowSelectionModel(oldWorkflowBundle).removeObserver(
+ /*
+ * Remove the workflow selection model listener from the
+ * previous (if any) and add to the new workflow (if any)
+ */
+ if (oldWorkflowBundle != null)
+ selectionManager.getDataflowSelectionModel(
+ oldWorkflowBundle).removeObserver(
workflowSelectionListener);
- }
- if (newWorkflowBundle != null) {
- selectionManager.getDataflowSelectionModel(newWorkflowBundle).addObserver(workflowSelectionListener);
- }
+ if (newWorkflowBundle != null)
+ selectionManager.getDataflowSelectionModel(
+ newWorkflowBundle).addObserver(
+ workflowSelectionListener);
// If the workflow tree has already been created switch to it
- if (openedWorkflowsTrees.containsKey(selectedWorkflow)) {
+ if (openedWorkflowsTrees.containsKey(selectedWorkflow))
switchWorkflowTree(selectedWorkflow);
- } else { // otherwise create a new tree for the workflow
+ else // otherwise create a new tree for the workflow
createWorkflowTree(selectedWorkflow);
- }
} else if (message instanceof WorkflowSelectionEvent) {
WorkflowSelectionEvent workflowSelectionEvent = (WorkflowSelectionEvent) message;
Workflow newWorkflow = workflowSelectionEvent.getSelectedWorkflow();
// If the workflow tree has already been created switch to it
- if (openedWorkflowsTrees.containsKey(newWorkflow)) {
+ if (openedWorkflowsTrees.containsKey(newWorkflow))
switchWorkflowTree(newWorkflow);
- } else { // otherwise create a new tree for the workflow
+ else // otherwise create a new tree for the workflow
createWorkflowTree(newWorkflow);
- }
}
}
}
/**
- * Update workflow tree on edits to the workflow. Gets called when either current workflow is
- * edited or when current workflow is a nested workflow that had been edited and then saved
- * which will trigger update to the parent workflow which is not the current workflow.
- *
+ * Update workflow tree on edits to the workflow. Gets called when either
+ * current workflow is edited or when current workflow is a nested workflow
+ * that had been edited and then saved which will trigger update to the
+ * parent workflow which is not the current workflow.
*/
- public class EditManagerObserver extends SwingAwareObserver<EditManagerEvent> {
+ public class EditManagerObserver extends
+ SwingAwareObserver<EditManagerEvent> {
@Override
- public void notifySwing(Observable<EditManagerEvent> sender, final EditManagerEvent message) {
+ public void notifySwing(Observable<EditManagerEvent> sender,
+ final EditManagerEvent message) {
if (message instanceof AbstractDataflowEditEvent) {
- WorkflowBundle workflowBundle = ((AbstractDataflowEditEvent) message).getDataFlow();
+ WorkflowBundle workflowBundle = ((AbstractDataflowEditEvent) message)
+ .getDataFlow();
// Update the workflow trees to reflect the changes
- for (Workflow workflow : workflowBundle.getWorkflows()) {
- if (openedWorkflowsTrees.containsKey(workflow)) {
+ for (Workflow workflow : workflowBundle.getWorkflows())
+ if (openedWorkflowsTrees.containsKey(workflow))
updateWorkflowTree(workflow);
- }
- }
}
}
}
/**
- * Observes events on workflow Selection Manager, i.e. when a workflow node is selected in the
- * graph view.
+ * Observes events on workflow Selection Manager, i.e. when a workflow node
+ * is selected in the graph view.
*/
- private final class DataflowSelectionListener extends SwingAwareObserver<DataflowSelectionMessage> {
+ private final class DataflowSelectionListener extends
+ SwingAwareObserver<DataflowSelectionMessage> {
@Override
- public void notifySwing(Observable<DataflowSelectionMessage> sender, DataflowSelectionMessage message) {
+ public void notifySwing(Observable<DataflowSelectionMessage> sender,
+ DataflowSelectionMessage message) {
setSelectedNodes(wfTree, workflow);
scrollPane.revalidate();
scrollPane.repaint();
diff --git a/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerFactory.java b/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerFactory.java
index 758722d..255c83c 100644
--- a/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerFactory.java
+++ b/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerFactory.java
@@ -35,12 +35,11 @@
/**
* Workflow Explorer factory.
- *
+ *
* @author Alex Nenadic
* @author David Withers
*/
public class WorkflowExplorerFactory implements UIComponentFactorySPI {
-
private EditManager editManager;
private FileManager fileManager;
private MenuManager menuManager;
@@ -49,15 +48,19 @@
private ActivityIconManager activityIconManager;
private ServiceRegistry serviceRegistry;
+ @Override
public UIComponentSPI getComponent() {
- return new WorkflowExplorer(editManager, fileManager, menuManager, reportManager,
- selectionManager, activityIconManager, serviceRegistry);
+ return new WorkflowExplorer(editManager, fileManager, menuManager,
+ reportManager, selectionManager, activityIconManager,
+ serviceRegistry);
}
+ @Override
public ImageIcon getIcon() {
return null;
}
+ @Override
public String getName() {
return "Workflow Explorer";
}
@@ -89,5 +92,4 @@
public void setServiceRegistry(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
-
}
diff --git a/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeCellRenderer.java b/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeCellRenderer.java
index b5e1d35..a212a69 100644
--- a/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeCellRenderer.java
+++ b/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeCellRenderer.java
@@ -20,6 +20,16 @@
******************************************************************************/
package net.sf.taverna.t2.workbench.ui.workflowexplorer;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.controlLinkIcon;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.datalinkIcon;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.folderClosedIcon;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.folderOpenIcon;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.inputIcon;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.inputPortIcon;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.outputIcon;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.outputPortIcon;
+import static net.sf.taverna.t2.workbench.icons.WorkbenchIcons.workflowExplorerIcon;
+
import java.awt.Component;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@@ -30,9 +40,8 @@
import javax.swing.tree.DefaultTreeCellRenderer;
import net.sf.taverna.t2.lang.ui.icons.Icons;
-import net.sf.taverna.t2.visit.VisitReport.Status;
+//import net.sf.taverna.t2.visit.VisitReport.Status;
import net.sf.taverna.t2.workbench.activityicons.ActivityIconManager;
-import net.sf.taverna.t2.workbench.icons.WorkbenchIcons;
import net.sf.taverna.t2.workbench.report.ReportManager;
import org.apache.commons.beanutils.BeanUtils;
@@ -60,14 +69,19 @@
* @author David Withers
*/
public class WorkflowExplorerTreeCellRenderer extends DefaultTreeCellRenderer {
+ // FIXME This enum is just a workaround
+ enum Status {
+ OK, WARNING, SEVERE
+ }
private static final long serialVersionUID = -1326663036193567147L;
+ private static final String RUNS_AFTER = " runs after ";
private final ActivityIconManager activityIconManager;
- private final String RUNS_AFTER = " runs after ";
-
+ @SuppressWarnings("unused")
private Workflow workflow = null;
+ @SuppressWarnings("unused")
private final ReportManager reportManager;
private Scufl2Tools scufl2Tools = new Scufl2Tools();
@@ -83,9 +97,8 @@
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
boolean expanded, boolean leaf, int row, boolean hasFocus) {
-
- Component result = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
- row, hasFocus);
+ Component result = super.getTreeCellRendererComponent(tree, value, sel,
+ expanded, leaf, row, hasFocus);
Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
// TODO rewrite report manager to use scufl2 validation
@@ -94,109 +107,110 @@
WorkflowExplorerTreeCellRenderer renderer = (WorkflowExplorerTreeCellRenderer) result;
if (userObject instanceof Workflow) { // the root node
- if (!hasGrandChildren((DefaultMutableTreeNode) value)) {
- renderer.setIcon(WorkbenchIcons.workflowExplorerIcon);
- } else {
- renderer.setIcon(chooseIcon(WorkbenchIcons.workflowExplorerIcon, status));
- }
+ if (!hasGrandChildren((DefaultMutableTreeNode) value))
+ renderer.setIcon(workflowExplorerIcon);
+ else
+ renderer.setIcon(chooseIcon(workflowExplorerIcon, status));
renderer.setText(((Workflow) userObject).getName());
} else if (userObject instanceof InputWorkflowPort) {
- renderer.setIcon(chooseIcon(WorkbenchIcons.inputIcon, status));
+ renderer.setIcon(chooseIcon(inputIcon, status));
renderer.setText(((InputWorkflowPort) userObject).getName());
} else if (userObject instanceof OutputWorkflowPort) {
- renderer.setIcon(chooseIcon(WorkbenchIcons.outputIcon, status));
+ renderer.setIcon(chooseIcon(outputIcon, status));
renderer.setText(((OutputWorkflowPort) userObject).getName());
} else if (userObject instanceof Processor) {
Processor p = (Processor) userObject;
- // Get the activity associated with the processor - currently only
- // the first one in the list gets displayed
- List<ProcessorBinding> processorbindings = scufl2Tools.processorBindingsForProcessor(p, p.getParent().getParent().getMainProfile());
+ /*
+ * Get the activity associated with the processor - currently only
+ * the first one in the list gets displayed
+ */
+ List<ProcessorBinding> processorbindings = scufl2Tools
+ .processorBindingsForProcessor(p, p.getParent().getParent()
+ .getMainProfile());
String text = p.getName();
if (!processorbindings.isEmpty()) {
Activity activity = processorbindings.get(0).getBoundActivity();
Icon basicIcon = activityIconManager.iconForActivity(activity);
renderer.setIcon(chooseIcon(basicIcon, status));
- String extraDescription;
try {
- extraDescription = BeanUtils.getProperty(activity, "extraDescription");
+ String extraDescription = BeanUtils.getProperty(activity,
+ "extraDescription");
text += " - " + extraDescription;
- } catch (IllegalAccessException e) {
+ } catch (IllegalAccessException | InvocationTargetException
+ | NoSuchMethodException e) {
// no problem
- } catch (InvocationTargetException e) {
- // no problem
- } catch (NoSuchMethodException e) {
- // no problem;
}
}
renderer.setText(text);
}
// Processor's child input port
else if (userObject instanceof InputProcessorPort) {
- renderer.setIcon(chooseIcon(WorkbenchIcons.inputPortIcon, status));
+ renderer.setIcon(chooseIcon(inputPortIcon, status));
renderer.setText(((InputProcessorPort) userObject).getName());
}
// Processor's child output port
else if (userObject instanceof OutputProcessorPort) {
- renderer.setIcon(chooseIcon(WorkbenchIcons.outputPortIcon, status));
+ renderer.setIcon(chooseIcon(outputPortIcon, status));
renderer.setText(((OutputProcessorPort) userObject).getName());
} else if (userObject instanceof DataLink) {
- renderer.setIcon(chooseIcon(WorkbenchIcons.datalinkIcon, status));
+ renderer.setIcon(chooseIcon(datalinkIcon, status));
SenderPort source = ((DataLink) userObject).getReceivesFrom();
String sourceName = findName(source);
ReceiverPort sink = ((DataLink) userObject).getSendsTo();
String sinkName = findName(sink);
renderer.setText(sourceName + " -> " + sinkName);
} else if (userObject instanceof BlockingControlLink) {
- renderer.setIcon(chooseIcon(WorkbenchIcons.controlLinkIcon, status));
+ renderer.setIcon(chooseIcon(controlLinkIcon, status));
String htmlText = "<html><head></head><body>"
- + ((BlockingControlLink) userObject).getBlock().getName() + " " + RUNS_AFTER + " "
- + ((BlockingControlLink) userObject).getUntilFinished().getName() + "</body></html>";
+ + ((BlockingControlLink) userObject).getBlock().getName()
+ + " "
+ + RUNS_AFTER
+ + " "
+ + ((BlockingControlLink) userObject).getUntilFinished()
+ .getName() + "</body></html>";
renderer.setText(htmlText);
} else {
- // It one of the main container nodes (inputs, outputs,
- // processors, datalinks) or a nested workflow node
- if (expanded) {
- renderer.setIcon(WorkbenchIcons.folderOpenIcon);
- } else {
- renderer.setIcon(WorkbenchIcons.folderClosedIcon);
- }
+ /*
+ * It one of the main container nodes (inputs, outputs, processors,
+ * datalinks) or a nested workflow node
+ */
+ if (expanded)
+ renderer.setIcon(folderOpenIcon);
+ else
+ renderer.setIcon(folderClosedIcon);
}
return result;
}
private static Icon chooseIcon(final Icon basicIcon, Status status) {
- if (status == null) {
+ if (status == null)
return basicIcon;
- }
- if (status == Status.OK) {
+ if (status == Status.OK)
return basicIcon;
- } else if (status == Status.WARNING) {
+ else if (status == Status.WARNING)
return Icons.warningIcon;
- } else if (status == Status.SEVERE) {
+ else if (status == Status.SEVERE)
return Icons.severeIcon;
- }
return basicIcon;
}
private static boolean hasGrandChildren(DefaultMutableTreeNode node) {
int childCount = node.getChildCount();
- for (int i = 0; i < childCount; i++) {
- if (node.getChildAt(i).getChildCount() > 0) {
+ for (int i = 0; i < childCount; i++)
+ if (node.getChildAt(i).getChildCount() > 0)
return true;
- }
- }
return false;
}
private String findName(Port port) {
if (port instanceof ProcessorPort) {
- String sourceProcessorName = ((ProcessorPort) port).getParent().getName();
+ String sourceProcessorName = ((ProcessorPort) port).getParent()
+ .getName();
return sourceProcessorName + ":" + port.getName();
- } else {
- return port.getName();
}
+ return port.getName();
}
}
diff --git a/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeModel.java b/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeModel.java
index ff62d9e..05255a4 100644
--- a/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeModel.java
+++ b/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeModel.java
@@ -20,8 +20,6 @@
******************************************************************************/
package net.sf.taverna.t2.workbench.ui.workflowexplorer;
-import java.util.Set;
-
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
@@ -42,8 +40,8 @@
* representing the workflow inputs, outputs, services (processors), dataLinks,
* controlLinks.
* <p>
- * A service node can contain a nested workflow if it contains an activity of
- * of type DataflowActivity. In this case, the service node will have 3 children:
+ * A service node can contain a nested workflow if it contains an activity of of
+ * type DataflowActivity. In this case, the service node will have 3 children:
* the input and output of the DataflowActivity and the workflow node itself
* (containing the nested workflow being wrapped inside the DataflowActivity).
* The structure of the workflow node sub-tree (the tree whose root is the
@@ -52,16 +50,13 @@
* and have only the processor's input and output ports as children.
* <p>
* Input, output, data link and control link nodes are leaves.
- *
+ *
* @author Alex Nenadic
* @author Stian Soiland-Reyes
* @author David Withers
*/
public class WorkflowExplorerTreeModel extends DefaultTreeModel{
-
-
private static final long serialVersionUID = -2327461863858923772L;
-
public static final String INPUTS = "Workflow input ports";
public static final String OUTPUTS = "Workflow output ports";
public static final String PROCESSORS = "Services";
@@ -69,13 +64,13 @@
public static final String CONTROLLINKS = "Control links";
public static final String MERGES = "Merges";
+ @SuppressWarnings("unused")
private Scufl2Tools scufl2Tools = new Scufl2Tools();
/* Root of the tree. */
private DefaultMutableTreeNode rootNode;
- public WorkflowExplorerTreeModel(Workflow df){
-
+ public WorkflowExplorerTreeModel(Workflow df) {
super(new DefaultMutableTreeNode(df)); // root node contains the whole workflow
rootNode = (DefaultMutableTreeNode) this.getRoot();
createTree(df, rootNode);
@@ -85,7 +80,6 @@
* Creates the tree model from a given workflow, for a given tree root.
*/
private void createTree(Workflow df, DefaultMutableTreeNode root) {
-
// Create the four main node groups - inputs, outputs,
// services, data links, control links and merges.
DefaultMutableTreeNode inputs = new DefaultMutableTreeNode(INPUTS);
@@ -102,74 +96,73 @@
root.add(controllinks);
// Populate the workflow's inputs.
- NamedSet<InputWorkflowPort> inputsList = df.getInputPorts();
- for (InputWorkflowPort dataflowInput : inputsList) {
+ for (InputWorkflowPort dataflowInput : df.getInputPorts())
inputs.add(new DefaultMutableTreeNode(dataflowInput));
- }
// Populate the workflow's outputs.
- NamedSet<OutputWorkflowPort> outputsList = df.getOutputPorts();
- for (OutputWorkflowPort dataflowOutput : outputsList) {
+ for (OutputWorkflowPort dataflowOutput : df.getOutputPorts())
outputs.add(new DefaultMutableTreeNode(dataflowOutput));
- }
- // Populate the workflow's processors (which in turn can contain a nested workflow).
+ /*
+ * Populate the workflow's processors (which in turn can contain a
+ * nested workflow).
+ */
NamedSet<Processor> processorsList = df.getProcessors();
- for (Processor processor : processorsList){
+ for (Processor processor : processorsList) {
DefaultMutableTreeNode processorNode = new DefaultMutableTreeNode(
processor);
services.add(processorNode);
// A processor node can have children (input and output ports).
- NamedSet<InputProcessorPort> inputPorts = processor.getInputPorts();
- for (InputProcessorPort inputPort : inputPorts) {
+ for (InputProcessorPort inputPort : processor.getInputPorts())
processorNode.add(new DefaultMutableTreeNode(inputPort));
- }
- NamedSet<OutputProcessorPort> outputPorts = processor.getOutputPorts();
- for (OutputProcessorPort outputPort : outputPorts) {
+ for (OutputProcessorPort outputPort : processor.getOutputPorts())
processorNode.add(new DefaultMutableTreeNode(outputPort));
- }
-
}
// Populate the workflow's data links.
- Set<DataLink> datalinksList = df.getDataLinks();
- for (DataLink datalink: datalinksList) {
+ for (DataLink datalink: df.getDataLinks())
datalinks.add(new DefaultMutableTreeNode(datalink));
- }
// Populate the workflow's control links.
- Set<ControlLink> controlLinksList = df.getControlLinks();
- for (ControlLink controlLink : controlLinksList) {
+ for (ControlLink controlLink : df.getControlLinks())
controllinks.add(new DefaultMutableTreeNode(controlLink));
- }
-
}
- /**
- * Returns a path from the root to the node containing the object. For a nested workflow,
- * only a path for the DataflowActivity and its input and output ports is returned - for all other
- * nested workflow objects we return null as we do not want them to be selection in the tree.
- */
- public static TreePath getPathForObject(Object userObject, DefaultMutableTreeNode root){
+ private static final int INPUT_IDX = 0;
+ private static final int OUTPUT_IDX = 1;
+ private static final int PROCESSOR_IDX = 2;
+ private static final int DATA_IDX = 3;
+ private static final int CONTROL_IDX = 4;
- if (userObject instanceof Workflow){ // node contains a Dataflow object
- if (root.getUserObject().equals(userObject)){ // is it the root of the tree?
+ /**
+ * Returns a path from the root to the node containing the object. For a
+ * nested workflow, only a path for the DataflowActivity and its input and
+ * output ports is returned - for all other nested workflow objects we
+ * return null as we do not want them to be selection in the tree.
+ */
+ public static TreePath getPathForObject(Object userObject,
+ DefaultMutableTreeNode root) {
+ if (userObject instanceof Workflow) { // node contains a Dataflow object
+ if (root.getUserObject().equals(userObject)) // is it the root of the tree?
return new TreePath(root.getPath());
- }
- }
- else if (userObject instanceof InputWorkflowPort){
+ } else if (userObject instanceof InputWorkflowPort) {
// Get the root inputs node
- DefaultMutableTreeNode inputs = (DefaultMutableTreeNode) root.getChildAt(0);
- for (int i = 0; i< inputs.getChildCount(); i++){
- DefaultMutableTreeNode node = (DefaultMutableTreeNode) inputs.getChildAt(i);
- if (node.getUserObject().equals(userObject)){
+ DefaultMutableTreeNode inputs = (DefaultMutableTreeNode) root
+ .getChildAt(INPUT_IDX);
+ for (int i = 0; i < inputs.getChildCount(); i++) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) inputs
+ .getChildAt(i);
+ if (node.getUserObject().equals(userObject))
return new TreePath(node.getPath());
- }
}
- // The node we are looking for must be under some nested workflow then - but
- // we do not want to let the user select a node under a nested workflow so return here
+ /*
+ * The node we are looking for must be under some nested workflow
+ * then - but we do not want to let the user select a node under a
+ * nested workflow so return here
+ */
return null;
+
/*DefaultMutableTreeNode processors = (DefaultMutableTreeNode) root.getChildAt(2);
for (int i = 0; i < processors.getChildCount(); i++){
DefaultMutableTreeNode processor = (DefaultMutableTreeNode) processors.getChildAt(i);
@@ -183,19 +176,23 @@
return tp;
}
}*/
- }
- else if (userObject instanceof OutputWorkflowPort){
+ } else if (userObject instanceof OutputWorkflowPort) {
// Get the root outputs node
- DefaultMutableTreeNode outputs = (DefaultMutableTreeNode) root.getChildAt(1);
- for (int i = 0; i< outputs.getChildCount(); i++){ // loop through the outputs
- DefaultMutableTreeNode node = (DefaultMutableTreeNode) outputs.getChildAt(i);
- if (node.getUserObject().equals(userObject)){
+ DefaultMutableTreeNode outputs = (DefaultMutableTreeNode) root
+ .getChildAt(OUTPUT_IDX);
+ for (int i = 0; i< outputs.getChildCount(); i++) { // loop through the outputs
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) outputs
+ .getChildAt(i);
+ if (node.getUserObject().equals(userObject))
return new TreePath(node.getPath());
- }
}
- // The node we are looking for must be under some nested workflow then - but
- // we do not want to let the user select a node under a nested workflow so return here
+ /*
+ * The node we are looking for must be under some nested workflow
+ * then - but we do not want to let the user select a node under a
+ * nested workflow so return here
+ */
return null;
+
/*DefaultMutableTreeNode processors = (DefaultMutableTreeNode) root.getChildAt(2);
for (int i = 0; i < processors.getChildCount(); i++){
DefaultMutableTreeNode processor = (DefaultMutableTreeNode) processors.getChildAt(i);
@@ -207,21 +204,25 @@
TreePath tp = getPathForObject(userObject, nestedWorkflowNode);
if (tp != null)
return tp;
- }
- }*/
- }
- else if (userObject instanceof Processor){
- // Get the root services (processors) node
- DefaultMutableTreeNode processors = (DefaultMutableTreeNode) root.getChildAt(2);
- for (int i = 0; i< processors.getChildCount(); i++){
- DefaultMutableTreeNode node = (DefaultMutableTreeNode) processors.getChildAt(i);
- if (node.getUserObject().equals(userObject)){
- return new TreePath(node.getPath());
}
+ }*/
+ } else if (userObject instanceof Processor) {
+ // Get the root services (processors) node
+ DefaultMutableTreeNode processors = (DefaultMutableTreeNode) root
+ .getChildAt(PROCESSOR_IDX);
+ for (int i = 0; i < processors.getChildCount(); i++) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) processors
+ .getChildAt(i);
+ if (node.getUserObject().equals(userObject))
+ return new TreePath(node.getPath());
}
- // The node we are looking for must be under some nested workflow then - but
- // we do not want to let the user select a node under a nested workflow so return here
+ /*
+ * The node we are looking for must be under some nested workflow
+ * then - but we do not want to let the user select a node under a
+ * nested workflow so return here
+ */
return null;
+
/*for (int i = 0; i < processors.getChildCount(); i++){
DefaultMutableTreeNode processor = (DefaultMutableTreeNode) processors.getChildAt(i);
// If this is a nested workflow - descend into it
@@ -232,19 +233,24 @@
TreePath tp = getPathForObject(userObject, nestedWorkflowNode);
if (tp != null)
return tp;
- }
+ }
}*/
- }
- else if (userObject instanceof InputProcessorPort){
+ } else if (userObject instanceof InputProcessorPort) {
// This is an input port of a processor
// Get the root processors node
- DefaultMutableTreeNode processors = (DefaultMutableTreeNode) root.getChildAt(2);
- for (int i = processors.getChildCount() - 1; i >= 0 ; i--){
+ DefaultMutableTreeNode processors = (DefaultMutableTreeNode) root
+ .getChildAt(PROCESSOR_IDX);
+ for (int i = processors.getChildCount() - 1; i >= 0; i--) {
// Looping backwards so that nested workflows are checked last
- DefaultMutableTreeNode processor = (DefaultMutableTreeNode) processors.getChildAt(i);
+ DefaultMutableTreeNode processor = (DefaultMutableTreeNode) processors
+ .getChildAt(i);
- // We actually do not want to check nested workflows as we do not want the user
- // to be able to select a component of a nested workflow
+ /*
+ * We actually do not want to check nested workflows as we do
+ * not want the user to be able to select a component of a
+ * nested workflow
+ */
+
/*
// If this is nested workflow - descend into it
if (Tools.containsNestedWorkflow((Processor) processor.getUserObject())){
@@ -253,44 +259,48 @@
for (int j = 0; j < processor.getChildCount()-1; j++){
DefaultMutableTreeNode port_node = (DefaultMutableTreeNode) processor.getChildAt(j);
if ((port_node.getUserObject() instanceof ActivityInputPort) &&
- (((ActivityInputPort) port_node.getUserObject()).equals(userObject))){
+ (((ActivityInputPort) port_node.getUserObject()).equals(userObject)))
return new TreePath(port_node.getPath());
- }
}
// Get the nested workflow node - it is always the last child of the
// wrapping processor's node
DefaultMutableTreeNode nestedWorkflowNode = (DefaultMutableTreeNode) processor.getLastChild();
TreePath tp = getPathForObject(userObject, nestedWorkflowNode);
- if ( tp != null){
+ if (tp != null)
return tp;
- }
- }
- else { */
- // This is not a nested workflow, so loop
- // thought the processor's input and output ports,
- // and see if there is a matching input port
- for (int j = 0; j < processor.getChildCount(); j++){
- DefaultMutableTreeNode port_node = (DefaultMutableTreeNode) processor.getChildAt(j);
- if ((port_node.getUserObject() instanceof InputProcessorPort) &&
- (((InputProcessorPort) port_node.getUserObject()).equals(userObject))){
+ } else */
+ /*
+ * This is not a nested workflow, so loop thought the
+ * processor's input and output ports, and see if there is a
+ * matching input port
+ */
+ for (int j = 0; j < processor.getChildCount(); j++) {
+ DefaultMutableTreeNode port_node = (DefaultMutableTreeNode) processor
+ .getChildAt(j);
+ if ((port_node.getUserObject() instanceof InputProcessorPort)
+ && (((InputProcessorPort) port_node
+ .getUserObject()).equals(userObject)))
return new TreePath(port_node.getPath());
- }
}
- //}
}
return null; // The node is inside a nested workflow so just return here
- }
- else if (userObject instanceof OutputProcessorPort){
+ } else if (userObject instanceof OutputProcessorPort) {
// This is an output port of a processor (i.e. of its associated activity)
// Get the root processors node
- DefaultMutableTreeNode processors = (DefaultMutableTreeNode) root.getChildAt(2);
+ DefaultMutableTreeNode processors = (DefaultMutableTreeNode) root
+ .getChildAt(PROCESSOR_IDX);
for (int i = processors.getChildCount() - 1; i >= 0 ; i--){
// Looping backwards so that nested workflows are checked last
- DefaultMutableTreeNode processor = (DefaultMutableTreeNode) processors.getChildAt(i);
+ DefaultMutableTreeNode processor = (DefaultMutableTreeNode) processors
+ .getChildAt(i);
- // We actually do not want to check nested workflows as we do not want the user
- // to be able to select a component of a nested workflow
+ /*
+ * We actually do not want to check nested workflows as we do
+ * not want the user to be able to select a component of a
+ * nested workflow
+ */
+
/*
// If this is nested workflow - descend into it
if (Tools.containsNestedWorkflow((Processor) processor.getUserObject())){
@@ -299,47 +309,51 @@
for (int j = 0; j < processor.getChildCount()-1; j++){
DefaultMutableTreeNode port_node = (DefaultMutableTreeNode) processor.getChildAt(j);
if ((port_node.getUserObject() instanceof ActivityOutputPortImpl) &&
- (((ActivityOutputPortImpl) port_node.getUserObject()).equals(userObject))){
+ (((ActivityOutputPortImpl) port_node.getUserObject()).equals(userObject)))
return new TreePath(port_node.getPath());
- }
}
// Get the nested workflow node - it is always the last child of the
// wrapping processor's node
DefaultMutableTreeNode nestedWorkflowNode = (DefaultMutableTreeNode) processor.getLastChild();
TreePath tp = getPathForObject(userObject, nestedWorkflowNode);
- if ( tp != null){
+ if (tp != null)
return tp;
+ } else */
+ {
+ /*
+ * This is not a nested workflow, so loop thought the
+ * processor's input and output ports, and see if there is a
+ * matching output port
+ */
+ for (int j = 0; j < processor.getChildCount(); j++) {
+ DefaultMutableTreeNode port_node = (DefaultMutableTreeNode) processor
+ .getChildAt(j);
+ if ((port_node.getUserObject() instanceof OutputProcessorPort)
+ && (((OutputProcessorPort) port_node
+ .getUserObject()).equals(userObject)))
+ return new TreePath(port_node.getPath());
}
}
- else { */
- // This is not a nested workflow, so loop
- // thought the processor's input and output ports,
- // and see if there is a matching output port
- for (int j = 0; j < processor.getChildCount(); j++){
-
- DefaultMutableTreeNode port_node = (DefaultMutableTreeNode) processor.getChildAt(j);
- if ((port_node.getUserObject() instanceof OutputProcessorPort) &&
- (((OutputProcessorPort) port_node.getUserObject()).equals(userObject))){
- return new TreePath(port_node.getPath());
- }
- }
- //}
}
return null; // The node is inside a nested workflow so just return here
- }
- else if (userObject instanceof DataLink){
+ } else if (userObject instanceof DataLink) {
// Get the root data links node
- DefaultMutableTreeNode datalinks = (DefaultMutableTreeNode) root.getChildAt(3);
- for (int i = 0; i< datalinks.getChildCount(); i++){
- DefaultMutableTreeNode node = (DefaultMutableTreeNode) datalinks.getChildAt(i);
- if (node.getUserObject().equals(userObject)){
+ DefaultMutableTreeNode datalinks = (DefaultMutableTreeNode) root
+ .getChildAt(DATA_IDX);
+ for (int i = 0; i < datalinks.getChildCount(); i++) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) datalinks
+ .getChildAt(i);
+ if (node.getUserObject().equals(userObject))
return new TreePath(node.getPath());
- }
}
- // The node we are looking for must be under some nested workflow then - but
- // we do not want to let the user select a node under a nested workflow so return here
+ /*
+ * The node we are looking for must be under some nested workflow
+ * then - but we do not want to let the user select a node under a
+ * nested workflow so return here
+ */
return null;
+
/*DefaultMutableTreeNode processors = (DefaultMutableTreeNode) root.getChildAt(2);
for (int i = 0; i < processors.getChildCount(); i++){
DefaultMutableTreeNode processor = (DefaultMutableTreeNode) processors.getChildAt(i);
@@ -353,19 +367,23 @@
return tp;
}
}*/
- }
- else if (userObject instanceof ControlLink){
+ } else if (userObject instanceof ControlLink) {
// Get the root control links node
- DefaultMutableTreeNode controllinks = (DefaultMutableTreeNode) root.getChildAt(4);
- for (int i = 0; i< controllinks.getChildCount(); i++){
- DefaultMutableTreeNode node = (DefaultMutableTreeNode) controllinks.getChildAt(i);
- if (node.getUserObject().equals(userObject)){
+ DefaultMutableTreeNode controllinks = (DefaultMutableTreeNode) root
+ .getChildAt(CONTROL_IDX);
+ for (int i = 0; i < controllinks.getChildCount(); i++) {
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) controllinks
+ .getChildAt(i);
+ if (node.getUserObject().equals(userObject))
return new TreePath(node.getPath());
- }
}
- // The node we are looking for must be under some nested workflow then - but
- // we do not want to let the user select a node under a nested workflow so return here
+ /*
+ * The node we are looking for must be under some nested workflow
+ * then - but we do not want to let the user select a node under a
+ * nested workflow so return here
+ */
return null;
+
/*DefaultMutableTreeNode processors = (DefaultMutableTreeNode) root.getChildAt(2);
for (int i = 0; i < processors.getChildCount(); i++){
DefaultMutableTreeNode processor = (DefaultMutableTreeNode) processors.getChildAt(i);
@@ -383,5 +401,4 @@
return null;
}
-
}
diff --git a/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeSelectionModel.java b/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeSelectionModel.java
index b3a3dd5..f9c9455 100644
--- a/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeSelectionModel.java
+++ b/workflow-explorer/src/main/java/net/sf/taverna/t2/workbench/ui/workflowexplorer/WorkflowExplorerTreeSelectionModel.java
@@ -23,23 +23,23 @@
import javax.swing.tree.DefaultTreeSelectionModel;
import javax.swing.tree.TreePath;
-public class WorkflowExplorerTreeSelectionModel extends DefaultTreeSelectionModel{
-
+public class WorkflowExplorerTreeSelectionModel extends
+ DefaultTreeSelectionModel {
private static final long serialVersionUID = 3127644524735089630L;
-
- public WorkflowExplorerTreeSelectionModel(){
+
+ public WorkflowExplorerTreeSelectionModel() {
super();
}
-
+
@Override
- public void setSelectionPath(TreePath path){
- // Nothing happens here - only calls to mySetSelectionPath()
- // will have the effect of a node being selected
+ public void setSelectionPath(TreePath path) {
+ /*
+ * Nothing happens here - only calls to mySetSelectionPath() will have
+ * the effect of a node being selected
+ */
}
-
- public void mySetSelectionPath(TreePath path){
+
+ public void mySetSelectionPath(TreePath path) {
super.setSelectionPath(path);
}
-
-
}