Author: tchemit Date: 2008-01-23 21:24:59 +0000 (Wed, 23 Jan 2008) New Revision: 454 Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementTreeNode.java Log: utilisation implantation par d?\195?\169faut + m?\195?\169thode collapseAll et expandAll Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementTreeNode.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementTreeNode.java 2008-01-23 21:24:03 UTC (rev 453) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementTreeNode.java 2008-01-23 21:24:59 UTC (rev 454) @@ -18,44 +18,41 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing.model; -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.LinkedList; -import java.util.Queue; /** * Le TreeNode de base pour afficher des LoggableElement dans un arbre. + * <p/> + * <b>Attention, l'objet interne au node n'est pas forcement un LoggableElement, + * par exemple pour le noeud 'Components' qui sera un simple String.</b> * * @author chemit */ -public class LoggableElementTreeNode implements TreeNode { +public class LoggableElementTreeNode extends DefaultMutableTreeNode { - protected LoggableElementTreeNode parent; + static protected Log log = LogFactory.getLog(LoggableElementTreeNode.class); - protected LoggableElementTreeNode[] childs; + private static final long serialVersionUID = -7544097600554338499L; - protected boolean allowedChildren; - - protected LoggableElement userObject; - - public LoggableElementTreeNode(LoggableElementTreeNode parent, LoggableElement root, boolean allowedChildren) { - this.parent = parent; - this.allowedChildren = allowedChildren; - this.userObject = root; + public LoggableElementTreeNode(LoggableElementTreeNode parent, Object userObject, boolean allowedChildren) { + super(userObject, allowedChildren); + if (parent != null) { + parent.add(this); + } + log.info("Parent " + parent + ", userObject : " + userObject + ", type : " + userObject.getClass().getSimpleName()); } public void collaspeAll(JTree tree) { if (isLeaf()) { return; } - for (LoggableElementTreeNode child : childs) { - child.collaspeAll(tree); + for (Object child : children) { + ((LoggableElementTreeNode) child).collaspeAll(tree); } tree.collapsePath(new TreePath(getPath())); } @@ -65,97 +62,9 @@ return; } tree.expandPath(new TreePath(getPath())); - for (LoggableElementTreeNode child : childs) { - child.expandAll(tree); + for (Object child : children) { + ((LoggableElementTreeNode) child).expandAll(tree); } } - @Override - public TreeNode getChildAt(int childIndex) { - if (childIndex < 0 || childIndex > getChildCount()) { - return null; - } - return childs[childIndex]; - } - - @Override - public int getChildCount() { - return childs == null ? 0 : childs.length; - } - - public TreeNode getParent() { - return parent; - } - - public int getIndex(TreeNode node) { - if (getChildCount() == 0) { - return -1; - } - for (int i = 0; i < childs.length; i++) { - LoggableElementTreeNode child = childs[i]; - if (node.equals(child)) { - return i; - } - } - return -1; - } - - public String toString() { - if (userObject == null) { - return null; - } else { - return userObject.toString(); - } - } - - @Override - public boolean getAllowsChildren() { - return allowedChildren; - } - - @Override - public boolean isLeaf() { - return getChildCount() == 0; - } - - public Enumeration children() { - return childs == null ? DefaultMutableTreeNode.EMPTY_ENUMERATION : new MyEnumeration<LoggableElementTreeNode>(childs); - } - - public TreeNode[] getPath() { - return getPathToRoot(this, 0); - } - - protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) { - TreeNode[] retNodes; - if (aNode == null) { - if (depth == 0) { - return null; - } else { - retNodes = new TreeNode[depth]; - } - } else { - depth++; - retNodes = getPathToRoot(aNode.getParent(), depth); - retNodes[retNodes.length - depth] = aNode; - } - return retNodes; - } - - class MyEnumeration<T> implements Enumeration<T> { - - Queue<T> queue; - - MyEnumeration(T[] queue) { - this.queue = new LinkedList<T>(Arrays.asList(queue)); - } - - public boolean hasMoreElements() { - return !queue.isEmpty(); - } - - public T nextElement() { - return queue.poll(); - } - } }