r4263 - in trunk: . src/main/java/fr/ifremer/isisfish src/main/java/fr/ifremer/isisfish/aspect src/main/java/fr/ifremer/isisfish/datastore src/main/java/fr/ifremer/isisfish/export src/main/java/fr/ifremer/isisfish/ui src/main/java/fr/ifremer/isisfish/ui/config src/main/java/fr/ifremer/isisfish/ui/input src/main/java/fr/ifremer/isisfish/ui/input/equation src/main/java/fr/ifremer/isisfish/ui/input/fisheryregion src/main/java/fr/ifremer/isisfish/ui/input/population src/main/java/fr/ifremer/
Author: echatellier Date: 2015-06-11 09:01:47 +0000 (Thu, 11 Jun 2015) New Revision: 4263 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4263 Log: merge branch /branches/isis-fish-4.4.0-editor merge branch /branches/isis-fish-4.4.0-ui-refactoring Added: trunk/src/main/java/fr/ifremer/isisfish/ui/SimulationHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxConstants.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/LogTokenMarker.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxEditor.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxEditorUI.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxTokenManagerFactory.java trunk/src/main/resources/icons/README.txt trunk/src/main/resources/icons/common/ trunk/src/main/resources/icons/common/exclamation.png trunk/src/main/resources/icons/input/ trunk/src/main/resources/icons/script/ trunk/src/main/resources/icons/sensitivity/ Removed: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxContants.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxEditor.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenManagerFactory.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenMarker.java trunk/src/main/resources/icons/accept.png trunk/src/main/resources/icons/add.png trunk/src/main/resources/icons/arrow_undo.png trunk/src/main/resources/icons/building.png trunk/src/main/resources/icons/building_add.png trunk/src/main/resources/icons/camera.png trunk/src/main/resources/icons/cancel.png trunk/src/main/resources/icons/connect.png trunk/src/main/resources/icons/cut.png trunk/src/main/resources/icons/database.png trunk/src/main/resources/icons/database_add.png trunk/src/main/resources/icons/database_connect.png trunk/src/main/resources/icons/database_delete.png trunk/src/main/resources/icons/database_edit.png trunk/src/main/resources/icons/database_error.png trunk/src/main/resources/icons/database_gear.png trunk/src/main/resources/icons/database_go.png trunk/src/main/resources/icons/database_key.png trunk/src/main/resources/icons/database_lightning.png trunk/src/main/resources/icons/database_link.png trunk/src/main/resources/icons/database_refresh.png trunk/src/main/resources/icons/database_save.png trunk/src/main/resources/icons/database_table.png trunk/src/main/resources/icons/delete.png trunk/src/main/resources/icons/page_copy.png trunk/src/main/resources/icons/page_paste.png trunk/src/main/resources/icons/page_white_compressed.png trunk/src/main/resources/icons/paintbrush.png trunk/src/main/resources/icons/resultset_next.png trunk/src/main/resources/icons/resultset_previous.png trunk/src/main/resources/icons/script.png trunk/src/main/resources/icons/script_add.png trunk/src/main/resources/icons/script_code.png trunk/src/main/resources/icons/script_code_red.png trunk/src/main/resources/icons/script_delete.png trunk/src/main/resources/icons/script_edit.png trunk/src/main/resources/icons/script_error.png trunk/src/main/resources/icons/script_gear.png trunk/src/main/resources/icons/script_go.png trunk/src/main/resources/icons/script_key.png trunk/src/main/resources/icons/script_lightning.png trunk/src/main/resources/icons/script_link.png trunk/src/main/resources/icons/script_palette.png trunk/src/main/resources/icons/script_save.png trunk/src/main/resources/icons/table.png trunk/src/main/resources/icons/table_multiple.png trunk/src/main/resources/icons/tick.png trunk/src/main/resources/icons/wrench.png trunk/src/main/resources/icons/wrench_orange.png Modified: trunk/ trunk/pom.xml trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java trunk/src/main/java/fr/ifremer/isisfish/aspect/AspectJWeavingAdaptor.java trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationInformation.java trunk/src/main/java/fr/ifremer/isisfish/export/ExportStep.java trunk/src/main/java/fr/ifremer/isisfish/ui/SimulationUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/EquationEditorPaneUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/InputOneEquationHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/InputOneEquationUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/input/fisheryregion/FisheryRegionHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/input/population/PopulationRecruitmentUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/logging/LoggingFrame.java trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleNamesListRenderer.java trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleParametersFactorTableCellEditor.java trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleParametersFactorTableCellRenderer.java trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeCellRenderer.java trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityChooserHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityContext.java trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivitySecondPassHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/FactorWizardHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ExportHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PlanHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PlanUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PreScriptsHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ResultChoiceHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooser.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooserHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorContext.java trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorTabHandler.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/FilterableComboBox.java trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/EquationTableEditor.java trunk/src/main/resources/i18n/isis-fish_en_GB.properties trunk/src/main/resources/i18n/isis-fish_fr_FR.properties trunk/src/test/java/fr/ifremer/isisfish/equation/EquationTest.java trunk/src/test/java/fr/ifremer/isisfish/ui/input/InputIT.java Property changes on: trunk ___________________________________________________________________ Added: svn:mergeinfo + /branches/isis-fish-4.4.0-editor:4243-4262 /branches/isis-fish-4.4.0-ui-refactoring:4246-4262 Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/pom.xml 2015-06-11 09:01:47 UTC (rev 4263) @@ -112,15 +112,26 @@ <dependency> <groupId>com.fifesoft</groupId> <artifactId>rsyntaxtextarea</artifactId> - <version>2.5.0</version> - <scope>compile</scope> + <version>2.5.6</version> </dependency> <dependency> <groupId>com.fifesoft</groupId> <artifactId>rstaui</artifactId> - <version>2.5.0</version> + <version>2.5.4</version> </dependency> + + <dependency> + <groupId>com.fifesoft</groupId> + <artifactId>autocomplete</artifactId> + <version>2.5.4</version> + </dependency> + + <dependency> + <groupId>com.fifesoft</groupId> + <artifactId>languagesupport</artifactId> + <version>2.5.6</version> + </dependency> <dependency> <groupId>javax.mail</groupId> @@ -391,13 +402,13 @@ <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-swing</artifactId> - <version>2.0.0</version> + <version>2.0.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-swing-junit</artifactId> - <version>2.0.0</version> + <version>2.0.2</version> <scope>test</scope> </dependency> </dependencies> @@ -595,14 +606,6 @@ <groupId>org.nuiton.jaxx</groupId> <artifactId>jaxx-maven-plugin</artifactId> <version>${jaxxVersion}</version> - <dependencies> - <dependency> - <groupId>com.fifesoft</groupId> - <artifactId>rsyntaxtextarea</artifactId> - <version>2.5.0</version> - <scope>compile</scope> - </dependency> - </dependencies> </plugin> <plugin> Modified: trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -749,10 +749,12 @@ WelcomeTabUI tabUI = (WelcomeTabUI)welcome.getWelcomePanelUI().getComponent(1); tabUI.getSimulUI().getBodyTabbedPane().setSelectedIndex(0); tabUI.getSensitivityUI().getBodyTabbedPane().setSelectedIndex(0); - + // never restore iconifed state (wevy boring) + welcome.setExtendedState(welcome.getExtendedState() & ~WelcomeUI.ICONIFIED); + // display frame welcome.setVisible(true); - + // SimulationService service = SimulationService.getService(); SimulationMonitor.getInstance().reloadConfig(service); Modified: trunk/src/main/java/fr/ifremer/isisfish/aspect/AspectJWeavingAdaptor.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/aspect/AspectJWeavingAdaptor.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/aspect/AspectJWeavingAdaptor.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -57,7 +57,7 @@ * Cette classe étend {@link WeavingAdaptor} pour avoir une instance personnalisée du champ {@link #weaver}. * * Toutes la logique consiste ensuite à pouvoir appeler le code {@code weaver.weave(wcp);} pour pouvoir déployer un - * apect à l'execution dans le {@code weaver} qui servira ensuite à "aspectiser une classe" via la méthode + * aspect à l'execution dans le {@code weaver} qui servira ensuite à "aspectiser une classe" via la méthode * {@link #weaveClass(String, byte[])}. * * Elle utilise pour l'instant de l'introspection agressive pour acceder aux attributs privés de la classe parentes et Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageCSV.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -136,7 +136,7 @@ new LinkedHashMap<TimeStep, Map<String, MatrixND>>() { private static final long serialVersionUID = 1L; @Override - protected boolean removeEldestEntry(Map.Entry eldest) { + protected boolean removeEldestEntry(Map.Entry<TimeStep, Map<String, MatrixND>> eldest) { return size() > cacheStep; } }; Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/ResultStorageInMemory.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -67,7 +67,7 @@ LinkedHashMap<TimeStep, Map<String, MatrixND>> data = new LinkedHashMap<TimeStep, Map<String, MatrixND>>() { private static final long serialVersionUID = 1L; @Override - protected boolean removeEldestEntry(Map.Entry eldest) { + protected boolean removeEldestEntry(Map.Entry<TimeStep, Map<String, MatrixND>> eldest) { return size() > maxTimeStep; } }; @@ -75,7 +75,7 @@ LinkedHashMap<TimeStep, List<String>> rules = new LinkedHashMap<TimeStep, List<String>>() { private static final long serialVersionUID = 1L; @Override - protected boolean removeEldestEntry(Map.Entry eldest) { + protected boolean removeEldestEntry(Map.Entry<TimeStep, List<String>> eldest) { return size() > maxTimeStep; } }; Modified: trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationInformation.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationInformation.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/datastore/SimulationInformation.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -36,9 +36,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; import java.util.Set; Modified: trunk/src/main/java/fr/ifremer/isisfish/export/ExportStep.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/export/ExportStep.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/export/ExportStep.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -62,7 +62,7 @@ throws Exception; /** - * Appeler a la fin de l'export + * Appeler a la fin de la simulation. * * @param simulation la simulation dont on souhaite exporter les resultats * @param out la sortie sur lequel il faut ecrire l'export Copied: trunk/src/main/java/fr/ifremer/isisfish/ui/SimulationHandler.java (from rev 4262, branches/isis-fish-4.4.0-ui-refactoring/src/main/java/fr/ifremer/isisfish/ui/SimulationHandler.java) =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/SimulationHandler.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/SimulationHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -0,0 +1,147 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric + * %% + * 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 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.ui; + +import static org.nuiton.i18n.I18n.t; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.Properties; + +import javax.swing.JFileChooser; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import fr.ifremer.isisfish.simulator.SimulationParameter; +import fr.ifremer.isisfish.ui.util.ErrorHelper; + +/** + * Common action for all handler. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class SimulationHandler { + + private static final Log log = LogFactory.getLog(SimulationHandler.class); + + public SimulationUI simulationUI; + + public SimulationHandler(SimulationUI simulationUI) { + this.simulationUI = simulationUI; + } + + protected SimulationParameter getParameters() { + return simulationUI.getContextValue(SimulationParameter.class); + } + + public void afterInit() { + simulationUI.addPropertyChangeListener(SimulationUI.PROPERTY_REGION_STORAGE, new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + simulationUI.regionStorageChanged(); + } + }); + + // FIXME c'est un hack qu'il faudrait supprimer + // c'est utilisé à l'arrache par certaines interfaces pour mettre à jour l'arbre de facteur + simulationUI.setContextValue(simulationUI, "SimulationUI"); + } + + /** + * Open user dialog to selected a parameter file. + * Reload it, and call {@link SimulationUI#refresh()}. + */ + public void importSimulation() { + JFileChooser fc = new JFileChooser(); + int returnVal = fc.showOpenDialog(simulationUI); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + //This is where a real application would open the file. + importSimulation(file); + simulationUI.refresh(); + } + } + + /** + * Save current parameter in user selected parameter output file. + */ + public void saveSimulation() { + JFileChooser fc = new JFileChooser(); + int returnVal = fc.showSaveDialog(simulationUI); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + File file = fc.getSelectedFile(); + //This is where a real application would open the file. + saveSimulation(file); + } + } + + /** + * Load simulation parameter file. + * + * @param f + * + * TODO public just for sensitivity + */ + protected void importSimulation(File f) { + + try (FileInputStream fos = new FileInputStream(f)) { + + Properties proper = new Properties(); + proper.load(fos); + getParameters().fromProperties(proper); + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Can't import simulation", e); + } + ErrorHelper.showErrorDialog(t("isisfish.error.simulation.importparameter"), e); + } + } + + /** + * Save current simulation to given file. + * + * @param f file to save simulation to + * + * TODO public just for sensitivity + */ + protected void saveSimulation(File f) { + try (FileOutputStream fos = new FileOutputStream(f)) { + getParameters().toProperties().store(fos, null); // XXX: was simulName instead of null + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Can't save simulation", e); + } + ErrorHelper.showErrorDialog(t("isisfish.error.simulation.savesimulation"), e); + } + } +} Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/SimulationUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/SimulationUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/SimulationUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -23,24 +23,15 @@ #L% --> <JPanel layout='{new BorderLayout()}' abstract="true"> - <import> - fr.ifremer.isisfish.ui.simulator.SimulAction; - java.beans.PropertyChangeEvent; - java.beans.PropertyChangeListener; - javax.swing.JFileChooser - java.io.File - </import> + <SimulationHandler id="handler" constructorParams="this" /> + <fr.ifremer.isisfish.datastore.RegionStorage id="regionStorage" javaBean="null" /> <script><![CDATA[ protected void $afterCompleteSetup() { - addPropertyChangeListener(PROPERTY_REGION_STORAGE, new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - regionStorageChanged(); - } - }); + handler.afterInit(); } /** @@ -74,36 +65,6 @@ public abstract void setEnabledOptimizationTab(boolean selected); /** - * Open user dialog to selected a parameter file. - * Reload it, and call {@link #refresh()}. - */ - protected void importSimulation() { - JFileChooser fc = new JFileChooser(); - int returnVal = fc.showOpenDialog(this); - - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fc.getSelectedFile(); - //This is where a real application would open the file. - getContextValue(SimulAction.class).importSimulation(file); - refresh(); - } - } - - /** - * Save current parameter in user selected parameter output file. - */ - public void saveSimulation() { - JFileChooser fc = new JFileChooser(); - int returnVal = fc.showSaveDialog(this); - - if (returnVal == JFileChooser.APPROVE_OPTION) { - File file = fc.getSelectedFile(); - //This is where a real application would open the file. - getContextValue(SimulAction.class).saveSimulation(file); - } - } - - /** * Rafraichit l'arbre des facteurs. */ public void refreshFactorTree() { @@ -112,8 +73,8 @@ ]]></script> <JMenuBar constraints='BorderLayout.NORTH'> <JMenu text="isisfish.simulation.menu.simulation"> - <JMenuItem id="miSave" text="isisfish.simulation.menu.save" onActionPerformed="saveSimulation()"/> - <JMenuItem id="miImport" text="isisfish.simulation.menu.import" onActionPerformed="importSimulation()"/> + <JMenuItem id="miSave" text="isisfish.simulation.menu.save" onActionPerformed="handler.saveSimulation()"/> + <JMenuItem id="miImport" text="isisfish.simulation.menu.import" onActionPerformed="handler.importSimulation()"/> </JMenu> </JMenuBar> <JTabbedPane id="bodyTabbedPane" constraints='BorderLayout.CENTER' decorator="boxed"/> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -22,14 +22,18 @@ */ package fr.ifremer.isisfish.ui; +import java.awt.AWTException; import java.awt.Component; import java.awt.Rectangle; import java.awt.Robot; import java.awt.image.BufferedImage; import java.io.File; +import java.io.IOException; + import javax.imageio.ImageIO; import javax.swing.JFileChooser; import javax.swing.SwingUtilities; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -80,31 +84,30 @@ } final Component realParent = parent; - // ask user for file - int opt = screenshotFileChooser.showSaveDialog(realParent); - if (opt == JFileChooser.APPROVE_OPTION) { - File file = screenshotFileChooser.getSelectedFile(); + try { + // take screenshot + // we must take screenshot BEFORE filechooser display + Rectangle screenRect = realParent.getBounds(); + final BufferedImage capture = new Robot().createScreenCapture(screenRect); - // add "png" if not yet set - if (!file.getName().endsWith(".png")) { - file = new File(file.getAbsolutePath() + ".png"); + // ask user for file + int opt = screenshotFileChooser.showSaveDialog(realParent); + if (opt == JFileChooser.APPROVE_OPTION) { + File file = screenshotFileChooser.getSelectedFile(); + + // add "png" if not yet set + if (!file.getName().endsWith(".png")) { + file = new File(file.getAbsolutePath() + ".png"); + } + final File realFile = file; + + // save screenshot + ImageIO.write(capture, "png", realFile); } - final File realFile = file; - - SwingUtilities.invokeLater(new Runnable() { - public void run() { - // take screenshot - try { - Rectangle screenRect = realParent.getBounds(); - BufferedImage capture = new Robot().createScreenCapture(screenRect); - ImageIO.write(capture, "png", realFile); - } catch (Exception ex) { - if (log.isErrorEnabled()) { - log.error("Can't show help", ex); - } - } - } - }); + } catch (AWTException|IOException ex) { + if (log.isErrorEnabled()) { + log.error("Can't take screenshot help", ex); + } } } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -62,7 +62,7 @@ toolTipText="Stop the process" /> </cell> --> <cell> - <JLabel icon="camera.png" toolTipText="isisfish.status.screenshot" onMouseClicked="handler.screenshot()" /> + <JLabel icon="common/camera.png" toolTipText="isisfish.status.screenshot" onMouseClicked="handler.screenshot()" /> </cell> <cell fill="both"> <jaxx.runtime.swing.StatusMessagePanel /> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -28,40 +28,40 @@ <script><![CDATA[ protected void $afterCompleteSetup() { - getHandler().afterInit(); + handler.afterInit(); } ]]></script> <JMenuBar> <JMenu text='isisfish.welcome.menu.file'> - <JMenuItem text="isisfish.welcome.menu.synchro" enabled='false' onActionPerformed='getHandler().updateVCS(this)'/> + <JMenuItem text="isisfish.welcome.menu.synchro" enabled='false' onActionPerformed='handler.updateVCS(this)'/> <JSeparator/> - <JMenuItem text="isisfish.welcome.menu.close" onActionPerformed='getHandler().close(this)'/> + <JMenuItem text="isisfish.welcome.menu.close" onActionPerformed='handler.close(this)'/> </JMenu> <JMenu text="isisfish.welcome.menu.frame"> - <JMenuItem text="isisfish.welcome.menu.simulation" onActionPerformed='getHandler().newSimulationFrame(this)'/> - <JMenuItem text="isisfish.welcome.menu.result" onActionPerformed='getHandler().newResultFrame(this)'/> - <JMenuItem text="isisfish.welcome.menu.input" onActionPerformed='getHandler().newInputFrame(this)'/> - <JMenuItem text="isisfish.welcome.menu.script" onActionPerformed='getHandler().newScriptFrame(this)'/> - <JMenuItem text="isisfish.sensitivity.title" onActionPerformed='getHandler().newSensitivityFrame(this)'/> + <JMenuItem text="isisfish.welcome.menu.simulation" onActionPerformed='handler.newSimulationFrame(this)'/> + <JMenuItem text="isisfish.welcome.menu.result" onActionPerformed='handler.newResultFrame(this)'/> + <JMenuItem text="isisfish.welcome.menu.input" onActionPerformed='handler.newInputFrame(this)'/> + <JMenuItem text="isisfish.welcome.menu.script" onActionPerformed='handler.newScriptFrame(this)'/> + <JMenuItem text="isisfish.sensitivity.title" onActionPerformed='handler.newSensitivityFrame(this)'/> <JSeparator/> - <JMenuItem text="isisfish.welcome.menu.queue" onActionPerformed='getHandler().newQueueFrame(this)'/> + <JMenuItem text="isisfish.welcome.menu.queue" onActionPerformed='handler.newQueueFrame(this)'/> </JMenu> <JMenu text="isisfish.welcome.menu.configuration"> - <JMenuItem text="isisfish.welcome.menu.configuration" onActionPerformed='getHandler().config(this)'/> - <JMenuItem text="isisfish.welcome.menu.configuration.vcs" onActionPerformed='getHandler().configVCS(this)' enabled="false"/> - <JMenuItem text="isisfish.welcome.menu.configuration.sshlauncher" onActionPerformed='getHandler().configurationSSHLauncher(this)'/> - <JMenuItem text="isisfish.welcome.menu.configuration.r" onActionPerformed='getHandler().configurationR(this)'/> + <JMenuItem text="isisfish.welcome.menu.configuration" onActionPerformed='handler.config(this)'/> + <JMenuItem text="isisfish.welcome.menu.configuration.vcs" onActionPerformed='handler.configVCS(this)' enabled="false"/> + <JMenuItem text="isisfish.welcome.menu.configuration.sshlauncher" onActionPerformed='handler.configurationSSHLauncher(this)'/> + <JMenuItem text="isisfish.welcome.menu.configuration.r" onActionPerformed='handler.configurationR(this)'/> </JMenu> <JMenu text="isisfish.welcome.menu.help"> - <JMenuItem text="isisfish.welcome.menu.help.isisfish" onActionPerformed='getHandler().help(this, "ISISFISH")'/> + <JMenuItem text="isisfish.welcome.menu.help.isisfish" onActionPerformed='handler.help(this, "ISISFISH")'/> <JMenu text="isisfish.welcome.menu.api"> - <JMenuItem text="isisfish.welcome.menu.help.javaapi" onActionPerformed='getHandler().help(this, "JAVA_API")'/> - <JMenuItem text="isisfish.welcome.menu.help.isisfishapi" onActionPerformed='getHandler().help(this, "ISIS_API")'/> - <JMenuItem text="isisfish.welcome.menu.help.matrixapi" onActionPerformed='getHandler().help(this, "MATRIX_API")'/> - <JMenuItem text="isisfish.welcome.menu.help.topiaapi" onActionPerformed='getHandler().help(this, "TOPIA_API")'/> + <JMenuItem text="isisfish.welcome.menu.help.javaapi" onActionPerformed='handler.help(this, "JAVA_API")'/> + <JMenuItem text="isisfish.welcome.menu.help.isisfishapi" onActionPerformed='handler.help(this, "ISIS_API")'/> + <JMenuItem text="isisfish.welcome.menu.help.matrixapi" onActionPerformed='handler.help(this, "MATRIX_API")'/> + <JMenuItem text="isisfish.welcome.menu.help.topiaapi" onActionPerformed='handler.help(this, "TOPIA_API")'/> </JMenu> <JSeparator/> - <JMenuItem text="isisfish.welcome.menu.about" onActionPerformed='getHandler().about(this)'/> + <JMenuItem text="isisfish.welcome.menu.about" onActionPerformed='handler.about(this)'/> </JMenu> </JMenuBar> <WelcomePanelUI id="welcomePanelUI" constructorParams='this'/> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/config/SSHLauncherConfigUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -185,16 +185,16 @@ <Table> <row fill='horizontal'> <cell fill='horizontal' weightx="1.0"> - <JButton id='testButton' text='isisfish.simulator.ssh.configuration.test' onActionPerformed="handler.testSSHConfiguration()" icon="connect.png" /> + <JButton id='testButton' text='isisfish.simulator.ssh.configuration.test' onActionPerformed="handler.testSSHConfiguration()" icon="common/plug-connect.png" /> </cell> <cell fill='horizontal' weightx="1.0"> - <JButton id='validButton' text='isisfish.common.valid' onActionPerformed="handler.saveSSHConfiguration()" icon="accept.png" enabled='{isConnected()}' /> + <JButton id='validButton' text='isisfish.common.valid' onActionPerformed="handler.saveSSHConfiguration()" icon="common/tick-button.png" enabled='{isConnected()}' /> </cell> <cell fill='horizontal' weightx="1.0"> - <JButton id='resetButton' text='isisfish.common.reset' onActionPerformed="handler.resetSSHConfiguration()" icon="arrow_undo.png" /> + <JButton id='resetButton' text='isisfish.common.reset' onActionPerformed="handler.resetSSHConfiguration()" icon="common/pencil-button.png" /> </cell> <cell fill='horizontal' weightx="1.0"> - <JButton id='cancelButton' text='isisfish.common.cancel' onActionPerformed="handler.cancelSSHConfiguration()" icon="cancel.png" /> + <JButton id='cancelButton' text='isisfish.common.cancel' onActionPerformed="handler.cancelSSHConfiguration()" icon="common/cross-button.png" /> </cell> </row> </Table> @@ -215,7 +215,7 @@ <JLabel id='statusFreeDatabaseLabel' enabled='{isConnected()}' /> </cell> <cell> - <JButton id='clearDatabaseButton' text='isisfish.common.clear' icon="paintbrush.png" + <JButton id='clearDatabaseButton' text='isisfish.common.clear' icon="common/broom.png" onActionPerformed="handler.clearDatabase()" enabled='{isConnected()}' /> </cell> </row> @@ -224,7 +224,7 @@ <JLabel id='statusFreeTempLabel' enabled='{isConnected()}' /> </cell> <cell> - <JButton id='clearTempButton' text='isisfish.common.clear' icon="paintbrush.png" + <JButton id='clearTempButton' text='isisfish.common.clear' icon="common/broom.png" onActionPerformed="handler.clearTempDirectory()" enabled='{isConnected()}' /> </cell> </row> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputContentUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -42,8 +42,8 @@ <!-- Layer avec les icones permettant d'ajouter des facteurs --> <jaxx.runtime.swing.BlockingLayerUI2 id='layerUI2' - blockIcon='{SwingUtil.createImageIcon("building.png")}' - acceptIcon='{SwingUtil.createImageIcon("building_add.png")}' + blockIcon='{SwingUtil.createImageIcon("sensitivity/flag.png")}' + acceptIcon='{SwingUtil.createImageIcon("sensitivity/flag--plus.png")}' acceptAction='{new AbstractAction() { private static final long serialVersionUID = 1L; @Override Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/EquationEditorPaneUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/EquationEditorPaneUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/EquationEditorPaneUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -49,7 +49,8 @@ <cell> <JSplitPane id='split' orientation='vertical' oneTouchExpandable='true' resizeWeight='0.8'> - <org.nuiton.widget.editor.Editor id="editor" askIfNotSaved="false" /> + <!--org.nuiton.widget.editor.Editor id="editor" askIfNotSaved="false" /--> + <fr.ifremer.isisfish.ui.widget.text.SyntaxEditor id='editor' askIfNotSaved="false" /> <JScrollPane> <JTextArea id="checkWindow" editable="false" /> </JScrollPane> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/InputOneEquationHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/InputOneEquationHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/InputOneEquationHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -42,7 +42,6 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; import org.nuiton.util.FileUtil; -import org.nuiton.widget.editor.Editor; import fr.ifremer.isisfish.datastore.FormuleStorage; import fr.ifremer.isisfish.entities.Equation; @@ -50,6 +49,7 @@ import fr.ifremer.isisfish.ui.input.InputContentHandler; import fr.ifremer.isisfish.ui.models.common.GenericComboModel; import fr.ifremer.isisfish.ui.util.ErrorHelper; +import fr.ifremer.isisfish.ui.widget.text.SyntaxEditor; /** * Equation handler. @@ -162,7 +162,7 @@ inputContentUI.setText(t("isisfish.common.equation")); } - inputContentUI.editor.getCurrentEditor().removeDocumentListener(listener); + inputContentUI.editor.removeDocumentListener(listener); try { File equationContentFile = FileUtil.getTempFile("", ".java"); inputContentUI.editor.open(equationContentFile); @@ -184,7 +184,7 @@ // le contenu de l'equation ne doit pas automatiquement // etre sauvé dans l'entité (pas de sens pour un facteur discret de type equation) if (inputContentUI.autoSaveModification) { - inputContentUI.editor.getCurrentEditor().addDocumentListener(listener); + inputContentUI.editor.addDocumentListener(listener); } } @@ -252,7 +252,7 @@ } public void openEditor(InputOneEquationUI ui, String category, String name, Class<?> javaInterface, - String content, Editor editor) { + String content, SyntaxEditor editor) { if (log.isTraceEnabled()) { log.trace("openEditor"); } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/InputOneEquationUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/InputOneEquationUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/equation/InputOneEquationUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -67,7 +67,8 @@ <JButton text="isisfish.common.saveModel" onActionPerformed='handler.saveModel()' enabled='{isActive() && formuleCategory != null}'/> </cell> <cell fill='both' weightx='1.0' weighty='1.0' rows="2"> - <org.nuiton.widget.editor.Editor id='editor' askIfNotSaved="false" enabled='{isActive()}'/> + <!-- org.nuiton.widget.editor.Editor id='editor' askIfNotSaved="false" enabled='{isActive()}'/--> + <fr.ifremer.isisfish.ui.widget.text.SyntaxEditor id='editor' askIfNotSaved="false" enabled='{isActive()}' /> </cell> </row> <row> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/fisheryregion/FisheryRegionHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/fisheryregion/FisheryRegionHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/fisheryregion/FisheryRegionHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -40,7 +40,6 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; import org.nuiton.util.FileUtil; -import org.nuiton.widget.SwingUtil; import fr.ifremer.isisfish.IsisFishDAOHelper; import fr.ifremer.isisfish.datastore.RegionStorage; @@ -252,7 +251,7 @@ CheckRegion.check(fisheryRegion, result); CheckResultFrame dialog = new CheckResultFrame(); dialog.setCheckResult(result); - SwingUtil.center(dialog); + dialog.setLocationByPlatform(true); dialog.setVisible(true); } catch (Exception eee) { if (log.isErrorEnabled()) { Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/input/population/PopulationRecruitmentUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/input/population/PopulationRecruitmentUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/input/population/PopulationRecruitmentUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -79,7 +79,7 @@ onMatrixChanged="handler.populationRecruitmentDistributionMatrixChanged(event)" /> </cell> <cell> - <JButton icon="table.png" toolTipText="isisfish.common.newMatrix" + <JButton icon="common/table--plus.png" toolTipText="isisfish.common.newMatrix" onActionPerformed="handler.createRecruitmentDistribution(getBean())" enabled='{isActive()}' decorator='boxed' /> </cell> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/logging/LoggingFrame.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/logging/LoggingFrame.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/logging/LoggingFrame.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -24,16 +24,20 @@ import static org.nuiton.i18n.I18n.t; +import java.awt.Frame; import java.io.File; import java.io.IOException; import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; import org.apache.commons.io.FileUtils; import fr.ifremer.isisfish.datastore.SimulationStorage; -import fr.ifremer.isisfish.ui.widget.text.IsisSyntaxContants; -import fr.ifremer.isisfish.ui.widget.text.IsisSyntaxEditor; +import fr.ifremer.isisfish.ui.widget.text.IsisSyntaxConstants; +import fr.ifremer.isisfish.ui.widget.text.SyntaxEditorUI; /** * Standalone frame to display log file with syntax highlight. @@ -45,18 +49,34 @@ /** serialVersionUID. */ private static final long serialVersionUID = -655585012872692567L; - protected IsisSyntaxEditor editor; + protected SyntaxEditorUI editor; public LoggingFrame() { - editor = new IsisSyntaxEditor(); - editor.setStyle(IsisSyntaxContants.SYNTAX_STYLE_LOG); + editor = new SyntaxEditorUI(); + editor.setStyle(IsisSyntaxConstants.SYNTAX_STYLE_LOG); add(editor); - setJMenuBar(editor.createMenuBar(this)); setSize(800, 600); } + + /** + * Return menu bar configured for {@code textArea} component. + * + * @param parent parent + * @return JMenuBar instance + */ + public JMenuBar createMenuBar(Frame parent) { + JMenuBar mb = new JMenuBar(); + JMenu menu = new JMenu(t("isisfish.script.search")); + menu.add(new JMenuItem(editor.getFindAction())); + menu.add(new JMenuItem(editor.getReplaceAction())); + menu.add(new JMenuItem(editor.getGotoAction())); + mb.add(menu); + return mb; + } + public void loadSimulationLog(String simulationName) throws IOException { setTitle(t("isisfish.simulation.log.console.title", simulationName)); Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleNamesListRenderer.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleNamesListRenderer.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleNamesListRenderer.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -27,6 +27,7 @@ import static org.nuiton.i18n.I18n.t; +import java.awt.Color; import java.awt.Component; import java.util.HashMap; import java.util.Map; @@ -76,7 +77,7 @@ String ruleName = (String)value; c.setText(ruleName); - + // c'est tres couteux d'avoir une instance // on les met en cache try { @@ -88,9 +89,11 @@ } c.setToolTipText(rule.getDescription()); + c.setForeground(null); } catch (Exception e) { String errorTooltip = TooltipHelper.getErrorTooltip(t("isisfish.error.compile.fileerror", ruleName)); c.setToolTipText(errorTooltip); + c.setForeground(Color.RED); } return c; Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleParametersFactorTableCellEditor.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleParametersFactorTableCellEditor.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleParametersFactorTableCellEditor.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -25,6 +25,12 @@ package fr.ifremer.isisfish.ui.models.rule; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.DOT; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.PARAMETERS_KEY; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.PARAMETER_KEY; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.RULE_KEY; +import static org.nuiton.i18n.I18n.t; + import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -42,9 +48,11 @@ import fr.ifremer.isisfish.IsisFishException; import fr.ifremer.isisfish.datastore.RuleStorage; import fr.ifremer.isisfish.rule.Rule; +import fr.ifremer.isisfish.simulator.sensitivity.Factor; import fr.ifremer.isisfish.simulator.sensitivity.SensitivityUtils; +import fr.ifremer.isisfish.ui.sensitivity.wizard.FactorWizardHandler; +import fr.ifremer.isisfish.ui.sensitivity.wizard.FactorWizardUI; import fr.ifremer.isisfish.ui.simulator.RuleChooser; -import fr.ifremer.isisfish.ui.simulator.SimulAction; /** * Specific editor for rule parameters. @@ -70,7 +78,7 @@ /** * Constructor. * - * Super dependant de l'ui {@link RuleChooser} et de {@link SimulAction}. + * Super dependant de l'ui {@link RuleChooser}. * * @param ruleChooser rule chooser ui * @param rule rule @@ -91,13 +99,12 @@ Class paramType = RuleStorage.getParameterType(rule, paramName); boolean canBeFactor = SensitivityUtils.canBeFactor(paramType); if (canBeFactor) { - JButton button = new JButton(Resource.getIcon("/icons/building_add.png")); + JButton button = new JButton(Resource.getIcon("/icons/sensitivity/flag--plus.png")); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cancelCellEditing(); - SimulAction simulAction = ruleChooser.getContextValue(SimulAction.class); - simulAction.addRuleParameterFactor(ruleChooser, rule, paramName); + addRuleParameterFactor(ruleChooser, rule, paramName); } }); comp = button; @@ -122,4 +129,62 @@ public Object getCellEditorValue() { return null; } + + /** + * Ajout d'un nouveau facteur sur un parametres de règles. + * + * Le facteur est directement crée avec un nom et un path correct. + * + * @param ruleChooser rule chooser + * @param rule rule + * @param paramName rule parameter name + */ + public void addRuleParameterFactor(RuleChooser ruleChooser, Rule rule, String paramName) { + + // get index of rule in rule list + // warning, factor path must always be cohérent + // with rule list, if a rule is deleted, factor on it must + // be deleted too, et next factor must be renamed + int index = ruleChooser.getRulesList().indexOf(rule); + String factorPath = PARAMETERS_KEY + DOT + RULE_KEY + DOT + index + DOT + + PARAMETER_KEY + DOT + paramName; + //try { + + /*// on a besoin de la valeur pour savoir s'il peut être continue + Object paramValue = RuleStorage.getParameterValue(rule, paramName); + + if (!SensitivityUtils.canBeContinue(paramValue)) { + // dans le cas ou il ne peut pas être continue, on le gere + // differement et on utilise sont type comme + // valeur + Class paramType = RuleStorage.getParameterType(rule, paramName); + factorPath += "." + paramType.getName(); + paramValue = paramType; + } + + // init new factor wizard ui + FactorWizardUI factorWizardUI = new FactorWizardUI(ruleChooser); + factorWizardUI.getFactorNameField().setText(t("isisfish.sensitivity.ruleparameterfactorname", + rule.getClass().getSimpleName(), paramName)); + factorWizardUI.setFactorPath(factorPath); + SensitivityWizardHandler handler = factorWizardUI.getHandler(); + handler.initNewFactorWithValue(factorWizardUI, paramValue); + factorWizardUI.pack(); + factorWizardUI.setLocationRelativeTo(ruleChooser); + factorWizardUI.setVisible(true);*/ + + Factor factor = new Factor(t("isisfish.sensitivity.ruleparameterfactorname", + rule.getClass().getSimpleName(), paramName)); + factor.setPath(factorPath); + FactorWizardUI factorWizardUI = new FactorWizardUI(ruleChooser); + FactorWizardHandler handler = factorWizardUI.getHandler(); + handler.initExistingFactor(factorWizardUI, factor); + factorWizardUI.pack(); + factorWizardUI.setLocationRelativeTo(ruleChooser); + factorWizardUI.setVisible(true); + + /*} catch (IsisFishException ex) { + throw new IsisFishRuntimeException("Can't add factor on rule", ex); + }*/ + } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleParametersFactorTableCellRenderer.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleParametersFactorTableCellRenderer.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/models/rule/RuleParametersFactorTableCellRenderer.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -81,7 +81,7 @@ Class paramType = RuleStorage.getParameterType(rule, paramName); boolean canBeFactor = SensitivityUtils.canBeFactor(paramType); if (canBeFactor) { - comp = new JButton(Resource.getIcon("/icons/building_add.png")); + comp = new JButton(Resource.getIcon("/icons/sensitivity/flag--plus.png")); } } catch (IsisFishException ex) { if (log.isWarnEnabled()) { Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -85,7 +85,7 @@ * Initialise la vue avec les liste des simulations disponible. */ public void afterInit() { - initSimulationList(resultUI); + initSimulationList(); // reference must stay allocated listener = new SimulationServiceListener() { @@ -110,10 +110,8 @@ /** * Reload simulation combo box model. - * - * @param resultUI resultUI */ - protected void initSimulationList(ResultUI resultUI) { + protected void initSimulationList() { List<String> value = SimulationStorage.getSimulationNames(); //resultUI.getSimulationComboBox().setEditable(false); @@ -124,10 +122,8 @@ /** * Open selected simulation item in new internal frame. - * - * @param resultUI resultUI */ - public void openNewSimulation(ResultUI resultUI) { + public void openNewSimulation() { String selected = (String)resultUI.getSimulationComboBox().getSelectedItem(); SimulationStorage simulation = SimulationStorage.getSimulation(selected); @@ -148,10 +144,8 @@ /** * Delete selected simulation. - * - * @param resultUI resultUI */ - public void deleteSimulation(ResultUI resultUI) { + public void deleteSimulation() { String selected = (String)resultUI.getSimulationComboBox().getSelectedItem(); SimulationStorage simulation = SimulationStorage.getSimulation(selected); try { @@ -159,15 +153,13 @@ } catch (StorageException ex) { throw new IsisFishRuntimeException("Can't delete simulation", ex); } - initSimulationList(resultUI); + initSimulationList(); } /** * Display simulation log. - * - * @param resultUI resultUI */ - public void showLog(ResultUI resultUI) { + public void showLog() { String selected = (String)resultUI.getSimulationComboBox().getSelectedItem(); try { SimulationLoggerUtil.showSimulationLogConsole(resultUI, selected); Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/result/ResultUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -43,15 +43,15 @@ </cell> <cell> <JButton id="openButton" text="isisfish.result.new.window" - onActionPerformed="getHandler().openNewSimulation(this)"/> + onActionPerformed="handler.openNewSimulation()"/> </cell> <cell> <JButton id="removeButton" text="isisfish.result.remove.simulation" - onActionPerformed="getHandler().deleteSimulation(this)"/> + onActionPerformed="handler.deleteSimulation()"/> </cell> <cell> <JButton id="logButton" text="isisfish.result.show.simulation.log" - onActionPerformed="getHandler().showLog(this)"/> + onActionPerformed="handler.showLog()"/> </cell> </row> </Table> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -30,6 +30,7 @@ import java.awt.Color; import java.awt.Component; import java.awt.Desktop; +import java.awt.Dimension; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.io.ByteArrayOutputStream; @@ -55,8 +56,6 @@ import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; -import javax.swing.event.CaretEvent; -import javax.swing.event.CaretListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; @@ -107,7 +106,7 @@ * Last update: $Date$ * by : $Author$ */ -public class ScriptHandler implements TreeSelectionListener, CaretListener { +public class ScriptHandler implements TreeSelectionListener { /** to use log facility, just put in your code: log.info(\"...\"); */ private static Log log = LogFactory.getLog(ScriptHandler.class); @@ -145,7 +144,6 @@ // specific template loader to get template from jars (classpath) ClassTemplateLoader templateLoader = new ClassTemplateLoader(ScriptHandler.class, "/"); freemarkerConfiguration.setTemplateLoader(templateLoader); - } /** @@ -157,10 +155,26 @@ // add listeners scriptTree.addTreeSelectionListener(this); - this.scriptUI.getEditor().addCaretListener(this); // expand official VCS tree node scriptTree.expandRow(0); + + // bind actions + scriptUI.getMiSearch().setAction(scriptUI.getEditor().getFindAction()); + scriptUI.getMiReplace().setAction(scriptUI.getEditor().getReplaceAction()); + scriptUI.getMiGoto().setAction(scriptUI.getEditor().getGotoAction()); + scriptUI.getMiSave().setAction(scriptUI.getEditor().getSaveAction()); + scriptUI.getMiCopy().setAction(scriptUI.getEditor().getCopyAction()); + scriptUI.getMiCut().setAction(scriptUI.getEditor().getCutAction()); + scriptUI.getMiPaste().setAction(scriptUI.getEditor().getPasteAction()); + scriptUI.buttonScriptCut.setAction(scriptUI.getEditor().getCutAction()); + scriptUI.buttonScriptCopy.setAction(scriptUI.getEditor().getCopyAction()); + scriptUI.buttonScriptPaste.setAction(scriptUI.getEditor().getPasteAction()); + scriptUI.buttonScriptSave.setAction(scriptUI.getEditor().getSaveAction()); + + // hide check log + scriptUI.getActionLogSplitPane().getBottomComponent().setMinimumSize(new Dimension()); + scriptUI.getActionLogSplitPane().setDividerLocation(1.0d); } /** @@ -184,6 +198,7 @@ WelcomePanelUI parentUI = scriptUI.getParentContainer(WelcomePanelUI.class); parentUI.setStatusMessage(msg); } + protected void setStatusMessage(String msg, boolean running) { // FIXME remove all parent container reference WelcomePanelUI parentUI = scriptUI.getParentContainer(WelcomePanelUI.class); @@ -412,24 +427,16 @@ @Override public void valueChanged(TreeSelectionEvent e) { if (e.getNewLeadSelectionPath() != null) { + Object selectedNode = e.getNewLeadSelectionPath().getLastPathComponent(); if (selectedNode instanceof File && ((File)selectedNode).isFile()) { File selectedFile = (File)selectedNode; // load file into current action codeStorage loadScript(selectedFile); scriptUI.getEditor().open(selectedFile); - // force refresh - scriptUI.getEditor().repaint(); - scriptUI.getEditor().validate(); - setButton(); - } - else { + } else { scriptUI.getEditor().close(); - // force refresh - scriptUI.getEditor().repaint(); - scriptUI.getEditor().validate(); - setButton(); } } @@ -669,27 +676,6 @@ return result; } - /** - * Cut selection in current editor. - */ - public void cut() { - scriptUI.getEditor().cut(); - } - - /** - * Copy selection in current editor. - */ - public void copy() { - scriptUI.getEditor().copy(); - } - - /** - * Paste clipboard content in editor. - */ - public void paste() { - scriptUI.getEditor().paste(); - } - protected static FileFilter scriptFileFilter; public static FileFilter getScriptFileFilter() { @@ -708,6 +694,8 @@ boolean check = false; + resetCheckLogArea(); + // can't compile formule if (codeStorage instanceof FormuleStorage) { return false; @@ -754,12 +742,22 @@ public void checkAllScripts() { new SwingWorker<Void, Void>() { public Void doInBackground() { - checkAllScripts(); + checkAllScriptsAsync(); return null; } }.execute(); } - + + protected void resetCheckLogArea() { + // hidden by default + int maxLocation = scriptUI.getActionLogSplitPane().getMaximumDividerLocation(); + if (scriptUI.getActionLogSplitPane().getBottomComponent().getHeight() == 0) { + scriptUI.getActionLogSplitPane().setDividerLocation((int)(maxLocation * 0.75)); + } + scriptUI.getActionLogArea().setBackground(null); + scriptUI.getActionLogArea().setText(""); + } + protected void checkAllScriptsAsync() { setStatusMessage(t("isisfish.message.check.inprogress"), true); @@ -767,8 +765,7 @@ boolean allSuccess = true; // reste previous state - scriptUI.getActionLogArea().setBackground(null); - scriptUI.getActionLogArea().setText(""); + resetCheckLogArea(); for (ScriptMapping scriptMapping : ScriptMapping.values()) { // normalement ne match pas les formules @@ -1130,15 +1127,6 @@ } } - /* - * @see javax.swing.event.CaretListener#caretUpdate(javax.swing.event.CaretEvent) - */ - @Override - public void caretUpdate(CaretEvent e) { - // selection pas vide si dot = mark - scriptUI.setTextSelected(e.getDot() != e.getMark()); - } - /** * Move files. * (called by drag and drop handler). Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -44,59 +44,60 @@ <!-- Menu --> <JMenuBar id="scriptMenuBar" constraints='BorderLayout.NORTH'> <JMenu id="scriptTxtFile" text="isisfish.script.menu.file"> - <JMenu id="scriptNewMenu" text="isisfish.script.menu.new" icon="script.png"> + <JMenu id="scriptNewMenu" text="isisfish.script.menu.new" icon="script/script.png"> <JMenuItem id="miNewScript" text="isisfish.script.menu.txtNewScript" - onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityScript)' icon="script.png" /> + onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityScript)' icon="script/script.png" /> <JMenuItem id="miNewSimulator" text="isisfish.script.menu.txtNewSimulator" - onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunitySimulator)' icon="script.png" /> + onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunitySimulator)' icon="script/script.png" /> <JMenuItem id="miNewExport" text="isisfish.script.menu.txtNewExport" - onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityExport)' icon="script.png" /> + onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityExport)' icon="script/script.png" /> <JMenuItem id="miNewExportStep" text="isisfish.script.menu.txtNewExportStep" - onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityExportStep)' icon="script.png" /> + onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityExportStep)' icon="script/script.png" /> <JMenuItem id="miNewRule" text="isisfish.script.menu.txtNewRule" - onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityRule)' icon="script.png" /> + onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityRule)' icon="script/script.png" /> <JMenuItem id="miNewSImulationPlan" text="isisfish.script.menu.txtNewSimulationPlan" - onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunitySimulationPlan)' icon="script.png" /> + onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunitySimulationPlan)' icon="script/script.png" /> <JMenuItem id="miNewSensitivity" text="isisfish.script.menu.txtNewSensitivity" - onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunitySensitivity)' icon="script.png" /> + onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunitySensitivity)' icon="script/script.png" /> <JMenuItem id="miNewSensitivityExport" text="isisfish.script.menu.txtNewSensitivityExport" - onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunitySensitivityExport)' icon="script.png" /> + onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunitySensitivityExport)' icon="script/script.png" /> <JMenuItem text="isisfish.script.menu.txtNewObjective" - onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityObjective)' icon="script.png" /> + onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityObjective)' icon="script/script.png" /> <JMenuItem text="isisfish.script.menu.txtNewOptimization" - onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityOptimization)' icon="script.png" /> + onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityOptimization)' icon="script/script.png" /> <JMenuItem id="miNewEquationModel" text="isisfish.script.menu.txtNewEquationModel" - onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityFormule)' icon="script.png" /> + onActionPerformed='handler.newScript(ScriptHandler.ScriptMapping.CommunityFormule)' icon="script/script.png" /> </JMenu> <JMenuItem id="miSave" text="isisfish.script.menu.save" - onActionPerformed="handler.saveScript()" icon="script_save.png" enabled='{isSingleFileSelected()}' /> + onActionPerformed="handler.saveScript()" icon="script/disk-black.png" enabled='{isSingleFileSelected()}' /> <JSeparator/> <JMenuItem id="miDelete" text="isisfish.script.menu.deleteLocaly" - onActionPerformed='handler.deleteScript(false)' icon="script_delete.png" enabled='{isSingleFileSelected()}' /> + onActionPerformed='handler.deleteScript(false)' icon="script/script--minus.png" enabled='{isSingleFileSelected()}' /> </JMenu> <JMenu id="scriptTxtEdit" text="isisfish.script.menu.edit"> - <JMenuItem id="miCut" text="isisfish.script.menu.cut" - onActionPerformed="handler.cut()" icon="cut.png" enabled='{isTextSelected()}' /> - <JMenuItem id="miCopy" text="isisfish.script.menu.copy" - onActionPerformed="handler.copy()" icon="page_copy.png" enabled='{isTextSelected()}' /> - <JMenuItem id="miPaste" text="isisfish.script.menu.paste" - onActionPerformed="handler.paste()" icon="page_paste.png" enabled='{isSingleFileSelected()}' /> + <JMenuItem id="miCut" /> + <JMenuItem id="miCopy" /> + <JMenuItem id="miPaste" /> + <JSeparator/> + <JMenuItem id="miSearch" /> + <JMenuItem id="miReplace" /> + <JMenuItem id="miGoto" /> </JMenu> <JMenu id="scriptTxtVCS" text="isisfish.script.menu.txtVCS"> - <JMenuItem id="miCommitVCS" text="isisfish.script.menu.commit" icon="database_go.png" + <JMenuItem id="miCommitVCS" text="isisfish.script.menu.commit" icon="script/database-import.png" onActionPerformed="handler.commitScript()" enabled='{isSingleFileSelected()}' /> - <JMenuItem id="miDiffVCS" text="isisfish.script.menu.diff" accelerator="mnDiffVCS" + <JMenuItem id="miDiffVCS" text="isisfish.script.menu.diff" accelerator="mnDiffVCS" icon="script/edit-diff.png" onActionPerformed="handler.diffScript()" enabled='{isSingleFileSelected()}' /> <JSeparator/> <JMenuItem id="miDeleteVCS" text="isisfish.script.menu.deleteLocalyServer" - onActionPerformed='handler.deleteScript(true)' icon="database_delete.png"/> + onActionPerformed='handler.deleteScript(true)' icon="script/database--minus.png"/> </JMenu> <JMenu id="scriptTxtCode" text="isisfish.script.menu.code"> - <JMenuItem id="miCheckSyntax" text="isisfish.script.menu.checkSyntax" icon="script_code_red.png" + <JMenuItem id="miCheckSyntax" text="isisfish.script.menu.checkSyntax" icon="script/compile.png" onActionPerformed="handler.checkScript()" enabled='{isJavaFileSelected()}' /> - <JMenuItem id="miCheckAllSyntax" text="isisfish.script.menu.checkAllSyntax" icon="script_code_red.png" + <JMenuItem id="miCheckAllSyntax" text="isisfish.script.menu.checkAllSyntax" icon="script/script-code.png" onActionPerformed="handler.checkAllScripts()" /> - <JMenuItem id="miEvaluate" text="isisfish.script.menu.evaluate" icon="script_gear.png" + <JMenuItem id="miEvaluate" text="isisfish.script.menu.evaluate" icon="script/terminal.png" onActionPerformed="handler.evaluateScript()" enabled='{isJavaFileSelected()}' /> <JSeparator/> <JMenuItem id="miGenerateJavadoc" text="isisfish.script.menu.javadocgenerate" @@ -110,23 +111,20 @@ <JPanel layout='{new BorderLayout()}' constraints='BorderLayout.CENTER'> <JPanel id="buttonBar" layout='{new GridLayout()}' constraints='BorderLayout.NORTH'> <JButton id="buttonScriptNew" text="isisfish.script.newplus" toolTipText='isisfish.script.new.tooltip' - onMousePressed='handler.newScript(event)' icon="script.png" /> + onMousePressed='handler.newScript(event)' icon="script/script.png" /> <JButton id="buttonScriptSave" text="isisfish.script.save" toolTipText="isisfish.script.save.tooltip" - enabled='{isSingleFileSelected()}' onActionPerformed='handler.saveScript()' icon="script_save.png" /> + enabled='{isSingleFileSelected()}' onActionPerformed='handler.saveScript()' icon="script/disk-black.png" /> <JButton id="buttonScriptExport" text="isisfish.script.export" toolTipText="isisfish.script.export.tooltip" enabled='false' - onActionPerformed='handler.exportScript()' icon="page_white_compressed.png" /> + onActionPerformed='handler.exportScript()' icon="script/folder-zipper.png" /> <JButton id="buttonScriptCommit" text="isisfish.script.commit" toolTipText="isisfish.script.commit.tooltip" enabled='{isSingleFileSelected()}' - onActionPerformed='handler.commitScript()' icon="database_go.png" /> - <JButton id="buttonScriptCut" text="isisfish.script.cut" toolTipText="isisfish.script.cut.tooltip" enabled='{isTextSelected()}' - onActionPerformed='handler.cut()' icon="cut.png" /> - <JButton id="buttonScriptCopy" text="isisfish.script.copy" toolTipText="isisfish.script.copy.tooltip" enabled='{isTextSelected()}' - onActionPerformed='handler.copy()' icon="page_copy.png" /> - <JButton id="buttonScriptPaste" text="isisfish.script.paste" toolTipText="isisfish.script.paste.tooltip" enabled='{isSingleFileSelected()}' - onActionPerformed='handler.paste()' icon="page_paste.png" /> + onActionPerformed='handler.commitScript()' icon="script/database-import.png" /> + <JButton id="buttonScriptCut" text="isisfish.script.cut" toolTipText="isisfish.script.cut.tooltip" /> + <JButton id="buttonScriptCopy" text="isisfish.script.copy" toolTipText="isisfish.script.copy.tooltip" /> + <JButton id="buttonScriptPaste" text="isisfish.script.paste" toolTipText="isisfish.script.paste.tooltip" enabled='{isSingleFileSelected()}' /> <JButton id="buttonScriptCheck" text="isisfish.script.check" toolTipText="isisfish.script.check.tooltip" enabled='{isJavaFileSelected()}' - onActionPerformed='handler.checkScript()' icon="script_code_red.png" /> + onActionPerformed='handler.checkScript()' icon="script/compile.png" /> <JButton id="buttonScriptEval" text="isisfish.script.evaluate" toolTipText="isisfish.script.evaluate.tooltip" enabled='{isJavaFileSelected()}' - onActionPerformed='handler.evaluateScript()' icon="script_gear.png" /> + onActionPerformed='handler.evaluateScript()' icon="script/terminal.png" /> </JPanel> <JSplitPane oneTouchExpandable="true" dividerLocation="250" orientation="HORIZONTAL" constraints='BorderLayout.CENTER'> <JScrollPane> @@ -135,8 +133,8 @@ rootVisible="false" model='{scriptTreeModel}' cellRenderer='{new fr.ifremer.isisfish.ui.script.model.ScriptTreeCellRenderer()}' /> </JScrollPane> - <JSplitPane oneTouchExpandable="true" resizeWeight="0.75" orientation="VERTICAL"> - <org.nuiton.widget.editor.Editor id='editor'/> + <JSplitPane id="actionLogSplitPane" oneTouchExpandable="true" orientation="VERTICAL"> + <fr.ifremer.isisfish.ui.widget.text.SyntaxEditor id='editor' askIfNotSaved="true" /> <JScrollPane> <JTextArea id="actionLogArea" editable="false" font='{new Font("Monospaced", Font.PLAIN, 12)}' /> </JScrollPane> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeCellRenderer.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeCellRenderer.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeCellRenderer.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -64,7 +64,7 @@ /** Class logger. */ private static Log log = LogFactory.getLog(ScriptTreeCellRenderer.class); - protected static final Icon VCS_ICON = Resource.getIcon("/icons/database_key.png"); + protected static final Icon VCS_ICON = Resource.getIcon("/icons/script/database.png"); /* * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean) Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityChooserHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityChooserHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityChooserHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -10,14 +10,17 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import fr.ifremer.isisfish.IsisFishException; import fr.ifremer.isisfish.datastore.RegionStorage; import fr.ifremer.isisfish.datastore.SensitivityAnalysisStorage; import fr.ifremer.isisfish.datastore.SensitivityExportStorage; import fr.ifremer.isisfish.datastore.StorageChangeEvent; import fr.ifremer.isisfish.datastore.StorageChangeListener; import fr.ifremer.isisfish.export.SensitivityExport; +import fr.ifremer.isisfish.simulator.SimulationParameter; import fr.ifremer.isisfish.simulator.sensitivity.Domain; import fr.ifremer.isisfish.simulator.sensitivity.Factor; +import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; import fr.ifremer.isisfish.simulator.sensitivity.SensitivityAnalysis; import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; import fr.ifremer.isisfish.ui.models.common.GenericComboModel; @@ -27,7 +30,7 @@ import fr.ifremer.isisfish.ui.models.common.ScriptParametersTableModel; import fr.ifremer.isisfish.ui.models.sensitivityexport.SensitivityExportListRenderer; import fr.ifremer.isisfish.ui.sensitivity.model.FactorCardinalityTableModel; -import fr.ifremer.isisfish.ui.simulator.SimulAction; +import fr.ifremer.isisfish.ui.widget.editor.ScriptParameterDialog; public class SensitivityChooserHandler { @@ -42,7 +45,29 @@ public SensitivityChooserHandler(SensitivityChooserUI sensitivityChooserUI) { this.sensitivityChooserUI = sensitivityChooserUI; } + + /** + * Return simulation parameters from context. + * + * @return SimulationParameter + * @deprecated maybe be inherited + */ + @Deprecated + protected SimulationParameter getParameters() { + return sensitivityChooserUI.getContextValue(SimulationParameter.class); + } + /** + * Return factor group from context. + * + * @return FactorGroup + * @deprecated maybe be inherited + */ + @Deprecated + protected FactorGroup getFactorGroup() { + return sensitivityChooserUI.getContextValue(FactorGroup.class); + } + protected void afterInit() { // listener to listen for modification on sensitivity analysis sensitivityAnalysisListener = new StorageChangeListener() { @@ -62,14 +87,9 @@ }; SensitivityExportStorage.addStorageChangeListener(sensitivityExportListener); } - - @Deprecated - protected SimulAction getSimulAction() { - return sensitivityChooserUI.getContextValue(SimulAction.class); - } public ComboBoxModel<String> getSensitivityAnalysisModel() { - List<String> sensitivityNames = getSimulAction().getSensitivityAnalysisNames(); + List<String> sensitivityNames = getSensitivityAnalysisNames(); GenericComboModel<String> model = new GenericComboModel<>(sensitivityNames); return model; } @@ -81,7 +101,7 @@ * Used by "reloadOldSimulation" operation. */ public void refreshSelectedSensitivityAnalysis() { - SensitivityAnalysis sensitivityAnalysis = getSimulAction().getSensitivityAnalysis(); + SensitivityAnalysis sensitivityAnalysis = getSensitivityAnalysis(); if (sensitivityAnalysis != null) { if (log.isDebugEnabled()) { log.debug("Refreshing sensitivity analysis list"); @@ -99,16 +119,16 @@ // this event is thrown by build a new Analysis instance // and parameter are lost // fix it with a small class name test - SensitivityAnalysis sensitivityAnalysis = getSimulAction().getSensitivityAnalysis(); + SensitivityAnalysis sensitivityAnalysis = getSensitivityAnalysis(); if (sensitivityAnalysis != null && sensitivityAnalysis.getClass().getSimpleName().equals(sensitivityName)) { - sensitivityAnalysis = getSimulAction().getSensitivityAnalysis(); + sensitivityAnalysis = getSensitivityAnalysis(); } else { - sensitivityAnalysis = getSimulAction().getSensitivityAnalysisInstance(sensitivityName); + sensitivityAnalysis = getSensitivityAnalysisInstance(sensitivityName); } // can be null for example if analysis can't be compiled if (sensitivityAnalysis != null) { - getSimulAction().setSensitivityAnalysis(sensitivityAnalysis); + setSensitivityAnalysis(sensitivityAnalysis); CardLayout factorPanelLayout = (CardLayout)sensitivityChooserUI.factorCardinalityPanel.getLayout(); if (sensitivityAnalysis.canManageCardinality()) { @@ -126,13 +146,13 @@ } public void setFactorCardinalityTableModel() { - List<Factor> factors = getSimulAction().getFactorGroup().getFactors(); + List<Factor> factors = getFactorGroup().getFactors(); List<Factor> factorsContinue = new ArrayList<Factor>(); /* get sublist with only Continous factor */ for (Factor f : factors) { Domain domain = f.getDomain(); if (ContinuousDomain.class.isInstance(domain)) { - ContinuousDomain continuousDomain = (ContinuousDomain)domain; + //ContinuousDomain continuousDomain = (ContinuousDomain)domain; factorsContinue.add(f); } } @@ -141,7 +161,7 @@ } protected GenericListModel<String> getAvailableExportListModel() { - List<String> exportNames = getSimulAction().getSensitivityExportNames(); + List<String> exportNames = getSensitivityExportNames(); GenericListModel<String> model = new GenericListModel<>(exportNames); return model; } @@ -154,7 +174,7 @@ protected void addExports() { List<String> exportNames = sensitivityChooserUI.availableSensitivityExports.getSelectedValuesList(); for (String exportName : exportNames) { - getSimulAction().addSensitivityExport(sensitivityChooserUI, exportName); + addSensitivityExport(sensitivityChooserUI, exportName); } setSensitivityExportListModel(); } @@ -165,7 +185,7 @@ protected void removeExports() { List<SensitivityExport> exports = sensitivityChooserUI.selectedSensitivityExports.getSelectedValuesList(); for (SensitivityExport export : exports) { - getSimulAction().removeSensitivityExport(export); + removeSensitivityExport(export); } setSensitivityExportListModel(); } @@ -174,7 +194,7 @@ * Clear all export. */ protected void clearExports() { - getSimulAction().clearSensitivityExport(); + clearSensitivityExport(); setSensitivityExportListModel(); } @@ -182,7 +202,7 @@ * Set model (refresh export JList). */ public void setSensitivityExportListModel() { - List<SensitivityExport> exports = getSimulAction().getSensitivityExports(); + List<SensitivityExport> exports = getSensitivityExports(); GenericListModel<SensitivityExport> model = new GenericListModel<>(exports); sensitivityChooserUI.selectedSensitivityExports.setModel(model); sensitivityChooserUI.selectedSensitivityExports.setCellRenderer(new SensitivityExportListRenderer()); @@ -212,8 +232,6 @@ * Fill export parameters names and values in table. */ protected void setExportParams() { - SimulAction simulAction = sensitivityChooserUI.getContextValue(SimulAction.class); - if (sensitivityChooserUI.selectedSensitivityExports.getSelectedIndices().length == 1) { SensitivityExport export = (SensitivityExport)sensitivityChooserUI.selectedSensitivityExports.getSelectedValue(); ScriptParametersTableModel model = new ScriptParametersTableModel(export); @@ -226,4 +244,102 @@ sensitivityChooserUI.exportParamsTable.setModel(new DefaultTableModel()); } } + + public List<String> getSensitivityExportNames() { + List<String> result = new ArrayList<>(); + List<String> exportNames = SensitivityExportStorage.getSensitivityExportNames(); + for (String export : exportNames) { + result.add(export); + } + return result; + } + + public List<SensitivityExport> getSensitivityExports() { + List<SensitivityExport> result = getParameters().getSensitivityExport(); + return result; + } + + public void addSensitivityExport(SensitivityChooserUI sensitivityChooserUI, String name) { + try { + SensitivityExportStorage storage = SensitivityExportStorage.getSensitivityExport(name); + SensitivityExport sensitivityExport = storage.getNewInstance(); + + // add it after autoconfiguration (if enabled) + sensitivityExport = (SensitivityExport)ScriptParameterDialog.displayConfigurationFrame(sensitivityChooserUI, sensitivityExport); + if (sensitivityExport != null) { + getParameters().getSensitivityExport().add(sensitivityExport); + } + } catch (IsisFishException e) { + if (log.isErrorEnabled()) { + log.error("Can't add sensitivity export", e); + } + } + } + + /** + * Remove an export. + * + * @param export export to remove + */ + public void removeSensitivityExport(SensitivityExport export) { + getParameters().getSensitivityExport().remove(export); + } + + public void clearSensitivityExport() { + getParameters().getSensitivityExport().clear(); + } + + /** + * Return sensitivity analysis name without .java extension. + * + * @return sensitivity analysis names list + */ + public List<String> getSensitivityAnalysisNames() { + List<String> result = new ArrayList<String>(); + for (String r : SensitivityAnalysisStorage.getSensitivityAnalysisNames()) { + // there is some non java files in sensitivity directory + if (r.endsWith(".java")) { + // Remove .java extention + // for example SensitivityStorage.getRuleName(String) + result.add(r.substring(0, r.length() - 5)); + } + } + return result; + } + + /** + * Get current sensitivity calculator instance. + * @return sensitivity calculator + */ + public SensitivityAnalysis getSensitivityAnalysis() { + return getParameters().getSensitivityAnalysis(); + } + + /** + * Build a new sensitivity calculator instance by his name. + * + * @param name calculator name + * @return instance + */ + public SensitivityAnalysis getSensitivityAnalysisInstance(String name) { + SensitivityAnalysis sensitivityAnalysis = null; + try { + SensitivityAnalysisStorage sensitivityStorage = SensitivityAnalysisStorage.getSensitivityAnalysis(name); + sensitivityAnalysis = sensitivityStorage.getNewInstance(); + } catch (IsisFishException e) { + if (log.isErrorEnabled()) { + log.error("Can't set sensitivity analysis", e); + } + } + return sensitivityAnalysis; + } + + /** + * Set calculator instance to use. + * + * @param sensitivityAnalysis new instance + */ + public void setSensitivityAnalysis(SensitivityAnalysis sensitivityAnalysis) { + getParameters().setSensitivityAnalysis(sensitivityAnalysis); + } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityContext.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityContext.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityContext.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -23,29 +23,27 @@ package fr.ifremer.isisfish.ui.sensitivity; import fr.ifremer.isisfish.ui.WelcomeSaveVerifier; -import fr.ifremer.isisfish.ui.simulator.SimulAction; +import fr.ifremer.isisfish.ui.simulator.SimulatorContext; import jaxx.runtime.JAXXContext; -import jaxx.runtime.context.JAXXInitialContext; /** * Ce contexte regroupe les élements qui servent à une hierachie d'interfaces Sensitivity. * + * C'est globalement un context de simulation + input (pour la selection des fateurs). + * * @author Eric Chatellier */ -public class SensitivityContext extends JAXXInitialContext { +public class SensitivityContext extends SimulatorContext { public SensitivityContext(JAXXContext parent) { - setParentContext(parent); + super(parent); - // add save verifier for this hierarchy + // add save verifier for this hierarchy (input) SensitivitySaveVerifier sensitivitySaveVerifier = new SensitivitySaveVerifier(); add(sensitivitySaveVerifier); - // this verifier is linked to global verifier + // this verifier is linked to global verifier (input) WelcomeSaveVerifier welcomeSaveVerifier = getContextValue(WelcomeSaveVerifier.class); welcomeSaveVerifier.addSaveVerifier(sensitivitySaveVerifier); - - // FIXME remove this - add(new SimulAction()); } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -67,7 +67,6 @@ import fr.ifremer.isisfish.ui.sensitivity.model.FactorTreeModel; import fr.ifremer.isisfish.ui.sensitivity.wizard.FactorWizardHandler; import fr.ifremer.isisfish.ui.sensitivity.wizard.FactorWizardUI; -import fr.ifremer.isisfish.ui.simulator.SimulAction; /** * Handler for sensitivity tab ui (fishery region factors). @@ -93,11 +92,6 @@ } - @Deprecated - protected SimulAction getSimulAction() { - return sensitivityInputUI.getContextValue(SimulAction.class); - } - protected InputSaveVerifier getVerifier() { return sensitivityInputUI.getContextValue(InputSaveVerifier.class); } @@ -105,6 +99,10 @@ protected RegionStorage getRegionStorage() { return sensitivityInputUI.getContextValue(RegionStorage.class); } + + protected FactorGroup getFactorGroup() { + return sensitivityInputUI.getContextValue(FactorGroup.class); + } public void setTreeModel() { if (sensitivityInputUI.getFisheryRegion() != null) { @@ -126,7 +124,7 @@ } public void setFactorModel() { - FactorGroup factorGroup = getSimulAction().getFactorGroup(); + FactorGroup factorGroup = getFactorGroup(); FactorTreeModel model = new FactorTreeModel(factorGroup); sensitivityInputUI.factorsTree.setModel(model); sensitivityInputUI.getParentContainer(SensitivityUI.class).getSensitivityChooserUI().getHandler().setFactorCardinalityTableModel(); @@ -228,7 +226,7 @@ t("isisfish.sensitivity.title"), JOptionPane.QUESTION_MESSAGE); if (StringUtils.isNotBlank(factorName)) { - FactorGroup rootFactorGroup = getSimulAction().getFactorGroup(); + FactorGroup rootFactorGroup = getFactorGroup(); FactorGroup factorGroup = new FactorGroup(factorName, continuous); rootFactorGroup.addFactor(factorGroup); setFactorModel(); @@ -248,7 +246,7 @@ selectedFactorGroup.addAllFactors(movedFactors); // remove duplicated from factor group - FactorGroup rootFactorGroup = getSimulAction().getFactorGroup(); + FactorGroup rootFactorGroup = getFactorGroup(); if (!rootFactorGroup.equals(selectedFactorGroup)) { rootFactorGroup.removeAll(movedFactors); } @@ -371,10 +369,8 @@ xmlFile = new File(xmlFile.getAbsolutePath() + ".xml"); } - SimulAction simulAction = sensitivityInputUI.getContextValue(SimulAction.class); - DesignPlan designPlan = new DesignPlan(); - designPlan.setFactorGroup(simulAction.getFactorGroup()); + designPlan.setFactorGroup(getFactorGroup()); //String xml = MexicoHelper.getDesignPlanAsXML(designPlan); MexicoHelper.writeDesignPlanToFile(xmlFile, designPlan); } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivityInputUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -56,7 +56,7 @@ onActionPerformed="handler.addNewFactorGroup(true)"/> </cell> <cell anchor='west' weightx='1'> - <JButton icon="script_go.png" toolTipText="isisfish.sensitivity.mexico.exporttoxml.tip" + <JButton icon="sensitivity/table-export.png" toolTipText="isisfish.sensitivity.mexico.exporttoxml.tip" onActionPerformed="handler.exportFactorsToMexico()"/> </cell> </row> @@ -65,7 +65,7 @@ <JScrollPane> <fr.ifremer.isisfish.ui.sensitivity.model.FactorTree id="factorsTree" constructorParams='this' rootVisible="true" selectionRow='0' - model='{new fr.ifremer.isisfish.ui.sensitivity.model.FactorTreeModel(handler.getSimulAction().getFactorGroup())}' + model='{new fr.ifremer.isisfish.ui.sensitivity.model.FactorTreeModel(handler.getFactorGroup())}' cellRenderer='{new fr.ifremer.isisfish.ui.sensitivity.model.FactorTreeCellRenderer()}' onMouseClicked='handler.factorsTreeMouseClicked(event)'/> </JScrollPane> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivitySecondPassHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivitySecondPassHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/SensitivitySecondPassHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -5,17 +5,21 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.SortedMap; +import java.util.TreeMap; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.simulator.SimulationParameter; import fr.ifremer.isisfish.simulator.launcher.SimulationJob; import fr.ifremer.isisfish.simulator.launcher.SimulationService; import fr.ifremer.isisfish.simulator.launcher.SimulationServiceListener; +import fr.ifremer.isisfish.simulator.sensitivity.SensitivityAnalysis; +import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException; import fr.ifremer.isisfish.ui.models.common.GenericComboModel; -import fr.ifremer.isisfish.ui.simulator.SimulAction; public class SensitivitySecondPassHandler { @@ -79,14 +83,9 @@ return model; } - @Deprecated - protected SimulAction getSimulAction() { - return sensitivitySecondPassUI.getContextValue(SimulAction.class); - } - protected void launchSecondPass(ActionEvent event) { if (sensitivitySecondPassUI.fieldSensitivitySimulationSelect.getSelectedIndex() != -1) { - getSimulAction().runSensitivitySecondPass((String)sensitivitySecondPassUI.fieldSensitivitySimulationSelect.getSelectedItem()); + runSensitivitySecondPass((String)sensitivitySecondPassUI.fieldSensitivitySimulationSelect.getSelectedItem()); displaySensitivitySecondPass(event); } } @@ -96,7 +95,7 @@ try { String selectedSimulationName = (String)sensitivitySecondPassUI.fieldSensitivitySimulationSelect.getSelectedItem(); - List<File> files = getSimulAction().getSensitivitySecondPassResults(selectedSimulationName); + List<File> files = getSensitivitySecondPassResults(selectedSimulationName); String content = ""; for(File file : files) { @@ -113,4 +112,85 @@ } } } + + /** + * Lance la second passe d'une analyse de sensibilité. + * + * @param masterSensitivitySimulationName nom du prefix de toutes les simulations (without _) + */ + public void runSensitivitySecondPass(String masterSensitivitySimulationName) { + + // sensitivity analysis found + SensitivityAnalysis sensitivityAnalysis = null; + //List<SimulationStorage> simulationStorageForAnalyze = new ArrayList<SimulationStorage>(); + SortedMap<Integer, SimulationStorage> simulationStorageForAnalyze = new TreeMap<Integer, SimulationStorage>(); + File simuationDirectory = SimulationStorage.getSimulationDirectory(); + for (File simuation : simuationDirectory.listFiles()) { + if (simuation.isDirectory() + && simuation.getName().startsWith( + masterSensitivitySimulationName + "_")) { + SimulationStorage storage = SimulationStorage + .getSimulation(simuation.getName()); + String suffix = simuation.getName().substring( + simuation.getName().lastIndexOf("_") + 1); + simulationStorageForAnalyze.put(Integer.valueOf(suffix), + storage); + + if (sensitivityAnalysis == null) { + // try to find find calculator name in one storage + SimulationParameter params = storage.getParameter(); + sensitivityAnalysis = params.getSensitivityAnalysis(); + } + } + } + + if (sensitivityAnalysis != null) { + try { + // build master sensitivity export directory + File masterExportDirectory = new File(SimulationStorage.getSensitivityResultsDirectory(), + masterSensitivitySimulationName); + if (!masterExportDirectory.isDirectory()) { + masterExportDirectory.mkdirs(); + } + List<SimulationStorage> simulationStorageForAnalyzeList = new ArrayList<SimulationStorage>( + simulationStorageForAnalyze.values()); + sensitivityAnalysis.analyzeResult( + simulationStorageForAnalyzeList, masterExportDirectory); + } catch (SensitivityException e) { + if (log.isErrorEnabled()) { + log.error("Can't call analyse result", e); + } + } + } else { + if (log.isWarnEnabled()) { + log.warn("Can't run sensitivity second pass"); + } + } + } + + /** + * Renvoie les resultats de la seconde pass. + * + * @param masterSensitivitySimulationName nom du prefix de toutes les simulations (without _) + * + * @return les fichiers genere lors de la seconde passe (seulement ceux qui ne commence pas par ".") + */ + public List<File> getSensitivitySecondPassResults( + String masterSensitivitySimulationName) { + + List<File> result = new ArrayList<File>(); + + // build master sensitivity export directory + File masterExportDirectory = new File(SimulationStorage.getSensitivityResultsDirectory(), masterSensitivitySimulationName); + if (masterExportDirectory.isDirectory()) { + for (File exportFile : masterExportDirectory.listFiles()) { + if (exportFile.isFile() + && !exportFile.getName().startsWith(".")) { + result.add(exportFile); + } + } + } + + return result; + } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/FactorWizardHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/FactorWizardHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/sensitivity/wizard/FactorWizardHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -31,8 +31,10 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.SortedMap; +import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -61,8 +63,10 @@ import fr.ifremer.isisfish.entities.Equation; import fr.ifremer.isisfish.entities.Population; import fr.ifremer.isisfish.rule.Rule; +import fr.ifremer.isisfish.simulator.SimulationParameter; import fr.ifremer.isisfish.simulator.sensitivity.Domain; import fr.ifremer.isisfish.simulator.sensitivity.Factor; +import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; import fr.ifremer.isisfish.simulator.sensitivity.SensitivityUtils; import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain; @@ -75,7 +79,6 @@ import fr.ifremer.isisfish.ui.SimulationUI; import fr.ifremer.isisfish.ui.input.equation.InputOneEquationUI; import fr.ifremer.isisfish.ui.simulator.RuleChooser; -import fr.ifremer.isisfish.ui.simulator.SimulAction; import fr.ifremer.isisfish.ui.widget.editor.MonthComponent; import fr.ifremer.isisfish.ui.widget.editor.StepComponent; @@ -515,8 +518,7 @@ } TopiaContext topiaContext = getTopiaContext(factorWizardUI); Population pop = IsisFishDAOHelper.getPopulationDAO(topiaContext).findByName(populationName); - SimulAction action = factorWizardUI.getContextValue(SimulAction.class); - MatrixND N = action.getSimulationParameter().getNumberOf(pop); + MatrixND N = getParameters().getNumberOf(pop); result = new MatrixPanelEditor(); ((MatrixPanelEditor)result).setMatrix(N.clone()); topiaContext.closeContext(); @@ -526,8 +528,7 @@ Matcher matcher = pattern.matcher(factorPath); if (matcher.matches()) { int ruleIndex = Integer.parseInt(matcher.group(1)); - SimulAction action = factorWizardUI.getContextValue(SimulAction.class); - Rule rule = action.getSimulationParameter().getRules().get(ruleIndex); + Rule rule = getParameters().getRules().get(ruleIndex); Class valueClazz = RuleStorage.getParameterType(rule, matcher.group(2)); Object value = RuleStorage.getParameterValue(rule, matcher.group(2)); result = getTypeDiscreteComponent(factorWizardUI, valueClazz, value); @@ -583,12 +584,12 @@ //DefaultContinuousPanelUI ui = new DefaultContinuousPanelUI(); String values = rangeOfValues.getValues(); String min = "0"; - String max = "0"; + //String max = "0"; if (values.matches("^\\ *[0-9]*\\ *\\-\\ *[0-9]*\\ *$")) { int first = values.indexOf("-"); if (first != -1) { min = values.substring(0, first); - max = values.substring(first + 1); + //max = values.substring(first + 1); } } result = new ContinuousDistributionPanel(min); @@ -634,8 +635,7 @@ } TopiaContext topiaContext = getTopiaContext(factorWizardUI); Population pop = IsisFishDAOHelper.getPopulationDAO(topiaContext).findByName(populationName); - SimulAction action = factorWizardUI.getContextValue(SimulAction.class); - MatrixND N = action.getSimulationParameter().getNumberOf(pop); + MatrixND N = getParameters().getNumberOf(pop); result = new ContinuousDistributionPanel(N.clone()); topiaContext.closeContext(); } @@ -644,8 +644,7 @@ Matcher matcher = pattern.matcher(factorPath); if (matcher.matches()) { int ruleIndex = Integer.parseInt(matcher.group(1)); - SimulAction action = factorWizardUI.getContextValue(SimulAction.class); - Rule rule = action.getSimulationParameter().getRules().get(ruleIndex); + Rule rule = getParameters().getRules().get(ruleIndex); Class valueClazz = RuleStorage.getParameterType(rule, matcher.group(2)); Object value = RuleStorage.getParameterValue(rule, matcher.group(2)); result = getTypeContinousComponent(factorWizardUI, valueClazz, value); @@ -754,12 +753,12 @@ if (factorWizardUI.getContinueRadio().isSelected()) { saveContinue(factorWizardUI.getFactorNameField().getText(), factorWizardUI.getComment().getText(), factorWizardUI.getFactorPath(), continuousPanel, - factorWizardUI.getContextValue(SimulAction.class), factorWizardUI.isEditingState()); + factorWizardUI.isEditingState()); } else { Component[] discreteComponents = factorWizardUI.getTabPane().getComponents(); saveDiscret(factorWizardUI.getFactorNameField().getText(), factorWizardUI.getComment().getText(), factorWizardUI.getFactorPath(), discreteComponents, - factorWizardUI.getContextValue(SimulAction.class), factorWizardUI.isEditingState()); + factorWizardUI.isEditingState()); } // refresh factor list @@ -776,12 +775,10 @@ * @param comment comment * @param path factor path * @param panel panel - * @param action action * @param exist exist */ protected void saveContinue(String name, - String comment, String path, ContinuousPanel panel, - SimulAction action, boolean exist) { + String comment, String path, ContinuousPanel panel, boolean exist) { if (panel instanceof EquationContinuousPanelUI) { try { EquationContinuousPanelUI equationPanel = (EquationContinuousPanelUI) panel; @@ -799,7 +796,7 @@ factor.setName(name); factor.setComment(comment); factor.setPath(path); - action.addContinuousEquationFactor(factor, exist); + addContinuousEquationFactor(factor, exist); } } catch (Exception ex) { if (log.isErrorEnabled()) { @@ -809,7 +806,7 @@ } else if (panel instanceof ContinuousDistributionPanel) { ContinuousDistributionPanel defaultPanel = (ContinuousDistributionPanel) panel; ContinuousDomain domain = defaultPanel.generateDomain(); - action.addContinuousFactor(name, comment, path, domain, exist); + addContinuousFactor(name, comment, path, domain, exist); } } @@ -820,12 +817,10 @@ * @param comment * @param path * @param components - * @param action * @param exist */ protected void saveDiscret(String name, - String comment, String path, Component[] components, - SimulAction action, boolean exist) { + String comment, String path, Component[] components, boolean exist) { List<Object> values = new ArrayList<Object>(); boolean ruleFactor = false; @@ -861,11 +856,11 @@ } if (ruleFactor) { - action.addDiscreteRuleFactor(name, comment, path, values, exist); + addDiscreteRuleFactor(name, comment, path, values, exist); } else if (equationFactor) { - action.addDiscreteEquationFactor(name, comment, path, values, exist); + addDiscreteEquationFactor(name, comment, path, values, exist); } else { - action.addDiscreteFactor(name, comment, path, values, exist); + addDiscreteFactor(name, comment, path, values, exist); } } @@ -875,8 +870,120 @@ * @param factorWizardUI factorWizardUI */ public void remove(FactorWizardUI factorWizardUI) { - factorWizardUI.getContextValue(SimulAction.class).removeFactor(factorWizardUI.getFactorPath()); + removeFactor(factorWizardUI.getFactorPath()); factorWizardUI.getContextValue(SimulationUI.class, "SimulationUI").refreshFactorTree(); factorWizardUI.dispose(); } + + protected void addFactor(Factor f) { + if (log.isDebugEnabled()) { + log.debug("Add factor (" + f.getName() + ") : " +f.getPath()); + } + getFactorGroup().addFactor(f); + } + + /** + * Ajout d'un facteur continue de type (min/max). + * + * @param name + * @param comment + * @param path + * @param domain + * @param exist + */ + public void addContinuousFactor(String name, String comment, String path, + ContinuousDomain domain, boolean exist) { + Factor f = new Factor(name); + f.setDomain(domain); + f.setComment(comment); + f.setPath(path); + if (exist) { + removeFactor(path); + } + addFactor(f); + } + + public void addDiscreteFactor(String name, String comment, String path, + List<Object> values, boolean exist) { + addDiscreteFactor(new DiscreteDomain(), name, comment, path, values, exist); + } + + public void addDiscreteRuleFactor(String name, String comment, String path, + List<Object> values, boolean exist) { + addDiscreteFactor(new RuleDiscreteDomain(), name, comment, path, values, exist); + } + + public void addDiscreteEquationFactor(String name, String comment, String path, + List<Object> values, boolean exist) { + addDiscreteFactor(new EquationDiscreteDomain(), name, comment, path, values, exist); + } + + protected void addDiscreteFactor(DiscreteDomain domain, String name, String comment, String path, + List<Object> values, boolean exist) { + Factor f = new Factor(name); + SortedMap<Object, Object> domainValues = new TreeMap<Object, Object>(); + int label = 0; + for (Object value : values) { + // FIXME test when integer + // Don't work with String ;( + domainValues.put(label, value); + // and start at 0 + label++; + } + domain.setValues(domainValues); + f.setDomain(domain); + f.setComment(comment); + f.setPath(path); + if (exist) { + removeFactor(path); + } + addFactor(f); + } + + public void addContinuousEquationFactor(Factor f, boolean exist) { + // factor name need to be composed + //Factor f = new Factor(name + "." + domain.getVariableName()); + //f.setDomain(domain); + //f.setComment(comment); + //f.setPath(path); + if (exist) { + removeFactor(f.getPath()); + } + addFactor(f); + } + + /** + * Remove factor in factor group tree by path. + * + * @param factorPath factor path to remove + */ + public void removeFactor(String factorPath) { + removeFactor(getFactorGroup(), factorPath); + } + + /** + * Recursive remove for factor in factor group by path. + * + * @param factorGroup factor group to search to + * @param factorPath factor path to remove + */ + protected void removeFactor(FactorGroup factorGroup, String factorPath) { + Collection<Factor> factorCopy = new ArrayList<Factor>(factorGroup.getFactors()); + for (Factor factor : factorCopy) { + if (factor instanceof FactorGroup) { + removeFactor((FactorGroup)factor, factorPath); + } + if (factorPath.equals(factor.getPath())) { + factorGroup.remove(factor); + } + } + } + + protected FactorGroup getFactorGroup() { + return factorWizardUI.getContextValue(FactorGroup.class); + } + + protected SimulationParameter getParameters() { + return factorWizardUI.getContextValue(SimulationParameter.class); + } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -25,6 +25,7 @@ import static org.nuiton.i18n.I18n.t; import java.util.Iterator; +import java.util.List; import java.util.Map; import javax.swing.event.ListSelectionEvent; @@ -34,6 +35,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.datastore.SimulatorStorage; +import fr.ifremer.isisfish.simulator.SimulationParameter; + /** * AdvancedParams UI handler. * @@ -66,56 +71,58 @@ } public void refresh() { - tabUI.fieldSimulAdvParamsSimulatorSelect.setSelectedItem(tabUI.getContextValue(SimulAction.class).getSimulationParameter().getSimulatorName()); - tabUI.fieldSimulationStatistique.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().getUseStatistic()); - tabUI.fieldSimulationCache.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().getUseCache()); + SimulationParameter params = getParameters(); - tabUI.fieldSimulAdvParamsSimulLoggerError.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isSimulErrorLevel()); - tabUI.fieldSimulAdvParamsSimulLoggerWarn.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isSimulWarnLevel()); - tabUI.fieldSimulAdvParamsSimulLoggerInfo.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isSimulInfoLevel()); - tabUI.fieldSimulAdvParamsSimulLoggerDebug.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isSimulDebugLevel()); + tabUI.fieldSimulAdvParamsSimulatorSelect.setSelectedItem(params.getSimulatorName()); + tabUI.fieldSimulationStatistique.setSelected(params.getUseStatistic()); + tabUI.fieldSimulationCache.setSelected(params.getUseCache()); - tabUI.fieldSimulAdvParamsScriptLoggerError.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isScriptErrorLevel()); - tabUI.fieldSimulAdvParamsScriptLoggerWarn.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isScriptWarnLevel()); - tabUI.fieldSimulAdvParamsScriptLoggerInfo.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isScriptInfoLevel()); - tabUI.fieldSimulAdvParamsScriptLoggerDebug.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isScriptDebugLevel()); + tabUI.fieldSimulAdvParamsSimulLoggerError.setSelected(params.isSimulErrorLevel()); + tabUI.fieldSimulAdvParamsSimulLoggerWarn.setSelected(params.isSimulWarnLevel()); + tabUI.fieldSimulAdvParamsSimulLoggerInfo.setSelected(params.isSimulInfoLevel()); + tabUI.fieldSimulAdvParamsSimulLoggerDebug.setSelected(params.isSimulDebugLevel()); - tabUI.fieldSimulAdvParamsLibLoggerError.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isLibErrorLevel()); - tabUI.fieldSimulAdvParamsLibLoggerWarn.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isLibWarnLevel()); - tabUI.fieldSimulAdvParamsLibLoggerInfo.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isLibInfoLevel()); - tabUI.fieldSimulAdvParamsLibLoggerDebug.setSelected(tabUI.getContextValue(SimulAction.class).getSimulationParameter().isLibDebugLevel()); + tabUI.fieldSimulAdvParamsScriptLoggerError.setSelected(params.isScriptErrorLevel()); + tabUI.fieldSimulAdvParamsScriptLoggerWarn.setSelected(params.isScriptWarnLevel()); + tabUI.fieldSimulAdvParamsScriptLoggerInfo.setSelected(params.isScriptInfoLevel()); + tabUI.fieldSimulAdvParamsScriptLoggerDebug.setSelected(params.isScriptDebugLevel()); + tabUI.fieldSimulAdvParamsLibLoggerError.setSelected(params.isLibErrorLevel()); + tabUI.fieldSimulAdvParamsLibLoggerWarn.setSelected(params.isLibWarnLevel()); + tabUI.fieldSimulAdvParamsLibLoggerInfo.setSelected(params.isLibInfoLevel()); + tabUI.fieldSimulAdvParamsLibLoggerDebug.setSelected(params.isLibDebugLevel()); + setTableTagValues(); } protected void addTagValue() { - tabUI.getContextValue(SimulAction.class).addTagValue(tabUI.fieldTag.getText(), tabUI.fieldValue.getText()); + addTagValue(tabUI.fieldTag.getText(), tabUI.fieldValue.getText()); setTableTagValues(); valueChanged(true); } protected void removeTagValue() { - tabUI.getContextValue(SimulAction.class).removeTagValue(tabUI.tableTagValues.getValueAt(tabUI.tableTagValues.getSelectedRow(),0).toString()); + removeTagValue(tabUI.tableTagValues.getValueAt(tabUI.tableTagValues.getSelectedRow(),0).toString()); setTableTagValues(); valueChanged(true); } protected void saveTagValues() { if (tabUI.fieldSimulAdvParamsSimulatorSelect.getSelectedIndex() != -1) { - tabUI.getContextValue(SimulAction.class).saveTagValue(tabUI.fieldSimulAdvParamsSimulatorSelect.getSelectedItem().toString()); + saveTagValue(tabUI.fieldSimulAdvParamsSimulatorSelect.getSelectedItem().toString()); } valueChanged(false); } protected void setSimulatorName() { if (tabUI.fieldSimulAdvParamsSimulatorSelect.getSelectedIndex() != -1) { - tabUI.getContextValue(SimulAction.class).getSimulationParameter().setSimulatorName(tabUI.fieldSimulAdvParamsSimulatorSelect.getSelectedItem().toString()); + getParameters().setSimulatorName(tabUI.fieldSimulAdvParamsSimulatorSelect.getSelectedItem().toString()); valueChanged(true); } } protected void setTableTagValues() { - Map<String, String> tagValues = tabUI.getContextValue(SimulAction.class).getSimulationParameter().getTagValue(); + Map<String, String> tagValues = getParameters().getTagValue(); // TODO make a table model for it String columnName[] = { t("isisfish.common.tag"), t("isisfish.common.value")}; @@ -141,4 +148,29 @@ protected void valueChanged(boolean b) { tabUI.setChanged(b); } + + public void addTagValue(String tag, String value) { + getParameters().getTagValue().put(tag, value); + } + + public void removeTagValue(String tag) { + if (log.isDebugEnabled()) { + log.debug("removeTagValue: " + tag); + } + getParameters().getTagValue().remove(tag); + } + + public void saveTagValue(String simulatorName) { + Map<String, String> tagValues = getParameters().getTagValue(); + if (log.isDebugEnabled()) { + log.debug("call saveTagValue: " + tagValues); + } + IsisFish.config.setDefaultTagValues(tagValues); + + IsisFish.config.setSimulatorClassfile(simulatorName); + } + + public List<String> getSimulatorNames() { + return SimulatorStorage.getSimulatorNames(); + } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -48,7 +48,7 @@ <cell columns="4" fill="horizontal"> <JComboBox id="fieldSimulAdvParamsSimulatorSelect" genericType="String" - model='{new DefaultComboBoxModel(getContextValue(SimulAction.class).getSimulatorNames().toArray())}' + model='{new DefaultComboBoxModel(handler.getSimulatorNames().toArray())}' onActionPerformed='handler.setSimulatorName()'/> </cell> </row> @@ -56,12 +56,13 @@ <cell columns="2" fill="horizontal"> <JCheckBox id="fieldSimulationStatistique" text="isisfish.advancedParams.simulationStatistique" - selected='{getContextValue(SimulAction.class).getSimulationParameter().getUseStatistic()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setUseStatistic(fieldSimulationStatistique.isSelected());'/> + selected='{handler.getParameters().getUseStatistic()}' + onActionPerformed='handler.getParameters().setUseStatistic(fieldSimulationStatistique.isSelected());'/> </cell> <cell columns="2" fill="horizontal"> - <JCheckBox id="fieldSimulationCache" text="isisfish.advancedParams.simulationCache" selected='{getContextValue(SimulAction.class).getSimulationParameter().getUseCache()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setUseCache(fieldSimulationCache.isSelected());'/> + <JCheckBox id="fieldSimulationCache" text="isisfish.advancedParams.simulationCache" + selected='{handler.getParameters().getUseCache()}' + onActionPerformed='handler.getParameters().setUseCache(fieldSimulationCache.isSelected());'/> </cell> </row> <row> @@ -70,23 +71,23 @@ </cell> <cell fill="horizontal" weightx="1.0"> <JRadioButton id="fieldSimulAdvParamsSimulLoggerError" text="isisfish.common.error" - buttonGroup="fieldSimulAdvParamsSimulLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isSimulErrorLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setSimulLogLevel("error");'/> + buttonGroup="fieldSimulAdvParamsSimulLoggerGroup" selected='{handler.getParameters().isSimulErrorLevel()}' + onActionPerformed='handler.getParameters().setSimulLogLevel("error");'/> </cell> <cell fill="horizontal" weightx="1.0"> <JRadioButton id="fieldSimulAdvParamsSimulLoggerWarn" text="isisfish.common.warn" - buttonGroup="fieldSimulAdvParamsSimulLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isSimulWarnLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setSimulLogLevel("warn");'/> + buttonGroup="fieldSimulAdvParamsSimulLoggerGroup" selected='{handler.getParameters().isSimulWarnLevel()}' + onActionPerformed='handler.getParameters().setSimulLogLevel("warn");'/> </cell> <cell fill="horizontal" weightx="1.0"> <JRadioButton id="fieldSimulAdvParamsSimulLoggerInfo" text="isisfish.common.info" - buttonGroup="fieldSimulAdvParamsSimulLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isSimulInfoLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setSimulLogLevel("info");'/> + buttonGroup="fieldSimulAdvParamsSimulLoggerGroup" selected='{handler.getParameters().isSimulInfoLevel()}' + onActionPerformed='handler.getParameters().setSimulLogLevel("info");'/> </cell> <cell fill="horizontal" weightx="1.0"> <JRadioButton id="fieldSimulAdvParamsSimulLoggerDebug" text="isisfish.common.debug" - buttonGroup="fieldSimulAdvParamsSimulLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isSimulDebugLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setSimulLogLevel("debug");'/> + buttonGroup="fieldSimulAdvParamsSimulLoggerGroup" selected='{handler.getParameters().isSimulDebugLevel()}' + onActionPerformed='handler.getParameters().setSimulLogLevel("debug");'/> </cell> </row> <row> @@ -95,23 +96,23 @@ </cell> <cell fill="horizontal"> <JRadioButton id="fieldSimulAdvParamsScriptLoggerError" text="isisfish.common.error" - buttonGroup="fieldSimulAdvParamsScriptLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isScriptErrorLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setScriptLogLevel("error");'/> + buttonGroup="fieldSimulAdvParamsScriptLoggerGroup" selected='{handler.getParameters().isScriptErrorLevel()}' + onActionPerformed='handler.getParameters().setScriptLogLevel("error");'/> </cell> <cell fill="horizontal"> <JRadioButton id="fieldSimulAdvParamsScriptLoggerWarn" text="isisfish.common.warn" - buttonGroup="fieldSimulAdvParamsScriptLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isScriptWarnLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setScriptLogLevel("warn");'/> + buttonGroup="fieldSimulAdvParamsScriptLoggerGroup" selected='{handler.getParameters().isScriptWarnLevel()}' + onActionPerformed='handler.getParameters().setScriptLogLevel("warn");'/> </cell> <cell fill="horizontal"> <JRadioButton id="fieldSimulAdvParamsScriptLoggerInfo" text="isisfish.common.info" - buttonGroup="fieldSimulAdvParamsScriptLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isScriptInfoLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setScriptLogLevel("info");'/> + buttonGroup="fieldSimulAdvParamsScriptLoggerGroup" selected='{handler.getParameters().isScriptInfoLevel()}' + onActionPerformed='handler.getParameters().setScriptLogLevel("info");'/> </cell> <cell fill="horizontal"> <JRadioButton id="fieldSimulAdvParamsScriptLoggerDebug" text="isisfish.common.debug" - buttonGroup="fieldSimulAdvParamsScriptLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isScriptDebugLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setScriptLogLevel("debug");'/> + buttonGroup="fieldSimulAdvParamsScriptLoggerGroup" selected='{handler.getParameters().isScriptDebugLevel()}' + onActionPerformed='handler.getParameters().setScriptLogLevel("debug");'/> </cell> </row> <row> @@ -120,23 +121,23 @@ </cell> <cell fill="horizontal"> <JRadioButton id="fieldSimulAdvParamsLibLoggerError" text="isisfish.common.error" - buttonGroup="fieldSimulAdvParamsLibLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isLibErrorLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setLibLogLevel("error");'/> + buttonGroup="fieldSimulAdvParamsLibLoggerGroup" selected='{handler.getParameters().isLibErrorLevel()}' + onActionPerformed='handler.getParameters().setLibLogLevel("error");'/> </cell> <cell fill="horizontal"> <JRadioButton id="fieldSimulAdvParamsLibLoggerWarn" text="isisfish.common.warn" - buttonGroup="fieldSimulAdvParamsLibLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isLibWarnLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setLibLogLevel("warn");'/> + buttonGroup="fieldSimulAdvParamsLibLoggerGroup" selected='{handler.getParameters().isLibWarnLevel()}' + onActionPerformed='handler.getParameters().setLibLogLevel("warn");'/> </cell> <cell fill="horizontal"> <JRadioButton id="fieldSimulAdvParamsLibLoggerInfo" text="isisfish.common.info" - buttonGroup="fieldSimulAdvParamsLibLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isLibInfoLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setLibLogLevel("info");'/> + buttonGroup="fieldSimulAdvParamsLibLoggerGroup" selected='{handler.getParameters().isLibInfoLevel()}' + onActionPerformed='handler.getParameters().setLibLogLevel("info");'/> </cell> <cell fill="horizontal"> <JRadioButton id="fieldSimulAdvParamsLibLoggerDebug" text="isisfish.common.debug" - buttonGroup="fieldSimulAdvParamsLibLoggerGroup" selected='{getContextValue(SimulAction.class).getSimulationParameter().isLibDebugLevel()}' - onActionPerformed='getContextValue(SimulAction.class).getSimulationParameter().setLibLogLevel("debug");'/> + buttonGroup="fieldSimulAdvParamsLibLoggerGroup" selected='{handler.getParameters().isLibDebugLevel()}' + onActionPerformed='handler.getParameters().setLibLogLevel("debug");'/> </cell> </row> <row> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ExportHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ExportHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ExportHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -24,6 +24,7 @@ import static org.nuiton.i18n.I18n.t; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -32,6 +33,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.datastore.ExportStorage; +import fr.ifremer.isisfish.simulator.SimulationParameter; import fr.ifremer.isisfish.ui.WelcomePanelUI; import fr.ifremer.isisfish.ui.models.common.GenericListModel; @@ -56,10 +60,6 @@ refresh(); } - protected SimulAction getSimulAction() { - return tabUI.getContextValue(SimulAction.class); - } - public void refresh() { // FIXME listen for export modification here @@ -69,12 +69,12 @@ } protected void setListSimulExportChooseModel() { - java.util.List<String> availableExports = getSimulAction().getExportNames(); - java.util.List<String> userExports = getSimulAction().getSimulationParameter().getExportNames(); + java.util.List<String> availableExports = getExportNames(); + java.util.List<String> userExports = getParameters().getExportNames(); // userExports = intersection(userExports,availableExports) userExports.retainAll(availableExports); - GenericListModel<String> exportModel = new GenericListModel<String>(availableExports); + GenericListModel<String> exportModel = new GenericListModel<>(availableExports); tabUI.listSimulExportChoose.setModel(exportModel); for (String userExport : userExports) { @@ -90,7 +90,7 @@ for (String o : values) { exportNames.add(o); } - getSimulAction().getSimulationParameter().setExportNames(exportNames); + getParameters().setExportNames(exportNames); if (log.isDebugEnabled()) { log.debug("Set exports in simulation : " + exportNames); @@ -100,13 +100,13 @@ protected void saveConfigExports() { // Set exports (this can save empty list (not a big deal)) List<String> values = tabUI.listSimulExportChoose.getSelectedValuesList(); - List<String> exportNames = new LinkedList<String>(); + List<String> exportNames = new LinkedList<>(); for (String o : values) { exportNames.add(o); } - getSimulAction().getSimulationParameter().setExportNames(exportNames); + getParameters().setExportNames(exportNames); - getSimulAction().saveExport(); + saveExport(); setInfoText(t("isisfish.export.saved")); } @@ -115,4 +115,30 @@ WelcomePanelUI root = tabUI.getParentContainer(WelcomePanelUI.class); root.setStatusMessage(txt); } + + /* + * ExportUI + */ + + public List<String> getExportNames() { + List<String> exportNames = ExportStorage.getExportNames(); + List<String> result = new ArrayList<>(exportNames); + return result; + } + + /** + * Save current parameters exports names in configuration. + */ + public void saveExport() { + + SimulationParameter param = getParameters(); + if (param.getExportNames() != null) { + + if (log.isDebugEnabled()) { + log.debug("Set exports in configuration : " + param.getExportNames()); + } + + IsisFish.config.setDefaultExportNames(param.getExportNames()); + } + } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/OptimizationHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -26,6 +26,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -83,8 +84,7 @@ public void refresh() { // get info - SimulAction simulAction = tabUI.getContextValue(SimulAction.class); - SimulationParameter param = simulAction.getSimulationParameter(); + SimulationParameter param = getParameters(); RegionStorage regionStorage = tabUI.getContextValue(RegionStorage.class); // refresh after simulation storage set @@ -106,17 +106,6 @@ } /** - * Get simulation parameter from ui context. - * - * @return simulation parameters - */ - protected SimulationParameter getSimulationParameter() { - SimulAction simulAction = tabUI.getContextValue(SimulAction.class); - SimulationParameter param = simulAction.getSimulationParameter(); - return param; - } - - /** * Optimization model for combo box. * * @return model @@ -141,7 +130,7 @@ */ public void objectiveChanged() { String objectiveName = (String)tabUI.getFieldObjectiveMethodSelect().getSelectedItem(); - SimulationParameter param = getSimulationParameter(); + SimulationParameter param = getParameters(); RegionStorage regionStorage = tabUI.getContextValue(RegionStorage.class); // creation new instance only when name change to not lose parameters value @@ -211,12 +200,12 @@ @Override public void windowClosing(WindowEvent e) { // get first factor - FactorGroup factorGroup = sensitivityTabUI.getContextValue(SimulAction.class).getFactorGroup(); + FactorGroup factorGroup = getFactorGroup(); if (factorGroup.size() > 0) { Factor factor = factorGroup.get(factorGroup.size() - 1); // useless, but clear for next call - sensitivityTabUI.getContextValue(SimulAction.class).removeFactor(factor.getPath()); + removeFactor(factor.getPath()); setSelectedFactor(factor); } } @@ -227,8 +216,39 @@ } return factorEditorListener; } + + /** + * Remove factor in factor group tree by path. + * + * @param factorPath factor path to remove + * @deprecated this is a hack i think, should not be here and not used at all + */ + @Deprecated + public void removeFactor(String factorPath) { + removeFactor(getFactorGroup(), factorPath); + } /** + * Recursive remove for factor in factor group by path. + * + * @param factorGroup factor group to search to + * @param factorPath factor path to remove + * @deprecated this is a hack i think, should not be here and not used at all + */ + @Deprecated + protected void removeFactor(FactorGroup factorGroup, String factorPath) { + Collection<Factor> factorCopy = new ArrayList<Factor>(factorGroup.getFactors()); + for (Factor factor : factorCopy) { + if (factor instanceof FactorGroup) { + removeFactor((FactorGroup)factor, factorPath); + } + if (factorPath.equals(factor.getPath())) { + factorGroup.remove(factor); + } + } + } + + /** * Optimization model for combo box. * * @return model @@ -253,7 +273,7 @@ */ public void optimizationChanged() { String optimizationName = (String)tabUI.getFieldOptimizationMethodSelect().getSelectedItem(); - SimulationParameter param = getSimulationParameter(); + SimulationParameter param = getParameters(); RegionStorage regionStorage = tabUI.getContextValue(RegionStorage.class); // creation new instance only when name change to not lose parameters value @@ -311,7 +331,7 @@ * @return model */ public ExportObservationTableModel getExportObservationTableModel() { - SimulationParameter param = getSimulationParameter(); + SimulationParameter param = getParameters(); Map<ExportInfo, Observation> optimizationExportsObservations = param.getOptimizationExportsObservations(); ExportObservationTableModel model = new ExportObservationTableModel(optimizationExportsObservations); return model; @@ -322,7 +342,7 @@ */ public void addExports() { // get elements - SimulationParameter param = getSimulationParameter(); + SimulationParameter param = getParameters(); ExportObservationTableModel tableModel = (ExportObservationTableModel)tabUI.getExportObservationTable().getModel(); // add all selected exports @@ -349,7 +369,7 @@ */ public void removeExports() { // get element - SimulationParameter param = getSimulationParameter(); + SimulationParameter param = getParameters(); Map<ExportInfo, Observation> optimizationExports = param.getOptimizationExportsObservations(); ExportObservationTableModel tableModel = (ExportObservationTableModel)tabUI.getExportObservationTable().getModel(); @@ -371,7 +391,7 @@ */ public void clearExports() { // get elements - SimulationParameter param = getSimulationParameter(); + SimulationParameter param = getParameters(); Map<ExportInfo, Observation> optimizationExports = param.getOptimizationExportsObservations(); ExportObservationTableModel tableModel = (ExportObservationTableModel)tabUI.getExportObservationTable().getModel(); Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -22,38 +22,73 @@ */ package fr.ifremer.isisfish.ui.simulator; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.DOT; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.NUMBER_KEY; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.PARAMETERS_KEY; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.POPULATION_KEY; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.RULES_KEY; import static org.nuiton.i18n.I18n.t; +import java.awt.BorderLayout; +import java.awt.CardLayout; import java.awt.Cursor; +import java.awt.event.ActionEvent; +import java.io.File; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.ComboBoxModel; import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JPanel; import javax.swing.SwingUtilities; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.math.matrix.MatrixND; +import org.nuiton.math.matrix.gui.MatrixPanelEditor; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.datastore.RegionStorage; import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.datastore.SimulatorStorage; import fr.ifremer.isisfish.datastore.StorageChangeEvent; import fr.ifremer.isisfish.datastore.StorageChangeListener; import fr.ifremer.isisfish.datastore.StorageException; import fr.ifremer.isisfish.entities.FisheryRegion; import fr.ifremer.isisfish.entities.Population; +import fr.ifremer.isisfish.entities.Species; import fr.ifremer.isisfish.entities.Strategy; +import fr.ifremer.isisfish.mexico.MexicoHelper; +import fr.ifremer.isisfish.simulator.SimulationParameter; import fr.ifremer.isisfish.simulator.launcher.SimulationJob; import fr.ifremer.isisfish.simulator.launcher.SimulationService; import fr.ifremer.isisfish.simulator.launcher.SimulationServiceListener; import fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher; +import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan; +import fr.ifremer.isisfish.simulator.sensitivity.Factor; +import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; +import fr.ifremer.isisfish.simulator.sensitivity.SensitivityAnalysis; import fr.ifremer.isisfish.ui.SimulationUI; import fr.ifremer.isisfish.ui.WelcomePanelUI; import fr.ifremer.isisfish.ui.WelcomeTabUI; import fr.ifremer.isisfish.ui.models.common.GenericComboModel; import fr.ifremer.isisfish.ui.sensitivity.SensitivityUI; +import fr.ifremer.isisfish.ui.sensitivity.wizard.FactorWizardHandler; +import fr.ifremer.isisfish.ui.sensitivity.wizard.FactorWizardUI; +import fr.ifremer.isisfish.ui.util.ErrorHelper; +import jaxx.runtime.SwingUtil; /** * Params UI handler. @@ -65,6 +100,8 @@ /** Class logger. */ private static final Log log = LogFactory.getLog(ParamsHandler.class); + private static final SimpleDateFormat DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd-HH-mm"); + protected ParamsUI tabUI; // instances variables déclaration @@ -73,6 +110,8 @@ protected List<String> oldSimulNames = null; + protected String simulationName; + protected ParamsHandler(ParamsUI tabUI) { super(tabUI); this.tabUI = tabUI; @@ -113,19 +152,102 @@ // la gestion des regles est maintenant independante de SimulAction // il faut faire la lié aux parametres de simulations - getSimulAction().getSimulationParameter().setRules(tabUI.ruleChooser.getRulesList()); + getParameters().setRules(tabUI.ruleChooser.getRulesList()); } + public void setSimulationName(String simulationName) { + this.simulationName = simulationName; + } + public void refresh() { - if (getSimulAction().getSimulationStorage() != null) { - tabUI.fieldSimulParamsName.setText(getSimulAction().getSimulationStorage().getName()); - } - tabUI.fieldSimulParamsDesc.setText(getSimulAction().getSimulationParameter().getDescription()); + tabUI.fieldSimulParamsDesc.setText(getParameters().getDescription()); setListSimulParamsStrategiesItems(); setListSimulParamsPopulationsItems(); } /** + * Change region in simulation launcher + * + * @param regionName region name + */ + public void regionChange(String regionName) { + RegionStorage regionStorage = RegionStorage.getRegion(regionName); + // TODO this could be changed by setting storage into simulation context + tabUI.getParentContainer(SimulationUI.class).setContextValue(regionStorage); + tabUI.getParentContainer(SimulationUI.class).setRegionStorage(regionStorage); + getParameters().setRegionName(regionName); + } + + /** + * Load old simulation. + * + * Reset some field to empty default values: + * <ul> + * <li>params</li> + * <li>simulation plans</li> + * <li>factors list</li> + * </ul> + * + * Open old simulation: + * <ul> + * <li>params copy</li> + * <li>factors</li> + * </ul> + * + * @param simulName name of simulation to load + */ + public void loadOldSimulation(String simulName) { + if (log.isDebugEnabled()) { + log.debug("call loadOldSimulation: " + simulName); + } + try { + SimulatorContext context = tabUI.getContextValue(SimulatorContext.class); + + // read storage to get name + SimulationStorage simulStorage = SimulationStorage.getSimulation(simulName); + tabUI.getFieldSimulParamsName().setText(simulStorage.getName()); + + SimulationParameter param = simulStorage.getParameter().copy(); + // all time reset number after load + param.setSimulationPlanNumber(-1); + context.setSimulationParameter(param); + + + RegionStorage regionStorage = param.getRegion(); + context.setRegionStorage(regionStorage); + + // Chargement des facteurs + // clear list even if mexico file doesn't exists + getFactorGroup().clearFactors(); + File f = SimulationStorage.getMexicoDesignPlan(SimulationStorage.getSimulationDirectory(simulName)); + if (f != null && f.canRead()) { + if (log.isInfoEnabled()) { + log.info("Import design plan from : " + f.getAbsolutePath()); + } + TopiaContext topiaContext = regionStorage.getStorage(); + DesignPlan designPlan = MexicoHelper.getDesignPlanFromXML(f, topiaContext); + for (Factor factor : designPlan.getFactors()) { + if (log.isDebugEnabled()) { + log.debug("Find factor : " + factor.getName()); + } + //factors.put(factor.getPath() + factor.getName(), factor); + FactorGroup factorGroup = designPlan.getFactorGroup(); + context.setFactorGroup(factorGroup); + } + } + else if (log.isInfoEnabled()) { + log.info("No xml design plan file found"); + } + } catch (Exception eee) { + throw new IsisFishRuntimeException(t("isisfish.error.simulation.loadoldsimulation"), eee); + } + } + + public List<SimulatorLauncher> getSimulationLauncher() { + return SimulationService.getService().getSimulationLaunchers(); + } + + /** * Called on user region selection change. */ protected void regionChange() { @@ -139,7 +261,7 @@ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - getSimulAction().regionChange(tabUI, selected); + regionChange(selected); // FIXME fix this if (!tabUI.isSensitivity()) { tabUI.getParentContainer(SimulUI.class).refresh(); @@ -156,16 +278,16 @@ protected void initSimulationParams() { if (!tabUI.isSensitivity()){ // prescript - String preScript = getSimulAction().getSimulationParameter().getPreScript(); + String preScript = getParameters().getPreScript(); tabUI.fieldUseSimulPreScripts.setSelected(preScript != null && !preScript.isEmpty()); tabUI.getParentContainer(SimulUI.class).getPreScriptUI().getFieldSimulPreScript().setText(preScript); // simulation plan - tabUI.fieldSimulUseSimulationPlan.setSelected(getSimulAction().getSimulationParameter().getUseSimulationPlan()); + tabUI.fieldSimulUseSimulationPlan.setSelected(getParameters().getUseSimulationPlan()); tabUI.getParentContainer(SimulUI.class).getPlanUI().getHandler().refresh(); // optimization - tabUI.fieldSimulUseOptimization.setSelected(getSimulAction().getSimulationParameter().getUseOptimization()); + tabUI.fieldSimulUseOptimization.setSelected(getParameters().getUseOptimization()); tabUI.getParentContainer(SimulUI.class).getOptimizationUI().getHandler().refresh(); } @@ -175,8 +297,8 @@ if (tabUI.isSensitivity()) { try { // FIXME this transaction in never closed - // and can't be closed because used in - TopiaContext tx = getSimulAction().getRegionStorage().getStorage().beginTransaction(); + // and can't be closed because used in + TopiaContext tx = tabUI.getContextValue(RegionStorage.class).getStorage().beginTransaction(); FisheryRegion fisheryRegion = RegionStorage.getFisheryRegion(tx); tabUI.getParentContainer(SensitivityUI.class).getSensitivityInputUI().setFisheryRegion(fisheryRegion); tabUI.getParentContainer(SensitivityUI.class).getSensitivityInputUI().getHandler().setTreeModel(); @@ -196,7 +318,7 @@ tabUI.getParentContainer(SensitivityUI.class).getSensitivityChooserUI().getHandler().refreshSelectedSensitivityAnalysis(); tabUI.getParentContainer(SensitivityUI.class).getSensitivityInputUI().getHandler().setFactorModel(); tabUI.getParentContainer(SensitivityUI.class).getSensitivityChooserUI().getHandler().setSensitivityExportListModel(); - tabUI.sensitivityOnlyKeepFirstResultCheckBox.setSelected(getSimulAction().getSimulationParameter().isSensitivityAnalysisOnlyKeepFirst()); + tabUI.sensitivityOnlyKeepFirstResultCheckBox.setSelected(getParameters().isSensitivityAnalysisOnlyKeepFirst()); } } @@ -215,8 +337,8 @@ @Override public void run() { - getSimulAction().loadOldSimulation(selected); - tabUI.fieldSimulParamsRegion.setSelectedItem(tabUI.getContextValue(SimulAction.class).getSimulationParameter().getRegionName()); + loadOldSimulation(selected); + tabUI.fieldSimulParamsRegion.setSelectedItem(getParameters().getRegionName()); // FIXME fix this if (!tabUI.isSensitivity()) { @@ -226,12 +348,12 @@ } // mise a jour des années - tabUI.fieldSimulParamsNbMois.setText(String.valueOf(getSimulAction().getNumberOfMonths())); + tabUI.fieldSimulParamsNbMois.setText(String.valueOf(getNumberOfMonths())); initSimulationParams(); initSensitivityParams(); // regles - tabUI.ruleChooser.setRulesList(getSimulAction().getSimulationParameter().getRules()); + tabUI.ruleChooser.setRulesList(getParameters().getRules()); tabUI.getParentContainer(WelcomePanelUI.class).setStatusMessage(t("isisfish.message.old.simulation.loaded")); tabUI.setCursor(Cursor.getDefaultCursor()); @@ -246,9 +368,9 @@ protected void launchSimulation() { if (!tabUI.isSensitivity()) { - getSimulAction().launchSimulation(tabUI.fieldSimulParamsName.getText(), (SimulatorLauncher)tabUI.comboSelLauncher.getSelectedItem()); + launchSimulation(tabUI.fieldSimulParamsName.getText(), (SimulatorLauncher)tabUI.comboSelLauncher.getSelectedItem()); } else { - getSimulAction().launchSimulationWithSensibility(tabUI.fieldSimulParamsName.getText(), (SimulatorLauncher)tabUI.comboSelLauncher.getSelectedItem()); + launchSimulationWithSensibility(tabUI.fieldSimulParamsName.getText(), (SimulatorLauncher)tabUI.comboSelLauncher.getSelectedItem()); } // dans le cas d'une fenetre independante, il n'y a pas de ParentContainer @@ -257,27 +379,261 @@ parent.setQueueTabSelection(); } } + + /** + * Launch simulation with factors variations parameters. + * + * @param simulationId id of the simulation to simulate + * @param launcher launcher to use + * + * @see SimulatorLauncher + * @see SensitivityAnalysis + * @see DesignPlan + */ + public void launchSimulationWithSensibility(String simulationId, + SimulatorLauncher launcher) { + + String fullSimulationId = "as_" + simulationId + "_" + + DATEFORMAT.format(new java.util.Date()); + + SensitivityAnalysis sensitivityAnalysis = getParameters().getSensitivityAnalysis(); + + // log + if (log.isDebugEnabled()) { + log.debug("Launch factor simulation with custom launcher " + + launcher.toString()); + log.debug("Using sensitivityCalculator : " + + sensitivityAnalysis.getDescription()); + } + + try { + if (checkAndPrepare(fullSimulationId)) { + DesignPlan designPlan = new DesignPlan(); + designPlan.setFactorGroup(getFactorGroup()); + SimulationService.getService().submit(fullSimulationId, getParameters(), + launcher, 0, sensitivityAnalysis, designPlan); + } + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't start simulation", eee); + } + ErrorHelper.showErrorDialog(t("isisfish.error.simulation.launchsimulation"), eee); + } + } + + protected boolean checkAndPrepare(String fullSimulationId) { + boolean result = !("".equals(fullSimulationId) + || SimulationStorage.localyExists(fullSimulationId) + || SimulationService.getService().exists(fullSimulationId)); + + if (result) { + // force all necessary config simulation in tag value + Map<String, String> m = new HashMap<String, String>( + IsisFish.config.getDefaultSimulationConfig()); + Map<String, String> tv = getParameters().getTagValue(); + m.putAll(tv); + getParameters().setTagValue(m); + } else { + ErrorHelper.showErrorDialog(t("isisfish.simulator.simulaction.badid", + fullSimulationId), null); + } + + return result; + } + /** + * Launch automatically the simulation, when is possible (no other simulation) + * or wait for the last automatically simulation ended. + * + * @param simulationId id of the simulation to simulate + * @param launcher launcher to use + * + * @see SimulatorLauncher + */ + public void launchSimulation(String simulationId, SimulatorLauncher launcher) { + + String fullSimulationId = "sim_" + simulationId + "_" + + DATEFORMAT.format(new java.util.Date()); + + // log + if (log.isDebugEnabled()) { + log.debug("Launch simulation with custom launcher " + + launcher.toString()); + } + + try { + if (checkAndPrepare(fullSimulationId)) { + SimulationService.getService().submit(fullSimulationId, getParameters(), + launcher, 0); + } + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Can't start simulation", eee); + } + ErrorHelper.showErrorDialog(t("isisfish.error.simulation.launchsimulation"), eee); + } + } + + /** + * Population selection changed. + * + * Fill matrix panel with population effective of selected population. + */ + public void populationSelected() { + CardLayout layout = (CardLayout)tabUI.getPopulationEffectivesPanel().getLayout(); + + List<Population> selectedPopulationsValues = tabUI.getListSimulParamsPopulations().getSelectedValuesList(); + if (CollectionUtils.isNotEmpty(selectedPopulationsValues)) { + tabUI.getPopulationEffectivesTabbedPane().removeAll(); + setPopulations(selectedPopulationsValues); + + for (Population selectedPopulation : selectedPopulationsValues) { + final MatrixPanelEditor matrixPanel = new MatrixPanelEditor(); + MatrixND populationEffectives = getParameters().getNumberOf(selectedPopulation); + matrixPanel.setMatrix(populationEffectives); + + JPanel matrixPanelComponent = new JPanel(new BorderLayout()); + matrixPanelComponent.add(matrixPanel, BorderLayout.CENTER); + + // add addFactorButton with matrixPanel (just in sensitivity cas) + if (tabUI.isSensitivity()) { + matrixPanel.putClientProperty("sensitivityPopulation", selectedPopulation); + // TODO add another thing that action + JButton addFactorButton = new JButton(); + addFactorButton.setAction(new AbstractAction() { + public void actionPerformed(ActionEvent e) { + addFactorWithComponent(matrixPanel); + } + @Override + public Object getValue(String key) { + Object result = null; + if (key.equals(Action.SMALL_ICON)) { + result = SwingUtil.createImageIcon("sensitivity/flag--plus.png"); + } + return result; + } + }); + matrixPanelComponent.add(addFactorButton, BorderLayout.EAST); + } + + tabUI.getPopulationEffectivesTabbedPane().add(matrixPanelComponent, + t("isisfish.params.populationEffectives", selectedPopulation.getName())); + } + + layout.show(tabUI.getPopulationEffectivesPanel(), "specific"); + } + else { + layout.show(tabUI.getPopulationEffectivesPanel(), "default"); + } + } + + /** + * Action appelée lors du clic sur les boutons a coté des composants factorisables. + * + * Contrairement à l'interface 'input', on edite ici des facteurs existants, + * (créé à la première demande). + * + * @param source la source de l'event + */ + public void addFactorWithComponent(JComponent source) { + + if (log.isDebugEnabled()) { + log.debug("Event intercepted on " + source); + } + + Factor selectedFactor = null; + + // new factor with rule domain + if (source instanceof RuleChooser) { + String factorPath = PARAMETERS_KEY + DOT + RULES_KEY; + selectedFactor = getFactor(factorPath); + if (selectedFactor == null) { + selectedFactor = new Factor(t("isisfish.sensitivity.rulesfactorname")); + selectedFactor.setPath(factorPath); + //selectedFactor.setDomain(new RuleDiscreteDomain()); + } + } + + // new factor with matrix continous domain + else if (source instanceof MatrixPanelEditor) { + Population population = (Population)source.getClientProperty("sensitivityPopulation"); + String factorPath = PARAMETERS_KEY + DOT + POPULATION_KEY + DOT + population.getName() + DOT + NUMBER_KEY; + selectedFactor = getFactor(factorPath); + if (selectedFactor == null) { + selectedFactor = new Factor(t("isisfish.sensitivity.populationfactorname", population.getName())); + selectedFactor.setPath(factorPath); + //MatrixND populationEffectives = getSimulationParameter().getNumberOf(population); + /*MatrixContinuousDomain factorDomain = new MatrixContinuousDomain(); + factorDomain.setReferenceValue(populationEffectives.copy()); + factorDomain.setCoefficient(0.0); + ContinuousDomain domain = new ContinuousDomain(Distribution.QUNIFPC); + domain.addDistributionParam(Distribution.QUNIFPC.getDistibutionParams()[0].getName(), populationEffectives.copy()); + domain.addDistributionParam(Distribution.QUNIFPC.getDistibutionParams()[1].getName(), 0.0d); + selectedFactor.setDomain(domain);*/ + } + } + + if (selectedFactor != null) { + FactorWizardUI wizard = new FactorWizardUI(tabUI); + FactorWizardHandler handler = wizard.getHandler(); + handler.initExistingFactor(wizard, selectedFactor); + wizard.pack(); + wizard.setLocationRelativeTo(tabUI); + wizard.setVisible(true); + } + } + + /** + * Search factor in factor group tree by path. + * + * @param factorPath factor path to search + * @return found factor + */ + public Factor getFactor(String factorPath) { + return getFactor(getFactorGroup(), factorPath); + } + + /** + * Recursive search for factor in factor group by path. + * + * @param factorGroup factor group to search to + * @param factorPath factor path to search + * @return found factor + */ + protected Factor getFactor(FactorGroup factorGroup, String factorPath) { + Factor result = null; + for (Factor factor : factorGroup.getFactors()) { + if (factor instanceof FactorGroup) { + result = getFactor((FactorGroup)factor, factorPath); + } + if (factorPath.equals(factor.getPath())) { + result = factor; + } + } + return result; + } + protected void enablePreScript() { - getSimulAction().getSimulationParameter().setUsePreScript(tabUI.fieldUseSimulPreScripts.isSelected()); + getParameters().setUsePreScript(tabUI.fieldUseSimulPreScripts.isSelected()); SimulationUI simulationUI = tabUI.getParentContainer(SimulationUI.class); simulationUI.setEnabledPrescriptTab(tabUI.fieldUseSimulPreScripts.isSelected()); } + protected void enableSimulationPlan() { - getSimulAction().getSimulationParameter().setUseSimulationPlan(tabUI.fieldSimulUseSimulationPlan.isSelected()); + getParameters().setUseSimulationPlan(tabUI.fieldSimulUseSimulationPlan.isSelected()); SimulationUI simulationUI = tabUI.getParentContainer(SimulationUI.class); simulationUI.setEnabledSimulationPlanTab(tabUI.fieldSimulUseSimulationPlan.isSelected()); } protected void enableOptimization() { - getSimulAction().getSimulationParameter().setUseOptimization(tabUI.fieldSimulUseOptimization.isSelected()); + getParameters().setUseOptimization(tabUI.fieldSimulUseOptimization.isSelected()); SimulationUI simulationUI = tabUI.getParentContainer(SimulationUI.class); simulationUI.setEnabledOptimizationTab(tabUI.fieldSimulUseOptimization.isSelected()); } protected void setListSimulParamsStrategiesItems() { - List<Strategy> strategiesSelected = getSimulAction().getSimulationParameter().getStrategies(); - DefaultListModel<Strategy> listSimulParamsStrategiesModel = new DefaultListModel<Strategy>(); - List<Strategy> strategies = getSimulAction().getStrategies(); + List<Strategy> strategiesSelected = getParameters().getStrategies(); + DefaultListModel<Strategy> listSimulParamsStrategiesModel = new DefaultListModel<>(); + List<Strategy> strategies = getStrategies(); for (Strategy s : strategies){ listSimulParamsStrategiesModel.addElement(s); } @@ -291,9 +647,9 @@ } } protected void setListSimulParamsPopulationsItems(){ - List<Population> populationsSelected = getSimulAction().getSimulationParameter().getPopulations(); - DefaultListModel<Population> listSimulParamsPopulationsModel = new DefaultListModel<Population>(); - List<Population> populations = getSimulAction().getPopulations(); + List<Population> populationsSelected = getParameters().getPopulations(); + DefaultListModel<Population> listSimulParamsPopulationsModel = new DefaultListModel<>(); + List<Population> populations = getPopulations(); for (Population p : populations){ listSimulParamsPopulationsModel.addElement(p); } @@ -307,8 +663,8 @@ } } - protected void strategySelected(){ - getSimulAction().setStrategies(tabUI.listSimulParamsStrategies.getSelectedValuesList()); + protected void strategySelected() { + setStrategies(tabUI.listSimulParamsStrategies.getSelectedValuesList()); } protected ComboBoxModel<String> getSimulParamsSelectModel() { @@ -380,4 +736,98 @@ public void resetOldSimulatorNames() { oldSimulNames = getOldSimulationItem(); } + + /** + * Get strategies list to fill Jlist in ParamUI. + * + * @return strategies list + */ + public List<Strategy> getStrategies() { + List<Strategy> result = new ArrayList<>(); + try { + TopiaContext tx = getParameters().getRegion().getStorage().beginTransaction(); + result = RegionStorage.getFisheryRegion(tx).getStrategy(); + tx.rollbackTransaction(); + tx.closeContext(); + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Can't get strategies", e); + } + ErrorHelper.showErrorDialog(t("isisfish.error.simulation.liststrategies"), e); + } + return result; + } + + /** + * Set parameters strategies. + * + * @param strategies + */ + public void setStrategies(List<Strategy> strategies) { + List<Strategy> result = new ArrayList<>(strategies); + getParameters().setStrategies(result); + } + + /** + * Get population list to fill JList in paramUI. + * + * @return populations list + */ + public List<Population> getPopulations() { + + List<Population> result = new ArrayList<>(); + try { + TopiaContext tx = getParameters().getRegion().getStorage().beginTransaction(); + List<Species> species = RegionStorage.getFisheryRegion(tx) + .getSpecies(); + for (Species s : species) { + Collection<Population> populations = s.getPopulation(); + + // FIXME initialiaze lazy hibernate collection + for (Population p : populations) { + p.getPopulationGroup().size(); + p.getPopulationZone().size(); + } + + result.addAll(populations); + } + tx.rollbackTransaction(); + tx.closeContext(); + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Can't get population", e); + } + ErrorHelper.showErrorDialog(t("isisfish.error.simulation.listpopulation"), e); + } + return result; + } + + /** + * Set parameter population. + * + * @param populations populations to set + */ + public void setPopulations(List<Population> populations) { + List<Population> result = new ArrayList<>(populations); + getParameters().setPopulations(result); + } + + public int getNumberOfMonths() { + return getParameters().getNumberOfMonths(); + } + + /** + * Change number of simulation month by parsing string value. + * Default to 1 if value is not parsable. + * + * @param months number of months to set + */ + public void setNumberOfMonths(String months) { + try { + getParameters().setNumberOfMonths(Integer.parseInt(months)); + } catch (NumberFormatException ex) { + // defaut to one year + getParameters().setNumberOfMonths(1); + } + } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -80,8 +80,8 @@ <JTextField id="fieldSimulParamsName" /> <javax.swing.text.Document javaBean="fieldSimulParamsName.getDocument()" - onInsertUpdate='getContextValue(SimulAction.class).setName(fieldSimulParamsName.getText())' - onRemoveUpdate='getContextValue(SimulAction.class).setName(fieldSimulParamsName.getText())' /> + onInsertUpdate='handler.setSimulationName(fieldSimulParamsName.getText())' + onRemoveUpdate='handler.setSimulationName(fieldSimulParamsName.getText())' /> </cell> </row> </Table> @@ -95,7 +95,7 @@ <cell fill="horizontal" weightx="1.0"> <JComboBox id="fieldSimulParamsRegion" genericType="String" model='{new fr.ifremer.isisfish.ui.models.common.GenericComboModel<String>(fr.ifremer.isisfish.datastore.RegionStorage.getRegionNames())}' - selectedItem='{getContextValue(SimulAction.class).getSimulationParameter().getRegionName()}' + selectedItem='{handler.getParameters().getRegionName()}' onActionPerformed='handler.regionChange()' /> </cell> </row> @@ -112,11 +112,11 @@ weighty="0.3"> <JScrollPane> <JTextArea id="fieldSimulParamsDesc" - text='{getContextValue(SimulAction.class).getSimulationParameter().getDescription()}' /> + text='{handler.getParameters().getDescription()}' /> <javax.swing.text.Document javaBean="fieldSimulParamsDesc.getDocument()" - onInsertUpdate='getContextValue(SimulAction.class).getSimulationParameter().setDescription(fieldSimulParamsDesc.getText())' - onRemoveUpdate='getContextValue(SimulAction.class).getSimulationParameter().setDescription(fieldSimulParamsDesc.getText())' /> + onInsertUpdate='handler.getParameters().setDescription(fieldSimulParamsDesc.getText())' + onRemoveUpdate='handler.getParameters().setDescription(fieldSimulParamsDesc.getText())' /> </JScrollPane> </cell> </row> @@ -132,11 +132,11 @@ <cell fill="both" weightx="1.0"> <JTextField id="fieldSimulParamsNbMois" - text='{String.valueOf(getContextValue(SimulAction.class).getSimulationParameter().getNumberOfMonths())}' /> + text='{String.valueOf(handler.getParameters().getNumberOfMonths())}' /> <javax.swing.text.Document javaBean="fieldSimulParamsNbMois.getDocument()" - onInsertUpdate='getContextValue(SimulAction.class).setNumberOfMonths(fieldSimulParamsNbMois.getText())' - onRemoveUpdate='getContextValue(SimulAction.class).setNumberOfMonths(fieldSimulParamsNbMois.getText())' /> + onInsertUpdate='handler.setNumberOfMonths(fieldSimulParamsNbMois.getText())' + onRemoveUpdate='handler.setNumberOfMonths(fieldSimulParamsNbMois.getText())' /> </cell> </row> </Table> @@ -177,7 +177,7 @@ genericType="fr.ifremer.isisfish.entities.Population" selectionMode="{javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION}" selectionModel="{new jaxx.runtime.swing.OneClicListSelectionModel(listSimulParamsPopulations.getSelectionModel(), listSimulParamsPopulations.getModel())}" - onValueChanged='getContextValue(SimulAction.class).populationSelected(this)' + onValueChanged='handler.populationSelected()' enabled="{getRegionStorage() != null}" /> </JScrollPane> </cell> @@ -210,8 +210,8 @@ </cell> <cell anchor="north"> <JButton id="addRuleFactorButton" - icon='{SwingUtil.createImageIcon("building_add.png")}' - onActionPerformed="getContextValue(SimulAction.class).addFactorWithComponent(this, ruleChooser)" + icon='{SwingUtil.createImageIcon("sensitivity/flag--plus.png")}' + onActionPerformed="handler.addFactorWithComponent(ruleChooser)" visible="{isSensitivity()}" enabled="{getRegionStorage() != null}" /> </cell> @@ -231,14 +231,14 @@ <cell fill="horizontal" weightx="1"> <JCheckBox text="isisfish.params.usePreSimulationScript" id="fieldUseSimulPreScripts" - selected='{getContextValue(SimulAction.class).getSimulationParameter().getUsePreScript()}' + selected='{handler.getParameters().getUsePreScript()}' visible='{!isSensitivity()}' onItemStateChanged='handler.enablePreScript()' /> </cell> <cell fill="horizontal" weightx="1"> <JCheckBox text="isisfish.params.useSimulationPlan" id="fieldSimulUseSimulationPlan" - selected='{getContextValue(SimulAction.class).getSimulationParameter().getUseSimulationPlan()}' + selected='{handler.getParameters().getUseSimulationPlan()}' visible='{!isSensitivity()}' onItemStateChanged='handler.enableSimulationPlan()' enabled="{getRegionStorage() != null}" /> @@ -246,7 +246,7 @@ <cell fill="horizontal" weightx="1"> <JCheckBox text="isisfish.params.useOptimization" id="fieldSimulUseOptimization" - selected='{getContextValue(SimulAction.class).getSimulationParameter().getUseOptimization()}' + selected='{handler.getParameters().getUseOptimization()}' visible='{!isSensitivity()}' onItemStateChanged='handler.enableOptimization()' enabled="{getRegionStorage() != null}" /> @@ -254,9 +254,9 @@ <cell fill="horizontal" weightx="1"> <JCheckBox text="isisfish.params.sensitivityOnlyKeepFirstResult" id="sensitivityOnlyKeepFirstResultCheckBox" - selected='{getContextValue(SimulAction.class).getSimulationParameter().isSensitivityAnalysisOnlyKeepFirst()}' + selected='{handler.getParameters().isSensitivityAnalysisOnlyKeepFirst()}' visible='{isSensitivity()}' - onItemStateChanged='getContextValue(SimulAction.class).getSimulationParameter().setSensitivityAnalysisOnlyKeepFirst(sensitivityOnlyKeepFirstResultCheckBox.isSelected())' + onItemStateChanged='handler.getParameters().setSensitivityAnalysisOnlyKeepFirst(sensitivityOnlyKeepFirstResultCheckBox.isSelected())' enabled="{getRegionStorage() != null}" /> </cell> </row> @@ -273,7 +273,7 @@ <cell fill="horizontal" weightx="0.4"> <JComboBox id="comboSelLauncher" genericType="fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher" - model='{new DefaultComboBoxModel(getContextValue(SimulAction.class).getSimulationLauncher().toArray())}' /> + model='{new DefaultComboBoxModel(handler.getSimulationLauncher().toArray())}' /> </cell> <cell fill="horizontal" weightx="0.4"> <JButton id="buttonSimulParamsSimulate" @@ -284,7 +284,7 @@ <cell fill="horizontal" weightx="0.2"> <JButton id="saveSimul" text="isisfish.simulation.menu.save" - onActionPerformed='getParentContainer(fr.ifremer.isisfish.ui.SimulationUI.class).saveSimulation()' + onActionPerformed='getParentContainer(fr.ifremer.isisfish.ui.SimulationUI.class).getHandler().saveSimulation()' enabled="{getRegionStorage() != null}" /> </cell> </row> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PlanHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PlanHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PlanHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -26,6 +26,8 @@ import javax.swing.table.DefaultTableModel; +import fr.ifremer.isisfish.IsisFishException; +import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.datastore.RegionStorage; import fr.ifremer.isisfish.datastore.SimulationPlanStorage; import fr.ifremer.isisfish.datastore.StorageChangeEvent; @@ -36,6 +38,7 @@ import fr.ifremer.isisfish.ui.models.common.ScriptParametersTableCellEditor; import fr.ifremer.isisfish.ui.models.common.ScriptParametersTableCellRenderer; import fr.ifremer.isisfish.ui.models.common.ScriptParametersTableModel; +import fr.ifremer.isisfish.ui.widget.editor.ScriptParameterDialog; /** * Plan UI handler. @@ -75,10 +78,45 @@ } /** + * Return simulation plan names list. + * + * @return simulation plan names + */ + public List<String> getSimulationPlanNames() { + return SimulationPlanStorage.getSimulationPlanNames(); + } + + public List<SimulationPlan> getParamSimulationPlans() { + return getParameters().getSimulationPlans(); + } + + public void addSimulationPlan(PlanUI planUI, String name) { + try { + SimulationPlan sp = SimulationPlanStorage.getSimulationPlan(name).getNewInstance(); + + // add it after autoconfiguration (if enabled) + sp = (SimulationPlan)ScriptParameterDialog.displayConfigurationFrame(planUI, sp); + if (sp != null) { + getParameters().addSimulationPlan(sp); + } + } catch (IsisFishException ex) { + throw new IsisFishRuntimeException("Can't add simulation plan", ex); + } + } + + public void removeSimulationPlan(SimulationPlan sp) { + getParameters().removeSimulationPlan(sp); + } + + public void clearSimulationPlans() { + getParameters().clearPlans(); + } + + /** * Refresh simulation plan names list. */ protected GenericComboModel<String> getSimulationPlansComboModel() { - List<String> simulationPlanNames = tabUI.simulAction.getSimulationPlanNames(); + List<String> simulationPlanNames = getSimulationPlanNames(); GenericComboModel<String> model = new GenericComboModel<>(simulationPlanNames); return model; } @@ -87,33 +125,33 @@ * Refresh simulation simulation plan list. */ protected GenericListModel<SimulationPlan> getSimulationSimulationPlansListModel() { - List<SimulationPlan> simulationPlans = tabUI.simulAction.getParamSimulationPlans(); + List<SimulationPlan> simulationPlans = getParamSimulationPlans(); GenericListModel<SimulationPlan> model = new GenericListModel<>(simulationPlans); return model; } protected void addSimulationPlan() { String selectedSimulationPlanName = (String)tabUI.fieldSimulParamsSimulationPlansSelect.getSelectedItem(); - tabUI.simulAction.addSimulationPlan(tabUI, selectedSimulationPlanName); + addSimulationPlan(tabUI, selectedSimulationPlanName); tabUI.listSimulParamsSimulationPlansList.setModel(getSimulationSimulationPlansListModel()); setSimulationPlanButtons(); } protected void removeSimulationPlan() { SimulationPlan selectedSimulationPlan = (SimulationPlan)tabUI.listSimulParamsSimulationPlansList.getSelectedValue(); - tabUI.simulAction.removeSimulationPlan(selectedSimulationPlan); + removeSimulationPlan(selectedSimulationPlan); tabUI.listSimulParamsSimulationPlansList.setModel(getSimulationSimulationPlansListModel()); setSimulationPlanButtons(); } protected void clearSimulationPlan() { - tabUI.simulAction.clearSimulationPlans(); + clearSimulationPlans(); tabUI.listSimulParamsSimulationPlansList.setModel(getSimulationSimulationPlansListModel()); setSimulationPlanButtons(); } protected void setSimulationPlanButtons() { - if (tabUI.getContextValue(SimulAction.class).getParamSimulationPlans().isEmpty()) { + if (getParamSimulationPlans().isEmpty()) { tabUI.buttonSimulParamsSimulationPlansClear.setEnabled(false); tabUI.buttonSimulParamsSimulationPlansRemove.setEnabled(false); } else { Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PlanUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PlanUI.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PlanUI.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -29,8 +29,6 @@ java.awt.Dimension </import> - <SimulAction id='simulAction' javaBean='getContextValue(SimulAction.class)' /> - <script><![CDATA[ protected void $afterCompleteSetup() { handler.afterInit(); Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PreScriptsHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PreScriptsHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/PreScriptsHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -41,7 +41,7 @@ } protected void save() { - tabUI.getContextValue(SimulAction.class).getSimulationParameter().setPreScript(tabUI.fieldSimulPreScript.getText()); + getParameters().setPreScript(tabUI.fieldSimulPreScript.getText()); } public void refresh() { Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ResultChoiceHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ResultChoiceHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ResultChoiceHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -24,12 +24,20 @@ import static org.nuiton.i18n.I18n.t; +import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.List; import javax.swing.event.ListSelectionEvent; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.datastore.ScriptStorage; import fr.ifremer.isisfish.ui.WelcomePanelUI; import fr.ifremer.isisfish.ui.models.common.GenericListModel; +import fr.ifremer.isisfish.ui.util.ErrorHelper; /** * Result choice UI handler. @@ -38,6 +46,8 @@ */ public class ResultChoiceHandler extends SimulatorTabHandler { + private static final Log log = LogFactory.getLog(ResultChoiceHandler.class); + protected ResultChoiceUI tabUI; public ResultChoiceHandler(ResultChoiceUI tabUI) { @@ -56,10 +66,39 @@ setListSimulResultChooseModel(); } + /** + * Looking for ResultName.java script and read all fields and fill + * list of field value and doc + * @return the list of result names found in ResultName script + */ + protected List<String> getResultNames() { + List<String> result = new ArrayList<String>(); + try { + ScriptStorage storage = ScriptStorage.getScript("ResultName.java"); + Class<?> resultNameClass = storage.getCodeClass(); + // TODO: if we can't find class, perhaps try to parser Java source ? + Field[] fields = resultNameClass.getFields(); + for (Field f : fields) { + String fieldName = (String) f.get(null); + result.add(fieldName); + } + } catch (Exception eee) { + if (log.isWarnEnabled()) { + log.warn("Can't find result name script", eee); + } + ErrorHelper.showErrorDialog(t("isisfish.error.simulation.getresultname"), eee); + } + return result; + } + + public List<String> getDefaultResultNames() { + return IsisFish.config.getDefaultResultNamesAsList(); + } + protected void setListSimulResultChooseModel() { - List<String> availableResults = getSimulAction().getResultNames(); - List<String> userResults = getSimulAction().getDefaultResultNames(); + List<String> availableResults = getResultNames(); + List<String> userResults = getDefaultResultNames(); // userResults = intersection(userResults,availableResult) userResults.retainAll(availableResults); @@ -73,14 +112,32 @@ } protected void saveParametersResultNames(ListSelectionEvent event) { - tabUI.getContextValue(SimulAction.class).saveParametersResultNames(tabUI.listResultNames.getSelectedValuesList()); + saveParametersResultNames(tabUI.listResultNames.getSelectedValuesList()); } protected void saveConfigResultNames() { - tabUI.getContextValue(SimulAction.class).saveConfigurationResultNames(tabUI.listResultNames.getSelectedValuesList()); + saveConfigurationResultNames(tabUI.listResultNames.getSelectedValuesList()); setStatusMessage(t("isisfish.resultChoice.saved")); } + + public void saveParametersResultNames(List<String> resultNames) { + List<String> resultNamesString = new ArrayList<>(resultNames); + getParameters().setResultEnabled(resultNamesString); + + if (log.isDebugEnabled()) { + log.debug("Set simulation result names : " + resultNamesString); + } + } + public void saveConfigurationResultNames(List<String> resultNames) { + List<String> resultNamesString = new ArrayList<>(resultNames); + IsisFish.config.setDefaultResultNames(resultNamesString); + + if (log.isDebugEnabled()) { + log.debug("Set configuration result names : " + resultNamesString); + } + } + protected void setStatusMessage(String txt) { // TODO remove getParentContainer use WelcomePanelUI root = tabUI.getParentContainer(WelcomePanelUI.class); Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooser.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooser.jaxx 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooser.jaxx 2015-06-11 09:01:47 UTC (rev 4263) @@ -48,9 +48,12 @@ <cell> <JPanel /> </cell> - <cell fill="horizontal"> + <cell fill="horizontal" weightx="1"> <JLabel text="isisfish.params.rules.selected" enabled="{isActive()}"/> </cell> + <cell> + <JLabel icon="common/information-small.png" toolTipText="isisfish.params.rules.tooltip" enabled="{isActive()}"/> + </cell> </row> <row> <cell fill="both" rows="3" weightx="1" weighty="1"> @@ -66,7 +69,7 @@ <cell fill='horizontal'> <JButton id="addRulesButton" text="isisfish.common.add" enabled="false" onActionPerformed='handler.addSelectedRules()'/> </cell> - <cell fill="both" rows="3" weightx="1" weighty="1"> + <cell fill="both" rows="3" columns="2" weightx="1" weighty="1"> <JScrollPane enabled="{isActive()}"> <fr.ifremer.isisfish.ui.models.common.GenericListModel id="selectedRulesListModel" genericType="fr.ifremer.isisfish.rule.Rule" /> <JList id="selectedRulesList" selectionMode="{javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION}" @@ -88,7 +91,7 @@ enabled="false" onActionPerformed='handler.clearAllRules()'/> </cell> </row> - <row weightx="2" weighty="2" columns="3"> + <row weightx="2" weighty="2" columns="4"> <cell fill='both'> <JScrollPane enabled="{isActive()}"> <fr.ifremer.isisfish.ui.models.common.ScriptParametersTableModel Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooserHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooserHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/RuleChooserHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -23,6 +23,10 @@ package fr.ifremer.isisfish.ui.simulator; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.DOT; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.PARAMETERS_KEY; +import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.RULE_KEY; + import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; @@ -33,17 +37,25 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.swing.DropMode; import javax.swing.JList; import javax.swing.TransferHandler; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import fr.ifremer.isisfish.IsisFishException; import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.datastore.RegionStorage; import fr.ifremer.isisfish.datastore.RuleStorage; import fr.ifremer.isisfish.rule.Rule; +import fr.ifremer.isisfish.simulator.sensitivity.Factor; +import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; import fr.ifremer.isisfish.ui.SimulationUI; import fr.ifremer.isisfish.ui.models.common.ScriptParametersTableCellEditor; import fr.ifremer.isisfish.ui.models.common.ScriptParametersTableCellRenderer; @@ -63,6 +75,8 @@ */ public class RuleChooserHandler { + private static final Log log = LogFactory.getLog(RuleChooserHandler.class); + protected RuleChooser ruleChooser; public RuleChooserHandler(RuleChooser ruleChooser) { @@ -185,7 +199,6 @@ * Remove selected rules for selected rules list. */ protected void removeSelectedRules() { - SimulAction simulAction = ruleChooser.getContextValue(SimulAction.class); List<Rule> selectedRuleValues = ruleChooser.getSelectedRulesList().getSelectedValuesList(); for (Rule selectedRuleValue : selectedRuleValues) { @@ -193,7 +206,7 @@ // de définition d'une simulation (hack) if (ruleChooser.isShowFactorColumn()) { int ruleIndex = ruleChooser.getRulesList().indexOf(selectedRuleValue); - simulAction.preRemoveRule(ruleIndex); + preRemoveRule(ruleIndex); ruleChooser.getContextValue(SimulationUI.class, "SimulationUI").refreshFactorTree(); } @@ -211,10 +224,9 @@ // condition pour savoir si on est dans l'instance principal // de définition d'une simulation (hack) if (ruleChooser.isShowFactorColumn()) { - SimulAction simulAction = ruleChooser.getContextValue(SimulAction.class); for (Rule rule : ruleChooser.getRulesList()) { int ruleIndex = ruleChooser.getRulesList().indexOf(rule); - simulAction.preRemoveRule(ruleIndex); + preRemoveRule(ruleIndex); } ruleChooser.getContextValue(SimulationUI.class, "SimulationUI").refreshFactorTree(); } @@ -249,4 +261,63 @@ ruleChooser.getSelectedRuleParameterTableModel().setScript(null); } } + + /** + * Called by RuleChooser component before rule deletion. + * Used to remove factor associated to rule to delete. + * + * Factor path reference rule with factor path containing rule index + * in rule list : + * for example : + * <pre> + * parameters.rule.2.parameter.tacPoids + * </pre> + * + * Must also rename all next indices. + * + * @param ruleIndex rule index to to delete + */ + public void preRemoveRule(int ruleIndex) { + preRemoveRule(ruleChooser.getContextValue(FactorGroup.class), ruleIndex); + } + + /** + * Recursive rename and delete rule factor path. + * + * @param factorGroup factorGroup + * @param ruleIndex rule index to to delete + */ + protected void preRemoveRule(FactorGroup factorGroup, int ruleIndex) { + Collection<Factor> factorCopy = new ArrayList<>(factorGroup.getFactors()); + for (Factor factor : factorCopy) { + if (factor instanceof FactorGroup) { + preRemoveRule((FactorGroup)factor, ruleIndex); + } + else { + Pattern factorPathPattern = Pattern.compile( + "^(" +PARAMETERS_KEY + "\\" + DOT + RULE_KEY + "\\" + DOT + ")(\\d+)(.*)$"); + Matcher factorPathMatcher = factorPathPattern.matcher(factor.getPath()); + if (factorPathMatcher.find()) { + Integer index = Integer.parseInt(factorPathMatcher.group(2)); + if (index == ruleIndex) { + // meme index, suppression + if (log.isDebugEnabled()) { + log.debug("Removing factor for index " + ruleIndex + " : " + factor.getPath()); + } + factorGroup.remove(factor); + } + else if (index > ruleIndex) { + // index supérieur, renommage + // avec un index de moins + String factorPath = factorPathMatcher.group(1) + + String.valueOf(index - 1) + factorPathMatcher.group(3); + if (log.isDebugEnabled()) { + log.debug("Renammed factor for index " + ruleIndex + " : " + factor.getPath()); + } + factor.setPath(factorPath); + } + } + } + } + } } Deleted: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -1,1301 +0,0 @@ -/* - * #%L - * IsisFish - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2005 - 2011 Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin, Chatellier Eric - * %% - * 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 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 Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package fr.ifremer.isisfish.ui.simulator; - -import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.DOT; -import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.NUMBER_KEY; -import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.PARAMETERS_KEY; -import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.PARAMETER_KEY; -import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.POPULATION_KEY; -import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.RULES_KEY; -import static fr.ifremer.isisfish.simulator.SimulationParameterPropertiesHelper.RULE_KEY; -import static org.nuiton.i18n.I18n.t; - -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.event.ActionEvent; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.lang.reflect.Field; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.SortedMap; -import java.util.TreeMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JPanel; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.math.matrix.MatrixND; -import org.nuiton.math.matrix.gui.MatrixPanelEditor; -import org.nuiton.topia.TopiaContext; - -import fr.ifremer.isisfish.IsisFish; -import fr.ifremer.isisfish.IsisFishException; -import fr.ifremer.isisfish.IsisFishRuntimeException; -import fr.ifremer.isisfish.datastore.ExportStorage; -import fr.ifremer.isisfish.datastore.RegionStorage; -import fr.ifremer.isisfish.datastore.ScriptStorage; -import fr.ifremer.isisfish.datastore.SensitivityAnalysisStorage; -import fr.ifremer.isisfish.datastore.SensitivityExportStorage; -import fr.ifremer.isisfish.datastore.SimulationPlanStorage; -import fr.ifremer.isisfish.datastore.SimulationStorage; -import fr.ifremer.isisfish.datastore.SimulatorStorage; -import fr.ifremer.isisfish.entities.Population; -import fr.ifremer.isisfish.entities.Species; -import fr.ifremer.isisfish.entities.Strategy; -import fr.ifremer.isisfish.export.ExportInfo; -import fr.ifremer.isisfish.export.SensitivityExport; -import fr.ifremer.isisfish.mexico.MexicoHelper; -import fr.ifremer.isisfish.rule.Rule; -import fr.ifremer.isisfish.simulator.SimulationParameter; -import fr.ifremer.isisfish.simulator.SimulationParameterImpl; -import fr.ifremer.isisfish.simulator.SimulationPlan; -import fr.ifremer.isisfish.simulator.launcher.SimulationService; -import fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher; -import fr.ifremer.isisfish.simulator.sensitivity.DesignPlan; -import fr.ifremer.isisfish.simulator.sensitivity.Factor; -import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; -import fr.ifremer.isisfish.simulator.sensitivity.SensitivityAnalysis; -import fr.ifremer.isisfish.simulator.sensitivity.SensitivityException; -import fr.ifremer.isisfish.simulator.sensitivity.domain.ContinuousDomain; -import fr.ifremer.isisfish.simulator.sensitivity.domain.DiscreteDomain; -import fr.ifremer.isisfish.simulator.sensitivity.domain.EquationDiscreteDomain; -import fr.ifremer.isisfish.simulator.sensitivity.domain.RuleDiscreteDomain; -import fr.ifremer.isisfish.ui.SimulationUI; -import fr.ifremer.isisfish.ui.sensitivity.SensitivityChooserUI; -import fr.ifremer.isisfish.ui.sensitivity.wizard.FactorWizardHandler; -import fr.ifremer.isisfish.ui.sensitivity.wizard.FactorWizardUI; -import fr.ifremer.isisfish.ui.util.ErrorHelper; -import fr.ifremer.isisfish.ui.widget.editor.ScriptParameterDialog; -import jaxx.runtime.SwingUtil; - -/** - * SimulAction. - * - * Created: 1 aout 2005 18:37:25 CEST - * - * @author Benjamin POUSSIN <poussin@codelutin.com> - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class SimulAction { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - private static Log log = LogFactory.getLog(SimulAction.class); - - private static final SimpleDateFormat DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd-HH-mm"); - - /** - * Les parametres de simulation (commun a tous les onglet de l'interface de simulation). - * Les parametres doivent toujours être liés avec les selections et état de l'ui. - * La mise en facteur des parametres et des regles est basé sur cet objet. - */ - protected SimulationParameter param = null; - - protected RegionStorage regionStorage = null; - protected SimulationStorage simulStorage = null; - protected String simulName = null; - - /** - * List de facteur sous forme d'arbre (factor group). - * {@code null} name for compatibility with 3.3.0.0. - */ - protected FactorGroup factorGroup = new FactorGroup(null); - - public SimulAction() { - init(); - } - - /** - * cree et initialise param avec les valeurs par defaut de l'utilisateur - */ - public void init() { - if (log.isDebugEnabled()) { - log.debug("Init "); - } - try { - param = new SimulationParameterImpl(); - List<String> resultNames = getResultNames(); - // put default value in param - param.setSimulatorName(IsisFish.config.getSimulatorClassfile()); - - Map<String, String> tv = new LinkedHashMap<String, String>(); - tv.putAll(IsisFish.config.getDefaultTagValueAsMap()); - tv.putAll(IsisFish.config.getDefaultSimulationConfig()); - param.setTagValue(tv); - - param.setExportNames(IsisFish.config.getDefaultExportNamesAsList()); - List<String> defaultResultNames = IsisFish.config - .getDefaultResultNamesAsList(); - if (defaultResultNames != null) { - param.setResultEnabled(defaultResultNames); - } else { - param.setResultEnabled(resultNames); - } - } catch (Exception eee) { - if (log.isErrorEnabled()) { - log.error("Can't init SimulationParameter", eee); - } - ErrorHelper.showErrorDialog(t("isisfish.error.simulation.initsimulaction"), eee); - } - } - - protected void setName(String name) { - simulName = name; - } - - /** - * Load simulation parameter file. - * - * @param f - * - * TODO public just for sensitivity - */ - public void importSimulation(File f) { - FileInputStream fos = null; - try { - fos = new FileInputStream(f); - Properties proper = new Properties(); - proper.load(fos); - param.fromProperties(proper); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("Can't import simulation", e); - } - ErrorHelper.showErrorDialog(t("isisfish.error.simulation.importparameter"), e); - } finally { - IOUtils.closeQuietly(fos); - } - } - - /** - * Save current simulation to given file. - * - * @param f file to save simulation to - * - * TODO public just for sensitivity - */ - public void saveSimulation(File f) { - FileOutputStream fos = null; - try { - fos = new FileOutputStream(f); - param.toProperties().store(fos, simulName); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("Can't save simulation", e); - } - ErrorHelper.showErrorDialog(t("isisfish.error.simulation.savesimulation"), e); - } finally { - IOUtils.closeQuietly(fos); - } - } - - /** - * Looking for ResultName.java script and read all fields and fill - * list of field value and doc - * @return the list of result names found in ResultName script - */ - protected List<String> getResultNames() { - List<String> result = new ArrayList<String>(); - try { - ScriptStorage storage = ScriptStorage.getScript("ResultName.java"); - Class<?> resultNameClass = storage.getCodeClass(); - // TODO: if we can't find class, perhaps try to parser Java source ? - Field[] fields = resultNameClass.getFields(); - for (Field f : fields) { - String fieldName = (String) f.get(null); - result.add(fieldName); - } - } catch (Exception eee) { - if (log.isWarnEnabled()) { - log.warn("Can't find result name script", eee); - } - ErrorHelper.showErrorDialog(t("isisfish.error.simulation.getresultname"), eee); - } - return result; - } - - /** - * Change region in simulation launcher - * - * @param paramsUI paramsUI - * @param regionName region name - */ - public void regionChange(ParamsUI paramsUI, String regionName) { - regionStorage = RegionStorage.getRegion(regionName); - paramsUI.getParentContainer(SimulationUI.class).setContextValue(regionStorage); - paramsUI.getParentContainer(SimulationUI.class).setRegionStorage(regionStorage); - param.setRegionName(regionName); - } - - /** - * Load old simulation. - * - * Reset some field to empty default values: - * <ul> - * <li>params</li> - * <li>simulation plans</li> - * <li>factors list</li> - * </ul> - * - * Open old simulation: - * <ul> - * <li>params copy</li> - * <li>factors</li> - * </ul> - * - * @param simulName name of simulation to load - */ - public void loadOldSimulation(String simulName) { - if (log.isDebugEnabled()) { - log.debug("call loadOldSimulation: " + simulName); - } - try { - this.simulName = simulName; - simulStorage = SimulationStorage.getSimulation(simulName); - param = simulStorage.getParameter().copy(); - // all time reset number after load - param.setSimulationPlanNumber(-1); - regionStorage = param.getRegion(); - - // Chargement des facteurs - // clear list even if mexico file doesn't exists - factorGroup.clearFactors(); - File f = SimulationStorage.getMexicoDesignPlan(SimulationStorage.getSimulationDirectory(simulName)); - if (f != null && f.canRead()) { - if (log.isInfoEnabled()) { - log.info("Import design plan from : " + f.getAbsolutePath()); - } - TopiaContext topiaContext = regionStorage.getStorage(); - DesignPlan designPlan = MexicoHelper.getDesignPlanFromXML(f, topiaContext); - for (Factor factor : designPlan.getFactors()) { - if (log.isDebugEnabled()) { - log.debug("Find factor : " + factor.getName()); - } - //factors.put(factor.getPath() + factor.getName(), factor); - factorGroup = designPlan.getFactorGroup(); - } - } - else if (log.isInfoEnabled()) { - log.info("No xml design plan file found"); - } - } catch (Exception eee) { - throw new IsisFishRuntimeException(t("isisfish.error.simulation.loadoldsimulation"), eee); - } - } - - /** - * Called by RuleChooser component before rule deletion. - * Used to remove factor associated to rule to delete. - * - * Factor path reference rule with factor path containing rule index - * in rule list : - * for example : - * <pre> - * parameters.rule.2.parameter.tacPoids - * </pre> - * - * Must also rename all next indices. - * - * @param ruleIndex rule index to to delete - */ - public void preRemoveRule(int ruleIndex) { - preRemoveRule(factorGroup, ruleIndex); - } - - /** - * Recursive rename and delete rule factor path. - * - * @param factorGroup factorGroup - * @param ruleIndex rule index to to delete - */ - protected void preRemoveRule(FactorGroup factorGroup, int ruleIndex) { - Collection<Factor> factorCopy = new ArrayList<Factor>(factorGroup.getFactors()); - for (Factor factor : factorCopy) { - if (factor instanceof FactorGroup) { - preRemoveRule((FactorGroup)factor, ruleIndex); - } - else { - Pattern factorPathPattern = Pattern.compile( - "^(" +PARAMETERS_KEY + "\\" + DOT + RULE_KEY + "\\" + DOT + ")(\\d+)(.*)$"); - Matcher factorPathMatcher = factorPathPattern.matcher(factor.getPath()); - if (factorPathMatcher.find()) { - Integer index = Integer.parseInt(factorPathMatcher.group(2)); - if (index == ruleIndex) { - // meme index, suppression - if (log.isDebugEnabled()) { - log.debug("Removing factor for index " + ruleIndex + " : " + factor.getPath()); - } - factorGroup.remove(factor); - } - else if (index > ruleIndex) { - // index supérieur, renommage - // avec un index de moins - String factorPath = factorPathMatcher.group(1) + - String.valueOf(index - 1) + factorPathMatcher.group(3); - if (log.isDebugEnabled()) { - log.debug("Renammed factor for index " + ruleIndex + " : " + factor.getPath()); - } - factor.setPath(factorPath); - } - } - } - } - } - /** - * Get strategies list to fill Jlist in ParamUI. - * - * @return strategies list - */ - public List<Strategy> getStrategies() { - List<Strategy> result = new ArrayList<Strategy>(); - try { - TopiaContext tx = param.getRegion().getStorage().beginTransaction(); - result = RegionStorage.getFisheryRegion(tx).getStrategy(); - tx.rollbackTransaction(); - tx.closeContext(); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("Can't get strategies", e); - } - ErrorHelper.showErrorDialog(t("isisfish.error.simulation.liststrategies"), e); - } - return result; - } - - /** - * Set parameters strategies. - * - * @param strategies - */ - public void setStrategies(List<Strategy> strategies) { - List<Strategy> result = new ArrayList<Strategy>(strategies); - param.setStrategies(result); - } - - /** - * Get population list to fill JList in paramUI. - * - * @return populations list - */ - public List<Population> getPopulations() { - - List<Population> result = new ArrayList<Population>(); - try { - TopiaContext tx = param.getRegion().getStorage().beginTransaction(); - List<Species> species = RegionStorage.getFisheryRegion(tx) - .getSpecies(); - for (Species s : species) { - Collection<Population> populations = s.getPopulation(); - - // FIXME initialiaze lazy hibernate collection - for (Population p : populations) { - p.getPopulationGroup().size(); - p.getPopulationZone().size(); - } - - result.addAll(populations); - } - tx.rollbackTransaction(); - tx.closeContext(); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("Can't get population", e); - } - ErrorHelper.showErrorDialog(t("isisfish.error.simulation.listpopulation"), e); - } - return result; - } - - /** - * Set parameter population. - * - * @param populations populations to set - */ - public void setPopulations(List<Population> populations) { - List<Population> result = new ArrayList<Population>(populations); - param.setPopulations(result); - } - -// // Years -// public int getNumberOfYear() { -// return param.getNumberOfYear(); -// } -// -// /** -// * Change number of simulation year by parsing string value. -// * Default to 1 if value is not parsable. -// * -// * @param years number of years to set -// */ -// public void setNumberOfYear(String years) { -// try { -// param.setNumberOfYear(Integer.parseInt(years)); -// } -// catch (NumberFormatException ex) { -// // defaut to one year -// param.setNumberOfYear(1); -// } -// } - - public int getNumberOfMonths() { - return param.getNumberOfMonths(); - } - - /** - * Change number of simulation month by parsing string value. - * Default to 1 if value is not parsable. - * - * @param months number of months to set - */ - public void setNumberOfMonths(String months) { - try { - param.setNumberOfMonths(Integer.parseInt(months)); - } - catch (NumberFormatException ex) { - // defaut to one year - param.setNumberOfMonths(1); - } - } - - public List<String> getSimulatorNames() { - return SimulatorStorage.getSimulatorNames(); - } - - /* - ************ - * AdvancedParameterUI - ************ - */ - - // Gestion des TagValues - public void addTagValue(String tag, String value) { - param.getTagValue().put(tag, value); - } - - public void removeTagValue(String tag) { - if (log.isDebugEnabled()) { - log.debug("removeTagValue: " + tag); - } - param.getTagValue().remove(tag); - } - - public void saveTagValue(String simulatorName) { - Map<String, String> tagValues = param.getTagValue(); - if (log.isDebugEnabled()) { - log.debug("call saveTagValue: " + tagValues); - } - IsisFish.config.setDefaultTagValues(tagValues); - - IsisFish.config.setSimulatorClassfile(simulatorName); - } - - /* - * ExportUI - */ - - public List<String> getExportNames() { - List<String> exportNames = ExportStorage.getExportNames(); - List<String> result = new ArrayList<String>(exportNames); - return result; - } - - /** - * Save current parameters exports names in configuration. - */ - public void saveExport() { - - if (param.getExportNames() != null) { - - if (log.isDebugEnabled()) { - log.debug("Set exports in configuration : " + param.getExportNames()); - } - - IsisFish.config.setDefaultExportNames(param.getExportNames()); - } - } - - /* - * ResultUI - */ - - public void saveParametersResultNames(List<String> resultNames) { - List<String> resultNamesString = new ArrayList<>(resultNames); - param.setResultEnabled(resultNamesString); - - if (log.isDebugEnabled()) { - log.debug("Set simulation result names : " + resultNamesString); - } - } - - public void saveConfigurationResultNames(List<String> resultNames) { - List<String> resultNamesString = new ArrayList<>(resultNames); - IsisFish.config.setDefaultResultNames(resultNamesString); - - if (log.isDebugEnabled()) { - log.debug("Set configuration result names : " + resultNamesString); - } - } - - public List<String> getDefaultResultNames() { - return IsisFish.config.getDefaultResultNamesAsList(); - } - - /** - * Return simulation plan names list. - * - * @return simulation plan names - */ - public List<String> getSimulationPlanNames() { - return SimulationPlanStorage.getSimulationPlanNames(); - } - - public List<SimulationPlan> getParamSimulationPlans() { - return param.getSimulationPlans(); - } - - public void addSimulationPlan(PlanUI planUI, String name) { - try { - SimulationPlan sp = SimulationPlanStorage.getSimulationPlan(name).getNewInstance(); - - // add it after autoconfiguration (if enabled) - sp = (SimulationPlan)ScriptParameterDialog.displayConfigurationFrame(planUI, sp); - if (sp != null) { - getSimulationParameter().addSimulationPlan(sp); - } - } catch (IsisFishException ex) { - throw new IsisFishRuntimeException("Can't add simulation plan", ex); - } - } - - public void removeSimulationPlan(SimulationPlan sp) { - getSimulationParameter().removeSimulationPlan(sp); - } - - public void clearSimulationPlans() { - getSimulationParameter().clearPlans(); - } - - public Map<String, Class<?>> getSimulationPlanParameterName(SimulationPlan sp) { - Map<String, Class<?>> result = null; - if (sp != null) { - result = SimulationPlanStorage.getParameterNames(sp); - } - return result; - } - - public Object getSimulationPlanParameterValue(String paramName, SimulationPlan sp) { - Object result = null; - if (sp != null) { - try { - result = SimulationPlanStorage.getParameterValue(sp, paramName); - } catch (IsisFishException ex) { - throw new IsisFishRuntimeException("Can't get simulation plan param value", ex); - } - } - return result; - } - - public void setSimulationPlanParameterValue(String paramName, SimulationPlan sp, - Object value) { - if (log.isDebugEnabled()) { - log.debug("paramName : " + paramName + " simulationPlanName : " + sp - + " value : " + value); - } - try { - SimulationPlanStorage.setParameterValue(sp, paramName, value); - } catch (IsisFishException ex) { - throw new IsisFishRuntimeException("Can't set simulation plan param value", ex); - } - } - - /* - * Sensitivity - */ - public List<String> getSensitivityExportNames() { - List<String> result = new ArrayList<String>(); - List<String> exportNames = SensitivityExportStorage.getSensitivityExportNames(); - for (String export : exportNames) { - result.add(export); - } - return result; - } - - public List<SensitivityExport> getSensitivityExports() { - List<SensitivityExport> result = param.getSensitivityExport(); - return result; - } - - public void addSensitivityExport(SensitivityChooserUI sensitivityChooserUI, String name) { - try { - SensitivityExportStorage storage = SensitivityExportStorage.getSensitivityExport(name); - SensitivityExport sensitivityExport = storage.getNewInstance(); - - // add it after autoconfiguration (if enabled) - sensitivityExport = (SensitivityExport)ScriptParameterDialog.displayConfigurationFrame(sensitivityChooserUI, sensitivityExport); - if (sensitivityExport != null) { - param.getSensitivityExport().add(sensitivityExport); - } - } catch (IsisFishException e) { - if (log.isErrorEnabled()) { - log.error("Can't add sensitivity export", e); - } - } - } - - /** - * Remove an export. - * - * @param export export to remove - */ - public void removeSensitivityExport(SensitivityExport export) { - param.getSensitivityExport().remove(export); - } - - public void clearSensitivityExport() { - param.getSensitivityExport().clear(); - } - - public Map<String, Class<?>> getSensitivityExportParameterNames( - SensitivityExport export) { - return SensitivityExportStorage.getParameterNames(export); - } - - public void setSensitivityExportParameterValue(ExportInfo export, - String paramName, Object value) { - if (value != null) { - try { - SensitivityExportStorage.setParameterValue(export, paramName, value); - } catch (IsisFishException e) { - if (log.isErrorEnabled()) { - log.error("Can't set sensitivity export param value", e); - } - } - } - } - - public Object getSensitivityExportParameterValue(SensitivityExport sensitivityExport, String paramName) { - Object result = null; - try { - result = SensitivityExportStorage.getParameterValue(sensitivityExport, paramName); - } catch (IsisFishException e) { - if (log.isErrorEnabled()) { - log.error("Can't get sensitivity export param value", e); - } - } - return result; - } - - /** - * Return sensitivity analysis name without .java extension. - * - * @return sensitivity analysis names list - */ - public List<String> getSensitivityAnalysisNames() { - List<String> result = new ArrayList<String>(); - for (String r : SensitivityAnalysisStorage.getSensitivityAnalysisNames()) { - // there is some non java files in sensitivity directory - if (r.endsWith(".java")) { - // Remove .java extention - // for example SensitivityStorage.getRuleName(String) - result.add(r.substring(0, r.length() - 5)); - } - } - return result; - } - - /** - * Get current sensitivity calculator instance. - * @return sensitivity calculator - */ - public SensitivityAnalysis getSensitivityAnalysis() { - return param.getSensitivityAnalysis(); - } - - /** - * Build a new sensitivity calculator instance by his name. - * - * @param name calculator name - * @return instance - */ - public SensitivityAnalysis getSensitivityAnalysisInstance(String name) { - SensitivityAnalysis sensitivityAnalysis = null; - try { - SensitivityAnalysisStorage sensitivityStorage = SensitivityAnalysisStorage.getSensitivityAnalysis(name); - sensitivityAnalysis = sensitivityStorage.getNewInstance(); - } catch (IsisFishException e) { - if (log.isErrorEnabled()) { - log.error("Can't set sensitivity analysis", e); - } - } - return sensitivityAnalysis; - } - - /** - * Set calculator instance to use. - * - * @param sensitivityAnalysis new instance - */ - public void setSensitivityAnalysis(SensitivityAnalysis sensitivityAnalysis) { - param.setSensitivityAnalysis(sensitivityAnalysis); - } - - /** - * Get current simulation factor list. - * - * @return factor list - */ - public FactorGroup getFactorGroup() { - return factorGroup; - } - - /** - * Search factor in factor group tree by path. - * - * @param factorPath factor path to search - * @return found factor - */ - public Factor getFactor(String factorPath) { - return getFactor(factorGroup, factorPath); - } - - /** - * Recursive search for factor in factor group by path. - * - * @param factorGroup factor group to search to - * @param factorPath factor path to search - * @return found factor - */ - protected Factor getFactor(FactorGroup factorGroup, String factorPath) { - Factor result = null; - for (Factor factor : factorGroup.getFactors()) { - if (factor instanceof FactorGroup) { - result = getFactor((FactorGroup)factor, factorPath); - } - if (factorPath.equals(factor.getPath())) { - result = factor; - } - } - return result; - } - - /** - * Remove factor in factor group tree by path. - * - * @param factorPath factor path to remove - */ - public void removeFactor(String factorPath) { - removeFactor(factorGroup, factorPath); - } - - /** - * Recursive remove for factor in factor group by path. - * - * @param factorGroup factor group to search to - * @param factorPath factor path to remove - */ - protected void removeFactor(FactorGroup factorGroup, String factorPath) { - Collection<Factor> factorCopy = new ArrayList<Factor>(factorGroup.getFactors()); - for (Factor factor : factorCopy) { - if (factor instanceof FactorGroup) { - removeFactor((FactorGroup)factor, factorPath); - } - if (factorPath.equals(factor.getPath())) { - factorGroup.remove(factor); - } - } - } - - public void addFactor(Factor f) { - if (log.isDebugEnabled()) { - log.debug("Add factor (" + f.getName() + ") : " +f.getPath()); - } - factorGroup.addFactor(f); - } - - /** - * Ajout d'un facteur continue de type (min/max). - * - * @param name - * @param comment - * @param path - * @param domain - * @param exist - */ - public void addContinuousFactor(String name, String comment, String path, - ContinuousDomain domain, boolean exist) { - Factor f = new Factor(name); - f.setDomain(domain); - f.setComment(comment); - f.setPath(path); - if (exist) { - removeFactor(path); - } - addFactor(f); - } - - public void addDiscreteFactor(String name, String comment, String path, - List<Object> values, boolean exist) { - addDiscreteFactor(new DiscreteDomain(), name, comment, path, values, exist); - } - - public void addDiscreteRuleFactor(String name, String comment, String path, - List<Object> values, boolean exist) { - addDiscreteFactor(new RuleDiscreteDomain(), name, comment, path, values, exist); - } - - public void addDiscreteEquationFactor(String name, String comment, String path, - List<Object> values, boolean exist) { - addDiscreteFactor(new EquationDiscreteDomain(), name, comment, path, values, exist); - } - - protected void addDiscreteFactor(DiscreteDomain domain, String name, String comment, String path, - List<Object> values, boolean exist) { - Factor f = new Factor(name); - SortedMap<Object, Object> domainValues = new TreeMap<Object, Object>(); - int label = 0; - for (Object value : values) { - // FIXME test when integer - // Don't work with String ;( - domainValues.put(label, value); - // and start at 0 - label++; - } - domain.setValues(domainValues); - f.setDomain(domain); - f.setComment(comment); - f.setPath(path); - if (exist) { - removeFactor(path); - } - addFactor(f); - } - - public void addContinuousEquationFactor(Factor f, boolean exist) { - // factor name need to be composed - //Factor f = new Factor(name + "." + domain.getVariableName()); - //f.setDomain(domain); - //f.setComment(comment); - //f.setPath(path); - if (exist) { - removeFactor(f.getPath()); - } - addFactor(f); - } - - /* - ************ - * General - ************ - */ - - public SimulationParameter getSimulationParameter() { - return param; - } - - public void setSimulationParameter(SimulationParameter p) { - param = p; - } - - public SimulationStorage getSimulationStorage() { - return simulStorage; - } - - public RegionStorage getRegionStorage() { - return regionStorage; - } - - public List<SimulatorLauncher> getSimulationLauncher() { - return SimulationService.getService().getSimulationLaunchers(); - } - - protected boolean checkAndPrepare(String fullSimulationId) { - boolean result = !("".equals(fullSimulationId) - || SimulationStorage.localyExists(fullSimulationId) - || SimulationService.getService().exists(fullSimulationId)); - - if (result) { - // force all necessary config simulation in tag value - Map<String, String> m = new HashMap<String, String>( - IsisFish.config.getDefaultSimulationConfig()); - Map<String, String> tv = param.getTagValue(); - m.putAll(tv); - param.setTagValue(m); - } else { - ErrorHelper.showErrorDialog(t("isisfish.simulator.simulaction.badid", - fullSimulationId), null); - } - - return result; - } - - /** - * Launch automatically the simulation, when is possible (no other simulation) - * or wait for the last automatically simulation ended. - * - * @param simulationId id of the simulation to simulate - * @param launcher launcher to use - * - * @see SimulatorLauncher - */ - public void launchSimulation(String simulationId, SimulatorLauncher launcher) { - - String fullSimulationId = "sim_" + simulationId + "_" - + DATEFORMAT.format(new java.util.Date()); - - // log - if (log.isDebugEnabled()) { - log.debug("Launch simulation with custom launcher " - + launcher.toString()); - } - - try { - if (checkAndPrepare(fullSimulationId)) { - SimulationService.getService().submit(fullSimulationId, param, - launcher, 0); - } - } catch (Exception eee) { - if (log.isErrorEnabled()) { - log.error("Can't start simulation", eee); - } - ErrorHelper.showErrorDialog(t("isisfish.error.simulation.launchsimulation"), eee); - } - } - - /** - * Launch simulation with factors variations parameters. - * - * @param simulationId id of the simulation to simulate - * @param launcher launcher to use - * @param sensitivityAnalysis sensitivity analysis to use - * - * @see SimulatorLauncher - * @see SensitivityAnalysis - * @see DesignPlan - */ - public void launchSimulation(String simulationId, - SimulatorLauncher launcher, SensitivityAnalysis sensitivityAnalysis) { - - String fullSimulationId = "as_" + simulationId + "_" - + DATEFORMAT.format(new java.util.Date()); - - // log - if (log.isDebugEnabled()) { - log.debug("Launch factor simulation with custom launcher " - + launcher.toString()); - log.debug("Using sensitivityCalculator : " - + sensitivityAnalysis.getDescription()); - } - - try { - if (checkAndPrepare(fullSimulationId)) { - DesignPlan designPlan = new DesignPlan(); - designPlan.setFactorGroup(factorGroup); - SimulationService.getService().submit(fullSimulationId, param, - launcher, 0, sensitivityAnalysis, designPlan); - } - } catch (Exception eee) { - if (log.isErrorEnabled()) { - log.error("Can't start simulation", eee); - } - ErrorHelper.showErrorDialog(t("isisfish.error.simulation.launchsimulation"), eee); - } - } - - public void launchSimulationWithSensibility(String simulationId, - SimulatorLauncher launcher) { - launchSimulation(simulationId, launcher, getSensitivityAnalysis()); - } - - /** - * Lance la second passe d'une analyse de sensibilité. - * - * @param masterSensitivitySimulationName nom du prefix de toutes les simulations (without _) - */ - public void runSensitivitySecondPass(String masterSensitivitySimulationName) { - - // sensitivity analysis found - SensitivityAnalysis sensitivityAnalysis = null; - //List<SimulationStorage> simulationStorageForAnalyze = new ArrayList<SimulationStorage>(); - SortedMap<Integer, SimulationStorage> simulationStorageForAnalyze = new TreeMap<Integer, SimulationStorage>(); - File simuationDirectory = SimulationStorage.getSimulationDirectory(); - for (File simuation : simuationDirectory.listFiles()) { - if (simuation.isDirectory() - && simuation.getName().startsWith( - masterSensitivitySimulationName + "_")) { - SimulationStorage storage = SimulationStorage - .getSimulation(simuation.getName()); - String suffix = simuation.getName().substring( - simuation.getName().lastIndexOf("_") + 1); - simulationStorageForAnalyze.put(Integer.valueOf(suffix), - storage); - - if (sensitivityAnalysis == null) { - // try to find find calculator name in one storage - SimulationParameter params = storage.getParameter(); - sensitivityAnalysis = params.getSensitivityAnalysis(); - } - } - } - - if (sensitivityAnalysis != null) { - try { - // build master sensitivity export directory - File masterExportDirectory = new File(SimulationStorage.getSensitivityResultsDirectory(), - masterSensitivitySimulationName); - if (!masterExportDirectory.isDirectory()) { - masterExportDirectory.mkdirs(); - } - List<SimulationStorage> simulationStorageForAnalyzeList = new ArrayList<SimulationStorage>( - simulationStorageForAnalyze.values()); - sensitivityAnalysis.analyzeResult( - simulationStorageForAnalyzeList, masterExportDirectory); - } catch (SensitivityException e) { - if (log.isErrorEnabled()) { - log.error("Can't call analyse result", e); - } - } - } else { - if (log.isWarnEnabled()) { - log.warn("Can't run sensitivity second pass"); - } - } - } - - /** - * Renvoie les resultats de la seconde pass. - * - * @param masterSensitivitySimulationName nom du prefix de toutes les simulations (without _) - * - * @return les fichiers genere lors de la seconde passe (seulement ceux qui ne commence pas par ".") - */ - public List<File> getSensitivitySecondPassResults( - String masterSensitivitySimulationName) { - - List<File> result = new ArrayList<File>(); - - // build master sensitivity export directory - File masterExportDirectory = new File(SimulationStorage.getSensitivityResultsDirectory(), masterSensitivitySimulationName); - if (masterExportDirectory.isDirectory()) { - for (File exportFile : masterExportDirectory.listFiles()) { - if (exportFile.isFile() - && !exportFile.getName().startsWith(".")) { - result.add(exportFile); - } - } - } - - return result; - } - - /** - * Population selection changed. - * - * Fill matrix panel with population effective of selected population. - * - * @param paramsUI paramsUI - */ - public void populationSelected(final ParamsUI paramsUI) { - CardLayout layout = (CardLayout)paramsUI.getPopulationEffectivesPanel().getLayout(); - - List<Population> selectedPopulationsValues = paramsUI.getListSimulParamsPopulations().getSelectedValuesList(); - if (CollectionUtils.isNotEmpty(selectedPopulationsValues)) { - paramsUI.getPopulationEffectivesTabbedPane().removeAll(); - setPopulations(selectedPopulationsValues); - - for (Population selectedPopulation : selectedPopulationsValues) { - final MatrixPanelEditor matrixPanel = new MatrixPanelEditor(); - MatrixND populationEffectives = getSimulationParameter().getNumberOf(selectedPopulation); - matrixPanel.setMatrix(populationEffectives); - - JPanel matrixPanelComponent = new JPanel(new BorderLayout()); - matrixPanelComponent.add(matrixPanel, BorderLayout.CENTER); - - // add addFactorButton with matrixPanel (just in sensitivity cas) - if (paramsUI.isSensitivity()) { - matrixPanel.putClientProperty("sensitivityPopulation", selectedPopulation); - // TODO add another thing that action - JButton addFactorButton = new JButton(); - addFactorButton.setAction(new AbstractAction() { - public void actionPerformed(ActionEvent e) { - addFactorWithComponent(paramsUI, matrixPanel); - } - @Override - public Object getValue(String key) { - Object result = null; - if (key.equals(Action.SMALL_ICON)) { - result = SwingUtil.createImageIcon("building_add.png"); - } - return result; - } - }); - matrixPanelComponent.add(addFactorButton, BorderLayout.EAST); - } - - paramsUI.getPopulationEffectivesTabbedPane().add(matrixPanelComponent, - t("isisfish.params.populationEffectives", selectedPopulation.getName())); - } - - layout.show(paramsUI.getPopulationEffectivesPanel(), "specific"); - } - else { - layout.show(paramsUI.getPopulationEffectivesPanel(), "default"); - } - } - - /** - * Action appelée lors du clic sur les boutons a coté des composants factorisables. - * - * Contrairement à l'interface 'input', on edite ici des facteurs existants, - * (créé à la première demande). - * - * @param paramsUI paramsUI - * @param source la source de l'event - */ - public void addFactorWithComponent(ParamsUI paramsUI, JComponent source) { - - if (log.isDebugEnabled()) { - log.debug("Event intercepted on " + source); - } - - Factor selectedFactor = null; - - // new factor with rule domain - if (source instanceof RuleChooser) { - String factorPath = PARAMETERS_KEY + DOT + RULES_KEY; - selectedFactor = getFactor(factorPath); - if (selectedFactor == null) { - selectedFactor = new Factor(t("isisfish.sensitivity.rulesfactorname")); - selectedFactor.setPath(factorPath); - //selectedFactor.setDomain(new RuleDiscreteDomain()); - } - } - - // new factor with matrix continous domain - else if (source instanceof MatrixPanelEditor) { - Population population = (Population)source.getClientProperty("sensitivityPopulation"); - String factorPath = PARAMETERS_KEY + DOT + POPULATION_KEY + DOT + population.getName() + DOT + NUMBER_KEY; - selectedFactor = getFactor(factorPath); - if (selectedFactor == null) { - selectedFactor = new Factor(t("isisfish.sensitivity.populationfactorname", population.getName())); - selectedFactor.setPath(factorPath); - //MatrixND populationEffectives = getSimulationParameter().getNumberOf(population); - /*MatrixContinuousDomain factorDomain = new MatrixContinuousDomain(); - factorDomain.setReferenceValue(populationEffectives.copy()); - factorDomain.setCoefficient(0.0); - ContinuousDomain domain = new ContinuousDomain(Distribution.QUNIFPC); - domain.addDistributionParam(Distribution.QUNIFPC.getDistibutionParams()[0].getName(), populationEffectives.copy()); - domain.addDistributionParam(Distribution.QUNIFPC.getDistibutionParams()[1].getName(), 0.0d); - selectedFactor.setDomain(domain);*/ - } - } - - if (selectedFactor != null) { - FactorWizardUI wizard = new FactorWizardUI(paramsUI); - FactorWizardHandler handler = wizard.getHandler(); - handler.initExistingFactor(wizard, selectedFactor); - wizard.pack(); - wizard.setLocationRelativeTo(paramsUI); - wizard.setVisible(true); - } - } - - /** - * Ajout d'un nouveau facteur sur un parametres de règles. - * - * Le facteur est directement crée avec un nom et un path correct. - * - * @param ruleChooser rule chooser - * @param rule rule - * @param paramName rule parameter name - */ - public void addRuleParameterFactor(RuleChooser ruleChooser, Rule rule, String paramName) { - - // get index of rule in rule list - // warning, factor path must always be cohérent - // with rule list, if a rule is deleted, factor on it must - // be deleted too, et next factor must be renamed - int index = ruleChooser.getRulesList().indexOf(rule); - String factorPath = PARAMETERS_KEY + DOT + RULE_KEY + DOT + index + DOT - + PARAMETER_KEY + DOT + paramName; - //try { - - /*// on a besoin de la valeur pour savoir s'il peut être continue - Object paramValue = RuleStorage.getParameterValue(rule, paramName); - - if (!SensitivityUtils.canBeContinue(paramValue)) { - // dans le cas ou il ne peut pas être continue, on le gere - // differement et on utilise sont type comme - // valeur - Class paramType = RuleStorage.getParameterType(rule, paramName); - factorPath += "." + paramType.getName(); - paramValue = paramType; - } - - // init new factor wizard ui - FactorWizardUI factorWizardUI = new FactorWizardUI(ruleChooser); - factorWizardUI.getFactorNameField().setText(t("isisfish.sensitivity.ruleparameterfactorname", - rule.getClass().getSimpleName(), paramName)); - factorWizardUI.setFactorPath(factorPath); - SensitivityWizardHandler handler = factorWizardUI.getHandler(); - handler.initNewFactorWithValue(factorWizardUI, paramValue); - factorWizardUI.pack(); - factorWizardUI.setLocationRelativeTo(ruleChooser); - factorWizardUI.setVisible(true);*/ - - Factor factor = new Factor(t("isisfish.sensitivity.ruleparameterfactorname", - rule.getClass().getSimpleName(), paramName)); - factor.setPath(factorPath); - FactorWizardUI factorWizardUI = new FactorWizardUI(ruleChooser); - FactorWizardHandler handler = factorWizardUI.getHandler(); - handler.initExistingFactor(factorWizardUI, factor); - factorWizardUI.pack(); - factorWizardUI.setLocationRelativeTo(ruleChooser); - factorWizardUI.setVisible(true); - - /*} catch (IsisFishException ex) { - throw new IsisFishRuntimeException("Can't add factor on rule", ex); - }*/ - } -} Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorContext.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorContext.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorContext.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -22,20 +22,135 @@ */ package fr.ifremer.isisfish.ui.simulator; +import static org.nuiton.i18n.I18n.t; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.datastore.RegionStorage; +import fr.ifremer.isisfish.datastore.ScriptStorage; +import fr.ifremer.isisfish.simulator.SimulationParameter; +import fr.ifremer.isisfish.simulator.SimulationParameterImpl; +import fr.ifremer.isisfish.simulator.sensitivity.FactorGroup; +import fr.ifremer.isisfish.ui.util.ErrorHelper; import jaxx.runtime.JAXXContext; import jaxx.runtime.context.JAXXInitialContext; /** * Ce contexte regroupe les élements qui servent à une hierachie d'interfaces Simulator. * + * Ce context contient: + * <ul> + * <li>SimulationParameter.class : les parametres des la simulation</li> + * <li>FactorGroup.class : le facteur group racine</li> + * <li>RegionStorage.class : la region sélectionner pour ajouter des facteurs</li> + * <li>SimulatorContext.class : l'instance de ce context</li> + * </ul> + * * @author Eric Chatellier */ public class SimulatorContext extends JAXXInitialContext { + private static final Log log = LogFactory.getLog(SimulatorContext.class); + public SimulatorContext(JAXXContext parent) { setParentContext(parent); - // FIXME remove this - add(new SimulAction()); + initDefaultParameters(); + initFactorGroup(); + // concurrentmodification : setSimulatorContext(this); } + + public void setSimulationParameter(SimulationParameter param) { + add(param); + } + + public void setFactorGroup(FactorGroup factorGroup) { + add(factorGroup); + } + + public void setRegionStorage(RegionStorage regionStorage) { + add(regionStorage); + } + + public void setSimulatorContext(SimulatorContext simulatorContext) { + add(simulatorContext); + } + + /** + * Build simulation parameters + */ + protected void initDefaultParameters() { + + SimulationParameter param = new SimulationParameterImpl(); + + // init with default values from configuration + param.setSimulatorName(IsisFish.config.getSimulatorClassfile()); + + // export names + param.setExportNames(IsisFish.config.getDefaultExportNamesAsList()); + + // result names + List<String> defaultResultNames = IsisFish.config.getDefaultResultNamesAsList(); + if (defaultResultNames != null) { + param.setResultEnabled(defaultResultNames); + } else { + List<String> allResultNames = getResultNames(); + param.setResultEnabled(allResultNames); + } + + // tag values + Map<String, String> tv = new LinkedHashMap<String, String>(); + tv.putAll(IsisFish.config.getDefaultTagValueAsMap()); + tv.putAll(IsisFish.config.getDefaultSimulationConfig()); + param.setTagValue(tv); + + // set it in context to be used by all UIs + setSimulationParameter(param); + } + + /** + * Looking for ResultName.java script and read all fields and fill + * list of field value and doc + * @return the list of result names found in ResultName script + * + * @deprecated duplicated with another one + */ + @Deprecated + protected List<String> getResultNames() { + List<String> result = new ArrayList<String>(); + try { + ScriptStorage storage = ScriptStorage.getScript("ResultName.java"); + Class<?> resultNameClass = storage.getCodeClass(); + // TODO: if we can't find class, perhaps try to parser Java source ? + Field[] fields = resultNameClass.getFields(); + for (Field f : fields) { + String fieldName = (String) f.get(null); + result.add(fieldName); + } + } catch (Exception eee) { + if (log.isWarnEnabled()) { + log.warn("Can't find result name script", eee); + } + ErrorHelper.showErrorDialog(t("isisfish.error.simulation.getresultname"), eee); + } + return result; + } + + /** + * List de facteur sous forme d'arbre (factor group). + * {@code null} name for compatibility with 3.3.0.0. + */ + protected void initFactorGroup() { + + FactorGroup factorGroup = new FactorGroup(null); + add(factorGroup); + } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorTabHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorTabHandler.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorTabHandler.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -36,9 +36,4 @@ protected FactorGroup getFactorGroup() { return simulationUI.getContextValue(FactorGroup.class); } - - @Deprecated - protected SimulAction getSimulAction() { - return simulationUI.getContextValue(SimulAction.class); - } } Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/FilterableComboBox.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/FilterableComboBox.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/FilterableComboBox.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -200,7 +200,7 @@ * Build layout. */ private void buildLayout() { - dataBox = new JComboBox<T>(); + dataBox = new JComboBox<>(); dataBox.setName("filterBox"); dataBox.addActionListener(new ComboBoxActionListener()); filterField = new JXTextField(t("isisfish.common.filter")); @@ -208,7 +208,7 @@ filterField.getDocument().addDocumentListener(new FilterDocumentListener()); // fix size filterField.setPreferredSize(new Dimension(200, 0)); - resetButton = new JButton(Resource.getIcon("/icons/cancel.png")); + resetButton = new JButton(Resource.getIcon("/icons/common/cross-button.png")); resetButton.addActionListener(new FilterActionListener()); resetButton.setEnabled(false); resetButton.setName("filterReset"); Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/EquationTableEditor.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/EquationTableEditor.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/EquationTableEditor.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -40,8 +40,6 @@ import javax.swing.event.ChangeEvent; import javax.swing.table.TableCellEditor; -import org.nuiton.widget.SwingUtil; - import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.entities.Equation; import fr.ifremer.isisfish.ui.input.equation.EquationEditorPaneUI; @@ -72,7 +70,7 @@ addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Window editorFrame = getFrame(); - SwingUtil.center(editorFrame); + editorFrame.setLocationByPlatform(true); editorFrame.setVisible(true); } }); Copied: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxConstants.java (from rev 4262, branches/isis-fish-4.4.0-editor/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxConstants.java) =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxConstants.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxConstants.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -0,0 +1,36 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric + * %% + * 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 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.isisfish.ui.widget.text; + +import org.fife.ui.rsyntaxtextarea.SyntaxConstants; + +/** + * Extends rsyntaxtextarea contantx to add isis specific. + * + * @author Eric Chatellier + */ +public interface IsisSyntaxConstants extends SyntaxConstants { + + public static final String SYNTAX_STYLE_LOG = "isisfish-log"; + +} Deleted: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxContants.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxContants.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxContants.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -1,36 +0,0 @@ -/* - * #%L - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric - * %% - * 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 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 Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ifremer.isisfish.ui.widget.text; - -import org.fife.ui.rsyntaxtextarea.SyntaxConstants; - -/** - * Extends rsyntaxtextarea contantx to add isis specific. - * - * @author Eric Chatellier - */ -public interface IsisSyntaxContants extends SyntaxConstants { - - public static final String SYNTAX_STYLE_LOG = "isisfish-log"; - -} Deleted: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxEditor.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxEditor.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisSyntaxEditor.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -1,221 +0,0 @@ -/* - * #%L - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric - * %% - * 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 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 Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ -package fr.ifremer.isisfish.ui.widget.text; - -import static org.nuiton.i18n.I18n.t; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Frame; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; - -import javax.swing.AbstractAction; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.KeyStroke; -import javax.swing.UIManager; -import javax.swing.text.BadLocationException; - -import org.fife.rsta.ui.GoToDialog; -import org.fife.rsta.ui.search.FindDialog; -import org.fife.rsta.ui.search.ReplaceDialog; -import org.fife.rsta.ui.search.SearchDialogSearchContext; -import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; -import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; -import org.fife.ui.rsyntaxtextarea.SyntaxScheme; -import org.fife.ui.rsyntaxtextarea.Token; -import org.fife.ui.rtextarea.RTextScrollPane; -import org.fife.ui.rtextarea.SearchEngine; - -/** - * {@link RSyntaxTextArea} component property configured for isis fish. - * - * @author Eric Chatellier - */ -public class IsisSyntaxEditor extends JPanel implements ActionListener { - - /** serialVersionUID. */ - private static final long serialVersionUID = 1427883892685276516L; - - protected RSyntaxTextArea textArea; - private FindDialog findDialog; - private ReplaceDialog replaceDialog; - - public IsisSyntaxEditor() { - super(new BorderLayout()); - textArea = new RSyntaxTextArea(); - add(new RTextScrollPane(textArea), BorderLayout.CENTER); - setAutoscrolls(false); - } - - /** - * Set highligth style. - * - * @param style new style - * @see IsisSyntaxContants - */ - public void setStyle(String style) { - RSyntaxDocument doc = new RSyntaxDocument(new IsisTokenManagerFactory(), style); - textArea.setDocument(doc); - - // special theme for log - if (IsisSyntaxContants.SYNTAX_STYLE_LOG.equals(style)) { - SyntaxScheme scheme = textArea.getSyntaxScheme(); - scheme.getStyle(Token.RESERVED_WORD_2).foreground = Color.RED; - } - } - - public void setText(String text) { - textArea.setText(text); - textArea.invalidate(); - } - - /** - * Return menu bar configured for {@code textArea} component. - * - * @param parent parent - * @return JMenuBar instance - */ - public JMenuBar createMenuBar(Frame parent) { - JMenuBar mb = new JMenuBar(); - JMenu menu = new JMenu(t("isisfish.script.search")); - menu.add(new JMenuItem(new ShowFindDialogAction())); - menu.add(new JMenuItem(new ShowReplaceDialogAction())); - menu.add(new JMenuItem(new GoToLineAction(parent))); - mb.add(menu); - - initSearchDialogs(parent); - - return mb; - } - - /** - * Creates our Find and Replace dialogs. - */ - protected void initSearchDialogs(Frame parent) { - - findDialog = new FindDialog(parent, this); - replaceDialog = new ReplaceDialog(parent, this); - - // This ties the properties of the two dialogs together (match - // case, regex, etc.). - replaceDialog.setSearchContext(findDialog.getSearchContext()); - - } - - private class GoToLineAction extends AbstractAction { - protected Frame parent; - public GoToLineAction(Frame parent) { - super(t("isisfish.script.gotoline")); - this.parent = parent; - int c = getToolkit().getMenuShortcutKeyMask(); - putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_L, c)); - } - - public void actionPerformed(ActionEvent e) { - if (findDialog.isVisible()) { - findDialog.setVisible(false); - } - if (replaceDialog.isVisible()) { - replaceDialog.setVisible(false); - } - GoToDialog dialog = new GoToDialog(this.parent); - dialog.setMaxLineNumberAllowed(textArea.getLineCount()); - dialog.setVisible(true); - int line = dialog.getLineNumber(); - if (line>0) { - try { - textArea.setCaretPosition(textArea.getLineStartOffset(line-1)); - } catch (BadLocationException ble) { // Never happens - UIManager.getLookAndFeel().provideErrorFeedback(textArea); - ble.printStackTrace(); - } - } - } - - } - - private class ShowFindDialogAction extends AbstractAction { - - public ShowFindDialogAction() { - super(t("isisfish.script.find")); - int c = getToolkit().getMenuShortcutKeyMask(); - putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, c)); - } - - public void actionPerformed(ActionEvent e) { - if (replaceDialog.isVisible()) { - replaceDialog.setVisible(false); - } - findDialog.setVisible(true); - } - - } - - private class ShowReplaceDialogAction extends AbstractAction { - - public ShowReplaceDialogAction() { - super(t("isisfish.script.replace")); - int c = getToolkit().getMenuShortcutKeyMask(); - putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_H, c)); - } - - public void actionPerformed(ActionEvent e) { - if (findDialog.isVisible()) { - findDialog.setVisible(false); - } - replaceDialog.setVisible(true); - } - - } - - /** - * Listens for events from our search dialogs and actually does the dirty - * work. - */ - public void actionPerformed(ActionEvent e) { - - String command = e.getActionCommand(); - SearchDialogSearchContext context = findDialog.getSearchContext(); - - if (FindDialog.ACTION_FIND.equals(command)) { - if (!SearchEngine.find(textArea, context)) { - UIManager.getLookAndFeel().provideErrorFeedback(textArea); - } - } else if (ReplaceDialog.ACTION_REPLACE.equals(command)) { - if (!SearchEngine.replace(textArea, context)) { - UIManager.getLookAndFeel().provideErrorFeedback(textArea); - } - } else if (ReplaceDialog.ACTION_REPLACE_ALL.equals(command)) { - int count = SearchEngine.replaceAll(textArea, context); - JOptionPane.showMessageDialog(null, count - + " occurrences replaced."); - } - - } -} Deleted: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenManagerFactory.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenManagerFactory.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenManagerFactory.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -1,82 +0,0 @@ -package fr.ifremer.isisfish.ui.widget.text; - -/* - * #%L - * ISIS-Fish - * %% - * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric - * %% - * 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 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 Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory; - -/** - * Extends rsyntaxtextarea factory to add Isis fish specific style. - * - * @author Eric Chatellier - */ -public class IsisTokenManagerFactory extends AbstractTokenMakerFactory implements IsisSyntaxContants { - - @Override - protected void initTokenMakerMap() { - // isis support for log - putMapping(SYNTAX_STYLE_LOG, IsisTokenMarker.class.getName()); - - // default code - String pkg = "org.fife.ui.rsyntaxtextarea.modes."; - - putMapping(SYNTAX_STYLE_NONE, pkg + "PlainTextTokenMaker"); - putMapping(SYNTAX_STYLE_ACTIONSCRIPT, pkg + "ActionScriptTokenMaker"); - putMapping(SYNTAX_STYLE_ASSEMBLER_X86, pkg + "AssemblerX86TokenMaker"); - putMapping(SYNTAX_STYLE_BBCODE, pkg + "BBCodeTokenMaker"); - putMapping(SYNTAX_STYLE_C, pkg + "CTokenMaker"); - putMapping(SYNTAX_STYLE_CLOJURE, pkg + "ClojureTokenMaker"); - putMapping(SYNTAX_STYLE_CPLUSPLUS, pkg + "CPlusPlusTokenMaker"); - putMapping(SYNTAX_STYLE_CSHARP, pkg + "CSharpTokenMaker"); - putMapping(SYNTAX_STYLE_CSS, pkg + "CSSTokenMaker"); - putMapping(SYNTAX_STYLE_DELPHI, pkg + "DelphiTokenMaker"); - putMapping(SYNTAX_STYLE_DTD, pkg + "DtdTokenMaker"); - putMapping(SYNTAX_STYLE_FORTRAN, pkg + "FortranTokenMaker"); - putMapping(SYNTAX_STYLE_GROOVY, pkg + "GroovyTokenMaker"); - putMapping(SYNTAX_STYLE_HTACCESS, pkg + "HtaccessTokenMaker"); - putMapping(SYNTAX_STYLE_HTML, pkg + "HTMLTokenMaker"); - putMapping(SYNTAX_STYLE_JAVA, pkg + "JavaTokenMaker"); - putMapping(SYNTAX_STYLE_JAVASCRIPT, pkg + "JavaScriptTokenMaker"); - putMapping(SYNTAX_STYLE_JSON, pkg + "JsonTokenMaker"); - putMapping(SYNTAX_STYLE_JSP, pkg + "JSPTokenMaker"); - putMapping(SYNTAX_STYLE_LATEX, pkg + "LatexTokenMaker"); - putMapping(SYNTAX_STYLE_LISP, pkg + "LispTokenMaker"); - putMapping(SYNTAX_STYLE_LUA, pkg + "LuaTokenMaker"); - putMapping(SYNTAX_STYLE_MAKEFILE, pkg + "MakefileTokenMaker"); - putMapping(SYNTAX_STYLE_MXML, pkg + "MxmlTokenMaker"); - putMapping(SYNTAX_STYLE_NSIS, pkg + "NSISTokenMaker"); - putMapping(SYNTAX_STYLE_PERL, pkg + "PerlTokenMaker"); - putMapping(SYNTAX_STYLE_PHP, pkg + "PHPTokenMaker"); - putMapping(SYNTAX_STYLE_PROPERTIES_FILE,pkg + "PropertiesFileTokenMaker"); - putMapping(SYNTAX_STYLE_PYTHON, pkg + "PythonTokenMaker"); - putMapping(SYNTAX_STYLE_RUBY, pkg + "RubyTokenMaker"); - putMapping(SYNTAX_STYLE_SAS, pkg + "SASTokenMaker"); - putMapping(SYNTAX_STYLE_SCALA, pkg + "ScalaTokenMaker"); - putMapping(SYNTAX_STYLE_SQL, pkg + "SQLTokenMaker"); - putMapping(SYNTAX_STYLE_TCL, pkg + "TclTokenMaker"); - putMapping(SYNTAX_STYLE_UNIX_SHELL, pkg + "UnixShellTokenMaker"); - putMapping(SYNTAX_STYLE_VISUAL_BASIC, pkg + "VisualBasicTokenMaker"); - putMapping(SYNTAX_STYLE_WINDOWS_BATCH, pkg + "WindowsBatchTokenMaker"); - putMapping(SYNTAX_STYLE_XML, pkg + "XMLTokenMaker"); - } - -} Deleted: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenMarker.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenMarker.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/IsisTokenMarker.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -1,266 +0,0 @@ -package fr.ifremer.isisfish.ui.widget.text; - -/* - * #%L - * ISIS-Fish - * %% - * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric - * %% - * 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 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 Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import javax.swing.text.Segment; - -import org.fife.ui.rsyntaxtextarea.AbstractTokenMaker; -import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; -import org.fife.ui.rsyntaxtextarea.Token; -import org.fife.ui.rsyntaxtextarea.TokenMap; - -public class IsisTokenMarker extends AbstractTokenMaker { - - private int currentTokenStart; - private int currentTokenType; - - @Override - public Token getTokenList(Segment text, int initialTokenType, int startOffset) { - resetTokenList(); - - char[] array = text.array; - int offset = text.offset; - int count = text.count; - int end = offset + count; - - // See, when we find a token, its starting position is always of the form: - // 'startOffset + (currentTokenStart-offset)'; but since startOffset and - // offset are constant, tokens' starting positions become: - // 'newStartOffset+currentTokenStart' for one less subtraction operation. - int newStartOffset = startOffset - offset; - - currentTokenStart = offset; - currentTokenType = initialTokenType; - -//beginning: - for (int i=offset; i<end; i++) { - - char c = array[i]; - - switch (currentTokenType) { - - case Token.NULL: - - currentTokenStart = i; // Starting a new token here. - - switch (c) { - - case ' ': - case '\t': - currentTokenType = Token.WHITESPACE; - break; - - case '"': - currentTokenType = Token.ERROR_STRING_DOUBLE; - break; - - // The "separators". - case '|': - addToken(text, currentTokenStart,i, Token.SEPARATOR, newStartOffset+currentTokenStart); - currentTokenType = Token.NULL; - break; - - default: - - // Just to speed things up a tad, as this will usually be the case (if spaces above failed). - if (RSyntaxUtilities.isLetterOrDigit(c) || c=='\\') { - currentTokenType = Token.IDENTIFIER; - break; - } - - - currentTokenType = Token.IDENTIFIER; - break; - - } // End of switch (c). - - break; - - case Token.WHITESPACE: - - switch (c) { - - case ' ': - case '\t': - break; // Still whitespace. - - case '"': - addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); - currentTokenStart = i; - currentTokenType = Token.ERROR_STRING_DOUBLE; - break; - - // The "separators". - case '|': - addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); - addToken(text, i,i, Token.SEPARATOR, newStartOffset+i); - currentTokenType = Token.NULL; - break; - - default: // Add the whitespace token and start anew. - - addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); - currentTokenStart = i; - - // Just to speed things up a tad, as this will usually be the case (if spaces above failed). - if (RSyntaxUtilities.isLetterOrDigit(c) || c=='\\') { - currentTokenType = Token.IDENTIFIER; - break; - } - - - currentTokenType = Token.IDENTIFIER; - - } // End of switch (c). - - break; - - default: // Should never happen - case Token.IDENTIFIER: - - switch (c) { - - case ' ': - case '\t': - // Check for REM comments. - if (i-currentTokenStart==3 && - (array[i-3]=='r' || array[i-3]=='R') && - (array[i-2]=='e' || array[i-2]=='E') && - (array[i-1]=='m' || array[i-1]=='M')) { - currentTokenType = Token.COMMENT_EOL; - break; - } - addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); - currentTokenStart = i; - currentTokenType = Token.WHITESPACE; - break; - - case '"': - addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); - currentTokenStart = i; - currentTokenType = Token.ERROR_STRING_DOUBLE; - break; - - // The "separators". - case '|': - addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); - addToken(text, i,i, Token.SEPARATOR, newStartOffset+i); - currentTokenType = Token.NULL; - break; - - - default: - - // Just to speed things up a tad, as this will usually be the case. - if (RSyntaxUtilities.isLetterOrDigit(c) || c=='\\') { - break; - } - - // Otherwise, fall through and assume we're still okay as an IDENTIFIER... - - } // End of switch (c). - - break; - - case Token.COMMENT_EOL: - i = end - 1; - addToken(text, currentTokenStart,i, Token.COMMENT_EOL, newStartOffset+currentTokenStart); - // We need to set token type to null so at the bottom we don't add one more token. - currentTokenType = Token.NULL; - break; - - case Token.PREPROCESSOR: // Used for labels - i = end - 1; - addToken(text, currentTokenStart,i, Token.PREPROCESSOR, newStartOffset+currentTokenStart); - // We need to set token type to null so at the bottom we don't add one more token. - currentTokenType = Token.NULL; - break; - - case Token.ERROR_STRING_DOUBLE: - - if (c=='"') { - addToken(text, currentTokenStart,i, Token.LITERAL_STRING_DOUBLE_QUOTE, newStartOffset+currentTokenStart); - currentTokenStart = i + 1; - currentTokenType = Token.NULL; - } - // Otherwise, we're still an unclosed string... - - break; - - } // End of switch (currentTokenType). - - } // End of for (int i=offset; i<end; i++). - - // Deal with the (possibly there) last token. - if (currentTokenType != Token.NULL) { - - // Check for REM comments. - if (end-currentTokenStart==3 && - (array[end-3]=='r' || array[end-3]=='R') && - (array[end-2]=='e' || array[end-2]=='E') && - (array[end-1]=='m' || array[end-1]=='M')) { - currentTokenType = Token.COMMENT_EOL; - } - - addToken(text, currentTokenStart,end-1, currentTokenType, newStartOffset+currentTokenStart); - } - - addNullToken(); - - // Return the first token in our linked list. - return firstToken; - - } - - @Override - public TokenMap getWordsToHighlight() { - TokenMap tokenMap = new TokenMap(); - - tokenMap.put("FATAL", Token.RESERVED_WORD_2); - tokenMap.put("ERROR", Token.RESERVED_WORD_2); - tokenMap.put("INFO", Token.RESERVED_WORD); - tokenMap.put("DEBUG", Token.RESERVED_WORD); - tokenMap.put("TRACE", Token.RESERVED_WORD); - - return tokenMap; - } - - @Override - public void addToken(Segment segment, int start, int end, int tokenType, int startOffset) { - - switch (tokenType) { - // Since reserved words, functions, and data types are all passed - // into here as "identifiers," we have to see what the token - // really is... - case Token.IDENTIFIER: - int value = wordsToHighlight.get(segment, start,end); - if (value!=-1) - tokenType = value; - break; - } - - super.addToken(segment, start, end, tokenType, startOffset); - - } - -} Copied: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/LogTokenMarker.java (from rev 4262, branches/isis-fish-4.4.0-editor/src/main/java/fr/ifremer/isisfish/ui/widget/text/LogTokenMarker.java) =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/LogTokenMarker.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/LogTokenMarker.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -0,0 +1,271 @@ +/* + * #%L + * ISIS-Fish + * %% + * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric + * %% + * 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 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.ui.widget.text; + +import javax.swing.text.Segment; + +import org.fife.ui.rsyntaxtextarea.AbstractTokenMaker; +import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; +import org.fife.ui.rsyntaxtextarea.Token; +import org.fife.ui.rsyntaxtextarea.TokenMap; + +/** + * Token marker for Isis Log files. + * + * @author Eric Chatellier + */ +public class LogTokenMarker extends AbstractTokenMaker { + + private int currentTokenStart; + private int currentTokenType; + + @Override + public Token getTokenList(Segment text, int initialTokenType, int startOffset) { + resetTokenList(); + + char[] array = text.array; + int offset = text.offset; + int count = text.count; + int end = offset + count; + + // See, when we find a token, its starting position is always of the form: + // 'startOffset + (currentTokenStart-offset)'; but since startOffset and + // offset are constant, tokens' starting positions become: + // 'newStartOffset+currentTokenStart' for one less subtraction operation. + int newStartOffset = startOffset - offset; + + currentTokenStart = offset; + currentTokenType = initialTokenType; + +//beginning: + for (int i=offset; i<end; i++) { + + char c = array[i]; + + switch (currentTokenType) { + + case Token.NULL: + + currentTokenStart = i; // Starting a new token here. + + switch (c) { + + case ' ': + case '\t': + currentTokenType = Token.WHITESPACE; + break; + + case '"': + currentTokenType = Token.ERROR_STRING_DOUBLE; + break; + + // The "separators". + case '|': + addToken(text, currentTokenStart,i, Token.SEPARATOR, newStartOffset+currentTokenStart); + currentTokenType = Token.NULL; + break; + + default: + + // Just to speed things up a tad, as this will usually be the case (if spaces above failed). + if (RSyntaxUtilities.isLetterOrDigit(c) || c=='\\') { + currentTokenType = Token.IDENTIFIER; + break; + } + + + currentTokenType = Token.IDENTIFIER; + break; + + } // End of switch (c). + + break; + + case Token.WHITESPACE: + + switch (c) { + + case ' ': + case '\t': + break; // Still whitespace. + + case '"': + addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); + currentTokenStart = i; + currentTokenType = Token.ERROR_STRING_DOUBLE; + break; + + // The "separators". + case '|': + addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); + addToken(text, i,i, Token.SEPARATOR, newStartOffset+i); + currentTokenType = Token.NULL; + break; + + default: // Add the whitespace token and start anew. + + addToken(text, currentTokenStart,i-1, Token.WHITESPACE, newStartOffset+currentTokenStart); + currentTokenStart = i; + + // Just to speed things up a tad, as this will usually be the case (if spaces above failed). + if (RSyntaxUtilities.isLetterOrDigit(c) || c=='\\') { + currentTokenType = Token.IDENTIFIER; + break; + } + + + currentTokenType = Token.IDENTIFIER; + + } // End of switch (c). + + break; + + default: // Should never happen + case Token.IDENTIFIER: + + switch (c) { + + case ' ': + case '\t': + // Check for REM comments. + if (i-currentTokenStart==3 && + (array[i-3]=='r' || array[i-3]=='R') && + (array[i-2]=='e' || array[i-2]=='E') && + (array[i-1]=='m' || array[i-1]=='M')) { + currentTokenType = Token.COMMENT_EOL; + break; + } + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + currentTokenStart = i; + currentTokenType = Token.WHITESPACE; + break; + + case '"': + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + currentTokenStart = i; + currentTokenType = Token.ERROR_STRING_DOUBLE; + break; + + // The "separators". + case '|': + addToken(text, currentTokenStart,i-1, Token.IDENTIFIER, newStartOffset+currentTokenStart); + addToken(text, i,i, Token.SEPARATOR, newStartOffset+i); + currentTokenType = Token.NULL; + break; + + + default: + + // Just to speed things up a tad, as this will usually be the case. + if (RSyntaxUtilities.isLetterOrDigit(c) || c=='\\') { + break; + } + + // Otherwise, fall through and assume we're still okay as an IDENTIFIER... + + } // End of switch (c). + + break; + + case Token.COMMENT_EOL: + i = end - 1; + addToken(text, currentTokenStart,i, Token.COMMENT_EOL, newStartOffset+currentTokenStart); + // We need to set token type to null so at the bottom we don't add one more token. + currentTokenType = Token.NULL; + break; + + case Token.PREPROCESSOR: // Used for labels + i = end - 1; + addToken(text, currentTokenStart,i, Token.PREPROCESSOR, newStartOffset+currentTokenStart); + // We need to set token type to null so at the bottom we don't add one more token. + currentTokenType = Token.NULL; + break; + + case Token.ERROR_STRING_DOUBLE: + + if (c=='"') { + addToken(text, currentTokenStart,i, Token.LITERAL_STRING_DOUBLE_QUOTE, newStartOffset+currentTokenStart); + currentTokenStart = i + 1; + currentTokenType = Token.NULL; + } + // Otherwise, we're still an unclosed string... + + break; + + } // End of switch (currentTokenType). + + } // End of for (int i=offset; i<end; i++). + + // Deal with the (possibly there) last token. + if (currentTokenType != Token.NULL) { + + // Check for REM comments. + if (end-currentTokenStart==3 && + (array[end-3]=='r' || array[end-3]=='R') && + (array[end-2]=='e' || array[end-2]=='E') && + (array[end-1]=='m' || array[end-1]=='M')) { + currentTokenType = Token.COMMENT_EOL; + } + + addToken(text, currentTokenStart,end-1, currentTokenType, newStartOffset+currentTokenStart); + } + + addNullToken(); + + // Return the first token in our linked list. + return firstToken; + + } + + @Override + public TokenMap getWordsToHighlight() { + TokenMap tokenMap = new TokenMap(); + + tokenMap.put("FATAL", Token.RESERVED_WORD_2); + tokenMap.put("ERROR", Token.RESERVED_WORD_2); + tokenMap.put("INFO", Token.RESERVED_WORD); + tokenMap.put("DEBUG", Token.RESERVED_WORD); + tokenMap.put("TRACE", Token.RESERVED_WORD); + + return tokenMap; + } + + @Override + public void addToken(Segment segment, int start, int end, int tokenType, int startOffset) { + + switch (tokenType) { + // Since reserved words, functions, and data types are all passed + // into here as "identifiers," we have to see what the token + // really is... + case Token.IDENTIFIER: + int value = wordsToHighlight.get(segment, start,end); + if (value!=-1) + tokenType = value; + break; + } + + super.addToken(segment, start, end, tokenType, startOffset); + + } + +} Copied: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxEditor.java (from rev 4262, branches/isis-fish-4.4.0-editor/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxEditor.java) =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxEditor.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxEditor.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -0,0 +1,393 @@ +package fr.ifremer.isisfish.ui.widget.text; + +import static org.nuiton.i18n.I18n.t; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchKey; +import java.nio.file.WatchService; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.KeyStroke; +import javax.swing.ToolTipManager; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.fife.rsta.ac.LanguageSupport; +import org.fife.rsta.ac.LanguageSupportFactory; +import org.fife.rsta.ac.java.JavaCompletionProvider; +import org.fife.rsta.ac.java.JavaLanguageSupport; +import org.fife.ui.autocomplete.AutoCompletion; +import org.fife.ui.autocomplete.CompletionProvider; +import org.fife.ui.autocomplete.DefaultCompletionProvider; +import org.fife.ui.rsyntaxtextarea.SyntaxConstants; +import org.nuiton.util.FileUtil; + +/** + * Add custom behavior to RSyntaxEditor UI. + * + * Like : + * <ul> + * <li>copy/paste</li> + * <li>file change detection</li> + * </ul> + * + * @author Eric Chatellier + */ +public class SyntaxEditor extends SyntaxEditorUI implements DocumentListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = 8010988112139944408L; + + /** class logger */ + private static Log log = LogFactory.getLog(SyntaxEditor.class); + + /** Will ask user to perform save on close. */ + protected boolean askIfNotSaved = false; + + /** Currently edited file. */ + protected File file; + + /** Flag is file has been modified. */ + protected transient boolean modified; + + /** Timestamp when saved has been performed from editor. */ + protected transient long lastSaveTimestamp; + + /** Save action instance. */ + protected Action saveAction; + + /** Single watch service instance. */ + protected WatchService watchService; + + /** Watch service thread. */ + protected Thread watchThread; + + /** Ask reload file panel (not null if displayed). */ + protected JPanel askReloadPanel; + + public SyntaxEditor() { + + // save action + int c = getToolkit().getMenuShortcutKeyMask(); + saveAction = new AbstractAction(t("isisfish.editor.save"), new ImageIcon(getClass().getResource("/icons/script/disk-black.png"))) { + public void actionPerformed(ActionEvent e) { + save(); + } + }; + saveAction.setEnabled(false); + saveAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, c)); + + // autocomplete support + setAutocomplete(); + + // to listen for user modification (after setAutocomplete) + textArea.getDocument().addDocumentListener(this); + } + + /** + * Autocomplete support is not perfect yet and don't support partial classes (equation). + */ + protected void setAutocomplete() { + + /*LanguageSupportFactory lsf = LanguageSupportFactory.get(); + LanguageSupport support = lsf.getSupportFor(SyntaxConstants.SYNTAX_STYLE_JAVA); + JavaLanguageSupport jls = (JavaLanguageSupport)support; + try { + jls.getJarManager().addCurrentJreClassFileSource(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + lsf.register(textArea); + + ToolTipManager.sharedInstance().registerComponent(textArea); + CompletionProvider provider = new DefaultCompletionProvider(); + AutoCompletion ac = new AutoCompletion(provider); + ac.install(textArea);*/ + } + + @Override + protected void finalize() throws Throwable { + try { + watchService.close(); + } finally { + super.finalize(); + } + } + + public boolean isAskIfNotSaved() { + return askIfNotSaved; + } + + public void setAskIfNotSaved(boolean askIfNotSaved) { + this.askIfNotSaved = askIfNotSaved; + } + + protected void setModified(boolean modified) { + this.modified = modified; + saveAction.setEnabled(modified); + } + + public boolean isModified() { + return modified; + } + + public void addDocumentListener(DocumentListener listener) { + textArea.getDocument().addDocumentListener(listener); + } + + public void removeDocumentListener(DocumentListener listener) { + textArea.getDocument().removeDocumentListener(listener); + } + + public boolean open(File file) { + // try to save previous file if necessary + boolean result = askAndSaveOrCancel(); + + if (result) { + + clearReloadPanel(); + + //try (Reader in = new BufferedReader(new FileReader(file), "utf-8")) { + try (Reader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) { + + String ext = FileUtil.extension(file); + if ("java".equalsIgnoreCase(ext)) { + textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA); + } else if ("xml".equalsIgnoreCase(ext)) { + textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML); + } else if ("sql".equalsIgnoreCase(ext)) { + textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL); + } else if ("r".equalsIgnoreCase(ext)) { + textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PERL); + } + + textArea.read(in, null); + textArea.setCaretPosition(0); + + setFile(file); // after textArea.read + } catch (Exception eee) { + if (log.isWarnEnabled()) { + log.warn("Can't read file", eee); + } + } + } + + return result; + } + + protected boolean askAndSaveOrCancel() { + boolean result = true; + if (isAskIfNotSaved() && isModified()) { + int val = JOptionPane.showConfirmDialog(this, + t("isisfish.editor.saveorcancel.message", file.getName()), + t("isisfish.editor.saveorcancel.title"), + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE); + switch (val) { + case JOptionPane.YES_OPTION: + save(); + result = true; + break; + case JOptionPane.NO_OPTION: + result = true; + break; + case JOptionPane.CANCEL_OPTION: + result = false; + break; + } + } + return result; + } + + public boolean close() { + boolean result = askAndSaveOrCancel(); + setFile(null); + return result; + } + + protected void setFile(File file) { + // XXX maybe remove old file watch service ? + this.file = file; + + setEnabled(file != null); + setModified(false); + + // detect external changes + if (file != null) { + detectExternalChanges(file); + } + } + + public void save() { + clearReloadPanel(); + + try (Writer out = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) { + lastSaveTimestamp = System.currentTimeMillis(); + + textArea.write(out); + setModified(false); + } catch (IOException eee) { + if (log.isWarnEnabled()) { + log.warn("Can't save file", eee); + } + } + } + + public String getText() { + return textArea.getText(); + } + + public void copy() { + textArea.copy(); + } + + public void paste() { + textArea.paste(); + } + + public void cut() { + textArea.cut(); + } + + @Override + public void insertUpdate(DocumentEvent e) { + setModified(true); + } + + @Override + public void removeUpdate(DocumentEvent e) { + setModified(true); + } + + @Override + public void changedUpdate(DocumentEvent e) { + setModified(true); + } + + public Action getSaveAction() { + return saveAction; + } + + protected void clearReloadPanel() { + if (askReloadPanel != null) { + hideBottomComponent(); + askReloadPanel = null; + } + } + + protected void detectExternalChanges(File file) { + if (askIfNotSaved) { + try { + if (watchService == null) { + watchService = FileSystems.getDefault().newWatchService(); + } + if (watchThread == null) { + watchThread = new WatchThread(); + watchThread.start(); + } + + // register new file to watch service + Path filePath = file.toPath(); + Path parentPath = filePath.getParent(); + parentPath.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_CREATE); + } catch (IOException ex) { + if (log.isErrorEnabled()) { + log.error("Can't listen for file", ex); + } + } + } + } + + protected void notifyFileChanged(final File file) { + if (askReloadPanel == null && file.equals(this.file)) { + + // check to not display self save + if (file.lastModified() - lastSaveTimestamp < 1000) { + return; + } + + setModified(true); // to allow erasure + + askReloadPanel = new JPanel(new BorderLayout()); + + askReloadPanel.setBackground(new Color(242, 242, 189)); // dark yellow + + askReloadPanel.add(new JLabel(t("isisfish.editor.reloadExternal"), + new ImageIcon(getClass().getResource("/icons/common/exclamation.png")), JLabel.LEFT), BorderLayout.CENTER); + + JPanel actionsPanel = new JPanel(new FlowLayout()); + actionsPanel.setBackground(new Color(242, 242, 189)); // dark yellow + actionsPanel.add(new JButton(new AbstractAction(t("isisfish.editor.reload")) { + @Override + public void actionPerformed(ActionEvent e) { + setModified(false); // to never ask + open(file); + } + })); + actionsPanel.add(new JButton(new AbstractAction(t("isisfish.editor.cancel")) { + @Override + public void actionPerformed(ActionEvent e) { + clearReloadPanel(); + } + })); + + askReloadPanel.add(actionsPanel, BorderLayout.EAST); + addBottomComponent(askReloadPanel); + showBottomComponent(askReloadPanel); + } + } + + class WatchThread extends Thread { + public void run() { + try { + while (true) { + final WatchKey wk = watchService.take(); + for (WatchEvent<?> event : wk.pollEvents()) { + //we only register "ENTRY_MODIFY" so the context is always a Path. + Path changed = (Path)event.context(); + Path watchPath = (Path)wk.watchable(); + File fullFile = new File(watchPath.toFile(), changed.toString()); + notifyFileChanged(fullFile); + } + // reset the key + boolean valid = wk.reset(); + if (!valid) { + if (log.isErrorEnabled()) { + log.error("Watch service unregistered"); + } + } + } + } catch (InterruptedException ex) { + if (log.isErrorEnabled()) { + log.error("Thread interrupted", ex); + } + } + } + } +} Copied: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxEditorUI.java (from rev 4262, branches/isis-fish-4.4.0-editor/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxEditorUI.java) =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxEditorUI.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxEditorUI.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -0,0 +1,340 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric + * %% + * 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 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.isisfish.ui.widget.text; + +import static org.nuiton.i18n.I18n.t; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.KeyStroke; +import javax.swing.UIManager; +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; +import javax.swing.text.BadLocationException; + +import org.fife.rsta.ui.CollapsibleSectionPanel; +import org.fife.rsta.ui.GoToDialog; +import org.fife.rsta.ui.search.FindDialog; +import org.fife.rsta.ui.search.ReplaceDialog; +import org.fife.rsta.ui.search.SearchEvent; +import org.fife.rsta.ui.search.SearchListener; +import org.fife.ui.rsyntaxtextarea.ErrorStrip; +import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; +import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; +import org.fife.ui.rsyntaxtextarea.SyntaxScheme; +import org.fife.ui.rsyntaxtextarea.Token; +import org.fife.ui.rtextarea.RTextScrollPane; +import org.fife.ui.rtextarea.SearchContext; +import org.fife.ui.rtextarea.SearchEngine; +import org.fife.ui.rtextarea.SearchResult; + +/** + * {@link RSyntaxTextArea} component property configured for isis fish. + * + * An intermediate panel is used here to allow displaying user action panel to user. + * + * @author Eric Chatellier + */ +public class SyntaxEditorUI extends CollapsibleSectionPanel implements SearchListener, CaretListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1427883892685276516L; + + protected RTextScrollPane textScrollpane; + protected RSyntaxTextArea textArea; + protected JLabel noFileLabel; + + protected FindDialog findDialog; + protected ReplaceDialog replaceDialog; + + protected Action findAction; + protected Action replaceAction; + protected Action gotoAction; + protected Action cutAction; + protected Action pasteAction; + protected Action copyAction; + + public SyntaxEditorUI() { + super(true); + + textArea = new RSyntaxTextArea(); + textScrollpane = new RTextScrollPane(textArea); + + noFileLabel = new JLabel(t("isisfish.editor.noselectedfile"), JLabel.CENTER); + noFileLabel.setEnabled(false); + + // for error/warning markers + ErrorStrip errorStrip = new ErrorStrip(textArea); + add(errorStrip, BorderLayout.LINE_END); + + // highlight marked occurence after small period of time + textArea.setMarkOccurrences(true); + + // display line number + textScrollpane.setLineNumbersEnabled(true); + + // tab is evil + textArea.setTabsEmulated(true); + textArea.setTabSize(4); + + initActions(); + + setEnabled(false); + } + + protected void initActions() { + Frame parent = null; + + findDialog = new FindDialog(parent, this); + replaceDialog = new ReplaceDialog(parent, this); + + findAction = new ShowFindDialogAction(); + replaceAction = new ShowReplaceDialogAction(); + gotoAction = new GoToLineAction(parent); + + int c = getToolkit().getMenuShortcutKeyMask(); + // caret update will update setEnabled state + textArea.addCaretListener(this); + cutAction = new AbstractAction(t("isisfish.editor.cut"), new ImageIcon(getClass().getResource("/icons/script/scissors.png"))) { + @Override + public void actionPerformed(ActionEvent e) { + textArea.cut(); + } + }; + cutAction.setEnabled(false); + cutAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, c)); + pasteAction = new AbstractAction(t("isisfish.editor.paste"), new ImageIcon(getClass().getResource("/icons/script/clipboard-paste.png"))) { + @Override + public void actionPerformed(ActionEvent e) { + textArea.paste(); + } + }; + pasteAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V, c)); + copyAction = new AbstractAction(t("isisfish.editor.copy"), new ImageIcon(getClass().getResource("/icons/script/document-copy.png"))) { + @Override + public void actionPerformed(ActionEvent e) { + textArea.copy(); + } + }; + copyAction.setEnabled(false); + copyAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, c)); + } + + /** + * Set highligth style. + * + * @param style new style + * @see IsisSyntaxConstants + */ + public void setStyle(String style) { + RSyntaxDocument doc = new RSyntaxDocument(new SyntaxTokenManagerFactory(), style); + textArea.setDocument(doc); + + // special theme for log + if (IsisSyntaxConstants.SYNTAX_STYLE_LOG.equals(style)) { + SyntaxScheme scheme = textArea.getSyntaxScheme(); + scheme.getStyle(Token.RESERVED_WORD_2).foreground = Color.RED; + } + } + + public void setText(String text) { + textArea.setText(text); + textArea.invalidate(); + } + + @Override + public void setEnabled(boolean enabled) { + if (enabled) { + remove(noFileLabel); + add(textScrollpane); + } else { + remove(textScrollpane); + add(noFileLabel); + + cutAction.setEnabled(false); + copyAction.setEnabled(false); + } + + pasteAction.setEnabled(enabled); + + // workarround for http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4286743 + //textScrollpane.getHorizontalScrollBar().setEnabled(enabled); + //textScrollpane.getVerticalScrollBar().setEnabled(enabled); + //textScrollpane.getViewport().getView().setEnabled(enabled); + //textScrollpane.setEnabled(enabled); + + revalidate(); + repaint(); + } + + private class GoToLineAction extends AbstractAction { + protected Frame parent; + public GoToLineAction(Frame parent) { + super(t("isisfish.script.gotoline")); + this.parent = parent; + int c = getToolkit().getMenuShortcutKeyMask(); + putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_L, c)); + } + + public void actionPerformed(ActionEvent e) { + if (findDialog.isVisible()) { + findDialog.setVisible(false); + } + if (replaceDialog.isVisible()) { + replaceDialog.setVisible(false); + } + GoToDialog dialog = new GoToDialog(this.parent); + dialog.setMaxLineNumberAllowed(textArea.getLineCount()); + dialog.setVisible(true); + int line = dialog.getLineNumber(); + if (line>0) { + try { + textArea.setCaretPosition(textArea.getLineStartOffset(line-1)); + } catch (BadLocationException ble) { // Never happens + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + ble.printStackTrace(); + } + } + } + + } + + private class ShowFindDialogAction extends AbstractAction { + + public ShowFindDialogAction() { + super(t("isisfish.script.find")); + int c = getToolkit().getMenuShortcutKeyMask(); + putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, c)); + } + + public void actionPerformed(ActionEvent e) { + if (replaceDialog.isVisible()) { + replaceDialog.setVisible(false); + } + findDialog.setVisible(true); + } + + } + + private class ShowReplaceDialogAction extends AbstractAction { + + public ShowReplaceDialogAction() { + super(t("isisfish.script.replace")); + int c = getToolkit().getMenuShortcutKeyMask(); + putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_H, c)); + } + + public void actionPerformed(ActionEvent e) { + if (findDialog.isVisible()) { + findDialog.setVisible(false); + } + replaceDialog.setVisible(true); + } + + } + + public Action getFindAction() { + return findAction; + } + + public Action getReplaceAction() { + return replaceAction; + } + + public Action getGotoAction() { + return gotoAction; + } + + public Action getPasteAction() { + return pasteAction; + } + + public Action getCopyAction() { + return copyAction; + } + + public Action getCutAction() { + return cutAction; + } + + @Override + public String getSelectedText() { + return textArea.getSelectedText(); + } + + /** + * Listens for events from our search dialogs and actually does the dirty + * work. + */ + @Override + public void searchEvent(SearchEvent e) { + + SearchEvent.Type type = e.getType(); + SearchContext context = e.getSearchContext(); + SearchResult result = null; + + switch (type) { + default: // Prevent FindBugs warning later + case MARK_ALL: + result = SearchEngine.markAll(textArea, context); + break; + case FIND: + result = SearchEngine.find(textArea, context); + if (!result.wasFound()) { + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + } + break; + case REPLACE: + result = SearchEngine.replace(textArea, context); + if (!result.wasFound()) { + UIManager.getLookAndFeel().provideErrorFeedback(textArea); + } + break; + case REPLACE_ALL: + result = SearchEngine.replaceAll(textArea, context); + JOptionPane.showMessageDialog(null, result.getCount() + + " occurrences replaced."); + break; + } + } + + /* + * @see javax.swing.event.CaretListener#caretUpdate(javax.swing.event.CaretEvent) + */ + @Override + public void caretUpdate(CaretEvent e) { + // selection pas vide si dot = mark + boolean selected = e.getDot() != e.getMark(); + cutAction.setEnabled(selected); + copyAction.setEnabled(selected); + } +} Copied: trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxTokenManagerFactory.java (from rev 4262, branches/isis-fish-4.4.0-editor/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxTokenManagerFactory.java) =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxTokenManagerFactory.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/widget/text/SyntaxTokenManagerFactory.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -0,0 +1,82 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric + * %% + * 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 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.isisfish.ui.widget.text; + +import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory; + +/** + * Extends rsyntaxtextarea factory to add Isis fish specific style. + * + * @author Eric Chatellier + */ +public class SyntaxTokenManagerFactory extends AbstractTokenMakerFactory implements IsisSyntaxConstants { + + @Override + protected void initTokenMakerMap() { + // isis support for log + putMapping(SYNTAX_STYLE_LOG, LogTokenMarker.class.getName()); + + // default code + String pkg = "org.fife.ui.rsyntaxtextarea.modes."; + + putMapping(SYNTAX_STYLE_NONE, pkg + "PlainTextTokenMaker"); + putMapping(SYNTAX_STYLE_ACTIONSCRIPT, pkg + "ActionScriptTokenMaker"); + putMapping(SYNTAX_STYLE_ASSEMBLER_X86, pkg + "AssemblerX86TokenMaker"); + putMapping(SYNTAX_STYLE_BBCODE, pkg + "BBCodeTokenMaker"); + putMapping(SYNTAX_STYLE_C, pkg + "CTokenMaker"); + putMapping(SYNTAX_STYLE_CLOJURE, pkg + "ClojureTokenMaker"); + putMapping(SYNTAX_STYLE_CPLUSPLUS, pkg + "CPlusPlusTokenMaker"); + putMapping(SYNTAX_STYLE_CSHARP, pkg + "CSharpTokenMaker"); + putMapping(SYNTAX_STYLE_CSS, pkg + "CSSTokenMaker"); + putMapping(SYNTAX_STYLE_DELPHI, pkg + "DelphiTokenMaker"); + putMapping(SYNTAX_STYLE_DTD, pkg + "DtdTokenMaker"); + putMapping(SYNTAX_STYLE_FORTRAN, pkg + "FortranTokenMaker"); + putMapping(SYNTAX_STYLE_GROOVY, pkg + "GroovyTokenMaker"); + putMapping(SYNTAX_STYLE_HTACCESS, pkg + "HtaccessTokenMaker"); + putMapping(SYNTAX_STYLE_HTML, pkg + "HTMLTokenMaker"); + putMapping(SYNTAX_STYLE_JAVA, pkg + "JavaTokenMaker"); + putMapping(SYNTAX_STYLE_JAVASCRIPT, pkg + "JavaScriptTokenMaker"); + putMapping(SYNTAX_STYLE_JSON, pkg + "JsonTokenMaker"); + putMapping(SYNTAX_STYLE_JSP, pkg + "JSPTokenMaker"); + putMapping(SYNTAX_STYLE_LATEX, pkg + "LatexTokenMaker"); + putMapping(SYNTAX_STYLE_LISP, pkg + "LispTokenMaker"); + putMapping(SYNTAX_STYLE_LUA, pkg + "LuaTokenMaker"); + putMapping(SYNTAX_STYLE_MAKEFILE, pkg + "MakefileTokenMaker"); + putMapping(SYNTAX_STYLE_MXML, pkg + "MxmlTokenMaker"); + putMapping(SYNTAX_STYLE_NSIS, pkg + "NSISTokenMaker"); + putMapping(SYNTAX_STYLE_PERL, pkg + "PerlTokenMaker"); + putMapping(SYNTAX_STYLE_PHP, pkg + "PHPTokenMaker"); + putMapping(SYNTAX_STYLE_PROPERTIES_FILE,pkg + "PropertiesFileTokenMaker"); + putMapping(SYNTAX_STYLE_PYTHON, pkg + "PythonTokenMaker"); + putMapping(SYNTAX_STYLE_RUBY, pkg + "RubyTokenMaker"); + putMapping(SYNTAX_STYLE_SAS, pkg + "SASTokenMaker"); + putMapping(SYNTAX_STYLE_SCALA, pkg + "ScalaTokenMaker"); + putMapping(SYNTAX_STYLE_SQL, pkg + "SQLTokenMaker"); + putMapping(SYNTAX_STYLE_TCL, pkg + "TclTokenMaker"); + putMapping(SYNTAX_STYLE_UNIX_SHELL, pkg + "UnixShellTokenMaker"); + putMapping(SYNTAX_STYLE_VISUAL_BASIC, pkg + "VisualBasicTokenMaker"); + putMapping(SYNTAX_STYLE_WINDOWS_BATCH, pkg + "WindowsBatchTokenMaker"); + putMapping(SYNTAX_STYLE_XML, pkg + "XMLTokenMaker"); + } + +} Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties =================================================================== --- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2015-06-11 09:01:47 UTC (rev 4263) @@ -250,7 +250,17 @@ isisfish.config.vcs.userName.description=Official VCS user name isisfish.config.vcs.userPassword.description=Official VCS password isisfish.date.toString=%1$s %2$s +isisfish.editor.cancel=Cancel +isisfish.editor.copy=Copy +isisfish.editor.cut=Cut +isisfish.editor.noselectedfile=No file selected \! isisfish.editor.parametersnameandtypes=Parameters (name and type) +isisfish.editor.paste=Paste +isisfish.editor.reload=Reload +isisfish.editor.reloadExternal=File has been modified by external application +isisfish.editor.save=Save +isisfish.editor.saveorcancel.message=File '%s' has been modified, do you want to save file ? +isisfish.editor.saveorcancel.title=Save file isisfish.effortDescription.crewFoodCost=Crew food cost isisfish.effortDescription.crewShareRate=Crew share rate isisfish.effortDescription.crewSize=Crew size @@ -620,6 +630,7 @@ isisfish.params.rules=Rules isisfish.params.rules.availables=Available rules isisfish.params.rules.selected=Selected rules +isisfish.params.rules.tooltip=Rules are executed ordered \! You can change order using drag and drop. isisfish.params.sensitivityName=Sensitivity name isisfish.params.sensitivityOnlyKeepFirstResult=Only keep results for first simulation isisfish.params.simulationLauncher=Simulation launcher @@ -794,7 +805,7 @@ isisfish.script.export.tooltip.checkAll=(Un)Check all scripts to export isisfish.script.export.tooltip.chooseDir=Choose directory to export script to isisfish.script.find=Find... -isisfish.script.gotoline=Got to line... +isisfish.script.gotoline=Go to line... isisfish.script.import=Import scripts from archive isisfish.script.import.cancel=Cancel isisfish.script.import.checkAll=(Un)Check all script to import Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties =================================================================== --- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2015-06-11 09:01:47 UTC (rev 4263) @@ -250,7 +250,17 @@ isisfish.config.vcs.userName.description=le login de l'utilisateur sur le serveur vcs isisfish.config.vcs.userPassword.description=le mot de passe de l'utilsateur sur le serveur vcs isisfish.date.toString=%1$s %2$s +isisfish.editor.cancel=Annuler +isisfish.editor.copy=Copier +isisfish.editor.cut=Couper +isisfish.editor.noselectedfile=Aucun fichier sélectionné \! isisfish.editor.parametersnameandtypes=Paramètres (nom et type) +isisfish.editor.paste=Coller +isisfish.editor.reload=Recharger +isisfish.editor.reloadExternal=Le fichier a été modifié par une autre application +isisfish.editor.save=Sauvegarder +isisfish.editor.saveorcancel.message=Le fichier '%s' a été modifié, voulez-vous le sauvegarder ? +isisfish.editor.saveorcancel.title=Sauvegarder le fichier isisfish.effortDescription.crewFoodCost=Coût de l'alimentation pour l'équipage isisfish.effortDescription.crewShareRate=Taux de partage de l'équipage isisfish.effortDescription.crewSize=Taille de l'équipage @@ -620,6 +630,7 @@ isisfish.params.rules=Règles isisfish.params.rules.availables=Règles disponibles isisfish.params.rules.selected=Règles sélectionnées +isisfish.params.rules.tooltip=Les règles sont executées dans l'ordre défini \! Vous pouvez modifier l'ordre à l'aide du glisser-déposer. isisfish.params.sensitivityName=Nom de l'analyse de sensibilité isisfish.params.sensitivityOnlyKeepFirstResult=Ne conserver les résultats que pour la première simulation. isisfish.params.simulationLauncher=Lanceur de simulation @@ -952,7 +963,7 @@ isisfish.ssh.askpassphrase.message=Entrez la passphrase pour la clé '%s' \: isisfish.ssh.askpassphrase.title=Déverrouillage de clé SSH isisfish.ssh.askpassphrase.wrongpassphrase=Mauvaise clé, entrez une nouvelle passphrase '%s' \: -isisfish.status.screenshot=Prendre une captures d'écran +isisfish.status.screenshot=Prendre une capture d'écran isisfish.strategy.comments=Commentaires isisfish.strategy.inactivity=Equation d'inactivité isisfish.strategy.inactivityEquationUsed=Utiliser une équation d'inactivité Copied: trunk/src/main/resources/icons/README.txt (from rev 4262, branches/isis-fish-4.4.0-ui-refactoring/src/main/resources/icons/README.txt) =================================================================== --- trunk/src/main/resources/icons/README.txt (rev 0) +++ trunk/src/main/resources/icons/README.txt 2015-06-11 09:01:47 UTC (rev 4263) @@ -0,0 +1,80 @@ +Fugue Icons + +(C) 2013 Yusuke Kamiyamane. All rights reserved. + +These icons are licensed under a Creative Commons +Attribution 3.0 License. +<http://creativecommons.org/licenses/by/3.0/> + +If you can't or don't want to provide attribution, please +purchase a royalty-free license. +<http://p.yusukekamiyamane.com/> + +I'm unavailable for custom icon design work. But your +suggestions are always welcome! +<mailto:p@yusukekamiyamane.com> + +------------------------------------------------------------ + +All logos and trademarks in some icons are property of their +respective owners. + +------------------------------------------------------------ + +- geotag + + (C) Geotag Icon Project. All rights reserved. + <http://www.geotagicons.com/> + + Geotag icon is licensed under a Creative Commons + Attribution-Share Alike 3.0 License or LGPL. + <http://creativecommons.org/licenses/by-sa/3.0/> + <http://opensource.org/licenses/lgpl-license.php> + +- language + + (C) Language Icon Project. All rights reserved. + <http://www.languageicon.org/> + + Language icon is licensed under a Creative Commons + Attribution-Share Alike 3.0 License. + <http://creativecommons.org/licenses/by-sa/3.0/> + +- open-share + + (C) Open Share Icon Project. All rights reserved. + <http://www.openshareicons.com/> + + Open Share icon is licensed under a Creative Commons + Attribution-Share Alike 3.0 License. + <http://creativecommons.org/licenses/by-sa/3.0/> + +- opml + + (C) OPML Icon Project. All rights reserved. + <http://opmlicons.com/> + + OPML icon is licensed under a Creative Commons + Attribution-Share Alike 2.5 License. + <http://creativecommons.org/licenses/by-sa/2.5/> + +- share + + (C) Share Icon Project. All rights reserved. + <http://shareicons.com/> + + Share icon is licensed under a GPL or LGPL or BSD or + Creative Commons Attribution 2.5 License. + <http://opensource.org/licenses/gpl-license.php> + <http://opensource.org/licenses/lgpl-license.php> + <http://opensource.org/licenses/bsd-license.php> + <http://creativecommons.org/licenses/by/2.5/> + +- xfn + + (C) Wolfgang Bartelme. All rights reserved. + <http://www.bartelme.at/> + + XFN icon is licensed under a Creative Commons + Attribution-Share Alike 2.5 License. + <http://creativecommons.org/licenses/by-sa/2.5/> \ No newline at end of file Deleted: trunk/src/main/resources/icons/accept.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/add.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/arrow_undo.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/building.png =================================================================== --- trunk/src/main/resources/icons/building.png 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/resources/icons/building.png 2015-06-11 09:01:47 UTC (rev 4263) @@ -1,15 +0,0 @@ -�PNG - - -IHDR�� -sRGB���bKGD������� pHYs��tIME� :1�5���IDAT8�͔�O\U����}�����TB�4�1i�5�BYY�ݴ��.��ڤK��U�n����bB��Blb��eTQk)�a����7������I���.�Y|�NιG�p�S144����eK)��ڦ�������!���dll\�������{�\fԶ�������-�7�������Ե�+�W�|����� -|�ۆR -) -�@��F���'�����瓓�}?3s� �Ν����s�d2���XV�i� @��r]�8N��l6�>��Q����&}}��T�T�"�"�� �5�Z��u�bq -}���}r��F��ZXV�@JI,f<)徙�4��B����S)$phP���>=�j.==lۢ��ƶc@�5B�a�i���x�rY��$��bq�ry�ioOR�Ԑ��4��g���4̓�Vs �à:;�c��r*����_;;::�d���/���A:�F,f��8N�� -�<|��-��Q*=? -l���aQ,�q�:�m���[[[loo��&�͒Nw`�6�z�j�%�ω��a1?��a�g30pl[��L�1�֚(��:$�cY1����)��tww�ܺu�y��q��t�����Ҡ�5N[[) -� Q�u66*XV���b�J��H$Doo���[�Pȱ�����h� C -DX��R{��Z���*�e��|�*�������)N�x#�V}</ #|?`}}�R��֚B!O6��4M���bp���ƍe��pw7���ˏ.]��2�H�b��.�FDH��>Bg���vwb�˟WW�M-K@�+m�[K -}�Z��VkA��{��O������=*g���o�߾}s��������,{��ٱw�c���Hon:JkMww�N$������{S��je� -x)��9`P)H�� !� ���σ�_0/�2���������JHfmIEND�B`� \ No newline at end of file Deleted: trunk/src/main/resources/icons/building_add.png =================================================================== --- trunk/src/main/resources/icons/building_add.png 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/main/resources/icons/building_add.png 2015-06-11 09:01:47 UTC (rev 4263) @@ -1,14 +0,0 @@ -�PNG - - -IHDR�� -sRGB���bKGD������� pHYs��tIME� -2����IDAT8˵�MLcU��s��mo������Ď,2����H��ְ���Y`\3ꚨvƍ��И �h!�)VK[~�{{齧����L���&��;�˓s��ZZZb�d2 -BDZ��revvV�)"O6+++Z2�|3����)�(�,۶w���w�b �����[�@��P(�*���a��`���e�?<<�˿wvv�J��P�&!��ח<�S�inZ�55::���=�\.7������ "�)�Js[[[�f����b�أ����c�1pΡi�u]! ���B����L&C�K@˲���c��b����u�����8�V���j�����ڥ�SS��ǰm��C�u�|��b�]�;�A�|����`�=�J`>������B�4 -�<���^J�#�c��W��{�^�w�JSJ�8����`�RHy�cJ)�� }�ނa�X���?������q����x<�T*���Ct:ض -J)���J�f ׇP�����f���M&''����z��9�h6��������: -�Tq��AG5��3�y�bENY2�$�R�r9^��.��zu?��È(����0��2��p=Լ{g0~�P��B��0J)����b}}�T -���h�P(�����^A"ꇏyИ�I��F&�)Ӱ����5-!��������y`�A)�V������w��ב��' �:. -J���gB�^�H,C8��Ͽ��f�UJ -(��9�m�h�6��f�D.��k���;{�a���gu��Mq�S�;.�N��j5�j������Lfefff�1v���$utt��4 -���N$)Պ���?7z��{��r4��O��k��uqVo���w��uw?���O$�T�ՊB�i����<==M��ɤA�@`�4�۔҇��G\�gT:��1�"�)������6��ʗ�u���|�����l�A9��IEND�B`� \ No newline at end of file Deleted: trunk/src/main/resources/icons/camera.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/cancel.png =================================================================== (Binary files differ) Added: trunk/src/main/resources/icons/common/exclamation.png =================================================================== (Binary files differ) Property changes on: trunk/src/main/resources/icons/common/exclamation.png ___________________________________________________________________ Added: svn:mime-type + image/png Deleted: trunk/src/main/resources/icons/connect.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/cut.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_add.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_connect.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_delete.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_edit.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_error.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_gear.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_go.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_key.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_lightning.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_link.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_refresh.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_save.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/database_table.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/delete.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/page_copy.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/page_paste.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/page_white_compressed.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/paintbrush.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/resultset_next.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/resultset_previous.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_add.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_code.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_code_red.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_delete.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_edit.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_error.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_gear.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_go.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_key.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_lightning.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_link.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_palette.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/script_save.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/table.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/table_multiple.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/tick.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/wrench.png =================================================================== (Binary files differ) Deleted: trunk/src/main/resources/icons/wrench_orange.png =================================================================== (Binary files differ) Modified: trunk/src/test/java/fr/ifremer/isisfish/equation/EquationTest.java =================================================================== --- trunk/src/test/java/fr/ifremer/isisfish/equation/EquationTest.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/test/java/fr/ifremer/isisfish/equation/EquationTest.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -24,14 +24,12 @@ */ package fr.ifremer.isisfish.equation; -import fr.ifremer.isisfish.AbstractIsisFishTest; -import fr.ifremer.isisfish.util.Args; -import fr.ifremer.isisfish.util.EvaluatorHelper; -import java.util.Arrays; -import org.apache.commons.lang3.reflect.MethodUtils; import org.junit.Assert; import org.junit.Test; +import fr.ifremer.isisfish.AbstractIsisFishTest; +import fr.ifremer.isisfish.util.EvaluatorHelper; + /** * Equation related tests. * Modified: trunk/src/test/java/fr/ifremer/isisfish/ui/input/InputIT.java =================================================================== --- trunk/src/test/java/fr/ifremer/isisfish/ui/input/InputIT.java 2015-06-11 08:39:17 UTC (rev 4262) +++ trunk/src/test/java/fr/ifremer/isisfish/ui/input/InputIT.java 2015-06-11 09:01:47 UTC (rev 4263) @@ -27,7 +27,6 @@ import java.io.File; import java.io.IOException; -import org.apache.commons.lang3.SystemUtils; import org.assertj.swing.core.matcher.JButtonMatcher; import org.junit.Assert; import org.junit.Before;
participants (1)
-
echatellier@users.forge.codelutin.com