r88 - in trunk: jmexico-editor/src/main/java/fr/reseaumexico/editor jmexico-editor/src/main/resources/i18n jmexico-editor-demo/src/main/java/fr/reseaumexico/editor/demo
Author: tchemit Date: 2012-10-07 18:24:50 +0200 (Sun, 07 Oct 2012) New Revision: 88 Url: http://forge.codelutin.com/repositories/revision/jmexico/88 Log: fixes #1576: Add import scenario action (add UI) fixes #1577: Add export scenario operation (add UI) Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/AbstractScenarioModel.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioModel.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioPanel.css trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioPanel.jaxx trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioModel.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioPanel.css trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioPanel.jaxx Modified: trunk/jmexico-editor-demo/src/main/java/fr/reseaumexico/editor/demo/MexicoEditorDemoUIHandler.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/CloneScenarioModel.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.css trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorModel.java trunk/jmexico-editor/src/main/resources/i18n/jmexico-editor_en_GB.properties trunk/jmexico-editor/src/main/resources/i18n/jmexico-editor_fr_FR.properties Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/AbstractScenarioModel.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/AbstractScenarioModel.java (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/AbstractScenarioModel.java 2012-10-07 16:24:50 UTC (rev 88) @@ -0,0 +1,71 @@ +package fr.reseaumexico.editor; + +/* + * #%L + * JMexico :: Swing Editor + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Réseau Mexico, 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>. + * #L% + */ + +import fr.reseaumexico.model.Scenario; +import org.jdesktop.beans.AbstractSerializableBean; + +import java.io.File; +import java.util.Collection; + +/** + * Model toimport a scenarion into a input design. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.7 + */ +public class AbstractScenarioModel<M extends AbstractScenarioModel> extends AbstractSerializableBean { + + private static final long serialVersionUID = 1L; + + protected Collection<Scenario> scenarios; + + protected Scenario selectedScenario; + + public Collection<Scenario> getScenarios() { + return scenarios; + } + + public Scenario getSelectedScenario() { + return selectedScenario; + } + + public void setSelectedScenario(Scenario selectedScenario) { + Object oldValue = this.selectedScenario; + this.selectedScenario = selectedScenario; + firePropertyChange("selectedScenario", oldValue, selectedScenario); + } + + + public void setScenarios(Collection<Scenario> scenarios) { + this.scenarios = scenarios; + firePropertyChange("scenarios", null, scenarios); + } + + public void copyTo(M model) { + model.setScenarios(getScenarios()); + model.setSelectedScenario(getSelectedScenario()); + } +} \ No newline at end of file Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/AbstractScenarioModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/CloneScenarioModel.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/CloneScenarioModel.java 2012-10-07 16:24:03 UTC (rev 87) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/CloneScenarioModel.java 2012-10-07 16:24:50 UTC (rev 88) @@ -35,48 +35,25 @@ * @author tchemit <chemit@codelutin.com> * @since 0.7 */ -public class CloneScenarioModel extends AbstractSerializableBean { +public class CloneScenarioModel extends AbstractScenarioModel<CloneScenarioModel> { private static final long serialVersionUID = 1L; - protected Collection<Scenario> scenarios; - - protected Scenario selectedScenario; - protected String scenarioName; - public Collection<Scenario> getScenarios() { - return scenarios; - } - - public Scenario getSelectedScenario() { - return selectedScenario; - } - public String getScenarioName() { return scenarioName; } - public void setSelectedScenario(Scenario selectedScenario) { - Object oldValue = this.selectedScenario; - this.selectedScenario = selectedScenario; - firePropertyChange("selectedScenario", oldValue, selectedScenario); - } - public void setScenarioName(String scenarioName) { Object oldValue = this.scenarioName; this.scenarioName = scenarioName; firePropertyChange("scenarioName", oldValue, scenarioName); } - public void setScenarios(Collection<Scenario> scenarios) { - this.scenarios = scenarios; - firePropertyChange("scenarios", null, scenarios); - } - + @Override public void copyTo(CloneScenarioModel model) { + super.copyTo(model); model.setScenarioName(getScenarioName()); - model.setScenarios(getScenarios()); - model.setSelectedScenario(getSelectedScenario()); } } Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioModel.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioModel.java (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioModel.java 2012-10-07 16:24:50 UTC (rev 88) @@ -0,0 +1,57 @@ +package fr.reseaumexico.editor; + +/* + * #%L + * JMexico :: Swing Editor + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Réseau Mexico, 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>. + * #L% + */ + +import java.io.File; + +/** + * Model to export a scenario. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.7 + */ +public class ExportScenarioModel extends AbstractScenarioModel<ExportScenarioModel> { + + private static final long serialVersionUID = 1L; + + protected File exportFile; + + public File getExportFile() { + return exportFile; + } + + public void setExportFile(File exportFile) { + Object oldValue = this.exportFile; + this.exportFile = exportFile; + firePropertyChange("exportFile", oldValue, exportFile); + } + + + @Override + public void copyTo(ExportScenarioModel model) { + super.copyTo(model); + model.setExportFile(getExportFile()); + } +} \ No newline at end of file Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioPanel.css =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioPanel.css (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioPanel.css 2012-10-07 16:24:50 UTC (rev 88) @@ -0,0 +1,38 @@ +/* + * #%L + * JMexico :: Swing Editor + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Réseau Mexico, Codelutin, Tony Chemit + * %% + * 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>. + * #L% + */ +#exportFileLabel { + text:"jmexico.label.scenario.export.file"; +} + +#exportFileEditor { + selectedFile:{model.getExportFile()}; +} + +#selectedScenarioLabel { + text:"jmexico.label.scenario.export.selected"; +} + +#selectedScenarioEditor { + selectedItem:{model.getSelectedScenario()}; +} Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioPanel.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioPanel.jaxx =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioPanel.jaxx (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioPanel.jaxx 2012-10-07 16:24:50 UTC (rev 88) @@ -0,0 +1,63 @@ +<!-- + #%L + JMexico :: Swing Editor + $Id$ + $HeadURL$ + %% + Copyright (C) 2011 - 2012 Réseau Mexico, Codelutin, Tony Chemit + %% + 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>. + #L% + --> +<Table id='panel' layout='{new BorderLayout()}'> + + <import> + jaxx.runtime.swing.editor.FileEditor + </import> + + <ExportScenarioModel id='model'/> + + <script> + <![CDATA[ +public void init(ExportScenarioModel model) { + model.copyTo(this.model); + + // init selected scenario + SwingUtil.fillComboBox(selectedScenarioEditor, + model.getScenarios(), + model.getSelectedScenario()); + } + ]]> + </script> + + <row fill='both'> + <cell> + <JLabel id='selectedScenarioLabel'/> + </cell> + <cell> + <JComboBox id='selectedScenarioEditor' + onItemStateChanged='InputDesignEditorHandler.onSelectedScenarioChanged(model, event)'/> + </cell> + </row> + <row fill='both'> + <cell> + <JLabel id='exportFileLabel'/> + </cell> + <cell> + <FileEditor id='exportFileEditor' + onActionPerformed='model.setExportFile(((FileEditor) event.getSource()).getSelectedFile())'/> + </cell> + </row> +</Table> Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ExportScenarioPanel.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioModel.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioModel.java (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioModel.java 2012-10-07 16:24:50 UTC (rev 88) @@ -0,0 +1,69 @@ +package fr.reseaumexico.editor; + +/* + * #%L + * JMexico :: Swing Editor + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Réseau Mexico, 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>. + * #L% + */ + +import java.io.File; + +/** + * Model toimport a scenarion into a input design. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.7 + */ +public class ImportScenarioModel extends AbstractScenarioModel<ImportScenarioModel> { + + private static final long serialVersionUID = 1L; + + protected File importFile; + + protected String scenarioName; + + public String getScenarioName() { + return scenarioName; + } + + public File getImportFile() { + return importFile; + } + + public void setScenarioName(String scenarioName) { + Object oldValue = this.scenarioName; + this.scenarioName = scenarioName; + firePropertyChange("scenarioName", oldValue, scenarioName); + } + + public void setImportFile(File importFile) { + Object oldValue = this.importFile; + this.importFile = importFile; + firePropertyChange("importFile", oldValue, importFile); + } + + @Override + public void copyTo(ImportScenarioModel model) { + super.copyTo(model); + model.setImportFile(getImportFile()); + model.setScenarioName(getScenarioName()); + } +} \ No newline at end of file Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioPanel.css =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioPanel.css (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioPanel.css 2012-10-07 16:24:50 UTC (rev 88) @@ -0,0 +1,38 @@ +/* + * #%L + * JMexico :: Swing Editor + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Réseau Mexico, Codelutin, Tony Chemit + * %% + * 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>. + * #L% + */ +#scenarioNameLabel { + text:"jmexico.label.scenario.import.name"; +} + +#scenarioNameEditor { + text:{model.getScenarioName()}; +} + +#importFileLabel { + text:"jmexico.label.scenario.import.file"; +} + +#importFileEditor { + selectedFile:{model.getImportFile()}; +} Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioPanel.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioPanel.jaxx =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioPanel.jaxx (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioPanel.jaxx 2012-10-07 16:24:50 UTC (rev 88) @@ -0,0 +1,57 @@ +<!-- + #%L + JMexico :: Swing Editor + $Id$ + $HeadURL$ + %% + Copyright (C) 2011 - 2012 Réseau Mexico, Codelutin, Tony Chemit + %% + 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>. + #L% + --> +<Table id='panel' layout='{new BorderLayout()}'> + + <import> + jaxx.runtime.swing.editor.FileEditor + </import> + + <ImportScenarioModel id='model'/> + + <script> + <![CDATA[ +public void init(ImportScenarioModel model) { + model.copyTo(this.model); +} + ]]> + </script> + <row fill='both'> + <cell> + <JLabel id='scenarioNameLabel'/> + </cell> + <cell> + <JTextField id='scenarioNameEditor' + onKeyReleased='model.setScenarioName(((JTextField)event.getSource()).getText())'/> + </cell> + </row> + <row fill='both'> + <cell> + <JLabel id='importFileLabel'/> + </cell> + <cell> + <FileEditor id='importFileEditor' + onActionPerformed='model.setImportFile(((FileEditor) event.getSource()).getSelectedFile())'/> + </cell> + </row> +</Table> Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/ImportScenarioPanel.jaxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.css =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.css 2012-10-07 16:24:03 UTC (rev 87) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.css 2012-10-07 16:24:50 UTC (rev 88) @@ -42,6 +42,16 @@ enabled:{model.isScenarioExists()}; } +#importScenarioButton { + text:"jmexico.action.import.scenario"; + enabled:{model.getInputDesign() != null}; +} + +#exportScenarioButton { + text:"jmexico.action.export.scenario"; + enabled:{model.isScenarioExists()}; +} + #selectedScenarioEditor { selectedItem:{model.getSelectedScenario()}; } \ No newline at end of file Modified: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx 2012-10-07 16:24:03 UTC (rev 87) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx 2012-10-07 16:24:50 UTC (rev 88) @@ -61,6 +61,10 @@ onActionPerformed='getHandler().removeScenario()'/> <JButton id='cloneScenarioButton' constraints='BorderLayout.EAST' onActionPerformed='getHandler().cloneScenario()'/> + <JButton id='importScenarioButton' constraints='BorderLayout.EAST' + onActionPerformed='getHandler().importScenario()'/> + <JButton id='exportScenarioButton' constraints='BorderLayout.EAST' + onActionPerformed='getHandler().exportScenario()'/> </JPanel> </JPanel> Modified: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java 2012-10-07 16:24:03 UTC (rev 87) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java 2012-10-07 16:24:50 UTC (rev 88) @@ -24,6 +24,7 @@ */ package fr.reseaumexico.editor; +import com.google.common.base.Function; import com.google.common.collect.Maps; import fr.reseaumexico.editor.factorValue.FactorValueCellEditor; import fr.reseaumexico.editor.factorValue.FactorValueCellRenderer; @@ -32,15 +33,24 @@ import fr.reseaumexico.model.InputDesign; import fr.reseaumexico.model.Scenario; import fr.reseaumexico.model.ScenarioImpl; +import fr.reseaumexico.model.parser.ScenarioXmlParser; +import fr.reseaumexico.model.writer.ScenarioXmlWriter; +import jaxx.runtime.swing.editor.FileEditor; import jaxx.runtime.swing.renderer.DecoratorProviderTableCellRenderer; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdesktop.swingx.JXTable; import javax.swing.JOptionPane; import java.awt.event.ItemEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.IOException; import java.util.Collection; +import java.util.List; import java.util.Map; import static org.nuiton.i18n.I18n._; @@ -52,6 +62,10 @@ */ public class InputDesignEditorHandler { + /** Logger. */ + private static final Log log = + LogFactory.getLog(InputDesignEditorHandler.class); + private final InputDesignEditor ui; public InputDesignEditorHandler(InputDesignEditor ui) { @@ -70,14 +84,18 @@ } } }); + + JXTable table = ui.getInputDesignTable(); + // table renderer - // TODO sletellier 20111221 : do on time for all, put in context ? - MexicoDecoratorProvider mexicoDecoratorProvider = new MexicoDecoratorProvider(); - ui.inputDesignTable.setDefaultRenderer(Factor.class, new DecoratorProviderTableCellRenderer(mexicoDecoratorProvider)); - ui.inputDesignTable.setDefaultRenderer(Object.class, new FactorValueCellRenderer(ui)); + table.setDefaultRenderer( + Factor.class, + new DecoratorProviderTableCellRenderer( + new MexicoDecoratorProvider())); + table.setDefaultRenderer(Object.class, new FactorValueCellRenderer(ui)); // cell editor - ui.inputDesignTable.setDefaultEditor(Object.class, new FactorValueCellEditor(ui)); + table.setDefaultEditor(Object.class, new FactorValueCellEditor(ui)); } public void addScenario() { @@ -181,7 +199,79 @@ } } - public static void onSelectedScenarioChanged(CloneScenarioModel model, + public void importScenario() { + + InputDesign inputDesign = ui.getInputDesign(); + + ImportScenarioModel model = new ImportScenarioModel(); + model.setScenarios(inputDesign.getScenario()); + + boolean accept = showImportScenarioUI(model); + + if (accept) { + + // import scenario + + File importFile = model.getImportFile(); + + String scenarioName = model.getScenarioName(); + + if (log.isInfoEnabled()) { + log.info("Import scenario '" + scenarioName + "' from " + importFile); + } + List<Factor> factors = ui.getModel().getFactors(); + ScenarioXmlParser parser = new ScenarioXmlParser(Maps.uniqueIndex(factors, new Function<Factor, String>() { + @Override + public String apply(Factor input) { + return input.getId(); + } + })); + try { + Scenario scenario = parser.getModel(importFile); + + scenario.setName(scenarioName); + scenario.setOrderNumber(getMaxOrder()); + inputDesign.addScenario(scenario); + + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Could not import scenario", e); + } + } + } + } + + public void exportScenario() { + + InputDesign inputDesign = ui.getInputDesign(); + + ExportScenarioModel model = new ExportScenarioModel(); + model.setScenarios(inputDesign.getScenario()); + + boolean accept = showExportScenarioUI(model); + + if (accept) { + + // export scenario + + File exportFile = model.getExportFile(); + Scenario scenario = model.getSelectedScenario(); + + if (log.isInfoEnabled()) { + log.info("Export scenario '" + scenario.getName() + + "' to file " + exportFile); + } + try { + ScenarioXmlWriter.write(scenario, exportFile); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Could not export scenario to " + exportFile, e); + } + } + } + } + + public static void onSelectedScenarioChanged(AbstractScenarioModel<?> model, ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) { @@ -246,7 +336,6 @@ } else { valid = isScenarioNameAvailable(selectedName); } - } doIt = valid || showCloneScenarioUI(model); @@ -255,6 +344,142 @@ return doIt; } + protected boolean showExportScenarioUI(ExportScenarioModel model) { + + // show ui + + ExportScenarioPanel panel = new ExportScenarioPanel(); + panel.init(model); + + FileEditor fileEditor = panel.getExportFileEditor(); + + fileEditor.setAcceptAllFileFilterUsed(false); + fileEditor.setExts(_("jmexico.config.scenario.extension")); + fileEditor.setExtsDescription( + _("jmexico.config.scenario.extension.description")); + + int response = JOptionPane.showConfirmDialog( + ui, + panel, + _("jmexico.title.scenario.export"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE); + + boolean doIt = response == JOptionPane.OK_OPTION; + + if (doIt) { + + // user ask to perform operation + + //copy back model + panel.getModel().copyTo(model); + + // validate model + boolean valid = true; + + Scenario selectedScenario = model.getSelectedScenario(); + if (selectedScenario == null) { + + // no scenario selected + JOptionPane.showMessageDialog( + ui, + _("jmexico.error.scenario.not.selected"), + _("jmexico.title.error"), + JOptionPane.ERROR_MESSAGE); + + valid = false; + } + + if (valid) { + + // check export file is filled + File exportFile = model.getExportFile(); + + if (exportFile == null) { + valid = false; + JOptionPane.showMessageDialog( + ui, + _("jmexico.error.scenario.exportFile.required"), + _("jmexico.title.error"), + JOptionPane.ERROR_MESSAGE); + + } + } + doIt = valid || showExportScenarioUI(model); + } + return doIt; + } + + protected boolean showImportScenarioUI(ImportScenarioModel model) { + + // show ui + + ImportScenarioPanel panel = new ImportScenarioPanel(); + panel.init(model); + + FileEditor fileEditor = panel.getImportFileEditor(); + + fileEditor.setAcceptAllFileFilterUsed(false); + fileEditor.setExts(_("jmexico.config.scenario.extension")); + fileEditor.setExtsDescription( + _("jmexico.config.scenario.extension.description")); + + + int response = JOptionPane.showConfirmDialog( + ui, + panel, + _("jmexico.title.scenario.import"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE); + + boolean doIt = response == JOptionPane.OK_OPTION; + + if (doIt) { + + // user ask to perform operation + + //copy back model + panel.getModel().copyTo(model); + + // validate model + boolean valid = true; + + + // check import file filled + File importFile = model.getImportFile(); + + if (importFile == null) { + valid = false; + JOptionPane.showMessageDialog( + ui, + _("jmexico.error.scenario.importFile.required"), + _("jmexico.title.error"), + JOptionPane.ERROR_MESSAGE); + } + + if (valid) { + + // check scenario name is not used + String selectedName = model.getScenarioName(); + + if (StringUtils.isBlank(selectedName)) { + + valid = false; + JOptionPane.showMessageDialog( + ui, + _("jmexico.error.scenario.name.required"), + _("jmexico.title.error"), + JOptionPane.ERROR_MESSAGE); + + } else { + valid = isScenarioNameAvailable(selectedName); + } + } + doIt = valid || showImportScenarioUI(model); + } + return doIt; + } + protected int getMaxOrder() { int maxOrder = 0; Modified: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorModel.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorModel.java 2012-10-07 16:24:03 UTC (rev 87) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorModel.java 2012-10-07 16:24:50 UTC (rev 88) @@ -81,6 +81,10 @@ return tableModel; } + public List<Factor> getFactors() { + return factors; + } + public void setInputDesign(InputDesign inputDesign) { InputDesign oldValue = this.inputDesign; Modified: trunk/jmexico-editor/src/main/resources/i18n/jmexico-editor_en_GB.properties =================================================================== --- trunk/jmexico-editor/src/main/resources/i18n/jmexico-editor_en_GB.properties 2012-10-07 16:24:03 UTC (rev 87) +++ trunk/jmexico-editor/src/main/resources/i18n/jmexico-editor_en_GB.properties 2012-10-07 16:24:50 UTC (rev 88) @@ -1,15 +1,27 @@ jmexico.action.add.scenario=Add scenario jmexico.action.clone.scenario=Clone scenario +jmexico.action.export.scenario=Export scenario +jmexico.action.import.scenario=Import scenario jmexico.action.remove.scenario=Remove scenario -jmexico.error.scenario.name.required=Error\: Name of scenario is mandatory +jmexico.config.scenario.extension=scenario +jmexico.config.scenario.extension.description=JMexico scenario file (*.scenario) +jmexico.error.scenario.exportFile.required=Error\: Export file is mandatory. +jmexico.error.scenario.importFile.required=Error\: Import file is mandatory. +jmexico.error.scenario.name.required=Error\: Name of scenario is mandatory. jmexico.error.scenario.name.used=Error\: Name of scenario '%1$s' is already used. jmexico.error.scenario.not.selected=Error\: No scenario selected. jmexico.factor.name=Factor -jmexico.label.scenario.add.name=Name of scenario to add \: +jmexico.label.scenario.add.name=Name of scenario to add jmexico.label.scenario.clone.name=Name of new scenario jmexico.label.scenario.clone.selected=Scenario to clone +jmexico.label.scenario.export.file=Export file +jmexico.label.scenario.export.selected=Scenario to export +jmexico.label.scenario.import.file=Import file +jmexico.label.scenario.import.name=Name of new scenario jmexico.label.scenario.remove.selected=Scenario to delete jmexico.title.error=Error jmexico.title.scenario.add=Add a scenario jmexico.title.scenario.clone=Clone a scenario +jmexico.title.scenario.export=Import a scenario +jmexico.title.scenario.import=Export a scenario jmexico.title.scenario.remove=Remove a scenario Modified: trunk/jmexico-editor/src/main/resources/i18n/jmexico-editor_fr_FR.properties =================================================================== --- trunk/jmexico-editor/src/main/resources/i18n/jmexico-editor_fr_FR.properties 2012-10-07 16:24:03 UTC (rev 87) +++ trunk/jmexico-editor/src/main/resources/i18n/jmexico-editor_fr_FR.properties 2012-10-07 16:24:50 UTC (rev 88) @@ -1,6 +1,12 @@ jmexico.action.add.scenario=Ajouter un scénario jmexico.action.clone.scenario=Dupliquer un scénario +jmexico.action.export.scenario=Exporter un scénario +jmexico.action.import.scenario=Importer un scénario jmexico.action.remove.scenario=Supprimer un scénario +jmexico.config.scenario.extension=scenario +jmexico.config.scenario.extension.description=Scénario jmexico (*.scenario) +jmexico.error.scenario.exportFile.required=Erreur \: pas de fichier d'export choisi +jmexico.error.scenario.importFile.required= jmexico.error.scenario.name.required=Erreur \: le nom du scénario est obligatoire jmexico.error.scenario.name.used=Erreur \: le scenario '%1$s' est déjà utilisé. jmexico.error.scenario.not.selected=Erreur \: scénario à cloner non sélectionné. @@ -8,8 +14,14 @@ jmexico.label.scenario.add.name=Nom du scénario jmexico.label.scenario.clone.name=Nom du nouveau scénario jmexico.label.scenario.clone.selected=Scénario à dupliquer -jmexico.label.scenario.remove.selected=Selection du scénario à supprimer +jmexico.label.scenario.export.file=Fichier d'export +jmexico.label.scenario.export.selected=Sélection du scénarion à exporter +jmexico.label.scenario.import.file=Fichier d'import +jmexico.label.scenario.import.name=Nom du scénario à importer +jmexico.label.scenario.remove.selected=Sélection du scénario à supprimer jmexico.title.error=Erreur jmexico.title.scenario.add=Ajouter un scénario jmexico.title.scenario.clone=Dupliquer un scénario +jmexico.title.scenario.export=Exporter un scénario +jmexico.title.scenario.import=Importer un scénario jmexico.title.scenario.remove=Supprimer un scénario Modified: trunk/jmexico-editor-demo/src/main/java/fr/reseaumexico/editor/demo/MexicoEditorDemoUIHandler.java =================================================================== --- trunk/jmexico-editor-demo/src/main/java/fr/reseaumexico/editor/demo/MexicoEditorDemoUIHandler.java 2012-10-07 16:24:03 UTC (rev 87) +++ trunk/jmexico-editor-demo/src/main/java/fr/reseaumexico/editor/demo/MexicoEditorDemoUIHandler.java 2012-10-07 16:24:50 UTC (rev 88) @@ -125,11 +125,10 @@ // save modified model try { - InputDesignXmlWriter writer = new InputDesignXmlWriter(selectedFile, ui.getInputDesign()); + InputDesignXmlWriter writer = new InputDesignXmlWriter(ui.getInputDesign()); try { - writer.write(); + writer.write(selectedFile); } finally { - writer.close(); ui.getModel().setOptionChanged(false); } } catch (IOException eee) { @@ -139,21 +138,16 @@ } protected InputDesign readInputDesignFile(File selectedFile) { - InputDesign inputDesignModel = null; + InputDesign result = null; try { - // parse inputDesign - InputDesignParser inputDesignParser = new InputDesignParser(selectedFile); - try { - inputDesignModel = inputDesignParser.getModel(); - } finally { - inputDesignParser.close(); - } + InputDesignParser parser = new InputDesignParser(); + result = parser.getModel(selectedFile); } catch (Exception eee) { log.error("Failed to read inputDesign file '" + selectedFile.getName() + "'", eee); ErrorDialogUI.showError(eee); } - return inputDesignModel; + return result; } }
participants (1)
-
tchemit@users.forge.codelutin.com