r1566 - isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator
Author: sletellier Date: 2008-10-17 14:58:29 +0000 (Fri, 17 Oct 2008) New Revision: 1566 Removed: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsAction.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/Queue.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorAction.java Log: Simulation completed Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsAction.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsAction.java 2008-10-17 14:57:40 UTC (rev 1565) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/AdvancedParamsAction.java 2008-10-17 14:58:29 UTC (rev 1566) @@ -1,49 +0,0 @@ -/* *##% - * Copyright (C) 2005 - * Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * IsisFish.java - * - * Created: 1 aout 2005 18:37:25 CEST - * - * @author Benjamin POUSSIN <poussin at codelutin.com> - * @version $Revision: 1312 $ - * - * Last update: $Date: 2008-08-28 10:21:07 +0200 (jeu, 28 aoû 2008) $ - * by : $Author: sletellier $ - */ - -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -/** - * - * @author letellier - */ -package fr.ifremer.isisfish.ui.simulator; - -public class AdvancedParamsAction{ - public AdvancedParamsAction(){ - - } - public void getSimulatorNames(){ - - } -} Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/Queue.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/Queue.java 2008-10-17 14:57:40 UTC (rev 1565) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/Queue.java 2008-10-17 14:58:29 UTC (rev 1566) @@ -1,212 +0,0 @@ -/* - * Queue.java - * - * Created on 22 août 2008, 23:01 - */ - -package fr.ifremer.isisfish.ui.simulator; - -import fr.ifremer.isisfish.logging.SimulationLoggerUtil; -import static org.codelutin.i18n.I18nf._; - -import fr.ifremer.isisfish.simulator.launcher.SimulationJob; -import fr.ifremer.isisfish.simulator.launcher.SimulationService; -import fr.ifremer.isisfish.simulator.launcher.SimulationServiceTableModel; -import java.awt.Component; -import javax.swing.GroupLayout; -import javax.swing.JProgressBar; -import javax.swing.JTable; -import javax.swing.LayoutStyle; -import javax.swing.LayoutStyle.ComponentPlacement; -import javax.swing.ListSelectionModel; -import javax.swing.table.TableCellRenderer; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.log.UserLog; -import org.jdesktop.beansbinding.AutoBinding; -import org.jdesktop.beansbinding.BeanProperty; -import org.jdesktop.beansbinding.Binding; -import org.jdesktop.beansbinding.BindingGroup; -import org.jdesktop.beansbinding.Bindings; -import org.jdesktop.beansbinding.ELProperty; - -/** - * Widget permettant d'afficher l'etat des simulations - * - * @author poussin - */ -public class Queue extends javax.swing.JPanel { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(SimulationServiceTableModel.class); - - public class JProgressBarTableCellRenderer implements TableCellRenderer { - public Component getTableCellRendererComponent(JTable table, - Object value, boolean isSelected, boolean hasFocus, - int row, int column) { - return (JProgressBar) value; - } - }// JProgressBarTableCellRenderer - - /** Creates new form Queue */ - public Queue() { - initComponents(); - SimulationService ss = SimulationService.getService(); - - modelJobs = new SimulationServiceTableModel(ss, true); - modelJobDones = new SimulationServiceTableModel(ss, false); - - tableJobs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - tableJobs.setDefaultRenderer(JProgressBar.class, - new JProgressBarTableCellRenderer()); - tableJobDones.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - tableJobDones.setDefaultRenderer(JProgressBar.class, - new JProgressBarTableCellRenderer()); - - tableJobs.setModel(modelJobs); - tableJobDones.setModel(modelJobDones); - } - - protected void stopSimulation(java.awt.event.ActionEvent evt) { - int i = tableJobs.getSelectedRow(); - if (i >= 0) { - SimulationJob job = modelJobs.getJob(i); - job.stop(); - log.info(_("User stop simulation %s", job.getItem().getControl().getId())); - } - } - - protected void viewLog(java.awt.event.ActionEvent evt) { - int i = tableJobs.getSelectedRow(); - if (i >= 0) { - SimulationJob job = modelJobs.getJob(i); - String id = job.getItem().getControl().getId(); - try { - SimulationLoggerUtil.showSimulationLogConsole(id); - } catch (Exception eee) { - UserLog.error(_("Can't open log for %s", id), eee); - } - } - } - - protected void clearDoneJobs(java.awt.event.ActionEvent evt) { - SimulationService ss = SimulationService.getService(); - ss.clearJobDone(); - } - - protected void initComponents() { - bindingGroup = new BindingGroup(); - - tableJobsScroll = new javax.swing.JScrollPane(); - tableJobs = new javax.swing.JTable(); - tableJobDonesScroll = new javax.swing.JScrollPane(); - tableJobDones = new javax.swing.JTable(); - autoLaunchButton = new javax.swing.JToggleButton(); - stopSimuButton = new javax.swing.JButton(); - showLogButton = new javax.swing.JButton(); - clearDoneJobsButton = new javax.swing.JButton(); - - tableJobsScroll.setViewportView(tableJobs); - - tableJobDonesScroll.setViewportView(tableJobDones); - - autoLaunchButton.setText(_("Auto Launch")); - - Binding binding = Bindings.createAutoBinding( - AutoBinding.UpdateStrategy.READ_WRITE, - SimulationService.getService(), ELProperty.create("${autoLaunch}"), - autoLaunchButton, BeanProperty.create("selected")); - bindingGroup.addBinding(binding); - - stopSimuButton.setText(_("Stop simulation")); - - binding = Bindings.createAutoBinding( - AutoBinding.UpdateStrategy.READ, - tableJobs, ELProperty.create("${selectedElement != null}"), - stopSimuButton, BeanProperty.create("enabled")); - binding.setSourceNullValue(false); - binding.setSourceUnreadableValue(false); - bindingGroup.addBinding(binding); - - stopSimuButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - stopSimulation(evt); - } - }); - - showLogButton.setText(_("View log")); - - binding = Bindings.createAutoBinding( - AutoBinding.UpdateStrategy.READ, - tableJobDones, ELProperty.create("${selectedElement != null}"), - showLogButton, BeanProperty.create("enabled")); - binding.setSourceNullValue(false); - binding.setSourceUnreadableValue(false); - bindingGroup.addBinding(binding); - - showLogButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - viewLog(evt); - } - }); - - clearDoneJobsButton.setText(_("Clear done jobs")); - - clearDoneJobsButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - clearDoneJobs(evt); - } - }); - - GroupLayout layout = new GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addGap(12, 12, 12) - .addComponent(autoLaunchButton) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(stopSimuButton) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(showLogButton) - .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) - .addComponent(clearDoneJobsButton)) - .addComponent(tableJobDonesScroll, GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE) - .addComponent(tableJobsScroll, GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE)) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(tableJobsScroll, GroupLayout.PREFERRED_SIZE, 140, Short.MAX_VALUE) - .addPreferredGap(ComponentPlacement.RELATED) - .addComponent(tableJobDonesScroll, GroupLayout.PREFERRED_SIZE, 140, Short.MAX_VALUE) - .addPreferredGap(ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) - .addComponent(autoLaunchButton) - .addComponent(stopSimuButton) - .addComponent(showLogButton) - .addComponent(clearDoneJobsButton)) - .addContainerGap()) - ); - - bindingGroup.bind(); - } - - protected SimulationServiceTableModel modelJobs; - protected SimulationServiceTableModel modelJobDones; - protected javax.swing.JToggleButton autoLaunchButton; - protected javax.swing.JButton stopSimuButton; - protected javax.swing.JButton showLogButton; - protected javax.swing.JButton clearDoneJobsButton; - protected javax.swing.JTable tableJobDones; - protected javax.swing.JScrollPane tableJobDonesScroll; - protected javax.swing.JTable tableJobs; - protected javax.swing.JScrollPane tableJobsScroll; - private org.jdesktop.beansbinding.BindingGroup bindingGroup; - -} Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorAction.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorAction.java 2008-10-17 14:57:40 UTC (rev 1565) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/SimulatorAction.java 2008-10-17 14:58:29 UTC (rev 1566) @@ -1,372 +0,0 @@ -/* *##% - * Copyright (C) 2006 - * Ifremer, Code Lutin, C?dric Pineau, Benjamin Poussin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -/* * - * SimulatorAction.java - * - * Created: 7 juil. 2006 12:19:06 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - -package fr.ifremer.isisfish.ui.simulator; - -import fr.ifremer.isisfish.IsisFish; -import fr.ifremer.isisfish.datastore.AnalysePlanStorage; -import fr.ifremer.isisfish.datastore.ExportStorage; -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 static fr.ifremer.isisfish.datastore.SimulationStorage.getSimulation; -import static fr.ifremer.isisfish.datastore.SimulationStorage.getSimulationNames; -import fr.ifremer.isisfish.logging.SimulationLoggerUtil; -import fr.ifremer.isisfish.simulator.SimulationException; -import fr.ifremer.isisfish.simulator.SimulationParameter; -import fr.ifremer.isisfish.simulator.SimulationProperties; -import fr.ifremer.isisfish.simulator.launcher.SimulationService; -import fr.ifremer.isisfish.simulator.launcher.SimulatorLauncher; -import fr.ifremer.isisfish.ui.simulator.filter.SimulationFilterUtil; -import fr.ifremer.isisfish.ui.widget.filter.FilterModel; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import static org.codelutin.i18n.I18nf._; -import org.codelutin.topia.TopiaContext; -import org.swixat.framework.AbstractFrame; -import org.swixat.framework.OutputView; -import org.swixat.model.Context; - -import javax.swing.*; -import javax.swing.table.TableModel; -import java.lang.reflect.Field; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import org.codelutin.log.UserLog; - - -/** - * @author poussin - */ - -public class SimulatorAction { - static private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm"); - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(SimulatorAction.class); - - static public Object opened(Context uiContext, AbstractFrame frame, - TopiaContext isisContext, JTabbedPane tabs, -// JButton start, JButton remove,JButton showLog, -// JTable table,JTable tableDone, - JButton removeAnalysePlan, - JList listAnalysePlan, - JButton removeRule, - JList listRule) { - log.debug("call opened " + isisContext); - try { - SimulationParameter param = new SimulationParameter(); - - // TODO refresh data context on all this when datas coming from script module - // when a modification is done in script dialog - // => then refresh whoses data - // and the associated ui - // compute result names available - List<String> resultNames = getResultNames(); - uiContext.setData("ResultNames", resultNames); - uiContext.setData("ExportNames", ExportStorage.getExportNames()); - uiContext.setData("AnalysePlanNames", AnalysePlanStorage.getAnalysePlanNames()); - uiContext.setData("RuleNames", RuleStorage.getRuleNames()); - - // put default value in param - param.setSimulatorName(IsisFish.config.getSimulatorClassfile()); - param.setTagValue(IsisFish.config.getDefaultTagValueAsMap()); - param.setExportDirectory(IsisFish.config.getDefaultExportDirectory().toString()); - param.setExportNames(IsisFish.config.getDefaultExportNamesAsList()); - List<String> defaultResultNames = IsisFish.config.getDefaultResultNamesAsList(); - if (defaultResultNames != 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 process) - List<String> value = getSimulationNames(); - // create filter model - FilterModel<SimulationProperties, String> model = - 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); - - // add analyse plan around button listeners - SimulatorListeners.initButtonRemoveIfItemSelected(removeAnalysePlan, listAnalysePlan); - - frame.refreshView(); - } catch (Exception eee) { - log.error("Can't init SimulationParameter", eee); - return new OutputView("Error.xml", "error", eee.getMessage()); - } - return null; - } - - /** - * 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 - */ - static private 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); - } - } - return result; - } - - /** - * Change region in simulation launcher - * - * @param uiContext swixat context - * @param frame swixat frame - * @param simulationName name of simulation to load - * @return <code>null</code> if ok, an OutputView otherwise with error - */ - static public Object loadOldSimulation(Context uiContext, AbstractFrame frame, - String simulationName) { - log.debug("call loadOldSimulation: " + simulationName); - try { - frame.setInfoText(_("isisfish.message.loading.old.simulation")); - - SimulationStorage storage = getSimulation(simulationName); - uiContext.setData("OldSimulationName", storage.getName()); - - SimulationParameter param = storage.getParameter().copy(); - // all time reset number after load - param.setAnalysePlanNumber(-1); - uiContext.setData("SimulationParameter", param); - - RegionStorage region = param.getRegion(); - uiContext.setData("RegionStorage", region); - - frame.refreshView(); - - JTabbedPane tab = (JTabbedPane) uiContext.getWidget("simulTabs"); - tab.setEnabledAt(1, param.getUsePreScript()); - tab.setEnabledAt(2, param.getUseAnalysePlan()); - - frame.setInfoText(_("isisfish.message.old.simulation.loaded")); - } catch (Exception eee) { - log.error("Can't load old Simulation: " + simulationName, eee); - return new OutputView("Error.xml", "error", eee.getMessage()); - } - return null; - } - - /** - * Change region in simulation launcher - * - * @param uiContext swixat context - * @param frame swixat frame - * @param param simulation parameter to use - * @param regionName SimulationParameter/description * @return - * @return <code>null</code> if ok, an OutputView otherwise with error - */ - static public Object loadRegion(Context uiContext, AbstractFrame frame, - SimulationParameter param, String regionName) { - log.debug("call loadRegion: " + regionName); - try { - frame.setInfoText(_("isisfish.message.loading.region")); - - RegionStorage storage = RegionStorage.getRegion(regionName); - uiContext.setData("RegionStorage", storage); - param.setRegionName(regionName); - - // change Region, we must init some list - param.setPopulations(null); - param.setRules(null); - param.setStrategies(null); - - frame.refreshView(); - frame.setInfoText(_("isisfish.message.region.loaded")); - } catch (Exception eee) { - log.error("Can't load region: " + regionName, eee); - return new OutputView("Error.xml", "error", eee.getMessage()); - } - return null; - } - - /** - * Launch automaticaly the simulation, when is possible (no other simulation) - * or wait for the last automaticaly simulation ended. - * - * @param uiContext swixat context - * @param frame swixat frame - * @param simulId id of the simulation to simulate - * @param param paramters of the simulation - * @param tabs the tabs - * @param inQueue flag to say put in queue - * @return <code>null</code> if ok, an OutputView otherwise with error - */ - static public Object simulate(Context uiContext, AbstractFrame frame, - String simulId, SimulationParameter param, - boolean inQueue, JTabbedPane tabs, - SimulatorLauncher launcher) { - log.debug("call simulate"); - try { - uiContext.setData("SimulationLaunched", false); - - simulId += " " + dateFormat.format(new java.util.Date()); - - if (simulId == null || "".equals(simulId) || - SimulationStorage.localyExists(simulId) || - SimulationService.getService().exists(simulId)) { - UserLog.error(_("Can't start simulation, bad id: %s", simulId)); - } else { - SimulationParameter p = param.copy(); - - SimulationService.getService().submit(simulId, p, launcher, 0); - - selectTab(tabs, true, 6); - } - } catch (Exception eee) { - log.error("Can't start simulation", eee); - return new OutputView("Error.xml", "error", eee.getMessage()); - } - return null; - } - - /** - * Save simulator name and local/remote choice in user preference - * - * @param simulatorName name of simulator - * @param local <code>true</code> to use local simulator - */ - static public void saveSimulatorChoice(String simulatorName, boolean local) { - IsisFish.config.setSimulatorClassfile(simulatorName); - IsisFish.config.setSimulatorLauncher(local?"local":"isis-server"); - } - - static public void saveExport(String exportDirectory, List<String> exportNames) { - IsisFish.config.setDefaultExportDirectory(exportDirectory); - IsisFish.config.setDefaultExportNames(exportNames); - } - - static public void saveResultNames(List<String> resultNames) { - IsisFish.config.setDefaultResultNames(resultNames); - } - - static public void saveTagValue(Map<String, String> tagValues) { - log.debug("call saveTagValue: " + tagValues); - IsisFish.config.setDefaultTagValues(tagValues); - } - - static public void addTagValue(SimulationParameter param, String tag, String value) { - param.getTagValue().put(tag, value); - } - - static public void removeTagValue(SimulationParameter param, String tag) { - log.debug("removeTagValue: " + tag); - param.getTagValue().remove(tag); - } - - static public void selectTab(JTabbedPane tabs, boolean mustGo, int tabIndex) { - log.debug("selectTab: " + mustGo + " index: " + tabIndex); - if (mustGo) { - tabs.setSelectedIndex(tabIndex); - } - } - - @SuppressWarnings({"UnusedDeclaration"}) - static public void refreshRule(Context uiContext, AbstractFrame frame, - JTable table) { - // we must first loose focus from table - //TODO No! we must fix bug on columnEditor : when focus lost, should - //TODO stop editing - frame.refreshView("simulParamsRules"); - } - - /** - * - * @param uiContext swiwat context - * @param frame swixat frame - * @param table the done simulation table - * @param model the done simulation table model - * @param selected state of the button clicked - * @return <code>null</code> if ok, an OutputView otherwise with error - */ - @SuppressWarnings({"UnusedDeclaration"}) - static public Object showLog(Context uiContext, AbstractFrame frame, - JTable table, TableModel model,int selected) { - try { - if (selected<0 || model==null) return null; - - // obtain the name of selected simulation - String id = (String) model.getValueAt(selected,0); - - // check if not a simulation with anaylse plans - Object analyzePlan = model.getValueAt(selected,1); - - if (analyzePlan instanceof Integer) { - // we have a simulation with anaylse - //TODO Make a ui to ask user which anaylyse to see - id = id+"_0"; - } - // launch log console - SimulationLoggerUtil.showSimulationLogConsole(id); - } catch (Exception e) { - // ignore ? - return new OutputView("Error.xml", "error", e.getMessage()); - } - return null; - } - -} //SimulatorAction
participants (1)
-
sletellier@users.labs.libre-entreprise.org