Buix-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
- 1440 discussions
r1265 - in jaxx/trunk: . jaxx-compiler-api jaxx-compiler-api/src/main/java/jaxx/compiler jaxx-compiler-api/src/main/java/jaxx/tags jaxx-example jaxx-example/src/main/java/jaxx/demo jaxx-example/src/main/resources/i18n jaxx-runtime-swing/src/main/java/jaxx/runtime jaxx-runtime-swing/src/main/java/jaxx/runtime/swing jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard
by tchemit@users.labs.libre-entreprise.org 13 Mar '09
by tchemit@users.labs.libre-entreprise.org 13 Mar '09
13 Mar '09
Author: tchemit
Date: 2009-03-13 22:00:34 +0000 (Fri, 13 Mar 2009)
New Revision: 1265
Added:
jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/EmptyDemo.jaxx
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardAbstractOperationAction.java
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardAbstractOperationActionThread.java
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardModelWithOperations.java
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardOperation.java
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java
Removed:
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java
Modified:
jaxx/trunk/changelog.txt
jaxx/trunk/jaxx-compiler-api/changelog.txt
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompiledObject.java
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultObjectHandler.java
jaxx/trunk/jaxx-example/changelog.txt
jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx
jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/JAXXDemo.jaxx
jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties
jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java
jaxx/trunk/pom.xml
Log:
- improve demo
- can now use geneticType on javaBean object
- add an extra method $afterCompleteSetup method to be included if find in script at last statement of $completeSetup method
-use i18n 0.10
-introduce Wizard package (must do javadoc)
- add iterator method util on JTabbedPane
Modified: jaxx/trunk/changelog.txt
===================================================================
--- jaxx/trunk/changelog.txt 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/changelog.txt 2009-03-13 22:00:34 UTC (rev 1265)
@@ -1,3 +1,5 @@
+1.3
+ * 20090313 [chemit] - use i18n 0.10
1.2 ??? 2009????
* 20090223 [chemit] - move sources from jaxx-util to jaxx-swing-action module
- delete jaxx-util module
Modified: jaxx/trunk/jaxx-compiler-api/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-03-13 22:00:34 UTC (rev 1265)
@@ -1,4 +1,7 @@
1.3 ??? 200902??
+ * 20090313 [chemit] - can now use geneticType on javaBean object
+ - add an extra method $afterCompleteSetup method to be included if find in script at last statement of $completeSetup method
+
* 20090309 [chemit] - must get the goal property from the event id to make possible inheritance
- improve override properties create method : when same type do not re-instanciate it
* 20090229 [chemit] - fix bug in ClassDescriptorLoader when searching for an arrayof primitive type
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompiledObject.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompiledObject.java 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/CompiledObject.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -575,26 +575,27 @@
public void registerDataBinding(String src, String property, String assignment, JAXXCompiler compiler) throws CompilerException {
compiler.registerDataBinding(src, getId() + "." + property, assignment);
}
-
- /** @return the array of generic types of the compiled object, or a empty array if none defined */
- public ClassDescriptor[] getGenericTypes() {
- if (genericTypes == null) {
- return new ClassDescriptor[0];
+ public String getGenericTypes() {
+ if (getGenericTypesLength() == 0) {
+ // not using it
+ return "";
}
- try {
- ClassDescriptor[] result = new ClassDescriptor[genericTypes.length];
- for (int i = 0; i < result.length; i++) {
- result[i] = ClassDescriptorLoader.getClassDescriptor(genericTypes[i], getObjectClass().getClassLoader());
- }
- return result;
+ String result = "";
+ for (int i = 0, j = getGenericTypesLength(); i < j; i++) {
+ result += ", " + genericTypes[i];
}
- catch (ClassNotFoundException e) {
- throw new RuntimeException(e);
- }
+ return "< " + result.substring(1) + " >";
}
public void setGenericTypes(String[] genericTypes) {
- this.genericTypes = genericTypes;
+ if (genericTypes == null) {
+ this.genericTypes = null;
+ return;
+ }
+ this.genericTypes = new String[genericTypes.length];
+ for (int i = 0, j = genericTypes.length; i < j; i++) {
+ this.genericTypes[i] = genericTypes[i].trim();
+ }
}
public boolean isJavaBean() {
@@ -647,4 +648,8 @@
additionCode = buffer.append(additionCode);
}
+
+ public int getGenericTypesLength() {
+ return genericTypes == null ? 0 : genericTypes.length;
+ }
}
\ No newline at end of file
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -887,6 +887,15 @@
return scriptMethods.toArray(new MethodDescriptor[scriptMethods.size()]);
}
+ public MethodDescriptor getScriptMethod(String methodName) {
+ for (MethodDescriptor m :symbolTable.getScriptMethods()) {
+ if (methodName.equals(m.getName())) {
+ return m;
+ }
+ }
+ return null;
+ }
+
public boolean isFailed() {
return failed;
}
@@ -1399,16 +1408,8 @@
if (clazz.isArray()) {
String canonicalName = getCanonicalName(clazz.getComponentType());
if (canonicalName != null) {
- if (compiled.getGenericTypes().length > 0) {
- canonicalName += "<";
- for (int i = 0; i < compiled.getGenericTypes().length; i++) {
- ClassDescriptor classDescriptor = compiled.getGenericTypes()[i];
- if (i > 0) {
- canonicalName += " ,";
- }
- canonicalName += classDescriptor.getName();
- }
- canonicalName += ">";
+ if (compiled.getGenericTypesLength() > 0) {
+ canonicalName += compiled.getGenericTypes();
}
return canonicalName + "[]";
}
@@ -1416,16 +1417,8 @@
}
String canonicalName = clazz.getName().replace('$', '.');
- if (compiled.getGenericTypes().length > 0) {
- canonicalName += "<";
- for (int i = 0; i < compiled.getGenericTypes().length; i++) {
- ClassDescriptor classDescriptor = compiled.getGenericTypes()[i];
- if (i > 0) {
- canonicalName += " ,";
- }
- canonicalName += classDescriptor.getName();
- }
- canonicalName += ">";
+ if (compiled.getGenericTypesLength() > 0) {
+ canonicalName += compiled.getGenericTypes();
}
return canonicalName;
}
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXObjectGenerator.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -536,7 +536,11 @@
code.append(compiler.getLateInitializer());
code.append(JAXXCompiler.getLineSeparator());
}
-
+ //TC-20090313 add an extra method after complete setup
+ MethodDescriptor method = compiler.getScriptMethod("$afterCompleteSetup");
+ if (method!=null) {
+ code.append("$afterCompleteSetup();").append(JAXXCompiler.getLineSeparator());
+ }
return JavaMethod.newMethod(Modifier.PRIVATE, "void", "$completeSetup", code.toString());
}
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultObjectHandler.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultObjectHandler.java 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/tags/DefaultObjectHandler.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -539,7 +539,12 @@
setDefaults(object, tag, compiler);
setAttributes(object, tag, compiler);
-
+ if (object.getGenericTypesLength() > 0 && !(object == compiler.getRootObject() || object.isJavaBean())) {
+ // can ony be apply to root object or javaBean object
+ compiler.reportWarning("'genericType' attribute can only be found on root, or a javaBean object tag but was found on tag " + tag);
+ object.setGenericTypes(null);
+ return;
+ }
compileChildrenSecondPass(tag, compiler);
}
@@ -625,8 +630,9 @@
String name = attribute.getName();
String value = attribute.getValue();
if (name.equals("javaBean")) {
+ //compiler.preprocessScript(value);
continue;
- }
+ }
if (name.equals("constraints") || isEventHandlerName(name)) {
compiler.preprocessScript(value); // adds dependencies as a side effect
} else if (name.equals("constructorParams")) {
@@ -695,12 +701,12 @@
}
if (name.equals("genericType")) {
- if (object != compiler.getRootObject()) {
- // can ony be apply to root object
- compiler.reportError("'genericType' attribute can only be found on root tag but was found on tag " + tag);
- return;
+ //TC-20090313 check after all atributes been processed
+ if (object == compiler.getRootObject() ) {
+ compiler.setGenericType(value);
+ } else {
+ object.setGenericTypes(value.split(","));
}
- compiler.setGenericType(value);
continue;
}
@@ -1041,9 +1047,9 @@
*/
protected int constantValue(String key, String value) {
JAXXBeanInfo JAXXBeanInfo = getJAXXBeanInfo();
- JAXXPropertyDescriptor[] properties = JAXXBeanInfo.getJAXXPropertyDescriptors();
+ JAXXPropertyDescriptor[] props = JAXXBeanInfo.getJAXXPropertyDescriptors();
String lowercaseValue = value.toLowerCase();
- for (JAXXPropertyDescriptor property : properties) {
+ for (JAXXPropertyDescriptor property : props) {
if (property.getName().equals(key)) {
Object[] values = (Object[]) property.getValue("enumerationValues");
if (values != null) {
Modified: jaxx/trunk/jaxx-example/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-example/changelog.txt 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-example/changelog.txt 2009-03-13 22:00:34 UTC (rev 1265)
@@ -1,3 +1,6 @@
+1.3
+ * 20090313 [chemit] - improve demo
+
1.1 chemit 20090220
* 20090202 [chemit] - no more scope attribute on validator
- fix I18NTableCellRenderer (must have tip inside)
Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx
===================================================================
--- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx 2009-03-13 22:00:34 UTC (rev 1265)
@@ -14,13 +14,12 @@
<script><![CDATA[
import jaxx.runtime.SwingUtil;
-public void initLayer() {
+void $afterCompleteSetup() {
for (JComponent boxed : SwingUtil.getLayeredComponents(this)) {
jaxx.runtime.swing.BlockingLayerUI ui = layerUI.clone();
if ( boxed == c) {
- ui.setUseIcon(false);
ui.setBlock(true);
- }
+ }
SwingUtil.getLayer(boxed).setUI(ui);
//ui.setDirty(true);
}
@@ -31,12 +30,8 @@
jaxx.runtime.swing.BlockingLayerUI ui = (jaxx.runtime.swing.BlockingLayerUI)SwingUtil.getLayer(boxed).getUI();
if ( boxed == c) {
ui.setBlock(active);
- } else {
- ui.setUseIcon(active);
- }
- //ui.setBlock(active && boxed == c);
- //ui.setUseIcon(active && boxed != c);
- //ui.setDirty(true);
+ }
+ ui.setUseIcon(active);
}
}
Added: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/EmptyDemo.jaxx
===================================================================
--- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/EmptyDemo.jaxx (rev 0)
+++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/EmptyDemo.jaxx 2009-03-13 22:00:34 UTC (rev 1265)
@@ -0,0 +1,5 @@
+<DemoPanel>
+<JPanel id='demoPanel'>
+ <JLabel text='emptyNode'/>
+</JPanel>
+</DemoPanel>
\ No newline at end of file
Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/JAXXDemo.jaxx
===================================================================
--- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/JAXXDemo.jaxx 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/JAXXDemo.jaxx 2009-03-13 22:00:34 UTC (rev 1265)
@@ -1,21 +1,26 @@
<Application title="JAXX Demo" width='1024' height='800' defaultCloseOperation='exit_on_close'>
<script><![CDATA[
-protected void changePanel() {
- Object value = list.getSelectionValue();
- if (value instanceof DemoPanel) {
- cardLayout.show(preview, ((DemoPanel) value).getLabel());
- }
+
+org.codelutin.i18n.I18n.init();
+
+void $afterCompleteSetup() {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ int i=0;
+ while( i < list.getRowCount()) {
+ list.expandRow(i++);
+ }
+ }
+ });
}
-// init i18n
-org.codelutin.i18n.I18n.init();
-boxedDecoratorDemo.initLayer();
-//boxedDecoratorDemo.setLayer(true);
]]></script>
<JSplitPane>
<!--JSplitPane dividerLocation='200'-->
<JScrollPane>
- <JTree id='list' showsRootHandles='true' onValueChanged='changePanel()'
+ <JTree id='list' showsRootHandles='true'
+ onValueChanged='cardLayout.show(preview, list.getSelectionValue() instanceof DemoPanel ? ((DemoPanel) list.getSelectionValue()).getLabel() : emptyDemo.getLabel())'
cellRenderer='{new javax.swing.tree.DefaultTreeCellRenderer() {
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (value instanceof DemoPanel)
@@ -82,6 +87,7 @@
<java.awt.CardLayout id='cardLayout'/>
<JPanel id='preview' layout='{cardLayout}'>
+ <EmptyDemo id='emptyDemo' constraints='emptyDemo.getLabel()'/>
<JButtonDemo id='buttonDemo' constraints='buttonDemo.getLabel()'/>
<JCheckBoxDemo id='checkBoxDemo' constraints='checkBoxDemo.getLabel()'/>
<JCheckBoxMenuItemDemo id='checkBoxMenuItemDemo' constraints='checkBoxMenuItemDemo.getLabel()'/>
Modified: jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties
===================================================================
--- jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-en_GB.properties 2009-03-13 22:00:34 UTC (rev 1265)
@@ -88,6 +88,7 @@
button\ A=
button\ B=
button\ C=
+button\ C\ (full\ block)=
button\ with\ layer=
cancel=
close=
@@ -96,6 +97,7 @@
edit=
edit2=
edit3=
+emptyNode=< empty node >
no\ layer=
valid=
validator.field=Champ
Modified: jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties
===================================================================
--- jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-example/src/main/resources/i18n/jaxx-example-fr_FR.properties 2009-03-13 22:00:34 UTC (rev 1265)
@@ -88,6 +88,7 @@
button\ A=
button\ B=
button\ C=
+button\ C\ (full\ block)=
button\ with\ layer=
cancel=
close=
@@ -96,6 +97,7 @@
edit=
edit2=
edit3=
+emptyNode=< empty node >
no\ layer=
valid=
validator.field=Champ
Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map;
@@ -31,6 +32,7 @@
import java.util.Properties;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
+import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import jaxx.runtime.swing.I18nTableCellRenderer;
@@ -357,4 +359,101 @@
}
}
}
+
+ /**
+ * Iterate the components of a {@link JTabbedPane} in natural order.
+ *
+ * Says using method {@link JTabbedPane#getComponent(int)}
+ * @param tabs the
+ * @return
+ * @since 1.4
+ */
+ public static TabbedPaneIterator<Component> newTabbedPaneIterator(JTabbedPane tabs) {
+ return new TabbedPaneIterator<Component>(false, tabs) {
+
+ @Override
+ protected Component get(int index, Component comp) {
+ return comp;
+ }
+ };
+ }
+
+ /**
+ * A simple iterator on a {@link JTabbedPane}.
+ *
+ * Implements the method {@link #get(int, java.awt.Component)} to obtain
+ * the data required given the component (or index).
+ *
+ * You can also inverse the order by usin the method {@link #reverse()}.
+ *
+ * Note: After the use of the method {@link #reverse()} the iterator returns
+ * to the first element.
+ *
+ * @param <O> the type of return elements.
+ * @since 1.4
+ */
+ public static abstract class TabbedPaneIterator<O> implements Iterator<O> {
+
+ final JTabbedPane tabs;
+ boolean reverse;
+ int index;
+ int increment;
+
+ protected abstract O get(int index, Component comp);
+
+ public TabbedPaneIterator(boolean reverse, JTabbedPane tabs) {
+ this.tabs = tabs;
+ setReverse(reverse);
+ }
+
+ public void reset() {
+ setReverse(reverse);
+ }
+
+ public TabbedPaneIterator<O> reverse() {
+ setReverse(!reverse);
+ return this;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return reverse ? index > 0 : index < tabs.getTabCount();
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ @Override
+ public O next() {
+ if (!hasNext()) {
+ throw new IllegalStateException("no next objet! for " + this);
+ }
+ Component next = tabs.getComponent(index);
+ O result = get(index, next);
+ index += increment;
+ return result;
+ }
+
+ @Override
+ public void remove() {
+ throw new IllegalStateException("not implemented for " + this);
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + "< reverse:" + reverse + ", index:" + index + ", size:" + tabs.getTabCount() + " >";
+ }
+
+ protected void setReverse(boolean reverse) {
+ if (reverse) {
+ index = tabs.getTabCount() - 1;
+ increment = -1;
+ } else {
+ index = 0;
+ increment = 1;
+ }
+ this.reverse = reverse;
+ }
+ }
}
Deleted: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -1,191 +0,0 @@
-package jaxx.runtime.swing;
-
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.util.List;
-
-/**
- * Un modèle de wizard.
- *
- * @param <E> le type de l'énumération contenant les etapes.
- *
- * @author tony
- * @since 1.3
- */
-public class WizardModel<E extends Enum<E>> {
-
- public static final String STEPS_PROPERTY_NAME = "steps";
- public static final String STEP_PROPERTY_NAME = "step";
- public static final String PREVIOUS_STEP_PROPERTY_NAME = "previousStep";
- public static final String NEXT_STEP_PROPERTY_NAME = "nextStep";
- public static final String VALID_STEP_PROPERTY_NAME = "validStep";
- /**
- * le type d'une etape du model (doit etre une enumeration)
- */
- protected final Class<E> stepClass;
- /**
- * Toutes les étapes à passer
- */
- protected List<E> steps;
- /**
- * L'étape courante
- */
- protected E step;
- /**
- * drapeau pour valider l'état de l'étape courante
- */
- protected boolean validStep;
- /**
- * pour propager les changements dans le modèle vers l'ui
- */
- protected PropertyChangeSupport pcs;
-
- public WizardModel(Class<E> stepClass, E... steps) {
- this.stepClass = stepClass;
- this.pcs = new PropertyChangeSupport(this);
- this.steps = new java.util.ArrayList<E>();
- if (steps.length > 0) {
- setSteps(steps);
- }
- }
-
- public void start() {
- if (steps.isEmpty()) {
- throw new IllegalStateException("can not start, no step found");
- }
- step = null;
- E startStep = steps.get(0);
- setStep(startStep);
- }
-
- public void gotoNextStep() {
- E nextStep = getNextStep();
- if (nextStep == null) {
- throw new IllegalStateException("no next step to go");
- }
- setStep(nextStep);
- }
-
- public void gotoPreviousStep() {
- E previousStep = getPreviousStep();
- if (previousStep == null) {
- throw new IllegalStateException("no previous step to go");
- }
- setStep(previousStep);
- }
-
- public void gotoStep(E e) {
- if (e == null) {
- throw new NullPointerException("step can not be null");
- }
- if (!steps.contains(e)) {
- throw new IllegalStateException("step " + e + " is not in universe of steps (" + steps + ")");
- }
- setStep(e);
- }
-
- public E getStep() {
- return step;
- }
-
- public int getStepIndex(E s) {
- int index = steps.indexOf(s);
- return index;
- }
-
- public boolean isValidStep() {
- return validStep;
- }
-
- public E getPreviousStep() {
- int index = getStepIndex(step);
- if (index < 1) {
- // si pas de step ou sur premier step
- return null;
- }
- return steps.get(index - 1);
- }
-
- public E getNextStep() {
- int index = getStepIndex(step);
- if (index == -1 || index == steps.size() - 1) {
- // si pas de step positionne ou dernier etape
- return null;
- }
- return steps.get(index + 1);
- }
-
- public List<E> getSteps() {
- return steps;
- }
-
- /**
- * Change l'univers des etapes.
- *
- * Note: on presume ici que l'étape courante est toujours la meme.
- *
- * @param steps le nouvel univers des etapes
- */
- public void setSteps(E... steps) {
- List<E> oldValue = this.steps;
- this.steps = java.util.Collections.unmodifiableList(java.util.Arrays.asList(steps));
- firePropertyChange(STEPS_PROPERTY_NAME, oldValue, this.steps);
- // la propriete nextStep peut avoir changee
- firePropertyChange(NEXT_STEP_PROPERTY_NAME, null, getNextStep());
- }
-
- public boolean validate(E s) {
- return step != null;
- }
-
- public void addPropertyChangeListener(PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(listener);
- }
-
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.addPropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListener(PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(listener);
- }
-
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
- pcs.removePropertyChangeListener(propertyName, listener);
- }
-
- public void removePropertyChangeListeners() {
- for (PropertyChangeListener l : pcs.getPropertyChangeListeners()) {
- pcs.removePropertyChangeListener(l);
- }
- }
- protected Class<E> getStepClass() {
- return stepClass;
- }
-
- protected void setStep(E step) {
- E oldValue = this.step;
- this.step = step;
- firePropertyChange(STEP_PROPERTY_NAME, oldValue, step);
- // la propriete nextStep peut avoir changee
- firePropertyChange(NEXT_STEP_PROPERTY_NAME, null, getNextStep());
- // la propriete previousStep peut avoir changee
- firePropertyChange(PREVIOUS_STEP_PROPERTY_NAME, null, getPreviousStep());
- validate();
- }
-
- protected void validate() {
- if (step == null) {
- // pas de validation quand aucune etape n'est sélectionnée
- return;
- }
- boolean validate = validate(step);
- this.validStep = validate;
- // toujours forcer la propagation
- firePropertyChange(VALID_STEP_PROPERTY_NAME, null, validStep);
- }
-
- protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
- pcs.firePropertyChange(propertyName, oldValue, newValue);
- }
-}
Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardAbstractOperationAction.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardAbstractOperationAction.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardAbstractOperationAction.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -0,0 +1,94 @@
+package jaxx.runtime.swing.wizard;
+
+import javax.swing.SwingWorker;
+import jaxx.runtime.JAXXContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * @author tony
+ * @param <E>
+ * @param <O>
+ * @param <R>
+ * @param <M>
+ * @since 1.3
+ */
+public abstract class WizardAbstractOperationAction<E extends Enum<E>,O extends Enum<O>, R extends Enum<R>, M extends WizardModelWithOperations<E,O,R>> extends SwingWorker<R, String> {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static final Log log = LogFactory.getLog(WizardAbstractOperationAction.class);
+ O operation;
+ Exception error;
+
+ public WizardAbstractOperationAction(O operation) {
+ super();
+ this.operation = operation;
+ }
+
+ public O getOperation() {
+ return operation;
+ }
+
+ public abstract void start(JAXXContext context);
+
+ public abstract void beforeAction(JAXXContext context, M model) throws Exception;
+
+ public abstract R doAction(M model) throws Exception;
+
+ public abstract R onError(M model, Exception e);
+
+ public abstract R onCancel(M model, Exception e);
+
+ public abstract void afterAction(M model, R result, Exception error);
+
+ protected abstract M getModel();
+
+ protected abstract JAXXContext getContext();
+
+ @Override
+ public String toString() {
+ return super.toString() + " < operation: " + operation + ", state: " + getState() + " >";
+ }
+
+ @Override
+ protected R doInBackground() throws Exception {
+ R result;
+ M model = getModel();
+ try {
+ log.info(this);
+ beforeAction(getContext(), model);
+ result = doAction(model);
+ } catch (Exception e) {
+ error = e;
+ result = onError(model, e);
+ }
+ return result;
+ }
+
+ @Override
+ protected void done() {
+ R result = null;
+ log.info(this);
+ M model = getModel();
+ try {
+ if (isCancelled()) {
+
+ result = onCancel(model, error);
+ } else {
+ result = get();
+ }
+ } catch (Exception e) {
+ // ne devrait jamais arrivé ?
+ log.error(e.getMessage(), e);
+ throw new RuntimeException(e);
+ } finally {
+ // on enregistre le resultat de l'opération
+
+ model.setOperationResult(operation, result);
+
+ // on notifie le resultat de l'action
+ firePropertyChange(WizardModelWithOperations.OPERATION_RESULT_PROPERTY_NAME, null, result);
+ }
+ }
+}
Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardAbstractOperationActionThread.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardAbstractOperationActionThread.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardAbstractOperationActionThread.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -0,0 +1,265 @@
+package jaxx.runtime.swing.wizard;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.Date;
+import jaxx.runtime.JAXXContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Thread qui réalise les opérations.
+ *
+ * Pour exécuter une nouvelle opération, on utilise la méthode
+ * {@link #launchOperation(SynchroActionWorker)}.
+ *
+ * Le thread possède 2 états internes :
+ *
+ * - busy lorsqu'il exécute une opération
+ *
+ * - canceled lorqu'une annulation a été demandée via la méthode {@link #setCanceled(boolean)}
+ *
+ * Note: Pour bloquer (ou débloquer) le thread, on utilise la méthode {@link #setwaiting(boolean)}
+ * @param <E> le type des etapes
+ * @param <O> le type des operations
+ * @param <R> le type des resultats d'operation
+ * @param <M> le type de modele
+ * @param <A> le type d'action d'operation
+ *
+ * @author tony
+ * @since 1.3
+ */
+public abstract class WizardAbstractOperationActionThread<E extends Enum<E>, O extends Enum<O>, R extends Enum<R>, M extends WizardModelWithOperations<E, O, R>, A extends WizardAbstractOperationAction<E, O, R, M>> extends Thread implements PropertyChangeListener {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ private static final Log log = LogFactory.getLog(WizardAbstractOperationActionThread.class);
+ public static final String BUSY_PROPERTY_NAME = "busy";
+ public static final String CANCELED_PROPERTY_NAME = "canceled";
+ /**
+ * l'état du thread pendant les étapes non interactives
+ */
+ private boolean busy;
+ /**
+ * l'état du thread si annulé
+ */
+ private boolean canceled;
+ /** suport of modification propagation */
+ protected PropertyChangeSupport pcs;
+ /** le context applicatif */
+ protected JAXXContext cotext;
+ 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 WizardAbstractOperationActionThread(Class<M> modelClass) throws IllegalArgumentException {
+ super(WizardAbstractOperationActionThread.class.getSimpleName() + " " + new Date());
+ this.modelClass = modelClass;
+ this.pcs = new PropertyChangeSupport(this);
+ }
+
+ public boolean isBusy() {
+ return busy;
+ }
+
+ public boolean isCanceled() {
+ return canceled;
+ }
+
+ public void cancel() {
+ setCanceled(true);
+ //currentAction = null;
+ setBusy(false);
+ setWaiting(false);
+ }
+
+ public void launchOperation(A action) {
+
+ if (busy || currentAction != null) {
+ // 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 = action;
+ // on libere le thread pour qu'il execute l'opération
+ setWaiting(false);
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ if (WizardModelWithOperations.OPERATION_RESULT_PROPERTY_NAME.equals(evt.getPropertyName())) {
+ // 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 passe en éta occupé
+ setBusy(true);
+ // le thread écoute les modifications de l'action
+ currentAction.addPropertyChangeListener(this);
+ // démarrage de l'opération
+ currentAction.start(getContext());
+ // le thread est bloqué jusqu'à la fin de l'opération
+ // ou une demande d'annulation
+ setWaiting(true);
+ // la main a ete rendue, le thread n'est plus actif
+ setBusy(false);
+ }
+
+ // 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 (currentAction != null) {
+ // 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 {
+ if (busy) {
+ setBusy(false);
+ setWaiting(false);
+ }
+
+ log.info(this + " will close...");
+ close();
+ }
+ }
+
+ /**
+ * La méthode pour nettoyer le thread, a la fermeture.
+ *
+ */
+ protected void close() {
+ // par defaut, on ne fait rien
+ log.info(this);
+ }
+
+ // PropertyChanged support
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(propertyName, listener);
+ }
+
+ public synchronized boolean hasListeners(String propertyName) {
+ return pcs.hasListeners(propertyName);
+ }
+
+ public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
+ return pcs.getPropertyChangeListeners(propertyName);
+ }
+
+ public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
+ return pcs.getPropertyChangeListeners();
+ }
+
+ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ pcs.firePropertyChange(propertyName, oldValue, newValue);
+ }
+
+ protected void setBusy(boolean busy) {
+ boolean oldValue = this.busy;
+ this.busy = busy;
+ firePropertyChange(BUSY_PROPERTY_NAME, oldValue, busy);
+ }
+
+ protected void setCanceled(boolean canceled) {
+ boolean oldValue = this.canceled;
+ this.canceled = canceled;
+ if (currentAction != null) {
+ log.info("cancel action " + currentAction);
+ // on a une action en cours, on l'annule
+ currentAction.cancel(true);
+ }
+ // on annule aussi le model
+ getModel().cancel();
+ //on notifie les écouteur que le thread est annulé
+ firePropertyChange(CANCELED_PROPERTY_NAME, oldValue, canceled);
+ }
+
+ 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();
+ }
+ }
+}
Copied: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java (from rev 1258, jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java)
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -0,0 +1,196 @@
+package jaxx.runtime.swing.wizard;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.List;
+
+/**
+ * Un modèle de wizard.
+ *
+ * @param <E> le type de l'énumération contenant les etapes.
+ *
+ * @author tony
+ * @since 1.3
+ */
+public class WizardModel<E extends Enum<E>> {
+
+ public static final String STEPS_PROPERTY_NAME = "steps";
+ public static final String STEP_PROPERTY_NAME = "step";
+ public static final String PREVIOUS_STEP_PROPERTY_NAME = "previousStep";
+ public static final String NEXT_STEP_PROPERTY_NAME = "nextStep";
+ public static final String VALID_STEP_PROPERTY_NAME = "validStep";
+
+ /**
+ * le type d'une etape du model (doit etre une enumeration)
+ */
+ protected final Class<E> stepClass;
+ /**
+ * Toutes les étapes à passer
+ */
+ protected List<E> steps;
+ /**
+ * L'étape courante
+ */
+ protected E step;
+ /**
+ * drapeau pour valider l'état de l'étape courante
+ */
+ protected boolean validStep;
+ /**
+ * pour propager les changements dans le modèle vers l'ui
+ */
+ protected PropertyChangeSupport pcs;
+
+ public WizardModel(Class<E> stepClass, E... steps) {
+ this.stepClass = stepClass;
+ this.pcs = new PropertyChangeSupport(this);
+ this.steps = new java.util.ArrayList<E>();
+ if (steps.length > 0) {
+ setSteps(steps);
+ }
+ }
+
+ public void start() {
+ if (steps.isEmpty()) {
+ throw new IllegalStateException("can not start, no step found");
+ }
+ step = null;
+ E startStep = steps.get(0);
+ setStep(startStep);
+ }
+
+ public void gotoNextStep() {
+ E nextStep = getNextStep();
+ if (nextStep == null) {
+ throw new IllegalStateException("no next step to go");
+ }
+ setStep(nextStep);
+ }
+
+ public void gotoPreviousStep() {
+ E previousStep = getPreviousStep();
+ if (previousStep == null) {
+ throw new IllegalStateException("no previous step to go");
+ }
+ setStep(previousStep);
+ }
+
+ public void gotoStep(E e) {
+ if (e == null) {
+ throw new NullPointerException("step can not be null");
+ }
+ if (!steps.contains(e)) {
+ throw new IllegalStateException("step " + e + " is not in universe of steps (" + steps + ")");
+ }
+ setStep(e);
+ }
+
+ public E getStep() {
+ return step;
+ }
+
+ public int getStepIndex(E s) {
+ int index = steps.indexOf(s);
+ return index;
+ }
+
+ public boolean isValidStep() {
+ return validStep;
+ }
+
+ public E getPreviousStep() {
+ int index = getStepIndex(step);
+ if (index < 1) {
+ // si pas de step ou sur premier step
+ return null;
+ }
+ return steps.get(index - 1);
+ }
+
+ public E getNextStep() {
+ int index = getStepIndex(step);
+ if (index == -1 || index == steps.size() - 1) {
+ // si pas de step positionne ou dernier etape
+ return null;
+ }
+ return steps.get(index + 1);
+ }
+
+ public List<E> getSteps() {
+ return steps;
+ }
+
+ /**
+ * Change l'univers des etapes.
+ *
+ * Note: on presume ici que l'étape courante est toujours la meme.
+ *
+ * @param steps le nouvel univers des etapes
+ */
+ public void setSteps(E... steps) {
+ List<E> oldValue = this.steps;
+ this.steps = java.util.Collections.unmodifiableList(java.util.Arrays.asList(steps));
+ firePropertyChange(STEPS_PROPERTY_NAME, oldValue, this.steps);
+ // la propriete nextStep peut avoir changee
+ firePropertyChange(NEXT_STEP_PROPERTY_NAME, null, getNextStep());
+ }
+
+ public boolean validate(E s) {
+ return step != null;
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListeners() {
+ for (PropertyChangeListener l : pcs.getPropertyChangeListeners()) {
+ pcs.removePropertyChangeListener(l);
+ }
+ }
+ protected Class<E> getStepClass() {
+ return stepClass;
+ }
+
+ protected void setStep(E step) {
+ E oldValue = this.step;
+ this.step = step;
+ firePropertyChange(STEP_PROPERTY_NAME, oldValue, step);
+ // la propriete nextStep peut avoir changee
+ firePropertyChange(NEXT_STEP_PROPERTY_NAME, null, getNextStep());
+ // la propriete previousStep peut avoir changee
+ firePropertyChange(PREVIOUS_STEP_PROPERTY_NAME, null, getPreviousStep());
+ validate();
+ }
+
+ protected void validate() {
+ if (step == null) {
+ // pas de validation quand aucune etape n'est sélectionnée
+ return;
+ }
+ boolean validate = validate(step);
+ this.validStep = validate;
+ // toujours forcer la propagation
+ firePropertyChange(VALID_STEP_PROPERTY_NAME, null, validStep);
+ }
+
+ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ pcs.firePropertyChange(propertyName, oldValue, newValue);
+ }
+
+ protected void updateUniverse() {
+
+ }
+}
Property changes on: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardModelWithOperations.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardModelWithOperations.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardModelWithOperations.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -0,0 +1,96 @@
+package jaxx.runtime.swing.wizard;
+
+import java.util.EnumMap;
+import java.util.EnumSet;
+
+/**
+ * Un modèle de wizard.
+ *
+ * @param <E> le type de l'énumération contenant les etapes.
+ *
+ * @param <O> le type de l'énumeration des opérations
+ * @param <R> le type de l'énumération des résultats d'opération
+ * @author tony
+ * @since 1.3
+ */
+public abstract class WizardModelWithOperations<E extends Enum<E>, O extends Enum<O>, R extends Enum<R>> extends WizardModel<E> {
+
+ public static final String OPERATIONS_PROPERTY_NAME = "operations";
+ public static final String OPERATION_RESULT_PROPERTY_NAME = "operationResult";
+ /**
+ * La liste des opérations à effectuer
+ */
+ protected EnumSet<O> operations;
+ /**
+ * Pour conserver les résultats des opérations
+ */
+ protected EnumMap<O, R> operationResults;
+ protected Class<O> operationClass;
+ protected Class<R> operationResultClass;
+
+ public abstract void cancel();
+
+ //protected abstract boolean isCancelResult(R operationResult);
+ //protected abstract boolean isErrorResult(R operationResult);
+
+ public WizardModelWithOperations(Class<E> stepClass, Class<O> operationClass, Class<R> operationResultClass, E... steps) {
+ super(stepClass, steps);
+ this.operationClass = operationClass;
+ this.operationResultClass = operationResultClass;
+ operationResults = new EnumMap<O, R>(operationClass);
+ }
+
+ public EnumSet<O> getOperations() {
+ if (operations == null) {
+ operations = EnumSet.noneOf(operationClass);
+ }
+ return operations;
+ }
+
+ public R getOperationResult(O operation) {
+ return operationResults.get(operation);
+ }
+
+ public void setOperationResult(O operation, R operationResult) {
+ R oldValue = getOperationResult(operation);
+ operationResults.put(operation, operationResult);
+ firePropertyChange(OPERATION_RESULT_PROPERTY_NAME, oldValue, operationResult);
+ }
+
+ @Override
+ public void start() {
+ super.start();
+ firePropertyChange(OPERATIONS_PROPERTY_NAME, null, operations);
+ }
+
+ public WizardModelWithOperations<E, O, R> addOperation(O operation) {
+ getOperations().add(operation);
+ /*if (operation == SynchroOperation.EXPORT_DATA) {
+ // pour exporter les données utilisateurs
+ // les operations synchronisation de référentiel et validation
+ // sont necessaires
+ getOperations().add(SynchroOperation.SYNCHRONIZE_REFERENTIEL);
+ getOperations().add(SynchroOperation.VALIDATION);
+ }*/
+ // on force la propagation de la nouvelle liste
+ firePropertyChange(OPERATIONS_PROPERTY_NAME, null, operations);
+
+ updateUniverse();
+ validate();
+ return this;
+ }
+
+ public void removeOperation(O operation) {
+ getOperations().remove(operation);
+ /*if (operation == SynchroOperation.SYNCHRONIZE_REFERENTIEL || operation == SynchroOperation.VALIDATION) {
+ // pour exporter les données utilisateurs
+ // les operations synchronisation de référentiel et validation
+ // sont necessaires
+ getOperations().remove(SynchroOperation.EXPORT_DATA);
+ }*/
+ // on force la propagation de la nouvelle liste
+ firePropertyChange(OPERATIONS_PROPERTY_NAME, null, operations);
+ updateUniverse();
+ validate();
+ }
+}
Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardOperation.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardOperation.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardOperation.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -0,0 +1,20 @@
+package jaxx.runtime.swing.wizard;
+
+/**
+ *
+ * @param <Action>
+ * @author tony
+ * @since 1.3
+ */
+public interface WizardOperation<Action extends WizardAbstractOperationAction> {
+
+ String name();
+
+ int ordinal();
+
+ String getLabel();
+
+ String getDescription();
+
+ public Action newAction();
+}
Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -0,0 +1,26 @@
+package jaxx.runtime.swing.wizard;
+
+import javax.swing.JTabbedPane;
+
+/**
+ *
+ * Contrat a respecter pour une ui de wizard.
+ *
+ * @param <E> le type d'etape
+ * @param <M> le type de model
+ *
+ * @author tony
+ * @since 1.3
+ */
+public interface WizardUI<E extends Enum<E>, M extends WizardModel<E>> {
+
+ public E getSelectedStep();
+
+ M getModel();
+
+ void init();
+
+ void start();
+
+ JTabbedPane getTabs();
+}
Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java 2009-03-13 22:00:34 UTC (rev 1265)
@@ -0,0 +1,93 @@
+package jaxx.runtime.swing.wizard;
+
+import javax.swing.JFrame;
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXInitialContext;
+import jaxx.runtime.JAXXObject;
+import org.apache.commons.beanutils.ConstructorUtils;
+
+/**
+ *
+ * Une classe pour lancer une ui avec wizard.
+ *
+ * @param <E> le type des etapes
+ * @param <M> le type de modele
+ * @param <UI> le type d'ui
+ * @author tony
+ * @since 1.3
+ */
+public abstract class WizardUILancher<E extends Enum<E>, M extends WizardModel<E>, UI extends WizardUI<E, M>> {
+
+ protected UI ui;
+
+ protected abstract void doAction(UI ui);
+
+ @SuppressWarnings("unchecked")
+ public WizardUILancher(JAXXContext context, JFrame mainUI, Class<UI> uiClass, Class<M> modelClass) {
+ super();
+ try {
+ JAXXInitialContext uiContext = new JAXXInitialContext();
+ // instanciate ui
+ // parent context
+ uiContext.add(mainUI == null ? context : mainUI);
+ // parent context
+ // model
+ uiContext.add(modelClass.newInstance());
+ // apply action
+ uiContext.add("apply", new Runnable() {
+
+ @Override
+ public void run() {
+ doAction(ui);
+ }
+ });
+ // cancel action
+ uiContext.add("cancel", new Runnable() {
+
+ @Override
+ public void run() {
+ doCancel(ui);
+ }
+ });
+
+ // instanciate ui
+ ui = (UI) ConstructorUtils.invokeConstructor(uiClass, new Object[]{mainUI, uiContext});
+
+ } catch (Exception ex) {
+ throw new RuntimeException("could not instanciate launcher for reason " + ex.getMessage(), ex);
+ }
+ }
+
+ public void start() {
+ init(ui);
+ //ui.start();
+ }
+
+ protected void init(UI ui) {
+ }
+
+ protected void afterInit(UI ui) {
+ }
+
+ protected void doCancel(UI ui) {
+ }
+
+ public <T> T getContextValue(Class<T> clazz, String name) {
+ if (ui == null) {
+ throw new NullPointerException("ui can not be null");
+ }
+ if (!(ui instanceof JAXXObject)) {
+ throw new ClassCastException("ui can not be casted to JAXXObject ");
+ }
+
+ return ((JAXXObject) ui).getContextValue(clazz, name);
+ }
+
+ public <T> T getContextValue(Class<T> clazz) {
+ return getContextValue(clazz, null);
+ }
+
+ public void dispose() {
+ ui = null;
+ }
+}
Modified: jaxx/trunk/pom.xml
===================================================================
--- jaxx/trunk/pom.xml 2009-03-12 09:03:21 UTC (rev 1264)
+++ jaxx/trunk/pom.xml 2009-03-13 22:00:34 UTC (rev 1265)
@@ -148,7 +148,7 @@
<!-- libs version -->
<lutinutil.version>1.0.3</lutinutil.version>
<jaxx.version>${project.version}</jaxx.version>
- <i18n.version>0.9</i18n.version>
+ <i18n.version>0.10</i18n.version>
<lutinpluginutil.version>0.3</lutinpluginutil.version>
</properties>
1
0
r1264 - in jaxx/trunk/jaxx-runtime-swing: . src/main/java/jaxx/runtime
by tchemit@users.labs.libre-entreprise.org 12 Mar '09
by tchemit@users.labs.libre-entreprise.org 12 Mar '09
12 Mar '09
Author: tchemit
Date: 2009-03-12 09:03:21 +0000 (Thu, 12 Mar 2009)
New Revision: 1264
Modified:
jaxx/trunk/jaxx-runtime-swing/changelog.txt
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java
Log:
add some usefull code from ObServe (load Nimbus L&F, load ui configuration)
Modified: jaxx/trunk/jaxx-runtime-swing/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-10 22:57:32 UTC (rev 1263)
+++ jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-12 09:03:21 UTC (rev 1264)
@@ -1,4 +1,5 @@
1.3 ?? 200903??
+ * 20090312 [chemit] - add some usefull code from ObServe (load Nimbus L&F, load ui configuration)
* 20090309 [chemit] - in BlockingLayerUI, add a new state 'block' to enable/disable blocking mode with a blockingColor
* 20090303 [chemit] - in BlockingLayerUI, add a new state 'useIcon' to enable/disable use of the action icon
- add a simple WizardModel
Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java 2009-03-10 22:57:32 UTC (rev 1263)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/SwingUtil.java 2009-03-12 09:03:21 UTC (rev 1264)
@@ -1,11 +1,15 @@
package jaxx.runtime;
+import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
+import java.awt.Rectangle;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
@@ -24,7 +28,11 @@
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Properties;
+import javax.swing.ImageIcon;
import javax.swing.JComponent;
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
import jaxx.runtime.swing.I18nTableCellRenderer;
import jaxx.runtime.swing.Item;
import jaxx.runtime.swing.JAXXComboBox;
@@ -46,6 +54,8 @@
static private final Log log = LogFactory.getLog(SwingUtil.class);
private static Field numReaders;
private static Field notifyingListeners;
+ public static final String ICON_PREFIX = "icon.";
+ public static final String COLOR_PREFIX = "color.";
public static void setText(final JTextComponent c, final String text) {
try {
@@ -261,4 +271,90 @@
return result;
}
+
+ /**
+ * Centrer un component graphique au center d'un autre component.
+ *
+ * <b>Note:</b> si le parent est null, alors on ne fait rien.
+ *
+ * @param parent le component parent
+ * @param component le component à centrer
+ */
+ public static void center(Component parent, Component component) {
+ if (parent == null) {
+ return;
+ }
+ Rectangle r = parent.getBounds();
+ int x = r.x + (r.width - component.getSize().width) / 2;
+ int y = r.y + (r.height - component.getSize().height) / 2;
+ component.setLocation(x, y);
+ }
+
+ /**
+ * Try to load the Nimbus look and feel.
+ * <p/>
+ * @throws UnsupportedLookAndFeelException
+ * if nimbus is not applicable
+ * @throws ClassNotFoundException
+ * @throws InstantiationException
+ * @throws IllegalAccessException
+ */
+ public static void initNimbusLoookAndFeel() throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+
+ for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
+ if ("Nimbus".equals(laf.getName())) {
+ UIManager.setLookAndFeel(laf.getClassName());
+ }
+ }
+ }
+
+ /**
+ * Load the ui.properties file and set in {@link UIManager} colors and icons found.
+ *
+ * @param defaultUIConfig le path vers le fichier de la config d'ui par défaut (doit etre dansle class-path)
+ * @param extraUIConfig le path vers une surcharge de la config d'ui (doit etre dans le class-path)
+ *
+ * @throws IOException if could not load the ui.properties file
+ */
+ public static void loadUIConfig(String defaultUIConfig, String extraUIConfig) throws IOException {
+
+ Properties p = new Properties();
+ log.info("loading default UI config " + defaultUIConfig);
+ p.load(SwingUtil.class.getResourceAsStream(defaultUIConfig));
+ if (log.isDebugEnabled()) {
+ log.debug(p.toString());
+ }
+ if (extraUIConfig != null) {
+ InputStream extraStream = SwingUtil.class.getResourceAsStream(extraUIConfig);
+ if (extraStream == null) {
+ log.warn("could not find extraUIConfig : " + extraUIConfig);
+ } else {
+ log.info("loading extra UI config " + extraUIConfig);
+ Properties p2 = new Properties(p);
+ p2.load(extraStream);
+ if (log.isDebugEnabled()) {
+ log.debug(p2.toString());
+ }
+ p.putAll(p2);
+ }
+ }
+ for (Entry<Object, Object> entry : p.entrySet()) {
+ String key = (String) entry.getKey();
+ if (key.startsWith(ICON_PREFIX)) {
+ ImageIcon icon;
+ try {
+ icon = createImageIcon((String) entry.getValue());
+ UIManager.put(key.substring(ICON_PREFIX.length()), icon);
+ } catch (Exception e) {
+ log.warn("could not load icon " + entry.getValue());
+ }
+ continue;
+ }
+ if (key.startsWith(COLOR_PREFIX)) {
+ String value = (String) entry.getValue();
+ String[] rgb = value.split(",");
+ UIManager.put(key.substring(COLOR_PREFIX.length()), new Color(Integer.valueOf(rgb[0]), Integer.valueOf(rgb[1]), Integer.valueOf(rgb[2])));
+ }
+ }
+ }
}
1
0
r1263 - jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator
by tchemit@users.labs.libre-entreprise.org 10 Mar '09
by tchemit@users.labs.libre-entreprise.org 10 Mar '09
10 Mar '09
Author: tchemit
Date: 2009-03-10 22:57:32 +0000 (Tue, 10 Mar 2009)
New Revision: 1263
Modified:
jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-validation.xml
Log:
improve CollectionUniqueKeyValidator
Modified: jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-validation.xml
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-validation.xml 2009-03-10 22:57:22 UTC (rev 1262)
+++ jaxx/trunk/jaxx-runtime-validator/src/test/resources/jaxx/runtime/validator/ValidatorBean-validation.xml 2009-03-10 22:57:32 UTC (rev 1263)
@@ -85,6 +85,11 @@
<param name="keys">intValue,stringValue,stringValue2</param>
<message>collectionUniqueKey.four.failed</message>
</field-validator>
+ <field-validator type="collectionUniqueKey">
+ <param name="keys">stringValue</param>
+ <param name="againstProperty">entry</param>
+ <message>collectionUniqueKey.five.failed</message>
+ </field-validator>
</field>
</validators>
\ No newline at end of file
1
0
r1262 - in jaxx/trunk/jaxx-runtime-validator/src: main/java/jaxx/runtime/validator/field test/java/jaxx/runtime/validator test/java/jaxx/runtime/validator/field
by tchemit@users.labs.libre-entreprise.org 10 Mar '09
by tchemit@users.labs.libre-entreprise.org 10 Mar '09
10 Mar '09
Author: tchemit
Date: 2009-03-10 22:57:22 +0000 (Tue, 10 Mar 2009)
New Revision: 1262
Modified:
jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/field/CollectionUniqueKeyValidator.java
jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/ValidatorBean.java
jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/CollectionUniqueKeyValidatorTest.java
Log:
improve CollectionUniqueKeyValidator
Modified: jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/field/CollectionUniqueKeyValidator.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/field/CollectionUniqueKeyValidator.java 2009-03-09 00:39:23 UTC (rev 1261)
+++ jaxx/trunk/jaxx-runtime-validator/src/main/java/jaxx/runtime/validator/field/CollectionUniqueKeyValidator.java 2009-03-10 22:57:22 UTC (rev 1262)
@@ -18,8 +18,8 @@
*/
public class CollectionUniqueKeyValidator extends FieldExpressionValidator {
+ public enum Mode {
- public enum Mode {
/** au moins une entrée de la collection doit etre valide */
AT_LEAST_ONE,
/** exactement une entrée dela collection doit être valide */
@@ -29,17 +29,36 @@
/** aucune valeur de la collection doivent etre valides */
NONE
}
-
/**
* la liste des propriétés d'une entrée de la collection qui définit la
* clef unique.
*/
protected String[] keys;
+ /**
+ * Une propriété optionnelle pour valider que l'objet reflétée par cette
+ * propriété ne viole pas l'intégrité de la clef unique.
+ * Cela permet de valider l'unicité sans que l'objet soit dans la collection
+ */
+ protected String againstProperty;
+ /**
+ * Lors de l'utilisation de la againstProperty et qu'un ne peut pas utiliser
+ * le equals sur l'objet, on peut spécifier une expression pour exclure des tests
+ * à exclure lors de la recherche de la violation de clef unique.
+ */
+ protected String againstIndexExpression;
public String[] getKeys() {
return keys;
}
+ public String getAgainstProperty() {
+ return againstProperty;
+ }
+
+ public String getAgainstIndexExpression() {
+ return againstIndexExpression;
+ }
+
public void setKeys(String[] keys) {
if (keys != null && keys.length == 1 && keys[0].indexOf(",") != -1) {
this.keys = keys[0].split(",");
@@ -48,6 +67,14 @@
}
}
+ public void setAgainstProperty(String againstProperty) {
+ this.againstProperty = againstProperty;
+ }
+
+ public void setAgainstIndexExpression(String againstIndexExpression) {
+ this.againstIndexExpression = againstIndexExpression;
+ }
+
@Override
public void validate(Object object) throws ValidationException {
@@ -59,26 +86,55 @@
Collection<?> col = getCollection(object);
- if (col.size() < 2) {
+ Object againstBean = againstProperty == null ? null : getFieldValue(againstProperty, object);
+
+ Integer againstIndex = (Integer) (againstIndexExpression == null ? -1 : getFieldValue(againstIndexExpression, object));
+ if (againstIndex == null) {
+ againstIndex = -1;
+ }
+ if (againstBean == null && col.size() < 2) {
// la liste ne contient pas deux entrées donc c'est valide
return;
}
boolean answer = true;
+ Integer againstHashCode = againstBean == null ? null : getUniqueKeyHashCode(againstBean);
+
List<Integer> hashCodes = new ArrayList<Integer>();
+ int index = 0;
for (Object o : col) {
Integer hash = getUniqueKeyHashCode(o);
- if (hashCodes.contains(hash)) {
- // on a deja rencontre cette clef unique,
- // donc la validation a echouee
- answer = false;
- break;
+ if (againstBean == null) {
+ if (hashCodes.contains(hash)) {
+ // on a deja rencontre cette clef unique,
+ // donc la validation a echouee
+ answer = false;
+ break;
+ }
+ } else {
+ // utilisation de againstBean
+ if (againstIndex != -1) {
+ if (index != againstIndex && hash.equals(againstHashCode)) {
+ // on a deja rencontre cette clef unique,
+ // donc la validation a echouee
+ answer = false;
+ break;
+ }
+ } else {
+ if (!againstBean.equals(o) && hash.equals(againstHashCode)) {
+ // on a deja rencontre cette clef unique,
+ // donc la validation a echouee
+ answer = false;
+ break;
+ }
+ }
}
-
// nouveau hashcode enregistre
hashCodes.add(hash);
+ // index suivant
+ index++;
}
if (!answer) {
@@ -137,5 +193,4 @@
public String getValidatorType() {
return "collectionUniqueKey";
}
-
}
\ No newline at end of file
Modified: jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/ValidatorBean.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/ValidatorBean.java 2009-03-09 00:39:23 UTC (rev 1261)
+++ jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/ValidatorBean.java 2009-03-10 22:57:22 UTC (rev 1262)
@@ -59,6 +59,8 @@
protected String stringValue;
+ protected ValidatorBeanEntry entry;
+
PropertyChangeSupport p;
public ValidatorBean() {
@@ -101,6 +103,10 @@
return notExistingDirectory;
}
+ public ValidatorBeanEntry getEntry() {
+ return entry;
+ }
+
public Collection<ValidatorBeanEntry> getEntries() {
return entries;
}
@@ -142,4 +148,11 @@
p.firePropertyChange("entries", null, entries);
}
+ public void setEntry(ValidatorBeanEntry entry) {
+ this.entry = entry;
+ p.firePropertyChange("entry", null, entry);
+ }
+
+
+
}
\ No newline at end of file
Modified: jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/CollectionUniqueKeyValidatorTest.java
===================================================================
--- jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/CollectionUniqueKeyValidatorTest.java 2009-03-09 00:39:23 UTC (rev 1261)
+++ jaxx/trunk/jaxx-runtime-validator/src/test/java/jaxx/runtime/validator/field/CollectionUniqueKeyValidatorTest.java 2009-03-10 22:57:22 UTC (rev 1262)
@@ -21,6 +21,7 @@
assertFieldInError("entries", "collectionUniqueKey.two.failed", false);
assertFieldInError("entries", "collectionUniqueKey.three.failed", false);
assertFieldInError("entries", "collectionUniqueKey.four.failed", false);
+ assertFieldInError("entries", "collectionUniqueKey.five.failed", false);
// add a entry
bean.setEntries(Arrays.asList(beanEntry));
@@ -29,7 +30,17 @@
assertFieldInError("entries", "collectionUniqueKey.two.failed", false);
assertFieldInError("entries", "collectionUniqueKey.three.failed", false);
assertFieldInError("entries", "collectionUniqueKey.four.failed", false);
+ assertFieldInError("entries", "collectionUniqueKey.five.failed", false);
+ // add violating property
+ bean.setEntry(beanEntry3);
+ assertFieldInError("entries", "collectionUniqueKey.one.failed", false);
+ assertFieldInError("entries", "collectionUniqueKey.two.failed", false);
+ assertFieldInError("entries", "collectionUniqueKey.three.failed", false);
+ assertFieldInError("entries", "collectionUniqueKey.four.failed", false);
+ assertFieldInError("entries", "collectionUniqueKey.five.failed", true);
+
+
// two entries with same key
bean.setEntries(Arrays.asList(beanEntry, beanEntry));
1
0
r1261 - jaxx/trunk/jaxx-example/src/main/java/jaxx/demo
by tchemit@users.labs.libre-entreprise.org 09 Mar '09
by tchemit@users.labs.libre-entreprise.org 09 Mar '09
09 Mar '09
Author: tchemit
Date: 2009-03-09 00:39:23 +0000 (Mon, 09 Mar 2009)
New Revision: 1261
Modified:
jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx
jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/JAXXDemo.jaxx
Log:
update BlockingLAyerUI example with block mode
Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx
===================================================================
--- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx 2009-03-09 00:39:02 UTC (rev 1260)
+++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/BoxedDecoratorDemo.jaxx 2009-03-09 00:39:23 UTC (rev 1261)
@@ -4,6 +4,7 @@
blockIcon='{SwingUtil.createImageIcon("action-block.png")}'
acceptIcon='{SwingUtil.createImageIcon("action-accept.png")}'
useIcon='true'
+ blockingColor='{new Color(50,50,50)}'
acceptAction='{new AbstractAction() { private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent e) {
@@ -13,16 +14,32 @@
<script><![CDATA[
import jaxx.runtime.SwingUtil;
-public void setLayer(boolean active) {
+public void initLayer() {
for (JComponent boxed : SwingUtil.getLayeredComponents(this)) {
- jaxx.runtime.swing.BlockingLayerUI ui = active ? layerUI.clone() : null;
- if ( ui != null && boxed == c) {
+ jaxx.runtime.swing.BlockingLayerUI ui = layerUI.clone();
+ if ( boxed == c) {
ui.setUseIcon(false);
- }
+ ui.setBlock(true);
+ }
SwingUtil.getLayer(boxed).setUI(ui);
+ //ui.setDirty(true);
}
}
+public void setLayer(boolean active) {
+ for (JComponent boxed : SwingUtil.getLayeredComponents(this)) {
+ jaxx.runtime.swing.BlockingLayerUI ui = (jaxx.runtime.swing.BlockingLayerUI)SwingUtil.getLayer(boxed).getUI();
+ if ( boxed == c) {
+ ui.setBlock(active);
+ } else {
+ ui.setUseIcon(active);
+ }
+ //ui.setBlock(active && boxed == c);
+ //ui.setUseIcon(active && boxed != c);
+ //ui.setDirty(true);
+ }
+}
+
protected void accept(ActionEvent e, String suffix) {
JButton source = (JButton) e.getSource();
String clickedMessage = (String) source.getClientProperty("clickedText");
Modified: jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/JAXXDemo.jaxx
===================================================================
--- jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/JAXXDemo.jaxx 2009-03-09 00:39:02 UTC (rev 1260)
+++ jaxx/trunk/jaxx-example/src/main/java/jaxx/demo/JAXXDemo.jaxx 2009-03-09 00:39:23 UTC (rev 1261)
@@ -9,7 +9,8 @@
// init i18n
org.codelutin.i18n.I18n.init();
-boxedDecoratorDemo.setLayer(true);
+boxedDecoratorDemo.initLayer();
+//boxedDecoratorDemo.setLayer(true);
]]></script>
<JSplitPane>
<!--JSplitPane dividerLocation='200'-->
1
0
r1260 - in jaxx/trunk/jaxx-compiler-api: . src/main/java/jaxx/compiler
by tchemit@users.labs.libre-entreprise.org 09 Mar '09
by tchemit@users.labs.libre-entreprise.org 09 Mar '09
09 Mar '09
Author: tchemit
Date: 2009-03-09 00:39:02 +0000 (Mon, 09 Mar 2009)
New Revision: 1260
Modified:
jaxx/trunk/jaxx-compiler-api/changelog.txt
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/DefaultCompiledObjectDecorator.java
jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java
Log:
- must get the goal property from the event id to make possible inheritance
- improve override properties create method : when same type do not re-instanciate it
Modified: jaxx/trunk/jaxx-compiler-api/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-03-09 00:35:43 UTC (rev 1259)
+++ jaxx/trunk/jaxx-compiler-api/changelog.txt 2009-03-09 00:39:02 UTC (rev 1260)
@@ -1,4 +1,6 @@
1.3 ??? 200902??
+ * 20090309 [chemit] - must get the goal property from the event id to make possible inheritance
+ - improve override properties create method : when same type do not re-instanciate it
* 20090229 [chemit] - fix bug in ClassDescriptorLoader when searching for an arrayof primitive type
- add a profile mode
* 20090228 [chemit] - fix bug in MethodDescriptor when no returnType defined (constructor method) in getReturnType method invocation
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/DefaultCompiledObjectDecorator.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/DefaultCompiledObjectDecorator.java 2009-03-09 00:35:43 UTC (rev 1259)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/DefaultCompiledObjectDecorator.java 2009-03-09 00:39:02 UTC (rev 1260)
@@ -41,27 +41,34 @@
return object.getInitializationCode(compiler);
}
StringBuffer result = new StringBuffer();
- result.append(object.getId());
- result.append(" = ");
- if (object.isJavaBean() && object.getJavaBeanInitCode() != null) {
- result.append(object.getJavaBeanInitCode()).append(";");
+ if (object.isOverride() && object.getOverrideType()==object.getObjectClass()) {
+ //TC-20090309 on utilise le super code quand l'objet est de meme type
+ result.append("super.").append(object.getCreationMethodName()).append("();");
} else {
- String constructorParams = object.getConstructorParams();
- if (constructorParams != null) {
- //TC - 20081017 compiledObject can have generics
- result.append(" new ").append(JAXXCompiler.getCanonicalName(object)).append("(").append(constructorParams).append(");");
- //result.append("(").append(getCanonicalName(object.getObjectClass())).append(") new ").append(getCanonicalName(object.getObjectClass())).append("(").append(constructorParams).append(");");
+ result.append(object.getId());
+ result.append(" = ");
+ if (object.isJavaBean() && object.getJavaBeanInitCode() != null) {
+ result.append(object.getJavaBeanInitCode()).append(";");
} else {
- //TC - 20081017 compiledObject can have generics
- result.append("new ").append(JAXXCompiler.getCanonicalName(object)).append("();");
+ String constructorParams = object.getConstructorParams();
+ if (constructorParams != null) {
+ //TC - 20081017 compiledObject can have generics
+ result.append(" new ").append(JAXXCompiler.getCanonicalName(object)).append("(").append(constructorParams).append(");");
+ //result.append("(").append(getCanonicalName(object.getObjectClass())).append(") new ").append(getCanonicalName(object.getObjectClass())).append("(").append(constructorParams).append(");");
+ } else {
+ //TC - 20081017 compiledObject can have generics
+ result.append("new ").append(JAXXCompiler.getCanonicalName(object)).append("();");
+ }
}
+ result.append(JAXXCompiler.getLineSeparator());
+ result.append("$objectMap.put(").append(TypeManager.getJavaCode(object.getId())).append(", ").append(object.getId()).append(");");
}
result.append(JAXXCompiler.getLineSeparator());
String initCode = object.getInitializationCode(compiler);
if (initCode != null && initCode.length() > 0) {
result.append(initCode);
}
- result.append("$objectMap.put(").append(TypeManager.getJavaCode(object.getId())).append(", ").append(object.getId()).append(");");
+
return result.toString();
}
Modified: jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java 2009-03-09 00:35:43 UTC (rev 1259)
+++ jaxx/trunk/jaxx-compiler-api/src/main/java/jaxx/compiler/JAXXCompiler.java 2009-03-09 00:39:02 UTC (rev 1260)
@@ -628,7 +628,12 @@
if (getOptions().isOptimize()) {
result = "$ev" + eventHandlerMethodNames.size();
} else {
- result = "do" + org.apache.commons.lang.StringUtils.capitalize(handler.getListenerMethod().getName()) + "__on__" + handler.getObjectCode();
+ //TC-20090309 must get the goal property from the event id
+ // to make possible inheritance
+ String id = handler.getEventId().substring(0,handler.getEventId().indexOf("."));
+
+ result = "do" + org.apache.commons.lang.StringUtils.capitalize(handler.getListenerMethod().getName()) + "__on__" + id;
+ //result = "do" + org.apache.commons.lang.StringUtils.capitalize(handler.getListenerMethod().getName()) + "__on__" + handler.getObjectCode();
}
eventHandlerMethodNames.put(handler, result);
}
1
0
r1259 - in jaxx/trunk/jaxx-runtime-swing: . src/main/java/jaxx/runtime/swing
by tchemit@users.labs.libre-entreprise.org 09 Mar '09
by tchemit@users.labs.libre-entreprise.org 09 Mar '09
09 Mar '09
Author: tchemit
Date: 2009-03-09 00:35:43 +0000 (Mon, 09 Mar 2009)
New Revision: 1259
Modified:
jaxx/trunk/jaxx-runtime-swing/changelog.txt
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java
Log:
in BlockingLayerUI, add a new state 'block' to enable/disable blocking mode with a blockingColor
Modified: jaxx/trunk/jaxx-runtime-swing/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-04 23:12:53 UTC (rev 1258)
+++ jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-09 00:35:43 UTC (rev 1259)
@@ -1,4 +1,5 @@
1.3 ?? 200903??
+ * 20090309 [chemit] - in BlockingLayerUI, add a new state 'block' to enable/disable blocking mode with a blockingColor
* 20090303 [chemit] - in BlockingLayerUI, add a new state 'useIcon' to enable/disable use of the action icon
- add a simple WizardModel
* 20090301 [chemit] - add usefull methods in JAXXButtonGroup
Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java 2009-03-04 23:12:53 UTC (rev 1258)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/BlockingLayerUI.java 2009-03-09 00:35:43 UTC (rev 1259)
@@ -1,8 +1,12 @@
package jaxx.runtime.swing;
+import java.awt.AlphaComposite;
+import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics2D;
+import java.awt.Insets;
import java.awt.Point;
+import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
@@ -34,6 +38,7 @@
public static final String CAN_CLICK_PROPERTY = "canClick";
public static final String ACCEPT_ICON_PROPERTY = "acceptIcon";
public static final String BLOCK_ICON_PROPERTY = "blockIcon";
+ public static final String BLOCK_PROPERTY = "block";
private static final long serialVersionUID = 1L;
/**
* Action to be treated when click on icon
@@ -48,6 +53,10 @@
*/
protected BufferedImage acceptIcon;
/**
+ * Optinal color to put fill background when blocking
+ */
+ protected Color blockingColor;
+ /**
* Internal state to known when we can accept click
*/
protected boolean canClick;
@@ -60,6 +69,10 @@
* By default, this is active.
*/
protected boolean useIcon = true;
+ /**
+ * Internal state when should block event and paint layer
+ */
+ protected boolean block;
public void setAcceptAction(Action acceptAction) {
this.acceptAction = acceptAction;
@@ -86,6 +99,28 @@
}
}
+ public void setBlock(boolean block) {
+ boolean oldvalue = this.block;
+ this.block = block;
+ firePropertyChange(BLOCK_PROPERTY, oldvalue, block);
+ if (oldvalue != block) {
+ setDirty(true);
+ }
+ }
+
+ @Override
+ public void setDirty(boolean isDirty) {
+ super.setDirty(isDirty);
+ }
+
+ public void setBlockIcon(BufferedImage blockIcon) {
+ this.blockIcon = blockIcon;
+ }
+
+ public void setBlockingColor(Color blockingColor) {
+ this.blockingColor = blockingColor;
+ }
+
public BufferedImage getBlockIcon() {
return blockIcon;
}
@@ -99,7 +134,11 @@
}
public void setUseIcon(boolean useIcon) {
+ boolean oldvalue = this.useIcon;
this.useIcon = useIcon;
+ if (oldvalue != useIcon) {
+ setDirty(true);
+ }
}
@Override
@@ -109,13 +148,17 @@
clone.acceptIcon = acceptIcon;
clone.blockIcon = blockIcon;
clone.useIcon = useIcon;
+ clone.block = block;
+ clone.blockingColor = blockingColor;
clone.setCanClick(false);
return clone;
}
@Override
protected void processKeyEvent(KeyEvent e, JXLayer<JComponent> l) {
- e.consume();
+ if (useIcon || block) {
+ e.consume();
+ }
}
@Override
@@ -123,7 +166,9 @@
if (useIcon) {
updateCanClickState(l, e);
}
- e.consume();
+ if (useIcon || block) {
+ e.consume();
+ }
}
@Override
@@ -143,12 +188,32 @@
break;
}
}
- e.consume();
+ if (useIcon || block) {
+ e.consume();
+ }
+
}
@Override
protected void paintLayer(Graphics2D g2, JXLayer<JComponent> l) {
super.paintLayer(g2, l);
+ if (block && blockingColor != null) {
+ // to be in sync with the view if the layer has a border
+ /*Insets layerInsets = l.getInsets();
+ g2.translate(layerInsets.left, layerInsets.top);
+
+ JComponent view = l.getView();
+ // To prevent painting on view's border
+ Insets insets = view.getInsets();
+ g2.clip(new Rectangle(insets.left, insets.top,
+ view.getWidth() - insets.left - insets.right,
+ view.getHeight() - insets.top - insets.bottom));
+ */
+
+ g2.setColor(blockingColor);
+ g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .1f));
+ g2.fillRect(0, 0, l.getWidth(), l.getHeight());
+ }
if (useIcon && getCurrentIcon() != null) {
g2.drawImage(getCurrentIcon(), l.getWidth() - getCurrentIcon().getWidth() - 1, 0, null);
}
1
0
r1258 - jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing
by tchemit@users.labs.libre-entreprise.org 04 Mar '09
by tchemit@users.labs.libre-entreprise.org 04 Mar '09
04 Mar '09
Author: tchemit
Date: 2009-03-04 23:12:53 +0000 (Wed, 04 Mar 2009)
New Revision: 1258
Modified:
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java
Log:
methode setSteps rendue publique
Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java 2009-03-03 19:33:22 UTC (rev 1257)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java 2009-03-04 23:12:53 UTC (rev 1258)
@@ -119,6 +119,21 @@
return steps;
}
+ /**
+ * Change l'univers des etapes.
+ *
+ * Note: on presume ici que l'étape courante est toujours la meme.
+ *
+ * @param steps le nouvel univers des etapes
+ */
+ public void setSteps(E... steps) {
+ List<E> oldValue = this.steps;
+ this.steps = java.util.Collections.unmodifiableList(java.util.Arrays.asList(steps));
+ firePropertyChange(STEPS_PROPERTY_NAME, oldValue, this.steps);
+ // la propriete nextStep peut avoir changee
+ firePropertyChange(NEXT_STEP_PROPERTY_NAME, null, getNextStep());
+ }
+
public boolean validate(E s) {
return step != null;
}
@@ -159,21 +174,6 @@
validate();
}
- /**
- * Change l'univers des etapes.
- *
- * Note: on presume ici que l'étape courante est toujours la meme.
- *
- * @param steps le nouvel univers des etapes
- */
- protected void setSteps(E... steps) {
- List<E> oldValue = this.steps;
- this.steps = java.util.Collections.unmodifiableList(java.util.Arrays.asList(steps));
- firePropertyChange(STEPS_PROPERTY_NAME, oldValue, this.steps);
- // la propriete nextStep peut avoir changee
- firePropertyChange(NEXT_STEP_PROPERTY_NAME, null, getNextStep());
- }
-
protected void validate() {
if (step == null) {
// pas de validation quand aucune etape n'est sélectionnée
1
0
r1257 - jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing
by tchemit@users.labs.libre-entreprise.org 03 Mar '09
by tchemit@users.labs.libre-entreprise.org 03 Mar '09
03 Mar '09
Author: tchemit
Date: 2009-03-03 19:33:22 +0000 (Tue, 03 Mar 2009)
New Revision: 1257
Modified:
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java
Log:
add a simple wizrd model
Modified: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java 2009-03-03 19:33:04 UTC (rev 1256)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java 2009-03-03 19:33:22 UTC (rev 1257)
@@ -10,6 +10,7 @@
* @param <E> le type de l'énumération contenant les etapes.
*
* @author tony
+ * @since 1.3
*/
public class WizardModel<E extends Enum<E>> {
1
0
r1256 - in jaxx/trunk/jaxx-runtime-swing: . src/main/java/jaxx/runtime/swing
by tchemit@users.labs.libre-entreprise.org 03 Mar '09
by tchemit@users.labs.libre-entreprise.org 03 Mar '09
03 Mar '09
Author: tchemit
Date: 2009-03-03 19:33:04 +0000 (Tue, 03 Mar 2009)
New Revision: 1256
Added:
jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java
Modified:
jaxx/trunk/jaxx-runtime-swing/changelog.txt
Log:
add a simple wizrd model
Modified: jaxx/trunk/jaxx-runtime-swing/changelog.txt
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-03 16:38:42 UTC (rev 1255)
+++ jaxx/trunk/jaxx-runtime-swing/changelog.txt 2009-03-03 19:33:04 UTC (rev 1256)
@@ -1,5 +1,6 @@
1.3 ?? 200903??
* 20090303 [chemit] - in BlockingLayerUI, add a new state 'useIcon' to enable/disable use of the action icon
+ - add a simple WizardModel
* 20090301 [chemit] - add usefull methods in JAXXButtonGroup
1.2 letellier 2009022?
Added: jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java
===================================================================
--- jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java (rev 0)
+++ jaxx/trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/WizardModel.java 2009-03-03 19:33:04 UTC (rev 1256)
@@ -0,0 +1,190 @@
+package jaxx.runtime.swing;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.List;
+
+/**
+ * Un modèle de wizard.
+ *
+ * @param <E> le type de l'énumération contenant les etapes.
+ *
+ * @author tony
+ */
+public class WizardModel<E extends Enum<E>> {
+
+ public static final String STEPS_PROPERTY_NAME = "steps";
+ public static final String STEP_PROPERTY_NAME = "step";
+ public static final String PREVIOUS_STEP_PROPERTY_NAME = "previousStep";
+ public static final String NEXT_STEP_PROPERTY_NAME = "nextStep";
+ public static final String VALID_STEP_PROPERTY_NAME = "validStep";
+ /**
+ * le type d'une etape du model (doit etre une enumeration)
+ */
+ protected final Class<E> stepClass;
+ /**
+ * Toutes les étapes à passer
+ */
+ protected List<E> steps;
+ /**
+ * L'étape courante
+ */
+ protected E step;
+ /**
+ * drapeau pour valider l'état de l'étape courante
+ */
+ protected boolean validStep;
+ /**
+ * pour propager les changements dans le modèle vers l'ui
+ */
+ protected PropertyChangeSupport pcs;
+
+ public WizardModel(Class<E> stepClass, E... steps) {
+ this.stepClass = stepClass;
+ this.pcs = new PropertyChangeSupport(this);
+ this.steps = new java.util.ArrayList<E>();
+ if (steps.length > 0) {
+ setSteps(steps);
+ }
+ }
+
+ public void start() {
+ if (steps.isEmpty()) {
+ throw new IllegalStateException("can not start, no step found");
+ }
+ step = null;
+ E startStep = steps.get(0);
+ setStep(startStep);
+ }
+
+ public void gotoNextStep() {
+ E nextStep = getNextStep();
+ if (nextStep == null) {
+ throw new IllegalStateException("no next step to go");
+ }
+ setStep(nextStep);
+ }
+
+ public void gotoPreviousStep() {
+ E previousStep = getPreviousStep();
+ if (previousStep == null) {
+ throw new IllegalStateException("no previous step to go");
+ }
+ setStep(previousStep);
+ }
+
+ public void gotoStep(E e) {
+ if (e == null) {
+ throw new NullPointerException("step can not be null");
+ }
+ if (!steps.contains(e)) {
+ throw new IllegalStateException("step " + e + " is not in universe of steps (" + steps + ")");
+ }
+ setStep(e);
+ }
+
+ public E getStep() {
+ return step;
+ }
+
+ public int getStepIndex(E s) {
+ int index = steps.indexOf(s);
+ return index;
+ }
+
+ public boolean isValidStep() {
+ return validStep;
+ }
+
+ public E getPreviousStep() {
+ int index = getStepIndex(step);
+ if (index < 1) {
+ // si pas de step ou sur premier step
+ return null;
+ }
+ return steps.get(index - 1);
+ }
+
+ public E getNextStep() {
+ int index = getStepIndex(step);
+ if (index == -1 || index == steps.size() - 1) {
+ // si pas de step positionne ou dernier etape
+ return null;
+ }
+ return steps.get(index + 1);
+ }
+
+ public List<E> getSteps() {
+ return steps;
+ }
+
+ public boolean validate(E s) {
+ return step != null;
+ }
+
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(listener);
+ }
+
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.addPropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(listener);
+ }
+
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ pcs.removePropertyChangeListener(propertyName, listener);
+ }
+
+ public void removePropertyChangeListeners() {
+ for (PropertyChangeListener l : pcs.getPropertyChangeListeners()) {
+ pcs.removePropertyChangeListener(l);
+ }
+ }
+ protected Class<E> getStepClass() {
+ return stepClass;
+ }
+
+ protected void setStep(E step) {
+ E oldValue = this.step;
+ this.step = step;
+ firePropertyChange(STEP_PROPERTY_NAME, oldValue, step);
+ // la propriete nextStep peut avoir changee
+ firePropertyChange(NEXT_STEP_PROPERTY_NAME, null, getNextStep());
+ // la propriete previousStep peut avoir changee
+ firePropertyChange(PREVIOUS_STEP_PROPERTY_NAME, null, getPreviousStep());
+ validate();
+ }
+
+ /**
+ * Change l'univers des etapes.
+ *
+ * Note: on presume ici que l'étape courante est toujours la meme.
+ *
+ * @param steps le nouvel univers des etapes
+ */
+ protected void setSteps(E... steps) {
+ List<E> oldValue = this.steps;
+ this.steps = java.util.Collections.unmodifiableList(java.util.Arrays.asList(steps));
+ firePropertyChange(STEPS_PROPERTY_NAME, oldValue, this.steps);
+ // la propriete nextStep peut avoir changee
+ firePropertyChange(NEXT_STEP_PROPERTY_NAME, null, getNextStep());
+ }
+
+ protected void validate() {
+ if (step == null) {
+ // pas de validation quand aucune etape n'est sélectionnée
+ return;
+ }
+ boolean validate = validate(step);
+ this.validStep = validate;
+ // toujours forcer la propagation
+ firePropertyChange(VALID_STEP_PROPERTY_NAME, null, validStep);
+ }
+
+ protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ pcs.firePropertyChange(propertyName, oldValue, newValue);
+ }
+}
1
0