Author: tchemit Date: 2010-06-05 09:51:37 +0200 (Sat, 05 Jun 2010) New Revision: 1950 Url: http://nuiton.org/repositories/revision/jaxx/1950 Log: improve wizard api Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java Removed: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationState.java Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java 2010-06-05 07:50:59 UTC (rev 1949) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationAction.java 2010-06-05 07:51:37 UTC (rev 1950) @@ -39,7 +39,7 @@ * @param <M> le type de modèle * @since 1.3 */ -public abstract class WizardOperationAction<E extends WizardOperationStep, M extends WizardOperationModel<E>, O extends WizardOperationActionModel<E>> extends SwingWorker<WizardOperationState, String> { +public abstract class WizardOperationAction<E extends WizardOperationStep, M extends WizardOperationModel<E>, O extends WizardOperationActionModel<E>> extends SwingWorker<WizardState, String> { /** Logger */ private static final Log log = LogFactory.getLog(WizardOperationAction.class); @@ -58,8 +58,8 @@ return operationModel; } - public WizardOperationState getOperationState() { - return operationModel.getOperationState(); + public WizardState getOperationState() { + return getModel().getOperationState(); } public Exception getError() { @@ -97,11 +97,11 @@ public abstract void beforeAction(JAXXContext context, M model) throws Exception; - public abstract WizardOperationState doAction(M model) throws Exception; + public abstract WizardState doAction(M model) throws Exception; - public abstract WizardOperationState onError(M model, Exception e); + public abstract WizardState onError(M model, Exception e); - public abstract WizardOperationState onCancel(M model, Exception e); + public abstract WizardState onCancel(M model, Exception e); protected abstract M getModel(); @@ -114,9 +114,9 @@ } @Override - protected WizardOperationState doInBackground() throws Exception { + protected WizardState doInBackground() throws Exception { log.trace(this); - WizardOperationState result; + WizardState result; M model = getModel(); try { beforeAction(getContext(), model); @@ -131,7 +131,7 @@ @Override protected void done() { log.trace(this); - WizardOperationState result = null; + WizardState result = null; try { if (isCancelled()) { @@ -140,13 +140,13 @@ result = get(); } } catch (Exception e) { - result = WizardOperationState.FAILED; + result = WizardState.FAILED; operationModel.setError(e); // ne devrait jamais arrivé ? log.error(e.getMessage(), e); } finally { // on enregistre le resultat de l'opération - operationModel.setOperationState(result); + getModel().setOperationState(result); getModel().setBusy(false); } } Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java 2010-06-05 07:50:59 UTC (rev 1949) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionModel.java 2010-06-05 07:51:37 UTC (rev 1950) @@ -49,7 +49,7 @@ protected final E operation; - protected WizardOperationState operationState; +// protected WizardState operationState; protected Exception error; @@ -62,21 +62,21 @@ return operation; } - public final WizardOperationState getOperationState() { - return operationState; - } +// public final WizardState getOperationState() { +// return operationState; +// } public final Exception getError() { return error; } - + public void setError(Exception error) { this.error = error; } - public void setOperationState(WizardOperationState operationState) { - this.operationState = operationState; - } +// public void setOperationState(WizardState operationState) { +// this.operationState = operationState; +// } public final void addPropertyChangeListener(PropertyChangeListener listener) { pcs.addPropertyChangeListener(listener); Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java 2010-06-05 07:50:59 UTC (rev 1949) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationActionThread.java 2010-06-05 07:51:37 UTC (rev 1950) @@ -89,7 +89,7 @@ @SuppressWarnings("unchecked") public A launchOperation(E operation) { - if (currentAction != null && (!currentAction.isDone() || currentAction.getOperationModel().getOperationState() == WizardOperationState.RUNNING)) { + if (currentAction != null && (!currentAction.isDone() || currentAction.getOperationState() == WizardState.RUNNING)) { // on ne peut traiter qu'une seule opération à la fois throw new IllegalStateException("can not add a operation when thread is busy, or has another operation to be done"); } @@ -150,7 +150,7 @@ currentAction.addPropertyChangeListener(this); // l'opération passe en etant en cours - getModel().setOperationState(WizardOperationState.RUNNING); + getModel().setOperationState(WizardState.RUNNING); // démarrage de l'opération dans un worker currentAction.start(getContext()); @@ -163,7 +163,7 @@ // dans la méthode onPropertyChanged if (canceled) { - getModel().setOperationState(WizardOperationState.CANCELED); + getModel().setOperationState(WizardState.CANCELED); } else { getModel().setOperationState(currentAction.getOperationState()); } Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java 2010-06-05 07:50:59 UTC (rev 1949) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationModel.java 2010-06-05 07:51:37 UTC (rev 1950) @@ -65,12 +65,12 @@ protected final Map<E, WizardOperationActionModel<E>> models; /** Pour conserver les états des opérations */ - protected Map<E, WizardOperationState> operationStates; + protected Map<E, WizardState> operationStates; protected Map<E, WizardOperationAction<?, ? extends WizardOperationModel<E>, ? extends WizardOperationActionModel<E>>> operationActions; /** L'état générale du modèle */ - protected WizardOperationState modelState; + protected WizardState modelState; /** un drapeau pour savoir siune opération a été lancée */ protected boolean wasStarted; @@ -104,7 +104,7 @@ return operations; } - public WizardOperationState getModelState() { + public WizardState getModelState() { return modelState; } @@ -131,12 +131,12 @@ return getStep() != null && getStep().isOperation() ? getStep() : null; } - public WizardOperationState getOperationState() { + public WizardState getOperationState() { E operation = getOperation(); return getOperationState(operation); } - public WizardOperationState getOperationState(E operation) { + public WizardState getOperationState(E operation) { return operationStates.get(operation); } @@ -157,15 +157,14 @@ return action; } - public void setOperationState(WizardOperationState operationState) { + public void setOperationState(WizardState operationState) { E operation = getOperation(); setOperationState(operation, operationState); } - public void setOperationState(E operation, WizardOperationState operationState) { - WizardOperationState oldValue = getOperationState(operation); + public void setOperationState(E operation, WizardState operationState) { + WizardState oldValue = getOperationState(operation); operationStates.put(operation, operationState); - getOperationModel(operation).setOperationState(operationState); fireIndexedPropertyChange(OPERATION_STATE_PROPERTY_NAME, getSteps().indexOf(operation), oldValue, operationState); updateModelState(operation, operationState); validate(); @@ -188,10 +187,10 @@ // les onglets au dela de l'onglet sélectionné sont accessibles // uniquement si l'onglet precedent est accessible, valide et son etat est a SUCCESSED E previousStep = steps.get(i - 1); - result[i] = modelState == WizardOperationState.SUCCESSED || + result[i] = modelState == WizardState.SUCCESSED || result[i - 1] && validate(previousStep) && - (!previousStep.isOperation() || getOperationState(previousStep) == WizardOperationState.SUCCESSED); + (!previousStep.isOperation() || getOperationState(previousStep) == WizardState.SUCCESSED); } } if (log.isDebugEnabled()) { @@ -208,18 +207,18 @@ updateUniverse(); // le modèle n'est pas démarré - setModelState(WizardOperationState.PENDING); + setModelState(WizardState.PENDING); } public void cancel() { for (E op : operations) { - if (getOperationState(op) == WizardOperationState.PENDING) { + if (getOperationState(op) == WizardState.PENDING) { // on annule l'opération à venir - setOperationState(op, WizardOperationState.CANCELED); + setOperationState(op, WizardState.CANCELED); } } - setModelState(WizardOperationState.CANCELED); + setModelState(WizardState.CANCELED); if (getStep() != null && getStep().isOperation()) { WizardOperationAction<?, ?, ?> action = getOperationAction(getStep()); if (action != null) { @@ -281,54 +280,54 @@ return newOp; } - protected void setModelState(WizardOperationState modelState) { - WizardOperationState oldValue = this.modelState; + protected void setModelState(WizardState modelState) { + WizardState oldValue = this.modelState; this.modelState = modelState; firePropertyChange(MODEL_STATE_PROPERTY_NAME, oldValue, modelState); if (!wasStarted) { - if ((oldValue == null || oldValue == WizardOperationState.PENDING) && modelState == WizardOperationState.RUNNING) { + if ((oldValue == null || oldValue == WizardState.PENDING) && modelState == WizardState.RUNNING) { wasStarted = true; firePropertyChange(WAS_STARTED_PROPERTY_NAME, false, true); } } } - protected void updateModelState(E operation, WizardOperationState operationState) { + protected void updateModelState(E operation, WizardState operationState) { switch (operationState) { case RUNNING: //le modele est occupé - setModelState(WizardOperationState.RUNNING); + setModelState(WizardState.RUNNING); break; case FAILED: //le modele est en erreur - setModelState(WizardOperationState.FAILED); + setModelState(WizardState.FAILED); break; case CANCELED: //le modele devient annulé - setModelState(WizardOperationState.CANCELED); + setModelState(WizardState.CANCELED); return; case PENDING: //le modele est en attente - setModelState(WizardOperationState.PENDING); + setModelState(WizardState.PENDING); break; case NEED_FIX: //le modele est en attente - setModelState(WizardOperationState.PENDING); + setModelState(WizardState.PENDING); break; case SUCCESSED: // on regarde si on peut passer le model a l'état success boolean valid = true; for (E o : operations) { - if (getOperationState(o) != WizardOperationState.SUCCESSED) { + if (getOperationState(o) != WizardState.SUCCESSED) { valid = false; break; } } if (valid) { - setModelState(WizardOperationState.SUCCESSED); + setModelState(WizardState.SUCCESSED); } else { - setModelState(WizardOperationState.PENDING); + setModelState(WizardState.PENDING); } break; } @@ -359,7 +358,7 @@ // on met a jour les opérations for (E op : operations) { if (!operationStates.containsKey(op)) { - operationStates.put(op, WizardOperationState.PENDING); + operationStates.put(op, WizardState.PENDING); } } for (E op : operationStates.keySet()) { Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationState.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationState.java 2010-06-05 07:50:59 UTC (rev 1949) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationState.java 2010-06-05 07:51:37 UTC (rev 1950) @@ -1,51 +0,0 @@ -/* - * #%L - * JAXX :: Runtime - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package jaxx.runtime.swing.wizard; - -/** - * Pour caractériser l'état d'une opération. - * - * @author tchemit <chemit@codelutin.com> - */ -public enum WizardOperationState { - - /** quand l'opération n'a pas encore été réalisée */ - PENDING, - - /** quand l'opération est en cours */ - RUNNING, - - /** quand l'opération est annulé en cours d'exécution */ - CANCELED, - - /** quand une erreur s'est produite pendant l'exécution */ - FAILED, - - /** quand l'exécution s'est terminée mais requière des corrections */ - NEED_FIX, - - /** quand l'exécution s'est terminée et ne requière pas de correction */ - SUCCESSED -} Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java (from rev 1945, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardOperationState.java) =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java 2010-06-05 07:51:37 UTC (rev 1950) @@ -0,0 +1,51 @@ +/* + * #%L + * JAXX :: Runtime + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package jaxx.runtime.swing.wizard; + +/** + * Pour caractériser l'état d'une opération. + * + * @author tchemit <chemit@codelutin.com> + */ +public enum WizardState { + + /** quand l'opération n'a pas encore été réalisée */ + PENDING, + + /** quand l'opération est en cours */ + RUNNING, + + /** quand l'opération est annulé en cours d'exécution */ + CANCELED, + + /** quand une erreur s'est produite pendant l'exécution */ + FAILED, + + /** quand l'exécution s'est terminée mais requière des corrections */ + NEED_FIX, + + /** quand l'exécution s'est terminée et ne requière pas de correction */ + SUCCESSED +} Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardState.java ___________________________________________________________________ Added: svn:keywords + HeadURL Id Date Revision Author Added: svn:mergeinfo + Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java 2010-06-05 07:50:59 UTC (rev 1949) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUI.java 2010-06-05 07:51:37 UTC (rev 1950) @@ -90,7 +90,7 @@ * * @param newState le nouvelle état du modèle de wizard */ - void onModelStateChanged(WizardOperationState newState); + void onModelStateChanged(WizardState newState); /** * Méthode invoqué lorsque l'état d'une opération a changé. @@ -98,6 +98,6 @@ * @param step l'étape dont l'état a changé * @param newState le nouvel état pour l'étape donné */ - void onOperationStateChanged(E step, WizardOperationState newState); + void onOperationStateChanged(E step, WizardState newState); } Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java 2010-06-05 07:50:59 UTC (rev 1949) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java 2010-06-05 07:51:37 UTC (rev 1950) @@ -26,11 +26,12 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXObject; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.context.JAXXInitialContext; -import org.apache.commons.beanutils.ConstructorUtils; -import javax.swing.*; -import java.awt.*; +import javax.swing.ImageIcon; +import java.awt.Window; /** * Une classe pour lancer une ui de wizard. @@ -43,6 +44,18 @@ */ public abstract class WizardUILancher<E extends WizardStep, M extends WizardModel<E>, UI extends WizardUI<E, M>> { + /** the jaxx context entry to store the apply action */ + public static final JAXXContextEntryDef<Runnable> APPLY_DEF = + JAXXUtil.newContextEntryDef("apply", Runnable.class); + + /** the jaxx context entry to store the cancel action */ + public static final JAXXContextEntryDef<Runnable> CANCEL_DEF = + JAXXUtil.newContextEntryDef("cancel", Runnable.class); + + public static <M extends WizardModel<?>> JAXXContextEntryDef<M> newModelEntry(Class<M> modelType) { + return JAXXUtil.newContextEntryDef("incoming", modelType); + } + protected UI ui; public WizardUILancher(JAXXContext context, @@ -139,7 +152,6 @@ protected void doClose(UI ui, boolean wasCanceld) { } - @SuppressWarnings("unchecked") protected UI createUI(JAXXContext context, Window mainUI, Class<UI> uiClass, @@ -150,10 +162,10 @@ // parent context model uiContext.add(modelClass.newInstance()); if (model != null) { - uiContext.add("incoming", model); + uiContext.add(newModelEntry(modelClass), model); } // apply action - uiContext.add("apply", new Runnable() { + uiContext.add(APPLY_DEF, new Runnable() { @Override public void run() { @@ -165,7 +177,7 @@ } }); // cancel action - uiContext.add("cancel", new Runnable() { + uiContext.add(CANCEL_DEF, new Runnable() { @Override public void run() { @@ -179,15 +191,14 @@ // instanciate ui - UI newUI = (UI) ConstructorUtils.invokeConstructor( + UI newUI = JAXXUtil.invokeConstructor( uiClass, - new Object[]{mainUI, uiContext}, - new Class[]{Window.class, JAXXContext.class} + new Class[]{Window.class, JAXXContext.class}, + mainUI, uiContext ); return newUI; } - @SuppressWarnings("unchecked") protected UI createUI(JAXXContext context, Class<UI> uiClass, Class<M> modelClass, @@ -200,10 +211,10 @@ // parent context model uiContext.add(modelClass.newInstance()); if (model != null) { - uiContext.add("incoming", model); + uiContext.add(newModelEntry(modelClass), model); } // apply action - uiContext.add("apply", new Runnable() { + uiContext.add(APPLY_DEF, new Runnable() { @Override public void run() { @@ -214,8 +225,9 @@ } } }); + // cancel action - uiContext.add("cancel", new Runnable() { + uiContext.add(CANCEL_DEF, new Runnable() { @Override public void run() { @@ -228,15 +240,15 @@ }); // instanciate ui - UI newUI = (UI) ConstructorUtils.invokeConstructor( + UI newUI = JAXXUtil.invokeConstructor( uiClass, - new Object[]{uiContext, title, tip, icon}, new Class[]{ JAXXContext.class, String.class, String.class, ImageIcon.class - } + }, + uiContext, title, tip, icon ); return newUI; } Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java 2010-06-05 07:50:59 UTC (rev 1949) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java 2010-06-05 07:51:37 UTC (rev 1950) @@ -27,8 +27,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import javax.swing.*; -import java.awt.*; +import javax.swing.JTabbedPane; +import java.awt.Component; import java.beans.IndexedPropertyChangeEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; @@ -51,8 +51,8 @@ protected WizardUtil() { } - public static boolean acceptStates(WizardOperationState state, WizardOperationState... accepted) { - for (WizardOperationState s : accepted) { + public static boolean acceptStates(WizardState state, WizardState... accepted) { + for (WizardState s : accepted) { if (s == state) { return true; } @@ -60,8 +60,8 @@ return false; } - public static boolean rejectStates(WizardOperationState state, WizardOperationState... rejected) { - for (WizardOperationState s : rejected) { + public static boolean rejectStates(WizardState state, WizardState... rejected) { + for (WizardState s : rejected) { if (s == state) { return false; } @@ -119,22 +119,22 @@ if (WizardModel.VALID_STEP_PROPERTY_NAME.equals(propertyName)) { Boolean value = (Boolean) evt.getNewValue(); if (value == null || !value) { - ui.onModelStateChanged(WizardOperationState.NEED_FIX); + ui.onModelStateChanged(WizardState.NEED_FIX); } else { - ui.onModelStateChanged(WizardOperationState.PENDING); + ui.onModelStateChanged(WizardState.PENDING); } return; } if (WizardOperationModel.MODEL_STATE_PROPERTY_NAME.equals(propertyName)) { //TODO should be unicast : only for good stepUI ? - ui.onModelStateChanged((WizardOperationState) evt.getNewValue()); + ui.onModelStateChanged((WizardState) evt.getNewValue()); return; } if (WizardOperationModel.OPERATION_STATE_PROPERTY_NAME.equals(propertyName)) { IndexedPropertyChangeEvent e = (IndexedPropertyChangeEvent) evt; int stepIndex = e.getIndex(); E step = ui.getModel().getSteps().get(stepIndex); - ui.onOperationStateChanged(step, (WizardOperationState) evt.getNewValue()); + ui.onOperationStateChanged(step, (WizardState) evt.getNewValue()); return; } }
participants (1)
-
tchemit@users.nuiton.org