Author: tchemit Date: 2008-02-20 19:18:44 +0000 (Wed, 20 Feb 2008) New Revision: 1153 Added: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/commandline/configs/SimExplorerConfig.java Removed: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerConfig.java Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorer.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java Log: move to commandline package Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorer.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorer.java 2008-02-20 19:17:59 UTC (rev 1152) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorer.java 2008-02-20 19:18:44 UTC (rev 1153) @@ -23,6 +23,7 @@ import fr.cemagref.simexplorer.is.ui.swing.ui.SimExplorerMainUI; import fr.cemagref.simexplorer.is.ui.swing.ui.SimExplorerTab; import fr.cemagref.simexplorer.is.ui.swing.ui.util.ErrorDialog; +import fr.cemagref.simexplorer.is.ui.swing.commandline.configs.SimExplorerConfig; import org.codelutin.i18n.I18n; import org.codelutin.option.ui.ConfigTableModel; import org.codelutin.option.ui.ConfigUI; Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerConfig.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerConfig.java 2008-02-20 19:17:59 UTC (rev 1152) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerConfig.java 2008-02-20 19:18:44 UTC (rev 1153) @@ -1,133 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* 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 Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.ui.swing; - -import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; -import fr.cemagref.simexplorer.is.ui.swing.commandline.configs.SimExplorerAbstractConfigMain; -import fr.cemagref.simexplorer.is.ui.swing.commandline.options.SimExplorerOptionConfig; -import fr.cemagref.simexplorer.is.ui.swing.commandline.options.SimExplorerOptionConfigFile; -import fr.cemagref.simexplorer.is.ui.swing.commandline.SimExplorerOptionParser; -import org.codelutin.i18n.CountryEnum; -import org.codelutin.i18n.I18n; -import static org.codelutin.i18n.I18n._; -import org.codelutin.i18n.LanguageEnum; -import org.codelutin.option.ConfigPropertyKey; -import org.codelutin.option.OptionParser; - -import java.io.File; -import java.io.IOException; - -/** - * L'implantation concrete de la config principale - * - * @author chemit - */ -public class SimExplorerConfig extends SimExplorerAbstractConfigMain { - - public SimExplorerConfig() { - super(); - String home = System.getProperty("user.home"); - if (home == null) { - // this is a serious fatal error - throw new SimExplorerRuntimeException("simexplorer.error.user.home"); - } - doInit(); - } - - public void init() throws IOException { - log.info("start for category [" + category + "] -------------------------"); - - SimExplorerOptionParser parser = SimExplorer.getContext().getParser(); - initConfigFile(parser); - log.info("config file : " + getSource()); - // chargement des valeurs par défaut - loadFromDefaultValue(); - // après le chargement des valeurs par défaut - // la configuration n'est pas modifiée - clearModified(); - // surcharge à partir du fichier de configuration de l'utilisateur - loadFromSource(); - // surcharge à partir des propriétés système - loadFromSystem(); - // surcharge à partir des propriétés de la jvm - loadFromJvm(); - // surcharge à partir de l'option config de la ligne de commande - loadFromOptions(parser); - clearModified(); - for (String s : this.toString().split("\n")) { - log.debug(s); - } - log.info("end for category [" + category + "] ---------------------------"); - } - - protected void initConfigFile(OptionParser parser) { - File file; - if (parser.isOptionEnabled(SimExplorerOptionParser.CONFIG_FILE_OPTION_KEY)) { - // surcharge config file - SimExplorerOptionConfigFile option = SimExplorerOptionParser.CONFIG_FILE_OPTION_KEY.getOptions().get(0); - - file = option.getConfigFile(); - } else { - String home = System.getProperty("user.home", ""); - File root = new File(home); - file = new File(root, SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY.getDefaultValue().getName()); - if (!file.exists()) { - SimExplorer.getContext().setFirstLaunch(true); - try { - file.createNewFile(); - } catch (IOException e) { - throw new SimExplorerRuntimeException(e); - } - } - } - if (containsKey(SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY)) { - setProperty(SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY, file); - } - setSource(file); - } - - public void initI18n() { - I18n.initISO88591(getUserLanguage().name(), getUserCountry().name()); - } - - protected void loadFromOptions(SimExplorerOptionParser parser) { - if (!parser.isOptionEnabled(SimExplorerOptionParser.CONFIG_OPTION_KEY)) { - return; - } - // surcharge config file - for (SimExplorerOptionConfig option : SimExplorerOptionParser.CONFIG_OPTION_KEY.getOptions()) { - if (getCategory().equals(SimExplorerOptionParser.MAIN_CONFIG_KEY.getCategory())) { - ConfigPropertyKey<?> propKey = getPropertyKey(option.getKey()); - if (propKey == null) { - // fatal error , could not found a matching configuration property - throw new SimExplorerRuntimeException(_("simexplorer.error.unfound.config.property", category, option.getKey())); - } - Object oldVal = propKey.getCurrentValue(); - setProperty(propKey, option.getValue()); - Object newVal = propKey.getCurrentValue(); - log.info(_("simexplorer.change.config.property", category, propKey, oldVal, newVal)); - } - } - } - - public void setI18n(LanguageEnum language, CountryEnum country) { - setUserLanguage(language); - setUserCountry(country); - } -} \ No newline at end of file Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java 2008-02-20 19:17:59 UTC (rev 1152) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java 2008-02-20 19:18:44 UTC (rev 1153) @@ -21,6 +21,7 @@ import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; import fr.cemagref.simexplorer.is.ui.swing.commandline.actions.SimExplorerCommonActions; import fr.cemagref.simexplorer.is.ui.swing.commandline.SimExplorerOptionParser; +import fr.cemagref.simexplorer.is.ui.swing.commandline.configs.SimExplorerConfig; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codelutin.option.ParserException; Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/commandline/configs/SimExplorerConfig.java (from rev 1150, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerConfig.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/commandline/configs/SimExplorerConfig.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/commandline/configs/SimExplorerConfig.java 2008-02-20 19:18:44 UTC (rev 1153) @@ -0,0 +1,134 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, +* Tony Chemit, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* 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 Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.ui.swing.commandline.configs; + +import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; +import fr.cemagref.simexplorer.is.ui.swing.commandline.configs.SimExplorerAbstractConfigMain; +import fr.cemagref.simexplorer.is.ui.swing.commandline.options.SimExplorerOptionConfig; +import fr.cemagref.simexplorer.is.ui.swing.commandline.options.SimExplorerOptionConfigFile; +import fr.cemagref.simexplorer.is.ui.swing.commandline.SimExplorerOptionParser; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorer; +import org.codelutin.i18n.CountryEnum; +import org.codelutin.i18n.I18n; +import static org.codelutin.i18n.I18n._; +import org.codelutin.i18n.LanguageEnum; +import org.codelutin.option.ConfigPropertyKey; +import org.codelutin.option.OptionParser; + +import java.io.File; +import java.io.IOException; + +/** + * L'implantation concrete de la config principale + * + * @author chemit + */ +public class SimExplorerConfig extends SimExplorerAbstractConfigMain { + + public SimExplorerConfig() { + super(); + String home = System.getProperty("user.home"); + if (home == null) { + // this is a serious fatal error + throw new SimExplorerRuntimeException("simexplorer.error.user.home"); + } + doInit(); + } + + public void init() throws IOException { + log.info("start for category [" + category + "] -------------------------"); + + SimExplorerOptionParser parser = SimExplorer.getContext().getParser(); + initConfigFile(parser); + log.info("config file : " + getSource()); + // chargement des valeurs par défaut + loadFromDefaultValue(); + // après le chargement des valeurs par défaut + // la configuration n'est pas modifiée + clearModified(); + // surcharge à partir du fichier de configuration de l'utilisateur + loadFromSource(); + // surcharge à partir des propriétés système + loadFromSystem(); + // surcharge à partir des propriétés de la jvm + loadFromJvm(); + // surcharge à partir de l'option config de la ligne de commande + loadFromOptions(parser); + clearModified(); + for (String s : this.toString().split("\n")) { + log.debug(s); + } + log.info("end for category [" + category + "] ---------------------------"); + } + + protected void initConfigFile(OptionParser parser) { + File file; + if (parser.isOptionEnabled(SimExplorerOptionParser.CONFIG_FILE_OPTION_KEY)) { + // surcharge config file + SimExplorerOptionConfigFile option = SimExplorerOptionParser.CONFIG_FILE_OPTION_KEY.getOptions().get(0); + + file = option.getConfigFile(); + } else { + String home = System.getProperty("user.home", ""); + File root = new File(home); + file = new File(root, SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY.getDefaultValue().getName()); + if (!file.exists()) { + SimExplorer.getContext().setFirstLaunch(true); + try { + file.createNewFile(); + } catch (IOException e) { + throw new SimExplorerRuntimeException(e); + } + } + } + if (containsKey(SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY)) { + setProperty(SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY, file); + } + setSource(file); + } + + public void initI18n() { + I18n.initISO88591(getUserLanguage().name(), getUserCountry().name()); + } + + protected void loadFromOptions(SimExplorerOptionParser parser) { + if (!parser.isOptionEnabled(SimExplorerOptionParser.CONFIG_OPTION_KEY)) { + return; + } + // surcharge config file + for (SimExplorerOptionConfig option : SimExplorerOptionParser.CONFIG_OPTION_KEY.getOptions()) { + if (getCategory().equals(SimExplorerOptionParser.MAIN_CONFIG_KEY.getCategory())) { + ConfigPropertyKey<?> propKey = getPropertyKey(option.getKey()); + if (propKey == null) { + // fatal error , could not found a matching configuration property + throw new SimExplorerRuntimeException(_("simexplorer.error.unfound.config.property", category, option.getKey())); + } + Object oldVal = propKey.getCurrentValue(); + setProperty(propKey, option.getValue()); + Object newVal = propKey.getCurrentValue(); + log.info(_("simexplorer.change.config.property", category, propKey, oldVal, newVal)); + } + } + } + + public void setI18n(LanguageEnum language, CountryEnum country) { + setUserLanguage(language); + setUserCountry(country); + } +} \ No newline at end of file