From 21230edbafdd30fcf0c43d1dc64ccbf4ca5e06a8 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 7 May 2014 17:33:57 +0200 Subject: Agent now extends Item, so they can have workflows. All traces of the old 'Entity' superclasses should be removed, including proxies and paths. Very large change, breaks API compatibility with CRISTAL 2.x. --- src/main/java/com/c2kernel/gui/tree/NodeItem.java | 93 ++++++++++++++++++----- 1 file changed, 72 insertions(+), 21 deletions(-) (limited to 'src/main/java/com/c2kernel/gui/tree/NodeItem.java') diff --git a/src/main/java/com/c2kernel/gui/tree/NodeItem.java b/src/main/java/com/c2kernel/gui/tree/NodeItem.java index 18d35be..9cdfc5a 100644 --- a/src/main/java/com/c2kernel/gui/tree/NodeItem.java +++ b/src/main/java/com/c2kernel/gui/tree/NodeItem.java @@ -15,13 +15,16 @@ import javax.swing.JPopupMenu; import com.c2kernel.collection.Aggregation; import com.c2kernel.collection.Collection; import com.c2kernel.collection.CollectionMember; +import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.entity.agent.Job; import com.c2kernel.entity.proxy.ItemProxy; -import com.c2kernel.gui.EntityDetails; -import com.c2kernel.gui.EntityTabManager; +import com.c2kernel.gui.ItemDetails; +import com.c2kernel.gui.ItemTabManager; import com.c2kernel.gui.MainFrame; import com.c2kernel.lookup.Path; import com.c2kernel.persistency.ClusterStorage; +import com.c2kernel.process.Gateway; +import com.c2kernel.utils.Language; import com.c2kernel.utils.Logger; /** @@ -29,8 +32,57 @@ import com.c2kernel.utils.Logger; * @author $Author: abranson $ * @version $Version$ */ -public class NodeItem extends NodeEntity implements Transferable { +public class NodeItem extends Node implements Transferable { + protected ItemProxy myItem = null; + + public NodeItem(Path path, ItemTabManager desktop) { + + super(path, desktop); + Logger.msg(2,"NodeEntity. - Creating item for '"+path.toString()+"'."); + + // if an item - resolve the item and get its properties + try { + myItem = Gateway.getProxyManager().getProxy(path); + this.sysKey = path.getSysKey(); + Logger.msg(2,"NodeEntity. - System key is "+this.sysKey); + + // 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.sysKey = -1; + 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 getParentCollection() { return parentCollection; } @@ -49,16 +101,6 @@ public class NodeItem extends NodeEntity implements Transferable { DataFlavor.getTextPlainUnicodeFlavor() }; - public NodeItem(Path path, EntityTabManager desktop) { - super(path, desktop); - try { - makeExpandable(); - } catch (Exception e) { - Logger.error(e); - } - - } - public void setCollection(Collection parentCollection, Integer slotNo, ItemProxy parentItem) { this.parentCollection = parentCollection; this.slotNo = slotNo; @@ -68,10 +110,10 @@ public class NodeItem extends NodeEntity implements Transferable { @Override public void loadChildren() { try { - String collections = myEntity.queryData("Collection/all"); + String collections = myItem.queryData("Collection/all"); StringTokenizer tok = new StringTokenizer(collections, ","); while (tok.hasMoreTokens()) { - NodeCollection newCollection = new NodeCollection((ItemProxy)myEntity, tok.nextToken(), desktop); + NodeCollection newCollection = new NodeCollection(myItem, tok.nextToken(), desktop); add(newCollection); } end(false); @@ -82,7 +124,17 @@ public class NodeItem extends NodeEntity implements Transferable { @Override public JPopupMenu getPopupMenu() { - JPopupMenu popup = super.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"); @@ -104,7 +156,7 @@ public class NodeItem extends NodeEntity implements Transferable { popup.addSeparator(); } try { - ArrayList jobList = ((ItemProxy)myEntity).getJobList(MainFrame.userAgent); + ArrayList jobList = myItem.getJobList(MainFrame.userAgent); ArrayList already = new ArrayList(); if (jobList.size() > 0) { for (Job thisJob : jobList) { @@ -139,17 +191,16 @@ public class NodeItem extends NodeEntity implements Transferable { } public void execute(String stepName) { - EntityDetails thisDetail = desktop.add(this); + ItemDetails thisDetail = desktop.add(this); thisDetail.runCommand("Execution", stepName); } - @Override public ArrayList getTabs() { - ArrayList requiredTabs = super.getTabs(); + ArrayList requiredTabs = new ArrayList(); requiredTabs.add("Properties"); try { - String collNames = myEntity.queryData(ClusterStorage.COLLECTION+"/all"); + String collNames = myItem.queryData(ClusterStorage.COLLECTION+"/all"); if (collNames.length() > 0) requiredTabs.add("Collection"); } catch (Exception e) { } -- cgit v1.2.3