Author: tchemit Date: 2013-05-30 14:36:46 +0200 (Thu, 30 May 2013) New Revision: 2679 Url: http://nuiton.org/projects/jaxx/repository/revisions/2679 Log: fixes #2710: Should be able to specify the file where to save Modified: trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigUIHelper.java trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/model/ConfigUIModel.java trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/model/ConfigUIModelBuilder.java trunk/jaxx-config/src/main/resources/i18n/jaxx-config_en_GB.properties trunk/jaxx-config/src/main/resources/i18n/jaxx-config_es_ES.properties trunk/jaxx-config/src/main/resources/i18n/jaxx-config_fr_FR.properties Modified: trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigUIHelper.java =================================================================== --- trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigUIHelper.java 2013-05-27 17:55:19 UTC (rev 2678) +++ trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/ConfigUIHelper.java 2013-05-30 12:36:46 UTC (rev 2679) @@ -41,6 +41,7 @@ import javax.swing.Icon; import javax.swing.table.TableCellEditor; import java.awt.Frame; +import java.io.File; import javax.swing.table.TableCellRenderer; /** @@ -68,6 +69,16 @@ modelBuilder.createModel(config); } + public ConfigUIHelper(Supplier<ApplicationConfig> config, File configFile) { + modelBuilder = new ConfigUIModelBuilder(); + modelBuilder.createModel(config, configFile); + } + + public ConfigUIHelper(ApplicationConfig config, File configFile) { + modelBuilder = new ConfigUIModelBuilder(); + modelBuilder.createModel(config, configFile); + } + public ConfigUIHelper(ApplicationConfig config) { modelBuilder = new ConfigUIModelBuilder(); modelBuilder.createModel(config); Modified: trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/model/ConfigUIModel.java =================================================================== --- trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/model/ConfigUIModel.java 2013-05-27 17:55:19 UTC (rev 2678) +++ trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/model/ConfigUIModel.java 2013-05-30 12:36:46 UTC (rev 2679) @@ -29,11 +29,15 @@ import com.google.common.collect.Lists; import jaxx.runtime.JAXXUtil; import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.util.config.ApplicationConfig; import javax.swing.Icon; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.io.File; +import java.io.IOException; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Iterator; @@ -53,11 +57,20 @@ */ public class ConfigUIModel implements Iterable<CategoryModel> { + /** Logger. */ + private static final Log log = LogFactory.getLog(ConfigUIModel.class); + public static final String CATEGORY_MODEL_PROPERTY_NAME = "categoryModel"; /** le dictionnaire des options disponibles par categorie */ protected final Map<String, CategoryModel> categories; + /** + * Le fichier où sauvegarder la configuration. + * @since 2.5.21 + */ + protected final File configFile; + /** La configuration de l'application */ protected final Object configBean; @@ -102,13 +115,26 @@ this(config, config.get()); } + public ConfigUIModel(Supplier<ApplicationConfig> config, File configFile) { + this(config, config.get(), configFile); + } + public ConfigUIModel(ApplicationConfig applicationConfig) { this(applicationConfig, applicationConfig); } + public ConfigUIModel(ApplicationConfig applicationConfig, File configFile) { + this(applicationConfig, applicationConfig, configFile); + } + public ConfigUIModel(Object configBean, ApplicationConfig applicationConfig) { + this(configBean, applicationConfig, applicationConfig.getUserConfigFile()); + } + + public ConfigUIModel(Object configBean, ApplicationConfig applicationConfig, File configFile) { this.configBean = configBean; this.applicationConfig = applicationConfig; + this.configFile = configFile; categories = new LinkedHashMap<String, CategoryModel>(); callBacksManager = new CallBacksManager(); pcs = new PropertyChangeSupport(this); @@ -289,7 +315,17 @@ setSaved(true); // save config - applicationConfig.saveForUser(transients.toArray(new String[transients.size()])); + // Ano +// applicationConfig.saveForUser(transients.toArray(new String[transients.size()])); + try { + applicationConfig.save(configFile, false, transients.toArray(new String[transients.size()])); + } catch (IOException eee) { + if (log.isWarnEnabled()) { + log.warn(_("config.error.applicationconfig.save", configFile), + eee); + } + } + // notify data has changed categoryModel.firePropertyChange( CategoryModel.MODIFIED_PROPERTY_NAME, Modified: trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/model/ConfigUIModelBuilder.java =================================================================== --- trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/model/ConfigUIModelBuilder.java 2013-05-27 17:55:19 UTC (rev 2678) +++ trunk/jaxx-config/src/main/java/jaxx/runtime/swing/config/model/ConfigUIModelBuilder.java 2013-05-30 12:36:46 UTC (rev 2679) @@ -34,6 +34,7 @@ import javax.swing.Icon; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; +import java.io.File; /** * A builder of {@link ConfigUIModel} @@ -82,6 +83,29 @@ /** * Create a new model and set it as current model. * + * @param config the configuration used in model + * @param configFile configuration file where to save (can not be null) + * @return the builder + * @throws IllegalStateException if there is already a current model + * @throws NullPointerException if config or configFile is {@code null} + * @since 2.5.21 + */ + public ConfigUIModelBuilder createModel(Supplier<ApplicationConfig> config, + File configFile) + throws IllegalStateException, NullPointerException { + checkNoCurrent(model, "model"); + checkNotNull(config, "createModel", "config"); + checkNotNull(configFile, "createModel", "configFile"); + model = new ConfigUIModel(config, configFile); + if (log.isDebugEnabled()) { + log.debug("model created : " + model); + } + return this; + } + + /** + * Create a new model and set it as current model. + * * @param config the configuration used in model * @return the builder * @throws IllegalStateException if there is already a current model @@ -92,6 +116,7 @@ checkNoCurrent(model, "model"); checkNotNull(config, "createModel", "config"); model = new ConfigUIModel(config); + if (log.isDebugEnabled()) { log.debug("model created : " + model); } @@ -99,6 +124,30 @@ } /** + * Create a new model and set it as current model. + * + * @param config the configuration used in model + * @param configFile configuration file where to save (can not be null) + * @return the builder + * @throws IllegalStateException if there is already a current model + * @throws NullPointerException if config or configFile is {@code null} + * @since 2.5.21 + */ + public ConfigUIModelBuilder createModel(ApplicationConfig config, + File configFile) + throws IllegalStateException, NullPointerException { + checkNoCurrent(model, "model"); + checkNotNull(config, "createModel", "config"); + checkNotNull(configFile, "createModel", "configFile"); + model = new ConfigUIModel(config, configFile); + + if (log.isDebugEnabled()) { + log.debug("model created : " + model); + } + return this; + } + + /** * Add a new category, and set it as current. * <p/> * <b>Note:</b> As side effets, if a previous category, then store it to Modified: trunk/jaxx-config/src/main/resources/i18n/jaxx-config_en_GB.properties =================================================================== --- trunk/jaxx-config/src/main/resources/i18n/jaxx-config_en_GB.properties 2013-05-27 17:55:19 UTC (rev 2678) +++ trunk/jaxx-config/src/main/resources/i18n/jaxx-config_en_GB.properties 2013-05-30 12:36:46 UTC (rev 2679) @@ -12,6 +12,7 @@ config.defaultValue.tip=Default value of the option config.description=Description config.detected.callBack=Detected actions +config.error.applicationconfig.save=Can't save config in file %s config.error.category.already.exists=category with name '%1$s' does already exist\! config.error.category.not.found=category with name '%1$s' does not exist\! config.key=Key Modified: trunk/jaxx-config/src/main/resources/i18n/jaxx-config_es_ES.properties =================================================================== --- trunk/jaxx-config/src/main/resources/i18n/jaxx-config_es_ES.properties 2013-05-27 17:55:19 UTC (rev 2678) +++ trunk/jaxx-config/src/main/resources/i18n/jaxx-config_es_ES.properties 2013-05-30 12:36:46 UTC (rev 2679) @@ -31,3 +31,4 @@ config.unvalid=Opción no valida (valor original \: %1$s, tipo requerido \: %2$s) config.value=Valor config.value.tip=Valor de la opción +nuitonutil.error.applicationconfig.save= Modified: trunk/jaxx-config/src/main/resources/i18n/jaxx-config_fr_FR.properties =================================================================== --- trunk/jaxx-config/src/main/resources/i18n/jaxx-config_fr_FR.properties 2013-05-27 17:55:19 UTC (rev 2678) +++ trunk/jaxx-config/src/main/resources/i18n/jaxx-config_fr_FR.properties 2013-05-30 12:36:46 UTC (rev 2679) @@ -12,6 +12,7 @@ config.defaultValue.tip=Valeur par défaut de l'option config.description=Description config.detected.callBack=Actions détectées pour les options modifiées +config.error.applicationconfig.save=Impossible de sauvegarder le fichier de configuration dans %s config.error.category.already.exists=La catégorie de nom '%1$s' existe déjà\! config.error.category.not.found=La catégorie de nom '%1$s' n'existe pas\! config.key=Clef