Jaxx-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
June 2010
- 2 participants
- 74 discussions
r1955 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree
by tchemit@users.nuiton.org 08 Jun '10
by tchemit@users.nuiton.org 08 Jun '10
08 Jun '10
Author: tchemit
Date: 2010-06-08 15:01:04 +0200 (Tue, 08 Jun 2010)
New Revision: 1955
Url: http://nuiton.org/repositories/revision/jaxx/1955
Log:
fix NPE when tree still not in help
reformat
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java 2010-06-08 10:00:28 UTC (rev 1954)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java 2010-06-08 13:01:04 UTC (rev 1955)
@@ -65,7 +65,7 @@
/** l'objet (optionnel) pour créer les noeuds fils */
protected final JaxxNodeChildLoador<?, N> childLoador;
- public JaxxNode(String id) {
+ protected JaxxNode(String id) {
this(String.class, id, null, null);
}
@@ -294,7 +294,7 @@
@Override
public String toString() {
- return System.identityHashCode(this) + " :" + id;
+ return System.identityHashCode(this) + " : " + id;
}
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java 2010-06-08 10:00:28 UTC (rev 1954)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java 2010-06-08 13:01:04 UTC (rev 1955)
@@ -226,9 +226,13 @@
return dataProvider;
}
- public void setTree(JTree tree, TreeSelectionListener listener) {
+ public void setTree(JTree tree,
+ boolean addExpandTreeListener,
+ TreeSelectionListener listener) {
this.tree = tree;
- this.tree.addTreeWillExpandListener(expandListener);
+ if (addExpandTreeListener) {
+ this.tree.addTreeWillExpandListener(expandListener);
+ }
if (listener != null) {
this.tree.getSelectionModel().addTreeSelectionListener(listener);
}
@@ -237,6 +241,9 @@
public AbstractJaxxTreeCellRenderer<N> getTreeCellRenderer() {
JTree t = getTree();
+ if (t == null) {
+ return null;
+ }
TreeCellRenderer r = t.getCellRenderer();
return (AbstractJaxxTreeCellRenderer<N>)
(r instanceof AbstractJaxxTreeCellRenderer ? r : null);
@@ -395,5 +402,11 @@
public void setDataProvider(DataProvider dataProvider) {
this.dataProvider = dataProvider;
+ AbstractJaxxTreeCellRenderer<N> renderer = getTreeCellRenderer();
+ if (renderer != null) {
+
+ // dispatch provider to renderer
+ renderer.setDataProvider(dataProvider);
+ }
}
}
1
0
r1954 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree
by tchemit@users.nuiton.org 08 Jun '10
by tchemit@users.nuiton.org 08 Jun '10
08 Jun '10
Author: tchemit
Date: 2010-06-08 12:00:28 +0200 (Tue, 08 Jun 2010)
New Revision: 1954
Url: http://nuiton.org/repositories/revision/jaxx/1954
Log:
finalize tree api
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/AbstractJaxxTreeCellRenderer.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/DataProvider.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNodeChildLoador.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/AbstractJaxxTreeCellRenderer.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/AbstractJaxxTreeCellRenderer.java 2010-06-07 14:50:20 UTC (rev 1953)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/AbstractJaxxTreeCellRenderer.java 2010-06-08 10:00:28 UTC (rev 1954)
@@ -24,7 +24,6 @@
*/
package jaxx.runtime.swing.tree;
-import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -41,42 +40,38 @@
* @author chemit <chemit(a)codelutin.com>
* @since 1.2
*/
-public abstract class AbstractJaxxTreeCellRenderer extends DefaultTreeCellRenderer {
+public abstract class AbstractJaxxTreeCellRenderer<N extends JaxxNode<N>> extends DefaultTreeCellRenderer {
/** Logger */
protected static final Log log =
LogFactory.getLog(AbstractJaxxTreeCellRenderer.class);
/** source de donnée */
- protected DataProvider dataSource;
+ protected DataProvider dataProvider;
/** le cache de rendu */
- protected final Map<JaxxNode, String> renderCache = new HashMap<JaxxNode, String>();
+ protected final Map<N, String> renderCache = new HashMap<N, String>();
/**
- * Determines the text render of a node using the {@link #dataSource}.
+ * Determines the text render of a node using the {@link #dataProvider}.
*
- * @param node
- * @return
+ * @param node the node to render
+ * @return the text render of the node
*/
- protected abstract String computeNodeRender(JaxxNode node);
+ protected abstract String computeNodeText(N node);
protected AbstractJaxxTreeCellRenderer() {
}
- public DataProvider getDataSource() {
-
- return dataSource;
+ public DataProvider getDataProvider() {
+ return dataProvider;
}
+ public void setDataProvider(DataProvider dataProvider) {
+ this.dataProvider = dataProvider;
- public void setDataSource(DataProvider dataSource) {
- this.dataSource = dataSource;
- if (dataSource != null) {
-
- // une nouvelle source utilisée, on vide le cache
- clearCache();
- }
+ // une nouvelle source utilisée, on vide le cache
+ clearCache();
}
public void clearCache() {
@@ -89,7 +84,7 @@
clearCache();
}
- public String getNodeText(JaxxNode node) {
+ public String getNodeText(N node) {
if (node == null) {
return null;
}
@@ -97,55 +92,32 @@
if (node.isDirty() || !renderCache.containsKey(node)) {
- // il calculer le rendu du noeud
- text = computeRender(node);
+ // calculer le rendu du noeud
+ if (node.isStringNode()) {
+ text = _(node.getId());
+ } else {
+
+ text = computeNodeText(node);
+ }
+
if (log.isDebugEnabled()) {
- log.debug("render for node [" + node + "] = " + text);
+ log.debug("text for node [" + node + "] = <" + text + ">");
}
// sauvegarde dans le cache
renderCache.put(node, text);
+ // le noeud est de nouveau propre
node.setDirty(false);
} else {
+
+ // recupération directement du rendu dans le cache
text = renderCache.get(node);
}
return text;
}
- protected String computeRender(JaxxNode node) {
-
- if (log.isDebugEnabled()) {
- log.debug("for node : " + node.getId());
- }
-
- String text;
-
- if (node.isStringNode()) {
- text = _(node.getId());
- return text;
- }
-
- // not a static node
- text = computeNodeRender(node);
-
- return text;
- }
-
- /**
- * @param value the value which should be a node
- * @return the cast {@link NavigationTreeNode}, or <code>null</code> if
- * value is null.
- */
- public static JaxxNode getNode(Object value) {
- JaxxNode node = null;
- if (value instanceof JaxxNode) {
- node = (JaxxNode) value;
- }
- return node;
- }
-
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/DataProvider.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/DataProvider.java 2010-06-07 14:50:20 UTC (rev 1953)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/DataProvider.java 2010-06-08 10:00:28 UTC (rev 1954)
@@ -25,13 +25,17 @@
package jaxx.runtime.swing.tree;
/**
- * Contract of provider of data from theire ids.
+ * Contract of provider of data from their ids.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.1
*/
public interface DataProvider {
- Object getData(String id) throws Exception;
+ /**
+ * @return {@code true} is provider is enabled and can provide datas,
+ * {@code false} otherwise.
+ */
+ boolean isEnabled();
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java 2010-06-07 14:50:20 UTC (rev 1953)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java 2010-06-08 10:00:28 UTC (rev 1954)
@@ -37,7 +37,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.1
*/
-public class JaxxNode extends DefaultMutableTreeNode {
+public class JaxxNode<N extends JaxxNode<N>> extends DefaultMutableTreeNode {
/** Logger */
static private final Log log = LogFactory.getLog(JaxxNode.class);
@@ -47,33 +47,39 @@
/** le type de l'objet encapsule dans le noeud */
protected final Class<?> internalClass;
+ /**
+ * un nom de context optionnel de context pour pouvoir gérer plusieurs
+ * types de noeud ayant la même {@link #internalClass}.
+ */
protected final String context;
/** l'id de l'objet encapsule dans le noeud */
protected final String id;
- /** un drapeau pour savoir quand il faut recalculer le rendu du noeud */
+ /** un drapeau pour savoir quand il faut recalculer les données du noeud */
protected boolean dirty = true;
-
/** un drapeau a faux tant que les fils n'ont pas ete chargés */
protected boolean loaded;
- /** l'objet pour créer les noeuds fils */
- protected final JaxxNodeChildLoador<?> childLoador;
+ /** l'objet (optionnel) pour créer les noeuds fils */
+ protected final JaxxNodeChildLoador<?, N> childLoador;
-
public JaxxNode(String id) {
this(String.class, id, null, null);
}
- public JaxxNode(Class<?> internalClass, String id, String context, JaxxNodeChildLoador<?> childLoador) {
+ public JaxxNode(Class<?> internalClass,
+ String id,
+ String context,
+ JaxxNodeChildLoador<?, N> childLoador) {
this.internalClass = internalClass;
this.id = id;
this.context = context;
this.childLoador = childLoador;
- if (childLoador == null) {
- // no child loador, this is a static node
+ if (isStaticNode()) {
+
+ // A static node is always full loaded
loaded = true;
}
if (log.isDebugEnabled()) {
@@ -81,16 +87,6 @@
}
}
- @Override
- public Object getUserObject() {
- return id;
- }
-
- @Override
- public JaxxNode getParent() {
- return (JaxxNode) super.getParent();
- }
-
public String getId() {
return id;
}
@@ -111,12 +107,70 @@
return dirty;
}
+ @Override
+ public Object getUserObject() {
+ return id;
+ }
+
+ @Override
+ public N getParent() {
+ return (N) super.getParent();
+ }
+
+ @Override
+ public N getRoot() {
+ return (N) super.getRoot();
+ }
+
+ @Override
+ public N getChildAt(int index) {
+ return (N) super.getChildAt(index);
+ }
+
+ @Override
+ public Enumeration<N> children() {
+ return (Enumeration<N>) super.children();
+ }
+
+ @Override
+ public boolean isLeaf() {
+ // there is two behaviours for the test :
+ // 1 - when the node is static, then can directly use his number of child
+ // to determine if node is a leaf (no child)
+ // 2 - when the node is dynamic, then ALWAYS says the node is NOT a leaf until
+ // it is loaded, otherwise the WillExpand listener will not load the childs...
+ // Once the node is loaded, use back the normal behaviour (count number of childs)
+ return isStaticNode() ? getChildCount() == 0 : isLoaded() && getChildCount() == 0;
+ }
+
+ /**
+ * Convinient method to known if we are on a String typed node.
+ *
+ * @return {@code true} if the type of node if
+ */
public boolean isStringNode() {
return String.class.equals(internalClass);
}
+ /**
+ * To know if the node is static.
+ * <p/>
+ * A {@code static} node has no {@link #childLoador}.
+ *
+ * @return {@code true} when the node is static : says, the node has
+ * no {@link #childLoador}.
+ */
+ public boolean isStaticNode() {
+ return childLoador == null;
+ }
- public JaxxNode getContainerNode() {
+ /**
+ * Get the first node form this one to the root which has a none
+ * {@code String} type.
+ *
+ * @return the first concrete node type
+ */
+ public N getContainerNode() {
if (isRoot()) {
// si on arrive sur le root, quelque chose ne va pas,
// on bloque par null, a defaut de declancher une exception
@@ -129,85 +183,118 @@
}
// cas final : sur un noeud de donnee + classe interne de donnee
- return this;
+ return (N) this;
}
- @Override
- public boolean isLeaf() {
- return !loaded || getChildCount() == 0;
- }
-
+ /**
+ * Changes the {@link #dirty} state.
+ * <p/>
+ * As a side effect, when a render will use this node, it will force to reload
+ * the datas from the {@link DataProvider}.
+ *
+ * @param dirty the new dirty value
+ */
public void setDirty(boolean dirty) {
this.dirty = dirty;
}
- @Override
- public String toString() {
- return System.identityHashCode(this) + " :" + id;
- }
+ public N findNodeById(String id,
+ DefaultTreeModel model,
+ DataProvider source) {
+ if (id == null) {
- public JaxxNode findNodeById(String id,
- DefaultTreeModel model,
- DataProvider source) {
- if (id == null) {
+ // id null ? donc rien a faire
return null;
}
if (id.equals(getId())) {
- return this;
+
+ // on a trouve le bon noeud
+ return (N) this;
}
+
if (!isLoaded()) {
- // il faut ouvrir le noeud pour effectuer la recherche
+ // il faut charger les fils du noeud pour effectuer la recherche
populateChilds(model, source);
}
- if (getChildCount() == 0) {
+
+ if (isLeaf()) {
+
+ // au final le noeud est une feuille, donc ne convient pas
return null;
}
- Enumeration<?> enumeration = children();
+
+ // on recherche dans les fils
+ Enumeration<N> enumeration = children();
while (enumeration.hasMoreElements()) {
- JaxxNode node = (JaxxNode) enumeration.nextElement();
- JaxxNode nodeById = node.findNodeById(id, model, source);
+ N node = enumeration.nextElement();
+ N nodeById = node.findNodeById(id, model, source);
if (nodeById != null) {
return nodeById;
}
}
+
+ // aucun des noeud fils ne convient
return null;
}
- public void populateChilds(DefaultTreeModel model, DataProvider source) {
- if (childLoador == null) {
- // pas de fils constructible
- return;
- }
- try {
- if (log.isDebugEnabled()) {
- log.debug("Will load childs for " + this);
- }
- childLoador.loadChilds(model, this, source);
- } catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- loaded = true;
- }
- }
-
+ /**
+ * Pour charger un noeud et optionnellement ces fils.
+ * <p/>
+ * Tous les noeuds modifiés (ou chargés) passent à l'état {@code dirty}, et
+ * donc les rendus seront recalculés.
+ *
+ * @param model le modèles content le noeud
+ * @param provider le provider de données
+ * @param populateChilds un drapeau pour charger aussi les fils du noeud courant
+ */
public void populateNode(DefaultTreeModel model,
- DataProvider source,
+ DataProvider provider,
boolean populateChilds) {
+ // on indique que le noeud n'est plus propre
setDirty(true);
if (populateChilds) {
// chargement des fils
- populateChilds(model, source);
+ populateChilds(model, provider);
}
+ }
- if (isStringNode()) {
+ /**
+ * Pour charger les fils d'un noeud en utilisant le {@link #childLoador}.
+ * <p/>
+ * Si le noeud est static (i.e n'a pas de childLoador), on ne fait rien.
+ *
+ * @param model le modèle contenant le noeud
+ * @param provider le provider de données
+ */
+ public void populateChilds(DefaultTreeModel model, DataProvider provider) {
+ if (isStaticNode()) {
+
+ // noeud static, rien a faire
return;
}
- throw new IllegalStateException("Cano not populate node [" + internalClass + ":" + id + "]");
+ // chargement des noeuds fils du noeud courant
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Will load childs for " + this);
+ }
+ childLoador.loadChilds(model, (N) this, provider);
+ } catch (Exception e) {
+ throw new RuntimeException(e.getMessage(), e);
+ } finally {
+
+ // au final, on passe le noeud a l'état chargé
+ loaded = true;
+ }
}
+ @Override
+ public String toString() {
+ return System.identityHashCode(this) + " :" + id;
+ }
+
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNodeChildLoador.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNodeChildLoador.java 2010-06-07 14:50:20 UTC (rev 1953)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNodeChildLoador.java 2010-06-08 10:00:28 UTC (rev 1954)
@@ -37,34 +37,44 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.4
*/
-public abstract class JaxxNodeChildLoador<O> implements Serializable {
+public abstract class JaxxNodeChildLoador<O, N extends JaxxNode<N>> implements Serializable {
/** Logger */
- static private final Log log =
- LogFactory.getLog(JaxxNodeChildLoador.class);
+ static private final Log log = LogFactory.getLog(JaxxNodeChildLoador.class);
+ /** Type of data of the node */
protected final Class<O> beanType;
- protected transient DataProvider dataService;
-
- public JaxxNodeChildLoador(Class<O> beanType) {
+ protected JaxxNodeChildLoador(Class<O> beanType) {
this.beanType = beanType;
}
+ /**
+ * Obtain the list of data to put in childs.
+ *
+ * @param parentClass type of parent
+ * @param parentId id of parent
+ * @param dataProvider the data provider
+ * @return the list of data
+ * @throws Exception if any problem
+ */
public abstract List<O> getData(Class<?> parentClass,
String parentId,
- DataProvider dataService);
+ DataProvider dataProvider) throws Exception;
- public abstract JaxxNode createNode(JaxxNode parentNode, O data);
+ /**
+ * Hook to create a child node given his {@code data}.
+ *
+ * @param parentNode the parent node
+ * @param data the data of the node to create
+ * @return the created node
+ */
+ public abstract N createNode(N parentNode, O data);
public Class<O> getBeanType() {
return beanType;
}
- public DataProvider getDataService() {
- return dataService;
- }
-
/**
* Charge les fils du noeud parent donne.
*
@@ -74,10 +84,10 @@
* @throws Exception pour tout probleme de recuperation de donnees
*/
public void loadChilds(DefaultTreeModel model,
- JaxxNode parentNode,
+ N parentNode,
DataProvider source) throws Exception {
- JaxxNode containerNode = parentNode.getContainerNode();
+ N containerNode = parentNode.getContainerNode();
if (containerNode == null) {
@@ -109,19 +119,21 @@
model.nodesWereInserted(parentNode, indices);
}
- protected void addChildNodes(JaxxNode parentNode, List<O> datas) {
+ protected void addChildNodes(N parentNode, List<O> datas) {
// creation des noeuds fils
for (O o : datas) {
- log.info("[" + parentNode + "] Will add child node for " + o);
- JaxxNode node = createNode(parentNode, o);
+ if (log.isInfoEnabled()) {
+ log.info("[" + parentNode + "] Will add child node for " + o);
+ }
+ N node = createNode(parentNode, o);
parentNode.add(node);
}
}
- protected void notifyChildChildAdded(DefaultTreeModel model, JaxxNode parentNode) {
+ protected void notifyChildChildAdded(DefaultTreeModel model, N parentNode) {
// notifie le modele d'un ajout de noeuds
for (int i = 0; i < parentNode.getChildCount(); i++) {
- JaxxNode at = (JaxxNode) parentNode.getChildAt(i);
+ N at = parentNode.getChildAt(i);
model.nodesWereInserted(at, new int[]{0});
}
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java 2010-06-07 14:50:20 UTC (rev 1953)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java 2010-06-08 10:00:28 UTC (rev 1954)
@@ -50,7 +50,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.1
*/
-public class JaxxTreeHelper {
+public class JaxxTreeHelper<N extends JaxxNode<N>> {
/** Logger */
static private final Log log = LogFactory.getLog(JaxxTreeHelper.class);
@@ -61,7 +61,8 @@
/** l'arbre utilisation le model */
protected JTree tree;
- protected DataProvider dataSource;
+ /** data provider */
+ protected DataProvider dataProvider;
/**
* pour charger les fils d'un noeud lorsqu'on l'ouvre. Cela permet de
@@ -90,8 +91,8 @@
if (e.getPath() == null) {
return;
}
- JaxxNode node =
- (JaxxNode) e.getPath().getLastPathComponent();
+ JaxxNode<?> node =
+ (JaxxNode<?>) e.getPath().getLastPathComponent();
if (log.isDebugEnabled()) {
log.debug("for node " + node);
@@ -123,7 +124,7 @@
DefaultTreeModel model = (DefaultTreeModel)
((JTree) event.getSource()).getModel();
- JaxxNode source = (JaxxNode)
+ JaxxNode<?> source = (JaxxNode<?>)
event.getPath().getLastPathComponent();
if (log.isDebugEnabled()) {
log.debug("will expand node " + source);
@@ -147,9 +148,10 @@
treeModelListener = new TreeModelListener() {
@Override
public void treeNodesChanged(TreeModelEvent e) {
- JaxxNode source = (JaxxNode) e.getTreePath().getLastPathComponent();
+ JaxxNode<?> source = (JaxxNode<?>) e.getTreePath().getLastPathComponent();
DefaultTreeModel model = (DefaultTreeModel) e.getSource();
- source.populateNode(model, getDataProvider(), false);
+ DataProvider dataProvider = getDataProvider();
+ source.populateNode(model, dataProvider, false);
if (log.isDebugEnabled()) {
String message = getLogMessage(e, source);
log.debug(message);
@@ -157,17 +159,18 @@
Object[] children = e.getChildren();
if (children != null) {
for (Object o : children) {
- JaxxNode child = (JaxxNode) o;
- child.populateNode(model, getDataProvider(), false);
+ JaxxNode<?> child = (JaxxNode<?>) o;
+ child.populateNode(model, dataProvider, false);
}
}
}
@Override
public void treeNodesInserted(TreeModelEvent e) {
- JaxxNode source = (JaxxNode) e.getTreePath().getLastPathComponent();
+ JaxxNode<?> source = (JaxxNode<?>) e.getTreePath().getLastPathComponent();
DefaultTreeModel model = (DefaultTreeModel) e.getSource();
- source.populateNode(model, getDataProvider(), false);
+ DataProvider dataProvider = getDataProvider();
+ source.populateNode(model, dataProvider, false);
if (log.isDebugEnabled()) {
String message = getLogMessage(e, source);
log.debug(message);
@@ -175,15 +178,15 @@
Object[] children = e.getChildren();
if (children != null) {
for (Object o : children) {
- JaxxNode child = (JaxxNode) o;
- child.populateNode(model, getDataProvider(), false);
+ JaxxNode<?> child = (JaxxNode<?>) o;
+ child.populateNode(model, dataProvider, false);
}
}
}
@Override
public void treeNodesRemoved(TreeModelEvent e) {
- JaxxNode source = (JaxxNode) e.getTreePath().getLastPathComponent();
+ JaxxNode<?> source = (JaxxNode<?>) e.getTreePath().getLastPathComponent();
if (log.isDebugEnabled()) {
String message = getLogMessage(e, source);
log.debug(message);
@@ -192,9 +195,10 @@
@Override
public void treeStructureChanged(TreeModelEvent e) {
- JaxxNode source = (JaxxNode) e.getTreePath().getLastPathComponent();
+ JaxxNode<?> source = (JaxxNode<?>) e.getTreePath().getLastPathComponent();
DefaultTreeModel model = (DefaultTreeModel) e.getSource();
- source.populateNode(model, getDataProvider(), false);
+ DataProvider dataProvider = getDataProvider();
+ source.populateNode(model, dataProvider, false);
if (log.isDebugEnabled()) {
String message = getLogMessage(e, source);
log.debug(message);
@@ -202,13 +206,13 @@
Object[] children = e.getChildren();
if (children != null) {
for (Object o : children) {
- JaxxNode child = (JaxxNode) o;
- child.populateNode(model, getDataProvider(), true);
+ JaxxNode<?> child = (JaxxNode<?>) o;
+ child.populateNode(model, dataProvider, true);
}
}
}
- protected String getLogMessage(TreeModelEvent e, JaxxNode source) {
+ protected String getLogMessage(TreeModelEvent e, JaxxNode<?> source) {
String message = source.getInternalClass() + " - " +
source.getId() + " : " + source.getUserObject() +
"\n" + "children indices : " +
@@ -219,7 +223,7 @@
}
protected DataProvider getDataProvider() {
- return dataSource;
+ return dataProvider;
}
public void setTree(JTree tree, TreeSelectionListener listener) {
@@ -231,10 +235,10 @@
this.tree.getSelectionModel().addTreeSelectionListener(selectionListener);
}
- public AbstractJaxxTreeCellRenderer getTreeCellRenderer() {
+ public AbstractJaxxTreeCellRenderer<N> getTreeCellRenderer() {
JTree t = getTree();
TreeCellRenderer r = t.getCellRenderer();
- return (AbstractJaxxTreeCellRenderer)
+ return (AbstractJaxxTreeCellRenderer<N>)
(r instanceof AbstractJaxxTreeCellRenderer ? r : null);
}
@@ -252,27 +256,25 @@
* @param deep un flag pour activer la repainte de la descendance du
* noeud
*/
- public void refreshNode(JaxxNode node, boolean deep) {
+ public void refreshNode(N node, boolean deep) {
if (log.isDebugEnabled()) {
log.debug(node);
}
model.nodeChanged(node);
if (deep) {
// repaint childs nodes
- //todo we should only repaint necessary nodes ?
- Enumeration<?> e = node.children();
+ Enumeration<N> e = node.children();
while (e.hasMoreElements()) {
- JaxxNode child = (JaxxNode) e.nextElement();
+ N child = e.nextElement();
refreshNode(child, true);
}
}
}
-
/** Sélection du parent du noeud selectionne dans l'arbre de navigation. */
public void selectParentNode() {
- JaxxNode node = getSelectedNode();
+ N node = getSelectedNode();
if (node == null) {
// pas de noeud selectionne
@@ -283,19 +285,19 @@
selectNode(node);
}
- public JaxxNode getSelectedNode() {
+ public N getSelectedNode() {
JTree tree = getTree();
TreePath path = tree.getSelectionPath();
- JaxxNode node = null;
+ N node = null;
if (path != null) {
- node = (JaxxNode) path.getLastPathComponent();
+ node = (N) path.getLastPathComponent();
}
return node;
}
public String[] getSelectedIds() {
List<String> result = new ArrayList<String>();
- JaxxNode selectedNode = getSelectedNode();
+ JaxxNode<?> selectedNode = getSelectedNode();
while (selectedNode != null && !selectedNode.isRoot()) {
result.add(selectedNode.getId());
@@ -311,8 +313,8 @@
* @param path le path absolue du noeud dans l'arbre
*/
public void selectNode(String... path) {
- JaxxNode root = (JaxxNode) model.getRoot();
- JaxxNode node = findNode(root, path);
+ N root = (N) model.getRoot();
+ N node = findNode(root, path);
if (log.isDebugEnabled()) {
log.debug(Arrays.toString(path) + " :: " + node);
}
@@ -326,7 +328,7 @@
*
* @param node le noeud à sélectionner dans l'arbre
*/
- public void selectNode(JaxxNode node) {
+ public void selectNode(N node) {
if (log.isDebugEnabled()) {
log.debug(node);
@@ -337,8 +339,8 @@
tree.scrollPathToVisible(path);
}
- public JaxxNode findNode(JaxxNode node, String... ids) {
- JaxxNode result = null;
+ public N findNode(N node, String... ids) {
+ N result = null;
for (String id : ids) {
result = node.findNodeById(id, model, getDataProvider());
@@ -353,135 +355,35 @@
return result;
}
- public JaxxNode removeChildNode(JaxxNode node) {
- JaxxNode parentNode = node.getParent();
+ public N removeChildNode(N node) {
+ N parentNode = node.getParent();
model.removeNodeFromParent(node);
return parentNode;
}
- public void moveNode(JaxxNode parentNode, JaxxNode node, int position) {
+ public void moveNode(N parentNode, N node, int position) {
parentNode.remove(node);
parentNode.insert(node, position);
model.nodeStructureChanged(parentNode);
}
-// public JaxxNode addUnsavedNode(JaxxNode parentNode, Class<?> type) {
-//
-// // noeud en mode creation
-// String label = decoratorService.getEntityLabel(type) + ".unsaved";
-// JaxxNode result = new JaxxNode(type, null, label, false, null);
-// parentNode.add(result);
-// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
-// return result;
-// }
-//
-// public JaxxNode addMaree(JaxxNode parentNode, Maree bean) {
-// JaxxNode result;
-// if (bean == null) {
-// throw new NullPointerException("Ne peut pas ajouter un objet null");
-// }
-//
-// result = new JaxxNode(Maree.class, bean.getTopiaId(), false, null);
-//
-// // Creation d'un node routes
-// JaxxNode child = new JaxxNode(
-// String.class,
-// n_("observe.common.routes"),
-// Maree.PROPERTY_ROUTE,
-// false,
-// new RoutesNodeChildLoador()
-// );
-// result.add(child);
-// parentNode.add(result);
-//
-// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
-// model.nodesWereInserted(result, new int[]{result.getIndex(child)});
-// return result;
-// }
-//
-// public JaxxNode addRoute(JaxxNode parentNode, Route bean) {
-// JaxxNode result;
-// if (bean == null) {
-// throw new NullPointerException("Ne peut pas ajouter un objet null");
-// }
-// result = new JaxxNode(Route.class, bean.getTopiaId(), false, null);
-//
-// // Creation d'un node activites
-// JaxxNode child = new JaxxNode(
-// String.class,
-// n_("observe.common.activites"),
-// Route.PROPERTY_ACTIVITE,
-// false,
-// new ActivitesNodeChildLoador()
-// );
-// result.add(child);
-// parentNode.add(result);
-//
-// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
-// model.nodesWereInserted(result, new int[]{result.getIndex(child)});
-// return result;
-// }
-//
-// public JaxxNode addActivite(JaxxNode parentNode, Activite bean) {
-// JaxxNode result;
-// if (bean == null) {
-// throw new NullPointerException("Ne peut pas ajouter un objet null");
-// }
-// result = new JaxxNode(Activite.class,
-// bean.getTopiaId(),
-// false,
-// new ActiviteNodeChildLoador());
-// parentNode.add(result);
-//
-// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
-// return result;
-// }
-//
-// public JaxxNode addObjetFlottant(JaxxNode parentNode, ObjetFlottant bean) {
-// JaxxNode result;
-// if (bean == null) {
-// throw new NullPointerException("Ne peut pas ajouter un objet null");
-// }
-// result = new JaxxNode(ObjetFlottant.class, bean.getTopiaId(), false, new ObjetFlottantNodeChildLoador());
-// parentNode.add(result);
-//
-// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
-// return result;
-// }
-//
-// public JaxxNode addCalee(JaxxNode parentNode, Calee bean) {
-// JaxxNode result;
-// if (bean == null) {
-// throw new NullPointerException("Ne peut pas ajouter un objet null");
-// }
-// result = new JaxxNode(Calee.class, bean.getTopiaId(), false, new CaleeNodeChildLoador());
-// parentNode.add(result);
-//
-// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
-// return result;
-// }
-
protected JTree getTree() {
return tree;
}
- protected DefaultTreeModel createModel(JaxxNode node) {
+ protected DefaultTreeModel createModel(N node) {
model = new DefaultTreeModel(node);
model.addTreeModelListener(treeModelListener);
return model;
}
public void reloadModel(JTree tree) {
-
-// DataSelectionTreeCellRenderer r = (DataSelectionTreeCellRenderer) tree.getCellRenderer();
-// r.clearCache();
-// tree.clearSelection();
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
TreeNode node = (TreeNode) model.getRoot();
reload(model, node);
}
- private void reload(DefaultTreeModel model, TreeNode node) {
+ protected void reload(DefaultTreeModel model, TreeNode node) {
model.nodeChanged(node);
Enumeration<?> enumeration = node.children();
while (enumeration.hasMoreElements()) {
@@ -491,7 +393,7 @@
}
}
- public void setDataProvider(DataProvider dataSource) {
- this.dataSource = dataSource;
+ public void setDataProvider(DataProvider dataProvider) {
+ this.dataProvider = dataProvider;
}
}
1
0
r1953 - in trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing: . tree
by tchemit@users.nuiton.org 07 Jun '10
by tchemit@users.nuiton.org 07 Jun '10
07 Jun '10
Author: tchemit
Date: 2010-06-07 16:50:20 +0200 (Mon, 07 Jun 2010)
New Revision: 1953
Url: http://nuiton.org/repositories/revision/jaxx/1953
Log:
Evolution #666: Introduce a new tree api to replace too complex old one
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/AbstractJaxxTreeCellRenderer.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/DataProvider.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNodeChildLoador.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/package.html
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/AbstractJaxxTreeCellRenderer.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/AbstractJaxxTreeCellRenderer.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/AbstractJaxxTreeCellRenderer.java 2010-06-07 14:50:20 UTC (rev 1953)
@@ -0,0 +1,151 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.tree;
+
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.DefaultTreeCellRenderer;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * Le renderer abstrait (qui a toutes les methodes qui aident) pour implanter de
+ * vrai renderer pour les différents cas d'utilisation de l'abre de navigation.
+ *
+ * @author chemit <chemit(a)codelutin.com>
+ * @since 1.2
+ */
+public abstract class AbstractJaxxTreeCellRenderer extends DefaultTreeCellRenderer {
+
+ /** Logger */
+ protected static final Log log =
+ LogFactory.getLog(AbstractJaxxTreeCellRenderer.class);
+
+ /** source de donnée */
+ protected DataProvider dataSource;
+
+ /** le cache de rendu */
+ protected final Map<JaxxNode, String> renderCache = new HashMap<JaxxNode, String>();
+
+ /**
+ * Determines the text render of a node using the {@link #dataSource}.
+ *
+ * @param node
+ * @return
+ */
+ protected abstract String computeNodeRender(JaxxNode node);
+
+ protected AbstractJaxxTreeCellRenderer() {
+ }
+
+ public DataProvider getDataSource() {
+
+ return dataSource;
+ }
+
+
+ public void setDataSource(DataProvider dataSource) {
+ this.dataSource = dataSource;
+ if (dataSource != null) {
+
+ // une nouvelle source utilisée, on vide le cache
+ clearCache();
+ }
+ }
+
+ public void clearCache() {
+ renderCache.clear();
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ clearCache();
+ }
+
+ public String getNodeText(JaxxNode node) {
+ if (node == null) {
+ return null;
+ }
+ String text;
+
+ if (node.isDirty() || !renderCache.containsKey(node)) {
+
+ // il calculer le rendu du noeud
+ text = computeRender(node);
+
+ if (log.isDebugEnabled()) {
+ log.debug("render for node [" + node + "] = " + text);
+ }
+
+ // sauvegarde dans le cache
+ renderCache.put(node, text);
+
+ node.setDirty(false);
+
+ } else {
+ text = renderCache.get(node);
+ }
+
+ return text;
+ }
+
+ protected String computeRender(JaxxNode node) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("for node : " + node.getId());
+ }
+
+ String text;
+
+ if (node.isStringNode()) {
+ text = _(node.getId());
+ return text;
+ }
+
+ // not a static node
+ text = computeNodeRender(node);
+
+ return text;
+ }
+
+ /**
+ * @param value the value which should be a node
+ * @return the cast {@link NavigationTreeNode}, or <code>null</code> if
+ * value is null.
+ */
+ public static JaxxNode getNode(Object value) {
+ JaxxNode node = null;
+ if (value instanceof JaxxNode) {
+ node = (JaxxNode) value;
+ }
+ return node;
+ }
+
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/AbstractJaxxTreeCellRenderer.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/DataProvider.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/DataProvider.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/DataProvider.java 2010-06-07 14:50:20 UTC (rev 1953)
@@ -0,0 +1,37 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.tree;
+
+/**
+ * Contract of provider of data from theire ids.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public interface DataProvider {
+
+ Object getData(String id) throws Exception;
+
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/DataProvider.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java 2010-06-07 14:50:20 UTC (rev 1953)
@@ -0,0 +1,213 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.tree;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import java.util.Enumeration;
+
+/**
+ * Definition of a node with no child loador.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public class JaxxNode extends DefaultMutableTreeNode {
+
+ /** Logger */
+ static private final Log log = LogFactory.getLog(JaxxNode.class);
+
+ private static final long serialVersionUID = 1L;
+
+ /** le type de l'objet encapsule dans le noeud */
+ protected final Class<?> internalClass;
+
+ protected final String context;
+
+ /** l'id de l'objet encapsule dans le noeud */
+ protected final String id;
+
+ /** un drapeau pour savoir quand il faut recalculer le rendu du noeud */
+ protected boolean dirty = true;
+
+
+ /** un drapeau a faux tant que les fils n'ont pas ete chargés */
+ protected boolean loaded;
+
+ /** l'objet pour créer les noeuds fils */
+ protected final JaxxNodeChildLoador<?> childLoador;
+
+
+ public JaxxNode(String id) {
+ this(String.class, id, null, null);
+ }
+
+ public JaxxNode(Class<?> internalClass, String id, String context, JaxxNodeChildLoador<?> childLoador) {
+ this.internalClass = internalClass;
+ this.id = id;
+ this.context = context;
+ this.childLoador = childLoador;
+ if (childLoador == null) {
+ // no child loador, this is a static node
+ loaded = true;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("new node : " + this);
+ }
+ }
+
+ @Override
+ public Object getUserObject() {
+ return id;
+ }
+
+ @Override
+ public JaxxNode getParent() {
+ return (JaxxNode) super.getParent();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getContext() {
+ return context;
+ }
+
+ public Class<?> getInternalClass() {
+ return internalClass;
+ }
+
+ public boolean isLoaded() {
+ return loaded;
+ }
+
+ public boolean isDirty() {
+ return dirty;
+ }
+
+ public boolean isStringNode() {
+ return String.class.equals(internalClass);
+ }
+
+
+ public JaxxNode getContainerNode() {
+ if (isRoot()) {
+ // si on arrive sur le root, quelque chose ne va pas,
+ // on bloque par null, a defaut de declancher une exception
+ return null;
+ }
+
+ if (isStringNode()) {
+ // on est sur un noeud de type String, donc on regarde sur le parent
+ return getParent().getContainerNode();
+ }
+
+ // cas final : sur un noeud de donnee + classe interne de donnee
+ return this;
+ }
+
+ @Override
+ public boolean isLeaf() {
+ return !loaded || getChildCount() == 0;
+ }
+
+ public void setDirty(boolean dirty) {
+ this.dirty = dirty;
+ }
+
+ @Override
+ public String toString() {
+ return System.identityHashCode(this) + " :" + id;
+ }
+
+ public JaxxNode findNodeById(String id,
+ DefaultTreeModel model,
+ DataProvider source) {
+ if (id == null) {
+ return null;
+ }
+ if (id.equals(getId())) {
+ return this;
+ }
+ if (!isLoaded()) {
+
+ // il faut ouvrir le noeud pour effectuer la recherche
+ populateChilds(model, source);
+ }
+ if (getChildCount() == 0) {
+ return null;
+ }
+ Enumeration<?> enumeration = children();
+ while (enumeration.hasMoreElements()) {
+ JaxxNode node = (JaxxNode) enumeration.nextElement();
+ JaxxNode nodeById = node.findNodeById(id, model, source);
+ if (nodeById != null) {
+ return nodeById;
+ }
+ }
+ return null;
+ }
+
+ public void populateChilds(DefaultTreeModel model, DataProvider source) {
+ if (childLoador == null) {
+ // pas de fils constructible
+ return;
+ }
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Will load childs for " + this);
+ }
+ childLoador.loadChilds(model, this, source);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ loaded = true;
+ }
+ }
+
+ public void populateNode(DefaultTreeModel model,
+ DataProvider source,
+ boolean populateChilds) {
+
+ setDirty(true);
+
+ if (populateChilds) {
+
+ // chargement des fils
+ populateChilds(model, source);
+ }
+
+ if (isStringNode()) {
+ return;
+ }
+
+ throw new IllegalStateException("Cano not populate node [" + internalClass + ":" + id + "]");
+ }
+
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNode.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNodeChildLoador.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNodeChildLoador.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNodeChildLoador.java 2010-06-07 14:50:20 UTC (rev 1953)
@@ -0,0 +1,128 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.tree;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.DefaultTreeModel;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Un object pour charger les fils d'un noeud.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.4
+ */
+public abstract class JaxxNodeChildLoador<O> implements Serializable {
+
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(JaxxNodeChildLoador.class);
+
+ protected final Class<O> beanType;
+
+ protected transient DataProvider dataService;
+
+ public JaxxNodeChildLoador(Class<O> beanType) {
+ this.beanType = beanType;
+ }
+
+ public abstract List<O> getData(Class<?> parentClass,
+ String parentId,
+ DataProvider dataService);
+
+ public abstract JaxxNode createNode(JaxxNode parentNode, O data);
+
+ public Class<O> getBeanType() {
+ return beanType;
+ }
+
+ public DataProvider getDataService() {
+ return dataService;
+ }
+
+ /**
+ * Charge les fils du noeud parent donne.
+ *
+ * @param model le model de l'arbre a impacter
+ * @param parentNode le noeud parent
+ * @param source le service pour recuperer les donnees
+ * @throws Exception pour tout probleme de recuperation de donnees
+ */
+ public void loadChilds(DefaultTreeModel model,
+ JaxxNode parentNode,
+ DataProvider source) throws Exception {
+
+ JaxxNode containerNode = parentNode.getContainerNode();
+
+ if (containerNode == null) {
+
+ // on considere que le container est le parent
+ containerNode = parentNode;
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("search data for " + containerNode.getInternalClass() +
+ " : " + containerNode.getId());
+ }
+
+ // recuperation des objets fils
+ List<O> datas = getData(containerNode.getInternalClass(),
+ containerNode.getId(),
+ source);
+
+ if (datas != null && !datas.isEmpty()) {
+
+ // on charge les fils
+ addChildNodes(parentNode, datas);
+ }
+
+ // notifie le modele d'un ajout de noeuds
+ int[] indices = new int[parentNode.getChildCount()];
+ for (int i = 0; i < indices.length; i++) {
+ indices[i] = i;
+ }
+ model.nodesWereInserted(parentNode, indices);
+ }
+
+ protected void addChildNodes(JaxxNode parentNode, List<O> datas) {
+ // creation des noeuds fils
+ for (O o : datas) {
+ log.info("[" + parentNode + "] Will add child node for " + o);
+ JaxxNode node = createNode(parentNode, o);
+ parentNode.add(node);
+ }
+ }
+
+ protected void notifyChildChildAdded(DefaultTreeModel model, JaxxNode parentNode) {
+ // notifie le modele d'un ajout de noeuds
+ for (int i = 0; i < parentNode.getChildCount(); i++) {
+ JaxxNode at = (JaxxNode) parentNode.getChildAt(i);
+ model.nodesWereInserted(at, new int[]{0});
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxNodeChildLoador.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java 2010-06-07 14:50:20 UTC (rev 1953)
@@ -0,0 +1,497 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.tree;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.JTree;
+import javax.swing.event.TreeExpansionEvent;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.event.TreeModelListener;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.event.TreeWillExpandListener;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeCellRenderer;
+import javax.swing.tree.TreeNode;
+import javax.swing.tree.TreePath;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+/**
+ * Tree helper to deal with the build of trees and other usefull operations.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public class JaxxTreeHelper {
+
+ /** Logger */
+ static private final Log log = LogFactory.getLog(JaxxTreeHelper.class);
+
+ /** le modèle de l'arbre */
+ protected DefaultTreeModel model;
+
+ /** l'arbre utilisation le model */
+ protected JTree tree;
+
+ protected DataProvider dataSource;
+
+ /**
+ * pour charger les fils d'un noeud lorsqu'on l'ouvre. Cela permet de
+ * ne pas a voir a construire tout l'arbre à démarrage.
+ */
+ protected TreeWillExpandListener expandListener;
+
+ /**
+ * pour ouvrir les fils d'un noeud que l'on vient de sélectionner pour
+ * éviter d'avoir à faire des doubles clics.
+ */
+ protected TreeSelectionListener selectionListener;
+
+ /**
+ * pour recharger le rendu des noeuds (et charger les fils si nécessaires)
+ * lors d'une modification dans le modèle de l'arbre.
+ */
+ protected TreeModelListener treeModelListener;
+
+ public JaxxTreeHelper() {
+
+ selectionListener = new TreeSelectionListener() {
+
+ @Override
+ public void valueChanged(TreeSelectionEvent e) {
+ if (e.getPath() == null) {
+ return;
+ }
+ JaxxNode node =
+ (JaxxNode) e.getPath().getLastPathComponent();
+
+ if (log.isDebugEnabled()) {
+ log.debug("for node " + node);
+ }
+ if (node == null) {
+ // pas de noeud selectionne
+ return;
+ }
+
+ if (!node.isLeaf()) {
+
+ // on ouvre le chemin si necessaire
+ for (TreePath path : e.getPaths()) {
+ if (e.isAddedPath(path) &&
+ !tree.isExpanded(path)) {
+ log.info("expand node [" + path + "]");
+ // will expand the node
+ tree.expandPath(path);
+ }
+ }
+ }
+
+ }
+ };
+ expandListener = new TreeWillExpandListener() {
+ @Override
+ public void treeWillExpand(TreeExpansionEvent event) {
+
+ DefaultTreeModel model = (DefaultTreeModel)
+ ((JTree) event.getSource()).getModel();
+
+ JaxxNode source = (JaxxNode)
+ event.getPath().getLastPathComponent();
+ if (log.isDebugEnabled()) {
+ log.debug("will expand node " + source);
+ }
+
+ if (!source.isLoaded()) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("will load childs of " + source);
+ }
+ // on charge les fils de l'arbre
+ source.populateChilds(model, getDataProvider());
+ }
+ }
+
+ @Override
+ public void treeWillCollapse(TreeExpansionEvent event) {
+ }
+ };
+
+ treeModelListener = new TreeModelListener() {
+ @Override
+ public void treeNodesChanged(TreeModelEvent e) {
+ JaxxNode source = (JaxxNode) e.getTreePath().getLastPathComponent();
+ DefaultTreeModel model = (DefaultTreeModel) e.getSource();
+ source.populateNode(model, getDataProvider(), false);
+ if (log.isDebugEnabled()) {
+ String message = getLogMessage(e, source);
+ log.debug(message);
+ }
+ Object[] children = e.getChildren();
+ if (children != null) {
+ for (Object o : children) {
+ JaxxNode child = (JaxxNode) o;
+ child.populateNode(model, getDataProvider(), false);
+ }
+ }
+ }
+
+ @Override
+ public void treeNodesInserted(TreeModelEvent e) {
+ JaxxNode source = (JaxxNode) e.getTreePath().getLastPathComponent();
+ DefaultTreeModel model = (DefaultTreeModel) e.getSource();
+ source.populateNode(model, getDataProvider(), false);
+ if (log.isDebugEnabled()) {
+ String message = getLogMessage(e, source);
+ log.debug(message);
+ }
+ Object[] children = e.getChildren();
+ if (children != null) {
+ for (Object o : children) {
+ JaxxNode child = (JaxxNode) o;
+ child.populateNode(model, getDataProvider(), false);
+ }
+ }
+ }
+
+ @Override
+ public void treeNodesRemoved(TreeModelEvent e) {
+ JaxxNode source = (JaxxNode) e.getTreePath().getLastPathComponent();
+ if (log.isDebugEnabled()) {
+ String message = getLogMessage(e, source);
+ log.debug(message);
+ }
+ }
+
+ @Override
+ public void treeStructureChanged(TreeModelEvent e) {
+ JaxxNode source = (JaxxNode) e.getTreePath().getLastPathComponent();
+ DefaultTreeModel model = (DefaultTreeModel) e.getSource();
+ source.populateNode(model, getDataProvider(), false);
+ if (log.isDebugEnabled()) {
+ String message = getLogMessage(e, source);
+ log.debug(message);
+ }
+ Object[] children = e.getChildren();
+ if (children != null) {
+ for (Object o : children) {
+ JaxxNode child = (JaxxNode) o;
+ child.populateNode(model, getDataProvider(), true);
+ }
+ }
+ }
+
+ protected String getLogMessage(TreeModelEvent e, JaxxNode source) {
+ String message = source.getInternalClass() + " - " +
+ source.getId() + " : " + source.getUserObject() +
+ "\n" + "children indices : " +
+ Arrays.toString(e.getChildIndices());
+ return message;
+ }
+ };
+ }
+
+ protected DataProvider getDataProvider() {
+ return dataSource;
+ }
+
+ public void setTree(JTree tree, TreeSelectionListener listener) {
+ this.tree = tree;
+ this.tree.addTreeWillExpandListener(expandListener);
+ if (listener != null) {
+ this.tree.getSelectionModel().addTreeSelectionListener(listener);
+ }
+ this.tree.getSelectionModel().addTreeSelectionListener(selectionListener);
+ }
+
+ public AbstractJaxxTreeCellRenderer getTreeCellRenderer() {
+ JTree t = getTree();
+ TreeCellRenderer r = t.getCellRenderer();
+ return (AbstractJaxxTreeCellRenderer)
+ (r instanceof AbstractJaxxTreeCellRenderer ? r : null);
+ }
+
+ public DefaultTreeModel getModel() {
+ return model;
+ }
+
+ /**
+ * Demande une opération de repaint sur un noeud de l'arbre de navigation.
+ * <p/>
+ * <b>Note:</b> La descendance du noeud est repainte si le paramètre
+ * <code>deep</code> est à <code>true</code>.
+ *
+ * @param node le noeud à repaindre
+ * @param deep un flag pour activer la repainte de la descendance du
+ * noeud
+ */
+ public void refreshNode(JaxxNode node, boolean deep) {
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ model.nodeChanged(node);
+ if (deep) {
+ // repaint childs nodes
+ //todo we should only repaint necessary nodes ?
+ Enumeration<?> e = node.children();
+ while (e.hasMoreElements()) {
+ JaxxNode child = (JaxxNode) e.nextElement();
+ refreshNode(child, true);
+ }
+ }
+ }
+
+
+ /** Sélection du parent du noeud selectionne dans l'arbre de navigation. */
+ public void selectParentNode() {
+
+ JaxxNode node = getSelectedNode();
+
+ if (node == null) {
+ // pas de noeud selectionne
+ throw new NullPointerException("no selected node in context");
+ }
+ node = node.getParent();
+
+ selectNode(node);
+ }
+
+ public JaxxNode getSelectedNode() {
+ JTree tree = getTree();
+ TreePath path = tree.getSelectionPath();
+ JaxxNode node = null;
+ if (path != null) {
+ node = (JaxxNode) path.getLastPathComponent();
+ }
+ return node;
+ }
+
+ public String[] getSelectedIds() {
+ List<String> result = new ArrayList<String>();
+ JaxxNode selectedNode = getSelectedNode();
+ while (selectedNode != null && !selectedNode.isRoot()) {
+
+ result.add(selectedNode.getId());
+ selectedNode = selectedNode.getParent();
+ }
+ Collections.reverse(result);
+ return result.toArray(new String[result.size()]);
+ }
+
+ /**
+ * Sélection d'un noeud dans l'arbre de navigation à partir de son path.
+ *
+ * @param path le path absolue du noeud dans l'arbre
+ */
+ public void selectNode(String... path) {
+ JaxxNode root = (JaxxNode) model.getRoot();
+ JaxxNode node = findNode(root, path);
+ if (log.isDebugEnabled()) {
+ log.debug(Arrays.toString(path) + " :: " + node);
+ }
+ if (node != null) {
+ selectNode(node);
+ }
+ }
+
+ /**
+ * Sélection d'un noeud dans l'arbre de navigation.
+ *
+ * @param node le noeud à sélectionner dans l'arbre
+ */
+ public void selectNode(JaxxNode node) {
+
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ TreePath path = new TreePath(model.getPathToRoot(node));
+
+ tree.setSelectionPath(path);
+ tree.scrollPathToVisible(path);
+ }
+
+ public JaxxNode findNode(JaxxNode node, String... ids) {
+ JaxxNode result = null;
+ for (String id : ids) {
+
+ result = node.findNodeById(id, model, getDataProvider());
+
+ if (result == null) {
+
+ // un des noeud n'a pas ete trouve, on sort
+ break;
+ }
+ node = result;
+ }
+ return result;
+ }
+
+ public JaxxNode removeChildNode(JaxxNode node) {
+ JaxxNode parentNode = node.getParent();
+ model.removeNodeFromParent(node);
+ return parentNode;
+ }
+
+ public void moveNode(JaxxNode parentNode, JaxxNode node, int position) {
+ parentNode.remove(node);
+ parentNode.insert(node, position);
+ model.nodeStructureChanged(parentNode);
+ }
+
+// public JaxxNode addUnsavedNode(JaxxNode parentNode, Class<?> type) {
+//
+// // noeud en mode creation
+// String label = decoratorService.getEntityLabel(type) + ".unsaved";
+// JaxxNode result = new JaxxNode(type, null, label, false, null);
+// parentNode.add(result);
+// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
+// return result;
+// }
+//
+// public JaxxNode addMaree(JaxxNode parentNode, Maree bean) {
+// JaxxNode result;
+// if (bean == null) {
+// throw new NullPointerException("Ne peut pas ajouter un objet null");
+// }
+//
+// result = new JaxxNode(Maree.class, bean.getTopiaId(), false, null);
+//
+// // Creation d'un node routes
+// JaxxNode child = new JaxxNode(
+// String.class,
+// n_("observe.common.routes"),
+// Maree.PROPERTY_ROUTE,
+// false,
+// new RoutesNodeChildLoador()
+// );
+// result.add(child);
+// parentNode.add(result);
+//
+// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
+// model.nodesWereInserted(result, new int[]{result.getIndex(child)});
+// return result;
+// }
+//
+// public JaxxNode addRoute(JaxxNode parentNode, Route bean) {
+// JaxxNode result;
+// if (bean == null) {
+// throw new NullPointerException("Ne peut pas ajouter un objet null");
+// }
+// result = new JaxxNode(Route.class, bean.getTopiaId(), false, null);
+//
+// // Creation d'un node activites
+// JaxxNode child = new JaxxNode(
+// String.class,
+// n_("observe.common.activites"),
+// Route.PROPERTY_ACTIVITE,
+// false,
+// new ActivitesNodeChildLoador()
+// );
+// result.add(child);
+// parentNode.add(result);
+//
+// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
+// model.nodesWereInserted(result, new int[]{result.getIndex(child)});
+// return result;
+// }
+//
+// public JaxxNode addActivite(JaxxNode parentNode, Activite bean) {
+// JaxxNode result;
+// if (bean == null) {
+// throw new NullPointerException("Ne peut pas ajouter un objet null");
+// }
+// result = new JaxxNode(Activite.class,
+// bean.getTopiaId(),
+// false,
+// new ActiviteNodeChildLoador());
+// parentNode.add(result);
+//
+// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
+// return result;
+// }
+//
+// public JaxxNode addObjetFlottant(JaxxNode parentNode, ObjetFlottant bean) {
+// JaxxNode result;
+// if (bean == null) {
+// throw new NullPointerException("Ne peut pas ajouter un objet null");
+// }
+// result = new JaxxNode(ObjetFlottant.class, bean.getTopiaId(), false, new ObjetFlottantNodeChildLoador());
+// parentNode.add(result);
+//
+// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
+// return result;
+// }
+//
+// public JaxxNode addCalee(JaxxNode parentNode, Calee bean) {
+// JaxxNode result;
+// if (bean == null) {
+// throw new NullPointerException("Ne peut pas ajouter un objet null");
+// }
+// result = new JaxxNode(Calee.class, bean.getTopiaId(), false, new CaleeNodeChildLoador());
+// parentNode.add(result);
+//
+// model.nodesWereInserted(parentNode, new int[]{parentNode.getIndex(result)});
+// return result;
+// }
+
+ protected JTree getTree() {
+ return tree;
+ }
+
+ protected DefaultTreeModel createModel(JaxxNode node) {
+ model = new DefaultTreeModel(node);
+ model.addTreeModelListener(treeModelListener);
+ return model;
+ }
+
+ public void reloadModel(JTree tree) {
+
+// DataSelectionTreeCellRenderer r = (DataSelectionTreeCellRenderer) tree.getCellRenderer();
+// r.clearCache();
+// tree.clearSelection();
+ DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
+ TreeNode node = (TreeNode) model.getRoot();
+ reload(model, node);
+ }
+
+ private void reload(DefaultTreeModel model, TreeNode node) {
+ model.nodeChanged(node);
+ Enumeration<?> enumeration = node.children();
+ while (enumeration.hasMoreElements()) {
+ TreeNode treeNode = (TreeNode) enumeration.nextElement();
+ model.nodeChanged(treeNode);
+ reload(model, treeNode);
+ }
+ }
+
+ public void setDataProvider(DataProvider dataSource) {
+ this.dataSource = dataSource;
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/JaxxTreeHelper.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/package.html
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/package.html (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/package.html 2010-06-07 14:50:20 UTC (rev 1953)
@@ -0,0 +1,12 @@
+<html>
+<body>
+<h1>JAXX - tree utilities</h1>
+
+This package contains all the classes of the new tree framework.
+
+<p>
+ Replace the previous framework from package
+ <code>jaxx.runtime.swing.navigation</code>
+</p>
+</body>
+</html>
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/tree/package.html
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r1952 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext
by tchemit@users.nuiton.org 07 Jun '10
by tchemit@users.nuiton.org 07 Jun '10
07 Jun '10
Author: tchemit
Date: 2010-06-07 16:49:50 +0200 (Mon, 07 Jun 2010)
New Revision: 1952
Url: http://nuiton.org/repositories/revision/jaxx/1952
Log:
add header
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStep.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStep.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStep.java 2010-06-07 10:44:18 UTC (rev 1951)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStep.java 2010-06-07 14:49:50 UTC (rev 1952)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
package jaxx.runtime.swing.wizard.ext;
import jaxx.runtime.swing.wizard.WizardStep;
1
0
r1951 - in trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard: . ext
by tchemit@users.nuiton.org 07 Jun '10
by tchemit@users.nuiton.org 07 Jun '10
07 Jun '10
Author: tchemit
Date: 2010-06-07 12:44:18 +0200 (Mon, 07 Jun 2010)
New Revision: 1951
Url: http://nuiton.org/repositories/revision/jaxx/1951
Log:
introduce wizard ext package and remove old too complex wizard operation framework
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStep.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStepModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtUI.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtUtil.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardState.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/package.html
Removed:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationStep.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java 2010-06-05 07:51:37 UTC (rev 1950)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -45,7 +45,7 @@
* @see WizardStep
* @since 1.3
*/
-public class WizardModel<E extends WizardStep> {
+public abstract class WizardModel<E extends WizardStep> {
public static final String STEPS_PROPERTY_NAME = "steps";
@@ -259,7 +259,9 @@
firePropertyChange(VALID_STEP_PROPERTY_NAME, null, validStep);
}
- protected Class<E> getStepClass() {
+ public abstract void updateUniverse();
+
+ public Class<E> getStepClass() {
return stepClass;
}
@@ -279,15 +281,12 @@
pcs.firePropertyChange(propertyName, oldValue, newValue);
}
+ protected void firePropertyChange(String propertyName, Object newValue) {
+ pcs.firePropertyChange(propertyName, null, newValue);
+ }
+
protected void fireIndexedPropertyChange(String propertyName, int index,
Object oldValue, Object newValue) {
pcs.fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
}
-
- protected E[] updateStepUniverse() {
- return null;
- }
-
- protected void updateUniverse() {
- }
}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java 2010-06-05 07:51:37 UTC (rev 1950)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -1,169 +0,0 @@
-/*
- * #%L
- * JAXX :: Runtime
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2010 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>.
- * #L%
- */
-package jaxx.runtime.swing.wizard;
-
-import jaxx.runtime.JAXXContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.SwingWorker;
-
-/**
- * La classe de base a implanter pour definir l'action d'une operation dans un
- * wizard.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @param <E> le type d'étapes
- * @param <M> le type de modèle
- * @since 1.3
- */
-public abstract class WizardOperationAction<E extends WizardOperationStep, M extends WizardOperationModel<E>, O extends WizardOperationActionModel<E>> extends SwingWorker<WizardState, String> {
-
- /** Logger */
- private static final Log log = LogFactory.getLog(WizardOperationAction.class);
-
- protected O operationModel;
-
- public WizardOperationAction(O operationModel) {
- this.operationModel = operationModel;
- }
-
- public E getOperation() {
- return operationModel.getOperation();
- }
-
- public O getOperationModel() {
- return operationModel;
- }
-
- public WizardState getOperationState() {
- return getModel().getOperationState();
- }
-
- public Exception getError() {
- return operationModel.getError();
- }
-
- /**
- * @param e the error to set
- * @deprecated since 2.1 prefer use the {@link WizardOperationActionModel#setError(Exception)}
- */
- @Deprecated
- public void setError(Exception e) {
- operationModel.setError(e);
- }
-
- public void sendMessage(String msg) {
- firePropertyChange("message", null, msg);
- }
-
- /**
- * Recopie les états d'une action vers une nouvelle action.
- * <p/>
- * Cette méthode est appellé quand une action se déroule en plusieurs
- * étapes. Du fait que les {@link SwingWorker} ne sont utilisable qu'une
- * seule fois, on recopie les états de l'action courante vers la nouvelle
- * action à exécuter.
- *
- * @param newAction la nouvelle action
- */
- public void copyTo(WizardOperationAction<?, ?, ?> newAction) {
- ((WizardOperationAction<?, ?, O>)newAction).operationModel = operationModel;
- }
-
- public abstract void start(JAXXContext context);
-
- public abstract void beforeAction(JAXXContext context, M model) throws Exception;
-
- public abstract WizardState doAction(M model) throws Exception;
-
- public abstract WizardState onError(M model, Exception e);
-
- public abstract WizardState onCancel(M model, Exception e);
-
- protected abstract M getModel();
-
- protected abstract JAXXContext getContext();
-
- @Override
- public String toString() {
- return super.toString() + " < operation: " + getOperation() + ", state: " +
- getState() + " >";
- }
-
- @Override
- protected WizardState doInBackground() throws Exception {
- log.trace(this);
- WizardState result;
- M model = getModel();
- try {
- beforeAction(getContext(), model);
- result = doAction(model);
- } catch (Exception e) {
- operationModel.setError(e);
- result = onError(model, e);
- }
- return result;
- }
-
- @Override
- protected void done() {
- log.trace(this);
- WizardState result = null;
- try {
- if (isCancelled()) {
-
- result = onCancel(getModel(), operationModel.getError());
- } else {
- result = get();
- }
- } catch (Exception e) {
- result = WizardState.FAILED;
- operationModel.setError(e);
- // ne devrait jamais arrivé ?
- log.error(e.getMessage(), e);
- } finally {
- // on enregistre le resultat de l'opération
- getModel().setOperationState(result);
- getModel().setBusy(false);
- }
- }
-
- public void destroy() {
- if (operationModel != null) {
- operationModel.destroy();
- operationModel = null;
- }
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- if (log.isDebugEnabled()) {
- log.debug("Will destroy " + this);
- }
- destroy();
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java 2010-06-05 07:51:37 UTC (rev 1950)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -1,122 +0,0 @@
-/*
- * #%L
- * JAXX :: Runtime
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2010 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>.
- * #L%
- */
-package jaxx.runtime.swing.wizard;
-
-import jaxx.runtime.JAXXUtil;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-
-/**
- * Abstract model of {@link WizardOperationAction}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @see WizardOperationAction
- * @since 2.1
- */
-public abstract class WizardOperationActionModel<E extends WizardOperationStep> {
-
- /** Logger */
- private static final Log log =
- LogFactory.getLog(WizardOperationActionModel.class);
-
- /** pour propager les changements dans le modèle vers l'ui */
- private final PropertyChangeSupport pcs;
-
- protected final E operation;
-
-// protected WizardState operationState;
-
- protected Exception error;
-
- protected WizardOperationActionModel(E operation) {
- this.operation = operation;
- pcs = new PropertyChangeSupport(this);
- }
-
- public final E getOperation() {
- return operation;
- }
-
-// public final WizardState getOperationState() {
-// return operationState;
-// }
-
- public final Exception getError() {
- return error;
- }
-
- public void setError(Exception error) {
- this.error = error;
- }
-
-// public void setOperationState(WizardState operationState) {
-// this.operationState = operationState;
-// }
-
- public final void addPropertyChangeListener(PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(listener);
- }
-
- public final void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(propertyName, listener);
- }
-
-
- public final void removePropertyChangeListener(PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(listener);
- }
-
- public final void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(propertyName, listener);
- }
-
- public void destroy() {
- if (log.isDebugEnabled()) {
- log.debug("will destroy " + this);
- }
-
- // remove all listeners
- JAXXUtil.destroy(pcs);
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- destroy();
- }
-
- protected final void firePropertyChange(String propertyName,
- Object oldValue,
- Object newValue) {
- pcs.firePropertyChange(propertyName, oldValue, newValue);
- }
-
- protected final void firePropertyChange(String propertyName, Object newValue) {
- pcs.firePropertyChange(propertyName, null, newValue);
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java 2010-06-05 07:51:37 UTC (rev 1950)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -1,228 +0,0 @@
-/*
- * #%L
- * JAXX :: Runtime
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2010 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>.
- * #L%
- */
-package jaxx.runtime.swing.wizard;
-
-import jaxx.runtime.JAXXContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.SwingWorker.StateValue;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.util.Date;
-
-/**
- * Thread qui réalise les opérations.
- * <p/>
- * Pour exécuter une nouvelle opération, on utilise la méthode {@link
- * #launchOperation(WizardOperationStep)}.
- * <p/>
- * Note: Pour bloquer (ou débloquer) le thread, on utilise la méthode {@link
- * #setWaiting(boolean)}
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @param <E> le type des etapes
- * @param <M> le type de modele
- * @param <A> le type d'action d'operation
- * @since 1.3
- */
-public abstract class WizardOperationActionThread<E extends WizardOperationStep, M extends WizardOperationModel<E>, A extends WizardOperationAction<E, M,?>> extends Thread implements PropertyChangeListener {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- private static final Log log = LogFactory.getLog(WizardOperationActionThread.class);
-
- /** l'état du thread si annulé */
- private boolean canceled;
-
- protected Class<M> modelClass;
-
- protected A currentAction;
-
- /**
- * un lock pour permettre la suspension et la reprise du thread lors du mode
- * interactif.
- */
- private final Object LOCK = new Object();
-
- protected abstract M getModel();
-
- protected abstract JAXXContext getContext();
-
- public WizardOperationActionThread(Class<M> modelClass) throws IllegalArgumentException {
- super(WizardOperationActionThread.class.getSimpleName() + " " + new Date());
- this.modelClass = modelClass;
- }
-
- public void cancel() {
- log.info("cancel " + this);
- canceled = true;
-
- // on annule le modele
- getModel().cancel();
-
- // on rend la main au thread
- setWaiting(false);
- }
-
- @SuppressWarnings("unchecked")
- public A launchOperation(E operation) {
-
- if (currentAction != null && (!currentAction.isDone() || currentAction.getOperationState() == WizardState.RUNNING)) {
- // on ne peut traiter qu'une seule opération à la fois
- throw new IllegalStateException("can not add a operation when thread is busy, or has another operation to be done");
- }
- currentAction = (A) getModel().getOperationAction(operation);
-
- // on libere le thread pour qu'il execute l'opération
- setWaiting(false);
-
- return currentAction;
- }
-
- public A getCurrentAction() {
- return currentAction;
- }
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- log.trace(evt.getPropertyName() + " <" + evt.getOldValue() + " - " + evt.getNewValue() + ">");
- if ("state".equals(evt.getPropertyName())) {
- StateValue state = (StateValue) evt.getNewValue();
- if (state == StateValue.DONE) {
- // on rend la main au thread pour qu'il attende une prochaine operation
- setWaiting(false);
- }
- }
- }
-
- @Override
- public void run() {
- try {
-
- // on vérifie que le context contient bien le modèle
- if (getModel() == null) {
- throw new NullPointerException("could not find model " + modelClass + " for " + this);
- }
-
- while (!canceled) {
-
- if (canceled) {
- // une annulation a été demandé
- // donc même si une opération est demandée, on ne la traite
- // pas
- break;
- }
-
- // en attente qu'une opération
- // le block est bloqué jusqu'à arrivée d'une opération
- // ou une demande d'annulation
- setWaiting(true);
-
- // le thread a repris la main, donc plus en attente
- log.trace("no more waiting " + this);
-
- if (!canceled) {
- // une opération a été demandée
-
- // le thread écoute les modifications de l'action
- currentAction.addPropertyChangeListener(this);
-
- // l'opération passe en etant en cours
- getModel().setOperationState(WizardState.RUNNING);
-
- // démarrage de l'opération dans un worker
- currentAction.start(getContext());
- // le thread est bloqué jusqu'à la fin de l'opération
- // ou une demande d'annulation
- setWaiting(true);
-
- // le thread reprend la main des que l'operation
- // est terminée ou a été annulée, on passera alors
- // dans la méthode onPropertyChanged
-
- if (canceled) {
- getModel().setOperationState(WizardState.CANCELED);
- } else {
- getModel().setOperationState(currentAction.getOperationState());
- }
-
- // le thread n'écoute plus l'action car elle est terminée
- // ou annulée
- currentAction.removePropertyChangeListener(this);
- // suppression de l'action
- //currentAction = null;
- }
-
- }
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- unlockThread();
- log.trace(this + " will close...");
- close();
- }
- }
-
- /** La méthode pour nettoyer le thread, a la fermeture. */
- protected void close() {
- // par defaut, on ne fait rien
- log.trace(this);
- }
-
- protected void setWaiting(boolean waiting) {
-
- if (waiting && !canceled) {
- // locking thread
- try {
- lockThread();
- } catch (InterruptedException ex) {
- log.error(ex.getMessage(), ex);
- canceled = true;
- }
- }
-
- if (!waiting) {
- // release lock
- unlockThread();
- }
- }
-
- protected void lockThread() throws InterruptedException {
- synchronized (LOCK) {
- log.trace(this);
- // lock
- LOCK.wait();
- }
- }
-
- protected void unlockThread() {
- synchronized (LOCK) {
- log.trace(this);
- // unlock
- LOCK.notify();
- }
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java 2010-06-05 07:51:37 UTC (rev 1950)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -1,382 +0,0 @@
-/*
- * #%L
- * JAXX :: Runtime
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2010 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>.
- * #L%
- */
-package jaxx.runtime.swing.wizard;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.SwingWorker.StateValue;
-import java.util.Arrays;
-import java.util.EnumMap;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Un modèle de wizard avec des opérations.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @param <E> le type des étapes.
- * @since 1.3
- */
-public class WizardOperationModel<E extends WizardOperationStep> extends WizardModel<E> {
-
-
- /** Logger */
- private static final Log log = LogFactory.getLog(WizardOperationModel.class);
-
- public static final String BUSY_PROPERTY_NAME = "busy";
-
- public static final String OPERATIONS_PROPERTY_NAME = "operations";
-
- public static final String OPERATION_STATE_PROPERTY_NAME = "operationState";
-
- public static final String MODEL_STATE_PROPERTY_NAME = "modelState";
-
- public static final String WAS_STARTED_PROPERTY_NAME = "wasStarted";
-
- /** La liste des opérations à effectuer */
- protected Set<E> operations;
-
- /** le dictionnaire des modèles d'opération */
- protected final Map<E, WizardOperationActionModel<E>> models;
-
- /** Pour conserver les états des opérations */
- protected Map<E, WizardState> operationStates;
-
- protected Map<E, WizardOperationAction<?, ? extends WizardOperationModel<E>, ? extends WizardOperationActionModel<E>>> operationActions;
-
- /** L'état générale du modèle */
- protected WizardState modelState;
-
- /** un drapeau pour savoir siune opération a été lancée */
- protected boolean wasStarted;
-
- /** un drapeau pour savoir si le modèle est occupé. */
- protected boolean busy;
-
- @SuppressWarnings("unchecked")
- public <T extends Enum<T>> WizardOperationModel(Class<E> stepClass, E... steps) {
- super(stepClass, steps);
- Class<T> k = (Class<T>) stepClass;
- operationStates = new EnumMap(k);
- operations = (Set<E>) EnumSet.noneOf(k);
- operationActions = new EnumMap(k);
- models = (Map<E, WizardOperationActionModel<E>>) new EnumMap(k);
- for (T o : EnumSet.allOf(k)) {
- E step = (E) o;
- if (step.isOperation()) {
-
- // initialisation du modèle associé à l'opération
- WizardOperationActionModel<E> model = (WizardOperationActionModel<E>) step.newModel();
- if (log.isInfoEnabled()) {
- log.info("[" + step + "] Add an operation model " + model);
- }
- models.put(step, model);
- }
- }
- }
-
- public Set<E> getOperations() {
- return operations;
- }
-
- public WizardState getModelState() {
- return modelState;
- }
-
- public boolean isWasStarted() {
- return wasStarted;
- }
-
- public boolean isBusy() {
- return busy;
- }
-
- public void setBusy(boolean busy) {
- boolean oldValue = this.busy;
- this.busy = busy;
- firePropertyChange(BUSY_PROPERTY_NAME, oldValue, busy);
- }
-
- public boolean containsOperation(E step) {
- return getOperations().contains(step);
- }
-
- @SuppressWarnings("unchecked")
- public E getOperation() {
- return getStep() != null && getStep().isOperation() ? getStep() : null;
- }
-
- public WizardState getOperationState() {
- E operation = getOperation();
- return getOperationState(operation);
- }
-
- public WizardState getOperationState(E operation) {
- return operationStates.get(operation);
- }
-
- public WizardOperationAction<?, ?, ?> getOperationAction(E operation) {
- if (operation==null || !operation.isOperation()) {
- return null;
- }
- WizardOperationAction<?, ?, ?> action = operationActions.get(operation);
- if (action == null) {
- try {
- WizardOperationActionModel<?> operationModel = getOperationModel(operation);
- action = operation.newAction(operationModel);
- operationActions.put(operation, (WizardOperationAction<E, ? extends WizardOperationModel<E>, ? extends WizardOperationActionModel<E>>) action);
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- }
- return action;
- }
-
- public void setOperationState(WizardState operationState) {
- E operation = getOperation();
- setOperationState(operation, operationState);
- }
-
- public void setOperationState(E operation, WizardState operationState) {
- WizardState oldValue = getOperationState(operation);
- operationStates.put(operation, operationState);
- fireIndexedPropertyChange(OPERATION_STATE_PROPERTY_NAME, getSteps().indexOf(operation), oldValue, operationState);
- updateModelState(operation, operationState);
- validate();
- }
-
- public boolean[] getAccessibleSteps() {
- if (log.isDebugEnabled()) {
- log.debug("compute with steps "+getSteps());
- }
- boolean[] result = new boolean[getSteps().size()];
- int index = getSteps().indexOf(getStep());
- if (index != -1) {
-
- for (int i = 0, j = steps.size(); i < j; i++) {
- if (i <= index) {
- // tous les onglets inferieur ou egal au courant sont accessibles
- result[i] = true;
- continue;
- }
- // les onglets au dela de l'onglet sélectionné sont accessibles
- // uniquement si l'onglet precedent est accessible, valide et son etat est a SUCCESSED
- E previousStep = steps.get(i - 1);
- result[i] = modelState == WizardState.SUCCESSED ||
- result[i - 1] &&
- validate(previousStep) &&
- (!previousStep.isOperation() || getOperationState(previousStep) == WizardState.SUCCESSED);
- }
- }
- if (log.isDebugEnabled()) {
- log.debug("accessibles steps -------- " + Arrays.toString(result));
- }
- return result;
- }
-
- @Override
- public void start() {
- super.start();
-
- // update universe of steps and actions
- updateUniverse();
-
- // le modèle n'est pas démarré
- setModelState(WizardState.PENDING);
- }
-
- public void cancel() {
-
- for (E op : operations) {
- if (getOperationState(op) == WizardState.PENDING) {
- // on annule l'opération à venir
- setOperationState(op, WizardState.CANCELED);
- }
- }
- setModelState(WizardState.CANCELED);
- if (getStep() != null && getStep().isOperation()) {
- WizardOperationAction<?, ?, ?> action = getOperationAction(getStep());
- if (action != null) {
- if (!action.isCancelled() && !action.isDone() && action.getState() == StateValue.STARTED) {
- // on annule l'action
- action.cancel(true);
- }
- }
- }
- }
-
- public WizardOperationModel<E> addOperation(E operation) {
- operations.add(operation);
- // mis a jour de l'univers des etapes et operations
- updateUniverse();
- // validation
- validate();
- return this;
- }
-
- public void removeOperation(E operation) {
- operations.remove(operation);
-
- // mis a jour de l'univers des etapes et operations
- updateUniverse();
- // validation
- validate();
- }
-
- @Override
- public void setSteps(E... steps) {
- super.setSteps(steps);
- // on force la propagation de la nouvelle liste
- firePropertyChange(OPERATIONS_PROPERTY_NAME, null, operations);
- updateOperationStates(Arrays.asList(steps));
- }
-
- public WizardOperationActionModel<E> getOperationModel(E operation) {
- if (operation==null) {
- return null;
- }
- if (!operation.isOperation()) {
- throw new IllegalStateException("step [" + operation + "] is not an operation.");
- }
- return models.get(operation);
- }
-
- public void updateOperationStates(List<E> steps) {
- int index = 0;
- for (E e : steps) {
- fireIndexedPropertyChange(OPERATION_STATE_PROPERTY_NAME, index++, null, getOperationState(e));
- }
- firePropertyChange(MODEL_STATE_PROPERTY_NAME, null, modelState);
- }
-
- public WizardOperationAction<?, ?, ?> reloadOperation(E operation) {
- operationActions.remove(operation);
- WizardOperationAction<?, ?, ?> newOp = getOperationAction(operation);
- return newOp;
- }
-
- protected void setModelState(WizardState modelState) {
- WizardState oldValue = this.modelState;
- this.modelState = modelState;
- firePropertyChange(MODEL_STATE_PROPERTY_NAME, oldValue, modelState);
- if (!wasStarted) {
- if ((oldValue == null || oldValue == WizardState.PENDING) && modelState == WizardState.RUNNING) {
- wasStarted = true;
- firePropertyChange(WAS_STARTED_PROPERTY_NAME, false, true);
- }
- }
- }
-
- protected void updateModelState(E operation, WizardState operationState) {
-
- switch (operationState) {
- case RUNNING:
- //le modele est occupé
- setModelState(WizardState.RUNNING);
- break;
- case FAILED:
- //le modele est en erreur
- setModelState(WizardState.FAILED);
- break;
- case CANCELED:
- //le modele devient annulé
- setModelState(WizardState.CANCELED);
- return;
- case PENDING:
- //le modele est en attente
- setModelState(WizardState.PENDING);
- break;
- case NEED_FIX:
- //le modele est en attente
- setModelState(WizardState.PENDING);
- break;
- case SUCCESSED:
- // on regarde si on peut passer le model a l'état success
- boolean valid = true;
- for (E o : operations) {
- if (getOperationState(o) != WizardState.SUCCESSED) {
- valid = false;
- break;
- }
- }
- if (valid) {
- setModelState(WizardState.SUCCESSED);
- } else {
- setModelState(WizardState.PENDING);
- }
- break;
- }
- updateOperationStates(steps);
- }
-
- @Override
- protected void updateUniverse() {
- E[] newSteps = updateStepUniverse();
- setSteps(newSteps);
- }
-
- @Override
- public void destroy() {
- super.destroy();
- Set<E> operations = getOperations();
- for (E op : operations) {
- WizardOperationAction<?, ?, ?> action = getOperationAction(op);
- if (log.isDebugEnabled()) {
- log.debug("destroy action " + action);
- }
- action.destroy();
- }
- }
-
- @Override
- protected E[] updateStepUniverse() {
- // on met a jour les opérations
- for (E op : operations) {
- if (!operationStates.containsKey(op)) {
- operationStates.put(op, WizardState.PENDING);
- }
- }
- for (E op : operationStates.keySet()) {
- if (!operations.contains(op)) {
- operationStates.remove(op);
- }
- }
- return null;
- }
-
- protected int getOperationIndex(E operation) {
- int index = 0;
- for (E o : operations) {
- if (o.equals(operation)) {
- return index;
- }
- index++;
- }
- return -1;
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationStep.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationStep.java 2010-06-05 07:51:37 UTC (rev 1950)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationStep.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -1,67 +0,0 @@
-/*
- * #%L
- * JAXX :: Runtime
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2010 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>.
- * #L%
- */
-package jaxx.runtime.swing.wizard;
-
-/**
- * Le contrat a implanter pour une etapes dans le modèle de wizard avec
- * opérations.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.3
- */
-public interface WizardOperationStep extends WizardStep {
-
- /** @return le label de l'opération */
- String getOperationLabel();
-
- /** @return la description de l'opération */
- String getOperationDescription();
-
- /** @return le type du modèle de l'action */
- Class<? extends WizardOperationActionModel<?>> getModelClass();
-
- /**
- * @return le type de l'action associée à l'étape ou <code>null</code> si
- * l'étape n'a pas d'opération associée.
- */
- Class<? extends WizardOperationAction<?, ?, ?>> getActionClass();
-
- /** @return le type de l'ui de l'opération */
- Class<? extends WizardStepUI<?, ?>> getUiClass();
-
- /**
- * @return <code>true</code> si l'étape a une opération associée,
- * <code>false</code> sinon.
- */
- boolean isOperation();
-
- boolean isConfig();
-
- WizardOperationActionModel<?> newModel();
-
- WizardOperationAction<?, ?, ?> newAction(WizardOperationActionModel<?> operationModel);
-
- WizardStepUI<?,?> newUI(WizardUI<?,?> ui) ;
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java 2010-06-05 07:51:37 UTC (rev 1950)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -1,51 +0,0 @@
-/*
- * #%L
- * JAXX :: Runtime
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2010 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>.
- * #L%
- */
-package jaxx.runtime.swing.wizard;
-
-/**
- * Pour caractériser l'état d'une opération.
- *
- * @author tchemit <chemit(a)codelutin.com>
- */
-public enum WizardState {
-
- /** quand l'opération n'a pas encore été réalisée */
- PENDING,
-
- /** quand l'opération est en cours */
- RUNNING,
-
- /** quand l'opération est annulé en cours d'exécution */
- CANCELED,
-
- /** quand une erreur s'est produite pendant l'exécution */
- FAILED,
-
- /** quand l'exécution s'est terminée mais requière des corrections */
- NEED_FIX,
-
- /** quand l'exécution s'est terminée et ne requière pas de correction */
- SUCCESSED
-}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java 2010-06-05 07:51:37 UTC (rev 1950)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -24,7 +24,7 @@
*/
package jaxx.runtime.swing.wizard;
-import javax.swing.*;
+import javax.swing.JTabbedPane;
/**
* Contrat a respecter pour une ui de wizard.
@@ -67,9 +67,6 @@
*/
JTabbedPane getTabs();
- /** Méthode invoqué lorsque la première opération du modèlé a été démarrée. */
- void onWasStarted();
-
/**
* Méthode invoquée lorsque l'univers des étapes a été modifié dans le
* modèle.
@@ -84,20 +81,4 @@
* @param newStep la nouvelle étape courante
*/
void onStepChanged(E newStep);
-
- /**
- * Méthode invoquée lorsque l'état interne du modèle a changé.
- *
- * @param newState le nouvelle état du modèle de wizard
- */
- void onModelStateChanged(WizardState newState);
-
- /**
- * Méthode invoqué lorsque l'état d'une opération a changé.
- *
- * @param step l'étape dont l'état a changé
- * @param newState le nouvel état pour l'étape donné
- */
- void onOperationStateChanged(E step, WizardState newState);
-
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java 2010-06-05 07:51:37 UTC (rev 1950)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -29,7 +29,6 @@
import javax.swing.JTabbedPane;
import java.awt.Component;
-import java.beans.IndexedPropertyChangeEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.Array;
@@ -51,24 +50,24 @@
protected WizardUtil() {
}
- public static boolean acceptStates(WizardState state, WizardState... accepted) {
- for (WizardState s : accepted) {
- if (s == state) {
- return true;
- }
- }
- return false;
- }
+// public static boolean acceptStates(WizardState state, WizardState... accepted) {
+// for (WizardState s : accepted) {
+// if (s == state) {
+// return true;
+// }
+// }
+// return false;
+// }
+//
+// public static boolean rejectStates(WizardState state, WizardState... rejected) {
+// for (WizardState s : rejected) {
+// if (s == state) {
+// return false;
+// }
+// }
+// return true;
+// }
- public static boolean rejectStates(WizardState state, WizardState... rejected) {
- for (WizardState s : rejected) {
- if (s == state) {
- return false;
- }
- }
- return true;
- }
-
public static void addDebugLogListener(final Log log, WizardModel<?> model) {
if (log.isDebugEnabled()) {
model.addPropertyChangeListener(new PropertyChangeListener() {
@@ -100,10 +99,10 @@
@SuppressWarnings("unchecked")
public void propertyChange(PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
- if (WizardOperationModel.WAS_STARTED_PROPERTY_NAME.equals(propertyName)) {
- ui.onWasStarted();
- return;
- }
+// if (WizardExtModel.WAS_STARTED_PROPERTY_NAME.equals(propertyName)) {
+// ui.onWasStarted();
+// return;
+// }
if (WizardModel.STEPS_PROPERTY_NAME.equals(propertyName)) {
List<E> steps = (List<E>) evt.getNewValue();
ui.onStepsChanged(
@@ -114,9 +113,9 @@
}
if (WizardModel.STEP_PROPERTY_NAME.equals(propertyName)) {
ui.onStepChanged((E) evt.getNewValue());
- return;
+// return;
}
- if (WizardModel.VALID_STEP_PROPERTY_NAME.equals(propertyName)) {
+ /*if (WizardModel.VALID_STEP_PROPERTY_NAME.equals(propertyName)) {
Boolean value = (Boolean) evt.getNewValue();
if (value == null || !value) {
ui.onModelStateChanged(WizardState.NEED_FIX);
@@ -125,18 +124,18 @@
}
return;
}
- if (WizardOperationModel.MODEL_STATE_PROPERTY_NAME.equals(propertyName)) {
+ if (WizardExtModel.MODEL_STATE_PROPERTY_NAME.equals(propertyName)) {
//TODO should be unicast : only for good stepUI ?
ui.onModelStateChanged((WizardState) evt.getNewValue());
return;
}
- if (WizardOperationModel.OPERATION_STATE_PROPERTY_NAME.equals(propertyName)) {
+ if (WizardExtModel.STEP_STATE_PROPERTY_NAME.equals(propertyName)) {
IndexedPropertyChangeEvent e = (IndexedPropertyChangeEvent) evt;
int stepIndex = e.getIndex();
E step = ui.getModel().getSteps().get(stepIndex);
ui.onOperationStateChanged(step, (WizardState) evt.getNewValue());
return;
- }
+ }*/
}
});
}
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtModel.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtModel.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -0,0 +1,453 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.wizard.ext;
+
+import jaxx.runtime.swing.wizard.WizardModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Un modèle de wizard avec des opérations.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @param <E> le type des étapes.
+ * @since 1.3
+ */
+public abstract class WizardExtModel<E extends WizardExtStep> extends WizardModel<E> {
+
+ /** Logger */
+ private static final Log log = LogFactory.getLog(WizardExtModel.class);
+
+ public static final String BUSY_PROPERTY_NAME = "busy";
+
+ public static final String OPERATIONS_PROPERTY_NAME = "operations";
+
+ public static final String STEP_STATE_PROPERTY_NAME = "stepState";
+
+ public static final String MODEL_STATE_PROPERTY_NAME = "modelState";
+
+ public static final String WAS_STARTED_PROPERTY_NAME = "wasStarted";
+
+ /** La liste des opérations à effectuer */
+ protected Set<E> operations;
+
+ /** le dictionnaire des modèles d'opération */
+ protected final Map<E, WizardExtStepModel<E>> models;
+
+ /** Pour conserver les états des opérations */
+ protected Map<E, WizardState> stepStates;
+
+ /** L'état générale du modèle */
+ protected WizardState modelState;
+
+ /** un drapeau pour savoir siune opération a été lancée */
+ protected boolean wasStarted;
+
+ /** un drapeau pour savoir si le modèle est occupé. */
+ protected boolean busy;
+
+ @SuppressWarnings("unchecked")
+ public <T extends Enum<T>> WizardExtModel(Class<E> stepClass, E... steps) {
+ super(stepClass, steps);
+ Class<T> k = (Class<T>) stepClass;
+ stepStates = new EnumMap(k);
+ operations = (Set<E>) EnumSet.noneOf(k);
+ models = (Map<E, WizardExtStepModel<E>>) new EnumMap(k);
+ }
+
+ public Set<E> getOperations() {
+ return operations;
+ }
+
+ public WizardState getModelState() {
+ return modelState;
+ }
+
+ public boolean isWasStarted() {
+ return wasStarted;
+ }
+
+ public boolean isBusy() {
+ return busy;
+ }
+
+ public void setBusy(boolean busy) {
+ boolean oldValue = this.busy;
+ this.busy = busy;
+ firePropertyChange(BUSY_PROPERTY_NAME, oldValue, busy);
+ }
+
+ public boolean containsOperation(E step) {
+ return getOperations().contains(step);
+ }
+
+ @SuppressWarnings("unchecked")
+ public E getOperation() {
+ return getStep() != null && getStep().isOperation() ? getStep() : null;
+ }
+
+ public WizardState getStepState() {
+ E operation = getOperation();
+ return getStepState(operation);
+ }
+
+ public WizardState getStepState(E step) {
+ return stepStates.get(step);
+ }
+
+ public void setStepState(WizardState newState) {
+ E operation = getOperation();
+ setStepState(operation, newState);
+ }
+
+ public void setStepState(E step, WizardState newState) {
+ WizardState oldValue = getStepState(step);
+ stepStates.put(step, newState);
+ if (valueAdjusting) {
+ return;
+ }
+ fireIndexedPropertyChange(STEP_STATE_PROPERTY_NAME, getSteps().indexOf(step), oldValue, newState);
+ updateModelState(step, newState);
+ validate();
+ }
+
+ public boolean[] getAccessibleSteps() {
+ if (log.isDebugEnabled()) {
+ log.debug("compute with steps " + getSteps());
+ }
+ boolean[] result = new boolean[getSteps().size()];
+ int index = getSteps().indexOf(getStep());
+ if (index != -1) {
+
+ for (int i = 0, j = steps.size(); i < j; i++) {
+ if (i <= index) {
+ // tous les onglets inferieur ou egal au courant sont accessibles
+ result[i] = true;
+ continue;
+ }
+ // les onglets au dela de l'onglet sélectionné sont accessibles
+ // uniquement si l'onglet precedent est accessible, valide et son etat est a SUCCESSED
+ E previousStep = steps.get(i - 1);
+ result[i] = modelState == WizardState.SUCCESSED ||
+ result[i - 1] &&
+ validate(previousStep) &&
+ (!previousStep.isOperation() || getStepState(previousStep) == WizardState.SUCCESSED);
+ }
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("accessibles steps -------- " + Arrays.toString(result));
+ }
+ return result;
+ }
+
+ @Override
+ public void start() {
+// super.start();
+
+ if (steps.isEmpty()) {
+ throw new IllegalStateException("can not start, no step found");
+ }
+
+ // update universe of steps and actions
+ updateUniverse();
+
+ // set first step
+ step = null;
+ E startStep = steps.get(0);
+ setStep(startStep);
+
+ // model is ready
+ setModelState(WizardState.PENDING);
+
+ validate();
+ }
+
+ public void cancel() {
+
+ for (E op : operations) {
+ if (getStepState(op) == WizardState.PENDING) {
+ // on annule l'opération à venir
+ setStepState(op, WizardState.CANCELED);
+ }
+ }
+ setModelState(WizardState.CANCELED);
+ }
+
+ public WizardExtModel<E> addOperation(E operation) {
+ if (operations.contains(operation)) {
+
+ // skip add
+ return this;
+ }
+
+ log.info("Add operation " + operation);
+ operations.add(operation);
+ // mis a jour de l'univers des etapes et operations
+ updateUniverse();
+ // validation
+ validate();
+ return this;
+ }
+
+ public void removeOperation(E operation) {
+ if (!operations.contains(operation)) {
+
+ // skip remove
+ return;
+ }
+ operations.remove(operation);
+
+ // mis a jour de l'univers des etapes et operations
+ updateUniverse();
+ // validation
+ validate();
+ }
+
+ @Override
+ public void setSteps(E... steps) {
+ super.setSteps(steps);
+ if (valueAdjusting) {
+ return;
+ }
+ // on force la propagation de la nouvelle liste
+ firePropertyChange(OPERATIONS_PROPERTY_NAME, null, operations);
+ }
+
+ public WizardExtStepModel<E> getStepModel(E operation) {
+ if (operation == null) {
+ return null;
+ }
+ if (!operation.isOperation()) {
+ throw new IllegalStateException("step [" + operation + "] is not an operation.");
+ }
+ return models.get(operation);
+ }
+
+ public void updateStepStates(List<E> steps) {
+ int index = 0;
+ for (E e : steps) {
+ fireIndexedPropertyChange(STEP_STATE_PROPERTY_NAME, index++, null, getStepState(e));
+ }
+ firePropertyChange(MODEL_STATE_PROPERTY_NAME, null, modelState);
+ }
+
+ protected void setModelState(WizardState modelState) {
+ WizardState oldValue = this.modelState;
+ this.modelState = modelState;
+ firePropertyChange(MODEL_STATE_PROPERTY_NAME, oldValue, modelState);
+ if (!wasStarted) {
+ if ((oldValue == null || oldValue == WizardState.PENDING) && modelState == WizardState.RUNNING) {
+ wasStarted = true;
+ firePropertyChange(WAS_STARTED_PROPERTY_NAME, false, true);
+ }
+ }
+ }
+
+ protected void updateModelState(E step, WizardState newState) {
+
+ switch (newState) {
+ case RUNNING:
+ //le modele est occupé
+ setModelState(WizardState.RUNNING);
+ break;
+ case FAILED:
+ //le modele est en erreur
+ setModelState(WizardState.FAILED);
+ break;
+ case CANCELED:
+ //le modele devient annulé
+ setModelState(WizardState.CANCELED);
+ return;
+ case PENDING:
+ //le modele est en attente
+ setModelState(WizardState.PENDING);
+ break;
+ case NEED_FIX:
+ //le modele est en attente
+ setModelState(WizardState.PENDING);
+ break;
+ case SUCCESSED:
+ // on regarde si on peut passer le model a l'état success
+ boolean valid = true;
+ for (E o : operations) {
+ if (getStepState(o) != WizardState.SUCCESSED) {
+ valid = false;
+ break;
+ }
+ }
+ if (valid) {
+ setModelState(WizardState.SUCCESSED);
+ } else {
+ setModelState(WizardState.PENDING);
+ }
+ break;
+ }
+ updateStepStates(steps);
+ }
+
+ @Override
+ public void updateUniverse() {
+// setValueAdjusting(true);
+
+ List<E> oldSteps = new ArrayList<E>(getSteps());
+ log.info("Start updateUniverse (oldSteps = " + oldSteps + ")");
+ E[] newSteps = updateStepUniverse();
+ log.info("newSteps = " + Arrays.toString(newSteps));
+
+ // do nothing if steps has not changed
+ boolean skip = true;
+ for (E newStep : newSteps) {
+ if (!oldSteps.contains(newStep)) {
+ skip = false;
+ }
+ }
+
+ if (skip && oldSteps.size() == newSteps.length) {
+
+ // same steps, so nothing to do
+ log.info("Steps are same, do not modify anything");
+ return;
+ }
+
+ for (WizardExtStepModel<E> model : models.values()) {
+ log.info("Destroy previous model : " + model);
+ model.destroy();
+ }
+ models.clear();
+
+ List<E> toAdd = new ArrayList<E>(Arrays.asList(newSteps));
+
+ log.info("Will add models for " + toAdd);
+
+ Iterator<E> itr = toAdd.iterator();
+ while (itr.hasNext()) {
+
+ E step = itr.next();
+
+ if (step.getModelClass() == null) {
+
+ // no model attach to the step
+ itr.remove();
+ continue;
+ }
+
+ if (step.isOperation()) {
+
+ // step is operation, model must be instanciate
+ WizardExtStepModel<E> model = (WizardExtStepModel<E>) step.newModel();
+ if (log.isInfoEnabled()) {
+ log.info("[" + step + "] Add primary model " + model);
+ }
+ models.put(step, model);
+
+ itr.remove();
+ }
+
+ // step has a model
+ }
+
+ if (!toAdd.isEmpty()) {
+
+ // there is some steps with model to attach
+ itr = toAdd.iterator();
+ while (itr.hasNext()) {
+
+ E step = itr.next();
+ Class<? extends WizardExtStepModel<?>> modelClass = step.getModelClass();
+ WizardExtStepModel<E> selectedModel = null;
+ // find out in models a
+ for (WizardExtStepModel<E> model : models.values()) {
+ if (modelClass.isAssignableFrom(model.getClass())) {
+ // find one
+ selectedModel = model;
+ break;
+ }
+ }
+
+ if (selectedModel == null) {
+ throw new IllegalStateException("Could not find a primary model " + modelClass + " for step [" + step + "]");
+ }
+
+ log.info("[" + step + "] Attach model " + selectedModel);
+ models.put(step, selectedModel);
+ itr.remove();
+ }
+
+ if (!toAdd.isEmpty()) {
+ throw new IllegalStateException("There is some step no model : " + toAdd);
+ }
+ }
+
+ setSteps(newSteps);
+
+ // on met a jour les états des étapes
+ stepStates.clear();
+ for (E step : newSteps) {
+ if (!stepStates.containsKey(step)) {
+ setStepState(step, WizardState.PENDING);
+ }
+ }
+
+ // finally set the steps (this will refire a lot)
+
+ log.info("Ending updateUniverse");
+
+// setValueAdjusting(false);
+ }
+
+ protected abstract E[] updateStepUniverse();
+
+ @Override
+ public void destroy() {
+ super.destroy();
+
+ for (WizardExtStepModel<E> model : models.values()) {
+ if (log.isDebugEnabled()) {
+ log.debug("destroy model " + model);
+ }
+ model.destroy();
+ }
+ }
+
+ protected int getOperationIndex(E operation) {
+ int index = 0;
+ for (E o : operations) {
+ if (o.equals(operation)) {
+ return index;
+ }
+ index++;
+ }
+ return -1;
+ }
+}
\ No newline at end of file
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStep.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStep.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStep.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -0,0 +1,54 @@
+package jaxx.runtime.swing.wizard.ext;
+
+import jaxx.runtime.swing.wizard.WizardStep;
+import jaxx.runtime.swing.wizard.WizardStepUI;
+
+
+/**
+ * Extension de {@link WizardStep} avec des états supplémentaires.
+ * <p/>
+ * Chaque étape possède un modèle de type {@link #getModelClass()}.
+ * Ce modèle peut être partagé par plusieurs étapes.
+ * <p/>
+ * De plus, on a deux drapeaux {@link #isConfig()} pour savoir si l'étape est une phase de configuration.
+ * <p/>
+ * Le drapeau {@link #isOperation()} quand à lui permet de savoir si l'étape est une opération.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public interface WizardExtStep extends WizardStep {
+
+ /** @return le label de l'opération */
+ String getOperationLabel();
+
+ /** @return la description de l'opération */
+ String getOperationDescription();
+
+ /** @return le type du modèle de l'action */
+ Class<? extends WizardExtStepModel<?>> getModelClass();
+
+ /** @return le type de l'ui de l'opération */
+ Class<? extends WizardStepUI<?, ?>> getUiClass();
+
+ /** @return {@code true} si l'étape a une opération associée, {@code false} sinon. */
+ boolean isOperation();
+
+ /** @return {@code true} si l'étape est une phase de configuration, {@code false} sinon. */
+ boolean isConfig();
+
+ /**
+ * Instancie le modèle associée à l'étape.
+ *
+ * @return le nouveau modèle associé à l'étape
+ */
+ WizardExtStepModel<?> newModel();
+
+ /**
+ * Construit l'ui associée à l'étape.
+ *
+ * @param ui l'ui principale du wiard
+ * @return la noveau ui associé à l'étape
+ */
+ WizardStepUI<?, ?> newUI(WizardExtUI<?, ?> ui);
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStep.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStepModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStepModel.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStepModel.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -0,0 +1,111 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.wizard.ext;
+
+import jaxx.runtime.JAXXUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+/**
+ * Abstract model of {@link WizardExtStep}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @see WizardExtStep
+ * @since 2.1
+ */
+public abstract class WizardExtStepModel<E extends WizardExtStep> {
+
+ /** Logger */
+ private static final Log log = LogFactory.getLog(WizardExtStepModel.class);
+
+ /** for properties change support */
+ private final PropertyChangeSupport pcs;
+
+ /** step of the model */
+ protected final E step;
+
+ /** to store if an error occurs while running */
+ protected Exception error;
+
+ protected WizardExtStepModel(E step) {
+ this.step = step;
+ pcs = new PropertyChangeSupport(this);
+ }
+
+ public final E getStep() {
+ return step;
+ }
+
+ public final Exception getError() {
+ return error;
+ }
+
+ public void setError(Exception error) {
+ this.error = error;
+ }
+
+ public final void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ public final void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(propertyName, listener);
+ }
+
+
+ public final void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ public final void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(propertyName, listener);
+ }
+
+ public void destroy() {
+ if (log.isDebugEnabled()) {
+ log.debug("will destroy " + this);
+ }
+
+ // remove all listeners
+ JAXXUtil.destroy(pcs);
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ destroy();
+ }
+
+ protected final void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ pcs.firePropertyChange(propertyName, oldValue, newValue);
+ }
+
+ protected final void firePropertyChange(String propertyName, Object newValue) {
+ pcs.firePropertyChange(propertyName, null, newValue);
+ }
+}
\ No newline at end of file
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtStepModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtUI.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtUI.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtUI.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -0,0 +1,60 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.wizard.ext;
+
+import jaxx.runtime.swing.wizard.WizardUI;
+
+/**
+ * Contrat a respecter pour une ui de wizard.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @param <E> le type d'etape
+ * @param <M> le type de model
+ * @since 1.3
+ */
+public interface WizardExtUI<E extends WizardExtStep, M extends WizardExtModel<E>> extends WizardUI<E, M> {
+
+ /** Méthode invoqué lorsque le modèle a été initialisé. */
+ void onWasInit();
+
+ /** Méthode invoqué lorsque la première opération du modèlé a été démarrée. */
+ void onWasStarted();
+
+ /**
+ * Méthode invoquée lorsque l'état interne du modèle a changé.
+ *
+ * @param newState le nouvelle état du modèle de wizard
+ */
+ void onModelStateChanged(WizardState newState);
+
+ /**
+ * Méthode invoqué lorsque l'état d'une opération a changé.
+ *
+ * @param step l'étape dont l'état a changé
+ * @param newState le nouvel état pour l'étape donné
+ */
+ void onOperationStateChanged(E step, WizardState newState);
+
+}
\ No newline at end of file
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtUI.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtUtil.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtUtil.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -0,0 +1,124 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.wizard.ext;
+
+import jaxx.runtime.swing.wizard.WizardModel;
+import jaxx.runtime.swing.wizard.WizardUI;
+import jaxx.runtime.swing.wizard.WizardUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.beans.IndexedPropertyChangeEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.lang.reflect.Array;
+import java.util.List;
+
+/**
+ * Classe de méthodes utiles sur les wizard.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.3
+ */
+public class WizardExtUtil extends WizardUtil {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(WizardUI.class);
+
+ protected WizardExtUtil() {
+ }
+
+ public static boolean acceptStates(WizardState state, WizardState... accepted) {
+ for (WizardState s : accepted) {
+ if (s == state) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean rejectStates(WizardState state, WizardState... rejected) {
+ for (WizardState s : rejected) {
+ if (s == state) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static <E extends WizardExtStep, M extends WizardExtModel<E>> void installWizardUIListeners(final WizardExtUI<E, M> ui) {
+
+
+ PropertyChangeListener dispatcher = new PropertyChangeListener() {
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void propertyChange(PropertyChangeEvent evt) {
+ String propertyName = evt.getPropertyName();
+ if (WizardExtModel.WAS_STARTED_PROPERTY_NAME.equals(propertyName)) {
+ ui.onWasStarted();
+ return;
+ }
+ WizardExtModel<E> model = (WizardExtModel<E>) evt.getSource();
+ if (WizardModel.STEPS_PROPERTY_NAME.equals(propertyName)) {
+ List<E> steps = (List<E>) evt.getNewValue();
+ ui.onStepsChanged(
+ steps.toArray((E[]) Array.newInstance(
+ model.getStepClass(), steps.size()))
+ );
+ return;
+ }
+ if (WizardModel.STEP_PROPERTY_NAME.equals(propertyName)) {
+ ui.onStepChanged((E) evt.getNewValue());
+ return;
+ }
+ if (WizardModel.VALID_STEP_PROPERTY_NAME.equals(propertyName)) {
+ Boolean value = (Boolean) evt.getNewValue();
+ if (value == null || !value) {
+ ui.onModelStateChanged(WizardState.NEED_FIX);
+ } else {
+ ui.onModelStateChanged(WizardState.PENDING);
+ }
+ return;
+ }
+ if (WizardExtModel.MODEL_STATE_PROPERTY_NAME.equals(propertyName)) {
+ //TODO should be unicast : only for good stepUI ?
+ ui.onModelStateChanged((WizardState) evt.getNewValue());
+ return;
+ }
+ if (WizardExtModel.STEP_STATE_PROPERTY_NAME.equals(propertyName)) {
+ IndexedPropertyChangeEvent e = (IndexedPropertyChangeEvent) evt;
+ int stepIndex = e.getIndex();
+ E step = model.getSteps().get(stepIndex);
+ ui.onOperationStateChanged(step, (WizardState) evt.getNewValue());
+ }
+ }
+ };
+ M model = ui.getModel();
+ log.info("Adding dispatcher " + dispatcher + " to model " + model);
+ model.addPropertyChangeListener(dispatcher);
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardExtUtil.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardState.java (from rev 1950, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardState.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardState.java 2010-06-07 10:44:18 UTC (rev 1951)
@@ -0,0 +1,51 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.wizard.ext;
+
+/**
+ * Pour caractériser l'état d'une opération.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ */
+public enum WizardState {
+
+ /** quand l'opération n'a pas encore été réalisée */
+ PENDING,
+
+ /** quand l'opération est en cours */
+ RUNNING,
+
+ /** quand l'opération est annulé en cours d'exécution */
+ CANCELED,
+
+ /** quand une erreur s'est produite pendant l'exécution */
+ FAILED,
+
+ /** quand l'exécution s'est terminée mais requière des corrections */
+ NEED_FIX,
+
+ /** quand l'exécution s'est terminée et ne requière pas de correction */
+ SUCCESSED
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/WizardState.java
___________________________________________________________________
Added: svn:keywords
+ HeadURL Id Date Revision Author
Added: svn:mergeinfo
+
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/package.html
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/package.html (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/package.html 2010-06-07 10:44:18 UTC (rev 1951)
@@ -0,0 +1,9 @@
+<html>
+<body>
+<h1>JAXX - Wizard framework</h1>
+
+This package contains all the classes of the wizard framework ext.
+
+This is a enriched wizard with operation on some steps.
+</body>
+</html>
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/ext/package.html
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
1
0
r1950 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard
by tchemit@users.nuiton.org 05 Jun '10
by tchemit@users.nuiton.org 05 Jun '10
05 Jun '10
Author: tchemit
Date: 2010-06-05 09:51:37 +0200 (Sat, 05 Jun 2010)
New Revision: 1950
Url: http://nuiton.org/repositories/revision/jaxx/1950
Log:
improve wizard api
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java
Removed:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationState.java
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java 2010-06-05 07:50:59 UTC (rev 1949)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java 2010-06-05 07:51:37 UTC (rev 1950)
@@ -39,7 +39,7 @@
* @param <M> le type de modèle
* @since 1.3
*/
-public abstract class WizardOperationAction<E extends WizardOperationStep, M extends WizardOperationModel<E>, O extends WizardOperationActionModel<E>> extends SwingWorker<WizardOperationState, String> {
+public abstract class WizardOperationAction<E extends WizardOperationStep, M extends WizardOperationModel<E>, O extends WizardOperationActionModel<E>> extends SwingWorker<WizardState, String> {
/** Logger */
private static final Log log = LogFactory.getLog(WizardOperationAction.class);
@@ -58,8 +58,8 @@
return operationModel;
}
- public WizardOperationState getOperationState() {
- return operationModel.getOperationState();
+ public WizardState getOperationState() {
+ return getModel().getOperationState();
}
public Exception getError() {
@@ -97,11 +97,11 @@
public abstract void beforeAction(JAXXContext context, M model) throws Exception;
- public abstract WizardOperationState doAction(M model) throws Exception;
+ public abstract WizardState doAction(M model) throws Exception;
- public abstract WizardOperationState onError(M model, Exception e);
+ public abstract WizardState onError(M model, Exception e);
- public abstract WizardOperationState onCancel(M model, Exception e);
+ public abstract WizardState onCancel(M model, Exception e);
protected abstract M getModel();
@@ -114,9 +114,9 @@
}
@Override
- protected WizardOperationState doInBackground() throws Exception {
+ protected WizardState doInBackground() throws Exception {
log.trace(this);
- WizardOperationState result;
+ WizardState result;
M model = getModel();
try {
beforeAction(getContext(), model);
@@ -131,7 +131,7 @@
@Override
protected void done() {
log.trace(this);
- WizardOperationState result = null;
+ WizardState result = null;
try {
if (isCancelled()) {
@@ -140,13 +140,13 @@
result = get();
}
} catch (Exception e) {
- result = WizardOperationState.FAILED;
+ result = WizardState.FAILED;
operationModel.setError(e);
// ne devrait jamais arrivé ?
log.error(e.getMessage(), e);
} finally {
// on enregistre le resultat de l'opération
- operationModel.setOperationState(result);
+ getModel().setOperationState(result);
getModel().setBusy(false);
}
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java 2010-06-05 07:50:59 UTC (rev 1949)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java 2010-06-05 07:51:37 UTC (rev 1950)
@@ -49,7 +49,7 @@
protected final E operation;
- protected WizardOperationState operationState;
+// protected WizardState operationState;
protected Exception error;
@@ -62,21 +62,21 @@
return operation;
}
- public final WizardOperationState getOperationState() {
- return operationState;
- }
+// public final WizardState getOperationState() {
+// return operationState;
+// }
public final Exception getError() {
return error;
}
-
+
public void setError(Exception error) {
this.error = error;
}
- public void setOperationState(WizardOperationState operationState) {
- this.operationState = operationState;
- }
+// public void setOperationState(WizardState operationState) {
+// this.operationState = operationState;
+// }
public final void addPropertyChangeListener(PropertyChangeListener listener) {
pcs.addPropertyChangeListener(listener);
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java 2010-06-05 07:50:59 UTC (rev 1949)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java 2010-06-05 07:51:37 UTC (rev 1950)
@@ -89,7 +89,7 @@
@SuppressWarnings("unchecked")
public A launchOperation(E operation) {
- if (currentAction != null && (!currentAction.isDone() || currentAction.getOperationModel().getOperationState() == WizardOperationState.RUNNING)) {
+ if (currentAction != null && (!currentAction.isDone() || currentAction.getOperationState() == WizardState.RUNNING)) {
// on ne peut traiter qu'une seule opération à la fois
throw new IllegalStateException("can not add a operation when thread is busy, or has another operation to be done");
}
@@ -150,7 +150,7 @@
currentAction.addPropertyChangeListener(this);
// l'opération passe en etant en cours
- getModel().setOperationState(WizardOperationState.RUNNING);
+ getModel().setOperationState(WizardState.RUNNING);
// démarrage de l'opération dans un worker
currentAction.start(getContext());
@@ -163,7 +163,7 @@
// dans la méthode onPropertyChanged
if (canceled) {
- getModel().setOperationState(WizardOperationState.CANCELED);
+ getModel().setOperationState(WizardState.CANCELED);
} else {
getModel().setOperationState(currentAction.getOperationState());
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java 2010-06-05 07:50:59 UTC (rev 1949)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java 2010-06-05 07:51:37 UTC (rev 1950)
@@ -65,12 +65,12 @@
protected final Map<E, WizardOperationActionModel<E>> models;
/** Pour conserver les états des opérations */
- protected Map<E, WizardOperationState> operationStates;
+ protected Map<E, WizardState> operationStates;
protected Map<E, WizardOperationAction<?, ? extends WizardOperationModel<E>, ? extends WizardOperationActionModel<E>>> operationActions;
/** L'état générale du modèle */
- protected WizardOperationState modelState;
+ protected WizardState modelState;
/** un drapeau pour savoir siune opération a été lancée */
protected boolean wasStarted;
@@ -104,7 +104,7 @@
return operations;
}
- public WizardOperationState getModelState() {
+ public WizardState getModelState() {
return modelState;
}
@@ -131,12 +131,12 @@
return getStep() != null && getStep().isOperation() ? getStep() : null;
}
- public WizardOperationState getOperationState() {
+ public WizardState getOperationState() {
E operation = getOperation();
return getOperationState(operation);
}
- public WizardOperationState getOperationState(E operation) {
+ public WizardState getOperationState(E operation) {
return operationStates.get(operation);
}
@@ -157,15 +157,14 @@
return action;
}
- public void setOperationState(WizardOperationState operationState) {
+ public void setOperationState(WizardState operationState) {
E operation = getOperation();
setOperationState(operation, operationState);
}
- public void setOperationState(E operation, WizardOperationState operationState) {
- WizardOperationState oldValue = getOperationState(operation);
+ public void setOperationState(E operation, WizardState operationState) {
+ WizardState oldValue = getOperationState(operation);
operationStates.put(operation, operationState);
- getOperationModel(operation).setOperationState(operationState);
fireIndexedPropertyChange(OPERATION_STATE_PROPERTY_NAME, getSteps().indexOf(operation), oldValue, operationState);
updateModelState(operation, operationState);
validate();
@@ -188,10 +187,10 @@
// les onglets au dela de l'onglet sélectionné sont accessibles
// uniquement si l'onglet precedent est accessible, valide et son etat est a SUCCESSED
E previousStep = steps.get(i - 1);
- result[i] = modelState == WizardOperationState.SUCCESSED ||
+ result[i] = modelState == WizardState.SUCCESSED ||
result[i - 1] &&
validate(previousStep) &&
- (!previousStep.isOperation() || getOperationState(previousStep) == WizardOperationState.SUCCESSED);
+ (!previousStep.isOperation() || getOperationState(previousStep) == WizardState.SUCCESSED);
}
}
if (log.isDebugEnabled()) {
@@ -208,18 +207,18 @@
updateUniverse();
// le modèle n'est pas démarré
- setModelState(WizardOperationState.PENDING);
+ setModelState(WizardState.PENDING);
}
public void cancel() {
for (E op : operations) {
- if (getOperationState(op) == WizardOperationState.PENDING) {
+ if (getOperationState(op) == WizardState.PENDING) {
// on annule l'opération à venir
- setOperationState(op, WizardOperationState.CANCELED);
+ setOperationState(op, WizardState.CANCELED);
}
}
- setModelState(WizardOperationState.CANCELED);
+ setModelState(WizardState.CANCELED);
if (getStep() != null && getStep().isOperation()) {
WizardOperationAction<?, ?, ?> action = getOperationAction(getStep());
if (action != null) {
@@ -281,54 +280,54 @@
return newOp;
}
- protected void setModelState(WizardOperationState modelState) {
- WizardOperationState oldValue = this.modelState;
+ protected void setModelState(WizardState modelState) {
+ WizardState oldValue = this.modelState;
this.modelState = modelState;
firePropertyChange(MODEL_STATE_PROPERTY_NAME, oldValue, modelState);
if (!wasStarted) {
- if ((oldValue == null || oldValue == WizardOperationState.PENDING) && modelState == WizardOperationState.RUNNING) {
+ if ((oldValue == null || oldValue == WizardState.PENDING) && modelState == WizardState.RUNNING) {
wasStarted = true;
firePropertyChange(WAS_STARTED_PROPERTY_NAME, false, true);
}
}
}
- protected void updateModelState(E operation, WizardOperationState operationState) {
+ protected void updateModelState(E operation, WizardState operationState) {
switch (operationState) {
case RUNNING:
//le modele est occupé
- setModelState(WizardOperationState.RUNNING);
+ setModelState(WizardState.RUNNING);
break;
case FAILED:
//le modele est en erreur
- setModelState(WizardOperationState.FAILED);
+ setModelState(WizardState.FAILED);
break;
case CANCELED:
//le modele devient annulé
- setModelState(WizardOperationState.CANCELED);
+ setModelState(WizardState.CANCELED);
return;
case PENDING:
//le modele est en attente
- setModelState(WizardOperationState.PENDING);
+ setModelState(WizardState.PENDING);
break;
case NEED_FIX:
//le modele est en attente
- setModelState(WizardOperationState.PENDING);
+ setModelState(WizardState.PENDING);
break;
case SUCCESSED:
// on regarde si on peut passer le model a l'état success
boolean valid = true;
for (E o : operations) {
- if (getOperationState(o) != WizardOperationState.SUCCESSED) {
+ if (getOperationState(o) != WizardState.SUCCESSED) {
valid = false;
break;
}
}
if (valid) {
- setModelState(WizardOperationState.SUCCESSED);
+ setModelState(WizardState.SUCCESSED);
} else {
- setModelState(WizardOperationState.PENDING);
+ setModelState(WizardState.PENDING);
}
break;
}
@@ -359,7 +358,7 @@
// on met a jour les opérations
for (E op : operations) {
if (!operationStates.containsKey(op)) {
- operationStates.put(op, WizardOperationState.PENDING);
+ operationStates.put(op, WizardState.PENDING);
}
}
for (E op : operationStates.keySet()) {
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationState.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationState.java 2010-06-05 07:50:59 UTC (rev 1949)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationState.java 2010-06-05 07:51:37 UTC (rev 1950)
@@ -1,51 +0,0 @@
-/*
- * #%L
- * JAXX :: Runtime
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2008 - 2010 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>.
- * #L%
- */
-package jaxx.runtime.swing.wizard;
-
-/**
- * Pour caractériser l'état d'une opération.
- *
- * @author tchemit <chemit(a)codelutin.com>
- */
-public enum WizardOperationState {
-
- /** quand l'opération n'a pas encore été réalisée */
- PENDING,
-
- /** quand l'opération est en cours */
- RUNNING,
-
- /** quand l'opération est annulé en cours d'exécution */
- CANCELED,
-
- /** quand une erreur s'est produite pendant l'exécution */
- FAILED,
-
- /** quand l'exécution s'est terminée mais requière des corrections */
- NEED_FIX,
-
- /** quand l'exécution s'est terminée et ne requière pas de correction */
- SUCCESSED
-}
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java (from rev 1945, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationState.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java 2010-06-05 07:51:37 UTC (rev 1950)
@@ -0,0 +1,51 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.wizard;
+
+/**
+ * Pour caractériser l'état d'une opération.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ */
+public enum WizardState {
+
+ /** quand l'opération n'a pas encore été réalisée */
+ PENDING,
+
+ /** quand l'opération est en cours */
+ RUNNING,
+
+ /** quand l'opération est annulé en cours d'exécution */
+ CANCELED,
+
+ /** quand une erreur s'est produite pendant l'exécution */
+ FAILED,
+
+ /** quand l'exécution s'est terminée mais requière des corrections */
+ NEED_FIX,
+
+ /** quand l'exécution s'est terminée et ne requière pas de correction */
+ SUCCESSED
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java
___________________________________________________________________
Added: svn:keywords
+ HeadURL Id Date Revision Author
Added: svn:mergeinfo
+
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java 2010-06-05 07:50:59 UTC (rev 1949)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java 2010-06-05 07:51:37 UTC (rev 1950)
@@ -90,7 +90,7 @@
*
* @param newState le nouvelle état du modèle de wizard
*/
- void onModelStateChanged(WizardOperationState newState);
+ void onModelStateChanged(WizardState newState);
/**
* Méthode invoqué lorsque l'état d'une opération a changé.
@@ -98,6 +98,6 @@
* @param step l'étape dont l'état a changé
* @param newState le nouvel état pour l'étape donné
*/
- void onOperationStateChanged(E step, WizardOperationState newState);
+ void onOperationStateChanged(E step, WizardState newState);
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java 2010-06-05 07:50:59 UTC (rev 1949)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java 2010-06-05 07:51:37 UTC (rev 1950)
@@ -26,11 +26,12 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
+import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.context.JAXXInitialContext;
-import org.apache.commons.beanutils.ConstructorUtils;
-import javax.swing.*;
-import java.awt.*;
+import javax.swing.ImageIcon;
+import java.awt.Window;
/**
* Une classe pour lancer une ui de wizard.
@@ -43,6 +44,18 @@
*/
public abstract class WizardUILancher<E extends WizardStep, M extends WizardModel<E>, UI extends WizardUI<E, M>> {
+ /** the jaxx context entry to store the apply action */
+ public static final JAXXContextEntryDef<Runnable> APPLY_DEF =
+ JAXXUtil.newContextEntryDef("apply", Runnable.class);
+
+ /** the jaxx context entry to store the cancel action */
+ public static final JAXXContextEntryDef<Runnable> CANCEL_DEF =
+ JAXXUtil.newContextEntryDef("cancel", Runnable.class);
+
+ public static <M extends WizardModel<?>> JAXXContextEntryDef<M> newModelEntry(Class<M> modelType) {
+ return JAXXUtil.newContextEntryDef("incoming", modelType);
+ }
+
protected UI ui;
public WizardUILancher(JAXXContext context,
@@ -139,7 +152,6 @@
protected void doClose(UI ui, boolean wasCanceld) {
}
- @SuppressWarnings("unchecked")
protected UI createUI(JAXXContext context,
Window mainUI,
Class<UI> uiClass,
@@ -150,10 +162,10 @@
// parent context model
uiContext.add(modelClass.newInstance());
if (model != null) {
- uiContext.add("incoming", model);
+ uiContext.add(newModelEntry(modelClass), model);
}
// apply action
- uiContext.add("apply", new Runnable() {
+ uiContext.add(APPLY_DEF, new Runnable() {
@Override
public void run() {
@@ -165,7 +177,7 @@
}
});
// cancel action
- uiContext.add("cancel", new Runnable() {
+ uiContext.add(CANCEL_DEF, new Runnable() {
@Override
public void run() {
@@ -179,15 +191,14 @@
// instanciate ui
- UI newUI = (UI) ConstructorUtils.invokeConstructor(
+ UI newUI = JAXXUtil.invokeConstructor(
uiClass,
- new Object[]{mainUI, uiContext},
- new Class[]{Window.class, JAXXContext.class}
+ new Class[]{Window.class, JAXXContext.class},
+ mainUI, uiContext
);
return newUI;
}
- @SuppressWarnings("unchecked")
protected UI createUI(JAXXContext context,
Class<UI> uiClass,
Class<M> modelClass,
@@ -200,10 +211,10 @@
// parent context model
uiContext.add(modelClass.newInstance());
if (model != null) {
- uiContext.add("incoming", model);
+ uiContext.add(newModelEntry(modelClass), model);
}
// apply action
- uiContext.add("apply", new Runnable() {
+ uiContext.add(APPLY_DEF, new Runnable() {
@Override
public void run() {
@@ -214,8 +225,9 @@
}
}
});
+
// cancel action
- uiContext.add("cancel", new Runnable() {
+ uiContext.add(CANCEL_DEF, new Runnable() {
@Override
public void run() {
@@ -228,15 +240,15 @@
});
// instanciate ui
- UI newUI = (UI) ConstructorUtils.invokeConstructor(
+ UI newUI = JAXXUtil.invokeConstructor(
uiClass,
- new Object[]{uiContext, title, tip, icon},
new Class[]{
JAXXContext.class,
String.class,
String.class,
ImageIcon.class
- }
+ },
+ uiContext, title, tip, icon
);
return newUI;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java 2010-06-05 07:50:59 UTC (rev 1949)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java 2010-06-05 07:51:37 UTC (rev 1950)
@@ -27,8 +27,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import javax.swing.*;
-import java.awt.*;
+import javax.swing.JTabbedPane;
+import java.awt.Component;
import java.beans.IndexedPropertyChangeEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@@ -51,8 +51,8 @@
protected WizardUtil() {
}
- public static boolean acceptStates(WizardOperationState state, WizardOperationState... accepted) {
- for (WizardOperationState s : accepted) {
+ public static boolean acceptStates(WizardState state, WizardState... accepted) {
+ for (WizardState s : accepted) {
if (s == state) {
return true;
}
@@ -60,8 +60,8 @@
return false;
}
- public static boolean rejectStates(WizardOperationState state, WizardOperationState... rejected) {
- for (WizardOperationState s : rejected) {
+ public static boolean rejectStates(WizardState state, WizardState... rejected) {
+ for (WizardState s : rejected) {
if (s == state) {
return false;
}
@@ -119,22 +119,22 @@
if (WizardModel.VALID_STEP_PROPERTY_NAME.equals(propertyName)) {
Boolean value = (Boolean) evt.getNewValue();
if (value == null || !value) {
- ui.onModelStateChanged(WizardOperationState.NEED_FIX);
+ ui.onModelStateChanged(WizardState.NEED_FIX);
} else {
- ui.onModelStateChanged(WizardOperationState.PENDING);
+ ui.onModelStateChanged(WizardState.PENDING);
}
return;
}
if (WizardOperationModel.MODEL_STATE_PROPERTY_NAME.equals(propertyName)) {
//TODO should be unicast : only for good stepUI ?
- ui.onModelStateChanged((WizardOperationState) evt.getNewValue());
+ ui.onModelStateChanged((WizardState) evt.getNewValue());
return;
}
if (WizardOperationModel.OPERATION_STATE_PROPERTY_NAME.equals(propertyName)) {
IndexedPropertyChangeEvent e = (IndexedPropertyChangeEvent) evt;
int stepIndex = e.getIndex();
E step = ui.getModel().getSteps().get(stepIndex);
- ui.onOperationStateChanged(step, (WizardOperationState) evt.getNewValue());
+ ui.onOperationStateChanged(step, (WizardState) evt.getNewValue());
return;
}
}
1
0
r1949 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application
by tchemit@users.nuiton.org 05 Jun '10
by tchemit@users.nuiton.org 05 Jun '10
05 Jun '10
Author: tchemit
Date: 2010-06-05 09:50:59 +0200 (Sat, 05 Jun 2010)
New Revision: 1949
Url: http://nuiton.org/repositories/revision/jaxx/1949
Log:
ActionWorker is generic
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionExecutor.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionWorker.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionExecutor.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionExecutor.java 2010-06-05 07:50:34 UTC (rev 1948)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionExecutor.java 2010-06-05 07:50:59 UTC (rev 1949)
@@ -51,7 +51,7 @@
LogFactory.getLog(ActionExecutor.class);
/** current tasks */
- protected final Set<ActionWorker> tasks = new HashSet<ActionWorker>();
+ protected final Set<ActionWorker<?, ?>> tasks = new HashSet<ActionWorker<?, ?>>();
/** the listener of running action */
protected final PropertyChangeListener workerListener;
@@ -61,36 +61,35 @@
*
* @param source the action worker containing the action to perform
*/
- public abstract void onActionStart(ActionWorker source);
+ public abstract void onActionStart(ActionWorker<?, ?> source);
/**
* Hook when a action has failed.
*
* @param source the action worker containing the action to perform
*/
- public abstract void onActionFail(ActionWorker source);
+ public abstract void onActionFail(ActionWorker<?, ?> source);
-
/**
* Hook when a action has been canceled.
*
* @param source the action worker containing the action to perform
*/
- public abstract void onActionCancel(ActionWorker source);
+ public abstract void onActionCancel(ActionWorker<?, ?> source);
/**
* Hook when a action has end with no failure or cancel.
*
* @param source the action worker containing the action to perform
*/
- public abstract void onActionEnd(ActionWorker source);
+ public abstract void onActionEnd(ActionWorker<?, ?> source);
/**
* Hook atfer action is consumed.
*
* @param source the action worker containing the action to perform
*/
- public abstract void onAfterAction(ActionWorker source);
+ public abstract void onAfterAction(ActionWorker<?, ?> source);
public ActionExecutor() {
workerListener = new PropertyChangeListener() {
@@ -105,11 +104,10 @@
}
if ("state".equals(evt.getPropertyName())) {
- ActionWorker source = (ActionWorker) evt.getSource();
+ ActionWorker<?, ?> source = (ActionWorker<?, ?>) evt.getSource();
SwingWorker.StateValue state =
(SwingWorker.StateValue) evt.getNewValue();
-
if (state == SwingWorker.StateValue.STARTED) {
// starting new action
@@ -156,13 +154,14 @@
* @param action the action to perform
* @return the worker that will launch the action
*/
- public ActionWorker addAction(String actionLabel, Runnable action) {
+ public ActionWorker<?, ?> addAction(String actionLabel, Runnable action) {
- ActionWorker worker;
+ ActionWorker<?, ?> worker;
if (action instanceof ActionWorker) {
- worker = (ActionWorker) action;
+ worker = (ActionWorker<?, ?>) action;
} else {
+
worker = new ActionWorker(actionLabel, action);
}
worker.addPropertyChangeListener(workerListener);
@@ -189,7 +188,7 @@
}
// ask executor to terminate
- for (ActionWorker task : tasks) {
+ for (ActionWorker<?, ?> task : tasks) {
task.cancel(true);
}
@@ -210,7 +209,7 @@
return getTasks().size();
}
- public Set<ActionWorker> getTasks() {
+ public Set<ActionWorker<?, ?>> getTasks() {
return tasks;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionWorker.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionWorker.java 2010-06-05 07:50:34 UTC (rev 1948)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionWorker.java 2010-06-05 07:50:59 UTC (rev 1949)
@@ -36,16 +36,14 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 2.1
*/
-public class ActionWorker extends SwingWorker<Void, Object> {
+public class ActionWorker<R,P> extends SwingWorker<R, P> {
-
/** Logger */
- private static final Log log =
- LogFactory.getLog(ActionWorker.class);
+ private static final Log log = LogFactory.getLog(ActionWorker.class);
protected final String actionLabel;
- protected final Runnable target;
+ protected Runnable target;
protected ActionStatus status;
@@ -55,19 +53,31 @@
protected long endTime;
+ public ActionWorker(String actionLabel) {
+ this.actionLabel = actionLabel;
+ }
+
public ActionWorker(String actionLabel, Runnable target) {
this.target = target;
this.actionLabel = actionLabel;
}
+ public Runnable getTarget() {
+ return target;
+ }
+
+ public void setTarget(Runnable target) {
+ this.target = target;
+ }
+
@Override
- protected Void doInBackground() throws Exception {
+ protected R doInBackground() throws Exception {
startTime = System.nanoTime();
if (log.isDebugEnabled()) {
log.debug("Action [" + getActionLabel() + "] is starting...");
}
try {
- target.run();
+ getTarget().run();
} catch (Exception e) {
error = e;
} finally {
1
0
r1948 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/context
by tchemit@users.nuiton.org 05 Jun '10
by tchemit@users.nuiton.org 05 Jun '10
05 Jun '10
Author: tchemit
Date: 2010-06-05 09:50:34 +0200 (Sat, 05 Jun 2010)
New Revision: 1948
Url: http://nuiton.org/repositories/revision/jaxx/1948
Log:
fix bug in JAXXInitialContext when usgin method add with an entry
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/JAXXInitialContext.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/JAXXInitialContext.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/JAXXInitialContext.java 2010-06-05 07:50:06 UTC (rev 1947)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/JAXXInitialContext.java 2010-06-05 07:50:34 UTC (rev 1948)
@@ -26,6 +26,7 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
+import org.apache.commons.lang.NotImplementedException;
import java.util.Map.Entry;
@@ -81,7 +82,7 @@
* @return the instance of the context
*/
public <O> JAXXInitialContext add(JAXXContextEntryDef<O> def, O value) {
- def.setContextValue(this, value);
+ super.setContextValue(value, def.getName());
return this;
}
@@ -101,31 +102,21 @@
@Override
public void setContextValue(Object o) {
- throw new RuntimeException("not implemented");
+ throw new NotImplementedException();
}
@Override
public void setContextValue(Object o, String name) {
- throw new RuntimeException("not implemented");
+ throw new NotImplementedException();
}
@Override
public <T> void removeContextValue(Class<T> klazz) {
- throw new RuntimeException("not implemented");
+ throw new NotImplementedException();
}
@Override
public <T> void removeContextValue(Class<T> klazz, String name) {
- throw new RuntimeException("not implemented");
+ throw new NotImplementedException();
}
-
-// @Override
-// public <O extends Container> O getParentContainer(Class<O> clazz) {
-// throw new RuntimeException("not implemented");
-// }
-//
-// @Override
-// public <O extends Container> O getParentContainer(Object top, Class<O> clazz) {
-// throw new RuntimeException("not implemented");
-// }
}
1
0
05 Jun '10
Author: tchemit
Date: 2010-06-05 09:50:06 +0200 (Sat, 05 Jun 2010)
New Revision: 1947
Url: http://nuiton.org/repositories/revision/jaxx/1947
Log:
add usefull method invokeConstructor
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-06-04 03:53:17 UTC (rev 1946)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-06-05 07:50:06 UTC (rev 1947)
@@ -26,10 +26,11 @@
import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.context.JAXXInitialContext;
+import org.apache.commons.beanutils.ConstructorUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.awt.*;
+import java.awt.Component;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeListenerProxy;
import java.beans.PropertyChangeSupport;
@@ -39,8 +40,14 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EventListener;
import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
public class JAXXUtil {
@@ -110,8 +117,8 @@
}
public static <O> JAXXContextEntryDef<O> newContextEntryDef(
- String name, Class<O> klass) {
- return new JAXXContextEntryDef<O>(name, klass);
+ String name, Class<?> klass) {
+ return new JAXXContextEntryDef<O>(name, (Class<O>) klass);
}
public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() {
@@ -134,7 +141,7 @@
}
@SuppressWarnings({"unchecked"})
- protected static<K, V> Class<Map<K, V>> castMap() {
+ protected static <K, V> Class<Map<K, V>> castMap() {
return (Class<Map<K, V>>) Collections.emptyMap().getClass();
}
@@ -335,7 +342,7 @@
component.removePropertyChangeListener(l);
}
}
-
+
public static boolean assignment(boolean value,
String name,
JAXXObject src) {
@@ -408,7 +415,7 @@
* @throws IllegalArgumentException if the entry is not found in context.
*/
public static void checkJAXXContextEntries(JAXXContext context,
- JAXXContextEntryDef<?>... defs)
+ JAXXContextEntryDef<?>... defs)
throws IllegalArgumentException {
for (JAXXContextEntryDef<?> def : defs) {
@@ -542,4 +549,26 @@
return toRemove.toArray(new PropertyChangeListener[toRemove.size()]);
}
+ /**
+ * Overrides the commons method to have generict cast fiex.
+ *
+ * @param type the type of objet to instanciate
+ * @param prototype prototype of the constructor
+ * @param parms params to pass to constructor
+ * @param <O> type of object to create
+ * @return the new object
+ * @throws Exception if something wrong
+ * @since 2.1
+ */
+ @SuppressWarnings({"unchecked"})
+ public static <O> O invokeConstructor(Class<O> type,
+ Class<?>[] prototype,
+ Object... parms) throws Exception {
+ O o = (O) ConstructorUtils.invokeConstructor(type,
+ parms,
+ prototype
+ );
+ return o;
+ }
+
}
1
0
r1946 - in trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing: . application wizard
by tchemit@users.nuiton.org 04 Jun '10
by tchemit@users.nuiton.org 04 Jun '10
04 Jun '10
Author: tchemit
Date: 2010-06-04 05:53:17 +0200 (Fri, 04 Jun 2010)
New Revision: 1946
Url: http://nuiton.org/repositories/revision/jaxx/1946
Log:
- introduce application package
- deprecated AbstractActionThread (prefer let SwingWorker deals with threads)
- add headers
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionExecutor.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionWorker.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ApplicationRunner.java
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java 2010-06-02 10:27:55 UTC (rev 1945)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java 2010-06-04 03:53:17 UTC (rev 1946)
@@ -24,11 +24,12 @@
*/
package jaxx.runtime.swing;
+import jaxx.runtime.swing.application.ActionExecutor;
+import jaxx.runtime.swing.application.ActionWorker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nuiton.util.StringUtil;
-import javax.swing.*;
+import javax.swing.SwingWorker;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationHandler;
@@ -44,11 +45,12 @@
* <p/>
* To consume an action, use the method {@link #addAction(String, Runnable)}.
* <p/>
- * TODO Make this multi-action enable
*
* @author tchemit <chemit(a)codelutin.com>
* @since 2.0
+ * @deprecated since 2.1, prefer the {@link ActionExecutor}.
*/
+@Deprecated
public abstract class AbstractActionThread extends Thread {
/** Logger */
@@ -70,96 +72,6 @@
/** the listener of running action */
protected final PropertyChangeListener workerListener;
- /** State of a running action */
- enum ActionStatus {
- OK,
- CANCEL,
- FAIL
- }
-
- /** Action worker to execute a incoming action. */
- public static class ActionWorker extends SwingWorker<Void, Object> {
-
- protected final String actionLabel;
-
- protected final Runnable target;
-
- protected ActionStatus status;
-
- protected Exception error;
-
- protected long startTime;
-
- protected long endTime;
-
- public ActionWorker(String actionLabel, Runnable target) {
- this.target = target;
- this.actionLabel = actionLabel;
- }
-
- @Override
- protected Void doInBackground() throws Exception {
- startTime = System.nanoTime();
- if (log.isDebugEnabled()) {
- log.debug("Action [" + getActionLabel() + "] is starting...");
- }
- try {
- target.run();
- } catch (Exception e) {
- error = e;
- } finally {
- if (log.isDebugEnabled()) {
- log.debug("Action [" + getActionLabel() + "] is ending...");
- }
- }
- return null;
- }
-
- public boolean isFailed() {
- return (isDone() || isCancelled()) && error != null;
- }
-
- public Exception getError() {
- return error;
- }
-
- public ActionStatus getStatus() {
- return status;
- }
-
- public String getActionLabel() {
- return actionLabel;
- }
-
- @Override
- protected void done() {
- super.done();
- endTime = System.nanoTime();
- if (error != null) {
- status = ActionStatus.FAIL;
- } else if (isCancelled()) {
- status = ActionStatus.CANCEL;
- } else {
- status = ActionStatus.OK;
- }
- if (log.isDebugEnabled()) {
- log.debug("Action [" + getActionLabel() + "] ends with status : " + status + " in " + getTime());
- }
- }
-
- public String getTime() {
- return StringUtil.convertTime(endTime - startTime);
- }
-
- public long getStartTime() {
- return startTime;
- }
-
- public long getEndTime() {
- return endTime;
- }
- }
-
protected AbstractActionThread(String name) {
super(name);
workerListener = new PropertyChangeListener() {
@@ -190,7 +102,7 @@
// on rend la main au thread pour qu'il attende une
// prochaine operation
- ActionStatus status = source.getStatus();
+ ActionWorker.ActionStatus status = source.getStatus();
if (log.isDebugEnabled()) {
log.debug("Action [" + source.getActionLabel() +
"] status = " + status);
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionExecutor.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionExecutor.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionExecutor.java 2010-06-04 03:53:17 UTC (rev 1946)
@@ -0,0 +1,306 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.application;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.SwingWorker;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Executor of {@link ActionWorker}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public abstract class ActionExecutor {
+
+ /** Logger */
+ private static final Log log =
+ LogFactory.getLog(ActionExecutor.class);
+
+ /** current tasks */
+ protected final Set<ActionWorker> tasks = new HashSet<ActionWorker>();
+
+ /** the listener of running action */
+ protected final PropertyChangeListener workerListener;
+
+ /**
+ * Hook when a action is about to start.
+ *
+ * @param source the action worker containing the action to perform
+ */
+ public abstract void onActionStart(ActionWorker source);
+
+ /**
+ * Hook when a action has failed.
+ *
+ * @param source the action worker containing the action to perform
+ */
+ public abstract void onActionFail(ActionWorker source);
+
+
+ /**
+ * Hook when a action has been canceled.
+ *
+ * @param source the action worker containing the action to perform
+ */
+ public abstract void onActionCancel(ActionWorker source);
+
+ /**
+ * Hook when a action has end with no failure or cancel.
+ *
+ * @param source the action worker containing the action to perform
+ */
+ public abstract void onActionEnd(ActionWorker source);
+
+ /**
+ * Hook atfer action is consumed.
+ *
+ * @param source the action worker containing the action to perform
+ */
+ public abstract void onAfterAction(ActionWorker source);
+
+ public ActionExecutor() {
+ workerListener = new PropertyChangeListener() {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ if (log.isDebugEnabled()) {
+ log.debug("action " + evt.getSource() + " property " +
+ evt.getPropertyName() + " changed <" +
+ evt.getOldValue() + " - " + evt.getNewValue() +
+ '>');
+ }
+
+ if ("state".equals(evt.getPropertyName())) {
+ ActionWorker source = (ActionWorker) evt.getSource();
+ SwingWorker.StateValue state =
+ (SwingWorker.StateValue) evt.getNewValue();
+
+
+ if (state == SwingWorker.StateValue.STARTED) {
+ // starting new action
+
+ onActionStart(source);
+ return;
+ }
+
+ if (state == SwingWorker.StateValue.DONE) {
+ // on rend la main au thread pour qu'il attende une
+ // prochaine operation
+
+ ActionWorker.ActionStatus status = source.getStatus();
+ if (log.isDebugEnabled()) {
+ log.debug("Action [" + source.getActionLabel() +
+ "] status = " + status);
+ }
+ try {
+ switch (status) {
+
+ case OK:
+ onActionEnd(source);
+ break;
+ case CANCEL:
+ onActionCancel(source);
+ break;
+ case FAIL:
+ onActionFail(source);
+ break;
+ }
+ } finally {
+ tasks.remove(source);
+ onAfterAction(source);
+ }
+ }
+ }
+ }
+ };
+ }
+
+ /**
+ * Add an new action to perform.
+ *
+ * @param actionLabel the name of the action to perform
+ * @param action the action to perform
+ * @return the worker that will launch the action
+ */
+ public ActionWorker addAction(String actionLabel, Runnable action) {
+
+ ActionWorker worker;
+ if (action instanceof ActionWorker) {
+
+ worker = (ActionWorker) action;
+ } else {
+ worker = new ActionWorker(actionLabel, action);
+ }
+ worker.addPropertyChangeListener(workerListener);
+ tasks.add(worker);
+ worker.execute();
+ return worker;
+ }
+
+ /**
+ * Ask the thread to stop.
+ * <p/>
+ * It will finish all incoming files (but will not accept more tasks).
+ * <p/>
+ * <b>Note:</b> The method does not return until all tasks are not
+ * consumed.
+ *
+ * @throws InterruptedException if something wrong while waiting end of
+ * executor
+ */
+ public void terminatesAndWaits() throws InterruptedException {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Executor " + this + " is terminating...");
+ }
+
+ // ask executor to terminate
+ for (ActionWorker task : tasks) {
+ task.cancel(true);
+ }
+
+// // wait until all submited jobs are terminated
+// // i don't want timeout, i think 2 minutes is good :)
+// ExecutorService service = ActionWorker.getWorkersExecutorService();
+// if (service != null) {
+// log.info("Shutodown executor service");
+// service.shutdown();
+// }
+
+ if (log.isDebugEnabled()) {
+ log.debug("Executor " + this + " is terminated at " + new Date());
+ }
+ }
+
+ public int getNbActions() {
+ return getTasks().size();
+ }
+
+ public Set<ActionWorker> getTasks() {
+ return tasks;
+ }
+
+ /**
+ * Creates a runnable instance (via a Proxy) to a method given by his name
+ * ({@code methodName}) to invoke on {@code methodcontainer} with given
+ * {@code arguments}.
+ * <p/>
+ * This is a great feature to create runnable code with a real context.
+ *
+ * @param methodContainer the container of the method to invoke
+ * @param methodName the name of the method to invoke
+ * @param arguments parameters to pass to method to invke.
+ * @return the proxy instance
+ */
+ public Runnable createRunnable(final Object methodContainer,
+ String methodName,
+ final Object... arguments) {
+
+ // find method
+
+ Class<?> klass = methodContainer.getClass();
+ Method mFound = null;
+ for (Method m : klass.getDeclaredMethods()) {
+ if (!methodName.equals(m.getName())) {
+ continue;
+ }
+ //same method name
+
+ Class<?>[] types = m.getParameterTypes();
+ if (arguments.length != types.length) {
+ continue;
+ }
+
+ // same number arguments
+ mFound = m;
+ break;
+ }
+ if (mFound == null) {
+ throw new IllegalArgumentException(
+ "could not find method " + methodName + " on type " +
+ klass.getName());
+ }
+
+ //TODO Test arguments are on good type...
+
+ final Method targetMethod = mFound;
+ targetMethod.setAccessible(true);
+ Runnable result;
+
+ // create runnable proxy
+
+ result = (Runnable) Proxy.newProxyInstance(
+ getClass().getClassLoader(),
+ new Class<?>[]{Runnable.class},
+ new InvocationHandler() {
+
+ @Override
+ public Object invoke(Object proxy,
+ Method method,
+ Object[] args) {
+ String methodName = method.getName();
+
+ if ("run".equals(methodName)) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("will invoke run method");
+ }
+ return targetMethod.invoke(methodContainer, arguments);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(
+ "could not invoke on container " +
+ methodContainer, e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (methodName.equals("toString")) {
+ return toString();
+ }
+ if (methodName.equals("equals")) {
+ return equals(args[0]);
+ }
+ if (methodName.equals("hashCode")) {
+ return hashCode();
+ }
+ return null;
+ }
+ }
+ );
+ return result;
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionExecutor.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionWorker.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionWorker.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionWorker.java 2010-06-04 03:53:17 UTC (rev 1946)
@@ -0,0 +1,132 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.application;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.StringUtil;
+
+import javax.swing.SwingWorker;
+
+/**
+ * Action worker to execute a incoming action.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public class ActionWorker extends SwingWorker<Void, Object> {
+
+
+ /** Logger */
+ private static final Log log =
+ LogFactory.getLog(ActionWorker.class);
+
+ protected final String actionLabel;
+
+ protected final Runnable target;
+
+ protected ActionStatus status;
+
+ protected Exception error;
+
+ protected long startTime;
+
+ protected long endTime;
+
+ public ActionWorker(String actionLabel, Runnable target) {
+ this.target = target;
+ this.actionLabel = actionLabel;
+ }
+
+ @Override
+ protected Void doInBackground() throws Exception {
+ startTime = System.nanoTime();
+ if (log.isDebugEnabled()) {
+ log.debug("Action [" + getActionLabel() + "] is starting...");
+ }
+ try {
+ target.run();
+ } catch (Exception e) {
+ error = e;
+ } finally {
+ if (log.isDebugEnabled()) {
+ log.debug("Action [" + getActionLabel() + "] is ending...");
+ }
+ }
+ return null;
+ }
+
+ public boolean isFailed() {
+ return (isDone() || isCancelled()) && error != null;
+ }
+
+ public Exception getError() {
+ return error;
+ }
+
+ public ActionStatus getStatus() {
+ return status;
+ }
+
+ public String getActionLabel() {
+ return actionLabel;
+ }
+
+ @Override
+ protected void done() {
+ super.done();
+ endTime = System.nanoTime();
+ if (error != null) {
+ status = ActionStatus.FAIL;
+ } else if (isCancelled()) {
+ status = ActionStatus.CANCEL;
+ } else {
+ status = ActionStatus.OK;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Action [" + getActionLabel() + "] ends with status : " + status + " in " + getTime());
+ }
+ }
+
+ public String getTime() {
+ return StringUtil.convertTime(endTime - startTime);
+ }
+
+ public long getStartTime() {
+ return startTime;
+ }
+
+ public long getEndTime() {
+ return endTime;
+ }
+
+ /** State of a running action */
+ public enum ActionStatus {
+ OK,
+ CANCEL,
+ FAIL
+ }
+
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ActionWorker.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ApplicationRunner.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ApplicationRunner.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ApplicationRunner.java 2010-06-04 03:53:17 UTC (rev 1946)
@@ -0,0 +1,251 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ * *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
+package jaxx.runtime.swing.application;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Simple application runner which authorize to reload an application.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.1
+ */
+public abstract class ApplicationRunner {
+
+ /** Logger */
+ private static Log log = LogFactory.getLog(ApplicationRunner.class);
+
+ private static final Object lock = new Object();
+
+ private static ApplicationRunner runner;
+
+ public static ApplicationRunner getRunner() {
+ if (runner == null) {
+ throw new IllegalStateException("No runner initialized");
+ }
+ return runner;
+ }
+
+ public static void lock() throws InterruptedException {
+ synchronized (lock) {
+ // on arrete le thread principal
+ // pour rendre la main a la methode main
+ lock.wait();
+ }
+ }
+
+ public static void unlock() {
+ synchronized (lock) {
+ // on arrete le thread principal
+ // pour rendre la main a la methode main
+ lock.notifyAll();
+ }
+ }
+
+ /** arguments given to runner at launch time */
+ protected final String[] args;
+
+ /** flag to reload the runner when closing it */
+ protected boolean reload;
+
+ /** the runner to start application */
+ protected final Runnable runnable;
+
+ protected long startingTime;
+
+ protected Exception error;
+
+ /**
+ * To execute some code only once.
+ * <p/>
+ * This code will not be re-execute when reloading the runner.
+ */
+ protected abstract void initOnce();
+
+ /**
+ * Hook to init runner.
+ *
+ * @throws Exception if any problem
+ */
+ protected abstract void onInit() throws Exception;
+
+ /**
+ * Hook to start runner.
+ *
+ * @throws Exception if any problem
+ */
+ protected abstract void onStart() throws Exception;
+
+ /**
+ * Hook to close runner.
+ *
+ * @param reload if reload was asked
+ * @throws Exception if any problme
+ */
+ protected abstract void onClose(boolean reload) throws Exception;
+
+ /**
+ * Hook to shutdown launcher
+ *
+ * @throws Exception if any problem
+ */
+ protected abstract void onShutdown() throws Exception;
+
+ /**
+ * Hook to shutdown launcher when an exception occurs on clsoing.
+ *
+ * @param ex the error catched while closing launcher
+ */
+ protected abstract void onShutdown(Exception ex);
+
+ /**
+ * Hook when an error occurs in runner.
+ *
+ * @param e the error catched
+ */
+ protected abstract void onError(Exception e);
+
+ protected ApplicationRunner(String[] args) {
+ runner = this;
+ this.args = args;
+
+ initOnce();
+
+ runnable = new Runnable() {
+ @Override
+ public void run() {
+ startingTime = System.nanoTime();
+ try {
+
+ onInit();
+
+ onStart();
+
+ } catch (Exception e) {
+ error = e;
+ onError(e);
+ unlock();
+ }
+ }
+ };
+
+ Thread shutdownHook = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+
+ //onClose(false);
+ onShutdown();
+
+ } catch (Exception e) {
+ error = e;
+ onShutdown(e);
+ }
+ }
+ }, "ShutDown " + getClass().getSimpleName());
+
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ }
+
+ public boolean isReload() {
+ return reload;
+ }
+
+ public void setReload(boolean reload) {
+ this.reload = reload;
+ }
+
+ protected Thread mainThread;
+
+ public final void launch() {
+
+ // au demarrage le reload est toujours desactive
+ reload = false;
+
+ // preparation du thread de l'application principale
+ // que l'on démarre
+ mainThread = new Thread(runnable, getClass().getSimpleName());
+ mainThread.start();
+
+ try {
+
+ // on attend que l'application se termine ou demande un redémarrage
+ lock();
+
+ // on va libérer le runner
+ log.info("Application [" + mainThread + "] is closing...");
+
+ } catch (InterruptedException e) {
+ if (log.isErrorEnabled()) {
+ log.error(mainThread + " was interrupted for reason " + e.getMessage(), e);
+ }
+ } finally {
+
+ close();
+
+ }
+ }
+
+ public final void close() {
+ boolean reload = isReload();
+
+ try {
+
+ // fermeture du runner
+ onClose(reload);
+
+ if (reload) {
+
+ // redemarrage du runner
+
+ if (log.isInfoEnabled()) {
+ log.info("Will reload application");
+ }
+
+ System.runFinalization();
+
+ launch();
+ }
+
+ } catch (Exception e) {
+ onError(e);
+ } finally {
+ if (!reload) {
+ if (log.isDebugEnabled()) {
+ log.debug("Will shutdown application ...");
+ }
+
+ unlock();
+
+ // force to shutdown
+ Runtime.getRuntime().exit(0);
+ }
+ }
+ }
+
+
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/application/ApplicationRunner.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java 2010-06-02 10:27:55 UTC (rev 1945)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java 2010-06-04 03:53:17 UTC (rev 1946)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * JAXX :: Runtime
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2008 - 2010 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>.
+ * #L%
+ */
package jaxx.runtime.swing.wizard;
import jaxx.runtime.JAXXUtil;
1
0