Author: tchemit Date: 2008-01-18 01:49:41 +0000 (Fri, 18 Jan 2008) New Revision: 180 Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/actions/SimExplorerCommonActions.java Log: les actions d'options de base (config,help,...) Added: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/actions/SimExplorerCommonActions.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/actions/SimExplorerCommonActions.java (rev 0) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/actions/SimExplorerCommonActions.java 2008-01-18 01:49:41 UTC (rev 180) @@ -0,0 +1,135 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, +* Benjamin Poussin, 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.actions; + +import fr.cemagref.simexplorer.is.configs.SimExplorerAbstractConfigMain; +import fr.cemagref.simexplorer.is.options.SimExplorerOptionEditConfig; +import fr.cemagref.simexplorer.is.options.SimExplorerOptionShowConfig; +import fr.cemagref.simexplorer.is.ui.swing.JConfigUI; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import static org.codelutin.i18n.I18n._; +import org.codelutin.option.Config; +import org.codelutin.option.ui.ConfigTableModel; + +import java.io.IOException; +import java.io.StringWriter; + +/** + * The class to define all common actions that IsisFish can launch at init time. + * + * @author chemit + */ +public class SimExplorerCommonActions { + + private static final Log log = LogFactory.getLog(SimExplorerCommonActions.class); + + static void printConfig(StringWriter writer, Config config) throws IOException { + writer.append('\n').append(config.toString()); + writer.flush(); + } + + public static class HelpAction extends SimExplorerAbstractOptionActionHelp { + + protected void run() throws Exception { + log.info("required help action"); + StringWriter writer = new StringWriter(); + parser.printUsage(writer, "SimExplorer SI v " + getContext().getConfig().getVersion()); + printConfig(writer, parser.getMainConfig()); + writer.append('\n'); + log.info(writer); + getContext().setQuit(true); + } + } + + public static class ShowConfigAction extends SimExplorerAbstractOptionActionShowConfig { + @Override + protected void beforeAll(SimExplorerOptionShowConfig... options) { + super.beforeAll(options); + // check we have not twice config + } + + public void run() throws Exception { + SimExplorerAbstractConfigMain conf; + conf = getParser().getMainConfig(); + + String category = option.getConstantArgumentValue(0); + if (conf == null) { + throw new IllegalArgumentException("could not found a configuration with category " + category); + } + log.info("required showConfig pour category [" + category + "]"); + StringWriter writer = new StringWriter(); + printConfig(writer, conf); + log.info(writer); + getContext().setQuit(true); + } + } + + public static class EditConfigAction extends SimExplorerAbstractOptionActionEditConfig { + @Override + protected void beforeAll(SimExplorerOptionEditConfig... options) { + super.beforeAll(options); + // check we have not twice config + } + + public void run() throws Exception { + SimExplorerAbstractConfigMain conf; + conf = getParser().getMainConfig(); + if (isAll()) { + JConfigUI.showUI(conf, ConfigTableModel.TypeModel.all); + } else if (isTec()) { + JConfigUI.showTechnicalUI(conf); + } else { + JConfigUI.showUI(conf); + } + + StringWriter writer = new StringWriter(); + printConfig(writer, conf); + log.info("required editConfig pour category [" + conf.getCategory() + "]" + writer); + } + } + + public static class ResetConfigAction extends SimExplorerAbstractOptionActionResetConfig { + + public void run() throws Exception { + //IsisFish.firstLaunch = true; + //IsisFish.resetConfig = true; + getContext().getConfig().getConfigFileName().delete(); + log.info(_("simexplorer.message.reset.user.configuration")); + getContext().setFirstLaunch(true); + } + + } + + public static class UiAction extends SimExplorerAbstractOptionActionUi { + protected boolean init = false; + + public void run() throws Exception { + Boolean bool = isValue(); + boolean launchUI = bool != null && bool; + log.info(option.getUsedAlias() + ", value:" + bool); + getContext().setLaunchUI(launchUI); + if (init) { + getContext().setQuit(true); + } + init = true; + } + } +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org