summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/gui/data/Node.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2012-06-26 12:41:56 +0200
committerAndrew Branson <andrew.branson@cern.ch>2012-06-26 12:41:56 +0200
commit6d8c74f97fe4289a984bdc6bd635c71653d5421c (patch)
tree35a028339a549d457bbf116a5614b6c59e850c1d /src/main/java/com/c2kernel/gui/data/Node.java
parente18629474efa8848d07404c8c4131489a225fa59 (diff)
Refactored GUI into separate module
Diffstat (limited to 'src/main/java/com/c2kernel/gui/data/Node.java')
-rw-r--r--src/main/java/com/c2kernel/gui/data/Node.java232
1 files changed, 0 insertions, 232 deletions
diff --git a/src/main/java/com/c2kernel/gui/data/Node.java b/src/main/java/com/c2kernel/gui/data/Node.java
deleted file mode 100644
index 2f12d6b..0000000
--- a/src/main/java/com/c2kernel/gui/data/Node.java
+++ /dev/null
@@ -1,232 +0,0 @@
-package com.c2kernel.gui.data;
-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 com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.gui.DynamicTreeBuilder;
-import com.c2kernel.gui.EntityTabManager;
-import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.Path;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.utils.Language;
-import com.c2kernel.utils.Logger;
-import com.c2kernel.utils.Resource;
-
-public abstract class Node implements Runnable {
-
- protected Path binding;
- protected DefaultMutableTreeNode treeNode;
- protected String name; // domain key
- protected int sysKey; // target item
- // attributes
- protected String type = "";
- 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 EntityTabManager desktop;
- static ImageIcon folder = Resource.findImage("folder.png");
- static ImageIcon emptyLeaf = Resource.findImage("leaf.png");
-
- public Node() {
- }
-
- protected void createTreeNode() {
- this.treeNode = new DefaultMutableTreeNode(this);
- }
-
- public Node(Path path, EntityTabManager desktop) {
- this.binding = path;
- this.desktop = desktop;
- this.sysKey = path.getSysKey();
- // 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.getProperty("Name");
- }
-
- public EntityTabManager getDesktop() {
- return desktop;
- }
-
- public Node newNode(Path path)
- {
- try {
- if (path.getEntity() instanceof AgentPath)
- return new NodeAgent(path, desktop);
- else
- return new NodeItem(path, desktop);
- } catch (ObjectNotFoundException ex) {
- 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);
- 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 int getSysKey() { return sysKey; }
-// 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 = Resource.findImage("typeicons/"+icon+"_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;
- }
-}