Author: tchemit Date: 2010-02-01 01:12:27 +0100 (Mon, 01 Feb 2010) New Revision: 1729 Added: trunk/jaxx-demo/src/main/resources/icons/action-reload-application.png trunk/jaxx-demo/src/main/resources/icons/action-reload-ui.png trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUIHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBackEntry.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBacksManager.java Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.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 trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/OptionModel.java trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-en_GB.properties trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-fr_FR.properties Log: Evolution #297: Improve ConfigUI with a CallBackManager Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-02-01 00:12:27 UTC (rev 1729) @@ -63,26 +63,27 @@ public static final String PROPERTY_ADJUSTING = "adjusting"; /** - * un drapeau pour bloquer la sauvegarde lors de la modification en masse des options - * via les setter. + * un drapeau pour bloquer la sauvegarde lors de la modification en + * masse des options via les setter. */ protected boolean adjusting; - protected final PropertyChangeListener saveAction = new PropertyChangeListener() { + protected final PropertyChangeListener saveAction = + new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (adjusting) { - if (log.isDebugEnabled()) { - log.debug("skip save while adjusting"); + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (adjusting) { + if (log.isDebugEnabled()) { + log.debug("skip save while adjusting"); + } + return; + } + if (log.isDebugEnabled()) { + log.debug("Saving configuration at " + new Date()); + } + saveForUser(); } - return; - } - if (log.isDebugEnabled()) { - log.debug("Saving configuration at " + new Date()); - } - saveForUser(); - } - }; + }; public DemoConfig() { @@ -90,7 +91,8 @@ // chargement de la configuration interne - InputStream stream = getClass().getResourceAsStream(APPLICATION_PROPERTIES); + InputStream stream = getClass().getResourceAsStream( + APPLICATION_PROPERTIES); Properties p = new Properties(); try { @@ -112,7 +114,8 @@ } // on supprime le stamp de snapshot s'il existe - String sVersion = VersionUtil.removeSnapshot(getOption("application.version")); + String sVersion = VersionUtil.removeSnapshot( + getOption("application.version")); Version version = VersionUtil.valueOf(sVersion); setDefaultOption("version", version.getVersion()); @@ -210,11 +213,17 @@ } public static final String[] DEFAULT_JAXX_PCS = { - PROPERTY_FULLSCREEN, PROPERTY_LOCALE, PROPERTY_FONT_SIZE, PROPERTY_ADJUSTING + PROPERTY_FULLSCREEN, + PROPERTY_LOCALE, + PROPERTY_FONT_SIZE, + PROPERTY_ADJUSTING }; public void removeJaxxPropertyChangeListener() { - PropertyChangeListener[] toRemove = JAXXUtil.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners()); + PropertyChangeListener[] toRemove; + toRemove = JAXXUtil.findJaxxPropertyChangeListener( + DEFAULT_JAXX_PCS, + getPropertyChangeListeners()); if (toRemove == null || toRemove.length == 0) { return; } @@ -235,11 +244,41 @@ ////////////////////////////////////////////////// public static enum Option implements OptionDef { - CONFIG_FILE(CONFIG_FILE_NAME, _("jaxxdemo.config.configFileName.description"), "jaxxdemo", String.class, true, true), - FULL_SCREEN("ui.fullscreen", _("jaxxdemo.config.ui.fullscreen"), "false", Boolean.class, false, false), - LOCALE("ui." + PROPERTY_LOCALE, _("jaxxdemo.config.ui." + PROPERTY_LOCALE), Locale.FRANCE.toString(), Locale.class, false, false), - FONT_SIZE("ui." + PROPERTY_FONT_SIZE, _("jaxxdemo.config.ui." + PROPERTY_FONT_SIZE), "10f", Float.class, false, false), - DEMO_PATH("ui.demo.path", _("jaxxdemo.config.ui.demo.path"), "$root/jaxxdemo.tree.component.jaxx/jaxxdemo.tree.component.jaxx.tree.navigation/" + FullNavigationTreeDemo.class.getSimpleName(), String.class, false, false); + CONFIG_FILE( + CONFIG_FILE_NAME, + _("jaxxdemo.config.configFileName.description"), + "jaxxdemo", + String.class, + true, + true), + FULL_SCREEN( + "ui.fullscreen", + _("jaxxdemo.config.ui.fullscreen"), + "false", + Boolean.class, + false, + false), + LOCALE( + "ui." + PROPERTY_LOCALE, + _("jaxxdemo.config.ui.locale"), + Locale.FRANCE.toString(), + Locale.class, + false, + false), + FONT_SIZE( + "ui." + PROPERTY_FONT_SIZE, + _("jaxxdemo.config.ui.fontSize"), + "10f", + Float.class, + false, + false), + DEMO_PATH( + "ui.demo.path", + _("jaxxdemo.config.ui.demo.path"), + "$root/jaxxdemo.tree.component.jaxx/jaxxdemo.tree.component.jaxx.tree.navigation/" + FullNavigationTreeDemo.class.getSimpleName(), + String.class, + false, + true); public final String key; public final String description; public final String defaultValue; Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-02-01 00:12:27 UTC (rev 1729) @@ -22,6 +22,7 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXUtil; +import jaxx.runtime.SwingUtil; import jaxx.runtime.context.DefaultApplicationContext; import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.context.JAXXInitialContext; @@ -249,6 +250,31 @@ } } + final Runnable reloadUICallback = new Runnable() { + + @Override + public void run() { + if (log.isInfoEnabled()) { + log.info("will reload ui"); + } + DefaultApplicationContext context = RunDemo.get(); + DemoUI ui = getUI(context); + DemoConfig config = ui.getConfig(); + reloadUI(context, config); + } + }; + + final Runnable reloadApplicationCallback = new Runnable() { + + @Override + public void run() { + if (log.isInfoEnabled()) { + log.info("will reload appplication"); + } + close(RunDemo.get()); + } + }; + public void showConfig(JAXXContext context) { DemoUI ui = getUI(context); final DemoConfig config = ui.getConfig(); @@ -257,19 +283,16 @@ builder.createModel(config); - builder.setReloadUICallback(new Runnable() { - @Override - public void run() { - if (log.isInfoEnabled()) { - log.info("will reload ui"); - } - DefaultApplicationContext context = RunDemo.get(); - DemoUI ui = getUI(context); - DemoConfig config = ui.getConfig(); - reloadUI(context, config); - } - }); + builder.registerCallBack("ui", + n_("demo.action.reload.ui"), + SwingUtil.createActionIcon("reload-ui"), + reloadUICallback); + + builder.registerCallBack("application", + n_("demo.action.reload.application"), + SwingUtil.createActionIcon("reload-application"), + reloadApplicationCallback); // categorie repertoires @@ -284,17 +307,21 @@ builder.addOption(DemoConfig.Option.FULL_SCREEN); builder.setOptionPropertyName(DemoConfig.PROPERTY_FULLSCREEN); - builder.setOptionNeedReloadUI(true); + builder.setOptionCallBack("ui"); builder.addOption(DemoConfig.Option.FONT_SIZE); builder.setOptionPropertyName(DemoConfig.PROPERTY_FONT_SIZE); + builder.setOptionCallBack("application"); builder.addOption(DemoConfig.Option.LOCALE); builder.setOptionPropertyName(DemoConfig.PROPERTY_LOCALE); - builder.setOptionNeedReloadUI(true); + builder.setOptionCallBack("ui"); ConfigUIModel model = builder.flushModel(); - ConfigUI configUI = ConfigUIBuilder.newConfigUI(context, model, "jaxxdemo.config.category.directories"); + ConfigUI configUI = ConfigUIBuilder.newConfigUI( + context, + model, + "jaxxdemo.config.category.other"); ConfigUIBuilder.showConfigUI(configUI, ui, false); } Modified: trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties =================================================================== --- trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties 2010-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-en_GB.properties 2010-02-01 00:12:27 UTC (rev 1729) @@ -104,6 +104,8 @@ close=Disable close2=Disable 2 close3=Disable 3 +demo.action.reload.application=Reload application +demo.action.reload.ui=Reload UI edit=Edit edit2=Edit 2 edit3=Edit 3 @@ -160,9 +162,10 @@ jaxxdemo.config.category.other=Others jaxxdemo.config.category.other.description=Others preferences jaxxdemo.config.configFileName.description=Configuration file name -jaxxdemo.config.ui.= jaxxdemo.config.ui.demo.path=Path of demo to select when starting application +jaxxdemo.config.ui.fontSize=default font size to use in sources jaxxdemo.config.ui.fullscreen=To change the screen mode (true for full screen) +jaxxdemo.config.ui.locale=Language used in application jaxxdemo.i18neditor.configuration=Configuration jaxxdemo.i18neditor.popupBorderText=Popup title jaxxdemo.i18neditor.selected.locale=Selected Language Modified: trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties =================================================================== --- trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties 2010-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo-fr_FR.properties 2010-02-01 00:12:27 UTC (rev 1729) @@ -104,6 +104,8 @@ close=Fermer close2=Fermer 2 close3=Fermer 3 +demo.action.reload.application=Redemarrer l'application +demo.action.reload.ui=Recharger l'interface graphique edit=Editer edit2=Editer 2 edit3=Editer 3 @@ -160,9 +162,10 @@ jaxxdemo.config.category.other=Autre jaxxdemo.config.category.other.description=Autres options jaxxdemo.config.configFileName.description=Le nom du fichier de configuration -jaxxdemo.config.ui.= -jaxxdemo.config.ui.demo.path= +jaxxdemo.config.ui.demo.path=Chemin de la d\u00E9mo par d\u00E9faut +jaxxdemo.config.ui.fontSize=La taille de la police \u00E0 utiliser pour visualiser dans les sources jaxxdemo.config.ui.fullscreen=Pour afficher l'aplication en mode pleine \u00E9cran +jaxxdemo.config.ui.locale=La langue utilis\u00E9e par l'application jaxxdemo.i18neditor.configuration=Configuration jaxxdemo.i18neditor.popupBorderText=Titre de la popup jaxxdemo.i18neditor.selected.locale=Langue s\u00E9lectionn\u00E9e Added: trunk/jaxx-demo/src/main/resources/icons/action-reload-application.png =================================================================== (Binary files differ) Property changes on: trunk/jaxx-demo/src/main/resources/icons/action-reload-application.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jaxx-demo/src/main/resources/icons/action-reload-ui.png =================================================================== (Binary files differ) Property changes on: trunk/jaxx-demo/src/main/resources/icons/action-reload-ui.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx 2010-02-01 00:12:27 UTC (rev 1729) @@ -0,0 +1,47 @@ +<JPanel layout='{new BorderLayout()}'> + <script><![CDATA[ + import jaxx.runtime.swing.editor.config.model.*; + + /** + * Init the ui. + */ + public void init() { + getHandler().init(this); + } + ]]> + </script> + + <ConfigCallBackUIHandler + id='handler' + initializer='getContextValue(ConfigCallBackUIHandler.class)'/> + + <JScrollPane constraints='BorderLayout.CENTER' + columnHeaderView='{treeHeader}'> + + <JTree id='detectedCallBack' + editable='false' + rootVisible='false' + rowHeight='24'/> + + </JScrollPane> + + <!--JPanel constraints='BorderLayout.SOUTH' layout='{new BorderLayout()}'> + + <JPanel constraints='BorderLayout.CENTER' + border='{new TitledBorder(_("config.callBack.description"))}'> + <JLabel id='callBackDescription'/> + </JPanel--> + + <JButton constraints='BorderLayout.SOUTH' + id='go' + text='config.launch.callBack' + toolTipText='config.launch.callBack.tip' + actionIcon='config-quit' + onActionPerformed='getHandler().doAction(this)'/> + <!--/JPanel--> + + <JPanel id='treeHeader' constraints='BorderLayout.EAST'> + <JLabel text='config.detected.callBack'/> + </JPanel> + +</JPanel> \ No newline at end of file Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUIHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUIHandler.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUIHandler.java 2010-02-01 00:12:27 UTC (rev 1729) @@ -0,0 +1,167 @@ +package jaxx.runtime.swing.editor.config; + +import jaxx.runtime.SwingUtil; +import jaxx.runtime.swing.editor.config.model.CallBackEntry; +import jaxx.runtime.swing.editor.config.model.OptionModel; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import static org.nuiton.i18n.I18n._; + +import javax.swing.*; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.DefaultTreeModel; +import java.awt.*; +import java.util.List; +import java.util.Map; + +/** + * callBackUI handler + * + * @author tchemit < chemit@codelutin.com > + * @since 2.0 + */ +public class ConfigCallBackUIHandler { + + /** + * Logger + */ + private static final Log log = LogFactory.getLog(ConfigCallBackUIHandler.class); + + public void init(ConfigCallBackUI ui) { + + // build tree model + DefaultMutableTreeNode root = new DefaultMutableTreeNode(); + + Map<CallBackEntry, List<OptionModel>> forSaved; + + forSaved = ui.getContextValue(Map.class, + ConfigUIBuilder.CALLBACKS_WITH_OPTIONS); + + for (Map.Entry<CallBackEntry, List<OptionModel>> e : + forSaved.entrySet()) { + + CallBackEntry callBackEntry = e.getKey(); + List<OptionModel> options = e.getValue(); + + DefaultMutableTreeNode callBackNode; + callBackNode = new DefaultMutableTreeNode(callBackEntry, true); + + root.add(callBackNode); + for (OptionModel o : options) { + + DefaultMutableTreeNode optionkNode; + optionkNode = new DefaultMutableTreeNode(o, false); + + callBackNode.add(optionkNode); + } + } + + JTree tree = ui.getDetectedCallBack(); + + tree.setModel(new DefaultTreeModel(root)); + + SwingUtil.expandTree(tree); + + tree.setCellRenderer(new DefaultTreeCellRenderer() { + @Override + public Component getTreeCellRendererComponent(JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { + if (log.isDebugEnabled()) { + log.debug("value = " + value.getClass()); + } + if (value == null) { + return super.getTreeCellRendererComponent( + tree, + value, + sel, + expanded, + leaf, + row, + hasFocus); + } + + if (!(value instanceof DefaultMutableTreeNode)) { + return super.getTreeCellRendererComponent( + tree, + value, + sel, + expanded, + leaf, + row, + hasFocus); + } + + DefaultMutableTreeNode n = (DefaultMutableTreeNode) value; + value = n.getUserObject(); + + if (value instanceof CallBackEntry) { + CallBackEntry v = (CallBackEntry) value; + if (log.isDebugEnabled()) { + log.debug("callBackEntry detected " + v.getName()); + } + value = _(v.getDescription()); + } else if (value instanceof OptionModel) { + + OptionModel v = (OptionModel) value; + if (log.isDebugEnabled()) { + log.debug("option detected " + v.getKey()); + } + value = v.getKey() + " (" + _(v.getDescription()) + ")"; + } + + JLabel rendererComponent; + rendererComponent = (JLabel) + super.getTreeCellRendererComponent( + tree, + value, + sel, + expanded, + leaf, + row, + hasFocus); + + value = n.getUserObject(); + + if (value instanceof CallBackEntry) { + + CallBackEntry v = (CallBackEntry) value; + rendererComponent.setIcon(v.getIcon()); + } + return rendererComponent; + } + }); + } + + public void doAction(final ConfigCallBackUI ui) { + log.info("Launch callBacks..."); + Window parent = ui.getContextValue(Window.class, "parent"); + if (parent != null) { + log.info("dispose parent window..."); + parent.dispose(); + } + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + List<CallBackEntry> callBacks; + callBacks = ui.getContextValue( + List.class, + ConfigUIBuilder.CALLBACKS); + for (CallBackEntry e : callBacks) { + if (log.isInfoEnabled()) { + log.info("launch callBack " + _(e.getDescription())); + } + e.getAction().run(); + } + } + }); + } +} \ No newline at end of file Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUIHandler.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.jaxx 2010-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.jaxx 2010-02-01 00:12:27 UTC (rev 1729) @@ -1,26 +1,3 @@ -<!-- - -/** - * *##% jaxx-runtime-swing-widget - * Copyright (C) 2008 - 2009 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>. ##%* - */ - ---> - <JPanel layout='{new BorderLayout()}'> <style source='ConfigCategoryUI.css'/> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx 2010-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx 2010-02-01 00:12:27 UTC (rev 1729) @@ -1,26 +1,3 @@ -<!-- - -/** - * *##% jaxx-runtime-swing-widget - * Copyright (C) 2008 - 2009 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>. ##%* - */ - ---> - <JPanel layout='{new BorderLayout()}'> <style source='ConfigUI.css'/> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java 2010-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java 2010-02-01 00:12:27 UTC (rev 1729) @@ -23,6 +23,7 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.SwingUtil; import jaxx.runtime.context.JAXXInitialContext; +import jaxx.runtime.swing.editor.config.model.CallBackEntry; import jaxx.runtime.swing.editor.config.model.CategoryModel; import jaxx.runtime.swing.editor.config.model.ConfigUIModel; import jaxx.runtime.swing.editor.config.model.OptionModel; @@ -36,8 +37,8 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; +import java.util.Map; /** * La classe pour construire l'ui @@ -47,6 +48,8 @@ public class ConfigUIBuilder { public static final Log log = LogFactory.getLog(ConfigUIBuilder.class); + public static final String CALLBACKS_WITH_OPTIONS = "callbacksWithOptions"; + public static final String CALLBACKS = "callbacks"; /** * Construire l'ui de configuration (sous forme de panel) @@ -56,14 +59,17 @@ * @param defaultCategory la categorie a selectionner * @return l'ui instanciate */ - public static ConfigUI newConfigUI(JAXXContext parentContext, final ConfigUIModel model, String defaultCategory) { + public static ConfigUI newConfigUI(JAXXContext parentContext, + final ConfigUIModel model, + String defaultCategory) { JAXXContext tx = new JAXXInitialContext().add(parentContext).add(model); final ConfigUI ui = new ConfigUI(tx); JButton quitButton = ui.getQuit(); // prepare quit action - Action quitAction = new AbstractAction(quitButton.getText(), quitButton.getIcon()) { + Action quitAction = new AbstractAction(quitButton.getText(), + quitButton.getIcon()) { private static final long serialVersionUID = 1L; @@ -73,119 +79,57 @@ return; } - boolean needReloadUI = false; - boolean needReloadApplication = false; + final Window parentWindow = ui.getParentContainer(Window.class); - StringBuilder reloadUIBuffer = new StringBuilder(); + if (!model.isSaved() || model.isStandalone()) { - StringBuilder reloadApplicationBuffer = new StringBuilder(); + // just quit, no callBack can be apply here - if (model.isSaved() && !model.isStandalone()) { + // close the configu ui + parentWindow.dispose(); + return; + } + Map<CallBackEntry, List<OptionModel>> forSaved; + forSaved = model.getCallBacksForSaved(); - StringBuilder buffer = new StringBuilder(); + if (forSaved.isEmpty()) { + // just quit, no callBack to call - // on doit verifier si des options sauvees necessite - // un redemarrage de l'application - for (CategoryModel cat : model) { - List<OptionModel> savedOptions = cat.getSavedOptions(); - List<OptionModel> needReloadUIOptions = new ArrayList<OptionModel>(); - List<OptionModel> needReloadApplicationOptions = new ArrayList<OptionModel>(); - if (!savedOptions.isEmpty()) { - Iterator<OptionModel> itr = savedOptions.iterator(); - buffer.append("\n").append(_("config.category.saved", _(cat.getCategory()))).append("\n"); - while (itr.hasNext()) { - OptionModel option = itr.next(); - buffer.append("\n- ").append(option.getKey()); - if (option.isNeedReloadApplication()) { - needReloadApplication = true; - needReloadApplicationOptions.add(option); - continue; - } - if (option.isNeedReloadUI()) { - needReloadUI = true; - needReloadUIOptions.add(option); - continue; - } - itr.remove(); - - } - if (!savedOptions.isEmpty()) { - - if (!needReloadApplicationOptions.isEmpty()) { - reloadApplicationBuffer.append("\n"); - reloadApplicationBuffer.append(_("config.category.needReloadApplication", _(cat.getCategory()))); - reloadApplicationBuffer.append("\n"); - // second pass to obtain needReloadUI - for (OptionModel option : needReloadApplicationOptions) { - reloadApplicationBuffer.append("\n- ").append(option.getKey()); - } - } - - if (!needReloadUIOptions.isEmpty()) { - reloadUIBuffer.append("\n"); - reloadUIBuffer.append(_("config.category.needReloadUI", _(cat.getCategory()))); - reloadUIBuffer.append("\n"); - // second pass to obtain needReloadUI - for (OptionModel option : needReloadUIOptions) { - reloadUIBuffer.append("\n- ").append(option.getKey()); - } - } - } - - } - } - - if (log.isInfoEnabled()) { - log.info("save options :\n" + buffer.toString()); - } - - if (needReloadApplication) { - - // reloading application implies reloading ui - needReloadUI = false; - - askUser(ui, - _("config.title.will.reload.application"), - _("config.model.needReloadApplication") + - reloadApplicationBuffer.toString(), - JOptionPane.INFORMATION_MESSAGE, - new Object[]{_("config.choice.ok")}, - 0); - } - - if (needReloadUI) { - askUser(ui, - _("config.title.will.reload.ui"), - _("config.model.needReloadUI") + - reloadUIBuffer.toString(), - JOptionPane.INFORMATION_MESSAGE, - new Object[]{_("config.choice.ok")}, - 0); - } + // close the configu ui + parentWindow.dispose(); + return; } - // close the configu ui - ui.getParentContainer(Window.class).dispose(); + forSaved = model.getCallBacksForSaved(); - if (needReloadApplication) { + // init callBackUI - Runnable callback = model.getReloadApplicationCallback(); - if (callback == null) { - throw new IllegalStateException("No reloadApplicationCallback found in model"); - } + ConfigCallBackUI lastUI = new ConfigCallBackUI( + new JAXXInitialContext(). + add("parent", parentWindow). + add(ui). + add(CALLBACKS_WITH_OPTIONS, forSaved). + add(CALLBACKS, new ArrayList<CallBackEntry>(forSaved.keySet())). + add(new ConfigCallBackUIHandler()) + ); - SwingUtilities.invokeLater(callback); - } else if (needReloadUI) { + lastUI.init(); + ui.setVisible(false); + parentWindow.remove(ui); + parentWindow.add(lastUI); + + SwingUtilities.invokeLater(new Runnable() { - Runnable callback = model.getReloadUICallback(); - if (callback == null) { - throw new IllegalStateException("No reloadUICallback found in model"); + @Override + public void run() { + parentWindow.validate(); } - SwingUtilities.invokeLater(callback); - } + }); +// dialog.pack(); +// SwingUtil.center(parentWindow, lastUI); - +// lastUI.setVisible(true); } }; String tip = quitButton.getToolTipText(); @@ -196,7 +140,8 @@ for (CategoryModel categoryModel : model) { String category = categoryModel.getCategory(); String categoryLabel = _(categoryModel.getCategoryLabel()); - ConfigCategoryUI p = new ConfigCategoryUI(new JAXXInitialContext().add(ui).add(categoryModel)); + ConfigCategoryUI p = new ConfigCategoryUI(new + JAXXInitialContext().add(ui).add(categoryModel)); p.getCategoryLabel().setText(categoryLabel); p.setName(category); ui.getCategories().addTab(_(category), null, p, categoryLabel); @@ -205,7 +150,8 @@ model.setCategory(defaultCategory); int categoryIndex = model.getCategoryIndex(defaultCategory); if (log.isDebugEnabled()) { - log.debug("index of default category (" + defaultCategory + ") : " + categoryIndex); + log.debug("index of default category (" + defaultCategory + ") : " + + categoryIndex); } ui.getCategories().setSelectedIndex(categoryIndex); return ui; @@ -215,10 +161,14 @@ * Affiche l'ui de configuration dans un boite de dialogue. * * @param configUI l'ui de configuration - * @param ui l'ui parent de la boite de dialogue a afficher (peut etre nulle) - * @param undecorated un drapeau pour savoir si on affiche les decorations de fenetre + * @param ui l'ui parent de la boite de dialogue a afficher + * (peut etre nulle) + * @param undecorated un drapeau pour savoir si on affiche les decorations + * de fenetre */ - public static void showConfigUI(final ConfigUI configUI, Frame ui, boolean undecorated) { + public static void showConfigUI(final ConfigUI configUI, + Frame ui, + boolean undecorated) { JDialog f = new JDialog(ui, true); f.setTitle(_("config.title")); f.add(configUI); @@ -240,7 +190,8 @@ f.setUndecorated(undecorated); JRootPane rootPane = f.getRootPane(); rootPane.setDefaultButton(configUI.getQuit()); - rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "quit"); + rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( + KeyStroke.getKeyStroke("ESCAPE"), "quit"); rootPane.getActionMap().put("quit", configUI.getQuit().getAction()); f.pack(); SwingUtil.center(ui, f); @@ -258,7 +209,9 @@ // get all the invalid options StringBuilder buffer = new StringBuilder(); - buffer.append(_("config.message.quit.invalid.category", categoryName)).append('\n'); + buffer.append(_("config.message.quit.invalid.category", + categoryName)); + buffer.append('\n'); for (OptionModel m : categoryModel.getInvalidOptions()) { buffer.append("\n- ").append(m.getKey()); } @@ -289,7 +242,8 @@ // category was modified, ask user if wants to save StringBuilder buffer = new StringBuilder(); - buffer.append(_("config.message.quit.valid.and.modified.category", categoryName)).append('\n'); + buffer.append(_("config.message.quit.valid.and.modified.category", + categoryName)).append('\n'); for (OptionModel m : categoryModel.getModifiedOptions()) { buffer.append("\n- ").append(m.getKey()); } @@ -323,7 +277,12 @@ return canContinue; } - public static int askUser(ConfigUI parent, String title, String message, int typeMessage, Object[] options, int defaultOption) { + public static int askUser(ConfigUI parent, + String title, + String message, + int typeMessage, + Object[] options, + int defaultOption) { int response = JOptionPane.showOptionDialog( parent, @@ -338,4 +297,159 @@ return response; } + + /** + * // prepare quit action + Action quitAction = new AbstractAction(quitButton.getText(), + quitButton.getIcon()) { + + private static final long serialVersionUID = 1L; + + @Override public void actionPerformed(ActionEvent e) { + if (!canQuitCategory(ui)) { + return; + } + + boolean needReloadUI = false; + boolean needReloadApplication = false; + + StringBuilder reloadUIBuffer = new StringBuilder(); + + StringBuilder reloadApplicationBuffer = new StringBuilder(); + + if (model.isSaved() && !model.isStandalone()) { + + + StringBuilder buffer = new StringBuilder(); + + // on doit verifier si des options sauvees necessite + // un redemarrage de l'application + for (CategoryModel cat : model) { + List<OptionModel> savedOptions = cat.getSavedOptions(); + List<OptionModel> needReloadUIOptions = new ArrayList<OptionModel>(); + List<OptionModel> needReloadApplicationOptions = new ArrayList<OptionModel>(); + if (!savedOptions.isEmpty()) { + Iterator<OptionModel> itr = savedOptions.iterator(); + buffer.append("\n").append(_("config.category.saved", _(cat.getCategory()))).append("\n"); + while (itr.hasNext()) { + OptionModel option = itr.next(); + buffer.append("\n- ").append(option.getKey()); + if (option.isNeedReloadApplication()) { + needReloadApplication = true; + needReloadApplicationOptions.add(option); + continue; + } + if (option.isNeedReloadUI()) { + needReloadUI = true; + needReloadUIOptions.add(option); + continue; + } + itr.remove(); + + } + if (!savedOptions.isEmpty()) { + + if (!needReloadApplicationOptions.isEmpty()) { + reloadApplicationBuffer.append("\n"); + reloadApplicationBuffer.append(_("config.category.needReloadApplication", _(cat.getCategory()))); + reloadApplicationBuffer.append("\n"); + // second pass to obtain needReloadUI + for (OptionModel option : needReloadApplicationOptions) { + reloadApplicationBuffer.append("\n- ").append(option.getKey()); + } + } + + if (!needReloadUIOptions.isEmpty()) { + reloadUIBuffer.append("\n"); + reloadUIBuffer.append(_("config.category.needReloadUI", _(cat.getCategory()))); + reloadUIBuffer.append("\n"); + // second pass to obtain needReloadUI + for (OptionModel option : needReloadUIOptions) { + reloadUIBuffer.append("\n- ").append(option.getKey()); + } + } + } + + } + } + + if (log.isInfoEnabled()) { + log.info("save options :\n" + buffer.toString()); + } + + if (needReloadApplication) { + + // reloading application implies reloading ui + needReloadUI = false; + + askUser(ui, + _("config.title.will.reload.application"), + _("config.model.needReloadApplication") + + reloadApplicationBuffer.toString(), + JOptionPane.INFORMATION_MESSAGE, + new Object[]{_("config.choice.ok")}, + 0); + } + + if (needReloadUI) { + askUser(ui, + _("config.title.will.reload.ui"), + _("config.model.needReloadUI") + + reloadUIBuffer.toString(), + JOptionPane.INFORMATION_MESSAGE, + new Object[]{_("config.choice.ok")}, + 0); + } + } + + // close the configu ui + ui.getParentContainer(Window.class).dispose(); + + if (needReloadApplication) { + + Runnable callback = model.getReloadApplicationCallback(); + if (callback == null) { + throw new IllegalStateException( + "No reloadApplicationCallback found in model"); + } + + SwingUtilities.invokeLater(callback); + } else if (needReloadUI) { + + Runnable callback = model.getReloadUICallback(); + if (callback == null) { + throw new IllegalStateException( + "No reloadUICallback found in model"); + } + SwingUtilities.invokeLater(callback); + } + + + } + }; + String tip = quitButton.getToolTipText(); + quitButton.setAction(quitAction); + quitButton.setToolTipText(tip); + + // build categories tabs + for (CategoryModel categoryModel : model) { + String category = categoryModel.getCategory(); + String categoryLabel = _(categoryModel.getCategoryLabel()); + ConfigCategoryUI p = new ConfigCategoryUI(new + JAXXInitialContext().add(ui).add(categoryModel)); + p.getCategoryLabel().setText(categoryLabel); + p.setName(category); + ui.getCategories().addTab(_(category), null, p, categoryLabel); + } + + model.setCategory(defaultCategory); + int categoryIndex = model.getCategoryIndex(defaultCategory); + if (log.isDebugEnabled()) { + log.debug("index of default category (" + defaultCategory + ") : " + + categoryIndex); + } + ui.getCategories().setSelectedIndex(categoryIndex); + return ui; + } + */ } Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBackEntry.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBackEntry.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBackEntry.java 2010-02-01 00:12:27 UTC (rev 1729) @@ -0,0 +1,57 @@ +package jaxx.runtime.swing.editor.config.model; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + +/** + * A call back with his attached options. + * + * @author tchemit < chemit@codelutin.com > + * @since 2.0 + */ +public class CallBackEntry { + + protected final String name; + protected final String description; + protected final Icon icon; + protected final Runnable action; + protected List<OptionModel> options; + + public CallBackEntry(String name, + String description, + Icon icon, + Runnable action) { + this.description = description; + this.icon = icon; + options = new ArrayList<OptionModel>(); + this.name = name; + this.action = action; + } + + public Runnable getAction() { + return action; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public Icon getIcon() { + return icon; + } + + public List<OptionModel> getOptions() { + // always send a copy + return new ArrayList<OptionModel>(options); + } + + protected void addOption(OptionModel option) { + options.add(option); + + } +} \ No newline at end of file Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBackEntry.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBacksManager.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBacksManager.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBacksManager.java 2010-02-01 00:12:27 UTC (rev 1729) @@ -0,0 +1,171 @@ +package jaxx.runtime.swing.editor.config.model; + +import javax.swing.*; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * CallBack manager. + * + * @author tchemit < chemit@codelutin.com > + * @since 2.0 + */ +public class CallBacksManager { + + /** + * lists of registred callback. + */ + protected List<CallBackEntry> callbacks; + + public CallBacksManager() { + callbacks = new ArrayList<CallBackEntry>(); + } + + /** + * Registers a new callback. + * <p/> + * <b>Note:</b> the order of registred callback is used to determine + * the higher priority of callback to launch if required. + * + * @param name the unique name of a callback + * @param description the i18n key to describe the action + * @param icon icon of callBack (used in ui) + * @param action the action of the callback + */ + public void registerCallBack(String name, + String description, + Icon icon, + Runnable action) { + if (name == null) { + throw new NullPointerException("parameter 'name' can not be null"); + } + if (action == null) { + throw new NullPointerException("parameter 'action' can not be null"); + } + if (description == null) { + throw new NullPointerException("parameter 'description' can " + + "not be null"); + } + if (icon == null) { + throw new NullPointerException("parameter 'icon' can not be null"); + } + if (getCallBack(name) != null) { + throw new IllegalArgumentException("there is already a callback " + + "with name '" + name + "'"); + } + callbacks.add(new CallBackEntry(name, description, icon, action)); + } + + /** + * Registers a option into a known callback. + * + * @param name the name of the callback + * @param option the option to register for the given callback + */ + public void registerOption(String name, OptionModel option) { + if (name == null) { + throw new NullPointerException("parameter 'name' can not be null"); + } + if (option == null) { + throw new NullPointerException("parameter 'option' can not be null"); + } + CallBackEntry callback = getCallBack(name); + if (callback == null) { + throw new IllegalArgumentException("could not find a callback " + + "with name '" + name + "'"); + } + callback.addOption(option); + } + + /** + * Scan a model and grab per callBack the options saved. + * + * @param model the model to scan + * @return the dictionnary of options for each callback to launch + */ + public Map<CallBackEntry, List<OptionModel>> getCallBacksForSaved( + ConfigUIModel model) { + + Map<CallBackEntry, List<OptionModel>> result; + result = new LinkedHashMap<CallBackEntry, List<OptionModel>>(); + + for (CategoryModel categoryModel : model) { + Map<CallBackEntry, List<OptionModel>> callBacks = + getCallBacksForSaved(categoryModel); + for (Map.Entry<CallBackEntry, List<OptionModel>> entry : + callBacks.entrySet()) { + CallBackEntry key = entry.getKey(); + List<OptionModel> value = entry.getValue(); + if (result.containsKey(key)) { + result.get(key).addAll(value); + } else { + result.put(key, value); + } + } + callBacks.clear(); + } + return result; + } + + /** + * Scan a category and grab per callBack the options saved. + * + * @param category the category to scan + * @return the dictionnary of options for each callBack to launch + */ + public Map<CallBackEntry, List<OptionModel>> getCallBacksForSaved( + CategoryModel category) { + + Map<CallBackEntry, List<OptionModel>> result; + result = new LinkedHashMap<CallBackEntry, List<OptionModel>>(); + + for (OptionModel optionModel : category) { + if (optionModel.isSaved()) { + CallBackEntry callBackEntry = getCallBack(optionModel); + if (callBackEntry != null) { + List<OptionModel> models = result.get(callBackEntry); + if (models == null) { + models = new ArrayList<OptionModel>(); + result.put(callBackEntry, models); + } + models.add(optionModel); + } + } + } + return result; + } + + /** + * Get the first callBack for a given option. + * + * @param option the option + * @return the first callBack (so the most important) on which the given + * option is attacjed. (can be null) + */ + protected CallBackEntry getCallBack(OptionModel option) { + for (CallBackEntry callback : callbacks) { + if (callback.getOptions().contains(option)) { + return callback; + } + } + return null; + } + + /** + * Obtain a registred callBack from his name. + * + * @param name the name of the searched callBack + * @return the callBack for the given name (or {@code null} if not found). + */ + protected CallBackEntry getCallBack(String name) { + for (CallBackEntry callback : callbacks) { + if (callback.getName().equals(name)) { + return callback; + } + } + return null; + } + +} \ No newline at end of file Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBacksManager.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL 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-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModel.java 2010-02-01 00:12:27 UTC (rev 1729) @@ -25,6 +25,7 @@ import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ApplicationConfig.OptionDef; +import javax.swing.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.util.*; @@ -68,14 +69,20 @@ */ protected boolean standalone; /** + * Callbacks manager + */ + protected CallBacksManager callBacksManager; + /** * call back when reload ui is necessary */ + @Deprecated protected Runnable reloadUICallback; /** * call back when reload application is necessary */ + @Deprecated protected Runnable reloadApplicationCallback; - + /** * suport of modification */ @@ -84,20 +91,27 @@ public ConfigUIModel(ApplicationConfig config) { this.config = config; this.categories = new LinkedHashMap<String, CategoryModel>(); + this.callBacksManager = new CallBacksManager(); } /** * Ajoute une categorie dans le modele. * - * @param category l'id de la categorie (la clef de traduction du nom de la categorie) - * @param categoryLabel la clef de traduction de la description de la categorie + * @param category l'id de la categorie (la clef de traduction du nom + * de la categorie) + * @param categoryLabel la clef de traduction de la description de + * la categorie * @param keys les options de la categorie - * @deprecated since 2.0.0 prefer use the {@link #addCategory(CategoryModel)} + * @deprecated since 2.0.0 prefer use the + * {@link #addCategory(CategoryModel)} */ @Deprecated - public void addCategory(String category, String categoryLabel, OptionDef... keys) { + public void addCategory(String category, + String categoryLabel, + OptionDef... keys) { if (categories.containsKey(category)) { - throw new IllegalArgumentException(_("config.error.category.already.exists", category)); + throw new IllegalArgumentException( + _("config.error.category.already.exists", category)); } OptionModel[] entries = new OptionModel[keys.length]; int index = 0; @@ -117,7 +131,9 @@ */ public void addCategory(CategoryModel category) { if (categories.containsKey(category.getCategory())) { - throw new IllegalArgumentException(_("config.error.category.already.exists", category.getCategory())); + throw new IllegalArgumentException( + _("config.error.category.already.exists", + category.getCategory())); } categories.put(category.getCategory(), category); } @@ -129,14 +145,52 @@ */ public void setCategory(String category) { if (!categories.containsKey(category)) { - throw new IllegalArgumentException(_("config.error.category.not.found", category)); + throw new IllegalArgumentException( + _("config.error.category.not.found", category)); } CategoryModel newCategoryModel = categories.get(category); setCategoryModel(newCategoryModel); - newCategoryModel.firePropertyChange(CategoryModel.MODIFIED_PROPERTY_NAME, false, getCategoryModel().isModified()); - newCategoryModel.firePropertyChange(CategoryModel.VALID_PROPERTY_NAME, false, getCategoryModel().isValid()); + newCategoryModel.firePropertyChange( + CategoryModel.MODIFIED_PROPERTY_NAME, false, + getCategoryModel().isModified()); + newCategoryModel.firePropertyChange( + CategoryModel.VALID_PROPERTY_NAME, false, + getCategoryModel().isValid()); } + /** + * Registers a new callback. + * <p/> + * <b>Note:</b> the order of registred callback is used to determine + * the higher priority of callback to launch if required. + * + * @param name the unique name of a callback + * @param description the i18n key to describe the action + * @param icon the icon of the callBack (used in ui) + * @param action the action of the callback + */ + public void registerCallBack(String name, + String description, + Icon icon, + Runnable action) { + callBacksManager.registerCallBack(name, description, icon, action); + } + + /** + * Registers a option into a known callback. + * + * @param name the name of the callback + * @param option the option to register for the given callback + */ + public void registerOptionCallBack(String name, OptionModel option) { + callBacksManager.registerOption(name, option); + } + + public Map<CallBackEntry, List<OptionModel>> getCallBacksForSaved( + ) { + return callBacksManager.getCallBacksForSaved(this); + } + @Override public Iterator<CategoryModel> iterator() { return categories.values().iterator(); @@ -168,10 +222,12 @@ this.standalone = standalone; } + @Deprecated public Runnable getReloadApplicationCallback() { return reloadApplicationCallback; } + @Deprecated public Runnable getReloadUICallback() { return reloadUICallback; } @@ -180,7 +236,8 @@ // compute transients keys (to never be saved) List<String> transients = new ArrayList<String>(); - //TODO TC-20091222 : will be in ApplicationConfig, for the moment catch in your config it... + //TODO TC-20091222 : will be in ApplicationConfig, for the moment + // catch in your config it... // config.setAdjusting(true); config.setOption("adjusting", "true"); @@ -192,13 +249,19 @@ if (option.getPropertyName() != null) { // this is a javaBean option try { - PropertyUtils.setProperty(config, option.getPropertyName(), value); + PropertyUtils.setProperty(config, + option.getPropertyName(), value); } catch (Exception e) { - throw new RuntimeException("could not set property [" + option.getPropertyName() + "] with value = " + value, e); + throw new RuntimeException( + "could not set property [" + + option.getPropertyName() + + "] with value = " + value, e); } } else { - // mutator could have extra code to be done when modify an option - config.setOption(option.getKey(), value == null ? null : value.toString()); + // mutator could have extra code to be done when + // modify an option + config.setOption(option.getKey(), value == null ? + null : value.toString()); } // l'option a été sauvegardée, on la marque option.setSaved(true); @@ -210,7 +273,8 @@ } } } finally { - //TODO TC-20091222 : will be in ApplicationConfig, for the moment catch in your config it... + //TODO TC-20091222 : will be in ApplicationConfig, + // for the moment catch in your config it... // config.setAdjusting(false); config.setOption("adjusting", "false"); } @@ -219,9 +283,14 @@ // save config config.saveForUser(transients.toArray(new String[transients.size()])); // notify data has changed - categoryModel.firePropertyChange(CategoryModel.MODIFIED_PROPERTY_NAME, categoryModel.isModified(), true); - categoryModel.firePropertyChange(CategoryModel.VALID_PROPERTY_NAME, false, categoryModel.isValid()); - categoryModel.firePropertyChange(CategoryModel.RELOAD_PROPERTY_NAME, false, true); + categoryModel.firePropertyChange( + CategoryModel.MODIFIED_PROPERTY_NAME, + categoryModel.isModified(), true); + categoryModel.firePropertyChange( + CategoryModel.VALID_PROPERTY_NAME, + false, categoryModel.isValid()); + categoryModel.firePropertyChange( + CategoryModel.RELOAD_PROPERTY_NAME, false, true); } public void reset() { @@ -232,9 +301,14 @@ } } // notify data has changed - categoryModel.firePropertyChange(CategoryModel.MODIFIED_PROPERTY_NAME, categoryModel.isModified(), true); - categoryModel.firePropertyChange(CategoryModel.VALID_PROPERTY_NAME, false, categoryModel.isValid()); - categoryModel.firePropertyChange(CategoryModel.RELOAD_PROPERTY_NAME, false, true); + categoryModel.firePropertyChange( + CategoryModel.MODIFIED_PROPERTY_NAME, + categoryModel.isModified(), true); + categoryModel.firePropertyChange( + CategoryModel.VALID_PROPERTY_NAME, + false, categoryModel.isValid()); + categoryModel.firePropertyChange( + CategoryModel.RELOAD_PROPERTY_NAME, false, true); } public int getCategoryIndex(String category) { @@ -249,7 +323,9 @@ return -1; } - public void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + public void firePropertyChange(String propertyName, + Object oldValue, + Object newValue) { pcs.firePropertyChange(propertyName, oldValue, newValue); } @@ -257,7 +333,8 @@ pcs.addPropertyChangeListener(listener); } - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + public void addPropertyChangeListener(String propertyName, + PropertyChangeListener listener) { pcs.addPropertyChangeListener(propertyName, listener); } @@ -265,7 +342,8 @@ pcs.removePropertyChangeListener(listener); } - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + public void removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { pcs.removePropertyChangeListener(propertyName, listener); } @@ -273,7 +351,8 @@ return pcs.hasListeners(propertyName); } - public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName) { + public synchronized PropertyChangeListener[] getPropertyChangeListeners( + String propertyName) { return pcs.getPropertyChangeListeners(propertyName); } @@ -281,10 +360,13 @@ return pcs.getPropertyChangeListeners(); } - protected void setReloadApplicationCallback(Runnable reloadApplicationCallback) { + @Deprecated + protected void setReloadApplicationCallback( + Runnable reloadApplicationCallback) { this.reloadApplicationCallback = reloadApplicationCallback; } + @Deprecated protected void setReloadUICallback(Runnable reloadUICallback) { this.reloadUICallback = reloadUICallback; } @@ -292,4 +374,8 @@ protected ApplicationConfig getConfig() { return config; } + + protected CallBacksManager getCallBacksManager() { + return callBacksManager; + } } 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-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java 2010-02-01 00:12:27 UTC (rev 1729) @@ -4,6 +4,7 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.util.ApplicationConfig; +import javax.swing.*; import javax.swing.table.TableCellEditor; /** @@ -43,7 +44,8 @@ * @throws IllegalStateException if there is already a current model * @throws NullPointerException if config is {@code null} */ - public void createModel(ApplicationConfig config) throws IllegalStateException, NullPointerException { + public void createModel(ApplicationConfig config) + throws IllegalStateException, NullPointerException { checkNoCurrent(model, "model"); checkNotNull(config, "createModel", "config"); model = new ConfigUIModel(config); @@ -58,9 +60,11 @@ * @param callback the call back to set * @throws IllegalStateException if there is not a current model * @throws NullPointerException if any of parameter is {@code null} - * @see jaxx.runtime.swing.editor.config.model.ConfigUIModel#setReloadApplicationCallback(Runnable) + * @see ConfigUIModel#setReloadApplicationCallback(Runnable) */ - public void setReloadApplicationCallback(Runnable callback) throws IllegalStateException, NullPointerException { + @Deprecated + public void setReloadApplicationCallback(Runnable callback) + throws IllegalStateException, NullPointerException { checkCurrent(model, "model"); checkNotNull(callback, "setReloadApplicationCallback", "callback"); model.setReloadApplicationCallback(callback); @@ -72,8 +76,9 @@ * @param callback the call back to set * @throws IllegalStateException if there is not a current model * @throws NullPointerException if any of parameter is {@code null} - * @see jaxx.runtime.swing.editor.config.model.ConfigUIModel#setReloadUICallback(Runnable) + * @see ConfigUIModel#setReloadUICallback(Runnable) */ + @Deprecated public void setReloadUICallback(Runnable callback) { checkCurrent(model, "model"); checkNotNull(callback, "setReloadUICallback", "callback"); @@ -83,14 +88,19 @@ /** * Add a new category, and set it as current. * <p/> - * <b>Note:</b> As side effets, if a previous category, then store it to the model. + * <b>Note:</b> As side effets, if a previous category, then store it to + * the model. * - * @param categoryName the name of the new category (can not to be {@code null}) - * @param categoryLabel the label of the new category (can not to be {@code null}) - * @throws IllegalStateException if there is not a current model, nor category + * @param categoryName the name of the new category + * (can not to be {@code null}) + * @param categoryLabel the label of the new category + * (can not to be {@code null}) + * @throws IllegalStateException if there is not a current model, + * nor category * @throws NullPointerException if any of parameter is {@code null} */ - public void addCategory(String categoryName, String categoryLabel) throws IllegalStateException, NullPointerException { + public void addCategory(String categoryName, String categoryLabel) + throws IllegalStateException, NullPointerException { checkCurrent(model, "model"); checkNotNull(categoryName, "addCategory", "categoryName"); checkNotNull(categoryLabel, "addCategory", "categoryLabel"); @@ -104,13 +114,16 @@ /** * Add a new option, and set it as current. * <p/> - * <b>Note:</b> As side effets, if a previous option, then store it to the model. + * <b>Note:</b> As side effets, if a previous option, then store it to + * the model. * * @param def the def ot the new option - * @throws IllegalStateException if there is not a current model, nor category + * @throws IllegalStateException if there is not a current model, + * nor category * @throws NullPointerException if any of parameter is {@code null} */ - public void addOption(ApplicationConfig.OptionDef def) throws IllegalStateException, NullPointerException { + public void addOption(ApplicationConfig.OptionDef def) + throws IllegalStateException, NullPointerException { checkCurrent(model, "model"); checkCurrent(category, "category"); checkNotNull(def, "addOption", "def"); @@ -125,7 +138,8 @@ /** * Add a new option with a propertyName, and set it as current. * <p/> - * <b>Note:</b> As side effets, if a previous option, then store it to the model. + * <b>Note:</b> As side effets, if a previous option, then store it to + * the model. * <p/> * <b>Note:</b> This method is a short-cut for * {@link #addOption(org.nuiton.util.ApplicationConfig.OptionDef)} then @@ -133,10 +147,12 @@ * * @param def the def ot the new option * @param propertyName the propertyName to set on the option - * @throws IllegalStateException if there is not a current model, nor category + * @throws IllegalStateException if there is not a current model, nor + * category * @throws NullPointerException if any of parameter is {@code null} */ - public void addOption(ApplicationConfig.OptionDef def, String propertyName) throws IllegalStateException, NullPointerException { + public void addOption(ApplicationConfig.OptionDef def, String propertyName) + throws IllegalStateException, NullPointerException { addOption(def); checkNotNull(propertyName, "setOptionPropertyName", "propertyName"); option.setPropertyName(propertyName); @@ -148,9 +164,10 @@ * @param propertyName the propertyName to set in the current option. * @throws IllegalStateException if there is not a current option set. * @throws NullPointerException if any of parameter is {@code null} - * @see jaxx.runtime.swing.editor.config.model.OptionModel#setPropertyName(String) + * @see OptionModel#setPropertyName(String) */ - public void setOptionPropertyName(String propertyName) throws IllegalStateException, NullPointerException { + public void setOptionPropertyName(String propertyName) + throws IllegalStateException, NullPointerException { checkCurrent(option, "option"); checkNotNull(propertyName, "setOptionPropertyName", "propertyName"); option.setPropertyName(propertyName); @@ -162,22 +179,58 @@ * @param editor the editor to set in the current option. * @throws IllegalStateException if there is not a current option set. * @throws NullPointerException if any of parameter is {@code null} - * @see jaxx.runtime.swing.editor.config.model.OptionModel#setEditor(javax.swing.table.TableCellEditor) + * @see OptionModel#setEditor(javax.swing.table.TableCellEditor) */ - public void setOptionEditor(TableCellEditor editor) throws IllegalStateException, NullPointerException { + public void setOptionEditor(TableCellEditor editor) + throws IllegalStateException, NullPointerException { checkCurrent(option, "option"); checkNotNull(editor, "setOptionEditor", "editor"); option.setEditor(editor); } /** + * Registers a new callback. + * <p/> + * <b>Note:</b> the order of registred callback is used to determine + * the higher priority of callback to launch if required. + * + * @param name the unique name of a callback + * @param description the i18n key to describe the action + * @param icon the icon of the callBack (used in ui) + * @param action the action of the callback + */ + public void registerCallBack(String name, + String description, + Icon icon, + Runnable action) { + checkCurrent(model, "model"); + checkNotNull(name, "registerCallBack", "name"); + checkNotNull(description, "registerCallBack", "description"); + checkNotNull(action, "registerCallBack", "action"); + model.registerCallBack(name, description, icon, action); + } + + /** + * Registers the current option into a known callback. + * + * @param name the name of the callback + */ + public void setOptionCallBack(String name) { + checkCurrent(option, "option"); + checkNotNull(name, "setOptionCallBack", "name"); + model.registerOptionCallBack(name, option); + } + + /** * Set the needReloadUI flag on the current option. * * @param needReload new value to set * @throws IllegalStateException if there is not a current option set. - * @see jaxx.runtime.swing.editor.config.model.OptionModel#setNeedReloadUI(boolean) + * @see OptionModel#setNeedReloadUI(boolean) */ - public void setOptionNeedReloadUI(boolean needReload) throws IllegalStateException { + @Deprecated + public void setOptionNeedReloadUI(boolean needReload) + throws IllegalStateException { checkCurrent(option, "option"); option.setNeedReloadUI(needReload); } @@ -187,9 +240,10 @@ * * @param needReload new value to set * @throws IllegalStateException if there is not a current option set. - * @see jaxx.runtime.swing.editor.config.model.OptionModel#setNeedReloadUI(boolean) + * @see OptionModel#setNeedReloadUI(boolean) */ - public void setOptionNeedReloadApplication(boolean needReload) throws IllegalStateException { + public void setOptionNeedReloadApplication(boolean needReload) + throws IllegalStateException { checkCurrent(option, "option"); option.setNeedReloadApplication(needReload); } @@ -197,7 +251,8 @@ /** * Flush the model and return it. * <p/> - * <b>Note:</b> As a side effect, nothing is available in the builder after this operation. + * <b>Note:</b> As a side effect, nothing is available in the builder + * after this operation. * To reuse the builder on a model, use the dedicated setter. * * @return the final model @@ -235,9 +290,11 @@ * <b>Note:</b> As side effets, il will clean current option. * * @param categoryModel the category to use - * @throws IllegalStateException if there is not a current model or a current category + * @throws IllegalStateException if there is not a current model or a + * current category */ - public void setCategory(CategoryModel categoryModel) throws IllegalStateException { + public void setCategory(CategoryModel categoryModel) + throws IllegalStateException { checkCurrent(model, "model"); checkNoCurrent(category, "category"); category = categoryModel; @@ -251,9 +308,11 @@ * Sets the given option as current option. * * @param optionModel the option to use - * @throws IllegalStateException if there is not a current model, nor category, or a current option + * @throws IllegalStateException if there is not a current model, nor + * category, or a current option */ - public void setOption(OptionModel optionModel) throws IllegalStateException { + public void setOption(OptionModel optionModel) + throws IllegalStateException { checkCurrent(model, "model"); checkCurrent(category, "category"); checkNoCurrent(option, "option"); @@ -292,13 +351,15 @@ 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 + "!"); } } Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/OptionModel.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/OptionModel.java 2010-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/OptionModel.java 2010-02-01 00:12:27 UTC (rev 1729) @@ -46,10 +46,12 @@ /** * un drapeau pour savoir si le changement de l'option nécessite un redémarrage de l'ui. */ + @Deprecated protected boolean needReloadUI = false; /** * un drapeau pour savoir si le changement de l'option nécessite un redémarrage de l'application. */ + @Deprecated protected boolean needReloadApplication = false; /** * la valeur non modifié de l'option @@ -103,10 +105,12 @@ return def.isFinal(); } + @Deprecated public boolean isNeedReloadUI() { return needReloadUI; } + @Deprecated public boolean isNeedReloadApplication() { return needReloadApplication; } @@ -160,10 +164,12 @@ this.editor = editor; } + @Deprecated protected void setNeedReloadUI(boolean needReloadUI) { this.needReloadUI = needReloadUI; } + @Deprecated protected void setNeedReloadApplication(boolean needReloadApplication) { this.needReloadApplication = needReloadApplication; } Modified: trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-en_GB.properties =================================================================== --- trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-en_GB.properties 2010-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-en_GB.properties 2010-02-01 00:12:27 UTC (rev 1729) @@ -20,10 +20,14 @@ config.defaultValue=Default value config.defaultValue.tip=Default value of the option config.descrition=Description +config.detected.callBack=Detected actions config.error.category.already.exists=category with name '%1$s' does already exist\! config.error.category.not.found=category with name '%1$s' does not exist\! +config.final.callBack=Action to perform config.key=Key config.key.tip=Key of the option +config.launch.callBack=Perform +config.launch.callBack.tip=Perform necessary actions config.message.quit.invalid.category=The category '%1$s' is not valid\! config.message.quit.valid.and.modified.category=The category '%1$s' has some modified options \: config.model.needReloadApplication= Modified: trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-fr_FR.properties =================================================================== --- trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-fr_FR.properties 2010-01-30 11:46:50 UTC (rev 1728) +++ trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-fr_FR.properties 2010-02-01 00:12:27 UTC (rev 1729) @@ -20,10 +20,14 @@ config.defaultValue=Valeur par d\u00E9faut config.defaultValue.tip=Valeur par d\u00E9faut de l'option config.descrition=Description +config.detected.callBack=Actions d\u00E9tect\u00E9es pour les options modifi\u00E9es config.error.category.already.exists=La cat\u00E9gorie de nom '%1$s' existe d\u00E9j\u00E0\! config.error.category.not.found=La cat\u00E9gorie de nom '%1$s' n'existe pas\! +config.final.callBack=Action \u00E0 executer config.key=Clef config.key.tip=Clef de l'option +config.launch.callBack=Lancer +config.launch.callBack.tip=Lancer les actions n\u00E9cessaires config.message.quit.invalid.category=La cat\u00E9gorie '%1$s' n'est pas valide\! config.message.quit.valid.and.modified.category=La cat\u00E9gorie '%1$s' poss\u00E8dent des options modifi\u00E9es \: config.model.needReloadApplication=Des options ont \u00E9t\u00E9 modifi\u00E9es qui n\u00E9cessitent le red\u00E9marrage de l'application.\n