r1694 - in trunk/jaxx-widgets: . src src/main/java/jaxx/runtime/swing src/main/java/jaxx/runtime/swing/editor/config src/main/java/jaxx/runtime/swing/editor/config/model src/main/resources/i18n src/test src/test/java src/test/java/jaxx src/test/java/jaxx/runtime src/test/java/jaxx/runtime/swing src/test/java/jaxx/runtime/swing/editor src/test/java/jaxx/runtime/swing/editor/config src/test/java/jaxx/runtime/swing/editor/config/model src/test/resources
Author: tchemit Date: 2009-12-22 18:34:34 +0100 (Tue, 22 Dec 2009) New Revision: 1694 Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java trunk/jaxx-widgets/src/test/ trunk/jaxx-widgets/src/test/java/ trunk/jaxx-widgets/src/test/java/jaxx/ trunk/jaxx-widgets/src/test/java/jaxx/runtime/ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilderTest.java trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java trunk/jaxx-widgets/src/test/resources/ trunk/jaxx-widgets/src/test/resources/log4j.properties Modified: trunk/jaxx-widgets/pom.xml trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizor.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigTableEditor.java 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/CategoryModel.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/main/resources/i18n/jaxx-widgets-en_GB.properties trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-fr_FR.properties Log: add ConfigModelBuilder api + reload ui and application call back in ConfigUI + fix FontSizor issues Modified: trunk/jaxx-widgets/pom.xml =================================================================== --- trunk/jaxx-widgets/pom.xml 2009-12-22 07:45:46 UTC (rev 1693) +++ trunk/jaxx-widgets/pom.xml 2009-12-22 17:34:34 UTC (rev 1694) @@ -41,6 +41,11 @@ <artifactId>commons-io</artifactId> </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + </dependencies> <!-- ************************************************************* --> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizor.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizor.jaxx 2009-12-22 07:45:46 UTC (rev 1693) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/FontSizor.jaxx 2009-12-22 17:34:34 UTC (rev 1694) @@ -39,7 +39,9 @@ public static final String BINDING_DEFAULT_FONT_SIZE_CALL_BACK = "defaultFontSize.callBack"; public void init() { - setFontSize(defaultFontSize); + if (fontSize == null) { + setFontSize(defaultFontSize); + } } boolean updateDefaultSizeEnabled(Float fontSize, Float defaultFontSize, boolean enabled) { @@ -69,7 +71,7 @@ setFontSize(defaultFontSize); } }); - applyDataBinding(BINDING_DEFAULT_FONT_SIZE_CALL_BACK); + //applyDataBinding(BINDING_DEFAULT_FONT_SIZE_CALL_BACK); } ]]> </script> 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 2009-12-22 07:45:46 UTC (rev 1693) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCategoryUI.jaxx 2009-12-22 17:34:34 UTC (rev 1694) @@ -24,7 +24,7 @@ <JPanel layout='{new BorderLayout()}'> <style source='ConfigCategoryUI.css'/> - + <script><![CDATA[ import jaxx.runtime.swing.editor.config.model.*; import jaxx.runtime.swing.editor.ColumnSelector; @@ -82,6 +82,9 @@ ]]> </script> + <!-- le modele de l'ui --> + <ConfigUIModel id='model' initializer='getContextValue(ConfigUIModel.class)'/> + <CategoryModel id='categoryModel' javaBean='getContextValue(CategoryModel.class)'/> <ConfigTableModel id='tableModel' constructorParams='categoryModel' @@ -112,8 +115,10 @@ <!-- actions of the category --> <JPanel layout='{new GridLayout(1,0)}' constraints='BorderLayout.SOUTH'> - <JButton id='reset' onActionPerformed='getContextValue(ConfigUIModel.class).reset()'/> - <JButton id='save' onActionPerformed='getContextValue(ConfigUIModel.class).saveModified()'/> + <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> Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigTableEditor.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigTableEditor.java 2009-12-22 07:45:46 UTC (rev 1693) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigTableEditor.java 2009-12-22 17:34:34 UTC (rev 1694) @@ -20,6 +20,7 @@ package jaxx.runtime.swing.editor.config; import jaxx.runtime.swing.editor.config.model.ConfigTableModel; + import javax.swing.DefaultCellEditor; import javax.swing.JTable; import javax.swing.event.CellEditorListener; @@ -27,9 +28,11 @@ import java.awt.Component; import java.util.EventObject; import java.util.Locale; + import jaxx.runtime.swing.editor.ClassCellEditor; import jaxx.runtime.swing.editor.EnumEditor; import jaxx.runtime.swing.editor.LocaleEditor; +import jaxx.runtime.swing.editor.config.model.OptionModel; /** * L'éditeur des valeurs des propriétés d'une configuration @@ -47,7 +50,7 @@ @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - delegate = findDelegate(table, model.getEntry(row).getType()); + delegate = findDelegate(table, model.getEntry(row)); return delegate.getTableCellEditorComponent(table, value, isSelected, row, column); } @@ -92,9 +95,11 @@ } } - protected TableCellEditor findDelegate(JTable table, Class<?> type) { + protected TableCellEditor findDelegate(JTable table, OptionModel option) { + Class<?> type = option.getType(); TableCellEditor editor = table.getDefaultEditor(type); TableCellEditor defaultEditor = table.getDefaultEditor(Object.class); + //TODO always Search from option.getEditor() and store editor as cache if (editor == defaultEditor) { // find not a specialized editor for the type if (type.isEnum()) { 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 2009-12-22 07:45:46 UTC (rev 1693) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx 2009-12-22 17:34:34 UTC (rev 1694) @@ -59,7 +59,7 @@ </script> <!-- le modele de l'ui --> - <ConfigUIModel id='model' javaBean='getContextValue(ConfigUIModel.class)'/> + <ConfigUIModel id='model' initializer='getContextValue(ConfigUIModel.class)'/> <!-- les differentes categories de la configuration --> <JTabbedPane id='categories' constraints='BorderLayout.CENTER' 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 2009-12-22 07:45:46 UTC (rev 1693) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java 2009-12-22 17:34:34 UTC (rev 1694) @@ -20,24 +20,9 @@ */ package jaxx.runtime.swing.editor.config; -import java.awt.Frame; -import java.awt.Window; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.List; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JOptionPane; -import javax.swing.JRootPane; -import javax.swing.KeyStroke; import jaxx.runtime.JAXXContext; +import jaxx.runtime.SwingUtil; import jaxx.runtime.context.JAXXInitialContext; -import jaxx.runtime.SwingUtil; - import jaxx.runtime.swing.editor.config.model.CategoryModel; import jaxx.runtime.swing.editor.config.model.ConfigUIModel; import jaxx.runtime.swing.editor.config.model.OptionModel; @@ -45,8 +30,18 @@ import org.apache.commons.logging.LogFactory; import static org.nuiton.i18n.I18n._; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + /** * La classe pour construire l'ui + * * @author chemit */ public class ConfigUIBuilder { @@ -56,12 +51,12 @@ /** * Construire l'ui de configuration (sous forme de panel) * - * @param parentContext le context applicatif - * @param model le modele de l'ui de configuration + * @param parentContext le context applicatif + * @param model le modele de l'ui de configuration * @param defaultCategory la categorie a selectionner * @return l'ui instanciate */ - public static ConfigUI newConfigUI(jaxx.runtime.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); @@ -78,28 +73,119 @@ 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"); - for (OptionModel option : savedOptions) { + 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()); } -// askUser(ui, -// _("config.title.will.reload.application"), buffer.toString(), -// JOptionPane.INFORMATION_MESSAGE, -// new Object[]{ -// _("config.choice.ok")}, -// 0); + + 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(); @@ -127,9 +213,9 @@ /** * 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 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 */ public static void showConfigUI(final ConfigUI configUI, Frame ui, boolean undecorated) { @@ -149,9 +235,6 @@ public void windowClosing(WindowEvent e) { ActionEvent myEvent = new ActionEvent(e.getSource(), 1, "quit"); configUI.getQuit().getAction().actionPerformed(myEvent); -// if (canQuitCategory(configUI)) { -// e.getWindow().dispose(); -// } } }); f.setUndecorated(undecorated); @@ -185,8 +268,8 @@ buffer.toString(), JOptionPane.ERROR_MESSAGE, new Object[]{ - _("config.choice.continue"), - _("config.choice.cancel")}, + _("config.choice.continue"), + _("config.choice.cancel")}, 0); switch (reponse) { @@ -216,9 +299,9 @@ _("config.title.need.confirm"), buffer.toString(), JOptionPane.WARNING_MESSAGE, new Object[]{ - _("config.choice.save"), - _("config.choice.doNotSave"), - _("config.choice.cancel")}, + _("config.choice.save"), + _("config.choice.doNotSave"), + _("config.choice.cancel")}, 0); switch (reponse) { @@ -242,7 +325,17 @@ public static int askUser(ConfigUI parent, String title, String message, int typeMessage, Object[] options, int defaultOption) { - int response = JOptionPane.showOptionDialog(parent, message, title, JOptionPane.DEFAULT_OPTION, typeMessage, null, options, options[defaultOption]); + int response = JOptionPane.showOptionDialog( + parent, + message, + title, + JOptionPane.DEFAULT_OPTION, + typeMessage, + null, + options, + options[defaultOption] + ); + return response; } } Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CategoryModel.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CategoryModel.java 2009-12-22 07:45:46 UTC (rev 1693) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CategoryModel.java 2009-12-22 17:34:34 UTC (rev 1694) @@ -49,6 +49,18 @@ /** suport of modification */ protected PropertyChangeSupport pcs = new PropertyChangeSupport(this); + protected CategoryModel(String category, String categoryLabel) { + super(); + this.category = category; + this.categoryLabel = categoryLabel; + this.entries = new ArrayList<OptionModel>(); + } + + protected void addOption(OptionModel option) { + entries.add(option); + } + + @Deprecated public CategoryModel(String category, String categoryLabel, OptionModel[] entries) { super(); this.category = category; 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 2009-12-22 07:45:46 UTC (rev 1693) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModel.java 2009-12-22 17:34:34 UTC (rev 1694) @@ -20,37 +20,41 @@ */ package jaxx.runtime.swing.editor.config.model; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import org.apache.commons.beanutils.PropertyUtils; +import static org.nuiton.i18n.I18n._; import org.nuiton.util.ApplicationConfig; import org.nuiton.util.ApplicationConfig.OptionDef; -import static org.nuiton.i18n.I18n._; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.*; + /** * Le modele de l'ui des preferences. + * <p/> + * Ce modele contient les catégories des options. * - * Ce modele contient les catégories des options. - * * @author chemit */ public class ConfigUIModel implements Iterable<CategoryModel> { public static final String CATEGORY_MODEL_PROPERTY_NAME = "categoryModel"; - /** le dictionnaire des options disponibles par categorie */ + /** + * le dictionnaire des options disponibles par categorie + */ protected final Map<String, CategoryModel> categories; - /** La configuration de l'application */ + /** + * La configuration de l'application + */ protected final ApplicationConfig config; - /** la cateogrie en cours d'utilisation */ + /** + * la cateogrie en cours d'utilisation + */ protected CategoryModel categoryModel; /** * un drapeau pour savoir si la configuration a été modifiée au moins une * fois. - * + * <p/> * On utilise ce drapeau lors de la sortie pour verifier s'il faut ou non * redemarer l'application (si non en mode standalone) */ @@ -58,12 +62,23 @@ /** * un drapeau pour savoir si l'ui de configuration a été lancée en mode * standalone ou pas. - * + * <p/> * Si pas lancée en mode standalone, et si la confi a été sauvé on vérifie * s'il ne faut pas relancer l'application. */ protected boolean standalone; - /** suport of modification */ + /** + * call back when reload ui is necessary + */ + protected Runnable reloadUICallback; + /** + * call back when reload application is necessary + */ + protected Runnable reloadApplicationCallback; + + /** + * suport of modification + */ protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); public ConfigUIModel(ApplicationConfig config) { @@ -74,10 +89,12 @@ /** * Ajoute une categorie dans le modele. * - * @param category l'id de la categorie (la clef de traduction du nom 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 + * @param keys les options de la categorie + * @deprecated since 2.0.0 prefer use the {@link #addCategory(CategoryModel)} */ + @Deprecated public void addCategory(String category, String categoryLabel, OptionDef... keys) { if (categories.containsKey(category)) { throw new IllegalArgumentException(_("config.error.category.already.exists", category)); @@ -94,8 +111,20 @@ } /** + * Ajoute une categorie dans le modele. + * + * @param category la categorie a ajouter au modèle. + */ + public void addCategory(CategoryModel category) { + if (categories.containsKey(category.getCategory())) { + throw new IllegalArgumentException(_("config.error.category.already.exists", category.getCategory())); + } + categories.put(category.getCategory(), category); + } + + /** * Change la categorie en cours d'édition. - * + * * @param category l'id de la categorie courante */ public void setCategory(String category) { @@ -139,25 +168,53 @@ this.standalone = standalone; } + public Runnable getReloadApplicationCallback() { + return reloadApplicationCallback; + } + + public Runnable getReloadUICallback() { + return reloadUICallback; + } + public void saveModified() { // compute transients keys (to never be saved) List<String> transients = new ArrayList<String>(); - for (OptionModel option : categoryModel) { - if (option.isModified()) { - Object value = option.getValue(); - //TODO TC-20090245 : should try to seek for a mutator, since - // 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); - // this is the new original value - option.initValue(value); + //TODO TC-20091222 : will be in ApplicationConfig, for the moment catch in your config it... +// config.setAdjusting(true); + config.setOption("adjusting", "true"); + + try { + for (OptionModel option : categoryModel) { + if (option.isModified()) { + Object value = option.getValue(); + //TODO TC-20090245 : should try to seek for a mutator, since + if (option.getPropertyName() != null) { + // this is a javaBean option + try { + PropertyUtils.setProperty(config, option.getPropertyName(), value); + } catch (Exception 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()); + } + // l'option a été sauvegardée, on la marque + option.setSaved(true); + // this is the new original value + option.initValue(value); + } + if (option.isTransient()) { + transients.add(option.getKey()); + } } - if (option.isTransient()) { - transients.add(option.getKey()); - } + } finally { + //TODO TC-20091222 : will be in ApplicationConfig, for the moment catch in your config it... +// config.setAdjusting(false); + config.setOption("adjusting", "false"); } + setSaved(true); // save config config.saveForUser(transients.toArray(new String[transients.size()])); @@ -223,4 +280,16 @@ public synchronized PropertyChangeListener[] getPropertyChangeListeners() { return pcs.getPropertyChangeListeners(); } + + protected void setReloadApplicationCallback(Runnable reloadApplicationCallback) { + this.reloadApplicationCallback = reloadApplicationCallback; + } + + protected void setReloadUICallback(Runnable reloadUICallback) { + this.reloadUICallback = reloadUICallback; + } + + protected ApplicationConfig getConfig() { + return config; + } } Added: 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 (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java 2009-12-22 17:34:34 UTC (rev 1694) @@ -0,0 +1,305 @@ +package 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.table.TableCellEditor; + +/** + * A builder of {@link jaxx.runtime.swing.editor.config.model.ConfigUIModel} + * Created: 22 déc. 2009 + * + * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author: tchemit $ + * @since 2.0.0 + */ +public class ConfigUIModelBuilder { + /** + * Logger + */ + private static final Log log = LogFactory.getLog(ConfigUIModelBuilder.class); + + /** + * current model used + */ + ConfigUIModel model; + /** + * current category used + */ + CategoryModel category; + /** + * current option used + */ + OptionModel option; + + /** + * Create a new model and set it as current model. + * + * @param config the configuration used in model + * @throws IllegalStateException if there is already a current model + * @throws NullPointerException if config is {@code null} + */ + public void createModel(ApplicationConfig config) throws IllegalStateException, NullPointerException { + checkNoCurrent(model, "model"); + checkNotNull(config, "createModel", "config"); + model = new ConfigUIModel(config); + if (log.isDebugEnabled()) { + log.debug("model created : " + model); + } + } + + /** + * Set the {@code reloadApplicationCallback} of the current model. + * + * @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) + */ + public void setReloadApplicationCallback(Runnable callback) throws IllegalStateException, NullPointerException { + checkCurrent(model, "model"); + checkNotNull(callback, "setReloadApplicationCallback", "callback"); + model.setReloadApplicationCallback(callback); + } + + /** + * Set the {@code reloadUICallback} of the current model. + * + * @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) + */ + public void setReloadUICallback(Runnable callback) { + checkCurrent(model, "model"); + checkNotNull(callback, "setReloadUICallback", "callback"); + model.setReloadUICallback(callback); + } + + /** + * 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. + * + * @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 { + checkCurrent(model, "model"); + checkNotNull(categoryName, "addCategory", "categoryName"); + checkNotNull(categoryLabel, "addCategory", "categoryLabel"); + flushCategory(); + category = new CategoryModel(categoryName, categoryLabel); + if (log.isDebugEnabled()) { + log.debug("category created : " + category); + } + } + + /** + * 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. + * + * @param def the def ot the new option + * @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 { + checkCurrent(model, "model"); + checkCurrent(category, "category"); + checkNotNull(def, "addOption", "def"); + flushOption(); + Object value = model.getConfig().getOption(def); + option = new OptionModel(def, value); + if (log.isDebugEnabled()) { + log.debug("option created : " + option); + } + } + + /** + * 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. + * <p/> + * <b>Note:</b> This method is a short-cut for + * {@link #addOption(org.nuiton.util.ApplicationConfig.OptionDef)} then + * {@link #setOptionPropertyName(String)}. + * + * @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 NullPointerException if any of parameter is {@code null} + */ + public void addOption(ApplicationConfig.OptionDef def, String propertyName) throws IllegalStateException, NullPointerException { + addOption(def); + checkNotNull(propertyName, "setOptionPropertyName", "propertyName"); + option.setPropertyName(propertyName); + } + + /** + * Set the propertyName on the current option. + * + * @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) + */ + public void setOptionPropertyName(String propertyName) throws IllegalStateException, NullPointerException { + checkCurrent(option, "option"); + checkNotNull(propertyName, "setOptionPropertyName", "propertyName"); + option.setPropertyName(propertyName); + } + + /** + * Set the editor on the current option. + * + * @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) + */ + public void setOptionEditor(TableCellEditor editor) throws IllegalStateException, NullPointerException { + checkCurrent(option, "option"); + checkNotNull(editor, "setOptionEditor", "editor"); + option.setEditor(editor); + } + + /** + * 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) + */ + public void setOptionNeedReloadUI(boolean needReload) throws IllegalStateException { + checkCurrent(option, "option"); + option.setNeedReloadUI(needReload); + } + + /** + * Set the needReloadApplication 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) + */ + public void setOptionNeedReloadApplication(boolean needReload) throws IllegalStateException { + checkCurrent(option, "option"); + option.setNeedReloadApplication(needReload); + } + + /** + * Flush the model and return it. + * <p/> + * <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 + * @throws IllegalStateException if there is not a current model set. + */ + public ConfigUIModel flushModel() throws IllegalStateException { + checkCurrent(model, "model"); + flushCategory(); + ConfigUIModel result = model; + model = null; + return result; + } + + /** + * Set the given model as current model. + * <p/> + * <b>Note:</b> As side effets, il will clean current category and option. + * + * @param model the model to use + * @throws IllegalStateException if there is already a current model + */ + public void setModel(ConfigUIModel model) throws IllegalStateException { + checkNoCurrent(model, "model"); + this.model = model; + if (log.isDebugEnabled()) { + log.debug("new current model : " + this.model); + } + category = null; + option = null; + } + + /** + * Set the given category as current category. + * <p/> + * <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 + */ + public void setCategory(CategoryModel categoryModel) throws IllegalStateException { + checkCurrent(model, "model"); + checkNoCurrent(category, "category"); + category = categoryModel; + if (log.isDebugEnabled()) { + log.debug("new current category : " + this.category); + } + option = null; + } + + /** + * 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 + */ + public void setOption(OptionModel optionModel) throws IllegalStateException { + checkCurrent(model, "model"); + checkCurrent(category, "category"); + checkNoCurrent(option, "option"); + option = optionModel; + if (log.isDebugEnabled()) { + log.debug("new current option : " + this.option); + } + } + + protected CategoryModel flushCategory() { + CategoryModel result = category; + if (category != null) { + flushOption(); + // add the previous category to the model + model.addCategory(category); + category = null; + } + return result; + } + + protected OptionModel flushOption() { + OptionModel result = option; + if (option != null) { + // add the previous option to the category + category.addOption(option); + option = null; + } + return result; + } + + protected void checkCurrent(Object o, String type) { + if (o == null) { + throw new IllegalStateException("no current " + type + "!"); + } + } + + protected void checkNoCurrent(Object o, String type) { + if (o != null) { + 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 + "!"); + } + } + +} Property changes on: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL 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 2009-12-22 07:45:46 UTC (rev 1693) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/OptionModel.java 2009-12-22 17:34:34 UTC (rev 1694) @@ -22,6 +22,8 @@ import org.nuiton.util.ApplicationConfig.OptionDef; +import javax.swing.table.TableCellEditor; + /** * le modele d'une option de la configuration a editer. * @@ -29,16 +31,42 @@ */ public class OptionModel implements OptionDef { - /** la definition de l'option ( venant de la config) */ + /** + * la definition de l'option ( venant de la config) + */ protected final OptionDef def; - /** un drapeau pour savoir si l'option est valide (n'est pas utilisé actuellement) */ + /** + * un drapeau pour savoir si l'option est valide (n'est pas utilisé actuellement) + */ protected boolean valid = true; - /** un drapeau pour savoir si l'option a été sauvée */ + /** + * un drapeau pour savoir si l'option a été sauvée + */ protected boolean saved = false; - /** la valeur non modifié de l'option */ + /** + * un drapeau pour savoir si le changement de l'option nécessite un redémarrage de l'ui. + */ + protected boolean needReloadUI = false; + /** + * un drapeau pour savoir si le changement de l'option nécessite un redémarrage de l'application. + */ + protected boolean needReloadApplication = false; + /** + * la valeur non modifié de l'option + */ protected Object originalValue; - /** la valeur actuelle de l'option (peut être la valeur orignal si non modifée)*/ + /** + * la valeur actuelle de l'option (peut être la valeur orignal si non modifée) + */ protected Object value; + /** + * le nom de la propriété javaBean (peut etre null, si option sans support javaBean) + */ + protected String propertyName; + /** + * l'editeur utilise pour modifier graphiquement l'option + */ + protected TableCellEditor editor; protected OptionModel(OptionDef def, Object value) { this.def = def; @@ -75,6 +103,14 @@ return def.isFinal(); } + public boolean isNeedReloadUI() { + return needReloadUI; + } + + public boolean isNeedReloadApplication() { + return needReloadApplication; + } + public Object getOriginalValue() { return originalValue; } @@ -106,9 +142,33 @@ public void setSaved(boolean saved) { this.saved = saved; } - + public void initValue(Object originalValue) { this.originalValue = originalValue; this.value = originalValue; } + + public String getPropertyName() { + return propertyName; + } + + public TableCellEditor getEditor() { + return editor; + } + + protected void setEditor(TableCellEditor editor) { + this.editor = editor; + } + + protected void setNeedReloadUI(boolean needReloadUI) { + this.needReloadUI = needReloadUI; + } + + protected void setNeedReloadApplication(boolean needReloadApplication) { + this.needReloadApplication = needReloadApplication; + } + + protected void setPropertyName(String propertyName) { + this.propertyName = propertyName; + } } 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 2009-12-22 07:45:46 UTC (rev 1693) +++ trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-en_GB.properties 2009-12-22 17:34:34 UTC (rev 1694) @@ -9,6 +9,8 @@ config.action.reset.tip=Cancel the modifications for the category config.action.save=Save config.action.save.tip=Save the modifications for the category +config.category.needReloadApplication= +config.category.needReloadUI= config.category.saved=The category '%1$s' was modified \: config.choice.cancel=Cancel config.choice.continue=Continue @@ -24,6 +26,8 @@ config.key.tip=Key of the option 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= +config.model.needReloadUI= config.modified=Option was modified (previous value \: %1$s) config.no.option.selected=< No selected option > config.option.final=This option can not be modified @@ -32,6 +36,7 @@ config.title=Preferences config.title.need.confirm=A confirmation is required config.title.will.reload.application=The application need to be restarted +config.title.will.reload.ui=The graphical interface must be relauched config.unmodifiable=Can not be modified config.unvalid=Option is not valid \! (previous value \: %1$s, required type \: %2$s) config.value=Value @@ -46,9 +51,9 @@ errorUI.action.close=Close errorUI.message=An error wad detected... errorUI.title=Error... -fontsize.action.default.tip= -fontsize.action.down.tip= -fontsize.action.up.tip= +fontsize.action.default.tip=Restore default font size +fontsize.action.down.tip=Decrease font size +fontsize.action.up.tip=Increase font size hidor.hideTip=Hide hidor.showTip=Show i18neditor.empty.locales=< No locale to select > @@ -74,5 +79,4 @@ numbereditor.clearAll=C numbereditor.clearOne=CE numbereditor.toggleSign=+/- -size\ \:\ = timeeditor.H=H 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 2009-12-22 07:45:46 UTC (rev 1693) +++ trunk/jaxx-widgets/src/main/resources/i18n/jaxx-widgets-fr_FR.properties 2009-12-22 17:34:34 UTC (rev 1694) @@ -9,6 +9,8 @@ config.action.reset.tip=Annuler les modifications de cette cat\u00E9gorie config.action.save=Enregistrer config.action.save.tip=Sauver les modifications de cette cat\u00E9gorie +config.category.needReloadApplication=Cat\u00E9gorie '%1$s' \: +config.category.needReloadUI=Cat\u00E9gorie '%1$s' \: config.category.saved=La cat\u00E9gorie '%1$s' a \u00E9t\u00E9 modifi\u00E9e \: config.choice.cancel=Annuler config.choice.continue=Continuer @@ -24,6 +26,8 @@ config.key.tip=Clef de l'option 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\u00E9s qui n\u00E9cessitent le red\u00E9marrage de l'application.\n +config.model.needReloadUI=Des options ont \u00E9t\u00E9 modifi\u00E9s qui n\u00E9cessitent le red\u00E9marrage de l'interface graphique.\n config.modified=Option modifi\u00E9e (valeur originale \: %1$s) config.no.option.selected=< Pas d'option s\u00E9lectionn\u00E9e > config.option.final=Option non modifiable @@ -32,6 +36,7 @@ config.title=Pr\u00E9f\u00E9rences config.title.need.confirm=Une confirmation de votre part est requise... config.title.will.reload.application=L'application doit \u00EAtre red\u00E9marrer... +config.title.will.reload.ui=L'interface graphique doit \u00EAtre relancer... config.unmodifiable=Ne peut pas \u00EAtre modifi\u00E9 config.unvalid=Option non valide (valeur originale \: %1$s, type requis \: %2$s) config.value=Valeur @@ -46,9 +51,9 @@ errorUI.action.close=Fermer errorUI.message=Une erreur est survenue \! errorUI.title=Erreur... -fontsize.action.default.tip= -fontsize.action.down.tip= -fontsize.action.up.tip= +fontsize.action.default.tip=Retour sur la taille par d\u00E9faut +fontsize.action.down.tip=Diminuer la taille de la police +fontsize.action.up.tip=Augmenter la taille de la police hidor.hideTip=Cacher hidor.showTip=Voir i18neditor.empty.locales=< Aucune locale \u00E0 s\u00E9lectionner > @@ -74,5 +79,4 @@ numbereditor.clearAll=C numbereditor.clearOne=CE numbereditor.toggleSign=+/- -size\ \:\ = timeeditor.H=H Added: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilderTest.java =================================================================== --- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilderTest.java (rev 0) +++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilderTest.java 2009-12-22 17:34:34 UTC (rev 1694) @@ -0,0 +1,343 @@ +package jaxx.runtime.swing.editor.config.model; + +import jaxx.runtime.swing.editor.MyDefaultCellEditor; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.swing.table.TableCellEditor; + +/** + * Created: 22 déc. 2009 + * + * @author Tony Chemit <chemit@codelutin.com> Copyright Code Lutin + * @version $Revision$ + * <p/> + * Mise a jour: $Date$ par : + * $Author: tchemit $ + * @since 2.0.0 + */ +public class ConfigUIModelBuilderTest { + + ConfigUIModelBuilder builder; + + static MyConfig config; + + @BeforeClass + public static void beforeeClass() { + config = new MyConfig(); + } + + + @Before + public void setup() { + builder = new ConfigUIModelBuilder(); + } + + @Test(expected = NullPointerException.class) + public void testCreateModelLimitCase0() throws Exception { + builder.createModel(null); + } + + @Test(expected = IllegalStateException.class) + public void testFlushModelLimitCase0() throws Exception { + builder.flushModel(); + } + + @Test + public void testCreateModel() throws Exception { + builder.createModel(config); + ConfigUIModel configModel = builder.flushModel(); + Assert.assertNotNull(configModel); + Assert.assertNotNull(configModel.getConfig()); + + } + + @Test(expected = IllegalStateException.class) + public void testSetReloadApplicationCallbackLimitCase0() throws Exception { + builder.setReloadApplicationCallback(null); + } + + @Test(expected = NullPointerException.class) + public void testSetReloadApplicationCallbackLimitCase1() throws Exception { + builder.createModel(config); + builder.setReloadApplicationCallback(null); + } + + @Test + public void testSetReloadApplicationCallback() throws Exception { + builder.createModel(config); + Runnable callback = new Runnable() { + + @Override + public void run() { + } + }; + builder.setReloadApplicationCallback(callback); + ConfigUIModel configModel = builder.flushModel(); + Assert.assertNotNull(configModel); + Assert.assertNotNull(configModel.getConfig()); + Assert.assertEquals(callback, configModel.getReloadApplicationCallback()); + } + + @Test(expected = IllegalStateException.class) + public void testSetReloadUICallbackLimitCase0() throws Exception { + builder.setReloadUICallback(null); + } + + @Test(expected = NullPointerException.class) + public void testSetReloadUICallbackLimitCase1() throws Exception { + builder.createModel(config); + builder.setReloadUICallback(null); + } + + @Test + public void testSetReloadUICallback() throws Exception { + builder.createModel(config); + Runnable callback = new Runnable() { + + @Override + public void run() { + } + }; + builder.setReloadUICallback(callback); + ConfigUIModel configModel = builder.flushModel(); + Assert.assertNotNull(configModel); + Assert.assertNotNull(configModel.getConfig()); + Assert.assertEquals(callback, configModel.getReloadUICallback()); + } + + @Test(expected = IllegalStateException.class) + public void testAddCategoryLimitCase0() throws Exception { + builder.addCategory(null, null); + } + + @Test(expected = NullPointerException.class) + public void testAddCategoryLimitCase1() throws Exception { + builder.createModel(config); + builder.addCategory(null, null); + } + + @Test(expected = NullPointerException.class) + public void testAddCategoryLimitCase2() throws Exception { + builder.createModel(config); + builder.addCategory("", null); + } + + @Test + public void testAddCategory() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + CategoryModel categoryModel = builder.flushCategory(); + Assert.assertNotNull(categoryModel); + Assert.assertEquals("cat0", categoryModel.category); + Assert.assertEquals("cat0 label", categoryModel.categoryLabel); + Assert.assertEquals(0, categoryModel.entries.size()); + + } + + @Test(expected = IllegalStateException.class) + public void testAddOptionLimitCase0() throws Exception { + builder.addOption(null); + } + + @Test(expected = IllegalStateException.class) + public void testAddOptionLimitCase1() throws Exception { + builder.createModel(config); + builder.addOption(null); + } + + @Test(expected = NullPointerException.class) + public void testAddOptionLimitCase2() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.addOption(null); + } + + @Test + public void testAddOption() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.addOption(MyConfig.Option.LOCALE); + OptionModel optionModel = builder.flushOption(); + Assert.assertNotNull(optionModel); + Assert.assertEquals(MyConfig.Option.LOCALE, optionModel.def); + + CategoryModel categoryModel = builder.flushCategory(); + Assert.assertNotNull(categoryModel); + Assert.assertEquals("cat0", categoryModel.category); + Assert.assertEquals("cat0 label", categoryModel.categoryLabel); + Assert.assertEquals(1, categoryModel.entries.size()); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionPropertyNameLimitCase0() throws Exception { + builder.setOptionPropertyName(null); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionPropertyNameLimitCase1() throws Exception { + builder.createModel(config); + builder.setOptionPropertyName(null); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionPropertyNameLimitCase2() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.setOptionPropertyName(null); + } + + + @Test(expected = NullPointerException.class) + public void testSetOptionPropertyNameLimitCase3() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.addOption(MyConfig.Option.LOCALE); + builder.setOptionPropertyName(null); + } + + @Test + public void testSetOptionPropertyName() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.addOption(MyConfig.Option.LOCALE); + builder.setOptionPropertyName(MyConfig.PROPERTY_LOCALE); + OptionModel optionModel = builder.flushOption(); + Assert.assertNotNull(optionModel); + Assert.assertEquals(MyConfig.Option.LOCALE, optionModel.def); + Assert.assertEquals(MyConfig.PROPERTY_LOCALE, optionModel.propertyName); + Assert.assertEquals(false, optionModel.needReloadUI); + Assert.assertNull(optionModel.editor); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionEditorLimitCase0() throws Exception { + builder.setOptionEditor(null); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionEditorLimitCase1() throws Exception { + builder.createModel(config); + builder.setOptionEditor(null); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionEditorLimitCase2() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.setOptionEditor(null); + } + + + @Test(expected = NullPointerException.class) + public void testSetOptionEditorLimitCase3() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.addOption(MyConfig.Option.LOCALE); + builder.setOptionEditor(null); + } + + @Test + public void testSetOptionEditor() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.addOption(MyConfig.Option.LOCALE); + TableCellEditor cellEditor = MyDefaultCellEditor.newBooleanEditor(); + builder.setOptionEditor(cellEditor); + OptionModel optionModel = builder.flushOption(); + Assert.assertNotNull(optionModel); + Assert.assertEquals(MyConfig.Option.LOCALE, optionModel.def); + Assert.assertNull(optionModel.propertyName); + Assert.assertEquals(false, optionModel.needReloadUI); + Assert.assertEquals(cellEditor, optionModel.editor); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionNeedReloadUILimitCase0() throws Exception { + builder.setOptionNeedReloadUI(false); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionNeedReloadUILimitCase1() throws Exception { + builder.createModel(config); + builder.setOptionNeedReloadUI(true); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionNeedReloadUILimitCase2() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.setOptionNeedReloadUI(false); + } + + @Test + public void testSetOptionNeedReloadUI() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.addOption(MyConfig.Option.LOCALE); + builder.setOptionNeedReloadUI(true); + OptionModel optionModel = builder.flushOption(); + Assert.assertNotNull(optionModel); + Assert.assertEquals(MyConfig.Option.LOCALE, optionModel.def); + Assert.assertEquals(true, optionModel.needReloadUI); + Assert.assertNull(optionModel.propertyName); + Assert.assertNull(optionModel.editor); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionNeedReloadApplicationLimitCase0() throws Exception { + builder.setOptionNeedReloadApplication(false); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionNeedReloadApplicationLimitCase1() throws Exception { + builder.createModel(config); + builder.setOptionNeedReloadApplication(true); + } + + @Test(expected = IllegalStateException.class) + public void testSetOptionNeedReloadApplicationLimitCase2() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.setOptionNeedReloadApplication(false); + } + + @Test + public void testSetOptionNeedReloadApplication() throws Exception { + builder.createModel(config); + builder.addCategory("cat0", "cat0 label"); + builder.addOption(MyConfig.Option.LOCALE); + builder.setOptionNeedReloadApplication(true); + OptionModel optionModel = builder.flushOption(); + Assert.assertNotNull(optionModel); + Assert.assertEquals(MyConfig.Option.LOCALE, optionModel.def); + Assert.assertEquals(true, optionModel.needReloadApplication); + Assert.assertNull(optionModel.propertyName); + Assert.assertNull(optionModel.editor); + } + + + @Test + public void testFlushModel() throws Exception { + builder.createModel(config); + ConfigUIModel configModel = builder.flushModel(); + Assert.assertNotNull(configModel); + Assert.assertNull(builder.model); + } + + @Test + public void testSetModel() throws Exception { + + } + + @Test + public void testSetCategory() throws Exception { + } + + @Test + public void testSetOption() throws Exception { + } + +} Property changes on: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilderTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL Copied: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java (from rev 1693, trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java) =================================================================== --- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java (rev 0) +++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/MyConfig.java 2009-12-22 17:34:34 UTC (rev 1694) @@ -0,0 +1,208 @@ +/* + * *##% + * JAXX Demo + * 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>. + * ##%* + */ +package jaxx.runtime.swing.editor.config.model; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import static org.nuiton.i18n.I18n._; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Date; +import java.util.Locale; + +/** + * @author chemit + * @since 2.0.0 + */ +public class MyConfig extends org.nuiton.util.ApplicationConfig { + + /** + * to use log facility, just put in your code: log.info(\"...\"); + */ + static private Log log = LogFactory.getLog(MyConfig.class); + + public static final String PROPERTY_FULLSCREEN = "fullscreen"; + public static final String PROPERTY_LOCALE = "locale"; + public static final String PROPERTY_FONT_SIZE = "fontSize"; + public static final String PROPERTY_ADJUSTING = "adjusting"; + + /** + * 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() { + + @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(); + } + }; + + @Override + public void saveForUser(String... excludeKeys) { + // never save anything :) + } + + public MyConfig() { + + setConfigFileName(Option.CONFIG_FILE.defaultValue); + + // chargement de la configuration interne + + for (Option o : Option.values()) { + setDefaultOption(o.key, o.defaultValue); + } + + adjusting = true; + addPropertyChangeListener(PROPERTY_FULLSCREEN, saveAction); + addPropertyChangeListener(PROPERTY_FONT_SIZE, saveAction); + addPropertyChangeListener(PROPERTY_LOCALE, saveAction); + adjusting = false; + } + + @Override + public void setOption(String key, String value) { + if (key.equals(PROPERTY_ADJUSTING)) { + setAdjusting(Boolean.valueOf(value)); + return; + } + super.setOption(key, value); + } + + + public boolean isFullScreen() { + Boolean result = getOptionAsBoolean(Option.FULL_SCREEN.key); + return result != null && result; + } + + public Locale getLocale() { + Locale result = getOption(Locale.class, Option.LOCALE.key); + return result; + } + + public Float getFontSize() { + Float result = getOption(Float.class, Option.FONT_SIZE.key); + return result; + } + + public void setFullscreen(boolean fullscreen) { + Object oldValue = null; + setOption(Option.FULL_SCREEN.key, fullscreen + ""); +// saveForUser(); + firePropertyChange(PROPERTY_FULLSCREEN, oldValue, fullscreen); + } + + public void setLocale(Locale newLocale) { + setOption(Option.LOCALE.key, newLocale.toString()); +// saveForUser(); + firePropertyChange(PROPERTY_LOCALE, null, newLocale); + } + + public void setFontSize(Float newFontSize) { + Float oldValue = getFontSize(); + if (log.isDebugEnabled()) { + log.debug("changing font-size to " + newFontSize); + } + setOption(Option.FONT_SIZE.key, newFontSize.toString()); +// saveForUser(); + firePropertyChange(PROPERTY_FONT_SIZE, oldValue, newFontSize); + } + + public boolean isAdjusting() { + return adjusting; + } + + public void setAdjusting(boolean adjusting) { + if (log.isDebugEnabled()) { + log.debug("changing adjusting to " + adjusting); + } + boolean oldValue = this.adjusting; + this.adjusting = adjusting; + firePropertyChange(PROPERTY_ADJUSTING, oldValue, adjusting); + } + + ////////////////////////////////////////////////// + // Toutes les options disponibles + ////////////////////////////////////////////////// + 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); + public final String key; + public final String description; + public final String defaultValue; + public final Class<?> type; + public final boolean _transient; + public final boolean _final; + + private Option(String key, String description, String defaultValue, Class<?> type, boolean _transient, boolean _final) { + this.key = key; + this.description = description; + this.defaultValue = defaultValue; + this.type = type; + this._final = _final; + this._transient = _transient; + } + + @Override + public boolean isFinal() { + return _final; + } + + @Override + public boolean isTransient() { + return _transient; + } + + @Override + public String getDefaultValue() { + return defaultValue; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getKey() { + return key; + } + + @Override + public Class<?> getType() { + return type; + } + } +} \ No newline at end of file Added: trunk/jaxx-widgets/src/test/resources/log4j.properties =================================================================== --- trunk/jaxx-widgets/src/test/resources/log4j.properties (rev 0) +++ trunk/jaxx-widgets/src/test/resources/log4j.properties 2009-12-22 17:34:34 UTC (rev 1694) @@ -0,0 +1,10 @@ +# Global logging configuration +log4j.rootLogger=ERROR, stdout +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n + +log4j.logger.jaxx.swing=INFO +#log4j.logger.jaxx.runtime.swing.editor.config.model.ConfigUIModelBuilder=DEBUG +log4j.logger.org.nuiton=WARN
participants (1)
-
tchemit@users.nuiton.org