Author: tchemit Date: 2010-04-15 09:39:30 +0200 (Thu, 15 Apr 2010) New Revision: 1845 Log: rename ConfigHelper to ConfigUIHelper + remove old code Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHelper.java Removed: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBacksManager.java Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-04-14 18:38:22 UTC (rev 1844) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-04-15 07:39:30 UTC (rev 1845) @@ -56,7 +56,7 @@ import jaxx.runtime.decorator.DecoratorProvider; import jaxx.runtime.swing.AboutPanel; import jaxx.runtime.swing.ErrorDialogUI; -import jaxx.runtime.swing.editor.config.ConfigHelper; +import jaxx.runtime.swing.editor.config.ConfigUIHelper; import jaxx.runtime.swing.navigation.tree.NavigationTreeNode; import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer; import org.apache.commons.logging.Log; @@ -303,7 +303,7 @@ DemoUI ui = getUI(context); DemoConfig config = ui.getConfig(); - ConfigHelper helper = new ConfigHelper(config); + ConfigUIHelper helper = new ConfigUIHelper(config); helper.registerCallBack("ui", n_("demo.action.reload.ui"), Deleted: 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 2010-04-14 18:38:22 UTC (rev 1844) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java 2010-04-15 07:39:30 UTC (rev 1845) @@ -1,179 +0,0 @@ -/* - * #%L - * JAXX :: Widgets - * - * $Author$ - * $LastChangedDate$ - * $LastChangedRevision$ - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package jaxx.runtime.swing.editor.config; - -import jaxx.runtime.JAXXContext; -import jaxx.runtime.SwingUtil; -import jaxx.runtime.context.JAXXInitialContext; -import jaxx.runtime.swing.editor.config.model.*; -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(ConfigHelper.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); - } - - public void setFinalizer(CallBackFinalizer finalizer) { - modelBuilder.setFinalizer(finalizer); - } - - /** - * 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) { - ui.getHandler().displayUI(parentUI,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); -// } -// }); - } -} 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 18:38:22 UTC (rev 1844) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java 2010-04-15 07:39:30 UTC (rev 1845) @@ -38,7 +38,7 @@ * 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 since 2.0.2, do not use any more, prefer use the {@link ConfigUIHelper} api. */ @Deprecated public class ConfigUIBuilder { Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java 2010-04-14 18:38:22 UTC (rev 1844) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHandler.java 2010-04-15 07:39:30 UTC (rev 1845) @@ -160,71 +160,72 @@ JButton button = ui.getQuit(); - Action quitAction = - new AbstractAction(button.getText(), button.getIcon()) { + Action quitAction = new AbstractAction(button.getText(), + button.getIcon()) { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - @Override - public void actionPerformed(ActionEvent e) { - if (!canQuitCategory()) { - return; - } + @Override + public void actionPerformed(ActionEvent e) { + if (!canQuitCategory()) { + return; + } - final Window parentWindow = ui.getParentContainer(Window.class); + final Window parentWindow = ui.getParentContainer(Window.class); - ConfigUIModel model = ui.getModel(); - if (!model.isSaved() || model.isStandalone()) { + ConfigUIModel model = ui.getModel(); + if (!model.isSaved() || model.isStandalone()) { - // just quit, no callBack can be apply here + // just quit, no callBack can be apply here - ui.destroy(); + ui.destroy(); - // close the configu ui - parentWindow.dispose(); - return; - } + // close the configu ui + parentWindow.dispose(); + return; + } - CallBackMap forSaved = model.getCallBacksForSaved(); + CallBackMap forSaved = model.getCallBacksForSaved(); - if (forSaved.isEmpty()) { - // just quit, no callBack to call + if (forSaved.isEmpty()) { + // just quit, no callBack to call - ui.destroy(); + ui.destroy(); - // close the configu ui - parentWindow.dispose(); - return; - } + // close the configu ui + parentWindow.dispose(); + return; + } - forSaved = model.getCallBacksForSaved(); + forSaved = model.getCallBacksForSaved(); - // init callBackUI + // 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()) - ); + JAXXInitialContext context = new JAXXInitialContext(). + add("parent", parentWindow). + add(ui). + add(CALLBACKS_WITH_OPTIONS, forSaved). + add(CALLBACKS, + new ArrayList<CallBackEntry>(forSaved.keySet())). + add(new ConfigCallBackUIHandler()); + + ConfigCallBackUI lastUI = new ConfigCallBackUI(context); - lastUI.init(); - ui.setVisible(false); - parentWindow.remove(ui); - parentWindow.add(lastUI); + lastUI.init(); + ui.setVisible(false); + parentWindow.remove(ui); + parentWindow.add(lastUI); - SwingUtilities.invokeLater(new Runnable() { + SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - parentWindow.validate(); - } - }); + @Override + public void run() { + parentWindow.validate(); } - }; + }); + } + }; return quitAction; } @@ -278,7 +279,8 @@ } buffer.append('\n'); - int reponse = askUser(_("config.title.need.confirm"), buffer.toString(), + int reponse = askUser(_("config.title.need.confirm"), + buffer.toString(), JOptionPane.WARNING_MESSAGE, new Object[]{ _("config.choice.save"), Copied: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHelper.java (from rev 1844, trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigHelper.java) =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHelper.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHelper.java 2010-04-15 07:39:30 UTC (rev 1845) @@ -0,0 +1,151 @@ +/* + * #%L + * JAXX :: Widgets + * + * $Author$ + * $LastChangedDate$ + * $LastChangedRevision$ + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package jaxx.runtime.swing.editor.config; + +import jaxx.runtime.JAXXContext; +import jaxx.runtime.context.JAXXInitialContext; +import jaxx.runtime.swing.editor.config.model.*; +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.*; + +/** + * 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 ConfigUIHelper { + + public static final Log log = LogFactory.getLog(ConfigUIHelper.class); + + /** internal model builder */ + protected final ConfigUIModelBuilder modelBuilder; + + /** internal model after builder flush */ + protected ConfigUIModel model; + + protected ConfigUI ui; + + public ConfigUIHelper(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); + } + + public void setFinalizer(CallBackFinalizer finalizer) { + modelBuilder.setFinalizer(finalizer); + } + + /** + * 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) { + ui.getHandler().displayUI(parentUI, undecorated); + } +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIHelper.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Modified: 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 2010-04-14 18:38:22 UTC (rev 1844) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CallBacksManager.java 2010-04-15 07:39:30 UTC (rev 1845) @@ -139,29 +139,6 @@ CallBackMap result = getCallBacks(model,true,false); return result; -// result = new CallBackMap(); -// -// 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(); -// } -// -// CallBackFinalizer finalizer = getFinalizer(); -// if (finalizer != null) { -// result = finalizer.finalize(result); -// } -// return result; } /** @@ -174,22 +151,6 @@ CallBackMap result = getCallBacks(category,true,false); return result; -// result = new CallBackMap(); -// -// 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; } /** @@ -246,7 +207,6 @@ for (OptionModel optionModel : category) { if (modified && optionModel.isModified() || saved && optionModel.isSaved()) { -// if (optionModel.isSaved()) { CallBackEntry callBackEntry = getCallBack(optionModel); if (callBackEntry != null) { List<OptionModel> models = result.get(callBackEntry);