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>