From e4ccc012a781d794c06b8d3fd27e0a1f532b3fe7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 3 Aug 2012 14:03:59 +0200 Subject: Menu item on collection members in the tree to remove them. Drag items onto dependencies to add them. Dependency view Logging cleanup Fixes #42 --- .../java/com/c2kernel/gui/tree/NodeCollection.java | 120 +++++++++++++++++---- 1 file changed, 101 insertions(+), 19 deletions(-) (limited to 'src/main/java/com/c2kernel/gui/tree/NodeCollection.java') diff --git a/src/main/java/com/c2kernel/gui/tree/NodeCollection.java b/src/main/java/com/c2kernel/gui/tree/NodeCollection.java index 631ed8b..47afc5f 100644 --- a/src/main/java/com/c2kernel/gui/tree/NodeCollection.java +++ b/src/main/java/com/c2kernel/gui/tree/NodeCollection.java @@ -4,19 +4,27 @@ import java.util.ArrayList; import javax.swing.tree.DefaultMutableTreeNode; +import com.c2kernel.collection.Collection; import com.c2kernel.collection.CollectionMember; -import com.c2kernel.collection.Parent2ChildCollection; +import com.c2kernel.collection.Dependency; import com.c2kernel.common.ObjectNotFoundException; +import com.c2kernel.entity.proxy.EntityProxyObserver; import com.c2kernel.entity.proxy.ItemProxy; +import com.c2kernel.entity.proxy.MemberSubscription; import com.c2kernel.gui.EntityTabManager; +import com.c2kernel.gui.MainFrame; import com.c2kernel.lookup.EntityPath; import com.c2kernel.lookup.InvalidEntityPathException; +import com.c2kernel.lookup.Path; +import com.c2kernel.persistency.ClusterStorage; +import com.c2kernel.utils.CastorHashMap; +import com.c2kernel.utils.KeyValuePair; import com.c2kernel.utils.Logger; -public class NodeCollection extends Node { +public class NodeCollection extends Node implements EntityProxyObserver> { ItemProxy parent; - Parent2ChildCollection thisCollection; + Collection thisCollection; String path; public NodeCollection(ItemProxy parent, String name, EntityTabManager desktop) { @@ -27,42 +35,116 @@ public class NodeCollection extends Node { createTreeNode(); this.makeExpandable(); } + + public NodeCollection(ItemProxy parent, Collection coll, EntityTabManager desktop) { + this.desktop = desktop; + this.parent = parent; + this.name = coll.getName(); + this.path = parent.getSystemKey()+"/Collection/"+name; + createTreeNode(); + this.makeExpandable(); + add(coll); + } @Override public void loadChildren() { Logger.msg(8, "NodeCollection::loadChildren()"); try { - thisCollection = (Parent2ChildCollection)parent.getObject("Collection/"+name); + if (thisCollection == null) { + Collection initColl = (Collection)parent.getObject(ClusterStorage.COLLECTION+"/"+name); + add(initColl); + } + parent.subscribe(new MemberSubscription>(this, ClusterStorage.COLLECTION, false)); } catch (ObjectNotFoundException ex) { end(false); return; } - - this.type = thisCollection.getClass().getName(); - int lastDot = this.type.lastIndexOf('.'); - if (lastDot > -1) this.type = this.type.substring(lastDot+1); - ArrayList collectionMembers = thisCollection.getMembers().list; - for (int i=0; i contents) { + if (!contents.getName().equals(name)) return; + this.type = contents.getClass().getSimpleName(); + ArrayList newMembers = contents.getMembers().list; + ArrayList oldMembers; + if (thisCollection == null) + oldMembers = new ArrayList(); + else + oldMembers = thisCollection.getMembers().list; + + ArrayList currentPaths = new ArrayList(); + // add any missing paths + for (CollectionMember newMember : newMembers) { + if (!oldMembers.contains(newMember) && newMember.getEntityKey()>-1) try { - EntityPath entityPath = new EntityPath(aMember.getEntityKey()); - add(new NodeItem(entityPath, desktop)); + EntityPath entityPath = new EntityPath(newMember.getEntityKey()); + currentPaths.add(entityPath); + NodeItem newMemberNode = new NodeItem(entityPath, desktop); + newMemberNode.setCollection(contents, newMember.getID(), parent); + newMemberNode.setToolTip(getPropertyToolTip(newMember.getProperties())); + add(newMemberNode); } catch (InvalidEntityPathException ex) { - Logger.error("InvalidEntityPathException::NodeCollection::loadChildren() " + ex.toString()); + Logger.error("NodeCollection::loadChildren() " + ex.toString()); } } - - end(false); - + // 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(int syskey) { + if (!isDependency()) return false; + String[] params = { thisCollection.getName(), String.valueOf(syskey) }; + 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(""); + for (KeyValuePair prop : props.getKeyValuePairs()) { + verStr.append("").append(prop.getKey()).append(": ").append(prop.getValue()).append("
"); + } + return verStr.append("").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; + } } -- cgit v1.2.3