From sletellier@users.labs.libre-entreprise.org Mon Jun 15 00:25:42 2026
From: sletellier@users.labs.libre-entreprise.org
To: isis-fish-commits@list.isis-fish.org
Subject: [Isis-fish-commits] r1548 -
	isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator
Date: Mon, 13 Oct 2008 13:42:24 +0200
Message-ID: <20081013114224.6C88D461B4E@labs.libre-entreprise.org>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============2706699165704455260=="

--===============2706699165704455260==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Author: sletellier
Date: 2008-10-13 11:42:24 +0000 (Mon, 13 Oct 2008)
New Revision: 1548

Modified:
   isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulAction=
.java
Log:
Simulation work

Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/Simu=
lAction.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulActio=
n.java	2008-10-10 16:13:12 UTC (rev 1547)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulActio=
n.java	2008-10-13 11:42:24 UTC (rev 1548)
@@ -40,11 +40,13 @@
  */
 package fr.ifremer.isisfish.ui.simulator;
=20
+import fr.ifremer.isisfish.datastore.StorageException;
 import static org.codelutin.i18n.I18nf._;
 import fr.ifremer.isisfish.IsisFish;
 import fr.ifremer.isisfish.IsisFishException;
 import fr.ifremer.isisfish.datastore.RegionStorage;
 import fr.ifremer.isisfish.datastore.RuleStorage;
+import fr.ifremer.isisfish.datastore.ScriptStorage;
 import fr.ifremer.isisfish.datastore.SimulationStorage;
 import fr.ifremer.isisfish.datastore.SimulatorStorage;
 import fr.ifremer.isisfish.entities.Population;
@@ -56,6 +58,7 @@
 import fr.ifremer.isisfish.simulator.launcher.SimulationJob;
 import fr.ifremer.isisfish.simulator.launcher.SimulationService;
 import fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher;
+import java.lang.reflect.Field;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -66,6 +69,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.codelutin.log.UserLog;
+import org.codelutin.topia.TopiaContext;
=20
 public class SimulAction {
    =20
@@ -80,7 +84,86 @@
     static private SimpleDateFormat dateFormat =3D new SimpleDateFormat("yyy=
y-MM-dd-HH-mm");
     public SimulAction(){
         param =3D new SimulationParameter();
+
+            // TODO refresh data context on all this when datas coming from =
script module
+            // when a modification is done in script dialog
+            // =3D> then refresh whoses data
+            // and the associated ui
+            // compute result names available
+            List<String> resultNames =3D getResultNames();
+//            uiContext.setData("ResultNames", resultNames);
+//            uiContext.setData("ExportNames", ExportStorage.getExportNames(=
));
+//            uiContext.setData("AnalysePlanNames", AnalysePlanStorage.getAn=
alysePlanNames());
+//            uiContext.setData("RuleNames", RuleStorage.getRuleNames());
+
+            // put default value in param
+            param.setSimulatorName(IsisFish.config.getSimulatorClassfile());
+            param.setTagValue(IsisFish.config.getDefaultTagValueAsMap());
+            param.setExportDirectory(IsisFish.config.getDefaultExportDirecto=
ry().toString());
+            param.setExportNames(IsisFish.config.getDefaultExportNamesAsList=
());
+            List<String> defaultResultNames =3D IsisFish.config.getDefaultRe=
sultNamesAsList();
+            if (defaultResultNames !=3D null)
+                param.setResultEnabled(defaultResultNames);
+            else
+                param.setResultEnabled(resultNames);
+//
+//            uiContext.setData("OldSimulationName", "");
+//            uiContext.setData("SimulationParameter", param);
+//
+//            // keep in context list of old simulation names (for filter pr=
ocess)
+//            List<String> value =3D getSimulationNames();
+//            // create filter model
+//            FilterModel<SimulationProperties, String> model =3D
+//                    SimulationFilterUtil.createFilterModel(value);
+//            // to used directly model.getFilteredResult() in xml
+//            // we must fill filterModel result with original items
+//            model.selectAll();
+//            uiContext.setData("SimulationFilterModel", model);
+//
+//            tabs.setEnabledAt(1, false); // disable prescript tab
+//            tabs.setEnabledAt(2, false); // disable analyse plan tab
+//
+////            // add simulation queue button listeners
+////            SimulatorListeners.initSimulQueueButtonsListener(
+////                    start,
+////                    remove,
+////                    showLog,
+////                    table,
+////                    tableDone
+////            );
+//            // add rule around button listeners
+//            SimulatorListeners.initButtonRemoveIfItemSelected(removeRule, =
listRule);
+//           =20
+//            // add analyse plan around button listeners
+//            SimulatorListeners.initButtonRemoveIfItemSelected(removeAnalys=
ePlan, listAnalysePlan);
+//
+//            frame.refreshView();
+       =20
     }
+
+    /**
+     * 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 =3D new ArrayList<String>();
+        try {
+            ScriptStorage storage =3D ScriptStorage.getScript("ResultName.ja=
va");
+            Class resultNameClass =3D storage.getCodeClass();
+            // TODO: if we can't find class, perhaps try to parser Java sour=
ce ?
+            Field[] fields =3D resultNameClass.getFields();
+            for (Field f : fields) {
+                String fieldName =3D (String) f.get(null);
+                result.add(fieldName);
+            }
+        } catch (Exception eee) {
+            if (log.isWarnEnabled()) {
+                log.warn("Can't find result name script", eee);
+            }
+        }
+        return result;
+    }
    =20
     protected void stopSimulation(SimulationJob job) {
         job.stop();
@@ -206,21 +289,26 @@
     }
     public List<Strategy> getStrategies(){
         List<Strategy> result =3D new ArrayList<Strategy>();
-        result =3D param.getStrategies();
+        try {
+            result =3D regionStorage.getFisheryRegion(param.getRegion().getS=
torage()).getStrategy();
+        } catch (StorageException ex) {
+            Logger.getLogger(SimulAction.class.getName()).log(Level.SEVERE, =
null, ex);
+        }
+//         result =3D param.getStrategies();
         return result;
     }
     public List<Population> getPopulations(){
         List<Species> species;
         List<Population> result =3D new ArrayList<Population>();
         try {
-//            species =3D simulStorage.getFisheryRegion(simulStorage.getStor=
age()).getSpecies();
-//            for (Species s : species){
-//                result.addAll(s.getPopulation());
-//            }
+            species =3D regionStorage.getFisheryRegion(param.getRegion().get=
Storage()).getSpecies();
+            for (Species s : species){
+                result.addAll(s.getPopulation());
+            }
         } catch (Exception ex) {
             Logger.getLogger(SimulAction.class.getName()).log(Level.SEVERE, =
null, ex);
         }
-        result =3D param.getPopulations();
+//        result =3D param.getPopulations();
         return result;
     }
     public void setNbAnnees(String years){


--===============2706699165704455260==--


