r1810 - in trunk: jaxx-compiler/src/site/rst jaxx-compiler/src/test/java/jaxx/compiler/reflect jaxx-demo/src/main/java/jaxx/demo jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation src/site/rst
Author: tchemit Date: 2010-03-26 12:34:09 +0100 (Fri, 26 Mar 2010) New Revision: 1810 Log: Evolution #419: Refactor navigation package (a abstract based + a impl package for tree and treetable) Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/ Removed: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java Modified: trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java trunk/src/site/rst/NavigationModel.rst Modified: trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst =================================================================== --- trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst 2010-03-26 11:34:09 UTC (rev 1810) @@ -15,12 +15,12 @@ Le développement est effectué dans le paquetage *jaxx.runtime.swing.navigation*. -jaxx.runtime.swing.navigation.NavigationTreeModel +jaxx.runtime.swing.navigation.NavigationTreeNodeModel ================================================= Il s'agit du modèle de l'arbre utilisé, c'est une extension d'un *javax.swing.tree.DefaultTreeModel*. -Les noeuds présents dans ce modèle sont aussi typés en *jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*. +Les noeuds présents dans ce modèle sont aussi typés en *jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*. L'idée principale est de pouvoir associé à un noeud précis un chemin depuis la racine, ce que l'on appele *chemin de navigation*. @@ -30,7 +30,7 @@ Définition d'un noeud ===================== -Le noeud (*jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*) est une extension d'un *javax.swing.tree.DefaultMutableTreeNode*. +Le noeud (*jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*) est une extension d'un *javax.swing.tree.DefaultMutableTreeNode*. Il apporte les nouvelles propriétés suivantes : Modified: trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java =================================================================== --- trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -1,23 +1,23 @@ -/* - * *##% - * JAXX Compiler - * Copyright (C) 2008 - 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * ##%* - */ +/* + * *##% + * JAXX Compiler + * Copyright (C) 2008 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * ##%* + */ package jaxx.compiler.reflect; import static org.junit.Assert.assertEquals; @@ -28,7 +28,7 @@ /*@Test public void testGetClassDescriptor() throws Exception { - ClassDescriptorLoader.getClassDescriptor("jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode"); + ClassDescriptorLoader.getClassDescriptor("jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode"); }*/ @Test public void testBuiltInClassName() throws ClassNotFoundException, NoSuchMethodException { Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -59,7 +59,7 @@ } @Override - public NavigationModel<NavigationTreeNode> createTreeModel(JAXXContext context) { + public NavigationTreeNodeModel createTreeModel(JAXXContext context) { if (log.isDebugEnabled()) { log.debug("start creating demo model"); @@ -126,7 +126,7 @@ addDemo(CounterDemo.class). addDemo(CalculatorDemo.class); - NavigationModel<NavigationTreeNode> model = builder.getModel(); + NavigationTreeNodeModel model = builder.getModel(); if (log.isDebugEnabled()) { builder.printModel(model.getRoot()); @@ -137,11 +137,11 @@ } @Override - public NavigationTreeHandler createTreeHandler(JAXXObject context) { + public NavigationTreeHandler<NavigationTreeNode> createTreeHandler(JAXXObject context) { - NavigationTreeHandler handler; + NavigationTreeHandler<NavigationTreeNode> handler; - handler = new NavigationTreeHandlerWithCardLayout( + handler = new NavigationTreeHandlerWithCardLayout<NavigationTreeNode>( getPrefix(), context, NavigationTreeHandler.Strategy.PER_UI_TYPE) { @@ -149,8 +149,8 @@ private static final long serialVersionUID = 1L; @Override - protected NavigationTreeModel getNavigationTreeModel() { - return (NavigationTreeModel) getModel(getContext()); + protected NavigationTreeNodeModel getNavigationTreeModel() { + return (NavigationTreeNodeModel) getModel(getContext()); } @Override @@ -181,7 +181,7 @@ return handler; } - static class TreeModelBuilder extends NavigationTreeModelBuilder { + static class TreeModelBuilder extends NavigationTreeNodeModelBuilder { /** la definition de l'unqiue object a partage */ static private final JAXXContextEntryDef<DemoConfig> def = Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -95,7 +95,7 @@ } @Override - public NavigationTreeModel createTreeModel(JAXXContext context) { + public NavigationTreeNodeModel createTreeModel(JAXXContext context) { if (builder == null) { builder = new FullNavigationTreeModelBuilder(context); @@ -103,7 +103,7 @@ builder.createInitialModel(); - NavigationTreeModel model = builder.getModel(); + NavigationTreeNodeModel model = builder.getModel(); // save tree model in context setModel(context, model); Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -27,7 +27,7 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.decorator.Decorator; import jaxx.runtime.decorator.DecoratorProvider; -import jaxx.runtime.swing.navigation.NavigationTreeModelBuilder; +import jaxx.runtime.swing.navigation.NavigationTreeNodeModelBuilder; import jaxx.runtime.swing.navigation.NavigationTreeNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,7 +40,7 @@ * @author chemit * @since 2.0.0 */ -public class FullNavigationTreeModelBuilder extends NavigationTreeModelBuilder { +public class FullNavigationTreeModelBuilder extends NavigationTreeNodeModelBuilder { /** * Logger Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2010-03-26 11:34:09 UTC (rev 1810) @@ -21,7 +21,7 @@ <JPanel abstract='true' layout='{new BorderLayout()}' genericType='B extends Object' - implements='jaxx.runtime.swing.navigation.NavigationContentUI'> + implements='jaxx.runtime.swing.navigation.NavigationContentUI<NavigationTreeNode>'> <script><![CDATA[ import jaxx.demo.component.jaxx.navigation.*; Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -0,0 +1,294 @@ +/* + * *##% + * JAXX Runtime + * Copyright (C) 2008 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * ##%* + */ +package jaxx.runtime.swing.navigation; + +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTreeTable; + +import javax.swing.*; +import javax.swing.tree.TreePath; +import java.lang.reflect.InvocationTargetException; +import java.util.Enumeration; +import java.util.regex.Pattern; + +/** + * Helper object associated to a given navigation tree system. + * <p/> + * To helper is context safe (base on a {@link NavigationTreeContextHelper}. + * + * @author Letellier + * @param <E> type of nodes in model + * @see NavigationTreeNodeModel + * @since 2.0.1 + */ +public abstract class AbstractNavigationHelper<E extends NavigationNode<E>> extends NavigationTreeContextHelper<E> { + + /** Logger */ + static private final Log log = + LogFactory.getLog(NavigationTreeHelper.class); + + /** + * Create the model. + * + * @param context the context to associate with fresh model + * @return the new model build with data from the given context + */ + public abstract NavigationModel<E> createTreeModel(JAXXContext context); + + /** + * Create the tree handler. + * + * @param context the context to associate with fresh handler + * @return the new handler + */ + public abstract NavigationTreeHandler createTreeHandler(JAXXObject context); + + public AbstractNavigationHelper(String contextPrefix) { + super(contextPrefix); + } + + public Object getContextValue(JAXXContext context, String path) + throws InvocationTargetException, NoSuchMethodException, + IllegalAccessException { + NavigationModel<E> treeModel = getSafeModel(context); + return treeModel.getBean(path); + } + + public E findNode(JAXXContext context, String path) { + NavigationModel<E> treeModel = getSafeModel(context); + return treeModel.findNode(path); + } + + public E findNode(JAXXContext context, String path, + String regex) { + NavigationModel<E> treeModel = getSafeModel(context); + return treeModel.findNode(path, regex); + } + + public E findNode(JAXXContext context, String path, + Pattern regex) { + + NavigationModel<E> treeModel = getSafeModel(context); + return treeModel.findNode(path, regex); + } + + public E findNode(JAXXContext context, String path, + String regex, String suffix) { + + NavigationModel<E> treeModel = getSafeModel(context); + + E node = treeModel.findNode(path, regex); + if (node != null && suffix != null) { + node = treeModel.findNode(node, suffix); + } + return node; + } + + public E findNode(JAXXContext context, String path, + Pattern regex, String suffix) { + + NavigationModel<E> treeModel = getSafeModel(context); + + E node = treeModel.findNode(path, regex); + if (node != null && suffix != null) { + node = treeModel.findNode(node, suffix); + } + return node; + } + + /** + * Sélection d'un noeud dans l'arbre de navigation à partir de son path. + * + * @param context le contexte applicatif + * @param path le path absolue du noeud dans l'arbre + */ + public void selectNode(JAXXContext context, String path) { + E node = findNode(context, path); + if (log.isDebugEnabled()) { + log.debug(path + " :: " + node); + } + if (node != null) { + selectNode(context, node); + } + } + + /** + * Sélection d'un noeud dans l'arbre de navigation. + * + * @param context le contexte applicatif + * @param node le noeud à sélectionner dans l'arbre + */ + public void selectNode(JAXXContext context, E node) { + + + NavigationModel<E> navigationModel = getSafeModel(context); + if (log.isDebugEnabled()) { + log.debug(node); + } + TreePath path = new TreePath(navigationModel.getPathToRoot(node)); + JTree tree = getTree(context); + if (tree == null) { + // FIXME : Refactor in other helper ? + // If its JXTreeTable + JXTreeTable treeTable = getSafeTreeTable(context); + treeTable.getTreeSelectionModel().setSelectionPath(path); + treeTable.scrollPathToVisible(path); + return; + } + tree.setSelectionPath(path); + tree.scrollPathToVisible(path); + } + + /** + * Sélection du parent du noeud selectionne dans l'arbre de navigation. + * + * @param context le contexte applicatif + */ + public void gotoParentNode(JAXXContext context) { + + E node = getSelectedNode(context); + + if (node == null) { + // pas de noeud selectionne + throw new NullPointerException("no selected node in context"); + } + node = node.getParent(); + + selectNode(context, node); + } + + /** + * Obtain the first ancestor with the matching internalClass + * + * @param current the node to test + * @param beanClass the type of the internal class to seek of + * @return the first ancestor node with the matching class or {@code null} + * if not found + */ + public E getParentNode(E current, + Class<?> beanClass) { + if (current == null) { + // ancestor not found + return null; + } + if (beanClass.isAssignableFrom(current.getInternalClass())) { + // matching node + return current; + } + // try in the parent of node + return getParentNode(current.getParent(), beanClass); + } + + /** + * Sélection d'un fils du noeud selectionne dans l'arbre de navigation. + * + * @param context le contexte applicatif + * @param childIndex index du fils a selectionner + */ + public void gotoChildNode(JAXXContext context, int childIndex) { + + E node = getSelectedNode(context); + + if (node == null) { + // pas de noeud selectionne + throw new NullPointerException("no selected node in context"); + } + node = node.getChildAt(childIndex); + + selectNode(context, node); + } + + /** + * Demande une opération de repaint sur un noeud de l'arbre de navigation. + * <p/> + * <b>Note:</b> La descendance du noeud n'est pas repainte. + * + * @param context le contexte applicatif + * @param node le noeud à repaindre + */ + public void repaintNode(JAXXContext context, E node) { + repaintNode(context, node, false); + } + + /** + * Demande une opération de repaint sur un noeud de l'arbre de navigation. + * <p/> + * <b>Note:</b> La descendance du noeud est repainte si le paramètre + * <code>deep</code> est à <code>true</code>. + * + * @param context le contexte applicatif + * @param node le noeud à repaindre + * @param deep un flag pour activer la repainte de la descendance du + * noeud + */ + public void repaintNode(JAXXContext context, E node, + boolean deep) { + NavigationModel<E> navigationModel = getSafeModel(context); + if (log.isDebugEnabled()) { + log.debug(node); + } + navigationModel.nodeChanged(node); + if (deep) { + // repaint childs nodes + //todo we should only repaint necessary nodes ? + Enumeration<? extends E> e = node.children(); + while (e.hasMoreElements()) { + E child = e.nextElement(); + repaintNode(context, child, true); + } + } + } + + public NavigationModel<E> getSafeModel(JAXXContext context) + throws NullPointerException { + NavigationModel<E> model = getModel(context); + if (model == null) { + throw new NullPointerException( + "could not find tree model with key " + + getModelContextEntry() + " in context " + context); + } + return model; + } + + public JTree getSafeTree(JAXXContext context) throws NullPointerException { + JTree tree = getTree(context); + if (tree == null) { + throw new NullPointerException( + "could not find tree with key " + getTreeContextEntry() + + " in context " + context); + } + return tree; + } + + public JXTreeTable getSafeTreeTable(JAXXContext context) + throws NullPointerException { + JXTreeTable treeTable = getTreeTable(context); + if (treeTable == null) { + throw new NullPointerException( + "could not find tree with key " + + getTreeTableContextEntry() + " in context " + context); + } + return treeTable; + } +} Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -0,0 +1,219 @@ +/* + * *##% + * JAXX Runtime + * Copyright (C) 2008 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * ##%* + */ +package jaxx.runtime.swing.navigation; + +import jaxx.runtime.JAXXContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.MutableTreeNode; +import javax.swing.tree.TreeNode; +import java.lang.reflect.Array; +import java.util.Enumeration; +import java.util.StringTokenizer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Model of the tree used for a navigation tree. It is composed of {@link E} + * nodes. + * + * @author letellier + * @param <E> the type of nodes in model + * @since 2.0.1 + */ +public abstract class AbstractNavigationModel<E extends NavigationNode<E>> extends DefaultTreeModel implements NavigationModel<E> { + + static private final long serialVersionUID = 1L; + + /** Logger */ + static private final Log log = LogFactory.getLog(NavigationTreeNodeModel.class); + + /** + * The path separator used to build the {@link NavigationTreeNode#fullPath}. + * + * @see NavigationTreeNode#getNodePath() + * @see NavigationTreeNode#getFullPath() + */ + protected final String pathSeparator; + + /** Context to retrieve beans */ + private JAXXContext context; + + public AbstractNavigationModel(String pathSeparator, JAXXContext context) { + super(null); + this.pathSeparator = pathSeparator; + this.context = context; + } + + @Override + public E getRoot() { + return (E) super.getRoot(); + } + + @Override + public void setRoot(E root) { + setRoot((TreeNode) root); + } + + @Override + public E findNode(String path) { + return findNode(getRoot(), path, (Pattern) null); + } + + @Override + public E findNode(String path, String regex) { + return findNode(getRoot(), path, regex); + } + + @Override + public E findNode(String path, Pattern regex) { + return findNode(getRoot(), path, regex); + } + + @Override + public E findNode(E root, String path) { + return findNode(root, path, (Pattern) null); + } + + @Override + public E findNode(E root, String path, String regex) { + return findNode(root, path, + regex == null ? null : Pattern.compile(regex)); + } + + @Override + public E findNode(E root, String path, Pattern regex) { + if (regex != null) { + Matcher matcher = regex.matcher(path); + if (!matcher.matches() || matcher.groupCount() < 1) { + log.warn("no matching regex " + regex + " to " + path); + return null; + } + path = matcher.group(1); + if (log.isDebugEnabled()) { + log.debug("matching regex " + regex + " : " + path); + } + } + StringTokenizer stk = new StringTokenizer(path, pathSeparator); + E result = root; + // pas the first token (matches the root node) + if (root.isRoot() && stk.hasMoreTokens()) { + String rootPath = stk.nextToken(); + if (!rootPath.equals(root.getNodePath())) { + return null; + } + } + while (stk.hasMoreTokens()) { + result = result.getChild(stk.nextToken()); + } + return result; + } + + @Override + public JAXXContext getContext() { + return context; + } + + @Override + public Object getBean(String navigationPath) { + Object result; + E node = findNode(navigationPath, (Pattern) null); + result = getBean(node); + return result; + } + + @Override + public Object getBean(E node) { + if (node == null) { + return null; + //fixme should throw a NPE exception + //throw new NullPointerException("node can not be null"); + } + return node.getBean(getContext()); + } + + @Override + public void nodeChanged(E node) { + nodeChanged(node, false); + if (log.isDebugEnabled()) { + log.debug(node); + } + } + + @Override + public void nodeStructureChanged(E node) { + E n = node; + //TC-20091004 never launch a deep reload + reload(n, true); + nodeStructureChanged((TreeNode) node); + if (log.isDebugEnabled()) { + log.debug(node); + } + } + + @Override + public void nodeChanged(E node, boolean deep) { + + E n = node; + //TC-20091004 never launch a deep clean, since we do a deep nodeChanged. + reload(n, deep); + nodeChanged((TreeNode) node); + } + + @Override + public String getPathSeparator() { + return pathSeparator; + } + + protected void reload(E node) { + reload(node, false); + } + + protected void reload(E node, boolean deep) { + if (node == null) { + return; + } + node.reload(getContext()); + + if (deep) { + Enumeration<? extends E> childs = node.children(); + while (childs.hasMoreElements()) { + E o = childs.nextElement(); + reload(o, true); + } + } + } + + @Override + public E[] getPathToRoot(E aNode) { + TreeNode[] treeNodes = getPathToRoot((TreeNode) aNode); + E[] result = (E[]) Array.newInstance(aNode.getClass(), treeNodes.length); + System.arraycopy(treeNodes, 0, result, 0, treeNodes.length); + return result; + } + + @Override + public void removeNodeFromParent(E node) { + removeNodeFromParent((MutableTreeNode) node); + } +} Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -27,7 +27,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.util.Collection; import java.util.Enumeration; /** @@ -37,7 +36,7 @@ * @author sletellier * @since 2.0.0 */ -public abstract class AbstractNavigationModelBuilder<E extends NavigationTreeNode> implements NavigationModelBuilder<E> { +public abstract class AbstractNavigationModelBuilder<E extends NavigationNode<E>> implements NavigationModelBuilder<E> { /** Logger */ static private final Log log = @@ -196,7 +195,7 @@ @Override public E removeChildNode(E node) { - E parentNode = (E) node.getParent(); + E parentNode = node.getParent(); model.removeNodeFromParent(node); return parentNode; } @@ -243,9 +242,9 @@ log.debug("value from node " + node.getBean(getModel().getContext())); log.debug("value from model " + getModel().getBean(node)); } - Enumeration<?> children = node.children(); + Enumeration<? extends E> children = node.children(); while (children.hasMoreElements()) { - printModel((E) children.nextElement()); + printModel(children.nextElement()); } } @@ -269,84 +268,4 @@ return node; } - public static abstract class ChildBuilder<O, E extends NavigationTreeNode> { - - protected AbstractNavigationModelBuilder<E> builder; - - protected ChildBuilder(AbstractNavigationModelBuilder<E> builder) { - this.builder = builder; - } - - protected abstract void init(Class<? extends O> klass); - - protected abstract Decorator<? extends O> getDecorator(O child); - - protected abstract String getJXPath(O child); - - protected abstract String getNavigationPath(O child); - - public void build(E parent, - boolean cacheValues, - Class<? extends O> klass, - Collection<? extends O> beans, - Class<? extends JAXXObject> ui, - Class<? extends JAXXAction> actionClass) { - - if (beans == null || beans.isEmpty()) { - // no bean to treate - return; - } - - init(klass); - - E node; - - for (O o : beans) { - node = builder.build( - parent, - getDecorator(o), - getJXPath(o), - getNavigationPath(o), - ui, - actionClass - ); - if (cacheValues) { - // cache the bean value to improve performance - node.setBean(o); - } - } - } - - public void build(E parent, - boolean cacheValues, - Class<? extends O> klass, - O[] beans, - Class<? extends JAXXObject> ui, - Class<? extends JAXXAction> actionClass) { - - if (beans == null || beans.length == 0) { - // no bean to treate - return; - } - - init(klass); - - E node; - - for (O o : beans) { - node = builder.build( - parent, - getDecorator(o), - getJXPath(o), - getNavigationPath(o), - ui, - actionClass - ); - if (cacheValues) { - // cache the bean value to improve performance - node.setBean(o); - } - } - } - } } Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -1,294 +0,0 @@ -/* - * *##% - * JAXX Runtime - * Copyright (C) 2008 - 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * ##%* - */ -package jaxx.runtime.swing.navigation; - -import jaxx.runtime.JAXXContext; -import jaxx.runtime.JAXXObject; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXTreeTable; - -import javax.swing.*; -import javax.swing.tree.TreePath; -import java.lang.reflect.InvocationTargetException; -import java.util.Enumeration; -import java.util.regex.Pattern; - -/** - * Helper object associated to a given navigation tree system. - * <p/> - * To helper is context safe (base on a {@link NavigationTreeContextHelper}. - * - * @author Letellier - * @param <E> type of nodes in model - * @see NavigationTreeModel - * @since 2.0.1 - */ -public abstract class GenericNavigationHelper<E extends NavigationTreeNode> extends NavigationTreeContextHelper<E> { - - /** Logger */ - static private final Log log = - LogFactory.getLog(NavigationTreeHelper.class); - - /** - * Create the model. - * - * @param context the context to associate with fresh model - * @return the new model build with data from the given context - */ - public abstract NavigationModel<E> createTreeModel(JAXXContext context); - - /** - * Create the tree handler. - * - * @param context the context to associate with fresh handler - * @return the new handler - */ - public abstract NavigationTreeHandler createTreeHandler(JAXXObject context); - - public GenericNavigationHelper(String contextPrefix) { - super(contextPrefix); - } - - public Object getContextValue(JAXXContext context, String path) - throws InvocationTargetException, NoSuchMethodException, - IllegalAccessException { - NavigationModel<E> treeModel = getSafeModel(context); - return treeModel.getBean(path); - } - - public E findNode(JAXXContext context, String path) { - NavigationModel<E> treeModel = getSafeModel(context); - return treeModel.findNode(path); - } - - public E findNode(JAXXContext context, String path, - String regex) { - NavigationModel<E> treeModel = getSafeModel(context); - return treeModel.findNode(path, regex); - } - - public E findNode(JAXXContext context, String path, - Pattern regex) { - - NavigationModel<E> treeModel = getSafeModel(context); - return treeModel.findNode(path, regex); - } - - public E findNode(JAXXContext context, String path, - String regex, String suffix) { - - NavigationModel<E> treeModel = getSafeModel(context); - - E node = treeModel.findNode(path, regex); - if (node != null && suffix != null) { - node = treeModel.findNode(node, suffix); - } - return node; - } - - public E findNode(JAXXContext context, String path, - Pattern regex, String suffix) { - - NavigationModel<E> treeModel = getSafeModel(context); - - E node = treeModel.findNode(path, regex); - if (node != null && suffix != null) { - node = treeModel.findNode(node, suffix); - } - return node; - } - - /** - * Sélection d'un noeud dans l'arbre de navigation à partir de son path. - * - * @param context le contexte applicatif - * @param path le path absolue du noeud dans l'arbre - */ - public void selectNode(JAXXContext context, String path) { - E node = findNode(context, path); - if (log.isDebugEnabled()) { - log.debug(path + " :: " + node); - } - if (node != null) { - selectNode(context, node); - } - } - - /** - * Sélection d'un noeud dans l'arbre de navigation. - * - * @param context le contexte applicatif - * @param node le noeud à sélectionner dans l'arbre - */ - public void selectNode(JAXXContext context, E node) { - - - NavigationModel<E> navigationModel = getSafeModel(context); - if (log.isDebugEnabled()) { - log.debug(node); - } - TreePath path = new TreePath(navigationModel.getPathToRoot(node)); - JTree tree = getTree(context); - if (tree == null) { - // FIXME : Refactor in other helper ? - // If its JXTreeTable - JXTreeTable treeTable = getSafeTreeTable(context); - treeTable.getTreeSelectionModel().setSelectionPath(path); - treeTable.scrollPathToVisible(path); - return; - } - tree.setSelectionPath(path); - tree.scrollPathToVisible(path); - } - - /** - * Sélection du parent du noeud selectionne dans l'arbre de navigation. - * - * @param context le contexte applicatif - */ - public void gotoParentNode(JAXXContext context) { - - E node = getSelectedNode(context); - - if (node == null) { - // pas de noeud selectionne - throw new NullPointerException("no selected node in context"); - } - node = (E) node.getParent(); - - selectNode(context, node); - } - - /** - * Obtain the first ancestor with the matching internalClass - * - * @param current the node to test - * @param beanClass the type of the internal class to seek of - * @return the first ancestor node with the matching class or {@code null} - * if not found - */ - public E getParentNode(E current, - Class<?> beanClass) { - if (current == null) { - // ancestor not found - return null; - } - if (beanClass.isAssignableFrom(current.getInternalClass())) { - // matching node - return current; - } - // try in the parent of node - return getParentNode((E) current.getParent(), beanClass); - } - - /** - * Sélection d'un fils du noeud selectionne dans l'arbre de navigation. - * - * @param context le contexte applicatif - * @param childIndex index du fils a selectionner - */ - public void gotoChildNode(JAXXContext context, int childIndex) { - - E node = getSelectedNode(context); - - if (node == null) { - // pas de noeud selectionne - throw new NullPointerException("no selected node in context"); - } - node = (E) node.getChildAt(childIndex); - - selectNode(context, node); - } - - /** - * Demande une opération de repaint sur un noeud de l'arbre de navigation. - * <p/> - * <b>Note:</b> La descendance du noeud n'est pas repainte. - * - * @param context le contexte applicatif - * @param node le noeud à repaindre - */ - public void repaintNode(JAXXContext context, E node) { - repaintNode(context, node, false); - } - - /** - * Demande une opération de repaint sur un noeud de l'arbre de navigation. - * <p/> - * <b>Note:</b> La descendance du noeud est repainte si le paramètre - * <code>deep</code> est à <code>true</code>. - * - * @param context le contexte applicatif - * @param node le noeud à repaindre - * @param deep un flag pour activer la repainte de la descendance du - * noeud - */ - public void repaintNode(JAXXContext context, E node, - boolean deep) { - NavigationModel<E> navigationModel = getSafeModel(context); - if (log.isDebugEnabled()) { - log.debug(node); - } - navigationModel.nodeChanged(node); - if (deep) { - // repaint childs nodes - //todo we should only repaint necessary nodes ? - Enumeration<?> e = node.children(); - while (e.hasMoreElements()) { - E child = (E) e.nextElement(); - repaintNode(context, child, true); - } - } - } - - public NavigationModel<E> getSafeModel(JAXXContext context) - throws NullPointerException { - NavigationModel<E> model = getModel(context); - if (model == null) { - throw new NullPointerException( - "could not find tree model with key " + - getModelContextEntry() + " in context " + context); - } - return model; - } - - public JTree getSafeTree(JAXXContext context) throws NullPointerException { - JTree tree = getTree(context); - if (tree == null) { - throw new NullPointerException( - "could not find tree with key " + getTreeContextEntry() + - " in context " + context); - } - return tree; - } - - public JXTreeTable getSafeTreeTable(JAXXContext context) - throws NullPointerException { - JXTreeTable treeTable = getTreeTable(context); - if (treeTable == null) { - throw new NullPointerException( - "could not find tree with key " + - getTreeTableContextEntry() + " in context " + context); - } - return treeTable; - } -} Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -1,219 +0,0 @@ -/* - * *##% - * JAXX Runtime - * Copyright (C) 2008 - 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * ##%* - */ -package jaxx.runtime.swing.navigation; - -import jaxx.runtime.JAXXContext; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeNode; -import java.lang.reflect.Array; -import java.util.Enumeration; -import java.util.StringTokenizer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Model of the tree used for a navigation tree. It is composed of {@link E} - * nodes. - * - * @author letellier - * @since 2.0.1 - * @param <E> the type of nodes in model - */ -public class GenericNavigationTreeModel<E extends NavigationTreeNode> extends DefaultTreeModel implements NavigationModel<E> { - - static private final long serialVersionUID = 1L; - - /** Logger */ - static private final Log log = LogFactory.getLog(NavigationTreeModel.class); - - /** - * The path separator used to build the {@link NavigationTreeNode#fullPath}. - * - * @see NavigationTreeNode#getNodePath() - * @see NavigationTreeNode#getFullPath() - */ - protected final String pathSeparator; - - /** Context to retrieve beans */ - private JAXXContext context; - - public GenericNavigationTreeModel(String pathSeparator, - JAXXContext context) { - super(null); - this.pathSeparator = pathSeparator; - this.context = context; - } - - @Override - public E getRoot() { - return (E) super.getRoot(); - } - - @Override - public void setRoot(E root) { - super.setRoot(root); - } - - @Override - public E findNode(String path) { - return findNode(getRoot(), path, (Pattern) null); - } - - @Override - public E findNode(String path, String regex) { - return findNode(getRoot(), path, regex); - } - - @Override - public E findNode(String path, Pattern regex) { - return findNode(getRoot(), path, regex); - } - - @Override - public E findNode(E root, String path) { - return findNode(root, path, (Pattern) null); - } - - @Override - public E findNode(E root, String path, String regex) { - return findNode(root, path, - regex == null ? null : Pattern.compile(regex)); - } - - @Override - public E findNode(E root, String path, Pattern regex) { - if (regex != null) { - Matcher matcher = regex.matcher(path); - if (!matcher.matches() || matcher.groupCount() < 1) { - log.warn("no matching regex " + regex + " to " + path); - return null; - } - path = matcher.group(1); - if (log.isDebugEnabled()) { - log.debug("matching regex " + regex + " : " + path); - } - } - StringTokenizer stk = new StringTokenizer(path, pathSeparator); - E result = root; - // pas the first token (matches the root node) - if (root.isRoot() && stk.hasMoreTokens()) { - String rootPath = stk.nextToken(); - if (!rootPath.equals(root.getNodePath())) { - return null; - } - } - while (stk.hasMoreTokens()) { - result = (E) result.getChild(stk.nextToken()); - } - return result; - } - - @Override - public JAXXContext getContext() { - return context; - } - - @Override - public Object getBean(String navigationPath) { - Object result; - E node = findNode(navigationPath, (Pattern) null); - result = getBean(node); - return result; - } - - @Override - public Object getBean(E node) { - if (node == null) { - return null; - //fixme should throw a NPE exception - //throw new NullPointerException("node can not be null"); - } - return node.getBean(getContext()); - } - - @Override - public void nodeChanged(E node) { - nodeChanged(node, false); - if (log.isDebugEnabled()) { - log.debug(node); - } - } - - @Override - public void nodeStructureChanged(E node) { - E n = node; - //TC-20091004 never launch a deep reload - reload(n, true); - super.nodeStructureChanged(node); - if (log.isDebugEnabled()) { - log.debug(node); - } - } - - @Override - public void nodeChanged(E node, boolean deep) { - - E n = node; - //TC-20091004 never launch a deep clean, since we do a deep nodeChanged. - reload(n, deep); - super.nodeChanged(node); - } - - @Override - public String getPathSeparator() { - return pathSeparator; - } - - protected void reload(E node) { - reload(node, false); - } - - protected void reload(E node, boolean deep) { - if (node == null) { - return; - } - node.reload(getContext()); - - if (deep) { - Enumeration<?> childs = node.children(); - while (childs.hasMoreElements()) { - E o = (E) childs.nextElement(); - reload(o, true); - } - } - } - - @Override - public E[] getPathToRoot(E aNode) { - TreeNode[] treeNodes = super.getPathToRoot(aNode); - E[] result = (E[]) Array.newInstance(aNode.getClass(),treeNodes.length); - System.arraycopy(treeNodes,0,result,0,treeNodes.length); - return result; - } - - @Override - public void removeNodeFromParent(E node) { - super.removeNodeFromParent(node); - } -} Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -28,17 +28,17 @@ * @author chemit * @since 2.0.0 */ -public interface NavigationContentUI { +public interface NavigationContentUI<E extends NavigationNode<E>> { /** * Init the ui just before been opened by the method {@link - * NavigationTreeHandler#openUI(Component, NavigationTreeNode)}. + * NavigationTreeHandler#openUI(Component, NavigationNode)}. * * @param node the selected node associated to the ui * @throws Exception if any pb while opening the content's ui - * @see NavigationTreeHandler#openUI(Component, NavigationTreeNode) + * @see NavigationTreeHandler#openUI(Component, NavigationNode) */ - void openUI(NavigationTreeNode node) throws Exception; + void openUI(E node) throws Exception; /** * Clean the ui after been closed by the method {@link @@ -48,5 +48,5 @@ * @throws Exception if any pb when closing the content'sui * @see NavigationTreeHandler#closeUI(Component) */ - void closeUI(NavigationTreeNode node) throws Exception; + void closeUI(E node) throws Exception; } Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -22,8 +22,8 @@ import jaxx.runtime.JAXXContext; -import javax.swing.tree.TreeModel; -import javax.swing.tree.TreeNode; +import javax.swing.event.TreeModelListener; +import javax.swing.tree.TreePath; import java.util.regex.Pattern; /** @@ -34,13 +34,14 @@ * @author sletellier * @since 2.0.0 */ -public interface NavigationModel<E extends NavigationTreeNode> extends TreeModel { +public interface NavigationModel<E extends NavigationNode<E>> { +//public interface NavigationModel<E extends NavigationNode<E>> extends TreeModel { E getRoot(); void setRoot(E root); - TreeNode[] getPathToRoot(E aNode); + E[] getPathToRoot(E aNode); void removeNodeFromParent(E node); @@ -164,4 +165,92 @@ void nodeChanged(E node, boolean deep); String getPathSeparator(); + + /** + * Returns the child of <code>parent</code> at index <code>index</code> + * in the parent's + * child array. <code>parent</code> must be a node previously obtained + * from this data source. This should not return <code>null</code> + * if <code>index</code> + * is a valid index for <code>parent</code> (that is <code>index >= 0 && + * index < getChildCount(parent</code>)). + * + * @param parent a node in the tree, obtained from this data source + * @return the child of <code>parent</code> at index <code>index</code> + */ + Object getChild(Object parent, int index); + + + /** + * Returns the number of children of <code>parent</code>. + * Returns 0 if the node + * is a leaf or if it has no children. <code>parent</code> must be a node + * previously obtained from this data source. + * + * @param parent a node in the tree, obtained from this data source + * @return the number of children of the node <code>parent</code> + */ + int getChildCount(Object parent); + + + /** + * Returns <code>true</code> if <code>node</code> is a leaf. + * It is possible for this method to return <code>false</code> + * even if <code>node</code> has no children. + * A directory in a filesystem, for example, + * may contain no files; the node representing + * the directory is not a leaf, but it also has no children. + * + * @param node a node in the tree, obtained from this data source + * @return true if <code>node</code> is a leaf + */ + boolean isLeaf(Object node); + + /** + * Messaged when the user has altered the value for the item identified + * by <code>path</code> to <code>newValue</code>. + * If <code>newValue</code> signifies a truly new value + * the model should post a <code>treeNodesChanged</code> event. + * + * @param path path to the node that the user has altered + * @param newValue the new value from the TreeCellEditor + */ + void valueForPathChanged(TreePath path, Object newValue); + + /** + * Returns the index of child in parent. If either <code>parent</code> + * or <code>child</code> is <code>null</code>, returns -1. + * If either <code>parent</code> or <code>child</code> don't + * belong to this tree model, returns -1. + * + * @param parent a node in the tree, obtained from this data source + * @param child the node we are interested in + * @return the index of the child in the parent, or -1 if either + * <code>child</code> or <code>parent</code> are <code>null</code> + * or don't belong to this tree model + */ + int getIndexOfChild(Object parent, Object child); + +// +// Change Events +// + + /** + * Adds a listener for the <code>TreeModelEvent</code> + * posted after the tree changes. + * + * @param l the listener to add + * @see #removeTreeModelListener + */ + void addTreeModelListener(TreeModelListener l); + + /** + * Removes a listener previously added with + * <code>addTreeModelListener</code>. + * + * @see #addTreeModelListener + * @param l the listener to remove + */ + void removeTreeModelListener(TreeModelListener l); + } Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -32,7 +32,7 @@ * @author sletellier * @since 2.0.0 */ -public interface NavigationModelBuilder<E extends NavigationTreeNode> { +public interface NavigationModelBuilder<E extends NavigationNode<E>> { NavigationModel<E> getModel(); Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -30,7 +30,7 @@ * @author sletellier * @since 2.0.1 */ -public interface NavigationMultiContentUI extends NavigationContentUI { +public interface NavigationMultiContentUI<E extends NavigationNode<E>> extends NavigationContentUI<E> { /** * Init the ui just before been opened by the method {@link @@ -39,7 +39,7 @@ * @param nodes the selected node associated to the ui * @throws Exception if any pb while opening the content's ui */ - void openUI(List<NavigationTreeNode> nodes) throws Exception; + void openUI(List<E> nodes) throws Exception; /** * Clean the ui after been closed by the method {@link @@ -49,5 +49,5 @@ * @throws Exception if any pb when closing the content'sui * @see NavigationTreeHandler#closeUI(Component) */ - void closeUI(List<NavigationTreeNode> nodes) throws Exception; + void closeUI(List<E> nodes) throws Exception; } Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -44,7 +44,7 @@ * @author sletellier * @since 2.0.1 */ -public abstract class NavigationMultiTreeHandler extends NavigationTreeHandler { +public abstract class NavigationMultiTreeHandler<E extends NavigationNode<E>> extends NavigationTreeHandler<E> { /** Logger */ static private final Log log = @@ -65,14 +65,13 @@ TreePath[] paths = event.getPaths(); // TODO : verifier que la selection n'est pas la même - List<NavigationTreeNode> nodes = new ArrayList<NavigationTreeNode>(); + List<E> nodes = new ArrayList<E>(); if (paths == null) { - selectNodeUI(new ArrayList<NavigationTreeNode>()); + selectNodeUI(new ArrayList<E>()); return; } for (TreePath path : paths) { - NavigationTreeNode node = - (NavigationTreeNode) path.getLastPathComponent(); + E node = (E) path.getLastPathComponent(); nodes.add(node); if (log.isDebugEnabled()) { log.debug("Adding path : " + path); @@ -90,7 +89,7 @@ * @throws Exception if any */ protected abstract void openUI(Component newUI, - List<NavigationTreeNode> nodes) + List<E> nodes) throws Exception; /** @@ -100,25 +99,25 @@ * @return la nouvelle ui associée au noeud * @throws Exception if any */ - protected abstract Component createUI(List<NavigationTreeNode> nodes) + protected abstract Component createUI(List<E> nodes) throws Exception; /** * @param nodes les noeuds associés à l'ui à retrouver * @return l'ui associés au nouveau noeud sélectionné */ - protected abstract Component getUI(List<NavigationTreeNode> nodes); + protected abstract Component getUI(List<E> nodes); - protected void selectNodeUI(List<NavigationTreeNode> nodes) { + protected void selectNodeUI(List<E> nodes) { log.info("select nodes " + nodes); try { - List<String> paths = new ArrayList<String>(); +// List<String> paths = new ArrayList<String>(); List<Object> beans = new ArrayList<Object>(); - for (NavigationTreeNode node : nodes) { + for (E node : nodes) { String path = node.getFullPath(); - paths.add(path); +// paths.add(path); if (log.isTraceEnabled()) { log.trace(path); @@ -134,7 +133,7 @@ // save it in context (must be done before init ui) JAXXContext ctxt = getContext(); - NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper(); + NavigationTreeContextHelper<E> helper = getContextHelper(); // remove previous selected bean //TODO-TC-20091004 should have an automatic clean context method @@ -162,8 +161,8 @@ // really open the ui associated with the selected node // init ui before to be visible - if (newUI instanceof NavigationMultiContentUI) { - ((NavigationMultiContentUI) newUI).openUI(nodes); + if (newUI instanceof NavigationMultiContentUI<?>) { + ((NavigationMultiContentUI<E>) newUI).openUI(nodes); } // set ui in content @@ -177,9 +176,9 @@ } } - protected List<String> getPaths(List<NavigationTreeNode> nodes) { + protected List<String> getPaths(List<E> nodes) { List<String> result = new ArrayList<String>(); - for (NavigationTreeNode node : nodes) { + for (E node : nodes) { result.add(node.getFullPath()); } return result; Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -0,0 +1,91 @@ +package jaxx.runtime.swing.navigation; + +import jaxx.runtime.JAXXAction; +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.context.JAXXContextEntryDef; + +import java.io.Serializable; +import java.util.Enumeration; + +public interface NavigationNode<E extends NavigationNode<E>> extends Cloneable, Serializable { +// public interface NavigationNode<E extends NavigationNode<E>> extends Cloneable, MutableTreeNode, Serializable { + NavigationTreeNodeRenderer getRenderer(); + + void setRenderer(NavigationTreeNodeRenderer renderer); + + String getPathSeparator(); + + String getNodePath(); + + void setNodePath(String navigationPath); + + Class<? extends JAXXObject> getUIClass(); + + void setUIClass(Class<? extends JAXXObject> uIClass); + + void setInternalClass(Class<?> internalClass); + + Class<? extends JAXXAction> getUIHandlerClass(); + + void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass); + + JAXXContextEntryDef<?> getJaxxContextEntryDef(); + + void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef); + + String getJaxxContextEntryPath(); + + void setJaxxContextEntryPath(String jaxxContextEntryPath); + + Class<?> getInternalClass(); + + String getFullPath(); + + E getChildAt(int index); + + E getParent(); + + E getChild(String path); + + Object getBean(); + + void setBean(Object bean); + + void reload(JAXXContext context); + + Object getBean(JAXXContext context); + + void insert(E child, int index); + + void remove(int index); + + void remove(E node); + + void setUserObject(Object object); + + void removeFromParent(); + + void setParent(E newParent); + + int getChildCount(); + + int getIndex(E node); + + boolean getAllowsChildren(); + + boolean isLeaf(); + + Enumeration<? extends E> children(); + + boolean isRoot(); + + Object getUserObject(); + + void add(E node); + + E[] getPathToRoot(E aNode, int depth) ; + + E[] getPath(); + +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -40,7 +40,7 @@ * @author sletellier * @since 2.0.1 */ -public abstract class NavigationOneClicSelectionHandler extends NavigationMultiTreeHandler { +public abstract class NavigationOneClicSelectionHandler<E extends NavigationNode<E>> extends NavigationMultiTreeHandler<E> { /** Logger */ static private final Log log = Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -64,7 +64,7 @@ * @author chemit * @since 1.7.2 */ -public class NavigationTreeContextHelper <E extends NavigationTreeNode> { +public class NavigationTreeContextHelper <E extends NavigationNode<E>> { /** * Logger Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -20,22 +20,23 @@ */ package jaxx.runtime.swing.navigation; -import java.awt.Component; -import java.util.Arrays; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.DefaultTreeSelectionModel; -import javax.swing.tree.TreePath; import jaxx.runtime.JAXXAction; import jaxx.runtime.JAXXContext; -import jaxx.runtime.context.JAXXInitialContext; import jaxx.runtime.JAXXObject; +import jaxx.runtime.context.JAXXInitialContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultTreeSelectionModel; +import javax.swing.tree.TreePath; +import java.awt.*; +import java.util.Arrays; + /** * The handler of a navigation tree. - * + * <p/> * This is also the selection model to use, since we must check before moving * from a node we can not just listen selection model changed, we must control * it. @@ -43,52 +44,48 @@ * @author tchemit <chemit@codelutin.com> * @since 1.7.2 */ -public abstract class NavigationTreeHandler extends DefaultTreeSelectionModel implements TreeSelectionListener{ +public abstract class NavigationTreeHandler<E extends NavigationNode<E>> extends DefaultTreeSelectionModel implements TreeSelectionListener { private static final long serialVersionUID = 1L; - /** - * Logger - */ + + /** Logger */ static private final Log log = LogFactory.getLog(NavigationTreeHandler.class); /** * Strategy of instanciation of ui. * <p/> - * For a given {@code node}, the method {@link #getId(NavigationTreeNode)} + * For a given {@code node}, the method {@link #getId(NavigationNode)} * returns the id of ui to use. */ public enum Strategy { - /** - * instanciate a ui for a node - */ + /** instanciate a ui for a node */ PER_NODE { @Override - public String getId(NavigationTreeNode node) { + public String getId(NavigationNode<?> node) { return node.getFullPath(); } }, /** - * instanciate only one a ui for a type,nodes will share the instanciation + * instanciate only one a ui for a type,nodes will share the + * instanciation */ PER_UI_TYPE { @Override - public String getId(NavigationTreeNode node) { + public String getId(NavigationNode<?> node) { return node.getUIClass().getName(); } }; - public abstract String getId(NavigationTreeNode node); + public abstract String getId(NavigationNode<?> node); } - /** - * UI which contains navigation tree - */ + + /** UI which contains navigation tree */ protected JAXXContext context; - /** - * UI Instanciation strategy - */ + + /** UI Instanciation strategy */ protected Strategy strategy; /** @@ -96,10 +93,10 @@ * * @since 1.7.2 */ - protected NavigationTreeContextHelper<NavigationTreeNode> contextHelper; + protected NavigationTreeContextHelper<E> contextHelper; protected NavigationTreeHandler(String contextPrefix, JAXXObject context, Strategy strategy) { - contextHelper = new NavigationTreeContextHelper<NavigationTreeNode>(contextPrefix); + contextHelper = new NavigationTreeContextHelper<E>(contextPrefix); this.context = context; this.strategy = strategy; addTreeSelectionListener(this); @@ -107,7 +104,7 @@ @Override public void valueChanged(TreeSelectionEvent event) { - if (log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Value changed for path : " + event.getPath()); log.debug("Old lead selection path : " + event.getOldLeadSelectionPath()); } @@ -115,18 +112,16 @@ // do not treate this if no path changed return; } - NavigationTreeNode node = (NavigationTreeNode) event.getPath().getLastPathComponent(); + E node = (E) event.getPath().getLastPathComponent(); selectNodeUI(node); } - /** - * @return le modèle de navigation associé - */ + /** @return le modèle de navigation associé */ protected abstract NavigationModel<?> getNavigationTreeModel(); /** - * @return le composent actuellement visible associé au noeud courant ou - * au noeud précédent lors d'un changement de noeud. + * @return le composent actuellement visible associé au noeud courant ou au + * noeud précédent lors d'un changement de noeud. */ protected abstract Component getCurrentUI(); @@ -134,11 +129,12 @@ * @param node le noeud associé à l'ui à retrouver * @return l'ui associé au novueau noeud sélectionné */ - protected abstract Component getUI(NavigationTreeNode node); + protected abstract Component getUI(E node); /** * @param component le composent actuellement visible - * @return <code>true</code> si le composent a bien été fermé, <code>false</code> sinon + * @return <code>true</code> si le composent a bien été fermé, + * <code>false</code> sinon * @throws Exception if any */ protected abstract boolean closeUI(Component component) throws Exception; @@ -150,7 +146,7 @@ * @return la nouvelle ui associée au noeud * @throws Exception if any */ - protected abstract Component createUI(NavigationTreeNode node) throws Exception; + protected abstract Component createUI(E node) throws Exception; /** * Ouvre l'ui associée au noeud sélectionné dans l'arbre de navigation. @@ -159,12 +155,12 @@ * @param node le node de l'ui a ouvrir * @throws Exception if any */ - protected abstract void openUI(Component newUI, NavigationTreeNode node) throws Exception; + protected abstract void openUI(Component newUI, E node) throws Exception; /** * Traitement des exceptions. * - * @param e l'erreur recontrée (ou null si pas d"erreur) + * @param e l'erreur recontrée (ou null si pas d"erreur) */ protected abstract void treateError(Exception e); @@ -172,7 +168,7 @@ return context; } - public NavigationTreeContextHelper<NavigationTreeNode> getContextHelper() { + public NavigationTreeContextHelper<E> getContextHelper() { return contextHelper; } @@ -195,8 +191,8 @@ // can not changed current node return; } - if (component instanceof NavigationContentUI) { - ((NavigationContentUI) component).closeUI((NavigationTreeNode) path.getLastPathComponent()); + if (component instanceof NavigationContentUI<?>) { + ((NavigationContentUI<E>) component).closeUI((E) path.getLastPathComponent()); } } catch (Exception ex) { treateError(ex); @@ -216,7 +212,7 @@ if (Arrays.equals(paths, getSelectionPaths())) { // stay on same node, can skip if (log.isDebugEnabled()) { - log.debug("skip stay on path " + paths); + log.debug("skip stay on path " + Arrays.toString(paths)); } return; } @@ -230,10 +226,10 @@ // can not changed current node return; } - if (component instanceof NavigationMultiContentUI) { - if (paths.length == 1){ - NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper(); - ((NavigationMultiContentUI) component).closeUI(helper.getSelectedNodes(getContext())); + if (component instanceof NavigationMultiContentUI<?>) { + if (paths.length == 1) { + NavigationTreeContextHelper<E> helper = getContextHelper(); + ((NavigationMultiContentUI<E>) component).closeUI(helper.getSelectedNodes(getContext())); } } } catch (Exception ex) { @@ -247,7 +243,7 @@ super.setSelectionPaths(paths); } - protected void selectNodeUI(NavigationTreeNode node) { + protected void selectNodeUI(E node) { try { @@ -274,7 +270,7 @@ } JAXXContext ctxt = getContext(); - NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper(); + NavigationTreeContextHelper<E> helper = getContextHelper(); // save in context current node context path helper.setSelectedPath(ctxt, node.getFullPath()); @@ -287,8 +283,8 @@ // really open the ui associated with the selected node // init ui before to be visible - if (newUI instanceof NavigationContentUI) { - ((NavigationContentUI) newUI).openUI(node); + if (newUI instanceof NavigationContentUI<?>) { + ((NavigationContentUI<E>) newUI).openUI(node); } // set ui in content @@ -309,7 +305,7 @@ * @return le context à utiliser pour instancier l'ui * @throws Exception if any */ - protected JAXXContext createUIContext(NavigationTreeNode node) throws Exception { + protected JAXXContext createUIContext(E node) throws Exception { if (node.getUIHandlerClass() == null) { if (log.isWarnEnabled()) { @@ -326,13 +322,13 @@ return uiContext; } - protected void addSelectedBeanInContext(NavigationTreeNode node, Object data) { + protected void addSelectedBeanInContext(E node, Object data) { if (log.isDebugEnabled()) { log.debug("find data for contextPath <" + node.getFullPath() + "> : " + (data == null ? null : data.getClass())); } JAXXContext ctxt = getContext(); - NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper(); + NavigationTreeContextHelper<E> helper = getContextHelper(); // remove previous selected bean //TODO-TC-20091004 should have an automatic clean context method while Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -42,7 +42,7 @@ * * @author chemit */ -public abstract class NavigationTreeHandlerWithCardLayout extends NavigationTreeHandler { +public abstract class NavigationTreeHandlerWithCardLayout<E extends NavigationNode<E>> extends NavigationTreeHandler<E> { /** Logger */ static private final Log log = LogFactory.getLog(NavigationTreeHandlerWithCardLayout.class); @@ -86,7 +86,7 @@ } @Override - protected Component getUI(NavigationTreeNode node) { + protected Component getUI(E node) { CardLayout2 layout = getContentLayout(); JPanel container = getContentContainer(); String constraints = strategy.getId(node); @@ -95,7 +95,7 @@ } @Override - protected void openUI(Component newUI, NavigationTreeNode node) throws + protected void openUI(Component newUI, E node) throws Exception { CardLayout2 layout = getContentLayout(); @@ -112,7 +112,7 @@ } @Override - protected Component createUI(NavigationTreeNode node) throws Exception { + protected Component createUI(E node) throws Exception { JAXXContext uiContext = createUIContext(node); Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -27,9 +27,9 @@ * * @author chemit * @since 1.7.2 - * @see NavigationTreeModel + * @see NavigationTreeNodeModel */ -public abstract class NavigationTreeHelper extends GenericNavigationHelper<NavigationTreeNode> { +public abstract class NavigationTreeHelper extends AbstractNavigationHelper<NavigationTreeNode> { protected NavigationTreeHelper(String contextPrefix) { super(contextPrefix); Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -1,40 +0,0 @@ -/* - * *##% - * JAXX Runtime - * Copyright (C) 2008 - 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * ##%* - */ -package jaxx.runtime.swing.navigation; - -import jaxx.runtime.JAXXContext; - -/** - * Model of the tree used for a navigation tree. - * <p/> - * Il est composé de {@link NavigationTreeNode} - * - * @author chemit - * @since 1.7.2 - */ -public class NavigationTreeModel extends GenericNavigationTreeModel<NavigationTreeNode> { - - private static final long serialVersionUID = 1L; - - public NavigationTreeModel(String pathSeparator, JAXXContext context) { - super(pathSeparator, context); - } -} Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -1,90 +0,0 @@ -/* - * *##% - * JAXX Runtime - * Copyright (C) 2008 - 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * ##%* - */ -package jaxx.runtime.swing.navigation; - -import jaxx.runtime.JAXXAction; -import jaxx.runtime.JAXXContext; -import jaxx.runtime.JAXXObject; -import jaxx.runtime.context.JAXXContextEntryDef; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * This object is design to build a {@link NavigationTreeModel}. - * - * @author chemit - * @see NavigationModelBuilder - * @since 17.2 - */ -public class NavigationTreeModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeNode> { - - /** Logger */ - static private final Log log = - LogFactory.getLog(NavigationTreeModelBuilder.class); - - public NavigationTreeModelBuilder( - String pathSeparator, - JAXXContext context, - Class<? extends JAXXObject> defaultUIClass, - Class<? extends JAXXAction> defaultUIHandlerClass) { - this(defaultUIClass, - defaultUIHandlerClass, - new NavigationTreeModel(pathSeparator, context) - ); - } - - @Override - public NavigationTreeModel getModel() { - return (NavigationTreeModel) super.getModel(); - } - - public NavigationTreeModelBuilder( - Class<? extends JAXXObject> defaultUIClass, - Class<? extends JAXXAction> defaultUIHandlerClass, - NavigationTreeModel model) { - super(defaultUIClass, defaultUIHandlerClass, model); - } - - @Override - public NavigationTreeNode createNavigationTreeNode( - String pathSeparator, - String contextName, - JAXXContextEntryDef<?> jaxxContextEntryDef, - String jaxxContextEntryPath) { - return new NavigationTreeNode( - pathSeparator, - contextName, - jaxxContextEntryDef, - jaxxContextEntryPath - ); - } - -// // TODO : to remove -// /** -// * @deprecated please use NavigationModel for return type -// * @return the tree model -// */ -// @Override -// @Deprecated -// public NavigationTreeModel getModel() { -// return (NavigationTreeModel)super.getModel(); -// } -} Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -33,7 +33,7 @@ import java.util.Enumeration; /** - * Node of the {@link NavigationTreeModel}. + * Node of the {@link NavigationTreeNodeModel}. * <p/> * Each node is associated with : <ul> <li> a {@code bean} coming from a {@link * JAXXContext} </li> <li> a {@code uiClass} to build the associated ui </li> @@ -61,11 +61,11 @@ * {@link NavigationTreeNodeRenderer#reload(Object)} method. * * @author chemit - * @see NavigationTreeModel + * @see NavigationTreeNodeModel * @see NavigationTreeNodeRenderer * @since 1.7.2 */ -public class NavigationTreeNode extends DefaultMutableTreeNode { +public class NavigationTreeNode extends DefaultMutableTreeNode implements NavigationNode<NavigationTreeNode> { private static final long serialVersionUID = 1L; @@ -115,7 +115,7 @@ * The UI class associated with the node. * <p/> * This class can be {@code null}, in that case, the {@link - * NavigationTreeModelBuilder#defaultUIClass} will be used while building + * NavigationTreeNodeModelBuilder#defaultUIClass} will be used while building * the model. */ protected Class<? extends JAXXObject> uIClass; @@ -124,7 +124,7 @@ * The UI handler class associated with the node. * <p/> * This class can be {@code null}, in that case, the {@link - * NavigationTreeModelBuilder#defaultUIHandlerClass} will be used while + * NavigationTreeNodeModelBuilder#defaultUIHandlerClass} will be used while * building the model. */ protected Class<? extends JAXXAction> uIHandlerClass; @@ -192,6 +192,7 @@ } /** @return the text node renderer (store in {@link #userObject} property. */ + @Override public NavigationTreeNodeRenderer getRenderer() { NavigationTreeNodeRenderer render = null; Object o = getUserObject(); @@ -201,60 +202,74 @@ return render; } + @Override public void setRenderer(NavigationTreeNodeRenderer renderer) { // clear all cache bean = null; setUserObject(renderer); } + @Override public String getPathSeparator() { return pathSeparator; } + @Override public String getNodePath() { return path; } + @Override public void setNodePath(String navigationPath) { path = navigationPath; } + @Override public Class<? extends JAXXObject> getUIClass() { return uIClass; } + @Override public void setUIClass(Class<? extends JAXXObject> uIClass) { this.uIClass = uIClass; } + @Override public void setInternalClass(Class<?> internalClass) { this.internalClass = internalClass; } + @Override public Class<? extends JAXXAction> getUIHandlerClass() { return uIHandlerClass; } + @Override public void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass) { this.uIHandlerClass = uIHandlerClass; } + @Override public JAXXContextEntryDef<?> getJaxxContextEntryDef() { return jaxxContextEntryDef; } + @Override public void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef) { this.jaxxContextEntryDef = jaxxContextEntryDef; } + @Override public String getJaxxContextEntryPath() { return jaxxContextEntryPath; } + @Override public void setJaxxContextEntryPath(String jaxxContextEntryPath) { this.jaxxContextEntryPath = jaxxContextEntryPath; } + @Override public Class<?> getInternalClass() { if (internalClass == null && getRenderer() != null) { return getRenderer().getInternalClass(); @@ -263,6 +278,7 @@ } /** @return the fully context path of the node from the root node to this. */ + @Override public String getFullPath() { if (fullPath == null) { StringBuilder sb = new StringBuilder(); @@ -290,10 +306,11 @@ * this node. * @return the child of this node with given {@link #path} value. */ + @Override public NavigationTreeNode getChild(String path) { - Enumeration<?> childs = children(); + Enumeration<? extends NavigationTreeNode> childs = children(); while (childs.hasMoreElements()) { - NavigationTreeNode son = (NavigationTreeNode) childs.nextElement(); + NavigationTreeNode son = childs.nextElement(); if (path.equals(son.getNodePath())) { return son; } @@ -301,14 +318,17 @@ return null; } + @Override public Object getBean() { return bean; } + @Override public void setBean(Object bean) { this.bean = bean; } + @Override public void reload(JAXXContext context) { // clear bean cache @@ -343,6 +363,7 @@ * @param context the context to seek * @return the value associated in context with the given context path */ + @Override public Object getBean(JAXXContext context) { if (bean != null) { // use cached bean @@ -413,6 +434,31 @@ return result; } + @Override + public void insert(NavigationTreeNode child, int index) { + super.insert(child, index); + } + + @Override + public void remove(NavigationTreeNode node) { + super.remove(node); + } + + @Override + public void setParent(NavigationTreeNode newParent) { + super.setParent(newParent); + } + + @Override + public int getIndex(NavigationTreeNode node) { + return super.getIndex(node); + } + + @Override + public Enumeration<? extends NavigationTreeNode> children() { + return super.children(); + } + /** * @return the first ancestor with a none null {@link #jaxxContextEntryDef} * or <code>null</code> if none find.. @@ -429,7 +475,7 @@ } protected String computeJXPath(String expr, NavigationTreeNode parentNode) { - if (this == parentNode) { + if (equals(parentNode)) { // reach the parent limit node, return the expr computed return expr; } @@ -480,4 +526,26 @@ ); return ancestor.computeJXPath(newExpr, parentNode); } + + @Override + public void add(NavigationTreeNode node) { + super.add(node); + } + + + @Override + public NavigationTreeNode[] getPath() { + TreeNode[] treeNodes = super.getPath(); + NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length]; + System.arraycopy(treeNodes, 0, result, 0, treeNodes.length); + return result; + } + + @Override + public NavigationTreeNode[] getPathToRoot(NavigationTreeNode aNode, int depth) { + TreeNode[] treeNodes = super.getPathToRoot(aNode, depth); + NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length]; + System.arraycopy(treeNodes, 0, result, 0, treeNodes.length); + return result; + } } Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -0,0 +1,40 @@ +/* + * *##% + * JAXX Runtime + * Copyright (C) 2008 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * ##%* + */ +package jaxx.runtime.swing.navigation; + +import jaxx.runtime.JAXXContext; + +/** + * Model of the tree used for a navigation tree. + * <p/> + * Il est composé de {@link NavigationTreeNode} + * + * @author chemit + * @since 1.7.2 + */ +public class NavigationTreeNodeModel extends AbstractNavigationModel<NavigationTreeNode> { + + private static final long serialVersionUID = 1L; + + public NavigationTreeNodeModel(String pathSeparator, JAXXContext context) { + super(pathSeparator, context); + } +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -0,0 +1,90 @@ +/* + * *##% + * JAXX Runtime + * Copyright (C) 2008 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * ##%* + */ +package jaxx.runtime.swing.navigation; + +import jaxx.runtime.JAXXAction; +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.context.JAXXContextEntryDef; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * This object is design to build a {@link NavigationTreeNodeModel}. + * + * @author chemit + * @see NavigationModelBuilder + * @since 17.2 + */ +public class NavigationTreeNodeModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeNode> { + + /** Logger */ + static private final Log log = + LogFactory.getLog(NavigationTreeNodeModelBuilder.class); + + public NavigationTreeNodeModelBuilder( + String pathSeparator, + JAXXContext context, + Class<? extends JAXXObject> defaultUIClass, + Class<? extends JAXXAction> defaultUIHandlerClass) { + this(defaultUIClass, + defaultUIHandlerClass, + new NavigationTreeNodeModel(pathSeparator, context) + ); + } + + @Override + public NavigationTreeNodeModel getModel() { + return (NavigationTreeNodeModel) super.getModel(); + } + + public NavigationTreeNodeModelBuilder( + Class<? extends JAXXObject> defaultUIClass, + Class<? extends JAXXAction> defaultUIHandlerClass, + NavigationTreeNodeModel model) { + super(defaultUIClass, defaultUIHandlerClass, model); + } + + @Override + public NavigationTreeNode createNavigationTreeNode( + String pathSeparator, + String contextName, + JAXXContextEntryDef<?> jaxxContextEntryDef, + String jaxxContextEntryPath) { + return new NavigationTreeNode( + pathSeparator, + contextName, + jaxxContextEntryDef, + jaxxContextEntryPath + ); + } + +// // TODO : to remove +// /** +// * @deprecated please use NavigationModel for return type +// * @return the tree model +// */ +// @Override +// @Deprecated +// public NavigationTreeNodeModel getModel() { +// return (NavigationTreeNodeModel)super.getModel(); +// } +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -24,9 +24,9 @@ import java.io.Serializable; /** - * Text Renderer of a {@link NavigationTreeNode}. + * Text Renderer of a {@link NavigationNode}. * <p/> - * This object will be placed as the {@link NavigationTreeNode#userObject} of + * This object will be placed as the {@link NavigationTreeNode#getUserObject()} of * nodes. * <p/> * Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -26,7 +26,6 @@ import org.jdesktop.swingx.tree.TreeModelSupport; import org.jdesktop.swingx.treetable.DefaultTreeTableModel; -import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.util.Enumeration; @@ -40,7 +39,7 @@ * <p/> * Il est composé de {@link NavigationTreeNode} * <p/> - * FIXME : Essayer d'enlever les copier coller {@link NavigationTreeModel} + * FIXME : Essayer d'enlever les copier coller {@link NavigationTreeNodeModel} * * @author sletellier * @since 2.0.0 Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -20,9 +20,16 @@ */ package jaxx.runtime.swing.navigation; +import jaxx.runtime.JAXXAction; +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; import jaxx.runtime.context.JAXXContextEntryDef; -import org.jdesktop.swingx.treetable.TreeTableNode; +import org.apache.commons.jxpath.JXPathContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; +import javax.swing.tree.TreeNode; import java.util.Enumeration; /** @@ -32,26 +39,438 @@ * @see NavigationTreeNode * @since 2.0.0 */ -public abstract class NavigationTreeTableNode extends NavigationTreeNode implements TreeTableNode { +public class NavigationTreeTableNode extends DefaultMutableTreeTableNode implements NavigationNode<NavigationTreeTableNode> { +//public abstract class NavigationTreeTableNode extends NavigationTreeNode implements TreeTableNode, NavigationNode<NavigationTreeTableNode> { + private static final long serialVersionUID = -1L; + + /** Logger */ + private static final Log log = + LogFactory.getLog(NavigationTreeTableNode.class); + + /** + * The path separator used to build the {@link #fullPath}. + * + * @see #path + * @see #fullPath + */ + protected final String pathSeparator; + + /** + * The node path. + * <p/> + * Used to build the {@link #fullPath} which gives a unique identifier of + * the node. + * + * @see #pathSeparator + * @see #fullPath + */ + protected String path; + + /** + * The full path for the node from the rood node. + * <p/> + * This path is build by appending nodes {@link #path} from the root node to + * this node, between each path we introduce the {@link #pathSeparator}. + * <p/> + * Exemple : + * <pre> + * root + * $root + * `-- child1 + * `-- child2 + * </pre> + * will given {@code $root/child1/child2}. + * + * @see #pathSeparator + * @see #path + */ + protected String fullPath; + + /** + * The UI class associated with the node. + * <p/> + * This class can be {@code null}, in that case, the {@link + * NavigationTreeNodeModelBuilder#defaultUIClass} will be used while building + * the model. + */ + protected Class<? extends JAXXObject> uIClass; + + /** + * The UI handler class associated with the node. + * <p/> + * This class can be {@code null}, in that case, the {@link + * NavigationTreeNodeModelBuilder#defaultUIHandlerClass} will be used while + * building the model. + */ + protected Class<? extends JAXXAction> uIHandlerClass; + + /** + * The context entry definition to retrieve the bean. + * <p/> + * <b>Note:</b> If not set - the {@code bean} will be retrieve on a ancestor + * node. + */ + protected JAXXContextEntryDef<?> jaxxContextEntryDef; + + /** + * The jxPath to process to obtain real {@code bean} from the data retrieve + * in the context. + * <p/> + * <b>Note:</b> If not set -no jxpath will be apply on the bean from + * context. + */ + protected String jaxxContextEntryPath; + + /** + * The bean associated with the node ( the value can be obtain via the + * method {@link #getBean(JAXXContext)} or directly set via method {@link + * #setBean(Object)}. + * <p/> + * cache of bean associated with bean to improve performance + */ + protected transient Object bean; + + /** + * The type of the related bean associated with the node. + * <p/> + * Note: This type is here to override the NodeRenderer internalClass, since + * we could need to override this data. + * <p/> + * If this property is let to null, then we will use the NodeRenderer one + */ + protected Class<?> internalClass; + +// public NavigationTreeTableNode(String pathSeparator, +// String navigationPath, +// Object jaxxContextEntryDef) { +// super(pathSeparator, navigationPath, jaxxContextEntryDef); +// } +// +// public NavigationTreeTableNode(String pathSeparator, +// String navigationPath, +// JAXXContextEntryDef<?> jaxxContextEntryDef, +// String jaxxContextEntryPath) { +// super(pathSeparator, +// navigationPath, +// jaxxContextEntryDef, +// jaxxContextEntryPath +// ); +// } + public NavigationTreeTableNode(String pathSeparator, String navigationPath, Object jaxxContextEntryDef) { - super(pathSeparator, navigationPath, jaxxContextEntryDef); + this.pathSeparator = pathSeparator; + path = navigationPath; + if (jaxxContextEntryDef instanceof JAXXContextEntryDef<?>) { + this.jaxxContextEntryDef = ((JAXXContextEntryDef<?>) jaxxContextEntryDef); + } else if (jaxxContextEntryDef instanceof String) { + jaxxContextEntryPath = (String) jaxxContextEntryDef; + } else if (jaxxContextEntryDef != null) { + // wrong context definition type + throw new IllegalArgumentException( + "to define a context link, must be a String (jxpath) or a " + JAXXContextEntryDef.class + ", but was " + jaxxContextEntryDef); + } } public NavigationTreeTableNode(String pathSeparator, String navigationPath, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath) { - super(pathSeparator, - navigationPath, - jaxxContextEntryDef, - jaxxContextEntryPath - ); + this.pathSeparator = pathSeparator; + path = navigationPath; + this.jaxxContextEntryDef = jaxxContextEntryDef; + this.jaxxContextEntryPath = jaxxContextEntryPath; } + /** @return the text node renderer (store in {@link #userObject} property. */ @Override + public NavigationTreeNodeRenderer getRenderer() { + NavigationTreeNodeRenderer render = null; + Object o = getUserObject(); + if (o != null && o instanceof NavigationTreeNodeRenderer) { + render = (NavigationTreeNodeRenderer) o; + } + return render; + } + + @Override + public void setRenderer(NavigationTreeNodeRenderer renderer) { + // clear all cache + bean = null; + setUserObject(renderer); + } + + @Override + public String getPathSeparator() { + return pathSeparator; + } + + @Override + public String getNodePath() { + return path; + } + + @Override + public void setNodePath(String navigationPath) { + path = navigationPath; + } + + @Override + public Class<? extends JAXXObject> getUIClass() { + return uIClass; + } + + @Override + public void setUIClass(Class<? extends JAXXObject> uIClass) { + this.uIClass = uIClass; + } + + @Override + public void setInternalClass(Class<?> internalClass) { + this.internalClass = internalClass; + } + + @Override + public Class<? extends JAXXAction> getUIHandlerClass() { + return uIHandlerClass; + } + + @Override + public void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass) { + this.uIHandlerClass = uIHandlerClass; + } + + @Override + public JAXXContextEntryDef<?> getJaxxContextEntryDef() { + return jaxxContextEntryDef; + } + + @Override + public void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef) { + this.jaxxContextEntryDef = jaxxContextEntryDef; + } + + @Override + public String getJaxxContextEntryPath() { + return jaxxContextEntryPath; + } + + @Override + public void setJaxxContextEntryPath(String jaxxContextEntryPath) { + this.jaxxContextEntryPath = jaxxContextEntryPath; + } + + @Override + public Class<?> getInternalClass() { + if (internalClass == null && getRenderer() != null) { + return getRenderer().getInternalClass(); + } + return internalClass; + } + + /** @return the fully context path of the node from the root node to this. */ + @Override + public String getFullPath() { + if (fullPath == null) { + StringBuilder sb = new StringBuilder(); + for (TreeNode treeNode : getPath()) { + NavigationTreeTableNode myNode = (NavigationTreeTableNode) treeNode; + sb.append(pathSeparator).append(myNode.getNodePath()); + } + fullPath = sb.substring(1); + } + return fullPath; + } + + /** + * @return the first ancestor with a none null {@link #jaxxContextEntryDef} + * or <code>null</code> if none find.. + */ + protected NavigationTreeTableNode getFirstAncestorWithDef() { + if (jaxxContextEntryDef != null) { + // find a node with a direct link with the context + return this; + } + // the node is not linked to context + // seek in his parent + NavigationTreeTableNode ancestor = getParent(); + return ancestor == null ? null : ancestor.getFirstAncestorWithDef(); + } + + protected String computeJXPath(String expr, NavigationTreeTableNode parentNode) { + if (equals(parentNode)) { + // reach the parent limit node, return the expr computed + return expr; + } + int firstIndex = expr.indexOf(".."); + int lastIndex = expr.lastIndexOf(".."); + if (firstIndex == -1) { + // this is a error, since current node is not parent limit node, + // we must find somewhere a way to go up in nodes + throw new IllegalArgumentException( + expr + " should contains at least one \"..\""); + } + if (firstIndex != 0) { + // this is a error, the ../ must be at the beginning of the expression + throw new IllegalArgumentException( + "\"..\" must be at the beginning but was : " + expr); + } + NavigationTreeTableNode ancestor = getParent(); + if (firstIndex == lastIndex) { + // found only one go up, so must be substitute by the parent node context + String newExpr = expr.substring(2); + //String newExpr = expr.substring(expr.startsWith("../") ? 3 : 2); + if (getParent().equals(parentNode)) { + // parent node is the final parent node, so no substitution needed + return newExpr; + } + // ancestor must have a jaxxContextEntryPath + if (ancestor.jaxxContextEntryPath == null) { + throw new IllegalArgumentException( + "with the expression " + expr + ", the ancestor node (" + + ancestor + ") must have a jaxxContextEntryPath " + + "definition, but was not "); + } + newExpr = ancestor.jaxxContextEntryPath + newExpr; + return ancestor.computeJXPath(newExpr, parentNode); + } + // have more than one go up, so the ancestor node can not have a + // jaxxContextEntryPath + if (ancestor.jaxxContextEntryPath != null) { + throw new IllegalArgumentException( + "with the expression " + expr + ", the ancestor node can " + + "not have a jaxxContextEntryPath definition"); + } + // substitute the last ..[/] and delegate to ancestor + String newExpr = expr.substring(0, lastIndex - 1) + + expr.substring( + lastIndex + + (expr.charAt(lastIndex + 3) == '/' ? 3 : 2) + ); + return ancestor.computeJXPath(newExpr, parentNode); + } + + + @Override + public Object getBean() { + return bean; + } + + @Override + public void setBean(Object bean) { + this.bean = bean; + } + + @Override + public void reload(JAXXContext context) { + + // clear bean cache + bean = null; + + // clear context navigation cache + fullPath = null; + + NavigationTreeNodeRenderer renderer = getRenderer(); + if (renderer == null) { + // this can't be ! + throw new NullPointerException( + "could not find the renderer for node " + this); + } + + String s = getFullPath(); + Object b = null; + try { + b = getBean(context); + } finally { + if (log.isInfoEnabled()) { + log.info("bean for path [" + s + "] = " + bean); + } + } + + renderer.reload(b); + } + + /** + * Obtain the associated bean value from context corresponding to node + * + * @param context the context to seek + * @return the value associated in context with the given context path + */ + @Override + public Object getBean(JAXXContext context) { + if (bean != null) { + // use cached bean + return bean; + } + Object result; + if (getJaxxContextEntryDef() != null && jaxxContextEntryPath == null) { + // the node maps directly a value in context, with no jxpath resolving + result = getJaxxContextEntryDef().getContextValue(context); + // save in cache + setBean(result); + return result; + } + // find the first ancestor node with a context def + NavigationTreeTableNode parentNode = getFirstAncestorWithDef(); + if (parentNode == null) { + log.warn("could not find a ancestor node with a definition of" + + " a context entry from node (" + this + ")"); + // todo must be an error + // no parent found + return null; + } + Object parentBean = parentNode.getJaxxContextEntryDef().getContextValue(context); + if (parentBean == null) { + // must be an error no bean found + log.warn("could not find a bean attached in context from context" + + " entry definition " + parentNode.getJaxxContextEntryDef()); + return null; + } + if (parentNode.jaxxContextEntryPath != null) { + // apply the jxpath on parentBean + JXPathContext jxcontext = JXPathContext.newContext(parentBean); + parentBean = jxcontext.getValue(parentNode.jaxxContextEntryPath); + } + // save in cache + parentNode.setBean(parentBean); + if (parentNode.equals(this)) { + // current node is the node matching the context entry value and + // no jxpath is found + return parentBean; + } + if (jaxxContextEntryPath == null) { + // todo must be an error + log.warn("must find a jaxxContextEntryPath on node (" + this + + ")"); + return null; + } + String jxpathExpression = computeJXPath(jaxxContextEntryPath, + parentNode); + if (jxpathExpression == null) { + /// todo must be an error + log.warn("could not build jxpath from node " + parentNode + + " to " + this); + // could not retreave the jxpath... + return null; + } + if (jxpathExpression.startsWith("[")) { + // special case when we want to access a collection + jxpathExpression = '.' + jxpathExpression; + } + if (log.isDebugEnabled()) { + log.debug("jxpath : " + jxpathExpression); + } + JXPathContext jxcontext = JXPathContext.newContext(parentBean); + result = jxcontext.getValue(jxpathExpression); + // save in cache + setBean(result); + return result; + } + + + @Override public NavigationTreeTableNode getChildAt(int index) { return (NavigationTreeTableNode) super.getChildAt(index); } @@ -75,14 +494,75 @@ } @Override - public abstract Object getValueAt(int column); + public Enumeration<? extends NavigationTreeTableNode> children() { + return (Enumeration<? extends NavigationTreeTableNode>) super.children(); + } @Override - public abstract int getColumnCount(); + public void insert(NavigationTreeTableNode child, int index) { + super.insert(child, index); + } @Override - public abstract boolean isEditable(int column); + public void remove(NavigationTreeTableNode node) { + super.remove(node); + } @Override - public abstract void setValueAt(Object aValue, int column); + public void setParent(NavigationTreeTableNode newParent) { + super.setParent(newParent); + } + + @Override + public int getIndex(NavigationTreeTableNode node) { + return super.getIndex(node); + } + + @Override + public void add(NavigationTreeTableNode node) { + super.add(node); + } + + @Override + public NavigationTreeTableNode[] getPath() { + return getPathToRoot(this, 0); + } + + @Override + public NavigationTreeTableNode[] getPathToRoot(NavigationTreeTableNode aNode, int depth) { + NavigationTreeTableNode[] retNodes; + + /* Check for null, in case someone passed in a null node, or + they passed in an element that isn't rooted at root. */ + if (aNode == null) { + if (depth == 0) { + return null; + } else { + retNodes = new NavigationTreeTableNode[depth]; + } + } else { + depth++; + retNodes = getPathToRoot(aNode.getParent(), depth); + retNodes[retNodes.length - depth] = aNode; + } + return retNodes; + } + + @Override + public boolean isRoot() { + return getParent() == null; + } + + // +// @Override +// public abstract Object getValueAt(int column); +// +// @Override +// public abstract int getColumnCount(); +// +// @Override +// public abstract boolean isEditable(int column); +// +// @Override +// public abstract void setValueAt(Object aValue, int column); } Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -1,63 +0,0 @@ -/* - * *##% - * JAXX Runtime - * Copyright (C) 2008 - 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * ##%* - */ -package jaxx.runtime.swing.navigation; - -import jaxx.runtime.JAXXAction; -import jaxx.runtime.JAXXObject; -import jaxx.runtime.context.JAXXContextEntryDef; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * This object is design to build a {@link NavigationTreeModel} with sorted - * nodes {@link SortedNavigationTreeNode} . - * - * @author sletellier - * @see NavigationModelBuilder - * @since 2.0.1 - */ -public class SortedNavigationTreeModelBuilder extends AbstractNavigationModelBuilder<SortedNavigationTreeNode> { - - /** Logger */ - static private final Log log = - LogFactory.getLog(SortedNavigationTreeModelBuilder.class); - - public SortedNavigationTreeModelBuilder( - Class<? extends JAXXObject> defaultUIClass, - Class<? extends JAXXAction> defaultUIHandlerClass, - NavigationModel<SortedNavigationTreeNode> navigationModel) { - super(defaultUIClass, defaultUIHandlerClass, navigationModel); - } - - @Override - public SortedNavigationTreeNode createNavigationTreeNode( - String pathSeparator, - String contextName, - JAXXContextEntryDef<?> jaxxContextEntryDef, - String jaxxContextEntryPath) { - return new SortedNavigationTreeNode( - pathSeparator, - contextName, - jaxxContextEntryDef, - jaxxContextEntryPath - ); - } -} Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -1,147 +0,0 @@ -/* - * *##% - * JAXX Runtime - * Copyright (C) 2008 - 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * ##%* - */ -package jaxx.runtime.swing.navigation; - -import jaxx.runtime.context.JAXXContextEntryDef; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.tree.MutableTreeNode; -import java.util.Collections; -import java.util.Comparator; -import java.util.Enumeration; -import java.util.List; - -/** - * Sprted node - * - * @author sletellier - * @see NavigationTreeNode - * @since 2.0.1 - */ -public class SortedNavigationTreeNode extends NavigationTreeNode { - - private static final long serialVersionUID = -1L; - - /** Logger */ - static private final Log log = - LogFactory.getLog(SortedNavigationTreeNode.class); - - @Override - public SortedNavigationTreeNode getChildAt(int index) { - return (SortedNavigationTreeNode) super.getChildAt(index); - } - - @Override - public SortedNavigationTreeNode getParent() { - return (SortedNavigationTreeNode) super.getParent(); - } - - @Override - public Enumeration<SortedNavigationTreeNode> children() { - return super.children(); - } - - @Override - public void add(MutableTreeNode newChild) { - - List<SortedNavigationTreeNode> children = - Collections.list(children()); - - if (children.isEmpty()) { - insert(newChild, 0); - return; - } - - SortedNavigationTreeNode newNode = (SortedNavigationTreeNode) newChild; - - children.add(newNode); - - Collections.sort(children, rendererDecorator); - int index = children.indexOf(newChild); - - log.info("Insert node : " + newNode.getRenderer().toString() + " in " + - index + " of parent " + this.getRenderer().toString()); - - insert(newChild, index); - } - - - public SortedNavigationTreeNode(String pathSeparator, - String navigationPath, - Object jaxxContextEntryDef) { - super(pathSeparator, navigationPath, jaxxContextEntryDef); -// sort(); - } - - public SortedNavigationTreeNode(String pathSeparator, - String navigationPath, - JAXXContextEntryDef<?> jaxxContextEntryDef, - String jaxxContextEntryPath) { - super(pathSeparator, - navigationPath, - jaxxContextEntryDef, - jaxxContextEntryPath - ); -// sort(); - } - -// public void sort() { -// List<SortedNavigationTreeNode> children = Collections.list(children()); -// -// if (children.isEmpty() || children.size() == 1){ -// return; -// } -// -// Collections.sort(children, rendererDecorator); -// -// if (children == null){ -// return; -// } -// -// Iterator<SortedNavigationTreeNode> childrenIterator = children.iterator(); -// if (childrenIterator != null){ -// removeAllChildren(); -// -// if (log.isDebugEnabled()){ -// log.debug("Adding " + children.size() + " children to parent " + getBean()); -// } -// while (childrenIterator.hasNext()) { -// SortedNavigationTreeNode childNode = childrenIterator.next(); -// childNode.sort(); -// add(childNode); -// } -// } -// } - - final Comparator<NavigationTreeNode> rendererDecorator = new Comparator<NavigationTreeNode>() { - @Override - public int compare(NavigationTreeNode o1, NavigationTreeNode o2) { - try { - String label1 = ((NavigationTreeNode) o1).getRenderer().toString(); - String label2 = ((NavigationTreeNode) o2).getRenderer().toString(); - return label1.compareToIgnoreCase(label2); - } catch (Exception eee) { - return 0; - } - } - }; -} Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java =================================================================== --- trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-03-26 11:34:09 UTC (rev 1810) @@ -46,7 +46,7 @@ @Test public void testFindNode() throws Exception { - NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, new DefaultJAXXContext(), null, null); + NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, new DefaultJAXXContext(), null, null); NavigationTreeNode rootNode = builder.build(null, (String) null, (String) null, ROOT_CONTEXT, null, null); @@ -60,7 +60,7 @@ } } - NavigationModel<?> model = builder.getModel(); + NavigationModel<NavigationTreeNode> model = builder.getModel(); NavigationTreeNode node; String contextPath; @@ -104,7 +104,7 @@ } /** - * Test the {@link NavigationTreeModel#getBean(String)}} with an entry point + * Test the {@link NavigationTreeNodeModel#getBean(String)}} with an entry point * as a bean. * <p/> * Tree is like this @@ -158,7 +158,7 @@ new Model("two", 2, Collections.<Model>emptyList()), new Model("three", 3, Collections.<Model>emptyList())))); - NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, context, null, null); + NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, context, null, null); NavigationTreeNode rootNode = builder.build(null, (String) null, (String) null, ROOT_CONTEXT, null, null); @@ -224,7 +224,7 @@ } /** - * Test the {@link NavigationTreeModel#getBean(String)} with an entry point + * Test the {@link NavigationTreeNodeModel#getBean(String)} with an entry point * as a list. * <p/> * Tree is like this @@ -279,7 +279,7 @@ context.setContextValue(list, "models"); - NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, context, null, null); + NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, context, null, null); NavigationTreeNode rootNode = builder.build(null, (String) null, (String) null, ROOT_CONTEXT, null, null); Modified: trunk/src/site/rst/NavigationModel.rst =================================================================== --- trunk/src/site/rst/NavigationModel.rst 2010-03-25 16:43:48 UTC (rev 1809) +++ trunk/src/site/rst/NavigationModel.rst 2010-03-26 11:34:09 UTC (rev 1810) @@ -22,7 +22,7 @@ Contrat representant le model de l'arbre de navigation. Les noeuds présents dans se modèle sont aussi typés en -*jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*. +*jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*. L'idée principale est de pouvoir associer à un noeud précis un chemin depuis la racine, ce que l'on appele *chemin de navigation*. @@ -33,7 +33,7 @@ Tout les models suivants implémantent cette interface. -jaxx.runtime.swing.navigation.NavigationTreeModel +jaxx.runtime.swing.navigation.NavigationTreeNodeModel ================================================= Il s'agit du modèle de l'arbre utilisé, c'est une extension d'un @@ -46,8 +46,8 @@ c'est une extension d'un *org.jdesktop.swingx.treetable.DefaultTreeTableModel*. Les noeuds présents dans se modèle sont typés en -*jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeTableNode* qui -étend *jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*. +*jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeTableNode* qui +étend *jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*. NavigationTreeTableNode est abstaite, l'instance doit donc être crée en implementant la méthode createNavigationTreeTableNode @@ -64,11 +64,11 @@ Tous les builders implémentent cette interface. -jaxx.runtime.swing.navigation.NavigationTreeModelBuilder +jaxx.runtime.swing.navigation.NavigationTreeNodeModelBuilder -------------------------------------------------------- Classe utilitaire pour construire le model (ici un -*jaxx.runtime.swing.navigation.NavigationTreeModel*) et décorer un arbre. +*jaxx.runtime.swing.navigation.NavigationTreeNodeModel*) et décorer un arbre. jaxx.runtime.swing.navigation.NavigationTreeTableModelBuilder ------------------------------------------------------------- @@ -114,7 +114,7 @@ ===================== Le noeud -(*jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*) est +(*jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*) est une extension d'un *javax.swing.tree.DefaultMutableTreeNode*. Il apporte les nouvelles propriétés suivantes :
participants (1)
-
tchemit@users.nuiton.org