[Buix-commits] r1292 - in jaxx/trunk: . jaxx-example/src/main/resources/i18n jaxx-runtime-swing jaxx-runtime-swing/src/main/java/jaxx/runtime jaxx-runtime-swing/src/main/java/jaxx/runtime/swing jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation
Author: tchemit Date: 2009-04-04 17:08:37 +0000 (Sat, 04 Apr 2009) New Revision: 1292 Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java Modified: jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties jaxx/trunk/jaxx-runtime-swing/changelog.txt jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationUtil.java jaxx/trunk/pom.xml Log: little works :) see in changelog ... Modified: jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties =================================================================== --- jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties 2009-04-04 17:05:55 UTC (rev 1291) +++ jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties 2009-04-04 17:08:37 UTC (rev 1292) @@ -108,10 +108,13 @@ no\ layer= valid= validator.field=Champ +validator.field.header.tip= validator.field.tip= validator.message=Message +validator.message.header.tip= validator.message.tip= validator.scope=... +validator.scope.header.tip= validator.scope.tip= with\ layer= x= Modified: jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties =================================================================== --- jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties 2009-04-04 17:05:55 UTC (rev 1291) +++ jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties 2009-04-04 17:08:37 UTC (rev 1292) @@ -107,11 +107,11 @@ form2.text2=Form2 \: text2 no\ layer= valid= -validator.field=Champ -validator.field.tip= -validator.message=Message -validator.message.tip= -validator.scope=... -validator.scope.tip= +validator.field= +validator.field.header.tip= +validator.message= +validator.message.header.tip= +validator.scope= +validator.scope.header.tip= with\ layer= x= Modified: jaxx/trunk/jaxx-runtime-swing/changelog.txt =================================================================== --- jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-04-04 17:05:55 UTC (rev 1291) +++ jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-04-04 17:08:37 UTC (rev 1292) @@ -1,4 +1,5 @@ 1.3 chemit 20090321 + * 20090404 [chemit] - introduce dimension factory in SwingUtil for min and max dimensions * 20090327 [chemit] - add javax help mecanism * 20090318 [chemit] - introduce the BlockingLayerUI2 class (should be merge with BlockingLayerUI) * 20090318 [chemit] - introduce the CardLayout2Ext class Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java =================================================================== --- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java 2009-04-04 17:05:55 UTC (rev 1291) +++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java 2009-04-04 17:08:37 UTC (rev 1292) @@ -3,6 +3,7 @@ import java.awt.Color; import java.awt.Component; import java.awt.Container; +import java.awt.Dimension; import java.awt.Rectangle; import java.beans.BeanInfo; import java.beans.IntrospectionException; @@ -35,6 +36,8 @@ import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JLabel; +import javax.swing.JLayeredPane; +import javax.swing.JRootPane; import javax.swing.JTabbedPane; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; @@ -62,6 +65,22 @@ public static final String ICON_PREFIX = "icon."; public static final String COLOR_PREFIX = "color."; + public static Dimension newMinDimension() { + return new Dimension(0, 0); + } + + public static Dimension newMaxXDimension() { + return new Dimension(Short.MAX_VALUE, 0); + } + + public static Dimension newMaxYDimension() { + return new Dimension(0, Short.MAX_VALUE); + } + + public static Dimension newMaxXYDimension() { + return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); + } + public static void setText(final JTextComponent c, final String text) { try { // AbstractDocument deadlocks if we try to acquire a write lock while a read lock is held by the current thread @@ -205,6 +224,7 @@ return result; } + @SuppressWarnings("unchecked") public static JXLayer<JComponent> getLayer(JComponent comp) { if (!isLayered(comp)) { return null; @@ -470,7 +490,7 @@ icon = (Icon) iconKey; } else if (iconKey instanceof String) { icon = jaxx.runtime.Util.getUIManagerActionIcon((String) iconKey); - } + } JLabel result; if (icon == null) { result = new JLabel(text, aligment); @@ -479,4 +499,97 @@ } return result; } + + /** + * Gets the higest visible component in a ancestor hierarchy at + * specific x,y coordinates + * @param parent + * @param x + * @param y + * @return + */ + public static Component getDeepestObjectAt(Component parent, int x, int y) { + + if (parent instanceof Container) { + Container cont = (Container) parent; + // use a copy of 1.3 Container.findComponentAt + Component child = findComponentAt(cont, cont.getWidth(), cont.getHeight(), x, y); + if (child != null && child != cont) { + //log.info("child find : " + child.getName()); + if (child instanceof JRootPane) { + JLayeredPane lp = ((JRootPane) child).getLayeredPane(); + Rectangle b = lp.getBounds(); + child = getDeepestObjectAt(lp, x - b.x, y - b.y); + } + if (child != null) { + return child; + } + } + } + // if the parent is not a Container then it might be a MenuItem. + // But even if it isn't a MenuItem just return the parent because + // that's a close as we can come. + return parent; + } + + public static Component findComponentAt(Container cont, int width, int height, int x, int y) { + //log.info("container : " + cont.getName()); + synchronized (cont.getTreeLock()) { + + if (!((x >= 0) && (x < width) && (y >= 0) && (y < height) && cont.isVisible() && cont.isEnabled())) { + return null; + } + + Component[] component = cont.getComponents(); + int ncomponents = cont.getComponentCount(); + + // Two passes: see comment in sun.awt.SunGraphicsCallback + for (int i = 0; i < ncomponents; i++) { + Component comp = component[i]; + Rectangle rect = null; + + if (comp != null && !comp.isLightweight()) { + if (rect == null || rect.width == 0 || rect.height == 0) { + rect = comp.getBounds(); + } + if (comp instanceof JXLayer) { + JXLayer layer = (JXLayer) comp; + comp = layer.getView(); + } + if (comp instanceof Container) { + comp = findComponentAt((Container) comp, rect.width, rect.height, x - rect.x, y - rect.y); + } else { + comp = comp.getComponentAt(x - rect.x, y - rect.y); + } + if (comp != null && comp.isVisible() && comp.isEnabled()) { + return comp; + } + } + } + + for (int i = 0; i < ncomponents; i++) { + Component comp = component[i]; + Rectangle rect = null; + + if (comp != null && comp.isLightweight()) { + if (rect == null || rect.width == 0 || rect.height == 0) { + rect = comp.getBounds(); + } + if (comp instanceof JXLayer) { + JXLayer layer = (JXLayer) comp; + comp = layer.getView(); + } + if (comp instanceof Container) { + comp = findComponentAt((Container) comp, rect.width, rect.height, x - rect.x, y - rect.y); + } else { + comp = comp.getComponentAt(x - rect.x, y - rect.y); + } + if (comp != null && comp.isVisible() && comp.isEnabled()) { + return comp; + } + } + } + return cont; + } + } } Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java =================================================================== --- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java 2009-04-04 17:05:55 UTC (rev 1291) +++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JaxxHelpBroker.java 2009-04-04 17:08:37 UTC (rev 1292) @@ -2,6 +2,7 @@ import java.applet.Applet; import java.awt.*; +import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; @@ -9,19 +10,16 @@ import java.net.URL; import java.util.Enumeration; import java.util.Hashtable; -import java.util.List; -import java.util.Map; import java.util.Vector; import javax.help.CSH; -import javax.help.CSH.DisplayHelpFromSource; import javax.help.HelpBroker; import javax.help.HelpSet; import javax.swing.AbstractButton; -import javax.swing.JComponent; import javax.swing.SwingUtilities; import javax.swing.UIManager; import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXObject; +import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -43,7 +41,6 @@ // Main HelpSet & Broker protected final HelpSet helpset; protected final HelpBroker helpBroker; - protected ActionListener showHelpAction; protected Hashtable<Component, Cursor> cursors; protected Cursor onItemCursor; @@ -64,40 +61,34 @@ } } - public AbstractButton getShowHelperButton(JAXXObject c) { - return (AbstractButton) c.getObjectById("showHelp"); - } - public void prepareUI(JAXXObject c) { if (c == null) { throw new NullPointerException("parameter c can not be null!"); } // l'ui doit avoir un boutton showHelp - AbstractButton help = getShowHelperButton(c); + AbstractButton help = getShowHelpButton(c); if (help == null) { - log.warn("no showButton detected for " + c.getClass()); + if (log.isDebugEnabled()) { + log.debug("no showButton detected for " + c.getClass()); + } } else { - boolean needListener = true; - for (ActionListener a : help.getActionListeners()) { - if (a instanceof DisplayHelpFromSource) { - needListener = false; - break; - } + + // attach context to button + help.putClientProperty(JAXX_CONTEXT_ENTRY, c.getDelegateContext()); + + // add tracking action + ActionListener listener = getShowHelpAction(); + if (log.isDebugEnabled()) { + log.debug("adding tracking action " + listener); } - if (needListener) { - // attach context to button - help.putClientProperty(JAXX_CONTEXT_ENTRY, c.getDelegateContext()); - help.addActionListener(getShowHelpAction(c)); - } + help.addActionListener(listener); } if (log.isDebugEnabled()) { - log.debug("for " + c); + log.debug("done for " + c); } - - //installUI(c, new java.util.ArrayList<String>()); } public HelpBroker getHelpBroker() { @@ -132,141 +123,72 @@ CSH.setHelpIDString(comp, helpId); } - protected void installUI(Object comp, List<String> scanned) { - //log.info(comp); - if (comp instanceof JComponent) { - JComponent c = (JComponent) comp; - if (scanned.contains(c.getName())) { - return; - } else { - scanned.add(c.getName()); - } - Object id = c.getClientProperty(helpKey); - if (id != null && id instanceof String) { - String helpId = (String) id; + public class ShowHelpForTrackedComponentAction implements ActionListener { - CSH.setHelpIDString(c, helpId); + @Override + public void actionPerformed(ActionEvent e) { + AbstractButton source = (AbstractButton) e.getSource(); - log.info(c.getName() + " : " + helpId); + JAXXContext context = (JAXXContext) source.getClientProperty(JAXX_CONTEXT_ENTRY); - if (log.isDebugEnabled()) { - log.debug(c.getName() + " : " + helpId); + // prepare cursor + onItemCursor = (Cursor) UIManager.get("HelpOnItemCursor"); + Vector topComponents = null; + cursors = null; + if (onItemCursor != null) { + cursors = new Hashtable<Component, Cursor>(); + topComponents = getTopContainers(source); + Enumeration enums = topComponents.elements(); + while (enums.hasMoreElements()) { + setAndStoreCursors((Container) enums.nextElement(), onItemCursor); } } - } - if (comp instanceof JAXXObject) { - JAXXObject jo = (JAXXObject) comp; - - - Map<String, Object> $objectMap = jo.get$objectMap(); - for (String key : $objectMap.keySet()) { - - if (scanned.contains(key)) { - continue; + // get the tracked component + Component comp = null; + try { + MouseEvent event = getMouseEvent(); + if (event == null) { + // tracking canceled + return; } - - Object o = $objectMap.get(key); - - if (o == comp) { - continue; + comp = (Component) event.getSource(); + if (log.isDebugEnabled()) { + log.debug("component traking " + comp.getName() + " : " + comp.getClass().getName()); } - - if (o instanceof JAXXObject) { - installUI(o, scanned); - scanned.add(key); - continue; + comp = SwingUtil.getDeepestObjectAt(comp, event.getX(), event.getY()); + if (log.isDebugEnabled()) { + log.debug("deepest component " + comp.getName() + " : " + comp.getClass().getName()); } - if (o instanceof JComponent) { - installUI(o, scanned); - continue; + } finally { + // restore the old cursors + if (topComponents != null) { + Enumeration containers = topComponents.elements(); + while (containers.hasMoreElements()) { + resetAndRestoreCursors((Container) containers.nextElement()); + } } + cursors = null; } - } - } - protected ActionListener getShowHelpAction(JAXXContext context) { - if (showHelpAction == null) { - showHelpAction = addShowHelpAction(context); + String helpID = CSH.getHelpIDString(comp); + + showHelp(context, helpID); } - return showHelpAction; } - protected ActionListener addShowHelpAction(JAXXContext context) { - return new CSH.DisplayHelpAfterTracking(helpBroker); + protected AbstractButton getShowHelpButton(JAXXObject c) { + return (AbstractButton) c.getObjectById("showHelp"); } - protected String getHelpID(Component source) { - String helpID = null; - - // It is necessery for UIManager.get("HelpOnItemCursor"); - - // Get the onItemCursor - onItemCursor = (Cursor) UIManager.get("HelpOnItemCursor"); - if (onItemCursor == null) { - return null; - } - - // change all the cursors on all windows - Vector topComponents = null; - cursors = null; - - if (onItemCursor != null) { - cursors = new Hashtable<Component, Cursor>(); - topComponents = getTopContainers(source); - Enumeration enums = topComponents.elements(); - while (enums.hasMoreElements()) { - setAndStoreCursors((Container) enums.nextElement(), onItemCursor); - } - } - /*MouseEvent event = getMouseEvent(); - - if (event != null) { - Component comp = (Component)event.getSource(); - log.info("component traking!!!!!!!! " + comp.getName()+" : "+comp.getClass().getName()); - }*/ - - - Object o = CSH.trackCSEvents(); - - if (o instanceof Component) { - - helpID = CSH.getHelpIDString((Component) o); - - log.info("component traking " + ((Component) o).getName() + " : " + helpID); - - if (log.isDebugEnabled()) { - log.debug("component traking " + ((Component) o).getName() + " : " + helpID); - } - } - - /*HelpSet objHS = getHelpset(); - try { - ID id = ID.create(helpID, objHS); - if (id == null) { - id = objHS.getHomeID(); - } - - } catch (Exception e2) { - e2.printStackTrace(); - } - if (helpID == null) { - helpID = getDefaultID(); - }*/ - - // restore the old cursors - if (topComponents != null) { - Enumeration containers = topComponents.elements(); - while (containers.hasMoreElements()) { - resetAndRestoreCursors((Container) containers.nextElement()); - } - } - cursors = null; - - return helpID; + protected ActionListener getShowHelpAction() { + return new ShowHelpForTrackedComponentAction(); } + //------------------------------------------------------------------------- + //--- Copy CSH code but with accessible modifiers and little improvments + //------------------------------------------------------------------------- /* * Get all top level containers to change it's cursors */ @@ -332,7 +254,6 @@ return null; } - /* * Set the cursor for a component and its children. * Store the old cursors for future resetting @@ -432,7 +353,9 @@ // can't call eq.dispatchEvent // so I pasted it's body here - // debug(event); + if (log.isDebugEnabled()) { + log.debug(event); + } // Not sure if I should suppress ActiveEvents or not // Modal dialogs do. For now we will not suppress the @@ -460,9 +383,22 @@ } else if (event instanceof MouseEvent) { MouseEvent e = (MouseEvent) event; int eID = e.getID(); + if ((eID == MouseEvent.MOUSE_CLICKED || eID == MouseEvent.MOUSE_PRESSED || eID == MouseEvent.MOUSE_RELEASED) && + SwingUtilities.isRightMouseButton(e)) { + // cancel tracking + e.consume(); + if (log.isDebugEnabled()) { + log.debug("tracking canceled!!!"); + } + return null; + } + + if ((eID == MouseEvent.MOUSE_CLICKED || + eID == MouseEvent.MOUSE_PRESSED || + eID == MouseEvent.MOUSE_RELEASED) && SwingUtilities.isLeftMouseButton(e)) { if (eID == MouseEvent.MOUSE_CLICKED) { if (eventNumber == 0) { @@ -483,14 +419,18 @@ ((InputEvent) event).consume(); } } else { - System.err.println("unable to dispatch event: " + event); + log.error("unable to dispatch event: " + event); } } } } catch (InterruptedException e) { - log.debug(e); + if (log.isDebugEnabled()) { + log.debug(e); + } } - log.debug("Fall Through code"); + if (log.isDebugEnabled()) { + log.debug("Fall Through code"); + } return null; } @@ -504,7 +444,7 @@ } else if (src instanceof MenuComponent) { ((MenuComponent) src).dispatchEvent(event); } else { - System.err.println("unable to dispatch event: " + event); + log.error("unable to dispatch event: " + event); } } } Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java =================================================================== --- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java (rev 0) +++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2009-04-04 17:08:37 UTC (rev 1292) @@ -0,0 +1,249 @@ +package jaxx.runtime.swing.navigation; + +import java.awt.Component; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultTreeSelectionModel; +import javax.swing.tree.TreePath; +import jaxx.runtime.JAXXAction; +import jaxx.runtime.JAXXContext; +import jaxx.runtime.JAXXContextEntryDef; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * The handler of a navigation tree. + * + * 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 tony + * @since 1.3 + */ +public abstract class NavigationTreeHandler extends DefaultTreeSelectionModel { + + private static final long serialVersionUID = 1L; + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private final Log log = LogFactory.getLog(NavigationTreeHandler.class); + static public final String NAVIGATION_SELECTED_BEAN = "navigation-selected-bean"; + static public final JAXXContextEntryDef<String> NAVIGATION_SELECTED_PATH_ENTRY_DEF = JAXXContextEntryDef.newDef("navigation-selected-path", String.class); + static public final JAXXContextEntryDef<NavigationTreeNode> NAVIGATION_SELECTED_NODE_ENTRY_DEF = JAXXContextEntryDef.newDef("navigation-selected-node", NavigationTreeNode.class); + + /** 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; + protected Class<? extends JAXXAction> defaultUIHandlerClass; + /** l'ui contenant l'arbre de navigation */ + protected JAXXObject context; + protected Strategy strategy; + + protected NavigationTreeHandler(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, JAXXObject context, Strategy strategy) { + this.defaultUIClass = defaultUIClass; + this.defaultUIHandlerClass = defaultUIHandlerClass; + this.context = context; + this.strategy = strategy; + addTreeSelectionListener(new TreeSelectionListener() { + + @Override + public void valueChanged(TreeSelectionEvent event) { + if (event.getOldLeadSelectionPath() != null && event.getOldLeadSelectionPath().equals(event.getPath())) { + // do not treate this if no path changed + return; + } + NavigationTreeNode node = (NavigationTreeNode) event.getPath().getLastPathComponent(); + selectNodeUI(node); + } + }); + } + + protected abstract NavigationTreeModel 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(NavigationTreeNode 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(NavigationTreeNode node) throws Exception; + + protected abstract JAXXContext createUIContext(NavigationTreeNode 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, NavigationTreeNode node) throws Exception; + + /** + * Traitement des exceptions. + * + * @param e l'erreur recontrée (ou null si pas d"erreur) + */ + protected abstract void treateError(Exception e); + + /** + * Prepare le nouveau noeud sélectionné. + * + * @param node le noeud a preparer + * @return le noeud selectionné et preparé + */ + protected NavigationTreeNode prepareNode(NavigationTreeNode node) { + + if (node.getJaxxClass() == null) { + // no ui is associated with this node, display a empty content + node.setJaxxClass(defaultUIClass); + } + + if (node.getJaxxActionClass() == null) { + node.setJaxxActionClass(defaultUIHandlerClass); + } + return node; + } + + @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; + } + } 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); + } + + public void selectNodeUI(NavigationTreeNode node) { + + try { + + node = prepareNode(node); + + String path = node.getContextPath(); + + 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 + + // always clean cache on the node before all + node.cachedBean = null; + if (node.renderer != null) { + node.renderer.setRendererCachedValue(null); + } + // before all, attach bean in context associated with the selected node in navigation tree + Object data = getNavigationTreeModel().getJAXXContextValue(context, path); + + addSelectedBeanInContext(node, data); + + if (newUI == null) { + // instanciate a new ui associated with the selected node + newUI = createUI(node); + } + + // save in context current node context path + NAVIGATION_SELECTED_PATH_ENTRY_DEF.setContextValue(context, node.getContextPath()); + + // save in context current node + NAVIGATION_SELECTED_NODE_ENTRY_DEF.setContextValue(context, node); + + // really open the ui associated with the selected node + openUI(newUI, node); + + } catch (Exception e) { + // remove data from context + + // if any error, go back to previvous node + treateError(e); + } + } + + protected void addSelectedBeanInContext(NavigationTreeNode node, Object data) { + + if (log.isDebugEnabled()) { + log.debug("find data for contextPath <" + node.getContextPath() + "> : " + (data == null ? null : data.getClass())); + } + + 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); + } + } + + 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 JAXXAction getJAXXAction(Class<? extends JAXXAction> jaxxActionClass) throws Exception { + JAXXAction action = jaxxActionClass.newInstance(); + return action; + } +} Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java =================================================================== --- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java (rev 0) +++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java 2009-04-04 17:08:37 UTC (rev 1292) @@ -0,0 +1,119 @@ +package jaxx.runtime.swing.navigation; + +import jaxx.runtime.JAXXAction; +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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JPanel; +import java.awt.Component; + +/** + * Simple {@link NavigationTreeSelectionAdapter} implementation with a {@link jaxx.runtime.swing.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 extends NavigationTreeHandler { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + 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(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); + } + 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(NavigationTreeNode node) { + CardLayout2 layout = getContentLayout(); + JPanel container = getContentContainer(); + String path = getNodeConstraints(node); + return layout.contains(path) ? layout.getComponent(container, path) : null; + } + + @Override + protected void openUI(Component newUI, NavigationTreeNode node) throws Exception { + + CardLayout2 layout = getContentLayout(); + JPanel container = getContentContainer(); + // switch layout + layout.show(container, getNodeConstraints(node)); + } + + @Override + protected boolean closeUI(Component component) throws Exception { + // by default, we says that component was succesfull closed + return true; + } + + @Override + protected JAXXContext createUIContext(NavigationTreeNode node) throws Exception { + + if (node.getJaxxActionClass() == null) { + if (log.isWarnEnabled()) { + log.warn("no action associated with ui " + node.getJaxxClass()); + } + // no action associated, just + return context; + } + + JAXXAction action = getJAXXAction(node.getJaxxActionClass()); + + // init context with + JAXXInitialContext uiContext = action.init(this.context); + return uiContext; + } + + @Override + protected Component createUI(NavigationTreeNode node) throws Exception { + + JAXXContext uiContext = createUIContext(node); + + JAXXObject newUI = node.getJaxxClass().getConstructor(JAXXContext.class).newInstance(uiContext); + + if (log.isDebugEnabled()) { + log.debug("instanciate new ui " + newUI); + } + + getContentContainer().add((Component) newUI, getNodeConstraints(node)); + return (Component) newUI; + } +} + Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java =================================================================== --- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java 2009-04-04 17:05:55 UTC (rev 1291) +++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeSelectionAdapter.java 2009-04-04 17:08:37 UTC (rev 1292) @@ -126,6 +126,7 @@ return node; } + @Override public void valueChanged(TreeSelectionEvent event) { if (event.getOldLeadSelectionPath() != null && event.getOldLeadSelectionPath().equals(event.getPath())) { // do not treate this if no path changed Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationUtil.java =================================================================== --- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationUtil.java 2009-04-04 17:05:55 UTC (rev 1291) +++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/navigation/NavigationUtil.java 2009-04-04 17:08:37 UTC (rev 1292) @@ -149,6 +149,11 @@ log.debug(rendererCachedValue); } } + + public String getRendererCachedValue() { + return rendererCachedValue; + } + } } Modified: jaxx/trunk/pom.xml =================================================================== --- jaxx/trunk/pom.xml 2009-04-04 17:05:55 UTC (rev 1291) +++ jaxx/trunk/pom.xml 2009-04-04 17:08:37 UTC (rev 1292) @@ -108,7 +108,8 @@ <dependency> <groupId>com.opensymphony</groupId> <artifactId>xwork</artifactId> - <version>2.1.1-cl_20090130</version> + <version>2.1.1-cl_20081015</version> + <!--version>2.1.1-cl_20090130</version--> <!--version>2.1.1</version--> </dependency>
participants (1)
-
tchemit@users.labs.libre-entreprise.org