Author: tchemit Date: 2010-03-26 19:05:31 +0100 (Fri, 26 Mar 2010) New Revision: 1814 Log: small refactor of navigation api Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContextHelper.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRenderer.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererDecoratorImpl.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererI18nImpl.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/AbstractNavigationHandler.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationHandler.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationMultiTreeHandler.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationOneClicSelectionHandler.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationTreeHandlerWithCardLayout.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeHelper.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModelBuilder.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeNode.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableHelper.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModelBuilder.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableNode.java Removed: 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/NavigationTreeNodeModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.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/DemoUIHandler.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/ActorContentUI.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 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/MovieContentUI.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 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/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/NavigationNode.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/package.html 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst 2010-03-26 18:05:31 UTC (rev 1814) @@ -15,12 +15,12 @@ Le développement est effectué dans le paquetage *jaxx.runtime.swing.navigation*. -jaxx.runtime.swing.navigation.NavigationTreeNodeModel +jaxx.runtime.swing.navigation.tree.NavigationTreeModel ================================================= 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.NavigationTreeNodeModel.NavigationTreeNode*. +Les noeuds présents dans ce modèle sont aussi typés en *jaxx.runtime.swing.navigation.tree.NavigationTreeModel.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.NavigationTreeNodeModel.NavigationTreeNode*) est une extension d'un *javax.swing.tree.DefaultMutableTreeNode*. +Le noeud (*jaxx.runtime.swing.navigation.tree.NavigationTreeModel.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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -28,7 +28,7 @@ /*@Test public void testGetClassDescriptor() throws Exception { - ClassDescriptorLoader.getClassDescriptor("jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode"); + ClassDescriptorLoader.getClassDescriptor("jaxx.runtime.swing.navigation.tree.NavigationTreeModel.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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -40,7 +40,13 @@ import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.swing.CardLayout2; import jaxx.runtime.swing.ErrorDialogUI; -import jaxx.runtime.swing.navigation.*; +import jaxx.runtime.swing.navigation.handler.AbstractNavigationHandler; +import jaxx.runtime.swing.navigation.handler.NavigationHandler; +import jaxx.runtime.swing.navigation.handler.NavigationTreeHandlerWithCardLayout; +import jaxx.runtime.swing.navigation.tree.NavigationTreeHelper; +import jaxx.runtime.swing.navigation.tree.NavigationTreeModel; +import jaxx.runtime.swing.navigation.tree.NavigationTreeModelBuilder; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -59,7 +65,7 @@ } @Override - public NavigationTreeNodeModel createTreeModel(JAXXContext context) { + public NavigationTreeModel createTreeModel(JAXXContext context) { if (log.isDebugEnabled()) { log.debug("start creating demo model"); @@ -126,7 +132,7 @@ addDemo(CounterDemo.class). addDemo(CalculatorDemo.class); - NavigationTreeNodeModel model = builder.getModel(); + NavigationTreeModel model = builder.getModel(); if (log.isDebugEnabled()) { builder.printModel(model.getRoot()); @@ -137,20 +143,20 @@ } @Override - public NavigationTreeHandler<NavigationTreeNode> createTreeHandler(JAXXObject context) { + public NavigationHandler<NavigationTreeNode> createTreeHandler(JAXXObject context) { - NavigationTreeHandler<NavigationTreeNode> handler; + NavigationHandler<NavigationTreeNode> handler; handler = new NavigationTreeHandlerWithCardLayout<NavigationTreeNode>( getPrefix(), context, - NavigationTreeHandler.Strategy.PER_UI_TYPE) { + NavigationHandler.Strategy.PER_UI_TYPE) { private static final long serialVersionUID = 1L; @Override - protected NavigationTreeNodeModel getNavigationTreeModel() { - return (NavigationTreeNodeModel) getModel(getContext()); + public NavigationTreeModel getNavigationTreeModel() { + return (NavigationTreeModel) getModel(getContext()); } @Override @@ -164,7 +170,7 @@ } @Override - protected void treateError(Exception e) { + public void treateError(Exception e) { ErrorDialogUI.showError(e); } @@ -174,14 +180,14 @@ } }; // on ne peut selectionner qu'un seul noeud a la fois - handler.setSelectionMode(NavigationTreeHandler.SINGLE_TREE_SELECTION); + handler.setSelectionMode(NavigationHandler.SINGLE_TREE_SELECTION); // save handler in ui context setTreeHandler(context, handler); return handler; } - static class TreeModelBuilder extends NavigationTreeNodeModelBuilder { + static class TreeModelBuilder extends NavigationTreeModelBuilder { /** la definition de l'unqiue object a partage */ static private final JAXXContextEntryDef<DemoConfig> def = Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -33,7 +33,7 @@ import jaxx.runtime.swing.editor.config.ConfigUIBuilder; import jaxx.runtime.swing.editor.config.model.ConfigUIModel; import jaxx.runtime.swing.editor.config.model.ConfigUIModelBuilder; -import jaxx.runtime.swing.navigation.NavigationTreeNode; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -27,6 +27,12 @@ import jaxx.runtime.swing.CardLayout2; import jaxx.runtime.swing.ErrorDialogUI; import jaxx.runtime.swing.navigation.*; +import jaxx.runtime.swing.navigation.handler.AbstractNavigationHandler; +import jaxx.runtime.swing.navigation.handler.NavigationHandler; +import jaxx.runtime.swing.navigation.handler.NavigationTreeHandlerWithCardLayout; +import jaxx.runtime.swing.navigation.tree.NavigationTreeHelper; +import jaxx.runtime.swing.navigation.tree.NavigationTreeModel; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,17 +47,6 @@ */ public class FullNavigationTreeHelper extends NavigationTreeHelper { -// static { -// // register decorator one for all -// -// DecoratorUtils.register( -// Movie.class.getSimpleName(), -// DecoratorUtils.newMultiJXPathDecorator(Movie.class, "${title}$s##${year}$s", "##", " - ")); -// -// DecoratorUtils.register( -// People.class.getSimpleName(), -// DecoratorUtils.newMultiJXPathDecorator(People.class, "${firstName}$s##${lastName}$s", "##", " ")); -// } /** * Logger */ @@ -95,7 +90,7 @@ } @Override - public NavigationTreeNodeModel createTreeModel(JAXXContext context) { + public NavigationTreeModel createTreeModel(JAXXContext context) { if (builder == null) { builder = new FullNavigationTreeModelBuilder(context); @@ -103,7 +98,7 @@ builder.createInitialModel(); - NavigationTreeNodeModel model = builder.getModel(); + NavigationTreeModel model = builder.getModel(); // save tree model in context setModel(context, model); @@ -111,23 +106,23 @@ } @Override - public NavigationTreeHandler createTreeHandler(JAXXObject context) { + public NavigationHandler<NavigationTreeNode> createTreeHandler(JAXXObject context) { if (log.isDebugEnabled()) { log.debug("create handler"); } - NavigationTreeHandler handler; + NavigationHandler<NavigationTreeNode> handler; - handler = new NavigationTreeHandlerWithCardLayout( + handler = new NavigationTreeHandlerWithCardLayout<NavigationTreeNode>( getPrefix(), context, - NavigationTreeHandler.Strategy.PER_UI_TYPE) { + NavigationHandler.Strategy.PER_UI_TYPE) { private static final long serialVersionUID = 1L; @Override - protected NavigationModel getNavigationTreeModel() { + public NavigationModel<NavigationTreeNode> getNavigationTreeModel() { return getSafeModel(getContext()); } @@ -142,7 +137,7 @@ } @Override - protected void treateError(Exception e) { + public void treateError(Exception e) { ErrorDialogUI.showError(e); } @@ -152,7 +147,7 @@ } }; // on ne peut selectionner qu'un seul noeud a la fois - handler.setSelectionMode(NavigationTreeHandler.SINGLE_TREE_SELECTION); + handler.setSelectionMode(NavigationHandler.SINGLE_TREE_SELECTION); // save handler in ui context setTreeHandler(context, handler); 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -27,24 +27,22 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.decorator.Decorator; import jaxx.runtime.decorator.DecoratorProvider; -import jaxx.runtime.swing.navigation.NavigationTreeNodeModelBuilder; -import jaxx.runtime.swing.navigation.NavigationTreeNode; +import jaxx.runtime.swing.navigation.tree.NavigationTreeModelBuilder; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import static org.nuiton.i18n.I18n._; import java.util.List; +import static org.nuiton.i18n.I18n._; + /** - * * @author chemit * @since 2.0.0 */ -public class FullNavigationTreeModelBuilder extends NavigationTreeNodeModelBuilder { +public class FullNavigationTreeModelBuilder extends NavigationTreeModelBuilder { - /** - * Logger - */ + /** Logger */ static private final Log log = LogFactory.getLog(FullNavigationTreeModelBuilder.class); protected FullNavigationTreeModelBuilder(JAXXContext context) { @@ -55,7 +53,7 @@ //TODO } - public void addActor(People people,Movie... movies) { + public void addActor(People people, Movie... movies) { //TODO } @@ -122,8 +120,8 @@ // construction du noeud avec les acteurs NavigationTreeNode actorsNode = build(rootNode, _("actors"), - FullNavigationTreeHelper.ACTORS, - "actors", ActorsContentUI.class, null); + FullNavigationTreeHelper.ACTORS, + "actors", ActorsContentUI.class, null); for (People p : actors) { // navigation path = $root/actors/p.id Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx 2010-03-26 18:05:31 UTC (rev 1814) @@ -21,7 +21,7 @@ <ContentUI superGenericType='People'> <script><![CDATA[ -import jaxx.runtime.swing.navigation.NavigationTreeNode; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; import jaxx.demo.component.jaxx.navigation.*; @Override Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 2010-03-26 18:05:31 UTC (rev 1814) @@ -23,7 +23,7 @@ <script><![CDATA[ import jaxx.demo.component.jaxx.navigation.*; import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer; -import jaxx.runtime.swing.navigation.NavigationTreeNode; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; @Override public void openUI(NavigationTreeNode node) throws Exception { 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2010-03-26 18:05:31 UTC (rev 1814) @@ -25,7 +25,7 @@ <script><![CDATA[ import jaxx.demo.component.jaxx.navigation.*; -import jaxx.runtime.swing.navigation.NavigationTreeNode; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; ContentUIHandler getHandler() { return getContextValue(ContentUIHandler.class); Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx 2010-03-26 18:05:31 UTC (rev 1814) @@ -21,7 +21,7 @@ <ContentUI superGenericType='Movie'> <script><![CDATA[ -import jaxx.runtime.swing.navigation.NavigationTreeNode; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; import jaxx.demo.component.jaxx.navigation.*; @Override Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 2010-03-26 18:05:31 UTC (rev 1814) @@ -23,7 +23,7 @@ <script><![CDATA[ import jaxx.demo.component.jaxx.navigation.*; import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer; -import jaxx.runtime.swing.navigation.NavigationTreeNode; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; @Override public void openUI(NavigationTreeNode node) throws Exception { Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -22,6 +22,9 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXObject; +import jaxx.runtime.swing.navigation.handler.NavigationHandler; +import jaxx.runtime.swing.navigation.tree.NavigationTreeHelper; +import jaxx.runtime.swing.navigation.tree.NavigationTreeModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXTreeTable; @@ -35,14 +38,14 @@ /** * Helper object associated to a given navigation tree system. * <p/> - * To helper is context safe (base on a {@link NavigationTreeContextHelper}. + * To helper is context safe (base on a {@link NavigationContextHelper}. * - * @author Letellier + * @author letellier <letellier@codelutin.com> * @param <E> type of nodes in model - * @see NavigationTreeNodeModel + * @see NavigationTreeModel * @since 2.0.1 */ -public abstract class AbstractNavigationHelper<E extends NavigationNode<E>> extends NavigationTreeContextHelper<E> { +public abstract class AbstractNavigationHelper<E extends NavigationNode<E>> extends NavigationContextHelper<E> { /** Logger */ static private final Log log = @@ -62,7 +65,7 @@ * @param context the context to associate with fresh handler * @return the new handler */ - public abstract NavigationTreeHandler createTreeHandler(JAXXObject context); + public abstract NavigationHandler<E> createTreeHandler(JAXXObject context); public AbstractNavigationHelper(String contextPrefix) { super(contextPrefix); Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -21,6 +21,7 @@ package jaxx.runtime.swing.navigation; import jaxx.runtime.JAXXContext; +import jaxx.runtime.swing.navigation.tree.NavigationTreeModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,38 +42,74 @@ * @since 2.0.1 */ public abstract class AbstractNavigationModel<E extends NavigationNode<E>> implements NavigationModel<E> { -//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); + static private final Log log = LogFactory.getLog(NavigationTreeModel.class); - final TreeModel delegate; + /** the delegate model */ + protected final TreeModel delegate; /** - * The path separator used to build the {@link NavigationTreeNode#fullPath}. + * The path separator used to build the {@link NavigationNode#getFullPath()}. * - * @see NavigationTreeNode#getNodePath() - * @see NavigationTreeNode#getFullPath() + * @see NavigationNode#getNodePath() + * @see NavigationNode#getFullPath() */ protected final String pathSeparator; /** Context to retrieve beans */ private JAXXContext context; - public AbstractNavigationModel(TreeModel delegate, String pathSeparator, JAXXContext context) { + public AbstractNavigationModel(TreeModel delegate, + String pathSeparator, + JAXXContext context) { this.pathSeparator = pathSeparator; this.context = context; this.delegate = delegate; } + //-------------------------------------------------------------------------- + // NavigationModel implementation + //-------------------------------------------------------------------------- + @Override + public JAXXContext getContext() { + return context; + } + + public TreeModel getDelegate() { + return delegate; + } + + @Override + public final String getPathSeparator() { + return pathSeparator; + } + + @Override public final E getRoot() { return (E) getDelegate().getRoot(); } @Override + public final Object getBean(String navigationPath) { + Object result; + E node = findNode(navigationPath, (Pattern) null); + result = getBean(node); + return result; + } + + @Override + public final 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 final E findNode(String path) { return findNode(getRoot(), path, (Pattern) null); } @@ -127,38 +164,6 @@ } @Override - public JAXXContext getContext() { - return context; - } - - public TreeModel getDelegate() { - return delegate; - } - - @Override - public final String getPathSeparator() { - return pathSeparator; - } - - @Override - public final Object getBean(String navigationPath) { - Object result; - E node = findNode(navigationPath, (Pattern) null); - result = getBean(node); - return result; - } - - @Override - public final 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 final void nodeChanged(E node) { nodeChanged(node, false); if (log.isDebugEnabled()) { 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -73,7 +73,7 @@ @Override public E buildEmptyRoot(JAXXContextEntryDef<?> entryDef, String contextName) { - E node = createNavigationTreeNode( + E node = createNavigationNode( model.getPathSeparator(), contextName, entryDef, @@ -91,7 +91,7 @@ String contextName, Class<? extends JAXXObject> uiClass, Class<? extends JAXXAction> actionClass) { - E node = createNavigationTreeNode( + E node = createNavigationNode( model.getPathSeparator(), contextName, entryDef, @@ -109,7 +109,7 @@ String contextName, Class<? extends JAXXObject> uiClass, Class<? extends JAXXAction> actionClass) { - E node = createNavigationTreeNode( + E node = createNavigationNode( model.getPathSeparator(), contextName, entryDef, @@ -127,7 +127,7 @@ String contextName, Class<? extends JAXXObject> uiClass, Class<? extends JAXXAction> actionClass) { - E node = createNavigationTreeNode( + E node = createNavigationNode( model.getPathSeparator(), contextName, null, @@ -146,7 +146,7 @@ String contextName, Class<? extends JAXXObject> uiClass, Class<? extends JAXXAction> actionClass) { - E node = createNavigationTreeNode( + E node = createNavigationNode( model.getPathSeparator(), contextName, entryDef, @@ -164,7 +164,7 @@ String contextName, Class<? extends JAXXObject> uiClass, Class<? extends JAXXAction> actionClass) { - E node = createNavigationTreeNode( + E node = createNavigationNode( model.getPathSeparator(), contextName, entryDef, @@ -182,7 +182,7 @@ String contextName, Class<? extends JAXXObject> uiClass, Class<? extends JAXXAction> actionClass) { - E node = createNavigationTreeNode( + E node = createNavigationNode( model.getPathSeparator(), contextName, null, @@ -212,12 +212,12 @@ @Override public void addI18nNodeRenderer(E node, String libelle) { - node.setRenderer(new NavigationTreeNodeRendererI18nImpl(libelle)); + node.setRenderer(new NavigationNodeRendererI18nImpl(libelle)); } @Override public void addDecoratorNodeRenderer(E node, Decorator<?> decorator) { - node.setRenderer(new NavigationTreeNodeRendererDecoratorImpl(decorator)); + node.setRenderer(new NavigationNodeRendererDecoratorImpl(decorator)); } @Override 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -20,6 +20,8 @@ */ package jaxx.runtime.swing.navigation; +import jaxx.runtime.swing.navigation.handler.NavigationHandler; + import java.awt.*; /** @@ -32,21 +34,21 @@ /** * Init the ui just before been opened by the method {@link - * NavigationTreeHandler#openUI(Component, NavigationNode)}. + * NavigationHandler#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, NavigationNode) + * @see NavigationHandler#openUI(Component, NavigationNode) */ void openUI(E node) throws Exception; /** * Clean the ui after been closed by the method {@link - * NavigationTreeHandler#closeUI(Component)}. + * NavigationHandler#closeUI(Component)}. * * @param node the selected node associated to the ui * @throws Exception if any pb when closing the content'sui - * @see NavigationTreeHandler#closeUI(Component) + * @see NavigationHandler#closeUI(Component) */ void closeUI(E node) throws Exception; } Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContextHelper.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContextHelper.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContextHelper.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,253 @@ +/* + * *##% + * 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.JAXXUtil; +import jaxx.runtime.context.JAXXContextEntryDef; +import jaxx.runtime.swing.navigation.handler.NavigationHandler; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTreeTable; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +/** + * To help getting and setting navigation tree objects from a {@link + * JAXXContext}. + * <p/> + * There is seven types of data which can be hold in a context : <ul> <li>tree : + * the tree </li> <li>tree-tablr : the jx tree table</li> <li>tree model : the + * navigation tree model</li> <li>tree handler : the navigation tree + * handler</li> <li>selected path : the navigation path of the selected + * node</li> <li>selected node : the selected node</li> <li>selected bean : the + * selected bean</li> </ul> + * <p/> + * To make possible the use of more than one navigation tree system in a same + * context, we <b>MUST</b> distinguish the context entries definition. For this + * purpose, entries definition are normalized and prefixed by a unique {@link + * #prefix}. + * <p/> + * Here is the keys mapping : <ul> <li>tree : {@code prefix + "-tree"}</li> + * <li>tree-table : {@code prefix + "-tree-table"}</li> <li>tree model : {@code + * prefix + "-tree-model"}</li> <li>tree handler : {@code prefix + + * "-tree-handler"}</li> <li>selected path : {@code prefix + + * "-selected-path"}</li> <li>selected node : {@code prefix + + * "-selected-node"}</li> <li>selected bean : {@code prefix + + * "-selected-bean"}</li> </ul> + * + * @author chemit + * @since 1.7.2 + */ +public class NavigationContextHelper<E extends NavigationNode<E>> { + + /** Logger */ + static private final Log log = LogFactory.getLog(NavigationContextHelper.class); + + protected final String prefix; + + protected JAXXContextEntryDef<List<String>> selectedPathsContextEntry; + + protected JAXXContextEntryDef<List<Object>> selectedBeansContextEntry; + + protected JAXXContextEntryDef<List<E>> selectedNodesContextEntry; + + protected JAXXContextEntryDef<NavigationModel<E>> modelContextEntry; + + protected JAXXContextEntryDef<NavigationHandler<E>> handlerContextEntry; + + protected JAXXContextEntryDef<JTree> treeContextEntry; + + protected JAXXContextEntryDef<JXTreeTable> treeTableContextEntry; + + public NavigationContextHelper(String prefix) { + this.prefix = prefix; + treeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree", JTree.class); + treeTableContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-table", JXTreeTable.class); + modelContextEntry = (JAXXContextEntryDef) JAXXUtil.newContextEntryDef(prefix + "-model", NavigationModel.class); + handlerContextEntry = (JAXXContextEntryDef) JAXXUtil.newContextEntryDef(prefix + "-handler", NavigationHandler.class); + selectedBeansContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-beans"); + selectedNodesContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-nodes"); + selectedPathsContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-paths"); + } + + public String getPrefix() { + return prefix; + } + + public JTree getTree(JAXXContext context) { + JTree r = getTreeContextEntry().getContextValue(context); + return r; + } + + public JXTreeTable getTreeTable(JAXXContext context) { + JXTreeTable r = getTreeTableContextEntry().getContextValue(context); + return r; + } + + public NavigationModel<E> getModel(JAXXContext context) { + NavigationModel<E> r = getModelContextEntry().getContextValue(context); + return r; + } + + public NavigationHandler<E> getTreeHandler(JAXXContext context) { + NavigationHandler<E> r = + getTreeHandlerContextEntry().getContextValue(context); + return r; + } + + public String getSelectedPath(JAXXContext context) { + String result = getSelectedValue(getSelectedPathContextEntry(), context); + return result; + } + + public List<String> getSelectedPaths(JAXXContext context) { + return getSelectedPathContextEntry().getContextValue(context); + } + + public E getSelectedNode(JAXXContext context) { + E result = getSelectedValue(getSelectedNodeContextEntry(), context); + return result; + } + + public List<E> getSelectedNodes(JAXXContext context) { + return getSelectedNodeContextEntry().getContextValue(context); + } + + public Object getSelectedBean(JAXXContext context) { + Object result = getSelectedValue(getSelectedBeanContextEntry(), context); + return result; + } + + public List<Object> getSelectedBeans(JAXXContext context) { + return getSelectedBeanContextEntry().getContextValue(context); + } + + public void setModel(JAXXContext context, NavigationModel<E> model) { + getModelContextEntry().setContextValue(context, model); + } + + public void setTree(JAXXContext context, JTree tree) { + getTreeContextEntry().setContextValue(context, tree); + } + + public void setTreeTable(JAXXContext context, JXTreeTable treeTable) { + getTreeTableContextEntry().setContextValue(context, treeTable); + } + + public void setTreeHandler(JAXXContext context, + NavigationHandler<E> handler) { + getTreeHandlerContextEntry().setContextValue(context, handler); + } + + public void setSelectedPath(JAXXContext context, String path) { + setSelectedValue(getSelectedPathContextEntry(), context, path); + } + + public void setSelectedPaths(JAXXContext context, List<String> paths) { + setSelectedValues(getSelectedPathContextEntry(), context, paths); + } + + public void setSelectedNode(JAXXContext context, E node) { + setSelectedValue(getSelectedNodeContextEntry(), context, node); + } + + public void setSelectedNodes(JAXXContext context, List<E> nodes) { + setSelectedValues(getSelectedNodeContextEntry(), context, nodes); + } + + public void setSelectedBean(JAXXContext context, Object bean) { + setSelectedValue(getSelectedBeanContextEntry(), context, bean); + } + + public void setSelectedBeans(JAXXContext context, List<Object> beans) { + setSelectedValues(getSelectedBeanContextEntry(), context, beans); + } + + protected JAXXContextEntryDef<NavigationModel<E>> getModelContextEntry() { + return modelContextEntry; + } + + protected JAXXContextEntryDef<NavigationHandler<E>> + getTreeHandlerContextEntry() { + return handlerContextEntry; + } + + protected JAXXContextEntryDef<List<Object>> getSelectedBeanContextEntry() { + return selectedBeansContextEntry; + } + + protected JAXXContextEntryDef<List<E>> getSelectedNodeContextEntry() { + return selectedNodesContextEntry; + } + + protected JAXXContextEntryDef<List<String>> getSelectedPathContextEntry() { + return selectedPathsContextEntry; + } + + protected JAXXContextEntryDef<JTree> getTreeContextEntry() { + return treeContextEntry; + } + + protected JAXXContextEntryDef<JXTreeTable> getTreeTableContextEntry() { + return treeTableContextEntry; + } + + protected <T> T getSelectedValue(JAXXContextEntryDef<List<T>> entry, + JAXXContext context) { + List<T> values = entry.getContextValue(context); + T result = null; + if (values != null && !values.isEmpty()) { + if (values.size() > 1) { + if (log.isWarnEnabled()) { + log.warn("There is " + values.size() + + " values selected, will return first one"); + } + } + result = values.get(0); + } + return result; + } + + protected <T> void setSelectedValue(JAXXContextEntryDef<List<T>> entry, + JAXXContext context, + T value) { + if (value == null) { + entry.removeContextValue(context); + } else { + List<T> selecteds = new ArrayList<T>(); + selecteds.add(value); + entry.setContextValue(context, selecteds); + } + } + + protected <T> void setSelectedValues(JAXXContextEntryDef<List<T>> entry, + JAXXContext context, + List<T> values) { + if (values == null || values.isEmpty()) { + entry.removeContextValue(context); + } else { + entry.setContextValue(context, values); + } + } +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContextHelper.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -21,6 +21,7 @@ package jaxx.runtime.swing.navigation; import jaxx.runtime.JAXXContext; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; import javax.swing.event.TreeModelListener; import javax.swing.tree.TreePath; @@ -29,13 +30,12 @@ /** * Interface to create model of the tree used for a navigation tree. * <p/> - * Il est composé de {@link NavigationTreeNode} + * Il est composé de {@link NavigationNode} * * @author sletellier * @since 2.0.0 */ -public interface NavigationModel<E extends NavigationNode<E>> { -//public interface NavigationModel<E extends NavigationNode<E>> extends TreeModel { +public interface NavigationModel<E extends NavigationNode<E>> { E getRoot(); @@ -54,8 +54,8 @@ * <pre>$root.child1.leaf1</pre> * * @param path the fully path of the searched node. - * @return the node matching the fully context from the root node, - * or <code>null</code> if not find. + * @return the node matching the fully context from the root node, or + * <code>null</code> if not find. */ E findNode(String path); @@ -113,14 +113,14 @@ * Apply first the regex pattern to obtain the searched node. * <p/> * Search then from a given root node a node named by his fully path - * (concatenation of nodes) {@link NavigationTreeNode#path} valued - * separated by {@link #getPathSeparator()}. + * (concatenation of nodes) {@link NavigationTreeNode#path} valued separated + * by {@link #getPathSeparator()}. * * @param root root node to be used * @param path the fully path of the searched node. * @param regex a previous regex to apply to path : must have a matches - * @return the node matching the fully context from the given root node, - * or <code>null</code> if not found. + * @return the node matching the fully context from the given root node, or + * <code>null</code> if not found. */ E findNode(E root, String path, String regex); @@ -134,16 +134,16 @@ * @param root root node to be used * @param path the fully path of the searched node. * @param regex a previous regex to apply to path : must have a matches - * @return the node matching the fully context from the given root node, - * or <code>null</code> if not found. + * @return the node matching the fully context from the given root node, or + * <code>null</code> if not found. */ E findNode(E root, String path, Pattern regex); JAXXContext getContext(); /** - * Obtain the associated bean value from context corresponding to node - * from given navigation path. + * Obtain the associated bean value from context corresponding to node from + * given navigation path. * * @param navigationPath the current context path of the node * @return the value associated in context with the given navigation path @@ -165,69 +165,64 @@ 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>)). + * 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> + * @param parent a node in the tree, obtained from this data source + * @param index index of the node + * @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. + * 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> + * @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. + * 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 + * @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 - */ + * 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. + * 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 + * @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 + * <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); @@ -236,21 +231,19 @@ // /** - * Adds a listener for the <code>TreeModelEvent</code> - * posted after the tree changes. + * Adds a listener for the {@code TreeModelEvent} posted after the tree + * changes. * - * @param l the listener to add - * @see #removeTreeModelListener + * @param l the listener to add + * @see #removeTreeModelListener */ void addTreeModelListener(TreeModelListener l); /** - * Removes a listener previously added with - * <code>addTreeModelListener</code>. + * Removes a listener previously added with {@code addTreeModelListener}. * - * @see #addTreeModelListener - * @param l the listener to remove + * @param l the listener to remove + * @see #addTreeModelListener */ 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -26,7 +26,7 @@ import jaxx.runtime.decorator.Decorator; /** - * Interface to create a builder, this object is design to build a {@link + * Contract to create a builder, this object is design to build a {@link * NavigationModel}. * * @author sletellier @@ -38,7 +38,7 @@ // To create your own instance of NavigationTreeTableNode - E createNavigationTreeNode( + E createNavigationNode( String pathSeparator, String contextName, JAXXContextEntryDef<?> jaxxContextEntryDef, @@ -92,10 +92,11 @@ E removeChildNode(E node); + void moveNode(E parentNode, E node, int position); + void addI18nNodeRenderer(E node, String libelle); - void addDecoratorNodeRenderer(E node, - Decorator<?> decorator); + void addDecoratorNodeRenderer(E node, Decorator<?> decorator); void addNodeJaxxClasses( E node, @@ -103,6 +104,4 @@ Class<? extends JAXXAction> uIHandlerClass); void printModel(E node); - - void moveNode(E parentNode, E node, int position); } 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -21,6 +21,8 @@ package jaxx.runtime.swing.navigation; +import jaxx.runtime.swing.navigation.handler.NavigationMultiTreeHandler; + import java.awt.*; import java.util.List; @@ -38,16 +40,17 @@ * * @param nodes the selected node associated to the ui * @throws Exception if any pb while opening the content's ui + * @see NavigationMultiTreeHandler#openUI(Component, List) */ void openUI(List<E> nodes) throws Exception; /** * Clean the ui after been closed by the method {@link - * NavigationTreeHandler#closeUI(Component)}. + * NavigationMultiTreeHandler#closeUI(Component)}. * * @param nodes the selected node associated to the ui * @throws Exception if any pb when closing the content'sui - * @see NavigationTreeHandler#closeUI(Component) + * @see NavigationMultiTreeHandler#closeUI(Component) */ void closeUI(List<E> nodes) throws Exception; } Deleted: 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,187 +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 javax.swing.event.TreeSelectionEvent; -import javax.swing.tree.TreePath; -import java.awt.*; -import java.util.ArrayList; -import java.util.List; - -/** - * The handler of a navigation tree. - * <p/> - * This is also the selection model to use, since we must check before moving - * from nodes we can not just listen selection model changed, we must control - * it. - * <p/> - * This one is used to enable multi selection - * - * @author sletellier - * @since 2.0.1 - */ -public abstract class NavigationMultiTreeHandler<E extends NavigationNode<E>> extends NavigationTreeHandler<E> { - - /** Logger */ - static private final Log log = - LogFactory.getLog(NavigationMultiTreeHandler.class); - - - public NavigationMultiTreeHandler(String contextPrefix, - JAXXObject context, - Strategy strategy) { - super(contextPrefix, context, strategy); - - // Enable multi selection - setSelectionMode(DISCONTIGUOUS_TREE_SELECTION); - } - - @Override - public void valueChanged(TreeSelectionEvent event) { - TreePath[] paths = event.getPaths(); - - // TODO : verifier que la selection n'est pas la même - List<E> nodes = new ArrayList<E>(); - if (paths == null) { - selectNodeUI(new ArrayList<E>()); - return; - } - for (TreePath path : paths) { - E node = (E) path.getLastPathComponent(); - nodes.add(node); - if (log.isDebugEnabled()) { - log.debug("Adding path : " + path); - log.debug("As node : " + node.getFullPath()); - } - } - selectNodeUI(nodes); - } - - /** - * Ouvre l'ui associée aux noeuds sélectionnés dans l'arbre de navigation. - * - * @param newUI l'ui associé au noeud sélectionné à ouvrir - * @param nodes les node de l'ui a ouvrir - * @throws Exception if any - */ - protected abstract void openUI(Component newUI, - List<E> nodes) - throws Exception; - - /** - * Instancie une nouvelle ui associé à des noeuds de l'arbre de navigation - * - * @param nodes les noeuds associés à l'ui à créer - * @return la nouvelle ui associée au noeud - * @throws Exception if any - */ - 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<E> nodes); - - protected void selectNodeUI(List<E> nodes) { - log.info("select nodes " + nodes); - - try { -// List<String> paths = new ArrayList<String>(); - List<Object> beans = new ArrayList<Object>(); - for (E node : nodes) { - - String path = node.getFullPath(); -// paths.add(path); - - if (log.isTraceEnabled()) { - log.trace(path); - } - // now, we are free to open the ui associated with the selected - // node in navigation - - // get the bean associated with the node - beans.add(getNavigationTreeModel().getBean(path)); - } - - Component newUI = getUI(nodes); - - // save it in context (must be done before init ui) - JAXXContext ctxt = getContext(); - NavigationTreeContextHelper<E> helper = getContextHelper(); - - // remove previous selected bean - //TODO-TC-20091004 should have an automatic clean context method - //TODO-TC-20091004 while - helper.setSelectedBean(ctxt, null); - -// if (beans != null) { - helper.setSelectedBeans(ctxt, beans); -// } - - if (newUI == null) { - - // a new ui instance is required - newUI = createUI(nodes); - } - - // save in context current node context path - helper.setSelectedPaths(ctxt, getPaths(nodes)); - - // save in context current node - helper.setSelectedNodes(ctxt, nodes); - - // save in context current ui -// helper.setSelectedUI(ctxt, newUI); - - // really open the ui associated with the selected node - // init ui before to be visible - if (newUI instanceof NavigationMultiContentUI<?>) { - ((NavigationMultiContentUI<E>) newUI).openUI(nodes); - } - - // set ui in content - openUI(newUI, nodes); - - } catch (Exception e) { - // remove data from context - - // if any error, go back to previvous node - treateError(e); - } - } - - protected List<String> getPaths(List<E> nodes) { - List<String> result = new ArrayList<String>(); - for (E node : nodes) { - result.add(node.getFullPath()); - } - return result; - } - -} Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -8,36 +8,29 @@ import java.io.Serializable; import java.util.Enumeration; +/** + * Contract of a navigation node. + * + * @author tchemit <chemit@codelutin.com> + * @param <E> type of the node + * @since 2.0.1 + */ 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); + NavigationNodeRenderer getRenderer(); 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(); @@ -50,24 +43,8 @@ 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); @@ -82,10 +59,40 @@ Object getUserObject(); - void add(E node); + E[] getPathToRoot(E aNode, int depth); - E[] getPathToRoot(E aNode, int depth) ; - E[] getPath(); + void setRenderer(NavigationNodeRenderer renderer); + + void setNodePath(String navigationPath); + + void setUIClass(Class<? extends JAXXObject> uIClass); + + void setInternalClass(Class<?> internalClass); + + void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass); + + void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef); + + void setJaxxContextEntryPath(String jaxxContextEntryPath); + + void setParent(E newParent); + + void setBean(Object bean); + + void setUserObject(Object object); + + void reload(JAXXContext context); + + void add(E node); + + void insert(E child, int index); + + void remove(int index); + + void remove(E node); + + void removeFromParent(); + } Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRenderer.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRenderer.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRenderer.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,62 @@ +/* + * *##% + * 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 javax.swing.tree.TreeCellRenderer; +import java.io.Serializable; + +/** + * Text Renderer of a {@link NavigationNode}. + * <p/> + * This object will be placed as the {@link NavigationNode#getUserObject()} of + * nodes. + * <p/> + * <p/> + * In that way, we can use the {@link #toString()} value to render the node + * without writing any {@link TreeCellRenderer}. + * <p/> + * To rebuild the renderer text of a node use the method {@link #reload(Object)} + * with the {@code bean} provides by the model for the node. + * + * @author chemit + * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear + * soon... + */ +public interface NavigationNodeRenderer extends Serializable { + + /** @return the render value of the node */ + @Override + String toString(); + + /** + * Can override the node internal class for display purpose. + * + * @return the type of data to be displayed. + */ + Class<?> getInternalClass(); + + /** + * Reload the render value from the {@code bean} of node. + * + * @param bean the bean associated to the node to render + */ + void reload(Object bean); +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRenderer.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererDecoratorImpl.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererDecoratorImpl.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererDecoratorImpl.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,72 @@ +/* + * *##% + * 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.decorator.Decorator; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; + +/** + * Decorator Renderer of a {@link NavigationTreeNode}. + * <p/> + * Apply a {@link Decorator} to the {@code bean} associated to the node. + * + * @author chemit + * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear + * soon... + */ +public class NavigationNodeRendererDecoratorImpl implements NavigationNodeRenderer { + + private static final long serialVersionUID = -1L; + + /** Decorator */ + protected final Decorator<?> decorator; + + /** internal class of representing data */ + protected final Class<?> internalClass; + + /** last renderered value */ + protected String text; + + public NavigationNodeRendererDecoratorImpl(Decorator<?> decorator) { + internalClass = decorator.getInternalClass(); + this.decorator = decorator; + } + + @Override + public String toString() { + return text; + } + + @Override + public void reload(Object bean) { + try { + text = decorator.toString(bean); + + } catch (Exception e) { + text = ""; + } + } + + @Override + public Class<?> getInternalClass() { + return internalClass; + } +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererDecoratorImpl.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererI18nImpl.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererI18nImpl.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererI18nImpl.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,68 @@ +/* + * *##% + * 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.swing.navigation.tree.NavigationTreeNode; + +import static org.nuiton.i18n.I18n._; + +/** + * I18n label Renderer of a {@link NavigationTreeNode}. + * <p/> + * Just apply a i18n translation on the given {@link #libelle}. + * + * @author chemit + * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear + * soon... + */ +public class NavigationNodeRendererI18nImpl implements NavigationNodeRenderer { + + private static final long serialVersionUID = -1L; + + /** Static i18n label to render */ + protected final String libelle; + + /** internal class of representing data */ + protected final Class<?> internalClass; + + /** last renderered value */ + protected String text; + + public NavigationNodeRendererI18nImpl(String libelle) { + this.libelle = libelle; + internalClass = String.class; + } + + @Override + public String toString() { + return text; + } + + @Override + public void reload(Object data) { + text = _(libelle); + } + + @Override + public Class<?> getInternalClass() { + return internalClass; + } +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererI18nImpl.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Deleted: 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,66 +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.JAXXObject; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.tree.TreePath; -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 nodes we can not just listen selection model changed, we must control - * it. - * <p/> - * This one is used to enable one clic multi selection - * - * @author sletellier - * @since 2.0.1 - */ -public abstract class NavigationOneClicSelectionHandler<E extends NavigationNode<E>> extends NavigationMultiTreeHandler<E> { - - /** Logger */ - static private final Log log = - LogFactory.getLog(NavigationOneClicSelectionHandler.class); - - - public NavigationOneClicSelectionHandler(String contextPrefix, - JAXXObject context, - Strategy strategy) { - super(contextPrefix, context, strategy); - } - - @Override - public void setSelectionPath(TreePath path) { - TreePath[] treePaths = getSelectionPaths(); - if (treePaths == null || !Arrays.asList(treePaths).contains(path)) { - addSelectionPath(path); - } else { - removeSelectionPath(path); - } - } - -} Deleted: 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,253 +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.JAXXUtil; -import jaxx.runtime.context.JAXXContextEntryDef; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jdesktop.swingx.JXTreeTable; - -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JTree; - -/** - * To help getting and setting navigation tree objects from a {@link JAXXContext}. - * <p/> - * There is seven types of data which can be hold in a context : - * <ul> - * <li>tree : the tree </li> - * <li>tree-tablr : the jx tree table</li> - * <li>tree model : the navigation tree model</li> - * <li>tree handler : the navigation tree handler</li> - * <li>selected path : the navigation path of the selected node</li> - * <li>selected node : the selected node</li> - * <li>selected bean : the selected bean</li> - * </ul> - * <p/> - * To make possible the use of more than one navigation tree system in a same - * context, we <b>MUST</b> distinguish the context entries definition. For this - * purpose, entries definition are normalized and prefixed by a unique {@link #prefix}. - * <p/> - * Here is the keys mapping : - * <ul> - * <li>tree : {@code prefix + "-tree"}</li> - * <li>tree-table : {@code prefix + "-tree-table"}</li> - * <li>tree model : {@code prefix + "-tree-model"}</li> - * <li>tree handler : {@code prefix + "-tree-handler"}</li> - * <li>selected path : {@code prefix + "-selected-path"}</li> - * <li>selected node : {@code prefix + "-selected-node"}</li> - * <li>selected bean : {@code prefix + "-selected-bean"}</li> - * </ul> - * - * @author chemit - * @since 1.7.2 - */ -public class NavigationTreeContextHelper <E extends NavigationNode<E>> { - - /** - * Logger - */ - static private final Log log = LogFactory.getLog(NavigationTreeContextHelper.class); - - protected final String prefix; - protected JAXXContextEntryDef<List<String>> selectedPathsContextEntry; - protected JAXXContextEntryDef<List<Object>> selectedBeansContextEntry; - protected JAXXContextEntryDef<List<E>> selectedNodesContextEntry; - protected JAXXContextEntryDef<NavigationModel<E>> modelContextEntry; - protected JAXXContextEntryDef<NavigationTreeHandler> handlerContextEntry; - protected JAXXContextEntryDef<JTree> treeContextEntry; - protected JAXXContextEntryDef<JXTreeTable> treeTableContextEntry; - - public NavigationTreeContextHelper(String prefix) { - this.prefix = prefix; - treeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree", JTree.class); - treeTableContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-table", JXTreeTable.class); - modelContextEntry = (JAXXContextEntryDef)JAXXUtil.newContextEntryDef(prefix + "-model", NavigationModel.class); - handlerContextEntry = JAXXUtil.newContextEntryDef(prefix + "-handler", NavigationTreeHandler.class); - selectedBeansContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-beans"); - selectedNodesContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-nodes"); - selectedPathsContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-paths"); - } - - public String getPrefix() { - return prefix; - } - - public JTree getTree(JAXXContext context) { - JTree r = getTreeContextEntry().getContextValue(context); - return r; - } - - public JXTreeTable getTreeTable(JAXXContext context) { - JXTreeTable r = getTreeTableContextEntry().getContextValue(context); - return r; - } - - public NavigationModel<E> getModel(JAXXContext context) { - NavigationModel<E> r = getModelContextEntry().getContextValue(context); - return r; - } - - public NavigationTreeHandler getTreeHandler(JAXXContext context) { - NavigationTreeHandler r = - getTreeHandlerContextEntry().getContextValue(context); - return r; - } - - public String getSelectedPath(JAXXContext context) { - String result = getSelectedValue(getSelectedPathContextEntry(),context); - return result; - } - - public List<String> getSelectedPaths(JAXXContext context) { - return getSelectedPathContextEntry().getContextValue(context); - } - - public E getSelectedNode(JAXXContext context) { - E result = getSelectedValue(getSelectedNodeContextEntry(),context); - return result; - } - - public List<E> getSelectedNodes(JAXXContext context) { - return getSelectedNodeContextEntry().getContextValue(context); - } - - public Object getSelectedBean(JAXXContext context) { - Object result = getSelectedValue(getSelectedBeanContextEntry(),context); - return result; - } - - public List<Object> getSelectedBeans(JAXXContext context) { - return getSelectedBeanContextEntry().getContextValue(context); - } - - public void setModel(JAXXContext context, NavigationModel<E> model) { - getModelContextEntry().setContextValue(context, model); - } - - public void setTree(JAXXContext context, JTree tree) { - getTreeContextEntry().setContextValue(context, tree); - } - - public void setTreeTable(JAXXContext context, JXTreeTable treeTable) { - getTreeTableContextEntry().setContextValue(context, treeTable); - } - - public void setTreeHandler(JAXXContext context, - NavigationTreeHandler handler) { - getTreeHandlerContextEntry().setContextValue(context, handler); - } - - public void setSelectedPath(JAXXContext context, String path) { - setSelectedValue(getSelectedPathContextEntry(), context, path); - } - - public void setSelectedPaths(JAXXContext context, List<String> paths) { - setSelectedValues(getSelectedPathContextEntry(), context, paths); - } - - public void setSelectedNode(JAXXContext context, E node) { - setSelectedValue(getSelectedNodeContextEntry(), context, node); - } - - public void setSelectedNodes(JAXXContext context, List<E> nodes) { - setSelectedValues(getSelectedNodeContextEntry(), context, nodes); - } - - public void setSelectedBean(JAXXContext context, Object bean) { - setSelectedValue(getSelectedBeanContextEntry(), context, bean); - } - - public void setSelectedBeans(JAXXContext context, List<Object> beans) { - setSelectedValues(getSelectedBeanContextEntry(), context, beans); - } - - protected JAXXContextEntryDef<NavigationModel<E>> getModelContextEntry() { - return modelContextEntry; - } - - protected JAXXContextEntryDef<NavigationTreeHandler> - getTreeHandlerContextEntry() { - return handlerContextEntry; - } - - protected JAXXContextEntryDef<List<Object>> getSelectedBeanContextEntry() { - return selectedBeansContextEntry; - } - - protected JAXXContextEntryDef<List<E>> getSelectedNodeContextEntry() { - return selectedNodesContextEntry; - } - - protected JAXXContextEntryDef<List<String>> getSelectedPathContextEntry() { - return selectedPathsContextEntry; - } - - protected JAXXContextEntryDef<JTree> getTreeContextEntry() { - return treeContextEntry; - } - - protected JAXXContextEntryDef<JXTreeTable> getTreeTableContextEntry() { - return treeTableContextEntry; - } - - protected <T> T getSelectedValue(JAXXContextEntryDef<List<T>> entry, - JAXXContext context) { - List<T> values = entry.getContextValue(context); - T result = null; - if (values != null && !values.isEmpty()) { - if (values.size() > 1) { - if (log.isWarnEnabled()) { - log.warn("There is " + values.size() + - " values selected, will return first one"); - } - } - result = values.get(0); - } - return result; - } - - protected <T> void setSelectedValue(JAXXContextEntryDef<List<T>> entry, - JAXXContext context, - T value) { - if (value == null) { - entry.removeContextValue(context); - } else { - List<T> selecteds = new ArrayList<T>(); - selecteds.add(value); - entry.setContextValue(context, selecteds); - } - } - - protected <T> void setSelectedValues(JAXXContextEntryDef<List<T>> entry, - JAXXContext context, - List<T> values) { - if (values == null || values.isEmpty()) { - entry.removeContextValue(context); - } else { - entry.setContextValue(context, values); - } - } -} Deleted: 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,342 +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.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. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.7.2 - */ -public abstract class NavigationTreeHandler<E extends NavigationNode<E>> extends DefaultTreeSelectionModel implements TreeSelectionListener { - - private static final long serialVersionUID = 1L; - - /** 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(NavigationNode)} - * returns the id of ui to use. - */ - public enum Strategy { - - /** instanciate a ui for a node */ - PER_NODE { - - @Override - public String getId(NavigationNode<?> node) { - return node.getFullPath(); - } - }, - /** - * instanciate only one a ui for a type,nodes will share the - * instanciation - */ - PER_UI_TYPE { - - @Override - public String getId(NavigationNode<?> node) { - return node.getUIClass().getName(); - } - }; - - public abstract String getId(NavigationNode<?> node); - } - - /** UI which contains navigation tree */ - protected JAXXContext context; - - /** UI Instanciation strategy */ - protected Strategy strategy; - - /** - * JAXXContext access helper. - * - * @since 1.7.2 - */ - protected NavigationTreeContextHelper<E> contextHelper; - - protected NavigationTreeHandler(String contextPrefix, JAXXObject context, Strategy strategy) { - contextHelper = new NavigationTreeContextHelper<E>(contextPrefix); - this.context = context; - this.strategy = strategy; - addTreeSelectionListener(this); - } - - @Override - public void valueChanged(TreeSelectionEvent event) { - if (log.isDebugEnabled()) { - log.debug("Value changed for path : " + event.getPath()); - log.debug("Old lead selection path : " + event.getOldLeadSelectionPath()); - } - if (event.getOldLeadSelectionPath() != null && event.getOldLeadSelectionPath().equals(event.getPath())) { - // do not treate this if no path changed - return; - } - E node = (E) event.getPath().getLastPathComponent(); - selectNodeUI(node); - } - - /** @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. - */ - protected abstract Component getCurrentUI(); - - /** - * @param node le noeud associé à l'ui à retrouver - * @return l'ui associé au novueau noeud sélectionné - */ - 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 - * @throws Exception if any - */ - protected abstract boolean closeUI(Component component) throws Exception; - - /** - * Instancie une nouvelle ui associé à un noeud de l'arbre de navigation - * - * @param node le noeud associé à l'ui à créer - * @return la nouvelle ui associée au noeud - * @throws Exception if any - */ - protected abstract Component createUI(E node) throws Exception; - - /** - * Ouvre l'ui associée au noeud sélectionné dans l'arbre de navigation. - * - * @param newUI l'ui associé au noeud sélectionné à ouvrir - * @param node le node de l'ui a ouvrir - * @throws Exception if any - */ - 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) - */ - protected abstract void treateError(Exception e); - - public JAXXContext getContext() { - return context; - } - - public NavigationTreeContextHelper<E> getContextHelper() { - return contextHelper; - } - - @Override - public void setSelectionPath(TreePath path) { - if (path.equals(getSelectionPath())) { - // stay on same node, can skip - if (log.isDebugEnabled()) { - log.debug("skip stay on path " + path); - } - return; - } - Component component = getCurrentUI(); - - try { - if (!closeUI(component)) { - if (log.isDebugEnabled()) { - log.debug("changing node canceled!"); - } - // can not changed current node - return; - } - if (component instanceof NavigationContentUI<?>) { - ((NavigationContentUI<E>) component).closeUI((E) path.getLastPathComponent()); - } - } catch (Exception ex) { - treateError(ex); - return; - } - if (log.isDebugEnabled()) { - log.debug("will select path " + path); - } - // ok can safely select the new path - super.setSelectionPath(path); - } - - @Override - public void setSelectionPaths(TreePath[] paths) { - //FIXME-TC20100315 this can not work... - // can't test like this paths as Array... - if (Arrays.equals(paths, getSelectionPaths())) { - // stay on same node, can skip - if (log.isDebugEnabled()) { - log.debug("skip stay on path " + Arrays.toString(paths)); - } - return; - } - Component component = getCurrentUI(); - - try { - if (!closeUI(component)) { - if (log.isDebugEnabled()) { - log.debug("changing node canceled!"); - } - // can not changed current node - return; - } - if (component instanceof NavigationMultiContentUI<?>) { - if (paths.length == 1) { - NavigationTreeContextHelper<E> helper = getContextHelper(); - ((NavigationMultiContentUI<E>) component).closeUI(helper.getSelectedNodes(getContext())); - } - } - } catch (Exception ex) { - treateError(ex); - return; - } - if (log.isDebugEnabled()) { - log.debug("will select " + paths.length + " paths"); - } - // ok can safely select the new path - super.setSelectionPaths(paths); - } - - protected void selectNodeUI(E node) { - - try { - - String path = node.getFullPath(); - - if (log.isTraceEnabled()) { - log.trace(path); - } - - Component newUI = getUI(node); - - // now, we are free to open the ui associated with the selected node in navigation - - // get the bean associated with the node - Object data = getNavigationTreeModel().getBean(path); - - // save it in context (must be done before init ui) - addSelectedBeanInContext(node, data); - - if (newUI == null) { - - // a new ui instance is required - newUI = createUI(node); - } - - JAXXContext ctxt = getContext(); - NavigationTreeContextHelper<E> helper = getContextHelper(); - - // save in context current node context path - helper.setSelectedPath(ctxt, node.getFullPath()); - - // save in context current node - helper.setSelectedNode(ctxt, node); - - // save in context current ui -// helper.setSelectedUI(ctxt, newUI); - - // really open the ui associated with the selected node - // init ui before to be visible - if (newUI instanceof NavigationContentUI<?>) { - ((NavigationContentUI<E>) newUI).openUI(node); - } - - // set ui in content - openUI(newUI, node); - - } catch (Exception e) { - // remove data from context - - // if any error, go back to previvous node - treateError(e); - } - } - - /** - * Prepare le context a utiliser pour initialiser une nouvelle ui. - * - * @param node le noeud associé à l'ui à créer - * @return le context à utiliser pour instancier l'ui - * @throws Exception if any - */ - protected JAXXContext createUIContext(E node) throws Exception { - - if (node.getUIHandlerClass() == null) { - if (log.isWarnEnabled()) { - log.warn("no action associated with ui " + node.getUIClass()); - } - // no action associated, just - return getContext(); - } - - JAXXAction action = node.getUIHandlerClass().newInstance(); - - // init context with - JAXXInitialContext uiContext = action.init(getContext()); - return uiContext; - } - - 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<E> helper = getContextHelper(); - - // remove previous selected bean - //TODO-TC-20091004 should have an automatic clean context method while - helper.setSelectedBean(ctxt, null); - - if (data != null) { - - helper.setSelectedBean(ctxt, data); - } - } -} Deleted: 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,131 +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 jaxx.runtime.swing.CardLayout2; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.*; -import java.awt.*; -import java.lang.reflect.Constructor; - -/** - * Simple {@link NavigationTreeHandler} implementation with a {@link - * CardLayout2} to manage components to associated with tree's nodes. - * <p/> - * For each node, the ui associated has a constraints in a cardlayout which is - * the node context path. - * <p/> - * A single container managed by the cardlayout is used to display the - * components associated with tree's nodes. - * - * @author chemit - */ -public abstract class NavigationTreeHandlerWithCardLayout<E extends NavigationNode<E>> extends NavigationTreeHandler<E> { - - /** Logger */ - static private final Log log = LogFactory.getLog(NavigationTreeHandlerWithCardLayout.class); - - /** - * All components associated with a tree's node is displayed in a single - * container. - * - * @return the containter of components - */ - protected abstract JPanel getContentContainer(); - - /** - * the cardlayout managing components associated with tree node. The - * constraints of each component is the node contextPath. - * - * @return the layout used to display components associated with tree's - * nodes. - */ - protected abstract CardLayout2 getContentLayout(); - - public NavigationTreeHandlerWithCardLayout(String contextPrefix, - JAXXObject context, - Strategy strategy) { - super(contextPrefix, context, strategy); - if (getContentContainer() == null) { - throw new IllegalArgumentException( - "could not have a null 'contentContainer' in ui " + context); - } - if (getContentLayout() == null) { - throw new IllegalArgumentException( - "could not have a null 'contentLayout' in ui " + context); - } - } - - @Override - protected Component getCurrentUI() { - CardLayout2 layout = getContentLayout(); - JPanel container = getContentContainer(); - return layout.getVisibleComponent(container); - } - - @Override - protected Component getUI(E node) { - CardLayout2 layout = getContentLayout(); - JPanel container = getContentContainer(); - String constraints = strategy.getId(node); - return layout.contains(constraints) ? - layout.getComponent(container, constraints) : null; - } - - @Override - protected void openUI(Component newUI, E node) throws - Exception { - - CardLayout2 layout = getContentLayout(); - JPanel container = getContentContainer(); - // switch layout - String constraints = strategy.getId(node); - layout.show(container, constraints); - } - - @Override - protected boolean closeUI(Component component) throws Exception { - // by default, we says that component was succesfull closed - return true; - } - - @Override - protected Component createUI(E node) throws Exception { - - JAXXContext uiContext = createUIContext(node); - - Constructor<? extends JAXXObject> constructor = - node.getUIClass().getConstructor(JAXXContext.class); - JAXXObject newUI = constructor.newInstance(uiContext); - - if (log.isDebugEnabled()) { - log.debug("instanciate new ui " + newUI); - } - String constraints = strategy.getId(node); - getContentContainer().add((Component) newUI, constraints); - return (Component) newUI; - } -} - Deleted: 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,37 +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; - -/** - * Helper object associated to a given navigation tree system. - * - * To helper is context safe (base on a {@link NavigationTreeContextHelper}. - * - * @author chemit - * @since 1.7.2 - * @see NavigationTreeNodeModel - */ -public abstract class NavigationTreeHelper extends AbstractNavigationHelper<NavigationTreeNode> { - - protected NavigationTreeHelper(String contextPrefix) { - super(contextPrefix); - } -} Deleted: 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,551 +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.jxpath.JXPathContext; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreeNode; -import java.util.Enumeration; - -/** - * 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> - * </ul> - * <p/> - * To retrieve the bean from the context, there is a huge logic in the method - * {@link #getBean(JAXXContext)}. - * <p/> - * In few words, if the {@link #jaxxContextEntryDef} is defined, it means that - * the object is taken from the {@code context}. - * <p/> - * Otherwise, find the first ancestor with an context entry and retrieve from - * here the bean. - * <p/> - * Then go down to the initial node by applying the jxpath expressions {@link - * #jaxxContextEntryPath} of each node on road back. - * <p/> - * <p/> - * To identify easly a node, each node has a {@link #path} and a {@link - * #fullPath} (full path from root node). - * <p/> - * <p/> - * To display the node we use a {@link NavigationTreeNodeRenderer} which is in - * fact the {@link #userObject}, the object can be synch with the bean via the - * {@link NavigationTreeNodeRenderer#reload(Object)} method. - * - * @author chemit - * @see NavigationTreeNodeModel - * @see NavigationTreeNodeRenderer - * @since 1.7.2 - */ -public class NavigationTreeNode extends DefaultMutableTreeNode implements NavigationNode<NavigationTreeNode> { - - private static final long serialVersionUID = 1L; - - /** Logger */ - static private final Log log = LogFactory.getLog(NavigationTreeNode.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 NavigationTreeNode(String pathSeparator, - String navigationPath, - Object 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 NavigationTreeNode(String pathSeparator, - String navigationPath, - JAXXContextEntryDef<?> jaxxContextEntryDef, - String 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()) { - NavigationTreeNode myNode = (NavigationTreeNode) treeNode; - sb.append(pathSeparator).append(myNode.getNodePath()); - } - fullPath = sb.substring(1); - } - return fullPath; - } - - @Override - public NavigationTreeNode getChildAt(int index) { - return (NavigationTreeNode) super.getChildAt(index); - } - - @Override - public NavigationTreeNode getParent() { - return (NavigationTreeNode) super.getParent(); - } - - /** - * @param path the name of the {@link #path} to be matched in the child of - * this node. - * @return the child of this node with given {@link #path} value. - */ - @Override - public NavigationTreeNode getChild(String path) { - Enumeration<? extends NavigationTreeNode> childs = children(); - while (childs.hasMoreElements()) { - NavigationTreeNode son = childs.nextElement(); - if (path.equals(son.getNodePath())) { - return son; - } - } - 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 - 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 - NavigationTreeNode 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 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.. - */ - protected NavigationTreeNode 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 - NavigationTreeNode ancestor = getParent(); - return ancestor == null ? null : ancestor.getFirstAncestorWithDef(); - } - - protected String computeJXPath(String expr, NavigationTreeNode 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); - } - NavigationTreeNode 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 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; - } -} Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,99 +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.TreeModel; -import javax.swing.tree.TreeNode; - -/** - * 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> implements TreeModel { - - /** Logger */ - private static final Log log = - LogFactory.getLog(NavigationTreeNodeModel.class); - -// private static final long serialVersionUID = 1L; - - public NavigationTreeNodeModel(String pathSeparator, JAXXContext context) { - super(new DefaultTreeModel(null), pathSeparator, context); - } -// -// @Override -// public NavigationTreeNode getRoot() { -// return (NavigationTreeNode) delegate.getRoot(); -// } - - @Override - public void setRoot(NavigationTreeNode root) { - getDelegate().setRoot(root); - } - - public DefaultTreeModel getDelegate() { - return (DefaultTreeModel) delegate; - } - - @Override - public NavigationTreeNode[] getPathToRoot(NavigationTreeNode aNode) { - TreeNode[] treeNodes = getDelegate().getPathToRoot(aNode); - NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length]; - System.arraycopy(treeNodes, 0, result, 0, treeNodes.length); - return result; - } - - @Override - public void removeNodeFromParent(NavigationTreeNode node) { - getDelegate().removeNodeFromParent(node); - } - - @Override - public void nodeStructureChanged(NavigationTreeNode node) { - NavigationTreeNode n = node; - //TC-20091004 never launch a deep reload - reload(n, true); - getDelegate().nodeStructureChanged(node); - if (log.isDebugEnabled()) { - log.debug(node); - } - } - - @Override - public void nodeChanged(NavigationTreeNode node, boolean deep) { - - NavigationTreeNode n = node; - //TC-20091004 never launch a deep clean, since we do a deep nodeChanged. - reload(n, deep); - getDelegate().nodeChanged(node); - } - - -} Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -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 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(); -// } -} Deleted: 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,65 +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 javax.swing.tree.TreeCellRenderer; -import java.io.Serializable; - -/** - * Text Renderer of a {@link NavigationNode}. - * <p/> - * This object will be placed as the {@link NavigationTreeNode#getUserObject()} of - * nodes. - * <p/> - * - * In that way, we can use the {@link #toString()} value to render the node - * without writing any {@link TreeCellRenderer}. - * <p/> - * To rebuild the renderer text of a node use the method {@link #reload(Object)} - * with the {@code bean} provides by the model for the node. - * - * @author chemit - * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear soon... - */ -public interface NavigationTreeNodeRenderer extends Serializable { - - /** - * - * @return the render value of the node - */ - @Override - String toString(); - - /** - * - * Can override the the node internal class for display purpose. - * - * @return the type of data to be displayed. - */ - Class<?> getInternalClass(); - - /** - * Reload the render value from the {@code bean} of node. - * - * @param bean the bean associated to the node to render - */ - void reload(Object bean); -} Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,71 +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.decorator.Decorator; - -/** - * Decorator Renderer of a {@link NavigationTreeNode}. - * <p/> - * Apply a {@link Decorator} to the {@code bean} associated to the node. - * - * @author chemit - * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear - * soon... - */ -public class NavigationTreeNodeRendererDecoratorImpl implements NavigationTreeNodeRenderer { - - private static final long serialVersionUID = -1L; - - /** Decorator */ - protected final Decorator<?> decorator; - - /** internal class of representing data */ - protected final Class<?> internalClass; - - /** last renderered value */ - protected String text; - - public NavigationTreeNodeRendererDecoratorImpl(Decorator<?> decorator) { - internalClass = decorator.getInternalClass(); - this.decorator = decorator; - } - - @Override - public String toString() { - return text; - } - - @Override - public void reload(Object bean) { - try { - text = decorator.toString(bean); - - } catch (Exception e) { - text = ""; - } - } - - @Override - public Class<?> getInternalClass() { - return internalClass; - } -} Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,68 +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 static org.nuiton.i18n.I18n._; - -/** - * I18n label Renderer of a {@link NavigationTreeNode}. - * - * Just apply a i18n translation on the given {@link #libelle}. - * - * @author chemit - * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear soon... - */ -public class NavigationTreeNodeRendererI18nImpl implements NavigationTreeNodeRenderer { - - private static final long serialVersionUID = -1L; - /** - * Static i18n label to render - */ - protected final String libelle; - /** - * internal class of representing data - */ - protected final Class<?> internalClass; - /** - * last renderered value - */ - protected String text; - - public NavigationTreeNodeRendererI18nImpl(String libelle) { - this.libelle = libelle; - internalClass = String.class; - } - - @Override - public String toString() { - return text; - } - - @Override - public void reload(Object data) { - text = _(libelle); - } - - @Override - public Class<?> getInternalClass() { - return internalClass; - } -} Deleted: 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,328 +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 org.jdesktop.swingx.tree.TreeModelSupport; -import org.jdesktop.swingx.treetable.DefaultTreeTableModel; -import org.jdesktop.swingx.treetable.TreeTableModel; - -import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; -import java.util.List; - -/** - * Model of the tree table used for a navigation tree table. - * <p/> - * Il est composé de {@link NavigationTreeNode} - * <p/> - * FIXME : Essayer d'enlever les copier coller {@link NavigationTreeNodeModel} - * - * @author sletellier - * @since 2.0.0 - */ -public class NavigationTreeTableModel extends AbstractNavigationModel<NavigationTreeTableNode> implements TreeTableModel { - -// static private final long serialVersionUID = 1L; - - /** Logger */ - static private final Log log = - LogFactory.getLog(NavigationTreeTableModel.class); - - public static class MyDefaultTreeTableModel extends DefaultTreeTableModel { - - public TreeModelSupport getModelSupport() { - return modelSupport; - } - } - -// /** -// * 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; - - protected List<String> columnsName; - - public NavigationTreeTableModel(String pathSeparator, JAXXContext context, List<String> columnsName) { - super(new MyDefaultTreeTableModel(), pathSeparator, context); -// this.pathSeparator = pathSeparator; -// this.context = context; - this.columnsName = columnsName; - } - - - public MyDefaultTreeTableModel getDelegate() { - return (MyDefaultTreeTableModel) delegate; - } - -// @Override -// public NavigationTreeTableNode getRoot() { -// return (NavigationTreeTableNode) getDelegate().getRoot(); -// } - - @Override - public NavigationTreeTableNode[] getPathToRoot(NavigationTreeTableNode aNode) { - if (aNode == null) { - return null; - } - TreeNode[] treeNodes = getDelegate().getPathToRoot(aNode); - NavigationTreeTableNode[] result = new NavigationTreeTableNode[treeNodes.length]; - System.arraycopy(treeNodes, 0, result, 0, treeNodes.length); - return result; - - } - - @Override - public void setRoot(NavigationTreeTableNode root) { - getDelegate().setRoot(root); -// this.root = root; - getModelSupport().fireNewRoot(); - } - - /** - * Message this to remove node from its parent. This will message - * nodesWereRemoved to create the appropriate event. This is the preferred - * way to remove a node as it handles the event creation for you. - */ - @Override - public void removeNodeFromParent(NavigationTreeTableNode node) { - NavigationTreeTableNode parent = node.getParent(); - - if (parent == null) { - throw new IllegalArgumentException("node does not have a parent."); - } - - int index = parent.getIndex(node); - node.removeFromParent(); - getModelSupport().fireChildRemoved(new TreePath(getPathToRoot(parent)), - index, node); - } - -// @Override -// public NavigationTreeTableNode findNode(String path) { -// return findNode(getRoot(), path, (Pattern) null); -// } -// -// @Override -// public NavigationTreeTableNode findNode(String path, String regex) { -// return findNode(getRoot(), path, regex); -// } -// -// @Override -// public NavigationTreeTableNode findNode(String path, Pattern regex) { -// return findNode(getRoot(), path, regex); -// } -// -// @Override -// public NavigationTreeTableNode findNode(NavigationTreeTableNode root, -// String path) { -// return findNode(root, path, (Pattern) null); -// } -// -// @Override -// public NavigationTreeTableNode findNode(NavigationTreeTableNode root, -// String path, -// String regex) { -// return findNode(root, path, regex == null ? -// null : Pattern.compile(regex)); -// } -// -// @Override -// public NavigationTreeTableNode findNode(NavigationTreeTableNode 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); -// NavigationTreeTableNode 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; -// NavigationTreeTableNode node = findNode(navigationPath, (Pattern) null); -// result = getBean(node); -// return result; -// } -// -// @Override -// public Object getBean(NavigationTreeTableNode node) { -// if (node == null) { -// return null; -// //fixme should throw a NPE exception -// //throw new NullPointerException("node can not be null"); -// } -// return node.getBean(getContext()); -// } - - - /** - * Accessor to tree model support. - * - * @return tree model support - */ - protected TreeModelSupport getModelSupport() { - return getDelegate().getModelSupport(); - } - -// @Override -// public void nodeChanged(NavigationTreeTableNode node) { -// if (node != null) { -// NavigationTreeTableNode parent = node.getParent(); -// NavigationTreeTableNode[] treeNodes = getPathToRoot(parent); -// if (treeNodes != null) { -// getModelSupport().fireChildChanged( -// new TreePath(treeNodes), parent.getIndex(node), node); -// } else { -// log.error("[Node changed] Path to root is null !"); -// } -// reload((NavigationTreeTableNode) node, true); -// } else { -// log.error("Node is null !"); -// } -// } - - @Override - public void nodeStructureChanged(NavigationTreeTableNode node) { - if (node != null) { - NavigationTreeTableNode parent = node.getParent(); - TreeNode[] treeNodes = getPathToRoot(parent); - if (treeNodes != null) { - getModelSupport().fireTreeStructureChanged(new TreePath(treeNodes)); - } else { - log.error("[Node structure changed] Path to root is null !"); - } - reload(node, true); - } else { - log.error("Node is null !"); - } - } - - @Override - public void nodeChanged(NavigationTreeTableNode node, boolean deep) { - if (node != null) { - NavigationTreeTableNode parent = node.getParent(); - TreeNode[] treeNodes = getPathToRoot(parent); - if (treeNodes != null) { - getModelSupport().fireChildChanged( - new TreePath(treeNodes), parent.getIndex(node), node); - } else { - log.error("[Node changed] Path to root is null !"); - } - reload(node, deep); - } else { - log.error("Node is null !"); - } - } -// -// @Override -// public String getPathSeparator() { -// return pathSeparator; -// } - - @Override - public Class<?> getColumnClass(int i) { - return getDelegate().getColumnClass(i); - } - - @Override - public int getColumnCount() { - return columnsName.size(); - } - - @Override - public String getColumnName(int column) { - return columnsName.get(column); - } - - @Override - public int getHierarchicalColumn() { - return getDelegate().getHierarchicalColumn(); - } - - @Override - public Object getValueAt(Object o, int i) { - return getDelegate().getValueAt(o, i); - } - - @Override - public boolean isCellEditable(Object o, int i) { - return getDelegate().isCellEditable(o, i); - } - - @Override - public void setValueAt(Object o, Object o1, int i) { - getDelegate().setValueAt(o, o1, i); - } -// -// protected void reload(NavigationTreeTableNode node) { -// reload(node, false); -// } -// -// protected void reload(NavigationTreeTableNode node, boolean deep) { -// if (node == null) { -// return; -// } -// node.reload(getContext()); -// -// if (deep) { -// Enumeration<?> childs = node.children(); -// while (childs.hasMoreElements()) { -// NavigationTreeTableNode o = (NavigationTreeTableNode) childs.nextElement(); -// reload(o, true); -// } -// } -// } - -} Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,29 +0,0 @@ -package jaxx.runtime.swing.navigation; - -import jaxx.runtime.JAXXAction; -import jaxx.runtime.JAXXObject; -import jaxx.runtime.context.JAXXContextEntryDef; - -public class NavigationTreeTableModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeTableNode> { - - public NavigationTreeTableModelBuilder( - Class<? extends JAXXObject> defaultUIClass, - Class<? extends JAXXAction> defaultUIHandlerClass, - NavigationModel<NavigationTreeTableNode> model) { - super(defaultUIClass, defaultUIHandlerClass, model); - } - - @Override - public NavigationTreeTableNode createNavigationTreeNode( - String pathSeparator, - String contextName, - JAXXContextEntryDef<?> jaxxContextEntryDef, - String jaxxContextEntryPath) { - return new NavigationTreeTableNode( - pathSeparator, - contextName, - jaxxContextEntryDef, - jaxxContextEntryPath - ); - } -} Deleted: 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,568 +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.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; - -/** - * Node of the {@link NavigationTreeTableModel}. - * - * @author sletellier - * @see NavigationTreeNode - * @since 2.0.0 - */ -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) { - 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) { - 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); - } - - @Override - public NavigationTreeTableNode getParent() { - return (NavigationTreeTableNode) super.getParent(); - } - - @Override - public NavigationTreeTableNode getChild(String path) { - Enumeration<?> childs = children(); - while (childs.hasMoreElements()) { - NavigationTreeTableNode son = - (NavigationTreeTableNode) childs.nextElement(); - if (path.equals(son.getNodePath())) { - return son; - } - } - return null; - } - - @Override - public Enumeration<? extends NavigationTreeTableNode> children() { - return (Enumeration<? extends NavigationTreeTableNode>) super.children(); - } - - @Override - public void insert(NavigationTreeTableNode child, int index) { - super.insert(child, index); - } - - @Override - public void remove(NavigationTreeTableNode node) { - super.remove(node); - } - - @Override - 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); -} Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/AbstractNavigationHandler.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/AbstractNavigationHandler.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/AbstractNavigationHandler.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,273 @@ +/* + * *##% + * 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.handler; + +import jaxx.runtime.JAXXAction; +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.context.JAXXInitialContext; +import jaxx.runtime.swing.navigation.NavigationContentUI; +import jaxx.runtime.swing.navigation.NavigationContextHelper; +import jaxx.runtime.swing.navigation.NavigationMultiContentUI; +import jaxx.runtime.swing.navigation.NavigationNode; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.event.TreeSelectionEvent; +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. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.7.2 + */ +public abstract class AbstractNavigationHandler<E extends NavigationNode<E>> extends DefaultTreeSelectionModel implements NavigationHandler<E> { + + private static final long serialVersionUID = 1L; + + /** Logger */ + static private final Log log = + LogFactory.getLog(AbstractNavigationHandler.class); + + /** UI which contains navigation tree */ + protected JAXXContext context; + + /** UI Instanciation strategy */ + protected Strategy strategy; + + /** + * JAXXContext access helper. + * + * @since 1.7.2 + */ + protected NavigationContextHelper<E> contextHelper; + + protected AbstractNavigationHandler(String contextPrefix, + JAXXObject context, + Strategy strategy) { + contextHelper = new NavigationContextHelper<E>(contextPrefix); + this.context = context; + this.strategy = strategy; + addTreeSelectionListener(this); + } + + @Override + public void valueChanged(TreeSelectionEvent event) { + if (log.isDebugEnabled()) { + log.debug("Value changed for path : " + event.getPath()); + log.debug("Old lead selection path : " + + event.getOldLeadSelectionPath()); + } + if (event.getOldLeadSelectionPath() != null && + event.getOldLeadSelectionPath().equals(event.getPath())) { + // do not treate this if no path changed + return; + } + E node = (E) event.getPath().getLastPathComponent(); + selectNodeUI(node); + } + + @Override + public JAXXContext getContext() { + return context; + } + + @Override + public NavigationContextHelper<E> getContextHelper() { + return contextHelper; + } + + @Override + public void setSelectionPath(TreePath path) { + if (path.equals(getSelectionPath())) { + // stay on same node, can skip + if (log.isDebugEnabled()) { + log.debug("skip stay on path " + path); + } + return; + } + Component component = getCurrentUI(); + + try { + if (!closeUI(component)) { + if (log.isDebugEnabled()) { + log.debug("changing node canceled!"); + } + // can not changed current node + return; + } + if (component instanceof NavigationContentUI<?>) { + ((NavigationContentUI<E>) component).closeUI((E) path.getLastPathComponent()); + } + } catch (Exception ex) { + treateError(ex); + return; + } + if (log.isDebugEnabled()) { + log.debug("will select path " + path); + } + // ok can safely select the new path + super.setSelectionPath(path); + } + + @Override + public void setSelectionPaths(TreePath[] paths) { + //FIXME-TC20100315 this can not work... + // can't test like this paths as Array... + if (Arrays.equals(paths, getSelectionPaths())) { + // stay on same node, can skip + if (log.isDebugEnabled()) { + log.debug("skip stay on path " + Arrays.toString(paths)); + } + return; + } + Component component = getCurrentUI(); + + try { + if (!closeUI(component)) { + if (log.isDebugEnabled()) { + log.debug("changing node canceled!"); + } + // can not changed current node + return; + } + if (component instanceof NavigationMultiContentUI<?>) { + if (paths.length == 1) { + NavigationContextHelper<E> helper = getContextHelper(); + ((NavigationMultiContentUI<E>) component).closeUI(helper.getSelectedNodes(getContext())); + } + } + } catch (Exception ex) { + treateError(ex); + return; + } + if (log.isDebugEnabled()) { + log.debug("will select " + paths.length + " paths"); + } + // ok can safely select the new path + super.setSelectionPaths(paths); + } + + protected void selectNodeUI(E node) { + + try { + + String path = node.getFullPath(); + + if (log.isTraceEnabled()) { + log.trace(path); + } + + Component newUI = getUI(node); + + // now, we are free to open the ui associated with the selected node in navigation + + // get the bean associated with the node + Object data = getNavigationTreeModel().getBean(path); + + // save it in context (must be done before init ui) + addSelectedBeanInContext(node, data); + + if (newUI == null) { + + // a new ui instance is required + newUI = createUI(node); + } + + JAXXContext ctxt = getContext(); + NavigationContextHelper<E> helper = getContextHelper(); + + // save in context current node context path + helper.setSelectedPath(ctxt, node.getFullPath()); + + // save in context current node + helper.setSelectedNode(ctxt, node); + + // save in context current ui +// helper.setSelectedUI(ctxt, newUI); + + // really open the ui associated with the selected node + // init ui before to be visible + if (newUI instanceof NavigationContentUI<?>) { + ((NavigationContentUI<E>) newUI).openUI(node); + } + + // set ui in content + openUI(newUI, node); + + } catch (Exception e) { + // remove data from context + + // if any error, go back to previvous node + treateError(e); + } + } + + /** + * Prepare le context a utiliser pour initialiser une nouvelle ui. + * + * @param node le noeud associé à l'ui à créer + * @return le context à utiliser pour instancier l'ui + * @throws Exception if any + */ + protected JAXXContext createUIContext(E node) throws Exception { + + if (node.getUIHandlerClass() == null) { + if (log.isWarnEnabled()) { + log.warn("no action associated with ui " + node.getUIClass()); + } + // no action associated, just + return getContext(); + } + + JAXXAction action = node.getUIHandlerClass().newInstance(); + + // init context with + JAXXInitialContext uiContext = action.init(getContext()); + return uiContext; + } + + 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(); + NavigationContextHelper<E> helper = getContextHelper(); + + // remove previous selected bean + //TODO-TC-20091004 should have an automatic clean context method while + helper.setSelectedBean(ctxt, null); + + if (data != null) { + + helper.setSelectedBean(ctxt, data); + } + } +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/AbstractNavigationHandler.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationHandler.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationHandler.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationHandler.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,109 @@ +package jaxx.runtime.swing.navigation.handler; + +import jaxx.runtime.JAXXContext; +import jaxx.runtime.swing.navigation.NavigationContextHelper; +import jaxx.runtime.swing.navigation.NavigationModel; +import jaxx.runtime.swing.navigation.NavigationNode; + +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.TreePath; +import javax.swing.tree.TreeSelectionModel; +import java.awt.*; +import java.io.Serializable; + +public interface NavigationHandler<E extends NavigationNode<E>> extends Cloneable, Serializable, TreeSelectionModel, TreeSelectionListener { + + /** + * Strategy of instanciation of ui. + * <p/> + * For a given {@code node}, the method {@link #getId(NavigationNode)} + * returns the id of ui to use. + */ + enum Strategy { + + /** instanciate a ui for a node */ + PER_NODE { + + @Override + public String getId(NavigationNode<?> node) { + return node.getFullPath(); + } + }, + /** + * instanciate only one a ui for a type,nodes will share the + * instanciation + */ + PER_UI_TYPE { + + @Override + public String getId(NavigationNode<?> node) { + return node.getUIClass().getName(); + } + }; + + public abstract String getId(NavigationNode<?> node); + } + + JAXXContext getContext(); + + /** @return le modèle de navigation associé */ + NavigationModel<E> getNavigationTreeModel(); + + /** + * @return le composent actuellement visible associé au noeud courant ou au + * noeud précédent lors d'un changement de noeud. + */ + Component getCurrentUI(); + + /** + * @param node le noeud associé à l'ui à retrouver + * @return l'ui associé au novueau noeud sélectionné + */ + 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 + * @throws Exception if any + */ + boolean closeUI(Component component) throws Exception; + + /** + * Instancie une nouvelle ui associé à un noeud de l'arbre de navigation + * + * @param node le noeud associé à l'ui à créer + * @return la nouvelle ui associée au noeud + * @throws Exception if any + */ + Component createUI(E node) throws Exception; + + /** + * Ouvre l'ui associée au noeud sélectionné dans l'arbre de navigation. + * + * @param newUI l'ui associé au noeud sélectionné à ouvrir + * @param node le node de l'ui a ouvrir + * @throws Exception if any + */ + void openUI(Component newUI, E node) throws Exception; + + /** + * Traitement des exceptions. + * + * @param e l'erreur recontrée (ou null si pas d"erreur) + */ + void treateError(Exception e); + + + @Override + void valueChanged(TreeSelectionEvent event); + + NavigationContextHelper<E> getContextHelper(); + + @Override + void setSelectionPath(TreePath path); + + @Override + void setSelectionPaths(TreePath[] paths); +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationHandler.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationMultiTreeHandler.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationMultiTreeHandler.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationMultiTreeHandler.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,189 @@ +/* + * *##% + * 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.handler; + +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.swing.navigation.NavigationContextHelper; +import jaxx.runtime.swing.navigation.NavigationMultiContentUI; +import jaxx.runtime.swing.navigation.NavigationNode; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.event.TreeSelectionEvent; +import javax.swing.tree.TreePath; +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +/** + * The handler of a navigation tree. + * <p/> + * This is also the selection model to use, since we must check before moving + * from nodes we can not just listen selection model changed, we must control + * it. + * <p/> + * This one is used to enable multi selection + * + * @author sletellier + * @since 2.0.1 + */ +public abstract class NavigationMultiTreeHandler<E extends NavigationNode<E>> extends AbstractNavigationHandler<E> { + + /** Logger */ + static private final Log log = + LogFactory.getLog(NavigationMultiTreeHandler.class); + + + public NavigationMultiTreeHandler(String contextPrefix, + JAXXObject context, + Strategy strategy) { + super(contextPrefix, context, strategy); + + // Enable multi selection + setSelectionMode(DISCONTIGUOUS_TREE_SELECTION); + } + + @Override + public void valueChanged(TreeSelectionEvent event) { + TreePath[] paths = event.getPaths(); + + // TODO : verifier que la selection n'est pas la même + List<E> nodes = new ArrayList<E>(); + if (paths == null) { + selectNodeUI(new ArrayList<E>()); + return; + } + for (TreePath path : paths) { + E node = (E) path.getLastPathComponent(); + nodes.add(node); + if (log.isDebugEnabled()) { + log.debug("Adding path : " + path); + log.debug("As node : " + node.getFullPath()); + } + } + selectNodeUI(nodes); + } + + /** + * Ouvre l'ui associée aux noeuds sélectionnés dans l'arbre de navigation. + * + * @param newUI l'ui associé au noeud sélectionné à ouvrir + * @param nodes les node de l'ui a ouvrir + * @throws Exception if any + */ + protected abstract void openUI(Component newUI, List<E> nodes) + throws Exception; + + /** + * Instancie une nouvelle ui associé à des noeuds de l'arbre de navigation + * + * @param nodes les noeuds associés à l'ui à créer + * @return la nouvelle ui associée au noeud + * @throws Exception if any + */ + 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<E> nodes); + + protected void selectNodeUI(List<E> nodes) { + log.info("select nodes " + nodes); + + try { +// List<String> paths = new ArrayList<String>(); + List<Object> beans = new ArrayList<Object>(); + for (E node : nodes) { + + String path = node.getFullPath(); +// paths.add(path); + + if (log.isTraceEnabled()) { + log.trace(path); + } + // now, we are free to open the ui associated with the selected + // node in navigation + + // get the bean associated with the node + beans.add(getNavigationTreeModel().getBean(path)); + } + + Component newUI = getUI(nodes); + + // save it in context (must be done before init ui) + JAXXContext ctxt = getContext(); + NavigationContextHelper<E> helper = getContextHelper(); + + // remove previous selected bean + //TODO-TC-20091004 should have an automatic clean context method + //TODO-TC-20091004 while + helper.setSelectedBean(ctxt, null); + +// if (beans != null) { + helper.setSelectedBeans(ctxt, beans); +// } + + if (newUI == null) { + + // a new ui instance is required + newUI = createUI(nodes); + } + + // save in context current node context path + helper.setSelectedPaths(ctxt, getPaths(nodes)); + + // save in context current node + helper.setSelectedNodes(ctxt, nodes); + + // save in context current ui +// helper.setSelectedUI(ctxt, newUI); + + // really open the ui associated with the selected node + // init ui before to be visible + if (newUI instanceof NavigationMultiContentUI<?>) { + ((NavigationMultiContentUI<E>) newUI).openUI(nodes); + } + + // set ui in content + openUI(newUI, nodes); + + } catch (Exception e) { + // remove data from context + + // if any error, go back to previvous node + treateError(e); + } + } + + protected List<String> getPaths(List<E> nodes) { + List<String> result = new ArrayList<String>(); + for (E node : nodes) { + result.add(node.getFullPath()); + } + return result; + } + +} Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationOneClicSelectionHandler.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationOneClicSelectionHandler.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationOneClicSelectionHandler.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,67 @@ +/* + * *##% + * 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.handler; + +import jaxx.runtime.JAXXObject; +import jaxx.runtime.swing.navigation.NavigationNode; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.tree.TreePath; +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 nodes we can not just listen selection model changed, we must control + * it. + * <p/> + * This one is used to enable one clic multi selection + * + * @author sletellier + * @since 2.0.1 + */ +public abstract class NavigationOneClicSelectionHandler<E extends NavigationNode<E>> extends NavigationMultiTreeHandler<E> { + + /** Logger */ + static private final Log log = + LogFactory.getLog(NavigationOneClicSelectionHandler.class); + + + public NavigationOneClicSelectionHandler(String contextPrefix, + JAXXObject context, + Strategy strategy) { + super(contextPrefix, context, strategy); + } + + @Override + public void setSelectionPath(TreePath path) { + TreePath[] treePaths = getSelectionPaths(); + if (treePaths == null || !Arrays.asList(treePaths).contains(path)) { + addSelectionPath(path); + } else { + removeSelectionPath(path); + } + } + +} Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationTreeHandlerWithCardLayout.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationTreeHandlerWithCardLayout.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationTreeHandlerWithCardLayout.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,132 @@ +/* + * *##% + * 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.handler; + +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.swing.CardLayout2; +import jaxx.runtime.swing.navigation.NavigationNode; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.*; +import java.awt.*; +import java.lang.reflect.Constructor; + +/** + * Simple {@link AbstractNavigationHandler} implementation with a {@link + * CardLayout2} to manage components to associated with tree's nodes. + * <p/> + * For each node, the ui associated has a constraints in a cardlayout which is + * the node context path. + * <p/> + * A single container managed by the cardlayout is used to display the + * components associated with tree's nodes. + * + * @author chemit + */ +public abstract class NavigationTreeHandlerWithCardLayout<E extends NavigationNode<E>> extends AbstractNavigationHandler<E> { + + /** Logger */ + static private final Log log = + LogFactory.getLog(NavigationTreeHandlerWithCardLayout.class); + + /** + * All components associated with a tree's node is displayed in a single + * container. + * + * @return the containter of components + */ + protected abstract JPanel getContentContainer(); + + /** + * the cardlayout managing components associated with tree node. The + * constraints of each component is the node contextPath. + * + * @return the layout used to display components associated with tree's + * nodes. + */ + protected abstract CardLayout2 getContentLayout(); + + public NavigationTreeHandlerWithCardLayout(String contextPrefix, + JAXXObject context, + Strategy strategy) { + super(contextPrefix, context, strategy); + if (getContentContainer() == null) { + throw new IllegalArgumentException( + "could not have a null 'contentContainer' in ui " + context); + } + if (getContentLayout() == null) { + throw new IllegalArgumentException( + "could not have a null 'contentLayout' in ui " + context); + } + } + + @Override + public Component getCurrentUI() { + CardLayout2 layout = getContentLayout(); + JPanel container = getContentContainer(); + return layout.getVisibleComponent(container); + } + + @Override + public Component getUI(E node) { + CardLayout2 layout = getContentLayout(); + JPanel container = getContentContainer(); + String constraints = strategy.getId(node); + return layout.contains(constraints) ? + layout.getComponent(container, constraints) : null; + } + + @Override + public void openUI(Component newUI, E node) throws Exception { + + CardLayout2 layout = getContentLayout(); + JPanel container = getContentContainer(); + // switch layout + String constraints = strategy.getId(node); + layout.show(container, constraints); + } + + @Override + public boolean closeUI(Component component) throws Exception { + // by default, we says that component was succesfull closed + return true; + } + + @Override + public Component createUI(E node) throws Exception { + + JAXXContext uiContext = createUIContext(node); + + Constructor<? extends JAXXObject> constructor = + node.getUIClass().getConstructor(JAXXContext.class); + JAXXObject newUI = constructor.newInstance(uiContext); + + if (log.isDebugEnabled()) { + log.debug("instanciate new ui " + newUI); + } + String constraints = strategy.getId(node); + getContentContainer().add((Component) newUI, constraints); + return (Component) newUI; + } +} + Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationTreeHandlerWithCardLayout.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/package.html =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/package.html 2010-03-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/package.html 2010-03-26 18:05:31 UTC (rev 1814) @@ -1,12 +1,12 @@ <html> - <body> - <h1>JAXX - tree utilities</h1> +<body> +<h1>JAXX - tree utilities</h1> - This package contains all the classes of the navigation tree framework. +This package contains all the classes of the navigation tree framework. - <p> - Replace the previous framework from package - <code>jaxx.runtime.swing.navigation</code> - </p> - </body> -</html> \ No newline at end of file +<p> + Replace the previous framework from package + <code>jaxx.runtime.swing.navigation</code> +</p> +</body> +</html> Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeHelper.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeHelper.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeHelper.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -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.tree; + +import jaxx.runtime.swing.navigation.AbstractNavigationHelper; +import jaxx.runtime.swing.navigation.NavigationContextHelper; + +/** + * Helper object associated to a given navigation tree system. + * <p/> + * To helper is context safe (base on a {@link NavigationContextHelper}. + * + * @author chemit + * @see NavigationTreeModel + * @since 1.7.2 + */ +public abstract class NavigationTreeHelper extends AbstractNavigationHelper<NavigationTreeNode> { + + protected NavigationTreeHelper(String contextPrefix) { + super(contextPrefix); + } +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeHelper.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModel.java (from rev 1813, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModel.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModel.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,93 @@ +/* + * *##% + * 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.tree; + +import jaxx.runtime.JAXXContext; +import jaxx.runtime.swing.navigation.AbstractNavigationModel; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeModel; +import javax.swing.tree.TreeNode; + +/** + * 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 AbstractNavigationModel<NavigationTreeNode> implements TreeModel { + + /** Logger */ + private static final Log log = + LogFactory.getLog(NavigationTreeModel.class); + + public NavigationTreeModel(String pathSeparator, JAXXContext context) { + super(new DefaultTreeModel(null), pathSeparator, context); + } + + @Override + public void setRoot(NavigationTreeNode root) { + getDelegate().setRoot(root); + } + + public DefaultTreeModel getDelegate() { + return (DefaultTreeModel) super.getDelegate(); + } + + @Override + public NavigationTreeNode[] getPathToRoot(NavigationTreeNode aNode) { + TreeNode[] treeNodes = getDelegate().getPathToRoot(aNode); + NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length]; + System.arraycopy(treeNodes, 0, result, 0, treeNodes.length); + return result; + } + + @Override + public void removeNodeFromParent(NavigationTreeNode node) { + getDelegate().removeNodeFromParent(node); + } + + @Override + public void nodeStructureChanged(NavigationTreeNode node) { + NavigationTreeNode n = node; + //TC-20091004 never launch a deep reload + reload(n, true); + getDelegate().nodeStructureChanged(node); + if (log.isDebugEnabled()) { + log.debug(node); + } + } + + @Override + public void nodeChanged(NavigationTreeNode node, boolean deep) { + + NavigationTreeNode n = node; + //TC-20091004 never launch a deep clean, since we do a deep nodeChanged. + reload(n, deep); + getDelegate().nodeChanged(node); + } + + +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModel.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModelBuilder.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModelBuilder.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,81 @@ +/* + * *##% + * 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.tree; + +import jaxx.runtime.JAXXAction; +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.context.JAXXContextEntryDef; +import jaxx.runtime.swing.navigation.AbstractNavigationModelBuilder; +import jaxx.runtime.swing.navigation.NavigationModelBuilder; +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) + ); + } + + public NavigationTreeModelBuilder( + Class<? extends JAXXObject> defaultUIClass, + Class<? extends JAXXAction> defaultUIHandlerClass, + NavigationTreeModel model) { + super(defaultUIClass, defaultUIHandlerClass, model); + } + + @Override + public NavigationTreeNode createNavigationNode( + String pathSeparator, + String contextName, + JAXXContextEntryDef<?> jaxxContextEntryDef, + String jaxxContextEntryPath) { + return new NavigationTreeNode( + pathSeparator, + contextName, + jaxxContextEntryDef, + jaxxContextEntryPath + ); + } + + @Override + public NavigationTreeModel getModel() { + return (NavigationTreeModel) super.getModel(); + } +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModelBuilder.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeNode.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeNode.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeNode.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,556 @@ +/* + * *##% + * 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.tree; + +import jaxx.runtime.JAXXAction; +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.context.JAXXContextEntryDef; +import jaxx.runtime.swing.navigation.NavigationNode; +import jaxx.runtime.swing.navigation.NavigationNodeRenderer; +import org.apache.commons.jxpath.JXPathContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreeNode; +import java.util.Enumeration; + +/** + * Node of the {@link NavigationTreeModel}. + * <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> + * </ul> + * <p/> + * To retrieve the bean from the context, there is a huge logic in the method + * {@link #getBean(JAXXContext)}. + * <p/> + * In few words, if the {@link #jaxxContextEntryDef} is defined, it means that + * the object is taken from the {@code context}. + * <p/> + * Otherwise, find the first ancestor with an context entry and retrieve from + * here the bean. + * <p/> + * Then go down to the initial node by applying the jxpath expressions {@link + * #jaxxContextEntryPath} of each node on road back. + * <p/> + * <p/> + * To identify easly a node, each node has a {@link #path} and a {@link + * #fullPath} (full path from root node). + * <p/> + * <p/> + * To display the node we use a {@link NavigationNodeRenderer} + * which is in fact the {@link #userObject}, the object can be synch with the + * bean via the {@link NavigationNodeRenderer#reload(Object)} + * method. + * + * @author chemit + * @see NavigationTreeModel + * @see NavigationNodeRenderer + * @since 1.7.2 + */ +public class NavigationTreeNode extends DefaultMutableTreeNode implements NavigationNode<NavigationTreeNode> { + + private static final long serialVersionUID = 1L; + + /** Logger */ + static private final Log log = LogFactory.getLog(NavigationTreeNode.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 + * NavigationTreeModelBuilder#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 + * NavigationTreeModelBuilder#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 NavigationTreeNode(String pathSeparator, + String navigationPath, + Object 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 NavigationTreeNode(String pathSeparator, + String navigationPath, + JAXXContextEntryDef<?> jaxxContextEntryDef, + String jaxxContextEntryPath) { + this.pathSeparator = pathSeparator; + path = navigationPath; + this.jaxxContextEntryDef = jaxxContextEntryDef; + this.jaxxContextEntryPath = jaxxContextEntryPath; + } + + /** @return the text node renderer (store in {@link #userObject} property. */ + @Override + public NavigationNodeRenderer getRenderer() { + NavigationNodeRenderer render = null; + Object o = getUserObject(); + if (o != null && o instanceof NavigationNodeRenderer) { + render = (NavigationNodeRenderer) o; + } + return render; + } + + @Override + public void setRenderer(NavigationNodeRenderer 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()) { + NavigationTreeNode myNode = (NavigationTreeNode) treeNode; + sb.append(pathSeparator).append(myNode.getNodePath()); + } + fullPath = sb.substring(1); + } + return fullPath; + } + + @Override + public NavigationTreeNode getChildAt(int index) { + return (NavigationTreeNode) super.getChildAt(index); + } + + @Override + public NavigationTreeNode getParent() { + return (NavigationTreeNode) super.getParent(); + } + + /** + * @param path the name of the {@link #path} to be matched in the child of + * this node. + * @return the child of this node with given {@link #path} value. + */ + @Override + public NavigationTreeNode getChild(String path) { + Enumeration<? extends NavigationTreeNode> childs = children(); + while (childs.hasMoreElements()) { + NavigationTreeNode son = childs.nextElement(); + if (path.equals(son.getNodePath())) { + return son; + } + } + 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 + bean = null; + + // clear context navigation cache + fullPath = null; + + NavigationNodeRenderer 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 + NavigationTreeNode 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 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(); + } + + @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; + } + + /** + * @return the first ancestor with a none null {@link #jaxxContextEntryDef} + * or <code>null</code> if none find.. + */ + protected NavigationTreeNode 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 + NavigationTreeNode ancestor = getParent(); + return ancestor == null ? null : ancestor.getFirstAncestorWithDef(); + } + + protected String computeJXPath(String expr, NavigationTreeNode 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); + } + NavigationTreeNode 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); + } +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeNode.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: svn:mergeinfo + Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableHelper.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableHelper.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableHelper.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,41 @@ +/* + * *##% + * 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.treetable; + +import jaxx.runtime.swing.navigation.AbstractNavigationHelper; +import jaxx.runtime.swing.navigation.NavigationContextHelper; +import jaxx.runtime.swing.navigation.tree.NavigationTreeModel; + +/** + * Helper object associated to a given navigation tree table system. + * <p/> + * To helper is context safe (base on a {@link NavigationContextHelper}. + * + * @author chemit + * @see NavigationTreeModel + * @since 1.7.2 + */ +public abstract class NavigationTreeTableHelper extends AbstractNavigationHelper<NavigationTreeTableNode> { + + protected NavigationTreeTableHelper(String contextPrefix) { + super(contextPrefix); + } +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableHelper.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java (from rev 1813, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,186 @@ +/* + * *##% + * 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.treetable; + +import jaxx.runtime.JAXXContext; +import jaxx.runtime.swing.navigation.AbstractNavigationModel; +import jaxx.runtime.swing.navigation.tree.NavigationTreeModel; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.tree.TreeModelSupport; +import org.jdesktop.swingx.treetable.DefaultTreeTableModel; +import org.jdesktop.swingx.treetable.TreeTableModel; + +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; +import java.util.List; + +/** + * Model of the tree table used for a navigation tree table. + * <p/> + * Il est composé de {@link NavigationTreeNode} + * <p/> + * FIXME : Essayer d'enlever les copier coller {@link NavigationTreeModel} + * + * @author sletellier + * @since 2.0.0 + */ +public class NavigationTreeTableModel extends AbstractNavigationModel<NavigationTreeTableNode> implements TreeTableModel { + + /** Logger */ + static private final Log log = + LogFactory.getLog(NavigationTreeTableModel.class); + + public static class MyDefaultTreeTableModel extends DefaultTreeTableModel { + + public TreeModelSupport getModelSupport() { + return modelSupport; + } + } + + protected List<String> columnsName; + + public NavigationTreeTableModel(String pathSeparator, JAXXContext context, List<String> columnsName) { + super(new MyDefaultTreeTableModel(), pathSeparator, context); + this.columnsName = columnsName; + } + + + public MyDefaultTreeTableModel getDelegate() { + return (MyDefaultTreeTableModel) delegate; + } + + @Override + public NavigationTreeTableNode[] getPathToRoot(NavigationTreeTableNode aNode) { + if (aNode == null) { + return null; + } + TreeNode[] treeNodes = getDelegate().getPathToRoot(aNode); + NavigationTreeTableNode[] result = new NavigationTreeTableNode[treeNodes.length]; + System.arraycopy(treeNodes, 0, result, 0, treeNodes.length); + return result; + + } + + @Override + public void setRoot(NavigationTreeTableNode root) { + getDelegate().setRoot(root); + getModelSupport().fireNewRoot(); + } + + /** + * Message this to remove node from its parent. This will message + * nodesWereRemoved to create the appropriate event. This is the preferred + * way to remove a node as it handles the event creation for you. + */ + @Override + public void removeNodeFromParent(NavigationTreeTableNode node) { + NavigationTreeTableNode parent = node.getParent(); + + if (parent == null) { + throw new IllegalArgumentException("node does not have a parent."); + } + + int index = parent.getIndex(node); + node.removeFromParent(); + getModelSupport().fireChildRemoved(new TreePath(getPathToRoot(parent)), + index, node); + } + + /** + * Accessor to tree model support. + * + * @return tree model support + */ + protected TreeModelSupport getModelSupport() { + return getDelegate().getModelSupport(); + } + + @Override + public void nodeStructureChanged(NavigationTreeTableNode node) { + if (node != null) { + NavigationTreeTableNode parent = node.getParent(); + TreeNode[] treeNodes = getPathToRoot(parent); + if (treeNodes != null) { + getModelSupport().fireTreeStructureChanged(new TreePath(treeNodes)); + } else { + log.error("[Node structure changed] Path to root is null !"); + } + reload(node, true); + } else { + log.error("Node is null !"); + } + } + + @Override + public void nodeChanged(NavigationTreeTableNode node, boolean deep) { + if (node != null) { + NavigationTreeTableNode parent = node.getParent(); + TreeNode[] treeNodes = getPathToRoot(parent); + if (treeNodes != null) { + getModelSupport().fireChildChanged( + new TreePath(treeNodes), parent.getIndex(node), node); + } else { + log.error("[Node changed] Path to root is null !"); + } + reload(node, deep); + } else { + log.error("Node is null !"); + } + } + + @Override + public Class<?> getColumnClass(int i) { + return getDelegate().getColumnClass(i); + } + + @Override + public int getColumnCount() { + return columnsName.size(); + } + + @Override + public String getColumnName(int column) { + return columnsName.get(column); + } + + @Override + public int getHierarchicalColumn() { + return getDelegate().getHierarchicalColumn(); + } + + @Override + public Object getValueAt(Object o, int i) { + return getDelegate().getValueAt(o, i); + } + + @Override + public boolean isCellEditable(Object o, int i) { + return getDelegate().isCellEditable(o, i); + } + + @Override + public void setValueAt(Object o, Object o1, int i) { + getDelegate().setValueAt(o, o1, i); + } + +} Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModelBuilder.java (from rev 1812, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModelBuilder.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,51 @@ +package jaxx.runtime.swing.navigation.treetable; + +import jaxx.runtime.JAXXAction; +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.context.JAXXContextEntryDef; +import jaxx.runtime.swing.navigation.AbstractNavigationModelBuilder; + +import java.util.List; + +public class NavigationTreeTableModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeTableNode> { + + + public NavigationTreeTableModelBuilder( + String pathSeparator, + JAXXContext context, + Class<? extends JAXXObject> defaultUIClass, + Class<? extends JAXXAction> defaultUIHandlerClass, + List<String> columnsName) { + this(defaultUIClass, + defaultUIHandlerClass, + new NavigationTreeTableModel(pathSeparator, context, columnsName) + ); + } + + public NavigationTreeTableModelBuilder( + Class<? extends JAXXObject> defaultUIClass, + Class<? extends JAXXAction> defaultUIHandlerClass, + NavigationTreeTableModel model) { + super(defaultUIClass, defaultUIHandlerClass, model); + } + + @Override + public NavigationTreeTableNode createNavigationNode( + String pathSeparator, + String contextName, + JAXXContextEntryDef<?> jaxxContextEntryDef, + String jaxxContextEntryPath) { + return new NavigationTreeTableNode( + pathSeparator, + contextName, + jaxxContextEntryDef, + jaxxContextEntryPath + ); + } + + @Override + public NavigationTreeTableModel getModel() { + return (NavigationTreeTableModel) super.getModel(); + } +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModelBuilder.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableNode.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableNode.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableNode.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -0,0 +1,552 @@ +/* + * *##% + * 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.treetable; + +import jaxx.runtime.JAXXAction; +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.context.JAXXContextEntryDef; +import jaxx.runtime.swing.navigation.NavigationNode; +import jaxx.runtime.swing.navigation.NavigationNodeRenderer; +import jaxx.runtime.swing.navigation.tree.NavigationTreeModelBuilder; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; +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; + +/** + * Node of the {@link NavigationTreeTableModel}. + * + * @author sletellier + * @see NavigationTreeNode + * @since 2.0.0 + */ +public class NavigationTreeTableNode extends DefaultMutableTreeTableNode implements 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 + * NavigationTreeModelBuilder#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 + * NavigationTreeModelBuilder#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) { + 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) { + this.pathSeparator = pathSeparator; + path = navigationPath; + this.jaxxContextEntryDef = jaxxContextEntryDef; + this.jaxxContextEntryPath = jaxxContextEntryPath; + } + + /** @return the text node renderer (store in {@link #userObject} property. */ + @Override + public NavigationNodeRenderer getRenderer() { + NavigationNodeRenderer render = null; + Object o = getUserObject(); + if (o != null && o instanceof NavigationNodeRenderer) { + render = (NavigationNodeRenderer) o; + } + return render; + } + + @Override + public void setRenderer(NavigationNodeRenderer 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; + + NavigationNodeRenderer 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); + } + + @Override + public NavigationTreeTableNode getParent() { + return (NavigationTreeTableNode) super.getParent(); + } + + @Override + public NavigationTreeTableNode getChild(String path) { + Enumeration<?> childs = children(); + while (childs.hasMoreElements()) { + NavigationTreeTableNode son = + (NavigationTreeTableNode) childs.nextElement(); + if (path.equals(son.getNodePath())) { + return son; + } + } + return null; + } + + @Override + public Enumeration<? extends NavigationTreeTableNode> children() { + return (Enumeration<? extends NavigationTreeTableNode>) super.children(); + } + + @Override + public void insert(NavigationTreeTableNode child, int index) { + super.insert(child, index); + } + + @Override + public void remove(NavigationTreeTableNode node) { + super.remove(node); + } + + @Override + 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; + } + +} 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-26 14:57:07 UTC (rev 1813) +++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-03-26 18:05:31 UTC (rev 1814) @@ -23,6 +23,9 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXUtil; import jaxx.runtime.context.DefaultJAXXContext; +import jaxx.runtime.swing.navigation.tree.NavigationTreeModel; +import jaxx.runtime.swing.navigation.tree.NavigationTreeModelBuilder; +import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; import org.junit.Assert; import org.junit.Test; @@ -46,7 +49,7 @@ @Test public void testFindNode() throws Exception { - NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, new DefaultJAXXContext(), null, null); + NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, new DefaultJAXXContext(), null, null); NavigationTreeNode rootNode = builder.build(null, (String) null, (String) null, ROOT_CONTEXT, null, null); @@ -104,7 +107,7 @@ } /** - * Test the {@link NavigationTreeNodeModel#getBean(String)}} with an entry point + * Test the {@link NavigationTreeModel#getBean(String)}} with an entry point * as a bean. * <p/> * Tree is like this @@ -158,7 +161,7 @@ new Model("two", 2, Collections.<Model>emptyList()), new Model("three", 3, Collections.<Model>emptyList())))); - NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, context, null, null); + NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, context, null, null); NavigationTreeNode rootNode = builder.build(null, (String) null, (String) null, ROOT_CONTEXT, null, null); @@ -224,7 +227,7 @@ } /** - * Test the {@link NavigationTreeNodeModel#getBean(String)} with an entry point + * Test the {@link NavigationTreeModel#getBean(String)} with an entry point * as a list. * <p/> * Tree is like this @@ -279,7 +282,7 @@ context.setContextValue(list, "models"); - NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, context, null, null); + NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(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-26 14:57:07 UTC (rev 1813) +++ trunk/src/site/rst/NavigationModel.rst 2010-03-26 18:05:31 UTC (rev 1814) @@ -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.NavigationTreeNodeModel.NavigationTreeNode*. +*jaxx.runtime.swing.navigation.tree.NavigationTreeModel.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,25 +33,25 @@ Tout les models suivants implémantent cette interface. -jaxx.runtime.swing.navigation.NavigationTreeNodeModel +jaxx.runtime.swing.navigation.tree.NavigationTreeModel ================================================= Il s'agit du modèle de l'arbre utilisé, c'est une extension d'un *javax.swing.tree.DefaultTreeModel*. -jaxx.runtime.swing.navigation.NavigationTreeTableModel +jaxx.runtime.swing.navigation.treetable.NavigationTreeTableModel ====================================================== Il s'agit du modèle de l'arbre tableau (*org.jdesktop.swingx.JXTreeTable*), 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.NavigationTreeNodeModel.NavigationTreeTableNode* qui -étend *jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*. +*jaxx.runtime.swing.navigation.tree.NavigationTreeModel.NavigationTreeTableNode* qui +étend *jaxx.runtime.swing.navigation.tree.NavigationTreeModel.NavigationTreeNode*. NavigationTreeTableNode est abstaite, l'instance doit donc être crée en implementant la méthode createNavigationTreeTableNode -du builder (*jaxx.runtime.swing.navigation.NavigationTreeTableModelBuilder*). +du builder (*jaxx.runtime.swing.navigation.treetable.NavigationTreeTableModelBuilder*). Les builders ============ @@ -64,23 +64,23 @@ Tous les builders implémentent cette interface. -jaxx.runtime.swing.navigation.NavigationTreeNodeModelBuilder +jaxx.runtime.swing.navigation.tree.NavigationTreeModelBuilder -------------------------------------------------------- Classe utilitaire pour construire le model (ici un -*jaxx.runtime.swing.navigation.NavigationTreeNodeModel*) et décorer un arbre. +*jaxx.runtime.swing.navigation.tree.NavigationTreeModel*) et décorer un arbre. -jaxx.runtime.swing.navigation.NavigationTreeTableModelBuilder +jaxx.runtime.swing.navigation.treetable.NavigationTreeTableModelBuilder ------------------------------------------------------------- Classe utilitaire pour construire le model (ici un -*jaxx.runtime.swing.navigation.NavigationTreeTableModel*) et décorer un arbre +*jaxx.runtime.swing.navigation.treetable.NavigationTreeTableModel*) et décorer un arbre tableau. Les Handlers ============ -jaxx.runtime.swing.navigation.NavigationTreeHandler +jaxx.runtime.swing.navigation.handler.AbstractNavigationHandler --------------------------------------------------- Cette classe est une implémentation d'un model de sélection pour les arbres @@ -90,31 +90,31 @@ (*Strategy.PER_NODE*) soit on associe une ui par type de noeud (*Strategy.PER_UI_TYPE*). -jaxx.runtime.swing.navigation.NavigationTreeHandlerWithCardLayout +jaxx.runtime.swing.navigation.handler.NavigationTreeHandlerWithCardLayout ----------------------------------------------------------------- -Extension de *jaxx.runtime.swing.navigation.NavigationTreeHandler* pour +Extension de *jaxx.runtime.swing.navigation.handler.AbstractNavigationHandler* pour l'utilisation de CardLayout (*jaxx.runtime.swing.CardLayout2*). -jaxx.runtime.swing.navigation.NavigationMultiTreeHandler +jaxx.runtime.swing.navigation.handler.NavigationMultiTreeHandler -------------------------------------------------------- TODO ajouter la strategie de la multiselection -Extension de *jaxx.runtime.swing.navigation.NavigationTreeHandler* pour +Extension de *jaxx.runtime.swing.navigation.handler.AbstractNavigationHandler* pour ajouter la possibilité d'utiliser la multisélection. -jaxx.runtime.swing.navigation.NavigationOneClicSelectionHandler +jaxx.runtime.swing.navigation.handler.NavigationOneClicSelectionHandler --------------------------------------------------------------- -Extension de *jaxx.runtime.swing.navigation.NavigationMultiTreeHandler* pour +Extension de *jaxx.runtime.swing.navigation.handler.NavigationMultiTreeHandler* pour activer le simple clic lors de la multi-selection. Définition d'un noeud ===================== Le noeud -(*jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*) est +(*jaxx.runtime.swing.navigation.tree.NavigationTreeModel.NavigationTreeNode*) est une extension d'un *javax.swing.tree.DefaultMutableTreeNode*. Il apporte les nouvelles propriétés suivantes :