[Buix-commits] r1514 - trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard
Author: tchemit Date: 2009-07-31 18:06:47 +0200 (Fri, 31 Jul 2009) New Revision: 1514 Modified: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java Log: add a policy to deal with tabs in WizardUI Modified: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java =================================================================== --- trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java 2009-07-30 22:28:43 UTC (rev 1513) +++ trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUILancher.java 2009-07-31 16:06:47 UTC (rev 1514) @@ -98,7 +98,7 @@ try { doAction(ui); } finally { - doClose(ui,false); + doClose(ui, false); } } }); @@ -110,7 +110,7 @@ try { doCancel(ui); } finally { - doClose(ui,true); + doClose(ui, true); } } }); @@ -138,7 +138,7 @@ try { doAction(ui); } finally { - doClose(ui,false); + doClose(ui, false); } } }); @@ -150,7 +150,7 @@ try { doCancel(ui); } finally { - doClose(ui,true); + doClose(ui, true); } } }); Modified: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java =================================================================== --- trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java 2009-07-30 22:28:43 UTC (rev 1513) +++ trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/wizard/WizardUtil.java 2009-07-31 16:06:47 UTC (rev 1514) @@ -1,11 +1,16 @@ package jaxx.runtime.swing.wizard; +import java.awt.Component; import java.beans.IndexedPropertyChangeEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.reflect.Array; +import javax.swing.JTabbedPane; import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import static org.nuiton.i18n.I18n._; + /** * Classe de méthodes utiles sur les wizard. * @@ -14,6 +19,9 @@ */ public class WizardUtil { + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(WizardUI.class); + protected WizardUtil() { } @@ -35,7 +43,7 @@ return true; } - public static void addDebugLogListener(final Log log, WizardModel model) { + public static void addDebugLogListener(final Log log, WizardModel<?> model) { if (log.isDebugEnabled()) { model.addPropertyChangeListener(new PropertyChangeListener() { @@ -47,7 +55,7 @@ } } - public static void addTraceLogListener(final Log log, WizardModel model) { + public static void addTraceLogListener(final Log log, WizardModel<?> model) { if (log.isTraceEnabled()) { model.addPropertyChangeListener(new PropertyChangeListener() { @@ -94,4 +102,56 @@ } }); } + + /** + * Ajoute un listener sur le modele pour gere la politique d'affichage des + * onglets. + * + * Dans cette implantation, les onglets sont ouverts jusqu'a l'etape courante. + * Lorsque l'on revient en arrière, les onglets d'etapes superieurs sont + * fermes. + * + * @param <E> le type d'un etape de l'assistant + * @param <M> le type du modele de l'assistant + * @param ui l'ui de l'assitant + * @since 1.7.1 + */ + public static <E extends WizardStep, M extends WizardModel<E>> void addTabsDisplayUntilStepListener(final WizardUI<E, M> ui) { + // on écoute les changements d'étapes + ui.getModel().addPropertyChangeListener(WizardModel.STEP_PROPERTY_NAME, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + M model = (M) evt.getSource(); + E oldStep = (E) evt.getOldValue(); + E newStep = (E) evt.getNewValue(); + log.debug("step has changed <old:" + oldStep + ", new:" + newStep + ">"); + int oldStepIndex = oldStep == null ? -1 : model.getStepIndex(oldStep); + int newStepIndex = model.getStepIndex(newStep); + JTabbedPane tabs = ui.getTabs(); + if (oldStepIndex + 1 == newStepIndex) { + // creation d'un nouvel onglet + WizardStepUI<E, M> c = ui.getStepUI(newStep); + String title = _(newStep.getLabel()); + String tip = _(newStep.getDescription()); + tabs.addTab(title, null, (Component) c, tip); + // selection du nouvel onglet + int index = tabs.indexOfComponent((Component) c); + if (index > -1) { + tabs.setSelectedIndex(index); + } + } else if (oldStepIndex > newStepIndex) { + // il s'agit d'un retour en arrière + // on supprime tous les onglets obsoletes + int index = newStepIndex + 1; + while (tabs.getTabCount() > index) { + log.trace("remove tab : " + index); + tabs.remove(index); + } + } else { + throw new IllegalStateException("can not go from " + oldStep + " to " + newStep); + } + } + }); + } }
participants (1)
-
tchemit@users.labs.libre-entreprise.org