Author: echatellier Date: 2014-07-21 16:03:27 +0200 (Mon, 21 Jul 2014) New Revision: 135 Url: http://forge.codelutin.com/projects/jmexico/repository/revisions/135 Log: fixes #5469: Add a way to rename an option Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioModel.java trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioPanel.css trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioPanel.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 trunk/jmexico-model/src/main/java/fr/reseaumexico/model/InputDesignImpl.java trunk/jmexico-model/src/main/xmi/mexico.zargo Modified: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/CloneScenarioModel.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/CloneScenarioModel.java 2014-07-21 13:05:39 UTC (rev 134) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/CloneScenarioModel.java 2014-07-21 14:03:27 UTC (rev 135) @@ -24,11 +24,6 @@ * #L% */ -import fr.reseaumexico.model.Scenario; -import org.jdesktop.beans.AbstractSerializableBean; - -import java.util.Collection; - /** * Model for clone scenario operation. * Modified: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.css =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.css 2014-07-21 13:05:39 UTC (rev 134) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.css 2014-07-21 14:03:27 UTC (rev 135) @@ -32,6 +32,11 @@ enabled:{model.getInputDesign() != null}; } +#renameScenarioButton { + text:"jmexico.action.rename.scenario"; + enabled:{model.getInputDesign() != null}; +} + #removeScenarioButton { text:"jmexico.action.remove.scenario"; enabled:{model.isScenarioExists()}; Modified: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx 2014-07-21 13:05:39 UTC (rev 134) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditor.jaxx 2014-07-21 14:03:27 UTC (rev 135) @@ -57,6 +57,8 @@ <JPanel id='editorToolBar' constraints='BorderLayout.SOUTH'> <JButton id='addScenarioButton' constraints='BorderLayout.WEST' onActionPerformed='getHandler().addScenario()'/> + <JButton id='renameScenarioButton' constraints='BorderLayout.WEST' + onActionPerformed='getHandler().renameScenario()'/> <JButton id='removeScenarioButton' constraints='BorderLayout.EAST' onActionPerformed='getHandler().removeScenario()'/> <JButton id='cloneScenarioButton' constraints='BorderLayout.EAST' Modified: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java 2014-07-21 13:05:39 UTC (rev 134) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorHandler.java 2014-07-21 14:03:27 UTC (rev 135) @@ -146,7 +146,34 @@ inputDesign.addScenario(scenarioToAdd); } } + + public void renameScenario() { + InputDesign inputDesign = ui.getInputDesign(); + + RenameScenarioModel model = new RenameScenarioModel(); + model.setScenarios(inputDesign.getScenario()); + + boolean accept = showRenameScenarioUI(model); + + if (accept) { + + // rename scenario + Collection<Scenario> scenarios = inputDesign.getScenario(); + for (Scenario scenario : scenarios) { + if (scenario.getName().equals(model.getScenarioName())) { + JOptionPane.showMessageDialog(ui, + _("jmexico.action.scenario.rename.alreadyexists", model.getScenarioName()), + _("jmexico.title.scenario.rename"), + JOptionPane.ERROR_MESSAGE); + return; + } + } + + inputDesign.renameScenario(model.getSelectedScenario(), model.getScenarioName()); + } + } + public void removeScenario() { InputDesign inputDesign = ui.getInputDesign(); @@ -445,7 +472,71 @@ return doIt; } + + protected boolean showRenameScenarioUI(RenameScenarioModel model) { + // show ui + + RenameScenarioPanel panel = new RenameScenarioPanel(); + panel.init(model); + + int response = JOptionPane.showConfirmDialog( + ui, + panel, + _("jmexico.title.scenario.rename"), + 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 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 || showRenameScenarioUI(model); + } + + return doIt; + } + protected boolean showExportScenarioUI(ExportScenarioModel model) { // show ui Modified: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorModel.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorModel.java 2014-07-21 13:05:39 UTC (rev 134) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/InputDesignEditorModel.java 2014-07-21 14:03:27 UTC (rev 135) @@ -113,6 +113,11 @@ fireScenarioModified(); } + @Override + public void scenarioRenamed(InputDesignScenarioEvent event) { + fireScenarioModified(); + } + public Collection<Scenario> getScenario() { return inputDesign == null ? null : inputDesign.getScenario(); } Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioModel.java =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioModel.java (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioModel.java 2014-07-21 14:03:27 UTC (rev 135) @@ -0,0 +1,54 @@ +package fr.reseaumexico.editor; + +/* + * #%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% + */ + +/** + * Model for rename scenario operation. + * + * @author Eric Chatellier + * @since 0.7 + */ +public class RenameScenarioModel extends AbstractScenarioModel<RenameScenarioModel> { + + private static final long serialVersionUID = 1L; + + protected String scenarioName; + + public String getScenarioName() { + return scenarioName; + } + + public void setScenarioName(String scenarioName) { + Object oldValue = this.scenarioName; + this.scenarioName = scenarioName; + firePropertyChange("scenarioName", oldValue, scenarioName); + } + + @Override + public void copyTo(RenameScenarioModel model) { + super.copyTo(model); + model.setScenarioName(getScenarioName()); + } +} Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioPanel.css =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioPanel.css (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioPanel.css 2014-07-21 14:03:27 UTC (rev 135) @@ -0,0 +1,38 @@ +/* + * #%L + * JMexico :: Swing Editor + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2014 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.rename.name"; +} + +#scenarioNameEditor { + text:{model.getScenarioName()}; +} + +#selectedScenarioLabel { + text:"jmexico.label.scenario.rename.selected"; +} + +#selectedScenarioEditor { + selectedItem:{model.getSelectedScenario()}; +} \ No newline at end of file Property changes on: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioPanel.css ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioPanel.jaxx =================================================================== --- trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioPanel.jaxx (rev 0) +++ trunk/jmexico-editor/src/main/java/fr/reseaumexico/editor/RenameScenarioPanel.jaxx 2014-07-21 14:03:27 UTC (rev 135) @@ -0,0 +1,59 @@ +<!-- + #%L + JMexico :: Swing Editor + $Id: CloneScenarioPanel.jaxx 84 2012-10-07 11:38:35Z tchemit $ + $HeadURL: https://svn.codelutin.com/jmexico/trunk/jmexico-editor/src/main/java/fr/rese... $ + %% + Copyright (C) 2014 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()}'> + + <RenameScenarioModel id='model'/> + + <script> + <![CDATA[ +public void init(RenameScenarioModel 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='scenarioNameLabel'/> + </cell> + <cell> + <JTextField id='scenarioNameEditor' + onKeyReleased='model.setScenarioName(((JTextField)event.getSource()).getText())'/> + </cell> + </row> +</Table> 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 2014-07-21 13:05:39 UTC (rev 134) +++ trunk/jmexico-editor/src/main/resources/i18n/jmexico-editor_en_GB.properties 2014-07-21 14:03:27 UTC (rev 135) @@ -3,6 +3,8 @@ jmexico.action.export.scenario=Export scenario jmexico.action.import.scenario=Import scenario jmexico.action.remove.scenario=Remove scenario +jmexico.action.rename.scenario=Rename scenario +jmexico.action.scenario.rename.alreadyexists=A scenario named %s already exists \! jmexico.config.scenario.extension=scenario jmexico.config.scenario.extension.csv=csv jmexico.config.scenario.extension.csv.description=JMexico scenario file (*.csv) @@ -24,6 +26,8 @@ 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.label.scenario.rename.name=New scenario name +jmexico.label.scenario.rename.selected=Scenario to rename jmexico.title.error=Error jmexico.title.importScenario=Import a scenario jmexico.title.scenario.add=Add a scenario @@ -31,4 +35,5 @@ jmexico.title.scenario.export=Import a scenario jmexico.title.scenario.import=Export a scenario jmexico.title.scenario.remove=Remove a scenario +jmexico.title.scenario.rename=Rename a scenario jmexico.warning.factor.not.imported=There is %s factor which do not exist in model, their values can not be imported\: %s 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 2014-07-21 13:05:39 UTC (rev 134) +++ trunk/jmexico-editor/src/main/resources/i18n/jmexico-editor_fr_FR.properties 2014-07-21 14:03:27 UTC (rev 135) @@ -3,6 +3,8 @@ 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.action.rename.scenario=Renommer un scénario +jmexico.action.scenario.rename.alreadyexists=Un scénario nommé %s existe déjà \! jmexico.config.scenario.extension=scenario jmexico.config.scenario.extension.csv=csv jmexico.config.scenario.extension.csv.description=Scénario jmexico (*.csv) @@ -24,6 +26,8 @@ jmexico.label.scenario.import.file=Fichier d'import jmexico.label.scenario.import.name=Nom du scénario à importer jmexico.label.scenario.remove.selected=Scénario à supprimer +jmexico.label.scenario.rename.name=Nouveau nom du scénario +jmexico.label.scenario.rename.selected=Scénario à renommer jmexico.title.error=Erreur jmexico.title.importScenario=Import de scénario jmexico.title.scenario.add=Ajouter un scénario @@ -31,4 +35,5 @@ jmexico.title.scenario.export=Exporter un scénario jmexico.title.scenario.import=Importer un scénario jmexico.title.scenario.remove=Supprimer un scénario +jmexico.title.scenario.rename=Renommer un scénario jmexico.warning.factor.not.imported=Il existe %s facteurs qui n'existent pas dans le modèle, leurs valeurs ne sont pas importées \: %s. 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 2014-07-21 13:05:39 UTC (rev 134) +++ trunk/jmexico-editor-demo/src/main/java/fr/reseaumexico/editor/demo/MexicoEditorDemoUIHandler.java 2014-07-21 14:03:27 UTC (rev 135) @@ -111,6 +111,11 @@ public void scenarioRemoved(InputDesignScenarioEvent event) { ui.setInputDesign(event.getSource()); } + + @Override + public void scenarioRenamed(InputDesignScenarioEvent event) { + ui.setInputDesign(event.getSource()); + } }); ui.setInputDesign(inputDesign); Modified: trunk/jmexico-model/src/main/java/fr/reseaumexico/model/InputDesignImpl.java =================================================================== --- trunk/jmexico-model/src/main/java/fr/reseaumexico/model/InputDesignImpl.java 2014-07-21 13:05:39 UTC (rev 134) +++ trunk/jmexico-model/src/main/java/fr/reseaumexico/model/InputDesignImpl.java 2014-07-21 14:03:27 UTC (rev 135) @@ -26,16 +26,19 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; + import fr.reseaumexico.model.event.InputDesignFactorEvent; import fr.reseaumexico.model.event.InputDesignFactorListener; import fr.reseaumexico.model.event.InputDesignScenarioEvent; import fr.reseaumexico.model.event.InputDesignScenarioListener; import fr.reseaumexico.model.event.ScenarioFactorValueEvent; import fr.reseaumexico.model.event.ScenarioFactorValueListener; + import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Collection; import java.util.Map; + import javax.swing.event.EventListenerList; /** @@ -95,6 +98,12 @@ } @Override + public void renameScenario(Scenario scenario, String newName) { + scenario.setName(newName); + fireInputDesignScenarioRenamed(scenario); + } + + @Override public void addAllScenario(Collection<Scenario> scenarios) { for (Scenario scenario : scenarios) { addScenario(scenario); @@ -152,6 +161,14 @@ listener.scenarioAdded(event); } } + + protected void fireInputDesignScenarioRenamed(Scenario scenario) { + InputDesignScenarioEvent event = new InputDesignScenarioEvent(this, scenario); + InputDesignScenarioListener[] listeners = listenerList.getListeners(InputDesignScenarioListener.class); + for (InputDesignScenarioListener listener : listeners) { + listener.scenarioRenamed(event); + } + } protected void fireInputDesignScenarioRemoved(Scenario scenario) { InputDesignScenarioEvent event = new InputDesignScenarioEvent(this, scenario); Modified: trunk/jmexico-model/src/main/xmi/mexico.zargo =================================================================== (Binary files differ)