r1837 - in trunk: . jaxx-demo/src/main/java/jaxx/demo jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model
Author: tchemit Date: 2010-04-14 14:29:18 +0200 (Wed, 14 Apr 2010) New Revision: 1837 Log: - Evolution #508: Use nuiton-utils 1.3 - Evolution #513: Introduce a ModelUIHelper to build model and display it in ui (deprecates ConfigUIBuilder) - Evolution #514: Remove jaxx-swing-action from part of build Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 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/OptionModel.java trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java trunk/pom.xml Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-04-14 12:17:45 UTC (rev 1836) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-04-14 12:29:18 UTC (rev 1837) @@ -56,10 +56,7 @@ import jaxx.runtime.decorator.DecoratorProvider; import jaxx.runtime.swing.AboutPanel; import jaxx.runtime.swing.ErrorDialogUI; -import jaxx.runtime.swing.editor.config.ConfigUI; -import jaxx.runtime.swing.editor.config.ConfigUIBuilder; -import jaxx.runtime.swing.editor.config.model.ConfigUIModel; -import jaxx.runtime.swing.editor.config.model.ConfigUIModelBuilder; +import jaxx.runtime.swing.editor.config.ConfigHelper; import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer; import org.apache.commons.logging.Log; @@ -306,51 +303,44 @@ DemoUI ui = getUI(context); DemoConfig config = ui.getConfig(); - ConfigUIModelBuilder builder = new ConfigUIModelBuilder(); + ConfigHelper helper = new ConfigHelper(config); - builder.createModel(config); - - - builder.registerCallBack("ui", + helper.registerCallBack("ui", n_("demo.action.reload.ui"), SwingUtil.createActionIcon("reload-ui"), reloadUICallback); - builder.registerCallBack("application", + helper.registerCallBack("application", n_("demo.action.reload.application"), SwingUtil.createActionIcon("reload-application"), reloadApplicationCallback); // categorie repertoires - builder.addCategory(n_("jaxxdemo.config.category.directories"), + helper.addCategory(n_("jaxxdemo.config.category.directories"), n_("jaxxdemo.config.category.directories.description")); - builder.addOption(DemoConfig.Option.CONFIG_FILE); + helper.addOption(DemoConfig.Option.CONFIG_FILE); // others - builder.addCategory(n_("jaxxdemo.config.category.other"), + helper.addCategory(n_("jaxxdemo.config.category.other"), n_("jaxxdemo.config.category.other.description")); - builder.addOption(DemoConfig.Option.FULL_SCREEN); - builder.setOptionPropertyName(DemoConfig.PROPERTY_FULLSCREEN); - builder.setOptionCallBack("ui"); + helper.addOption(DemoConfig.Option.FULL_SCREEN); + helper.setOptionPropertyName(DemoConfig.PROPERTY_FULLSCREEN); + helper.setOptionCallBack("ui"); - builder.addOption(DemoConfig.Option.FONT_SIZE); - builder.setOptionPropertyName(DemoConfig.PROPERTY_FONT_SIZE); - builder.setOptionCallBack("application"); + helper.addOption(DemoConfig.Option.FONT_SIZE); + helper.setOptionPropertyName(DemoConfig.PROPERTY_FONT_SIZE); + helper.setOptionCallBack("application"); - builder.addOption(DemoConfig.Option.LOCALE); - builder.setOptionPropertyName(DemoConfig.PROPERTY_LOCALE); - builder.setOptionCallBack("ui"); + helper.addOption(DemoConfig.Option.LOCALE); + helper.setOptionPropertyName(DemoConfig.PROPERTY_LOCALE); + helper.setOptionCallBack("ui"); - ConfigUIModel model = builder.flushModel(); - ConfigUI configUI = ConfigUIBuilder.newConfigUI( - context, - model, - "jaxxdemo.config.category.other"); + helper.buildUI(context, "jaxxdemo.config.category.other"); - ConfigUIBuilder.showConfigUI(configUI, ui, false); + helper.displayUI(ui, false); } // @Override 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-04-14 12:17:45 UTC (rev 1836) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.jaxx 2010-04-14 12:29:18 UTC (rev 1837) @@ -87,14 +87,17 @@ </script> <!-- le modele de l'ui --> - <ConfigUIModel id='model' initializer='getContextValue(ConfigUIModel.class)'/> + <ConfigUIModel id='model' + initializer='getContextValue(ConfigUIModel.class)'/> - <CategoryModel id='categoryModel' javaBean='getContextValue(CategoryModel.class)'/> + <CategoryModel id='categoryModel' + javaBean='getContextValue(CategoryModel.class)'/> <ConfigTableModel id='tableModel' constructorParams='categoryModel' onTableChanged='updateDescriptionText()'/> - <ListSelectionModel id='selectionModel' javaBean='new DefaultListSelectionModel()' + <ListSelectionModel id='selectionModel' + javaBean='new DefaultListSelectionModel()' onValueChanged='if (!event.getValueIsAdjusting()) { updateDescriptionText(); }'/> <!--<ColumnSelector id='columnSelector' />--> @@ -118,11 +121,10 @@ </JScrollPane> <!-- actions of the category --> - <JPanel layout='{new GridLayout(1,0)}' constraints='BorderLayout.SOUTH'> + <JPanel layout='{new GridLayout(1,0)}' + constraints='BorderLayout.SOUTH'> <JButton id='reset' onActionPerformed='model.reset()'/> <JButton id='save' onActionPerformed='model.saveModified()'/> - <!--<JButton id='reset' onActionPerformed='getContextValue(ConfigUIModel.class).reset()'/>--> - <!--<JButton id='save' onActionPerformed='getContextValue(ConfigUIModel.class).saveModified()'/>--> </JPanel> </JPanel> </JPanel> Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java 2010-04-14 12:29:18 UTC (rev 1837) @@ -0,0 +1,151 @@ +package jaxx.runtime.swing.editor.config; + +import jaxx.runtime.JAXXContext; +import jaxx.runtime.SwingUtil; +import jaxx.runtime.context.JAXXInitialContext; +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.table.TableCellEditor; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import static org.nuiton.i18n.I18n._; + +/** + * A helper to build a config ui. + * <p/> + * contains all states as method to build model, then ui and finally display it. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0.2 + */ +public class ConfigHelper { + + public static final Log log = LogFactory.getLog(ConfigUIBuilder.class); + + /** internal model builder */ + protected final ConfigUIModelBuilder modelBuilder; + + /** internal model after builder flush */ + protected ConfigUIModel model; + + protected ConfigUI ui; + + public ConfigHelper(ApplicationConfig config) { + modelBuilder = new ConfigUIModelBuilder(); + modelBuilder.createModel(config); + } + + public ConfigUIModel getModel() { + if (model == null) { + model = modelBuilder.flushModel(); + } + return model; + } + + public void addCategory(String categoryName, String categoryLabel) throws IllegalStateException, NullPointerException { + modelBuilder.addCategory(categoryName, categoryLabel); + } + + public void addOption(ApplicationConfig.OptionDef def) throws IllegalStateException, NullPointerException { + modelBuilder.addOption(def); + } + + public void addOption(ApplicationConfig.OptionDef def, String propertyName) throws IllegalStateException, NullPointerException { + modelBuilder.addOption(def, propertyName); + } + + public void setOptionPropertyName(String propertyName) throws IllegalStateException, NullPointerException { + modelBuilder.setOptionPropertyName(propertyName); + } + + public void setOptionEditor(TableCellEditor editor) throws IllegalStateException, NullPointerException { + modelBuilder.setOptionEditor(editor); + } + + public void registerCallBack(String name, String description, Icon icon, Runnable action) { + modelBuilder.registerCallBack(name, description, icon, action); + } + + public void setOptionCallBack(String name) { + modelBuilder.setOptionCallBack(name); + } + + public void setModel(ConfigUIModel model) throws IllegalStateException { + modelBuilder.setModel(model); + } + + public void setCategory(CategoryModel categoryModel) throws IllegalStateException { + modelBuilder.setCategory(categoryModel); + } + + public void setOption(OptionModel optionModel) throws IllegalStateException { + modelBuilder.setOption(optionModel); + } + + /** + * Construire l'ui de configuration (sous forme de panel) + * + * @param parentContext le context applicatif + * @param defaultCategory la categorie a selectionner + * @return l'ui instanciate + */ + public ConfigUI buildUI(JAXXContext parentContext, String defaultCategory) { + + ConfigUIModel model = getModel(); + + JAXXContext tx = new JAXXInitialContext().add(parentContext).add(model); + + ui = new ConfigUI(tx); + + ui.init(defaultCategory); + + return ui; + } + + public void displayUI(Frame parentUI, boolean undecorated) { + final JDialog f = new JDialog(parentUI, true); + f.setTitle(_("config.title")); + f.add(ui); + if (parentUI != null) { + f.setIconImage(parentUI.getIconImage()); + } + // pour savoir si l'ui est autonome + ui.getModel().setStandalone(ui == null); + + f.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + f.addWindowListener(new WindowAdapter() { + + @Override + public void windowClosing(WindowEvent e) { + ActionEvent myEvent = new ActionEvent(e.getSource(), 1, "quit"); + ui.getQuit().getAction().actionPerformed(myEvent); + } + }); + f.setUndecorated(undecorated); + JRootPane rootPane = f.getRootPane(); + rootPane.setDefaultButton(ui.getQuit()); + rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( + KeyStroke.getKeyStroke("ESCAPE"), "quit"); + rootPane.getActionMap().put("quit", ui.getQuit().getAction()); + f.pack(); + SwingUtil.center(ui, f); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + + f.setVisible(true); + } + }); + + } +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL 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-04-14 12:17:45 UTC (rev 1836) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx 2010-04-14 12:29:18 UTC (rev 1837) @@ -32,24 +32,10 @@ <script><![CDATA[ import jaxx.runtime.swing.editor.config.model.ConfigUIModel; -categories.setModel(new DefaultSingleSelectionModel() { +public void init(String defaultCategory) { + getHandler().initUI(defaultCategory); +} - private static final long serialVersionUID = 1L; - - @Override - public void setSelectedIndex(int index) { - // check if catgeory can be quit - boolean canContinue = !isSelected() || ConfigUIBuilder.canQuitCategory(ConfigUI.this); - if (canContinue) { - if (log.isDebugEnabled()) { - log.debug("new index : " + index); - } - // was authorized to continue - super.setSelectedIndex(index); - } - } -}); - public void destroy() { log.info("destroy ui " + getName()); JAXXUtil.destroy(this); @@ -61,25 +47,18 @@ super.finalize(); destroy(); } - -protected void changeCategory(ChangeEvent e) { - JPanel p = (JPanel) getCategories().getSelectedComponent(); - if (p == null) { - // pas de selection - return; - } - getModel().setCategory(p.getName()); - getCategories().invalidate(); -} ]]> </script> + <ConfigUIHandler id='handler' constructorParams='this'/> + <!-- le modele de l'ui --> - <ConfigUIModel id='model' initializer='getContextValue(ConfigUIModel.class)'/> + <ConfigUIModel id='model' + initializer='getContextValue(ConfigUIModel.class)'/> <!-- les differentes categories de la configuration --> <JTabbedPane id='categories' constraints='BorderLayout.CENTER' - onStateChanged='changeCategory(event)' /> + onStateChanged='getHandler().changeCategory(event)' /> <!-- pour quitter l'ui --> <JPanel layout='{new GridLayout(1,0)}' constraints='BorderLayout.SOUTH'> 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-04-14 12:17:45 UTC (rev 1836) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java 2010-04-14 12:29:18 UTC (rev 1837) @@ -31,7 +31,6 @@ 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; @@ -44,15 +43,14 @@ import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; /** * La classe pour construire l'ui * * @author tchemit <chemit@codelutin.com> + * @deprecated since 2.0.2, do not use any more, prefer use the {@link ConfigHelper} api. */ +@Deprecated public class ConfigUIBuilder { public static final Log log = LogFactory.getLog(ConfigUIBuilder.class); @@ -73,99 +71,98 @@ 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()) { + ui.init(defaultCategory); - private static final long serialVersionUID = 1L; - - @Override - public void actionPerformed(ActionEvent e) { - if (!canQuitCategory(ui)) { - return; - } - - final Window parentWindow = ui.getParentContainer(Window.class); - - if (!model.isSaved() || model.isStandalone()) { - - // just quit, no callBack can be apply here - - ui.destroy(); - - // close the configu ui - parentWindow.dispose(); - return; - } - - Map<CallBackEntry, List<OptionModel>> forSaved; - forSaved = model.getCallBacksForSaved(); - - if (forSaved.isEmpty()) { - // just quit, no callBack to call - - ui.destroy(); - - // close the configu ui - parentWindow.dispose(); - return; - } - - forSaved = model.getCallBacksForSaved(); - - // init callBackUI - - 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()) - ); - - lastUI.init(); - ui.setVisible(false); - parentWindow.remove(ui); - parentWindow.add(lastUI); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - parentWindow.validate(); - } - }); -// dialog.pack(); -// SwingUtil.center(parentWindow, lastUI); - -// lastUI.setVisible(true); - } - }; - 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); +// JButton quitButton = ui.getQuit(); +// +// // 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; +// } +// +// final Window parentWindow = ui.getParentContainer(Window.class); +// +// if (!model.isSaved() || model.isStandalone()) { +// +// // just quit, no callBack can be apply here +// +// ui.destroy(); +// +// // close the configu ui +// parentWindow.dispose(); +// return; +// } +// +// Map<CallBackEntry, List<OptionModel>> forSaved; +// forSaved = model.getCallBacksForSaved(); +// +// if (forSaved.isEmpty()) { +// // just quit, no callBack to call +// +// ui.destroy(); +// +// // close the configu ui +// parentWindow.dispose(); +// return; +// } +// +// forSaved = model.getCallBacksForSaved(); +// +// // init callBackUI +// +// 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()) +// ); +// +// lastUI.init(); +// ui.setVisible(false); +// parentWindow.remove(ui); +// parentWindow.add(lastUI); +// +// SwingUtilities.invokeLater(new Runnable() { +// +// @Override +// public void run() { +// parentWindow.validate(); +// } +// }); +// } +// }; +// 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/ConfigUIHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java 2010-04-14 12:29:18 UTC (rev 1837) @@ -0,0 +1,272 @@ +package jaxx.runtime.swing.editor.config; + +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; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static org.nuiton.i18n.I18n._; + +/** + * Handler of the {@link ConfigUI} ui. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.0.2 + */ +public class ConfigUIHandler { + + public static final Log log = LogFactory.getLog(ConfigUIHandler.class); + + public static final String CALLBACKS_WITH_OPTIONS = "callbacksWithOptions"; + + public static final String CALLBACKS = "callbacks"; + + private final ConfigUI ui; + + public ConfigUIHandler(ConfigUI ui) { + this.ui = ui; + } + + public void initUI(String defaultCategory) { + + ConfigUIModel model = ui.getModel(); + + JTabbedPane categories = ui.getCategories(); + + categories.setModel(new DefaultSingleSelectionModel() { + + private static final long serialVersionUID = 1L; + + @Override + public void setSelectedIndex(int index) { + // check if catgeory can be quit + boolean canContinue = !isSelected() || canQuitCategory(); + if (canContinue) { + if (log.isDebugEnabled()) { + log.debug("new index : " + index); + } + // was authorized to continue + super.setSelectedIndex(index); + } + } + }); + + JButton quitButton = ui.getQuit(); + + // prepare quit action + Action quitAction = createQuitAction(); + + 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); + categories.addTab(_(category), null, p, categoryLabel); + } + + model.setCategory(defaultCategory); + int categoryIndex = model.getCategoryIndex(defaultCategory); + if (log.isDebugEnabled()) { + log.debug("index of default category (" + defaultCategory + ") : " + + categoryIndex); + } + categories.setSelectedIndex(categoryIndex); + } + + public void changeCategory(ChangeEvent e) { + JPanel p = (JPanel) ui.getCategories().getSelectedComponent(); + if (p == null) { + // pas de selection + return; + } + ui.getModel().setCategory(p.getName()); + ui.getCategories().invalidate(); + } + + protected Action createQuitAction() { + + JButton button = ui.getQuit(); + + Action quitAction = + new AbstractAction(button.getText(), button.getIcon()) { + + private static final long serialVersionUID = 1L; + + @Override + public void actionPerformed(ActionEvent e) { + if (!canQuitCategory()) { + return; + } + + final Window parentWindow = ui.getParentContainer(Window.class); + + + ConfigUIModel model = ui.getModel(); + if (!model.isSaved() || model.isStandalone()) { + + // just quit, no callBack can be apply here + + ui.destroy(); + + // close the configu ui + parentWindow.dispose(); + return; + } + + Map<CallBackEntry, List<OptionModel>> forSaved; + forSaved = model.getCallBacksForSaved(); + + if (forSaved.isEmpty()) { + // just quit, no callBack to call + + ui.destroy(); + + // close the configu ui + parentWindow.dispose(); + return; + } + + forSaved = model.getCallBacksForSaved(); + + // init callBackUI + + 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()) + ); + + lastUI.init(); + ui.setVisible(false); + parentWindow.remove(ui); + parentWindow.add(lastUI); + + SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + parentWindow.validate(); + } + }); + } + }; + return quitAction; + } + + protected boolean canQuitCategory() { + boolean canContinue = true; + ConfigUIModel model = ui.getModel(); + CategoryModel categoryModel = model.getCategoryModel(); + String categoryName = _(categoryModel.getCategory()); + if (!categoryModel.isValid()) { + + // the category is not valid + // get all the invalid options + + StringBuilder buffer = new StringBuilder(); + buffer.append(_("config.message.quit.invalid.category", + categoryName)); + buffer.append('\n'); + for (OptionModel m : categoryModel.getInvalidOptions()) { + buffer.append("\n- ").append(m.getKey()); + } + buffer.append('\n'); + int reponse = askUser(_("config.title.need.confirm"), + buffer.toString(), + JOptionPane.ERROR_MESSAGE, + new Object[]{ + _("config.choice.continue"), + _("config.choice.cancel")}, + 0); + + switch (reponse) { + case JOptionPane.CLOSED_OPTION: + case 1: + canContinue = false; + break; + case 0: + if (categoryModel.isModified()) { + // wil reset category + model.reset(); + } + break; + } + } else if (categoryModel.isModified()) { + + // 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'); + for (OptionModel m : categoryModel.getModifiedOptions()) { + buffer.append("\n- ").append(m.getKey()); + } + buffer.append('\n'); + + int reponse = askUser(_("config.title.need.confirm"), buffer.toString(), + JOptionPane.WARNING_MESSAGE, + new Object[]{ + _("config.choice.save"), + _("config.choice.doNotSave"), + _("config.choice.cancel")}, + 0); + + switch (reponse) { + case JOptionPane.CLOSED_OPTION: + case 2: + canContinue = false; + break; + case 0: + // will save ui + model.saveModified(); + break; + case 1: + // wil reset ui + model.reset(); + break; + } + } + return canContinue; + } + + public int askUser(String title, + String message, + int typeMessage, + Object[] options, + int defaultOption) { + + int response = JOptionPane.showOptionDialog( + ui, + message, + title, + JOptionPane.DEFAULT_OPTION, + typeMessage, + null, + options, + options[defaultOption] + ); + + return response; + } +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.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-04-14 12:17:45 UTC (rev 1836) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModel.java 2010-04-14 12:29:18 UTC (rev 1837) @@ -155,8 +155,12 @@ callBacksManager.registerOption(name, option); } - public Map<CallBackEntry, List<OptionModel>> getCallBacksForSaved( - ) { + /** + * Obtain the dictionnary of callback for all to saved modified options. + * + * @return the dictonnary + */ + public Map<CallBackEntry, List<OptionModel>> getCallBacksForSaved() { return callBacksManager.getCallBacksForSaved(this); } 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-04-14 12:17:45 UTC (rev 1836) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/OptionModel.java 2010-04-14 12:29:18 UTC (rev 1837) @@ -112,6 +112,21 @@ return value; } + @Override + public void setDefaultValue(String defaultValue) { + def.setDefaultValue(defaultValue); + } + + @Override + public void setTransient(boolean isTransient) { + def.setTransient(isTransient); + } + + @Override + public void setFinal(boolean isFinal) { + def.setFinal(isFinal); + } + public void setValue(Object value) { this.value = value; } Modified: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java =================================================================== --- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java 2010-04-14 12:17:45 UTC (rev 1836) +++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java 2010-04-14 12:29:18 UTC (rev 1837) @@ -171,10 +171,10 @@ FONT_SIZE("ui." + PROPERTY_FONT_SIZE, _("jaxxdemo.config.ui." + PROPERTY_FONT_SIZE), "10f", Float.class, false, false); public final String key; public final String description; - public final String defaultValue; + public String defaultValue; public final Class<?> type; - public final boolean _transient; - public final boolean _final; + public boolean _transient; + public boolean _final; Option(String key, String description, String defaultValue, Class<?> type, boolean _transient, boolean _final) { this.key = key; @@ -191,6 +191,21 @@ } @Override + public void setDefaultValue(String defaultValue) { + this.defaultValue=defaultValue; + } + + @Override + public void setTransient(boolean _transient) { + this._transient = _transient; + } + + @Override + public void setFinal(boolean _final) { + this._final= _final; + } + + @Override public boolean isTransient() { return _transient; } @@ -214,5 +229,7 @@ public Class<?> getType() { return type; } + + } } \ No newline at end of file Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-04-14 12:17:45 UTC (rev 1836) +++ trunk/pom.xml 2010-04-14 12:29:18 UTC (rev 1837) @@ -50,7 +50,7 @@ <module>jaxx-compiler</module> - <module>jaxx-swing-action</module> + <!--module>jaxx-swing-action</module--> <module>maven-jaxx-plugin</module> <module>jaxx-widgets</module>
participants (1)
-
tchemit@users.nuiton.org