r1053 - in lutinjaxx/trunk/jaxx-core: . src/main/java/jaxx/runtime/swing/navigation
Author: tchemit Date: 2008-12-02 20:59:03 +0000 (Tue, 02 Dec 2008) New Revision: 1053 Modified: lutinjaxx/trunk/jaxx-core/changelog lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapterWithCardLayout.java Log: add strategy for loading ui in NavigationTreeSelectionAdapter Modified: lutinjaxx/trunk/jaxx-core/changelog =================================================================== --- lutinjaxx/trunk/jaxx-core/changelog 2008-12-02 19:25:08 UTC (rev 1052) +++ lutinjaxx/trunk/jaxx-core/changelog 2008-12-02 20:59:03 UTC (rev 1053) @@ -1,5 +1,7 @@ 0.7 chemit 200812?? - * 20081202 [chemit] - fix bug when searching for a inner class + * 20081202 [chemit] - add strategy for loading ui in NavigationTreeSelectionAdapter + - fix bug when searching for a inner class + * 20081201 [chemit] - implements jaxx.runtime.JXPathDecorator - add setcontextValue and removeContextValue on JAXXContextEntryDef - introduce scope in BeanValidator (ERROR or WARNING) and related swing stuff Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java 2008-12-02 19:25:08 UTC (rev 1052) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java 2008-12-02 20:59:03 UTC (rev 1053) @@ -24,6 +24,14 @@ static public final String NAVIGATION_SELECTED_BEAN = "navigation-selected-bean"; + /** defined the stategy of instanciation of ui */ + public enum Strategy { + /** instanciate a ui for a node */ + PER_NODE, + /** instanciate only one a ui for a type,nodes will share the instanciation */ + PER_UI_TYPE + } + /** la classe d'ui par defaut, associé à un noeud de l'arbe */ protected Class<? extends JAXXObject> defaultUIClass; @@ -32,12 +40,16 @@ /** l'ui contenant l'arbre de navigation */ protected JAXXObject context; - protected NavigationTreeSelectionAdapter(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, JAXXObject context) { + protected Strategy strategy; + + protected NavigationTreeSelectionAdapter(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, JAXXObject context, Strategy strategy) { this.defaultUIClass = defaultUIClass; this.defaultUIHandlerClass = defaultUIHandlerClass; this.context = context; + this.strategy = strategy; } + protected abstract NavigationTreeModel getNavigationTreeModel(); /** @@ -47,10 +59,10 @@ protected abstract Component getCurrentUI(); /** - * @param path le chemin du noeud selectionne dont on veut afficher l'ui associée + * @param node le noeud associé à l'ui à retrouver * @return l'ui associé au novueau noeud sélectionné */ - protected abstract Component getNewUI(String path); + protected abstract Component getUI(NavigationTreeNode node); /** * @param event l'evenement de selection de noeud @@ -73,10 +85,10 @@ * 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 path le path dans le context de navigation + * @param node le node de l'ui a ouvrir * @throws Exception if any */ - protected abstract void openUI(Component newUI, NavigationTreeNode path) throws Exception; + protected abstract void openUI(Component newUI, NavigationTreeNode node) throws Exception; /** * Retourne au noeud précdemment sélectionné dans l'arbre de navigation, avec la possibilité de notifier @@ -123,10 +135,10 @@ log.trace(path); } - Component newUI = getNewUI(path); + Component newUI = getUI(node); Component component = getCurrentUI(); - if (newUI != null && newUI.equals(component)) { + if (newUI != null && strategy == Strategy.PER_NODE && newUI.equals(component)) { // call back from goto back to previous node, do nothing return; } @@ -143,23 +155,11 @@ // before all, attach bean in context associated with the selected node in naivgation tree Object data = getNavigationTreeModel().getJAXXContextValue(context, path); - if (log.isDebugEnabled()) { - log.debug("find data for contextPath <" + path + "> : " + (data == null ? null : data.getClass())); - } + addSelectedBeanInContext(node, data); - context.removeContextValue(Object.class,NAVIGATION_SELECTED_BEAN); - - if (data != null) { - context.setContextValue(data, NAVIGATION_SELECTED_BEAN); - //todo should we not use this to avoid conflict in context ? - context.setContextValue(data); - } - - if (newUI == null) { // instanciate a new ui associated with the selected node newUI = createUI(node); - } // save in context current node context path @@ -179,25 +179,36 @@ } } - /* protected Object attachBeanFromNodeToContext(NavigationTreeNode node) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException { + protected void addSelectedBeanInContext(NavigationTreeNode node, Object data) { - String path = node.getContextPath(); + if (log.isDebugEnabled()) { + log.debug("find data for contextPath <" + node.getContextPath() + "> : " + (data == null ? null : data.getClass())); + } - NavigationTreeModel navigationModel = getNavigationTreeModel(); + context.removeContextValue(Object.class, NAVIGATION_SELECTED_BEAN); - //if (navigationModel != null) { - - Object data = navigationModel.getJAXXContextValue(context, path); if (data != null) { - if (log.isInfoEnabled()) { - log.info("find data for contextPath <" + path + "> : " + data.getClass()); - } + context.setContextValue(data, NAVIGATION_SELECTED_BEAN); + //todo should we not use this to avoid conflict in context ? context.setContextValue(data); } - //} - return data; - }*/ + } + protected String getNodeConstraints(NavigationTreeNode node) { + String constraints; + switch (strategy) { + case PER_NODE: + constraints = node.getContextPath(); + break; + case PER_UI_TYPE: + constraints = node.getJaxxClass().getName(); + break; + default: + throw new IllegalArgumentException("could not find constraint for node : " + node); + } + return constraints; + } + protected void returnToPreviousNode(JTree tree, TreeSelectionEvent event) { // go back to previous node // put in context a tag to not come back again here Modified: lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapterWithCardLayout.java =================================================================== --- lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapterWithCardLayout.java 2008-12-02 19:25:08 UTC (rev 1052) +++ lutinjaxx/trunk/jaxx-core/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapterWithCardLayout.java 2008-12-02 20:59:03 UTC (rev 1053) @@ -4,8 +4,8 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXInitialContext; import jaxx.runtime.JAXXObject; +import jaxx.runtime.swing.CardLayout2; import jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode; -import jaxx.runtime.swing.CardLayout2; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -44,8 +44,8 @@ */ protected abstract CardLayout2 getContentLayout(); - public NavigationTreeSelectionAdapterWithCardLayout(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, JAXXObject context) { - super(defaultUIClass, defaultUIHandlerClass, context); + public NavigationTreeSelectionAdapterWithCardLayout(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, JAXXObject context, Strategy strategy) { + super(defaultUIClass, defaultUIHandlerClass, context,strategy); if (getContentContainer() == null) { throw new IllegalArgumentException("could not have a null 'contentContainer' in ui " + context); @@ -61,17 +61,19 @@ return layout.getVisibleComponent(container); } - protected Component getNewUI(String path) { + protected Component getUI(NavigationTreeNode node) { CardLayout2 layout = getContentLayout(); JPanel container = getContentContainer(); + String path = getNodeConstraints(node); return layout.contains(path) ? layout.getComponent(container, path) : null; } protected void openUI(Component newUI, NavigationTreeNode node) throws Exception { + CardLayout2 layout = getContentLayout(); JPanel container = getContentContainer(); // switch layout - layout.show(container, node.getContextPath()); + layout.show(container, getNodeConstraints(node)); } protected boolean closeUI(TreeSelectionEvent event, Component component) throws Exception { @@ -99,7 +101,7 @@ log.debug("instanciate new ui " + newUI); } - getContentContainer().add((Component) newUI, node.getContextPath()); + getContentContainer().add((Component) newUI, getNodeConstraints(node)); return (Component) newUI; } }
participants (1)
-
tchemit@users.labs.libre-entreprise.org