Author: tchemit Date: 2008-01-20 14:01:09 +0000 (Sun, 20 Jan 2008) New Revision: 272 Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorer.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerConfig.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerException.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerMainUI.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerRuntimeException.java Removed: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorer.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerConfig.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerContext.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerException.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerMainUI.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerRuntimeException.java Modified: trunk/simexplorer-is-swing/go.sh trunk/simexplorer-is-swing/profiles.xml Log: on d?\195?\169place toutes les classes vers ui.swing Modified: trunk/simexplorer-is-swing/go.sh =================================================================== --- trunk/simexplorer-is-swing/go.sh 2008-01-20 13:57:39 UTC (rev 271) +++ trunk/simexplorer-is-swing/go.sh 2008-01-20 14:01:09 UTC (rev 272) @@ -38,7 +38,7 @@ VER=$(xmlstarlet sel -N "p=http://maven.apache.org/POM/4.0.0" -t -v "/p:project/p:version" pom.xml) RELEASE="simexplorer-is-swing-$VER" -MAIN_CLASS="fr.cemagref.simexplorer.is.SimExplorer" +MAIN_CLASS="fr.cemagref.simexplorer.is.ui.swing.SimExplorer" MX=512M Modified: trunk/simexplorer-is-swing/profiles.xml =================================================================== --- trunk/simexplorer-is-swing/profiles.xml 2008-01-20 13:57:39 UTC (rev 271) +++ trunk/simexplorer-is-swing/profiles.xml 2008-01-20 14:01:09 UTC (rev 272) @@ -19,7 +19,7 @@ <maven.compile.target>1.6</maven.compile.target> <!--Main class in JAR --> <maven.jar.main.class> - fr.cemagref.simexplorer.is.SimExplorer + fr.cemagref.simexplorer.is.ui.swing.SimExplorer </maven.jar.main.class> </properties> </profile> Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorer.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorer.java 2008-01-20 13:57:39 UTC (rev 271) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorer.java 2008-01-20 14:01:09 UTC (rev 272) @@ -1,165 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 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; - -import fr.cemagref.simexplorer.is.service.MockStorageServiceImpl; -import fr.cemagref.simexplorer.is.service.StorageService; -import fr.cemagref.simexplorer.is.ui.swing.JConfigUI; -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerTabManager; -import org.codelutin.i18n.I18n; -import org.codelutin.option.ui.ConfigTableModel; - -import java.io.IOException; - -/** - * L'application principale - * - * @author chemit - */ -public class SimExplorer { - - /** le context principal de l'application */ - protected static SimExplorerContext context; - - /** l'ui principale de l'application */ - protected static SimExplorerMainUI ui; - - /** le service de données local */ - private static StorageService remoteStorageService; - - /** le service de données distant */ - protected static StorageService storageService; - - public static SimExplorerContext getContext() { - checkInitContext(); - return context; - } - - public static SimExplorerMainUI getUI() { - checkInitContext(); - if (ui == null) { - ui = new SimExplorerMainUI(); - ui.postInit(); - } - return ui; - } - - public static void reloadUI() { - ui = null; - JConfigUI.reloadUI(); - SimExplorerTabManager.reloadUI(); - } - - /** - * initialisation de l'application : - * <p/> - * chargement du context - * - * @param args les arguments passés à l'application - */ - public static void init(String... args) { - - // init context - context = new SimExplorerContext(); - - // init i18n - I18n.initISO88591(); - - // init parser - context.initParser(args); - - // init config - context.initConfig(); - - // save config - try { - context.save(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - /** Lancement de l'ui après init de l'application. */ - public static void launch() { - - // init ui - SimExplorerMainUI mainUI = getUI(); - - SimExplorerConfig conf = getContext().getConfig(); - - if (conf.isShowLocalTab()) { - // show local tab - mainUI.getToolbar().getToggleTab_local().doClick(); - } - if (conf.isShowRemoteTab()) { - // show remote tab - mainUI.getToolbar().getToggleTab_remote().doClick(); - } - if (conf.isShowSynchTab()) { - // show synchronize tab - mainUI.getToolbar().getToggleTab_synchronize().doClick(); - } - - mainUI.setVisible(true); - } - - public static void main(String... args) throws Exception { - - // init application (parser,config,i18n,...) - init(args); - - // launch actions required - context.getParser().doAllActions(); - - // show edit config if first launch - if (SimExplorer.context.isFirstLaunch()) { - JConfigUI.showUI(context.getConfig(), ConfigTableModel.TypeModel.all); - } - - // launch ui only if required - if (!context.isQuit() && context.isLaunchUI()) { - launch(); - } - - } - - public static StorageService getStorageService() { - if (storageService == null) { - storageService = new MockStorageServiceImpl(); - } - return storageService; - } - - public static StorageService getRemoteStorageService() { - if (remoteStorageService == null) { - remoteStorageService = new MockStorageServiceImpl(); - } - return remoteStorageService; - } - - protected static void checkInitContext() { - if (context == null) { - throw new IllegalStateException("context is null, you must init first the " + SimExplorer.class.getName() + " class via init method"); - } - } - - protected SimExplorer() { - // protected restricted access - } -} Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerConfig.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerConfig.java 2008-01-20 13:57:39 UTC (rev 271) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerConfig.java 2008-01-20 14:01:09 UTC (rev 272) @@ -1,131 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, -* Tony Chemit -* -* 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; - -import fr.cemagref.simexplorer.is.configs.SimExplorerAbstractConfigMain; -import fr.cemagref.simexplorer.is.options.SimExplorerOptionConfig; -import fr.cemagref.simexplorer.is.options.SimExplorerOptionConfigFile; -import org.codelutin.i18n.I18n; -import org.codelutin.i18n.LanguageEnum; -import org.codelutin.i18n.CountryEnum; -import static org.codelutin.i18n.I18n._; -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 RuntimeException("simexplorer.error.user.home"); - } - doInit(); - } - - public void init() throws Exception { - 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 RuntimeException(e); - } - } - } - if (containsKey(SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY)) { - setProperty(SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY, file); - } - setSource(file); - } - - public void initI18n() { - I18n.initISO88591(getLanguage().name(), getCountry().name()); - } - - protected void loadFromOptions(SimExplorerOptionParser parser) throws Exception { - 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 IllegalArgumentException(_("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) { - setLanguage(language); - setCountry(country); - } -} \ No newline at end of file Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerContext.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerContext.java 2008-01-20 13:57:39 UTC (rev 271) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerContext.java 2008-01-20 14:01:09 UTC (rev 272) @@ -1,145 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* 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; - -import fr.cemagref.simexplorer.is.actions.SimExplorerCommonActions; -import fr.cemagref.simexplorer.is.ui.swing.bean.ApplicationBean; -import fr.cemagref.simexplorer.is.ui.swing.bean.ListApplicationBean; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.option.ParserException; - -import java.io.BufferedOutputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -/** - * Le context de l'application, implanté en singleton. - * <p/> - * Contient la configuration de l'application, le parseur d'options,... - * - * @author chemit - */ -public class SimExplorerContext { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(SimExplorerContext.class); - - private SimExplorerOptionParser parser; - private boolean quit; - private boolean launchUI = true; - private boolean firstLaunch; - - protected ListApplicationBean localApplications; - protected ListApplicationBean remoteApplications; - protected ApplicationBean applicationBean; - - public ApplicationBean getApplicationBean() { - return applicationBean; - } - - public ListApplicationBean getLocalApplications() { - return localApplications; - } - - public ListApplicationBean getRemoteApplications() { - return remoteApplications; - } - - public SimExplorerOptionParser getParser() { - if (parser == null) { - // creation du parseur - parser = new SimExplorerOptionParser(); - // enregistrement des actions concretes - parser.registerActions(SimExplorerCommonActions.class); - - // enregistrement des configs concretes - parser.registerConfig(SimExplorerConfig.class); - } - return parser; - } - - public SimExplorerConfig getConfig() { - return (SimExplorerConfig) getParser().getMainConfig(); - } - - public void save() throws IOException { - if (getConfig().getSource() == null) { - return; - } - BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(getConfig().getSource())); - try { - getConfig().save(out); - } finally { - out.flush(); - out.close(); - } - } - - public void saveSafely() { - try { - save(); - } catch (Exception e) { - log.warn("simexplorer.error.unsafe.save.config" + e.getMessage(), e); - } - } - - public void setQuit(boolean quit) { - this.quit = quit; - } - - public boolean isQuit() { - return quit; - } - - public void setLaunchUI(boolean launchUI) { - this.launchUI = launchUI; - } - - public boolean isLaunchUI() { - return launchUI; - } - - public void setFirstLaunch(boolean firstLaunch) { - this.firstLaunch = firstLaunch; - } - - public boolean isFirstLaunch() { - return firstLaunch; - } - - /** restricted access constructor */ - SimExplorerContext() { - - } - - void initParser(String... args) { - try { - getParser().doParse(args); - } catch (ParserException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - void initConfig() { - getConfig().initI18n(); - } -} Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerException.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerException.java 2008-01-20 13:57:39 UTC (rev 271) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerException.java 2008-01-20 14:01:09 UTC (rev 272) @@ -1,44 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 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; - -/** - * Exception de base. - * - * @author chemit - */ -public class SimExplorerException extends Exception { - - private static final long serialVersionUID = -8288416952045350383L; - - public SimExplorerException() { - } - - public SimExplorerException(Throwable cause) { - super(cause); - } - - public SimExplorerException(String message) { - super(message); - } - - public SimExplorerException(String message, Throwable cause) { - super(message, cause); - } -} Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerMainUI.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerMainUI.java 2008-01-20 13:57:39 UTC (rev 271) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerMainUI.java 2008-01-20 14:01:09 UTC (rev 272) @@ -1,70 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 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; - -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerActionManager; -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerUI; -import fr.cemagref.simexplorer.is.ui.swing.action.common.ChangeI18nAction; -import org.codelutin.i18n.CountryEnum; -import org.codelutin.i18n.LanguageEnum; - -import javax.swing.AbstractButton; -import java.util.regex.Matcher; - -/** - * L'ui principale de l'application - * @author chemit - */ -public class SimExplorerMainUI extends SimExplorerUI { - - public SimExplorerMainUI() { - super(); - - // chargement des classes d'implantations des actions d'ui - SimExplorerActionManager.init(); - - // chargement dans l'ui des actions - SimExplorerActionManager.loadActions(this); - - // repaint i18n actions - repaintI18nActions(); - } - - public void repaintI18nActions() { - LanguageEnum language = SimExplorer.getContext().getConfig().getLanguage(); - CountryEnum country = SimExplorer.getContext().getConfig().getCountry(); - String[] actions = SimExplorerActionManager.getActionNames(); - for (String actionName : actions) { - Matcher matcher = ChangeI18nAction.PATTERN_NAME.matcher(actionName); - if (!matcher.matches()) { - continue; - } - AbstractButton button = (AbstractButton) getObjectById(actionName); - ChangeI18nAction action = (ChangeI18nAction) button.getAction(); - boolean enable = !action.equalsLocale(language, country); - button.setEnabled(enable); - } - } - - public void postInit() { - // chargement dans le toolbar des actions - //TODO cela devrait être générique - SimExplorerActionManager.loadActions(getToolbar()); - } -} Deleted: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerRuntimeException.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerRuntimeException.java 2008-01-20 13:57:39 UTC (rev 271) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerRuntimeException.java 2008-01-20 14:01:09 UTC (rev 272) @@ -1,43 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 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; - -/** - * RuntimeException de base. - * - * @author chemit - */ -public class SimExplorerRuntimeException extends RuntimeException { - private static final long serialVersionUID = -4412747043461741154L; - - public SimExplorerRuntimeException() { - } - - public SimExplorerRuntimeException(Throwable cause) { - super(cause); - } - - public SimExplorerRuntimeException(String message) { - super(message); - } - - public SimExplorerRuntimeException(String message, Throwable cause) { - super(message, cause); - } -} \ No newline at end of file Copied: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorer.java (from rev 259, trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorer.java) =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorer.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorer.java 2008-01-20 14:01:09 UTC (rev 272) @@ -0,0 +1,166 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 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.service.MockStorageServiceImpl; +import fr.cemagref.simexplorer.is.service.StorageService; +import fr.cemagref.simexplorer.is.ui.swing.JConfigUI; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerTabManager; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerMainUI; +import org.codelutin.i18n.I18n; +import org.codelutin.option.ui.ConfigTableModel; + +import java.io.IOException; + +/** + * L'application principale + * + * @author chemit + */ +public class SimExplorer { + + /** le context principal de l'application */ + protected static SimExplorerContext context; + + /** l'ui principale de l'application */ + protected static SimExplorerMainUI ui; + + /** le service de données local */ + private static StorageService remoteStorageService; + + /** le service de données distant */ + protected static StorageService storageService; + + public static SimExplorerContext getContext() { + checkInitContext(); + return context; + } + + public static SimExplorerMainUI getUI() { + checkInitContext(); + if (ui == null) { + ui = new SimExplorerMainUI(); + ui.postInit(); + } + return ui; + } + + public static void reloadUI() { + ui = null; + JConfigUI.reloadUI(); + SimExplorerTabManager.reloadUI(); + } + + /** + * initialisation de l'application : + * <p/> + * chargement du context + * + * @param args les arguments passés à l'application + */ + public static void init(String... args) { + + // init context + context = new SimExplorerContext(); + + // init i18n + I18n.initISO88591(); + + // init parser + context.initParser(args); + + // init config + context.initConfig(); + + // save config + try { + context.save(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** Lancement de l'ui après init de l'application. */ + public static void launch() { + + // init ui + SimExplorerMainUI mainUI = getUI(); + + SimExplorerConfig conf = getContext().getConfig(); + + if (conf.isShowLocalTab()) { + // show local tab + mainUI.getToolbar().getToggleTab_local().doClick(); + } + if (conf.isShowRemoteTab()) { + // show remote tab + mainUI.getToolbar().getToggleTab_remote().doClick(); + } + if (conf.isShowSynchTab()) { + // show synchronize tab + mainUI.getToolbar().getToggleTab_synchronize().doClick(); + } + + mainUI.setVisible(true); + } + + public static void main(String... args) throws Exception { + + // init application (parser,config,i18n,...) + init(args); + + // launch actions required + context.getParser().doAllActions(); + + // show edit config if first launch + if (SimExplorer.context.isFirstLaunch()) { + JConfigUI.showUI(context.getConfig(), ConfigTableModel.TypeModel.all); + } + + // launch ui only if required + if (!context.isQuit() && context.isLaunchUI()) { + launch(); + } + + } + + public static StorageService getStorageService() { + if (storageService == null) { + storageService = new MockStorageServiceImpl(); + } + return storageService; + } + + public static StorageService getRemoteStorageService() { + if (remoteStorageService == null) { + remoteStorageService = new MockStorageServiceImpl(); + } + return remoteStorageService; + } + + protected static void checkInitContext() { + if (context == null) { + throw new IllegalStateException("context is null, you must init first the " + SimExplorer.class.getName() + " class via init method"); + } + } + + protected SimExplorer() { + // protected restricted access + } +} Copied: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerConfig.java (from rev 235, trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerConfig.java) =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerConfig.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerConfig.java 2008-01-20 14:01:09 UTC (rev 272) @@ -0,0 +1,132 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, +* Tony Chemit +* +* 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.configs.SimExplorerAbstractConfigMain; +import fr.cemagref.simexplorer.is.options.SimExplorerOptionConfig; +import fr.cemagref.simexplorer.is.options.SimExplorerOptionConfigFile; +import fr.cemagref.simexplorer.is.SimExplorerOptionParser; +import org.codelutin.i18n.I18n; +import org.codelutin.i18n.LanguageEnum; +import org.codelutin.i18n.CountryEnum; +import static org.codelutin.i18n.I18n._; +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 RuntimeException("simexplorer.error.user.home"); + } + doInit(); + } + + public void init() throws Exception { + 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 RuntimeException(e); + } + } + } + if (containsKey(SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY)) { + setProperty(SimExplorerConfig.CONFIG_FILE_NAME_PROPERTY_KEY, file); + } + setSource(file); + } + + public void initI18n() { + I18n.initISO88591(getLanguage().name(), getCountry().name()); + } + + protected void loadFromOptions(SimExplorerOptionParser parser) throws Exception { + 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 IllegalArgumentException(_("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) { + setLanguage(language); + setCountry(country); + } +} \ No newline at end of file Copied: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java (from rev 268, trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerContext.java) =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java 2008-01-20 14:01:09 UTC (rev 272) @@ -0,0 +1,146 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, +* Tony Chemit +* +* 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.actions.SimExplorerCommonActions; +import fr.cemagref.simexplorer.is.ui.swing.bean.ApplicationBean; +import fr.cemagref.simexplorer.is.ui.swing.bean.ListApplicationBean; +import fr.cemagref.simexplorer.is.SimExplorerOptionParser; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.option.ParserException; + +import java.io.BufferedOutputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +/** + * Le context de l'application, implanté en singleton. + * <p/> + * Contient la configuration de l'application, le parseur d'options,... + * + * @author chemit + */ +public class SimExplorerContext { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = LogFactory.getLog(SimExplorerContext.class); + + private SimExplorerOptionParser parser; + private boolean quit; + private boolean launchUI = true; + private boolean firstLaunch; + + protected ListApplicationBean localApplications; + protected ListApplicationBean remoteApplications; + protected ApplicationBean applicationBean; + + public ApplicationBean getApplicationBean() { + return applicationBean; + } + + public ListApplicationBean getLocalApplications() { + return localApplications; + } + + public ListApplicationBean getRemoteApplications() { + return remoteApplications; + } + + public SimExplorerOptionParser getParser() { + if (parser == null) { + // creation du parseur + parser = new SimExplorerOptionParser(); + // enregistrement des actions concretes + parser.registerActions(SimExplorerCommonActions.class); + + // enregistrement des configs concretes + parser.registerConfig(SimExplorerConfig.class); + } + return parser; + } + + public SimExplorerConfig getConfig() { + return (SimExplorerConfig) getParser().getMainConfig(); + } + + public void save() throws IOException { + if (getConfig().getSource() == null) { + return; + } + BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(getConfig().getSource())); + try { + getConfig().save(out); + } finally { + out.flush(); + out.close(); + } + } + + public void saveSafely() { + try { + save(); + } catch (Exception e) { + log.warn("simexplorer.error.unsafe.save.config" + e.getMessage(), e); + } + } + + public void setQuit(boolean quit) { + this.quit = quit; + } + + public boolean isQuit() { + return quit; + } + + public void setLaunchUI(boolean launchUI) { + this.launchUI = launchUI; + } + + public boolean isLaunchUI() { + return launchUI; + } + + public void setFirstLaunch(boolean firstLaunch) { + this.firstLaunch = firstLaunch; + } + + public boolean isFirstLaunch() { + return firstLaunch; + } + + /** restricted access constructor */ + SimExplorerContext() { + + } + + void initParser(String... args) { + try { + getParser().doParse(args); + } catch (ParserException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + void initConfig() { + getConfig().initI18n(); + } +} Copied: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerException.java (from rev 258, trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerException.java) =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerException.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerException.java 2008-01-20 14:01:09 UTC (rev 272) @@ -0,0 +1,44 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 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; + +/** + * Exception de base. + * + * @author chemit + */ +public class SimExplorerException extends Exception { + + private static final long serialVersionUID = -8288416952045350383L; + + public SimExplorerException() { + } + + public SimExplorerException(Throwable cause) { + super(cause); + } + + public SimExplorerException(String message) { + super(message); + } + + public SimExplorerException(String message, Throwable cause) { + super(message, cause); + } +} Copied: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerMainUI.java (from rev 260, trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerMainUI.java) =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerMainUI.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerMainUI.java 2008-01-20 14:01:09 UTC (rev 272) @@ -0,0 +1,71 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 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.ui.swing.SimExplorerActionManager; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerUI; +import fr.cemagref.simexplorer.is.ui.swing.action.common.ChangeI18nAction; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorer; +import org.codelutin.i18n.CountryEnum; +import org.codelutin.i18n.LanguageEnum; + +import javax.swing.AbstractButton; +import java.util.regex.Matcher; + +/** + * L'ui principale de l'application + * @author chemit + */ +public class SimExplorerMainUI extends SimExplorerUI { + + public SimExplorerMainUI() { + super(); + + // chargement des classes d'implantations des actions d'ui + SimExplorerActionManager.init(); + + // chargement dans l'ui des actions + SimExplorerActionManager.loadActions(this); + + // repaint i18n actions + repaintI18nActions(); + } + + public void repaintI18nActions() { + LanguageEnum language = SimExplorer.getContext().getConfig().getLanguage(); + CountryEnum country = SimExplorer.getContext().getConfig().getCountry(); + String[] actions = SimExplorerActionManager.getActionNames(); + for (String actionName : actions) { + Matcher matcher = ChangeI18nAction.PATTERN_NAME.matcher(actionName); + if (!matcher.matches()) { + continue; + } + AbstractButton button = (AbstractButton) getObjectById(actionName); + ChangeI18nAction action = (ChangeI18nAction) button.getAction(); + boolean enable = !action.equalsLocale(language, country); + button.setEnabled(enable); + } + } + + public void postInit() { + // chargement dans le toolbar des actions + //TODO cela devrait être générique + SimExplorerActionManager.loadActions(getToolbar()); + } +} Copied: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerRuntimeException.java (from rev 258, trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/SimExplorerRuntimeException.java) =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerRuntimeException.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerRuntimeException.java 2008-01-20 14:01:09 UTC (rev 272) @@ -0,0 +1,43 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 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; + +/** + * RuntimeException de base. + * + * @author chemit + */ +public class SimExplorerRuntimeException extends RuntimeException { + private static final long serialVersionUID = -4412747043461741154L; + + public SimExplorerRuntimeException() { + } + + public SimExplorerRuntimeException(Throwable cause) { + super(cause); + } + + public SimExplorerRuntimeException(String message) { + super(message); + } + + public SimExplorerRuntimeException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file