r2045 - in trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config: . model
Author: tchemit Date: 2010-08-29 09:00:07 +0200 (Sun, 29 Aug 2010) New Revision: 2045 Url: http://nuiton.org/repositories/revision/jaxx/2045 Log: Evolution #827: Add a closeAction in ConfigUI api + improve code Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHelper.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModel.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java 2010-08-29 06:57:46 UTC (rev 2044) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java 2010-08-29 07:00:07 UTC (rev 2045) @@ -27,13 +27,29 @@ import jaxx.runtime.SwingUtil; import jaxx.runtime.context.JAXXInitialContext; -import jaxx.runtime.swing.editor.config.model.*; +import jaxx.runtime.swing.editor.config.model.CallBackEntry; +import jaxx.runtime.swing.editor.config.model.CallBackMap; +import jaxx.runtime.swing.editor.config.model.CategoryModel; +import jaxx.runtime.swing.editor.config.model.ConfigUIModel; +import jaxx.runtime.swing.editor.config.model.OptionModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import javax.swing.*; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.DefaultSingleSelectionModel; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRootPane; +import javax.swing.JTabbedPane; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; -import java.awt.*; +import java.awt.Frame; +import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -176,23 +192,16 @@ if (!model.isSaved() || model.isStandalone()) { // just quit, no callBack can be apply here - - ui.destroy(); - - // close the configu ui - parentWindow.dispose(); + closeUI(parentWindow, model); return; } CallBackMap forSaved = model.getCallBacksForSaved(); if (forSaved.isEmpty()) { + // just quit, no callBack to call - - ui.destroy(); - - // close the configu ui - parentWindow.dispose(); + closeUI(parentWindow, model); return; } @@ -207,7 +216,7 @@ add(CALLBACKS, new ArrayList<CallBackEntry>(forSaved.keySet())). add(new ConfigCallBackUIHandler()); - + ConfigCallBackUI lastUI = new ConfigCallBackUI(context); lastUI.init(); @@ -227,6 +236,20 @@ return quitAction; } + protected void closeUI(Window parentWindow, ConfigUIModel model) { + + ui.destroy(); + + // close the config ui + parentWindow.dispose(); + + Runnable runnable = model.getCloseAction(); + if (runnable != null) { + log.info("execute close action"); + runnable.run(); + } + } + protected boolean canQuitCategory() { boolean canContinue = true; ConfigUIModel model = ui.getModel(); Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHelper.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHelper.java 2010-08-29 06:57:46 UTC (rev 2044) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHelper.java 2010-08-29 07:00:07 UTC (rev 2045) @@ -27,14 +27,18 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.context.JAXXInitialContext; -import jaxx.runtime.swing.editor.config.model.*; +import jaxx.runtime.swing.editor.config.model.CallBackFinalizer; +import jaxx.runtime.swing.editor.config.model.CategoryModel; +import jaxx.runtime.swing.editor.config.model.ConfigUIModel; +import jaxx.runtime.swing.editor.config.model.ConfigUIModelBuilder; +import jaxx.runtime.swing.editor.config.model.OptionModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.ApplicationConfig; -import javax.swing.*; +import javax.swing.Icon; import javax.swing.table.TableCellEditor; -import java.awt.*; +import java.awt.Frame; /** * A helper to build a config ui. @@ -122,6 +126,10 @@ modelBuilder.setFinalizer(finalizer); } + public void setCloseAction(Runnable runnable) { + modelBuilder.setCloseAction(runnable); + } + /** * Construire l'ui de configuration (sous forme de panel) * Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModel.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModel.java 2010-08-29 06:57:46 UTC (rev 2044) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModel.java 2010-08-29 07:00:07 UTC (rev 2045) @@ -81,13 +81,20 @@ /** Callbacks manager */ protected CallBacksManager callBacksManager; - /** suport of modification */ - protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + /** + * optional action to execute (if not null) if no call backs fits. + * @since 1.4.2 + */ + protected Runnable closeAction; + /** support of modification notifications */ + protected final PropertyChangeSupport pcs; + public ConfigUIModel(ApplicationConfig config) { this.config = config; categories = new LinkedHashMap<String, CategoryModel>(); callBacksManager = new CallBacksManager(); + pcs = new PropertyChangeSupport(this); } /** @@ -156,6 +163,14 @@ callBacksManager.setFinalizer(finalizer); } + public Runnable getCloseAction() { + return closeAction; + } + + public void setCloseAction(Runnable closeAction) { + this.closeAction=closeAction; + } + /** * Obtain the dictionnary of callback for all to saved modified options. * Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java 2010-08-29 06:57:46 UTC (rev 2044) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java 2010-08-29 07:00:07 UTC (rev 2045) @@ -28,7 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.util.ApplicationConfig; -import javax.swing.*; +import javax.swing.Icon; import javax.swing.table.TableCellEditor; /** @@ -39,22 +39,16 @@ * @since 2.0.0 */ public class ConfigUIModelBuilder { - /** - * Logger - */ + /** Logger */ private static final Log log = LogFactory.getLog(ConfigUIModelBuilder.class); - /** - * current model used - */ + /** current model used */ ConfigUIModel model; - /** - * current category used - */ + + /** current category used */ CategoryModel category; - /** - * current option used - */ + + /** current option used */ OptionModel option; /** @@ -81,11 +75,11 @@ * the model. * * @param categoryName the name of the new category - * (can not to be {@code null}) + * (can not to be {@code null}) * @param categoryLabel the label of the new category - * (can not to be {@code null}) + * (can not to be {@code null}) * @throws IllegalStateException if there is not a current model, - * nor category + * nor category * @throws NullPointerException if any of parameter is {@code null} */ public void addCategory(String categoryName, String categoryLabel) @@ -288,6 +282,13 @@ } } + public void setCloseAction(Runnable runnable) { + checkNotNull(runnable, "setCloseAction", "runnable"); + checkCurrent(model, "model"); + model.setCloseAction(runnable); + + } + protected CategoryModel flushCategory() { CategoryModel result = category; if (category != null) { @@ -317,16 +318,16 @@ protected void checkNoCurrent(Object o, String type) { if (o != null) { - throw new IllegalStateException("there is already a current " + - type + "!"); + throw new IllegalStateException( + "there is already a current " + type + "!"); } } protected void checkNotNull(Object o, String method, String parameter) { if (o == null) { - throw new NullPointerException("method " + method + - " does not support null parameter " + parameter + "!"); + throw new NullPointerException( + "method " + method + " does not support null parameter " + + parameter + "!"); } } - }
participants (1)
-
tchemit@users.nuiton.org