r1570 - in isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui: script simulator widget/editor
Author: sletellier Date: 2008-10-23 13:02:40 +0000 (Thu, 23 Oct 2008) New Revision: 1570 Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/GenericCell.java Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SensUI.jaxx isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterColumnEditor.java Log: ScriptUI completed Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java 2008-10-23 13:02:01 UTC (rev 1569) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java 2008-10-23 13:02:40 UTC (rev 1570) @@ -9,16 +9,47 @@ * * @author letellier */ +import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.datastore.AnalysePlanStorage; +import fr.ifremer.isisfish.datastore.CodeSourceStorage; import fr.ifremer.isisfish.datastore.ExportStorage; import fr.ifremer.isisfish.datastore.FormuleStorage; +import fr.ifremer.isisfish.datastore.JavaSourceStorage; import fr.ifremer.isisfish.datastore.RuleStorage; import fr.ifremer.isisfish.datastore.ScriptStorage; -import fr.ifremer.isisfish.datastore.SimulationStorage; -import fr.ifremer.isisfish.ui.script.Action.ScriptMapping; +import fr.ifremer.isisfish.datastore.SimulatorStorage; +import fr.ifremer.isisfish.ui.ScriptActionHelper; +import fr.ifremer.isisfish.ui.script.Action.ScriptFileFilter; +import fr.ifremer.isisfish.ui.widget.editor.GenericCell; +import fr.ifremer.isisfish.vcs.VCSException; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import static org.codelutin.i18n.I18nf._; import java.io.File; +import java.io.FileFilter; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.io.PrintStream; +import java.lang.reflect.Method; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Date; import java.util.List; +import javax.swing.JOptionPane; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreePath; +import org.apache.commons.logging.Log; +import org.codelutin.util.FileUtil; +import static org.apache.commons.logging.LogFactory.getLog; +import static fr.ifremer.isisfish.equation.Language.JAVA; + public class ScriptAction { + CodeSourceStorage code; + /** to use log facility, just put in your code: log.info(\"...\"); */ + static private Log log = getLog(ScriptAction.class); + File fileOpen= null; public ScriptAction(){ } @@ -34,8 +65,8 @@ public List<String> getScriptNames(){ return ScriptStorage.getScriptNames(); } - public List<String> getSimulationNames(){ - return SimulationStorage.getSimulationNames(); + public List<String> getSimulatorNames(){ + return SimulatorStorage.getSimulatorNames(); } public List<String> getExportNames(){ return ExportStorage.getExportNames(); @@ -55,8 +86,8 @@ public File getScriptDirectory(){ return ScriptStorage.getScriptDirectory(); } - public File getSimulationDirectory(){ - return SimulationStorage.getSimulationDirectory(); + public File getSimulatorDirectory(){ + return SimulatorStorage.getSimulatorDirectory(); } public File getExportDirectory(){ return ExportStorage.getExportDirectory(); @@ -70,4 +101,779 @@ public File getFormuleDirectory(){ return FormuleStorage.getFormuleDirectory(); } + /* + * JButton Action + */ + /** + * Creer un nouveau script, ici un script peut-etre un Script, un Simulator, + * un Export. + * + * @param uiContext TODO + * @param frame TODO + * @param scriptType le type que l'on souhaite Script, Simulator, + * ou Export. + * @param jmodel TODO + * @param tree TODO + * @return TODO + */ + public Object newScript(String fileName, String scriptType) { +// log.info("newScript called [" + scriptType + "] " + uiContext); + + Exception e; + try { + // Vérifie qu'il n'y pas de caractères spéciaux. Seul les caractre + // de a à z (majuscule ou minuscule) ainsi que les nombres sont + // autorisés. + pour signifier qu'il doit y avoir + // au moins 1 caractère. + String realFilename; + String category; + ScriptMapping mapping = ScriptMapping.valueOf(scriptType); + if (mapping == null) { + e = new RuntimeException("ScriptType unknown: " + scriptType); + return returnError(_("isisfish.error.script.create",fileName, e.getMessage()),e); + } + + int pos = fileName.lastIndexOf('/'); + if (pos != -1) { + if (mapping!= ScriptMapping.EquationModel) { + // interdit pour le moment ? + String message = _("isisfish.error.invalid.file.name", fileName); + e = new RuntimeException(message); + return returnError(_("isisfish.error.script.create",fileName, e.getMessage()),e); + } + // il y a un sous type à traiter + if (pos == fileName.length() - 1) { + String message = _("isisfish.error.invalid.file.name", fileName); + e = new RuntimeException(message); + return returnError(_("isisfish.error.script.create",fileName, e.getMessage()),e); + } + realFilename = fileName.substring(fileName.lastIndexOf('/') + 1); + category = fileName.substring(0, fileName.lastIndexOf('/')); + } else { + realFilename = fileName; + category = ""; + } + if (!realFilename.matches("[A-Z0-9_][a-zA-Z0-9_]*")) { + String message = _("isisfish.error.invalid.file.name", fileName); + e = new RuntimeException(message); + return returnError(_("isisfish.error.script.create",fileName, e.getMessage()),e); + } + //TODO do test on category + CodeSourceStorage script = null; + String template; + template = mapping.getDefaultContent(); + switch (mapping) { + case EquationModel: +// if (!category.isEmpty()) { +// // on utilise la category passée dans le nom +// parentNode = (TreeNodeWrapper) jmodel.getNode(category); +// if (parentNode == null) { +// parentNode = (TreeNodeWrapper) jmodel.getNode(scriptType); +// JTreeNode jparentNode = parentNode.getWrapped(); +// JTreeNode jnode = (JTreeNode) jparentNode.getComponent(0); +// jnode.setName(category); +// parentNode.addNode(jnode, category); +// parentNode = (TreeNodeWrapper) jmodel.getNode(category); +// UIHelper.setTreeSelection(tree, jmodel, category); +// } +// } else { +// // on utilise la category dans la navigation +// TreePath path = tree.getSelectionPath(); +// if (path.getPath().length < 2) { +// // fatal error no category found, and was required +// String message = _("isisfish.error.invalid.category.name", fileName); +// e = new RuntimeException(message); +// return returnError(_("isisfish.error.script.create", fileName, e.getMessage()), e); +// } +// TreeNodeWrapper categotyNode = (TreeNodeWrapper) path.getPathComponent(2); +// parentNode = categotyNode; +// category = String.valueOf(categotyNode.getUserObject()); +// } + + script = FormuleStorage.createFormule(category, realFilename, JAVA); + break; + case AnalysePlan: + script = AnalysePlanStorage.getAnalysePlan(fileName); + break; + case Export: + script = ExportStorage.getExport(fileName); + break; + case Rule: + script = RuleStorage.getRule(fileName); + break; + case Script: + script = ScriptStorage.getScript(fileName); + break; + case Simulator: + script = SimulatorStorage.getSimulator(fileName); + break; + default: + log.fatal("ScriptType unknown: " + scriptType); + } + + if (script.exists()) { + // Message d'erreur si le fichier existe en local. + String message = _("isisfish.error.file.already.exists", fileName); + e = new RuntimeException(message); + return returnError(_("isisfish.error.script.create",fileName, e.getMessage()),e); + } + + // add default script content + String content = MessageFormat.format(template, + category.isEmpty() ? "" : '.' + category.replaceAll("\\/", "."), + realFilename, + new Date(), + IsisFish.config.getUserName(), + IsisFish.config.getUserMail()); + script.setContent(content); + // ajout du nouveau script dans l'arbre +// if (parentNode == null) { +// parentNode = (TreeNodeWrapper) jmodel.getNode(scriptType); +// } +// if (parentNode != null) { +// JTreeNode jparentNode = parentNode.getWrapped(); +// JTreeNode jnode = (JTreeNode) jparentNode.getComponent(0); +// parentNode.addNode(jnode, script.getName()); +// } +// // selection du nouveau noeud, ce qui appel la methode load +// UIHelper.setTreeSelection(tree, jmodel, script.getName()); + +// uiContext.setData(SCRIPT_STORAGE, script); + code = script; +// uiContext.setData(SCRIPT_TYPE, scriptType); +// frame.refreshView("scriptJedit"); +// frame.refreshView("buttonBar"); +// frame.refreshView("scriptMenuBar"); + } catch (Exception eee) { + return returnError(_("isisfish.error.script.create",fileName, eee.getMessage()),eee); + } + return null; + + } + public static Object returnError(String s, Exception eee) { + log.error(s,eee); +// return new OutputView("Error.xml", "error", s); + return null; + } + public void loadScript(GenericCell c, String fileName, String type){ + ScriptMapping mapping = ScriptMapping.valueOf(type); + CodeSourceStorage script = null; + + try { + + switch (mapping) { + case EquationModel: + script = FormuleStorage.getFormule((String)c.getValue(), fileName); + break; + case Rule: + script = RuleStorage.getRule(fileName); + break; + case AnalysePlan: + script = AnalysePlanStorage.getAnalysePlan(fileName); + break; + case Export: + script = ExportStorage.getExport(fileName); + break; + case Script: + script = ScriptStorage.getScript(fileName); + break; + case Simulator: + script = SimulatorStorage.getSimulator(fileName); + break; + default: + log.fatal("ScriptType unknown: " + fileName); + } + + //frame.setInfoText(_("isisfish.message.load.finished")); + } finally { + code = script; + } + } + public boolean fileLoaded(){ + return code != null; + } + public boolean isJavaScript(){ + return JavaSourceStorage.class.isInstance(code); + } + public Object saveScript(String content) { + log.info("saveScript called [" + code.getName() + "] "); + try { + code.setContent(content); + } catch (Exception eee) { + return returnError(_("isisfish.error.script.save", code.getFile(), eee.getMessage()),eee); + } + return null; + } + public String commitScript(String content) { + String result = null; + try { + log.debug("commitScript called for "); + // save script before commit + code.setContent(content); + String msg = JOptionPane.showInputDialog(_("Indiquez vos modifications")); +// String msg = VCSUIHelper.getCommitMessage(script.getFile(), true); + if (msg == null) { + result = _("isisfish.message.commit.cancelled"); + } else { + code.commit(msg); + code.reload(); + result = _("isisfish.message.commit.finished"); + } + return null; + } catch (Exception ex) { + Logger.getLogger(ScriptAction.class.getName()).log(Level.SEVERE, null, ex); + } + return result; + } + /** + * Exporte le(s) script(s) sélectionnés dans l'arbe. + * <br>L'arbre doit avoir au moins un script de selectionne + * + * @param uiContext swixat context + * @param frame swiaxt frame + * @param tree tree contaings script + * @return <code>null</code> if everything is ok, + * an <code>OutputVie<</code> with an error to display otherwise + */ + public static String exportScript(TreePath[] selectedPaths) { + String message = null; + // first step : acquire list of files required + int prefixLength = IsisFish.config.getDatabaseDirectory().getAbsolutePath().length() + 1; + List<String> listFiles = extractFiles(prefixLength, selectedPaths); + +// try { +// boolean fired = ScriptActionHelper.exportScript(null, listFiles, false, true, frame); +// if (!fired) { +// message = _("isisfish.message.export.cancelled"); +// } else { +// message = _("isisfish.message.export.done"); +// } +// } catch (Exception eee) { +// } + return message; + } + protected static List<String> extractFiles(int prefixLength,TreePath[] selectedPaths) { + List<String> result = new ArrayList<String>(); + List<File> dirFound = new ArrayList<File>(); + List<File> dirWithFileFound = new ArrayList<File>(); + + for (TreePath selectedPath : selectedPaths) { + + DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedPath.getPathComponent(1); + String moduleDisplayName = String.valueOf(node.getUserObject()); + File file = ScriptMapping.valueOf(moduleDisplayName).getModule(); + int nbPaths = selectedPath.getPathCount(); + if (nbPaths > 2) + for (int i = 2; i < nbPaths; i++) { + node = (DefaultMutableTreeNode) selectedPath.getPathComponent(i); + String pathName = String.valueOf(node.getUserObject()); + file = new File(file, pathName); + } + if (file.isFile()) { + File parentFile = file.getParentFile(); + if (!dirFound.contains(parentFile)) dirFound.add(parentFile); + dirWithFileFound.add(parentFile); + result.add(file.getAbsolutePath().substring(prefixLength)); + } else { + // mark the file + dirFound.add(file); + } + } + + // keep only user selected directories + dirFound.removeAll(dirWithFileFound); + dirWithFileFound.clear(); + + if (!dirFound.isEmpty()) { + List<File> listF = new ArrayList<File>(); + // there is some directories selected by user + for (File dir : dirFound) { + // take all files and directories in the dir + // (without VCS and data dirs) +// SVNMigrateHelper.grabbFiles(dir, excludeFilter, listF); + + + // getFilteredElements use include file filter, we inverse excludeFilter + FileFilter filter = new FileFilter() { + FileFilter excludeFilter = getSCRIPT_FILE_FILTER(); + public boolean accept(File pathname) { + return !excludeFilter.accept(pathname); + } + }; + listF.addAll(FileUtil.getFilteredElements(dir, filter, true)); + } + for (File file : listF) + result.add(file.getAbsolutePath().substring(prefixLength)); + listF.clear(); + } + dirFound.clear(); + return result; + } + + public static FileFilter SCRIPT_FILE_FILTER; + public static FileFilter getSCRIPT_FILE_FILTER() { + if (SCRIPT_FILE_FILTER == null) { + SCRIPT_FILE_FILTER = new ScriptFileFilter(IsisFish.vcs); + } + return SCRIPT_FILE_FILTER; + } + //public static Object updateScript() + public void updateScript() { + try { + log.debug("updateScript called for "); + //TODO Use VCS UI dialog + //TODO Use FileState new mecanism to obtain state + code.update(); + code.reload(); + } catch (VCSException ex) { + Logger.getLogger(ScriptAction.class.getName()).log(Level.SEVERE, null, ex); + } + } + public String checkScript(String content) { + String resultLog = ""; + try { + log.debug("checkScript called"); + // save script before commit + code.setContent(content); + JavaSourceStorage javaCode = (JavaSourceStorage)code; + StringWriter result = new StringWriter(); + PrintWriter out = new PrintWriter(result); + int compileResult = 0; + Exception e = null; + try { + compileResult = javaCode.compile(false, out); + } catch (Exception eee) { + compileResult = -1; + e=eee; + } + if (compileResult != 0) { + out.flush(); + resultLog = result.toString(); + if (e == null) { + e = new RuntimeException("there is some problem in script"); + } + } + else{ + resultLog = "ok"; + } + } catch (IOException ex) { + Logger.getLogger(ScriptAction.class.getName()).log(Level.SEVERE, null, ex); + } + return resultLog; + } + public String evaluateScript(String content) { + log.debug("evaluateScript called"); + String msg = ""; + try { + String checkResult = checkScript(content); + if (checkResult != null) { + return checkResult; + } + code.setContent(content); + JavaSourceStorage javaCode = (JavaSourceStorage) code; + ByteArrayOutputStream result = new ByteArrayOutputStream(); + PrintStream out = new PrintStream(result); + PrintStream err = new PrintStream(result); + PrintStream oldOut = System.out; + PrintStream oldErr = System.err; + System.setOut(out); + System.setErr(err); + Class clazz = javaCode.getCodeClass(); + Method main = clazz.getMethod("main", String[].class); + //noinspection RedundantArrayCreation + main.invoke(null, new Object[]{new String[]{}}); + System.setOut(oldOut); + System.setErr(oldErr); + msg = result.toString(); + } catch (Exception ex) { + Logger.getLogger(ScriptAction.class.getName()).log(Level.SEVERE, null, ex); + } + return msg; + } + /** enum to encapsulate a script module */ + enum ScriptMapping { + + Script(ScriptStorage.getScriptDirectory(), + /** + * 0 = package name, + * 1 = class name, + * 2 = current date, + * 3 = author name, + * 4 = author email + */ + "package scripts{0};\n" + + "\n" + + "import org.apache.commons.logging.Log;\n" + + "import org.apache.commons.logging.LogFactory;\n" + + "\n" + + "import fr.ifremer.isisfish.util.Doc;\n" + + "\n" + + "import org.codelutin.math.matrix.*;\n" + + "\n" + + "import fr.ifremer.isisfish.entities.*;\n" + + "\n" + + "/**\n" + + " * {0}.{1}.java\n" + + " *\n" + + " * Created: {2,date, long}\n" + + " *\n" + + " * @author {3} <{4}>\n" + + //" * @version $Revision: 1545 $\n" + + " *\n" + + //" * Last update: $Date: 2008-10-08 16:13:44 +0200 (mer 08 oct 2008) $\n" + + //" * by : $Author: sletellier $\n" + + " */\n" + + "public class {1} '{'\n" + + "\n" + + " /** to use log facility, just put in your code: log.info(\"...\"); */\n" + + " static private Log log = LogFactory.getLog({1}.class);\n" + + "\n" + + " // add your method here\n" + + "'}'\n"), + + Simulator(SimulatorStorage.getSimulatorDirectory(), + /** + * 0 = package name, + * 1 = class name, + * 2 = current date, + * 3 = author name, + * 4 = author email + */ + "package simulators{0};\n" + + "\n" + + "import org.apache.commons.logging.Log;\n" + + "import org.apache.commons.logging.LogFactory;\n" + + "\n" + + "import org.codelutin.math.matrix.*;\n" + + "\n" + + "import fr.ifremer.isisfish.util.Doc;\n" + + "import fr.ifremer.isisfish.entities.*;\n" + + "import fr.ifremer.isisfish.simulator.Simulator;\n" + + "import fr.ifremer.isisfish.simulator.SimulationContext;\n" + + "\n" + + "/**\n" + + " * {1}.java\n" + + " *\n" + + " * Created: {2,date, long}\n" + + " *\n" + + " * @author {3} <{4}>\n" + + //" * @version $Revision: 1545 $\n" + + " *\n" + + //" * Last update$\n" + + //" * by : $Author: sletellier $\n" + + " */\n" + + "public class {1} implements Simulator '{'\n" + + "\n" + + " /** to use log facility, just put in your code: log.info(\"...\"); */\n" + + " static private Log log = LogFactory.getLog({1}.class);\n" + + "\n" + + " public void simulate(SimulationContext context) throws Exception '{'\n" + + " // put your code here\n" + + " '}'\n" + + "\n" + + "'}'\n"), + Export(ExportStorage.getExportDirectory(), + /** + * 0 = package name, + * 1 = class name, + * 2 = current date, + * 3 = author name, + * 4 = author email + */ + "package exports{0};\n" + + "\n" + + "import org.apache.commons.logging.Log;\n" + + "import org.apache.commons.logging.LogFactory;\n" + + "\n" + + "import java.io.Writer;\n" + + "\n" + + + "import static org.codelutin.i18n.I18nf._;\n" + + "import org.codelutin.math.matrix.*;\n" + + "\n" + + "import fr.ifremer.isisfish.util.Doc;\n" + + "import fr.ifremer.isisfish.entities.*;\n" + + "import fr.ifremer.isisfish.export.Export;\n" + + "import fr.ifremer.isisfish.datastore.SimulationStorage;\n" + + "import fr.ifremer.isisfish.datastore.ResultStorage;\n" + + "\n" + + "/**\n" + + " * {1}.java\n" + + " *\n" + + " * Created: {2,date, long}\n" + + " *\n" + + " * @author {3} <{4}>\n" + + //" * @version $Revision: 1545 $\n" + + " *\n" + + //" * Last update: $Date: 2008-10-08 16:13:44 +0200 (mer 08 oct 2008) $\n" + + //" * by : $Author: sletellier $\n" + + " */\n" + + "public class {1} implements Export '{'\n" + + "\n" + + " /** to use log facility, just put in your code: log.info(\"...\"); */\n" + + " static private Log log = LogFactory.getLog({1}.class);\n" + + "\n" + + " public String [] necessaryResult = '{'\n" + + " // put here all necessary result for this rule\n" + + " // example: \n" + + " // ResultName.MATRIX_BIOMASS,\n" + + " // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,\n" + + " '}';\n" + + "\n" + + " public String[] getNecessaryResult() '{'\n" + + " return this.necessaryResult;\n" + + " '}'\n" + + "\n" + + " public String getExportFilename() '{'\n" + + " // remove _(...) if you don''t want translation on filename" + + " return _(\"{0}\");\n" + + " '}'\n" + + "\n" + + " public String getExtensionFilename() '{'\n" + + " return \".csv\";\n" + + " '}'\n" + + "\n" + + " public String getDescription() '{'\n" + + " return _(\"TODO export description\");\n" + + " '}'\n" + + "\n" + + " public void export(SimulationStorage simulation, Writer out) throws Exception '{'\n" + + " // put your code here, and write export with: out.write(\"...\")\n" + + " '}'\n" + + "\n" + + "'}'\n"), + Rule(RuleStorage.getRuleDirectory(), + /** + * 0 = package name, + * 1 = class name, + * 2 = current date, + * 3 = author name, + * 4 = author email, + * 5 = region name + */ + "package rules{0};\n" + + "\n" + + "import static org.codelutin.i18n.I18nf._;\n" + + "\n" + + "import org.apache.commons.logging.Log;\n" + + "import org.apache.commons.logging.LogFactory;\n" + + "\n" + + "import scripts.ResultName;\n" + + "\n" + + "import java.io.Writer;\n" + + "\n" + + "import org.codelutin.math.matrix.*;\n" + + "\n" + + "import fr.ifremer.isisfish.util.Doc;\n" + + "import fr.ifremer.isisfish.simulator.SimulationContext;\n" + + "import fr.ifremer.isisfish.types.Date;\n" + + "import fr.ifremer.isisfish.entities.*;\n" + + "import fr.ifremer.isisfish.rule.AbstractRule;\n" + + "import fr.ifremer.isisfish.datastore.SimulationStorage;\n" + + "import fr.ifremer.isisfish.datastore.ResultStorage;\n" + + "\n" + + "/**\n" + + " * {1}.java\n" + + " *\n" + + " * Created: {2,date, long}\n" + + " *\n" + + " * @author {3} <{4}>\n" + + //" * @version $Revision: 1545 $\n" + + " *\n" + + //" * Last update: $Date: 2008-10-08 16:13:44 +0200 (mer 08 oct 2008) $\n" + + //" * by : $Author: sletellier $\n" + + " */\n" + + "public class {1} extends AbstractRule '{'\n" + + "\n" + + " /** to use log facility, just put in your code: log.info(\"...\"); */\n" + + " static private Log log = LogFactory.getLog({1}.class);\n" + + "\n" + + " public String [] necessaryResult = '{'\n" + + " // put here all necessary result for this rule\n" + + " // example: \n" + + " // ResultName.MATRIX_BIOMASS,\n" + + " // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,\n" + + " '}';\n" + + "\n" + + " public String[] getNecessaryResult() '{'\n" + + " return this.necessaryResult;\n" + + " '}'\n" + + "\n" + + " /**\n" + + " * Permet d''afficher a l''utilisateur une aide sur la regle.\n" + + " * @return L''aide ou la description de la regle\n" + + " */\n" + + " public String getDescription() throws Exception '{'\n" + + " // TODO\n" + + " return _(\"TODO description rule\");\n" + + " '}'\n" + + " \n" + + " /**\n" + + " * Appelé au démarrage de la simulation, cette méthode permet d''initialiser\n" + + " * des valeurs\n" + + " * @param simulation La simulation pour lequel on utilise cette regle\n" + + " */\n" + + " public void init(SimulationContext context) throws Exception '{'\n" + + " // TODO\n" + + " '}'\n" + + " /**\n" + + " * La condition qui doit etre vrai pour faire les actions\n" + + " * @param simulation La simulation pour lequel on utilise cette regle\n" + + " * @return vrai si on souhaite que les actions soit faites\n" + + " */\n" + + " public boolean condition(SimulationContext context, Date date, Metier metier) throws Exception '{'\n" + + " // TODO\n" + + " return false;\n" + + " '}'\n" + + " \n" + + " /**\n" + + " * Si la condition est vrai alors cette action est executée avant le pas\n" + + " * de temps de la simulation.\n" + + " * @param simulation La simulation pour lequel on utilise cette regle\n" + + " */\n" + + " public void preAction(SimulationContext context, Date date, Metier metier) throws Exception '{'\n" + + " // TODO\n" + + " '}'\n" + + " \n" + + " /**\n" + + " * Si la condition est vrai alors cette action est executée apres le pas\n" + + " * de temps de la simulation.\n" + + " * @param simulation La simulation pour lequel on utilise cette regle\n" + + " */\n" + + " public void postAction(SimulationContext context, Date date, Metier metier) throws Exception '{'\n" + + " // TODO\n" + + " '}'\n" + + "\n" + + "'}'\n"), + AnalysePlan(AnalysePlanStorage.getAnalysePlanDirectory(), + /** + * 0 = package name, + * 1 = class name, + * 2 = current date, + * 3 = author name, + * 4 = author email, + * 5 = region name + */ + "package analyseplans{0};\n" + + "\n" + + "import static org.codelutin.i18n.I18nf._;\n" + + "\n" + + "import org.apache.commons.logging.Log;\n" + + "import org.apache.commons.logging.LogFactory;\n" + + "\n" + + "import scripts.ResultName;\n" + + "\n" + + "import java.io.Writer;\n" + + "\n" + + "import org.codelutin.math.matrix.*;\n" + + "import org.codelutin.util.*;\n" + + "import org.codelutin.topia.*;\n" + + "\n" + + "import fr.ifremer.isisfish.util.Doc;\n" + + "import fr.ifremer.isisfish.*;\n" + + "import fr.ifremer.isisfish.simulator.SimulationContext;\n" + + "import fr.ifremer.isisfish.types.Date;\n" + + "import fr.ifremer.isisfish.entities.*;\n" + + "import fr.ifremer.isisfish.simulator.AnalysePlan;\n" + + "import fr.ifremer.isisfish.simulator.AnalysePlanContext;\n" + + "import fr.ifremer.isisfish.simulator.SimulationParameter;\n" + + "import fr.ifremer.isisfish.datastore.SimulationStorage;\n" + + "import fr.ifremer.isisfish.datastore.ResultStorage;\n" + + "\n" + + "/**\n" + + " * {1}.java\n" + + " *\n" + + " * Created: {2,date, long}\n" + + " *\n" + + " * @author {3} <{4}>\n" + + //" * @version $Revision: 1545 $\n" + + " *\n" + + //" * Last update: $Date: 2008-10-08 16:13:44 +0200 (mer 08 oct 2008) $\n" + + //" * by : $Author: sletellier $\n" + + " */\n" + + "public class {1} implements AnalysePlan '{'\n" + + "\n" + + " /** to use log facility, just put in your code: log.info(\"...\"); */\n" + + " static private Log log = LogFactory.getLog({1}.class);\n" + + "\n" + + " public String [] necessaryResult = '{'\n" + + " // put here all necessary result for this rule\n" + + " // example: \n" + + " // ResultName.MATRIX_BIOMASS,\n" + + " // ResultName.MATRIX_NET_VALUE_OF_LANDINGS_PER_STRATEGY_MET,\n" + + " '}';\n" + + "\n" + + " public String[] getNecessaryResult() '{'\n" + + " return this.necessaryResult;\n" + + " '}'\n" + + "\n" + + " /**\n" + + " * Permet d''afficher a l''utilisateur une aide sur le plan.\n" + + " * @return L''aide ou la description du plan\n" + + " */\n" + + " public String getDescription() throws Exception '{'\n" + + " // TODO\n" + + " return _(\"TODO description plan\");\n" + + " '}'\n" + + " \n" + + " /**\n" + + " * Appelé au démarrage de la simulation, cette méthode permet d''initialiser\n" + + " * des valeurs\n" + + " * @param simulation La simulation pour lequel on utilise cette regle\n" + + " */\n" + + " public void init(AnalysePlanContext context) throws Exception '{'\n" + + " // TODO\n" + + " '}'\n" + + " \n" + + " /**\n" + + " * Call before each simulation\n" + + " * @param context plan context\n" + + " * @param nextSimulation storage used for next simulation\n" + + " * @return true if we must do next simulation, false to stop plan\n" + + " * @throws Exception\n" + + " */\n" + + " public boolean next(AnalysePlanContext context, SimulationStorage nextSimulation) throws Exception '{'\n" + + " return false; // TODO\n" + + " '}'\n" + + "\n" + + "'}'\n"), + EquationModel(FormuleStorage.getFormuleDirectory(), + /** + * 0 = package name, + * 1 = class name, + * 2 = current date, + * 3 = author name, + * 4 = author email + */ + "/**\n" + + " * {1}.java\n" + + " *\n" + + " * Created: {2,date, long}\n" + + " *\n" + + " * @author {3} <{4}>\n" + + //" * @version $Revision: 1545 $\n" + + " *\n" + + //" * Last update: $7 $\n" + + //" * by : $Author: sletellier $\n" + + //" */\n" + + "\n" + + "// put your code here\n" + + "\n"); + + private File module; + private String defaultContent; + + ScriptMapping(File module, String defaultContent) { + this.module = module; + this.defaultContent = defaultContent; + } + + File getModule() { + return module; + } + + String getDefaultContent() { + return defaultContent; + } + } } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx 2008-10-23 13:02:01 UTC (rev 1569) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx 2008-10-23 13:02:40 UTC (rev 1570) @@ -37,193 +37,254 @@ import javax.swing.event.TreeSelectionListener; import jaxx.runtime.swing.JAXXTree; import javax.swing.tree.TreePath; - - protected Map<String, Item> items; - + import fr.ifremer.isisfish.ui.widget.editor.GenericCell; + import javax.swing.tree.DefaultTreeModel; + import javax.swing.tree.DefaultMutableTreeNode; + import javax.swing.tree.TreeNode; + import static org.codelutin.i18n.I18nf._; + import fr.ifremer.isisfish.ui.WelcomePanelUI; + setContextValue(new ScriptAction()); - setItems(); tree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { - JAXXTree tree = (JAXXTree)e.getSource(); - String selectedValue = (String)tree.getSelectionValue(); - Item i = items.get(selectedValue); - File f = null; - if (i != null){ - Item parent = i.getParent(); - if (parent.equals(scriptItem)){ - f = new File(getContextValue(ScriptAction.class).getScriptDirectory().getPath() + File.separator + selectedValue); + DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); + if (node != null){ + GenericCell selectedValue = (GenericCell) node.getUserObject(); + if (selectedValue.getValue() != null){ + String parent = selectedValue.getValue().toString(); + File f = null; + if (!parent.equals("EquationModel")) { + if (parent.equals("Script")) { + f = new File(getContextValue(ScriptAction.class).getScriptDirectory().getPath() + File.separator + selectedValue); + } else if (parent.equals("Simulator")) { + f = new File(getContextValue(ScriptAction.class).getSimulatorDirectory().getPath() + File.separator + selectedValue); + } else if (parent.equals("Export")) { + f = new File(getContextValue(ScriptAction.class).getExportDirectory().getPath() + File.separator + selectedValue); + } else if (parent.equals("Rule")) { + f = new File(getContextValue(ScriptAction.class).getRuleDirectory().getPath() + File.separator + selectedValue); + } else if (parent.equals("AnalysePlan")) { + f = new File(getContextValue(ScriptAction.class).getAnalysePlanDirectory().getPath() + File.separator + selectedValue); + } else { + f = new File(getContextValue(ScriptAction.class).getFormuleDirectory().getPath() + File.separator + parent + File.separator + selectedValue); + parent = "EquationModel"; + } + } + if (f != null) { + getContextValue(ScriptAction.class).loadScript(selectedValue, selectedValue.getName(), parent); + setEditor(f); + } + setButton(); } - else if (parent.equals(simulationItem)){ - f = new File(getContextValue(ScriptAction.class).getSimulationDirectory().getPath() + File.separator + selectedValue); + else { + editor.close(); + editor.repaint(); } - else if (parent.equals(exportItem)){ - f = new File(getContextValue(ScriptAction.class).getExportDirectory().getPath() + File.separator + selectedValue); - } - else if (parent.equals(ruleItem)){ - f = new File(getContextValue(ScriptAction.class).getRuleDirectory().getPath() + File.separator + selectedValue); - } - else if (parent.equals(analysePlanItem)){ - f = new File(getContextValue(ScriptAction.class).getAnalysePlanDirectory().getPath() + File.separator + selectedValue); - } - else if (parent.equals(equationModelItem)){ - f = new File(getContextValue(ScriptAction.class).getFormuleDirectory().getPath() + File.separator + selectedValue); - } - if (f!=null){ - setEditor(f); - } + actionLogArea.setText(""); + setButton(); } } }); - protected void setItems(){ - items = new HashMap<String, Item>(); - setScriptItems(); - setSimulationItems(); - setExportItems(); - setRuleItems(); - setAnalysePlanItem(); - setEquationModelItem(); + protected void setTreeModel(){ + tree.setModel(getTreeModel()); } - protected void setScriptItems(){ - for (String value : getContextValue(ScriptAction.class).getScriptNames()){ - Item i = new Item(value, null, value, false); - items.put(value, i); - scriptItem.addChild(i); + protected DefaultTreeModel getTreeModel(){ + DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(); + DefaultTreeModel treeModel = new DefaultTreeModel(rootNode); + DefaultMutableTreeNode scriptNode = new DefaultMutableTreeNode(new GenericCell("Script", null)); + DefaultMutableTreeNode simulatorNode = new DefaultMutableTreeNode(new GenericCell("Simulator", null)); + DefaultMutableTreeNode exportNode = new DefaultMutableTreeNode(new GenericCell("Export", null)); + DefaultMutableTreeNode ruleNode = new DefaultMutableTreeNode(new GenericCell("Rule", null)); + DefaultMutableTreeNode analysePlanNode = new DefaultMutableTreeNode(new GenericCell("AnalysePlan", null)); + DefaultMutableTreeNode equationModelNode = new DefaultMutableTreeNode(new GenericCell("EquationModel", null)); + setNode(scriptNode, getContextValue(ScriptAction.class).getScriptNames(), "Script"); + setNode(simulatorNode, getContextValue(ScriptAction.class).getSimulatorNames(), "Simulator"); + setNode(exportNode, getContextValue(ScriptAction.class).getExportNames(), "Export"); + setNode(ruleNode, getContextValue(ScriptAction.class).getRuleNames(), "Rule"); + setNode(analysePlanNode, getContextValue(ScriptAction.class).getAnalysePlanNames(), "AnalysePlan"); + setNode(equationModelNode, getContextValue(ScriptAction.class).getCategories(), "EquationModel"); + for (Enumeration e = equationModelNode.children(); e.hasMoreElements();){ + DefaultMutableTreeNode node = (DefaultMutableTreeNode)e.nextElement(); + GenericCell g = (GenericCell)node.getUserObject(); + setNode(node, getContextValue(ScriptAction.class).getFormuleNames(g.toString()), g.toString()); } + treeModel.insertNodeInto(scriptNode, rootNode, 0); + treeModel.insertNodeInto(simulatorNode, rootNode, 1); + treeModel.insertNodeInto(exportNode, rootNode, 2); + treeModel.insertNodeInto(ruleNode, rootNode, 3); + treeModel.insertNodeInto(analysePlanNode, rootNode, 4); + treeModel.insertNodeInto(equationModelNode, rootNode, 5); + return treeModel; } - protected void setSimulationItems(){ - for (String value : getContextValue(ScriptAction.class).getSimulationNames()){ - Item i = new Item(value, null, value, false); - items.put(value, i); - simulationItem.addChild(i); + protected void setNode(DefaultMutableTreeNode node, java.util.List<String> values, String type) { + for (String value : values){ + DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(new GenericCell(value, type)); + node.add(childNode); } } - protected void setExportItems(){ - for (String value : getContextValue(ScriptAction.class).getExportNames()){ - Item i = new Item(value, null, value, false); - items.put(value, i); - exportItem.addChild(i); - } + protected void setEditor(File f){ + editor.open(f); + editor.repaint(); } - protected void setRuleItems(){ - for (String value : getContextValue(ScriptAction.class).getRuleNames()){ - Item i = new Item(value, null, value, false); - items.put(value, i); - ruleItem.addChild(i); + protected DefaultMutableTreeNode findNode(DefaultMutableTreeNode root, String value){ + DefaultMutableTreeNode result= null; + for (Enumeration e = root.children(); e.hasMoreElements();){ + DefaultMutableTreeNode node = (DefaultMutableTreeNode)e.nextElement(); + GenericCell g = (GenericCell)node.getUserObject(); + if (value.equals(g.getName())){ + result = node; + } } + return result; } - protected void setAnalysePlanItem(){ - for (String value : getContextValue(ScriptAction.class).getAnalysePlanNames()){ - Item i = new Item(value, null, value, false); - items.put(value, i); - analysePlanItem.addChild(i); + + protected void setButton(){ + boolean fileLoaded = getContextValue(ScriptAction.class).fileLoaded(); + boolean isJavaScript = getContextValue(ScriptAction.class).isJavaScript(); + buttonScriptExport.setEnabled(tree.getSelectionValue() != null); +// buttonScriptCommit +// buttonScriptUpdate + buttonScriptSave.setEnabled(fileLoaded); + buttonScriptCut.setEnabled(fileLoaded); + buttonScriptCopy.setEnabled(fileLoaded); + buttonScriptPaste.setEnabled(fileLoaded); + buttonScriptCheck.setEnabled(isJavaScript); + buttonScriptEval.setEnabled(isJavaScript); + } + protected void setInfoText(String msg){ + WelcomePanelUI root = getParentContainer(WelcomePanelUI.class); + root.setInfoText("msg"); + } +/* + * JButton Action + */ + + protected void newScript(){ + java.util.List<String> values = getContextValue(ScriptAction.class).getCategories(); + String scriptType = (String)ScriptTypeChoice.getSelectedItem(); + String equationModelType = ""; + String equationModelTypePath = ""; + if (scriptType.equals("EquationModel")){ + equationModelType = (String)JOptionPane.showInputDialog( + this, + "Select the equation model's category", + "Equation model", + JOptionPane.PLAIN_MESSAGE, + null, + values.toArray(), + values.get(0)); + equationModelTypePath = equationModelType + File.separator; } - } - protected void setEquationModelItem(){ - for (String categorie : getContextValue(ScriptAction.class).getCategories()){ - Item item = new Item(categorie, null, categorie, false); - equationModelItem.addChild(item); - for (String formule : getContextValue(ScriptAction.class).getFormuleNames(categorie)){ - Item i = new Item(formule, null, formule, false); - items.put(formule, i); - i.addChild(i); + if (equationModelType != null){ + String fileName = JOptionPane.showInputDialog(_("isisfish.message.new.filename")); + if (fileName != null){ + getContextValue(ScriptAction.class).newScript(equationModelTypePath + fileName, scriptType); + setTreeModel(); + setInfoText(_("isisfish.message.creation.done", script.getName())); + DefaultMutableTreeNode element = null; + element = findNode((DefaultMutableTreeNode) tree.getModel().getRoot(), scriptType); + if (!equationModelTypePath.equals("")){ + element = findNode(element, equationModelType); + } + element = findNode(element, fileName + ".java"); + TreeNode[] path = element.getPath(); + if (log.isDebugEnabled()) { + log.debug("chemin du prochain noeud selectionnée: " + Arrays.toString(path)); + } + TreePath newSelectionPath = new TreePath(path); + tree.setSelectionPath(newSelectionPath); } } } - protected void setEditor(File f){ - editor.open(f); + protected void saveScript(){ + getContextValue(ScriptAction.class).saveScript(editor.getText()); + setInfoText(_("isisfish.message.save.finished")); } + protected void exportScript(){ + getContextValue(ScriptAction.class).exportScript(tree.getSelectionPaths()); + } + protected void commitScript(){ + setInfoText(_(getContextValue(ScriptAction.class).commitScript(editor.getText()))); + } + protected void updateScript(){ + getContextValue(ScriptAction.class).updateScript(); + setInfoText(_("isisfish.message.update.finished")); + } + protected void cut(){ + } + protected void copy(){ + } + protected void paste(){ + } + protected void checkScript(){ + actionLogArea.setText(getContextValue(ScriptAction.class).checkScript(editor.getText())); + setInfoText(_("isisfish.message.check.finished")); + } + protected void evaluateScript(){ + actionLogArea.setText(getContextValue(ScriptAction.class).evaluateScript(editor.getText())); + setInfoText(_("isisfish.message.evaluation.finished")); + } ]]> </script> -<!-- -title="isisfish.script.title" -visible="true" size='{new Dimension(620,400)}' ---> - -<!-- Fixme : WindowsEvents -<WindowEvents id="events" onOpened="script.Action.opened()" /> -Maximizable="true" Closable="true" -bundle="org.codelutin.i18n.I18nBundleBridge" ---> - -<!-- Fixme : ContextDataSource - <ContextDataSource id="ScriptStorage" context="current" source="ScriptStorage"/> - <ContextDataSource id="ActionLog" context="current" source="ActionLog"/> - <ContextDataSource id="ScriptType" context="current" source="ScriptType"/> - <ContextDataSource id="canCommit" context="current" source="canCommit"/> - <ContextDataSource id="canUpdate" context="current" source="canUpdate"/> - <ContextDataSource id="canDiff" context="current" source="canDiff"/> - <ContextDataSource id="canDelete" context="current" source="canDelete"/> ---> - <!-- | Toolbar +--> <JPanel id="buttonBar" layout='{new GridLayout()}' constraints='BorderLayout.NORTH'> <JComboBox id="ScriptTypeChoice" model='{new DefaultComboBoxModel(getContextValue(ScriptAction.class).getScriptTypesNames())}'/> + <JButton id="buttonScriptNew" text="isisfish.script.new" onActionPerformed='newScript()'/> <!-- -origin="ScriptType" -renderer="org.codelutin.i18n.I18n._(.)" ---> - - <!-- no change name in combo box, or change for menu and in Action.newScript too --> -<!-- Fixme : comboboxmodel - <comboboxmodel origin="fr.ifremer.isisfish.ui.script.Action.getScriptTypesNames()"/> ---> - <JButton id="buttonScriptNew" text="isisfish.script.new"/> -<!-- ToolTipText="Create a new script" actionCommand="script.Action.newScript($tree, $treeModel, $ScriptTypeChoice/selectedItem)" --> - <JButton id="buttonScriptSave" text="isisfish.script.save"/> + <JButton id="buttonScriptSave" text="isisfish.script.save" enabled='false' onActionPerformed='saveScript()'/> <!-- ToolTipText="Save current script" origin="util:isValid($ScriptStorage)" actionCommand="script.Action.saveScript($ScriptStorage, $scriptJedit/text)" --> - <JButton id="buttonScriptExport" text="isisfish.script.txtExport"/> + <JButton id="buttonScriptExport" text="isisfish.script.txtExport" enabled='false' onActionPerformed='exportScript()'/> <!-- ToolTipText="Export selected script(s) to zip archive" origin="$tree/selectionPaths" actionCommand="script.Action.exportScript($tree)" --> - <JButton id="buttonScriptCommit" text="isisfish.script.commit"/> + <JButton id="buttonScriptCommit" text="isisfish.script.commit" enabled='false' onActionPerformed='commitScript()'/> <!-- ToolTipText="Commit script to CVS server" origin="$canCommit" actionCommand="script.Action.commitScript($tree, $ScriptStorage, $scriptJedit/text)" --> - <JButton id="buttonScriptUpdate" text="isisfish.script.update"/> + <JButton id="buttonScriptUpdate" text="isisfish.script.update" enabled='false' onActionPerformed='updateScript()'/> <!-- ToolTipText="Update current script from server" origin="$canUpdate" actionCommand="script.Action.updateScript($tree,$ScriptStorage)" --> - <JButton id="buttonScriptCut" text="isisfish.script.cut"/> + <JButton id="buttonScriptCut" text="isisfish.script.cut" enabled='false' onActionPerformed='cut()'/> <!-- ToolTipText="Cut current selection (Ctrl-x)" origin="util:isValid($ScriptStorage)" actionCommand="xpath:cut($scriptJedit)" --> - <JButton id="buttonScriptCopy" text="isisfish.script.copy"/> + <JButton id="buttonScriptCopy" text="isisfish.script.copy" enabled='false' onActionPerformed='copy()'/> <!-- ToolTipText="Copy current selection (Ctrl-c)" origin="util:isValid($ScriptStorage)" actionCommand="xpath:copy($scriptJedit)" --> - <JButton id="buttonScriptPaste" text="isisfish.script.paste"/> + <JButton id="buttonScriptPaste" text="isisfish.script.paste" enabled='false' onActionPerformed='paste()'/> <!-- ToolTipText="Paste current selection (Ctrl-v)" origin="util:isValid($ScriptStorage)" actionCommand="xpath:paste($scriptJedit)" --> - <JButton id="buttonScriptCheck" text="isisfish.script.check"/> + <JButton id="buttonScriptCheck" text="isisfish.script.check" enabled='false' onActionPerformed='checkScript()'/> <!-- ToolTipText="Check syntax of the current script" origin="util:isInstance('fr.ifremer.isisfish.datastore.JavaSourceStorage', $ScriptStorage)" actionCommand="script.Action.checkScript($ScriptStorage, $scriptJedit/text)" --> - <JButton id="buttonScriptEval" text="isisfish.script.evaluate"/> + <JButton id="buttonScriptEval" text="isisfish.script.evaluate" enabled='false' onActionPerformed='evaluateScript()'/> <!-- ToolTipText="Try to eval current script (must be have main method)" origin="util:isInstance('fr.ifremer.isisfish.datastore.JavaSourceStorage', $ScriptStorage)" @@ -246,13 +307,7 @@ <!-- Fixme : non plus : JScrollPane does not accept constraints constraints='"tree"' --> - <JTree id="tree" name="tree" rootVisible="false"> - <item id='scriptItem' selected='true' value="Script"/> - <item id='simulationItem' value="Simulator"/> - <item id='exportItem' value="Export"/> - <item id='ruleItem' value="Rule"/> - <item id='analysePlanItem' value="AnalysePlan"/> - <item id='equationModelItem' value="EquationModel"/> + <javax.swing.JTree id="tree" name="tree" rootVisible="false" model='{getTreeModel()}'/> <!-- Fixme : NestedTreeModel, TreeRenderer and TreeSelectionEvents <NestedTreeModel id="treeModel"> @@ -288,7 +343,6 @@ <TreeSelectionEvents id="treeSelectionListener" onValueChanged="thread:script.Action.loadScript($tree, $tree/selectionPath/path[2]/userObject, $tree/selectionPath/lastPathComponent)"/> --> - </JTree> </JScrollPane> <JSplitPane oneTouchExpandable="true" dividerLocation="250" orientation="VERTICAL"> Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2008-10-23 13:02:01 UTC (rev 1569) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ParamsUI.jaxx 2008-10-23 13:02:40 UTC (rev 1570) @@ -45,9 +45,9 @@ import org.codelutin.math.matrix.gui.MatrixPanelEditor; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; + import fr.ifremer.isisfish.ui.widget.editor.GenericCell; + import javax.swing.table.TableColumn; import fr.ifremer.isisfish.ui.widget.editor.ParameterColumnEditor; - import javax.swing.table.TableColumn; -import fr.ifremer.isisfish.ui.widget.editor.ParameterCellEditor; setContextValue(new MatrixPanelEditor()); simulParamsNumbers.add(getContextValue(MatrixPanelEditor.class), BorderLayout.CENTER); @@ -208,7 +208,7 @@ for (Iterator<String> it = values.keySet().iterator(); it.hasNext();) { String name = it.next(); Object properties = getContextValue(SimulAction.class).getRuleParameterValue(name, listSimulParamsMesuresList.getSelectedValue().toString()); - ParameterCellEditor value = new ParameterCellEditor(name, values.get(name)); + GenericCell value = new GenericCell(name, values.get(name)); model.setValueAt(value, row, 0); model.setValueAt(properties, row, 1); row++; @@ -223,7 +223,7 @@ public void tableChanged(TableModelEvent e) { int row = e.getFirstRow(); TableModel model = (TableModel)e.getSource(); - ParameterCellEditor data = (ParameterCellEditor) model.getValueAt(row, 0); + GenericCell data = (GenericCell) model.getValueAt(row, 0); getContextValue(SimulAction.class).setRuleParameterValue(data.getName(), listSimulParamsMesuresList.getSelectedValue().toString(), model.getValueAt(row, 1)); } }); Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SensUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SensUI.jaxx 2008-10-23 13:02:01 UTC (rev 1569) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SensUI.jaxx 2008-10-23 13:02:40 UTC (rev 1570) @@ -38,7 +38,7 @@ import javax.swing.table.TableModel; import fr.ifremer.isisfish.ui.widget.editor.ParameterColumnEditor; import javax.swing.table.TableColumn; - import fr.ifremer.isisfish.ui.widget.editor.ParameterCellEditor; + import fr.ifremer.isisfish.ui.widget.editor.GenericCell; public SensUI (SimulAction action){ setContextValue(action); @@ -89,7 +89,7 @@ for (Iterator<String> it = values.keySet().iterator(); it.hasNext();) { String name = it.next(); Object properties = getContextValue(SimulAction.class).getAnalysePlanParameterValue(name, listSimulParamsAnalysePlansList.getSelectedValue().toString()); - ParameterCellEditor value = new ParameterCellEditor(name, values.get(name)); + GenericCell value = new GenericCell(name, values.get(name)); model.setValueAt(value, row, 0); model.setValueAt(properties, row, 1); row++; @@ -103,7 +103,7 @@ public void tableChanged(TableModelEvent e) { int row = e.getFirstRow(); TableModel model = (TableModel)e.getSource(); - ParameterCellEditor data = (ParameterCellEditor) model.getValueAt(row, 0); + GenericCell data = (GenericCell) model.getValueAt(row, 0); getContextValue(SimulAction.class).setAnalysePlanParameterValue(data.getName(), listSimulParamsAnalysePlansList.getSelectedValue().toString(), model.getValueAt(row, 1)); } }); Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/GenericCell.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/GenericCell.java (rev 0) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/GenericCell.java 2008-10-23 13:02:40 UTC (rev 1570) @@ -0,0 +1,29 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package fr.ifremer.isisfish.ui.widget.editor; + +/** + * + * @author letellier + */ +public class GenericCell{ + private String name; + private Object value; + public GenericCell(String n, Object c){ + name = n; + value = c; + } + @Override + public String toString(){ + return name; + } + public Object getValue(){ + return value; + } + public String getName(){ + return name; + } +} Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterColumnEditor.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterColumnEditor.java 2008-10-23 13:02:01 UTC (rev 1569) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/editor/ParameterColumnEditor.java 2008-10-23 13:02:40 UTC (rev 1570) @@ -152,8 +152,8 @@ // Map.Entry<String, Class> p = (Map.Entry<String, Class>) table.getValueAt(row, 0); // type = p.getValue(); // log.debug(p.getKey() + " P.type:" + type); - ParameterCellEditor p = (ParameterCellEditor) table.getValueAt(row, 0); - type = p.getType(); + GenericCell p = (GenericCell) table.getValueAt(row, 0); + type = (Class)p.getValue(); JComboBox c; //if (!table.hasFocus()) return null;
participants (1)
-
sletellier@users.labs.libre-entreprise.org