Author: tchemit Date: 2008-01-23 22:08:36 +0000 (Wed, 23 Jan 2008) New Revision: 461 Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractAction.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/CollapseAllAction.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/ExpandAllAction.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementTreeHelper.java Log: factorisation code Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractAction.java 2008-01-23 21:58:29 UTC (rev 460) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractAction.java 2008-01-23 22:08:36 UTC (rev 461) @@ -82,9 +82,8 @@ return (String) getValue(NAME); } - protected boolean beforeAction(ActionEvent e) throws Exception { - // nothing by default - return true; + protected boolean beforeAction(ActionEvent e) throws Exception { + return isEnabled(); } protected void doAction(ActionEvent e) throws Exception { Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/CollapseAllAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/CollapseAllAction.java 2008-01-23 21:58:29 UTC (rev 460) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/CollapseAllAction.java 2008-01-23 22:08:36 UTC (rev 461) @@ -19,11 +19,11 @@ package fr.cemagref.simexplorer.is.ui.swing.action.application; import fr.cemagref.simexplorer.is.ui.swing.action.SimExplorerAbstractTabAction; +import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeHelper; import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeNode; import fr.cemagref.simexplorer.is.ui.swing.tab.JApplicationDetailTab; import javax.swing.JTree; -import javax.swing.tree.TreePath; import java.awt.event.ActionEvent; /** @@ -52,32 +52,20 @@ @Override protected boolean beforeAction(ActionEvent e) throws Exception { - if (!super.beforeAction(e) || !isEnabled()) { + if (!super.beforeAction(e)) { return false; } JApplicationDetailTab ui = (JApplicationDetailTab) getUI(); - tree = ui.getTree(); - TreePath path = tree.getSelectionPath(); - if (path != null) { - Object o = path.getLastPathComponent(); - if (o != null && !(o instanceof LoggableElementTreeNode)) { - return false; - } - node = (LoggableElementTreeNode) o; - } - if (node == null) { - // take the root node - node = (LoggableElementTreeNode) tree.getModel().getRoot(); - } + node = LoggableElementTreeHelper.getSelectedNodeOrRootNode(tree); boolean result; - result = node != null && !node.isLeaf(); + result = !(node == null || node.isLeaf()); return result; } @Override protected void doAction(ActionEvent e) throws Exception { - + node.collaspeAll(tree); } Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/ExpandAllAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/ExpandAllAction.java 2008-01-23 21:58:29 UTC (rev 460) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/ExpandAllAction.java 2008-01-23 22:08:36 UTC (rev 461) @@ -20,10 +20,10 @@ import fr.cemagref.simexplorer.is.ui.swing.action.SimExplorerAbstractTabAction; import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeNode; +import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeHelper; import fr.cemagref.simexplorer.is.ui.swing.tab.JApplicationDetailTab; import javax.swing.JTree; -import javax.swing.tree.TreePath; import java.awt.event.ActionEvent; /** @@ -52,26 +52,14 @@ @Override protected boolean beforeAction(ActionEvent e) throws Exception { - if (!super.beforeAction(e) || !isEnabled()) { + if (!super.beforeAction(e)) { return false; } JApplicationDetailTab ui = (JApplicationDetailTab) getUI(); - tree = ui.getTree(); - TreePath path = tree.getSelectionPath(); - if (path != null) { - Object o = path.getLastPathComponent(); - if (o != null && !(o instanceof LoggableElementTreeNode)) { - return false; - } - node = (LoggableElementTreeNode) o; - } - if (node == null) { - // take the root node - node = (LoggableElementTreeNode) tree.getModel().getRoot(); - } + node = LoggableElementTreeHelper.getSelectedNodeOrRootNode(tree); boolean result; - result = node != null && !node.isLeaf(); + result = !(node == null || node.isLeaf()); return result; } Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementTreeHelper.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementTreeHelper.java 2008-01-23 21:58:29 UTC (rev 460) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementTreeHelper.java 2008-01-23 22:08:36 UTC (rev 461) @@ -32,6 +32,8 @@ import static org.codelutin.i18n.I18n._; import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; +import javax.swing.JTree; /** * Une classe d'utilitaire pour construire les arbres de LoggableElement @@ -40,6 +42,26 @@ * @see LoggableElementTreeNode */ public class LoggableElementTreeHelper { + public static LoggableElementTreeNode getSelectedNodeOrRootNode(JTree tree) { + TreePath path = tree.getSelectionPath(); + LoggableElementTreeNode node = null; + if (path != null) { + Object o = path.getLastPathComponent(); + if (o != null && !(o instanceof LoggableElementTreeNode)) { + return null; + } + node = (LoggableElementTreeNode) o; + } + if (node == null) { + // take the root node + Object root = tree.getModel().getRoot(); + if (root == null || !(root instanceof LoggableElementTreeNode)) { + return null; + } + node = (LoggableElementTreeNode) root; + } + return node; + } public enum TypeNode { explorationApplication(ExplorationApplication.class),
participants (1)
-
tchemit@users.labs.libre-entreprise.org