summaryrefslogtreecommitdiff
path: root/src/main/java/org/cristalise/gui/tree
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-10-07 09:18:33 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-10-07 09:18:33 +0200
commit5e4034b5cba89460a62fa958fc78c2b85acb3d5f (patch)
treeaa8e32f014801459ad65acdf45eee70d16008fe6 /src/main/java/org/cristalise/gui/tree
parenta5a9d90ec6714ad6a9358c35ca7093e5868373f7 (diff)
Repackage to org.cristalise
Diffstat (limited to 'src/main/java/org/cristalise/gui/tree')
-rw-r--r--src/main/java/org/cristalise/gui/tree/Node.java252
-rw-r--r--src/main/java/org/cristalise/gui/tree/NodeAgent.java33
-rw-r--r--src/main/java/org/cristalise/gui/tree/NodeCollection.java144
-rw-r--r--src/main/java/org/cristalise/gui/tree/NodeContext.java66
-rw-r--r--src/main/java/org/cristalise/gui/tree/NodeItem.java241
-rw-r--r--src/main/java/org/cristalise/gui/tree/NodeRole.java34
-rw-r--r--src/main/java/org/cristalise/gui/tree/NodeSubscriber.java13
-rw-r--r--src/main/java/org/cristalise/gui/tree/NodeTransferHandler.java74
8 files changed, 857 insertions, 0 deletions
diff --git a/src/main/java/org/cristalise/gui/tree/Node.java b/src/main/java/org/cristalise/gui/tree/Node.java
new file mode 100644
index 0000000..4ef3942
--- /dev/null
+++ b/src/main/java/org/cristalise/gui/tree/Node.java
@@ -0,0 +1,252 @@
+package org.cristalise.gui.tree;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import org.cristalise.gui.DynamicTreeBuilder;
+import org.cristalise.gui.ImageLoader;
+import org.cristalise.gui.ItemTabManager;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.lookup.AgentPath;
+import org.cristalise.kernel.lookup.ItemPath;
+import org.cristalise.kernel.lookup.Path;
+import org.cristalise.kernel.lookup.RolePath;
+import org.cristalise.kernel.process.Gateway;
+import org.cristalise.kernel.utils.Language;
+import org.cristalise.kernel.utils.Logger;
+
+
+public abstract class Node implements Runnable {
+
+ protected Path binding;
+ protected DefaultMutableTreeNode treeNode;
+ protected String name; // domain key
+ protected ItemPath itemPath; // target item
+ // attributes
+ protected String type = "";
+ protected String toolTip = null;
+ protected Icon icon;
+ protected boolean isExpandable = false;
+ protected HashMap<Path, Node> childNodes = new HashMap<Path, Node>();
+ protected ArrayList<NodeSubscriber> subscribers = new ArrayList<NodeSubscriber>();
+ protected DynamicTreeBuilder loader = null;
+ private boolean loaded = false;
+ private String iconName;
+ protected ItemTabManager desktop;
+ static ImageIcon folder = ImageLoader.findImage("folder.png");
+ static ImageIcon emptyLeaf = ImageLoader.findImage("leaf.png");
+
+ public Node(ItemTabManager desktop) {
+ this.desktop = desktop;
+ }
+
+ protected void createTreeNode() {
+ this.treeNode = new DefaultMutableTreeNode(this);
+ }
+
+ public Node(Path path, ItemTabManager desktop) {
+ this.binding = path;
+ this.desktop = desktop;
+ try {
+ this.itemPath = path.getItemPath();
+ } catch (ObjectNotFoundException e) { }
+ // get the name of this node (last path element)
+ String[] pathComponents = path.getPath();
+ if (pathComponents.length > 0)
+ this.name = pathComponents[pathComponents.length-1];
+ else
+ this.name = Gateway.getProperties().getProperty("Name");
+ }
+
+ public ItemTabManager getDesktop() {
+ return desktop;
+ }
+
+ public Node newNode(Path path)
+ {
+ try {
+ if (path.getItemPath() instanceof AgentPath)
+ return new NodeAgent(path, desktop);
+ else
+ return new NodeItem(path, desktop);
+ } catch (ObjectNotFoundException ex) {
+ if (path instanceof RolePath)
+ return new NodeRole(path, desktop);
+ return new NodeContext(path, desktop);
+ }
+
+ }
+
+ /** Inserts a tree builder as the first child of the node, so it can be opened in the tree
+ */
+ public void makeExpandable() {
+ if (isExpandable) return;
+ loader = new DynamicTreeBuilder(this.treeNode, desktop);
+ this.treeNode.insert(loader.getTreeNode(),0);
+ isExpandable = true;
+ }
+
+
+ public DefaultMutableTreeNode getTreeNode() {
+ return treeNode;
+ }
+
+ public void setTreeNode(DefaultMutableTreeNode treeNode) {
+ this.treeNode = treeNode;
+ treeNode.setUserObject(this);
+ }
+
+ /** Subscription for loading node children.
+ * Note this is separate from the itemproxy subscription as it included query of the naming service
+ * and eventually should not require access to the item at all for higher performance */
+ public void subscribeNode(NodeSubscriber target) {
+ subscribers.add(target);
+ if (loaded == false) {
+ loaded = true;
+ loadMore();
+ }
+ else {
+ synchronized (childNodes) {
+ Node newNode;
+ for (Iterator<Node> nodes = childNodes.values().iterator(); nodes.hasNext();) {
+ newNode = nodes.next();
+ Logger.msg("subscribeNode target.add("+newNode.name+")");
+ target.add(newNode);
+ }
+ }
+ }
+ }
+
+ public void loadMore() {
+ Thread loading = new Thread(this);
+ loading.start();
+ }
+
+ public void unsubscribeNode(NodeSubscriber target) {
+ subscribers.remove(target);
+ }
+
+ public void add(Node newNode) {
+ synchronized(childNodes) {
+ childNodes.put(newNode.getPath(), newNode);
+ for (NodeSubscriber thisSub : subscribers) {
+ thisSub.add(newNode);
+ }
+ }
+ }
+
+ public void remove(Path oldPath) {
+ synchronized(childNodes) {
+ childNodes.remove(oldPath);
+ for (NodeSubscriber thisSub : subscribers) {
+ thisSub.remove(oldPath);
+ }
+ }
+ }
+
+ public void removeAllChildren() {
+ synchronized(childNodes) {
+ while (childNodes.keySet().iterator().hasNext()) {
+ remove(childNodes.keySet().iterator().next());
+ }
+ }
+ }
+
+ public Node getChildNode(Path itsPath) {
+ for (Iterator<Path> i = childNodes.keySet().iterator(); i.hasNext();) {
+ Object next = i.next();
+ if ( next.equals(itsPath) ) return childNodes.get(next);
+ }
+ return null;
+ }
+
+ // end of current batch
+ public void end(boolean more) {
+ for (NodeSubscriber thisSub : subscribers) {
+ thisSub.end(more);
+ }
+ }
+
+
+ @Override
+ public void run() {
+ Thread.currentThread().setName("Node Loader: "+name);
+ loadChildren();
+ }
+
+ public abstract void loadChildren();
+
+ public void refresh() {
+ removeAllChildren();
+ loadChildren();
+ }
+
+ // Getters and Setters
+
+ public ItemPath getItemPath() { return itemPath; }
+// public void setSysKey( int sysKey ) { this.sysKey = sysKey; }
+
+ public String getName() { return name; }
+// public void setName( String name ) { this.name = name; }
+
+ public String getType() { return type; }
+// public void setType( String type ) { this.type = type; }
+
+ public Path getPath() { return binding; }
+
+ public DynamicTreeBuilder getTreeBuilder() { return loader; }
+
+ @Override
+ public String toString() {
+ if (this.name.length() > 0) {
+ return this.name;
+ }
+ else { return "Cristal"; }
+ }
+
+ public Icon getIcon() {
+ if (icon != null) return icon;
+ return(isExpandable?folder:emptyLeaf);
+ }
+
+ public String getIconName() {
+ return iconName;
+ }
+
+ public void setIcon(String icon) {
+ iconName = icon;
+ this.icon = ImageLoader.findImage("typeicons/"+icon+"_16.png");
+ if (this.icon==ImageLoader.nullImg) this.icon = ImageLoader.findImage("typeicons/item_16.png");
+ }
+
+ public JPopupMenu getPopupMenu() {
+ JPopupMenu popup = new JPopupMenu();
+ JMenuItem menuItem = new JMenuItem(Language.translate("Refresh"));
+ menuItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (isExpandable) refresh();
+ }
+ });
+ popup.add(menuItem);
+ return popup;
+ }
+
+ public String getToolTip() {
+ if (toolTip != null && toolTip.length()>0)
+ return toolTip;
+ else
+ return type;
+ }
+
+ public void setToolTip(String tip) {
+ this.toolTip = tip;
+ }}
diff --git a/src/main/java/org/cristalise/gui/tree/NodeAgent.java b/src/main/java/org/cristalise/gui/tree/NodeAgent.java
new file mode 100644
index 0000000..b070c5d
--- /dev/null
+++ b/src/main/java/org/cristalise/gui/tree/NodeAgent.java
@@ -0,0 +1,33 @@
+
+package org.cristalise.gui.tree;
+
+
+import java.util.ArrayList;
+
+import org.cristalise.gui.ItemTabManager;
+import org.cristalise.kernel.lookup.Path;
+
+
+/**
+ * Structure for Item presence on the tree and ItemDetails boxes. Created by NodeFactory.
+ * @author $Author: abranson $
+ * @version $Version$
+ */
+public class NodeAgent extends NodeItem {
+
+ public NodeAgent(Path path, ItemTabManager desktop) {
+ super(path, desktop);
+ }
+
+ @Override
+ public void loadChildren() {
+ }
+
+ @Override
+ public ArrayList<String> getTabs() {
+
+ ArrayList<String> requiredTabs = super.getTabs();
+ requiredTabs.add("JobList");
+ return requiredTabs;
+ }
+}
diff --git a/src/main/java/org/cristalise/gui/tree/NodeCollection.java b/src/main/java/org/cristalise/gui/tree/NodeCollection.java
new file mode 100644
index 0000000..3a8643a
--- /dev/null
+++ b/src/main/java/org/cristalise/gui/tree/NodeCollection.java
@@ -0,0 +1,144 @@
+package org.cristalise.gui.tree;
+
+import java.util.ArrayList;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import org.cristalise.gui.ItemTabManager;
+import org.cristalise.gui.MainFrame;
+import org.cristalise.kernel.collection.Collection;
+import org.cristalise.kernel.collection.CollectionMember;
+import org.cristalise.kernel.collection.Dependency;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.entity.proxy.ItemProxy;
+import org.cristalise.kernel.entity.proxy.MemberSubscription;
+import org.cristalise.kernel.entity.proxy.ProxyObserver;
+import org.cristalise.kernel.lookup.ItemPath;
+import org.cristalise.kernel.lookup.Path;
+import org.cristalise.kernel.persistency.ClusterStorage;
+import org.cristalise.kernel.utils.CastorHashMap;
+import org.cristalise.kernel.utils.KeyValuePair;
+import org.cristalise.kernel.utils.Logger;
+
+
+public class NodeCollection extends Node implements ProxyObserver<Collection<? extends CollectionMember>> {
+
+ ItemProxy parent;
+ Collection<? extends CollectionMember> thisCollection;
+ String path;
+
+ public NodeCollection(ItemProxy parent, String name, ItemTabManager desktop) {
+ super(desktop);
+ this.parent = parent;
+ this.name = name;
+ this.path = parent.getPath()+"/"+ClusterStorage.COLLECTION+"/"+name+"/last";
+ createTreeNode();
+ this.makeExpandable();
+ }
+
+ public NodeCollection(ItemProxy parent, Collection<? extends CollectionMember> coll, ItemTabManager desktop) {
+ super(desktop);
+ this.parent = parent;
+ this.name = coll.getName();
+ this.path = parent.getPath()+"/"+ClusterStorage.COLLECTION+"/"+name+"/last";
+ createTreeNode();
+ this.makeExpandable();
+ add(coll);
+ }
+
+ @Override
+ public void loadChildren() {
+ Logger.msg(8, "NodeCollection::loadChildren()");
+ try {
+ if (thisCollection == null) {
+ Collection<? extends CollectionMember> initColl = (Collection<? extends CollectionMember>)parent.getObject(ClusterStorage.COLLECTION+"/"+name+"/last");
+ add(initColl);
+ }
+ parent.subscribe(new MemberSubscription<Collection<? extends CollectionMember>>(this, ClusterStorage.COLLECTION, false));
+ } catch (ObjectNotFoundException ex) {
+ end(false);
+ return;
+ }
+ }
+
+ @Override
+ public void add(Collection<? extends CollectionMember> contents) {
+ if (!contents.getName().equals(name)) return;
+ this.type = contents.getClass().getSimpleName();
+ ArrayList<? extends CollectionMember> newMembers = contents.getMembers().list;
+ ArrayList<? extends CollectionMember> oldMembers;
+ if (thisCollection == null)
+ oldMembers = new ArrayList<CollectionMember>();
+ else
+ oldMembers = thisCollection.getMembers().list;
+
+ ArrayList<Path> currentPaths = new ArrayList<Path>();
+ // add any missing paths
+ for (CollectionMember newMember : newMembers) {
+ ItemPath itemPath = newMember.getItemPath();
+ if (!oldMembers.contains(newMember) && itemPath != null) {
+ currentPaths.add(itemPath);
+ NodeItem newMemberNode = new NodeItem(itemPath, desktop);
+ newMemberNode.setCollection(contents, newMember.getID(), parent);
+ newMemberNode.setToolTip(getPropertyToolTip(newMember.getProperties()));
+ add(newMemberNode);
+ }
+ }
+ // remove those no longer present
+ for (Path childPath : childNodes.keySet()) {
+ if (!currentPaths.contains(childPath)) {
+ remove(childPath);
+ }
+
+ }
+
+ thisCollection = contents;
+ if (isDependency())
+ setToolTip(getPropertyToolTip(((Dependency)contents).getProperties()));
+ end(false);
+ }
+
+ public boolean addMember(ItemPath itemPath) {
+ if (!isDependency()) return false;
+ String[] params = { thisCollection.getName(), itemPath.getUUID().toString() };
+ try {
+ MainFrame.userAgent.execute(parent, "AddMemberToCollection", params);
+ return true;
+ } catch (Exception e1) {
+ MainFrame.exceptionDialog(e1);
+ return false;
+ }
+ }
+
+ public static String getPropertyToolTip(CastorHashMap props) {
+ if (props.size() == 0) return null;
+ StringBuffer verStr = new StringBuffer("<html>");
+ for (KeyValuePair prop : props.getKeyValuePairs()) {
+ verStr.append("<b>").append(prop.getKey()).append(":</b> ").append(prop.getValue()).append("<br/>");
+ }
+ return verStr.append("</html>").toString();
+ }
+
+ @Override
+ public DefaultMutableTreeNode getTreeNode() {
+ return treeNode;
+ }
+
+
+
+ @Override
+ public void remove(String id) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void control(String control, String msg) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean isDependency() {
+ return thisCollection instanceof Dependency;
+ }
+}
diff --git a/src/main/java/org/cristalise/gui/tree/NodeContext.java b/src/main/java/org/cristalise/gui/tree/NodeContext.java
new file mode 100644
index 0000000..97252c7
--- /dev/null
+++ b/src/main/java/org/cristalise/gui/tree/NodeContext.java
@@ -0,0 +1,66 @@
+package org.cristalise.gui.tree;
+
+import java.util.Iterator;
+
+import org.cristalise.gui.ItemTabManager;
+import org.cristalise.kernel.entity.proxy.DomainPathSubscriber;
+import org.cristalise.kernel.lookup.DomainPath;
+import org.cristalise.kernel.lookup.Path;
+import org.cristalise.kernel.process.Gateway;
+import org.cristalise.kernel.utils.Logger;
+
+
+
+public class NodeContext extends Node implements DomainPathSubscriber {
+ Iterator<Path> children;
+
+ public NodeContext(Path path, ItemTabManager desktop) {
+ super(path, desktop);
+ this.itemPath = null;
+ createTreeNode();
+ this.makeExpandable();
+ this.type = "Cristal Context";
+ }
+
+
+ @Override
+ public void loadChildren() {
+ if (children == null) {
+ Gateway.getProxyManager().subscribeTree(this, (DomainPath)binding);
+ children = Gateway.getLookup().getChildren(binding);
+ }
+
+ int batch = 75;
+ while (children.hasNext() && batch > 0) {
+ Path newPath = children.next();
+ if (newPath == null) break;
+ Logger.msg(2, "Subscription.run() - new node: " + newPath );
+ add( newNode(newPath));
+ batch--;
+ }
+ end(children.hasNext());
+ }
+
+ @Override
+ public void pathAdded(DomainPath path) {
+ add(newNode(path));
+ }
+
+ @Override
+ public void refresh() {
+ children = null;
+ super.refresh();
+ }
+ @Override
+ public void pathRemoved(DomainPath path) {
+ remove(path);
+ }
+
+}
+
+
+
+
+
+
+
diff --git a/src/main/java/org/cristalise/gui/tree/NodeItem.java b/src/main/java/org/cristalise/gui/tree/NodeItem.java
new file mode 100644
index 0000000..667b701
--- /dev/null
+++ b/src/main/java/org/cristalise/gui/tree/NodeItem.java
@@ -0,0 +1,241 @@
+package org.cristalise.gui.tree;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+
+import org.cristalise.gui.ItemDetails;
+import org.cristalise.gui.ItemTabManager;
+import org.cristalise.gui.MainFrame;
+import org.cristalise.kernel.collection.Aggregation;
+import org.cristalise.kernel.collection.Collection;
+import org.cristalise.kernel.collection.CollectionMember;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.entity.agent.Job;
+import org.cristalise.kernel.entity.proxy.ItemProxy;
+import org.cristalise.kernel.lookup.Path;
+import org.cristalise.kernel.persistency.ClusterStorage;
+import org.cristalise.kernel.process.Gateway;
+import org.cristalise.kernel.utils.Language;
+import org.cristalise.kernel.utils.Logger;
+
+
+/**
+ * Structure for Item presence on the tree and ItemDetails boxes. Created by NodeFactory.
+ * @author $Author: abranson $
+ * @version $Version$
+ */
+public class NodeItem extends Node implements Transferable {
+
+ protected ItemProxy myItem = null;
+
+ public NodeItem(Path path, ItemTabManager desktop) {
+
+ super(path, desktop);
+ Logger.msg(2,"NodeEntity.<init> - Creating item for '"+path.toString()+"'.");
+
+ // if an item - resolve the item and get its properties
+ try {
+ myItem = Gateway.getProxyManager().getProxy(path);
+ this.itemPath = path.getItemPath();
+ Logger.msg(2,"NodeEntity.<init> - System key is "+this.itemPath);
+
+ // Name should be the alias if present
+ String alias = myItem.getName();
+ if (alias != null) this.name = alias;
+
+ try {
+ this.type = myItem.getProperty("Type");
+ } catch (ObjectNotFoundException e) {
+ this.type = "";
+ }
+ String iconString = this.type;
+ if (type.equals("ActivityDesc"))
+ try {
+ iconString = myItem.getProperty("Complexity")+iconString;
+ } catch (ObjectNotFoundException e) {
+ iconString = "error";
+ }
+ iconString = iconString.toLowerCase();
+ this.setIcon(iconString);
+ } catch (ObjectNotFoundException e1) {
+ this.itemPath = null;
+ this.type="Error";
+ this.name="Entity not found";
+ this.setIcon("error");
+ }
+ createTreeNode();
+ makeExpandable();
+ }
+
+ public ItemProxy getItem() {
+ return myItem;
+ }
+
+ public void openItem() {
+ desktop.add(this);
+ }
+
+ public Collection<? extends CollectionMember> getParentCollection() {
+ return parentCollection;
+ }
+
+ public Integer getSlotNo() {
+ return slotNo;
+ }
+
+ Collection<? extends CollectionMember> parentCollection;
+ Integer slotNo = null;
+ static DataFlavor dataFlavor = new DataFlavor(NodeItem.class, "NodeItem");
+ ItemProxy parentItem;
+ static DataFlavor[] supportedFlavours = new DataFlavor[] {
+ dataFlavor,
+ new DataFlavor(Path.class, "Path"),
+ DataFlavor.getTextPlainUnicodeFlavor() };
+
+
+ public void setCollection(Collection<? extends CollectionMember> parentCollection, Integer slotNo, ItemProxy parentItem) {
+ this.parentCollection = parentCollection;
+ this.slotNo = slotNo;
+ this.parentItem = parentItem;
+ }
+
+ @Override
+ public void loadChildren() {
+ try {
+ String collections = myItem.queryData("Collection/all");
+ StringTokenizer tok = new StringTokenizer(collections, ",");
+ while (tok.hasMoreTokens()) {
+ NodeCollection newCollection = new NodeCollection(myItem, tok.nextToken(), desktop);
+ add(newCollection);
+ }
+ end(false);
+ } catch (Exception e) {
+ Logger.error(e);
+ }
+ }
+
+ @Override
+ public JPopupMenu getPopupMenu() {
+
+ JPopupMenu popup = super.getPopupMenu();
+ JMenuItem openItem = new JMenuItem(Language.translate("Open"));
+ openItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ openItem();
+ }
+ });
+ popup.addSeparator();
+ popup.add(openItem);
+ popup.addSeparator();
+ if (parentCollection != null && MainFrame.isAdmin) {
+ JMenuItem collMenuItem = new JMenuItem("Remove from collection");
+ //collMenuItem.setActionCommand("removeColl");
+ collMenuItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String[] params = { parentCollection.getName(), String.valueOf(slotNo) };
+ String predefStepName = parentCollection instanceof Aggregation?"ClearSlot":"RemoveSlotFromCollection";
+ try {
+ MainFrame.userAgent.execute(parentItem, predefStepName, params);
+ } catch (Exception e1) {
+ MainFrame.exceptionDialog(e1);
+ }
+
+ }
+ });
+ popup.add(collMenuItem);
+ popup.addSeparator();
+ }
+ try {
+ ArrayList<Job> jobList = myItem.getJobList(MainFrame.userAgent);
+ ArrayList<String> already = new ArrayList<String>();
+ if (jobList.size() > 0) {
+ for (Job thisJob : jobList) {
+ String stepName = thisJob.getStepName();
+ if (already.contains(stepName))
+ continue;
+ already.add(stepName);
+ JMenuItem menuItem = new JMenuItem(stepName);
+ menuItem.setActionCommand(stepName);
+ menuItem.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ execute(e.getActionCommand());
+ }
+ });
+ popup.add(menuItem);
+
+ }
+ }
+ else {
+ JMenuItem noAct = new JMenuItem("No activities");
+ noAct.setEnabled(false);
+ popup.add(noAct);
+ }
+ } catch (Exception ex) {
+ JMenuItem error = new JMenuItem("Error querying jobs");
+ error.setEnabled(false);
+ popup.add(error);
+ }
+
+ return popup;
+ }
+
+ public void execute(String stepName) {
+ ItemDetails thisDetail = desktop.add(this);
+ thisDetail.runCommand("Execution", stepName);
+ }
+
+ public ArrayList<String> getTabs() {
+
+ ArrayList<String> requiredTabs = new ArrayList<String>();
+ requiredTabs.add("Properties");
+ try {
+ String collNames = myItem.queryData(ClusterStorage.COLLECTION+"/all");
+ if (collNames.length() > 0)
+ requiredTabs.add("Collection");
+ } catch (Exception e) { }
+ requiredTabs.add("Execution");
+ requiredTabs.add("History");
+ requiredTabs.add("Viewpoint");
+ requiredTabs.add("Workflow");
+ return requiredTabs;
+
+ }
+
+ @Override
+ public DataFlavor[] getTransferDataFlavors() {
+ return supportedFlavours;
+ }
+
+ @Override
+ public boolean isDataFlavorSupported(DataFlavor flavor) {
+ for (DataFlavor flavour : supportedFlavours) {
+ if (flavour.equals(flavor))
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public Object getTransferData(DataFlavor flavor)
+ throws UnsupportedFlavorException, IOException {
+ if (flavor.equals(supportedFlavours[0]))
+ return this;
+ if (flavor.equals(supportedFlavours[1]))
+ return binding;
+ if (flavor.equals(supportedFlavours[2]))
+ return name;
+ throw new UnsupportedFlavorException(flavor);
+ }
+}
diff --git a/src/main/java/org/cristalise/gui/tree/NodeRole.java b/src/main/java/org/cristalise/gui/tree/NodeRole.java
new file mode 100644
index 0000000..288d3b6
--- /dev/null
+++ b/src/main/java/org/cristalise/gui/tree/NodeRole.java
@@ -0,0 +1,34 @@
+package org.cristalise.gui.tree;
+
+import org.cristalise.gui.ItemTabManager;
+import org.cristalise.kernel.common.ObjectNotFoundException;
+import org.cristalise.kernel.lookup.AgentPath;
+import org.cristalise.kernel.lookup.Path;
+import org.cristalise.kernel.lookup.RolePath;
+import org.cristalise.kernel.process.Gateway;
+import org.cristalise.kernel.utils.Logger;
+
+
+public class NodeRole extends NodeContext {
+
+ RolePath role;
+ public NodeRole(Path path, ItemTabManager desktop) {
+ super(path, desktop);
+ role = (RolePath)path;
+ }
+ @Override
+ public void loadChildren() {
+ AgentPath[] agents;
+ try {
+ agents = Gateway.getLookup().getAgents(role);
+ for (AgentPath agentPath : agents) {
+ add (newNode(agentPath));
+ }
+ } catch (ObjectNotFoundException e) {
+ Logger.error("Role "+role.getName()+" not found");
+ }
+ super.loadChildren();
+ }
+
+
+}
diff --git a/src/main/java/org/cristalise/gui/tree/NodeSubscriber.java b/src/main/java/org/cristalise/gui/tree/NodeSubscriber.java
new file mode 100644
index 0000000..b06f497
--- /dev/null
+++ b/src/main/java/org/cristalise/gui/tree/NodeSubscriber.java
@@ -0,0 +1,13 @@
+package org.cristalise.gui.tree;
+
+import org.cristalise.kernel.lookup.Path;
+
+
+public interface NodeSubscriber {
+
+ public void add(Node newNode);
+
+ public void remove(Path path);
+
+ public void end(boolean more);
+}
diff --git a/src/main/java/org/cristalise/gui/tree/NodeTransferHandler.java b/src/main/java/org/cristalise/gui/tree/NodeTransferHandler.java
new file mode 100644
index 0000000..89f503c
--- /dev/null
+++ b/src/main/java/org/cristalise/gui/tree/NodeTransferHandler.java
@@ -0,0 +1,74 @@
+package org.cristalise.gui.tree;
+
+import java.awt.datatransfer.Transferable;
+
+import javax.swing.Icon;
+import javax.swing.JComponent;
+import javax.swing.TransferHandler;
+
+import org.cristalise.gui.ImageLoader;
+import org.cristalise.gui.MainFrame;
+import org.cristalise.gui.TreeBrowser;
+import org.cristalise.kernel.utils.Logger;
+
+
+public class NodeTransferHandler extends TransferHandler {
+
+ TreeBrowser tree;
+
+ public NodeTransferHandler(TreeBrowser treeBrowser) {
+ tree = treeBrowser;
+ }
+
+ @Override
+ public int getSourceActions(JComponent c) {
+ return COPY_OR_MOVE;
+ }
+
+ @Override
+ public Transferable createTransferable(JComponent c) {
+ Node selNode = tree.getSelectedNode();
+ if (selNode instanceof Transferable)
+ return (Transferable)selNode;
+ else
+ return null;
+ }
+
+ @Override
+ public boolean importData(TransferSupport support) {
+ if (!canImport(support)) {
+ return false;
+ }
+ Node dropNode = tree.getNodeAt(support.getDropLocation().getDropPoint());
+ if (dropNode instanceof NodeCollection) {
+ NodeCollection collNode = (NodeCollection)dropNode;
+ NodeItem source;
+ try {
+ source = (NodeItem)support.getTransferable().getTransferData(NodeItem.dataFlavor);
+ return collNode.addMember(source.getItemPath());
+ } catch (Exception e) {
+ Logger.error(e);
+ return false;
+ }
+ }
+ return super.importData(support);
+ }
+
+ @Override
+ public boolean canImport(TransferSupport support) {
+ boolean isNode = support.isDataFlavorSupported(NodeItem.dataFlavor);
+ if (!isNode) return false;
+ Node dropNode = tree.getNodeAt(support.getDropLocation().getDropPoint());
+ if (MainFrame.isAdmin && dropNode instanceof NodeCollection && ((NodeCollection)dropNode).isDependency())
+ return true;
+ return false;
+
+ }
+
+ @Override
+ public Icon getVisualRepresentation(Transferable t) {
+ if (t instanceof NodeItem)
+ return (((NodeItem)t).getIcon());
+ return ImageLoader.nullImg;
+ }
+}