Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15588/src/net/sourceforge/bprocessor/gui/treeview
Modified Files:
GenericTreeView.java
Log Message:
Refactored ContainerNode.update() to use generics
Index: GenericTreeView.java
===================================================================
RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview/GenericTreeView.java,v
retrieving revision 1.78
retrieving revision 1.79
diff -C2 -d -r1.78 -r1.79
*** GenericTreeView.java 8 Mar 2007 13:09:29 -0000 1.78
--- GenericTreeView.java 8 Mar 2007 14:38:28 -0000 1.79
***************
*** 18,27 ****
import java.util.Comparator;
import java.util.Enumeration;
- import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
- import java.util.Map;
import java.util.Set;
import java.util.Stack;
--- 18,25 ----
***************
*** 406,410 ****
*/
public class ContainerNode extends GenericNode {
! protected Object content;
/**
--- 404,408 ----
*/
public class ContainerNode extends GenericNode {
! protected Collection< ? extends Entity> content;
/**
***************
*** 413,417 ****
* @param label The label for the container node
*/
! public ContainerNode(Object label, Object object) {
super(label);
this.content = object;
--- 411,415 ----
* @param label The label for the container node
*/
! public ContainerNode(Object label, Collection< ? extends Entity> object) {
super(label);
this.content = object;
***************
*** 470,501 ****
/**
* Update the node with the given object
! * @param o The object
*/
! public void update(Object o) {
! if (o instanceof Collection) {
! content = (Collection) o;
! //to make sure undo and redo keep nodes
! Map elem = new HashMap();
! Iterator iter = ((Collection)o).iterator();
! while (iter.hasNext()) {
! Entity e = (Entity)iter.next();
! elem.put(e.getId(), e);
! }
! //Set elem = new HashSet((Collection)o);
! Set children = new HashSet();
! Enumeration e = this.children();
! while (e.hasMoreElements()) {
! GenericNode sn = (GenericNode)e.nextElement();
! Long id = ((Entity)sn.getUserObject()).getId();
! if (elem.containsKey(id)) {
! //If the node is allready there then just update it
! sn.update(elem.get(id));
! elem.remove(id);
} else {
! children.add(sn);
}
}
! if (elem.size() > 0) {
! this.insertChildren(elem.values());
}
if (children.size() > 0) {
--- 468,492 ----
/**
* Update the node with the given object
! * @param object The object
*/
! public void update(Object object) {
! if (object instanceof Collection) {
! content = (Collection) object;
! Set<Entity> elements = new HashSet();
! elements.addAll(content);
! Set<GenericNode> children = new HashSet();
! Enumeration enumeration = this.children();
! while (enumeration.hasMoreElements()) {
! GenericNode node = (GenericNode)enumeration.nextElement();
! Entity entity = (Entity)node.getUserObject();
! if (elements.contains(entity)) {
! node.update(entity);
! elements.remove(entity);
} else {
! children.add(node);
}
}
! if (elements.size() > 0) {
! this.insertChildren(elements);
}
if (children.size() > 0) {
***************
*** 503,507 ****
}
} else {
! log.warn(userObject + " were called with " + o + " and not a list");
}
}
--- 494,498 ----
}
} else {
! log.warn(userObject + " were called with " + object + " and not a list");
}
}
***************
*** 1249,1253 ****
*/
public ParameterBlockNode(String name, ParameterBlock object) {
! super(name, object);
insertChildren(object.getAttributes());
}
--- 1240,1244 ----
*/
public ParameterBlockNode(String name, ParameterBlock object) {
! super(name, object.getAttributes());
insertChildren(object.getAttributes());
}
***************
*** 1258,1262 ****
public void update(Object o) {
if (o instanceof ParameterBlock) {
! update(((ParameterBlock)o).getAttributes());
}
}
--- 1249,1253 ----
public void update(Object o) {
if (o instanceof ParameterBlock) {
! //super.update(((ParameterBlock)o).getAttributes());
}
}
|