Author: echatellier Date: 2015-05-20 13:11:09 +0000 (Wed, 20 May 2015) New Revision: 4229 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4229 Log: Move script code to dedicated handler (queue) Added: trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueHandler.java Removed: trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueAction.java Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/queue/PauseButtonModel.java trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueUI.jaxx Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/queue/PauseButtonModel.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/queue/PauseButtonModel.java 2015-05-20 12:58:46 UTC (rev 4228) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/queue/PauseButtonModel.java 2015-05-20 13:11:09 UTC (rev 4229) @@ -4,7 +4,7 @@ * #%L * IsisFish * %% - * Copyright (C) 2014 Ifremer, Codelutin, Benjamin Poussin + * Copyright (C) 2014 - 2015 Ifremer, Codelutin, 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 @@ -22,7 +22,6 @@ * #L% */ - import fr.ifremer.isisfish.simulator.launcher.SimulationExecutor; import fr.ifremer.isisfish.simulator.launcher.SimulationService; import java.awt.event.ItemEvent; @@ -89,5 +88,4 @@ } } - } Deleted: trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueAction.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueAction.java 2015-05-20 12:58:46 UTC (rev 4228) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueAction.java 2015-05-20 13:11:09 UTC (rev 4229) @@ -1,146 +0,0 @@ -/* - * #%L - * IsisFish - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 Ifremer, Code Lutin - * %% - * 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.queue; - -import static org.nuiton.i18n.I18n.t; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import fr.ifremer.isisfish.logging.SimulationLoggerUtil; -import fr.ifremer.isisfish.simulator.launcher.SimulationJob; -import fr.ifremer.isisfish.simulator.launcher.SimulationService; -import fr.ifremer.isisfish.ui.util.ErrorHelper; - -/** - * Common action for all queue ui. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class QueueAction { - - /** Log. */ - private static Log log = LogFactory.getLog(QueueAction.class); - - /** queue ui to manage. */ - protected QueueUI queueUI; - - /** - * Queue action. - * - * @param queueUI queue ui to manage - */ - public QueueAction(QueueUI queueUI) { - this.queueUI = queueUI; - } - - /** - * Update ui buttons. - */ - public void updateActions() { - queueUI.setCanStop(!queueUI.getSelectionModelQueueTable().isSelectionEmpty()); - queueUI.setCanShowLog(!queueUI.getSelectionModelQueueTableDone().isSelectionEmpty()); - queueUI.setCanClear(queueUI.getQueueTableDone().getModel().getRowCount()>0); - queueUI.setCanRestart(!queueUI.getSelectionModelQueueTableDone().isSelectionEmpty()); - } - - /** - * Stop simulation associated with table selected rows. - */ - protected void stopSimulation() { - int[] selectedRows = queueUI.getQueueTable().getSelectedRows(); - SimulationJob[] jobsToStop = new SimulationJob[selectedRows.length]; - int index = 0; - - // to do in two pass, because each stopped simulation - // change selected rows - for (int selectedRow : selectedRows) { - jobsToStop[index++] = queueUI.getNewSimulationModel().getJob(selectedRow); - } - for (SimulationJob jobToStop : jobsToStop) { - jobToStop.stop(); - if (log.isInfoEnabled()) { - log.info(t("User stop simulation %s", jobToStop.getItem().getControl() - .getId())); - } - } - } - - /** - * Restart simulation. - */ - protected void restartSimulation() { - int[] selectedRows = queueUI.getQueueTableDone().getSelectedRows(); - SimulationJob[] jobsToRestart = new SimulationJob[selectedRows.length]; - int index = 0; - - // to do in two pass, because each simulation - // change selected rows - for (int selectedRow : selectedRows) { - jobsToRestart[index++] = queueUI.getDoneSimulationModel().getJob(selectedRow); - } - for (SimulationJob jobToRestart : jobsToRestart) { - - jobToRestart.restart(); - jobToRestart.getItem().getControl().setText(t("isisfish.simulation.restarting")); - if (log.isInfoEnabled()) { - log.info(t("User restart simulation %s", jobToRestart.getItem().getControl() - .getId())); - } - } - } - - /** - * View log of selected done jobs. - */ - protected void viewLog() { - if (queueUI.getQueueTableDone().getSelectedRow() >= 0) { - SimulationJob selectedJob = queueUI.getDoneSimulationModel().getJob(queueUI.getQueueTableDone().getSelectedRow()); - - String id = selectedJob.getItem().getControl().getId(); - try { - SimulationLoggerUtil.showSimulationLogConsole(queueUI, id); - } catch (Exception eee) { - if (log.isErrorEnabled()) { - log.error(t("Can't open log for %s", id), eee); - } - ErrorHelper.showErrorDialog(t("Can't open log for %s", id), eee); - } - } - } - - /** - * Remove all done jobs. - */ - protected void clearDoneJobs() { - SimulationService ss = SimulationService.getService(); - ss.clearJobDone(); - } -} Copied: trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueHandler.java (from rev 4226, trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueAction.java) =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueHandler.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueHandler.java 2015-05-20 13:11:09 UTC (rev 4229) @@ -0,0 +1,151 @@ +/* + * #%L + * IsisFish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2010 Ifremer, Code Lutin + * %% + * 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.queue; + +import static org.nuiton.i18n.I18n.t; + +import javax.swing.JProgressBar; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import fr.ifremer.isisfish.logging.SimulationLoggerUtil; +import fr.ifremer.isisfish.simulator.launcher.SimulationJob; +import fr.ifremer.isisfish.simulator.launcher.SimulationService; +import fr.ifremer.isisfish.ui.util.ErrorHelper; + +/** + * Common action for all queue ui. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class QueueHandler { + + /** Log. */ + private static Log log = LogFactory.getLog(QueueHandler.class); + + /** queue ui to manage. */ + protected QueueUI queueUI; + + /** + * Queue action. + * + * @param queueUI queue ui to manage + */ + public void init(QueueUI queueUI) { + this.queueUI = queueUI; + + queueUI.queueTable.setDefaultRenderer(JProgressBar.class, new ComponentTableCellRenderer()); + queueUI.queueTableDone.setDefaultRenderer(JProgressBar.class, new ComponentTableCellRenderer()); + } + + /** + * Update ui buttons. + */ + public void updateActions() { + queueUI.setCanStop(!queueUI.getSelectionModelQueueTable().isSelectionEmpty()); + queueUI.setCanShowLog(!queueUI.getSelectionModelQueueTableDone().isSelectionEmpty()); + queueUI.setCanClear(queueUI.getQueueTableDone().getModel().getRowCount()>0); + queueUI.setCanRestart(!queueUI.getSelectionModelQueueTableDone().isSelectionEmpty()); + } + + /** + * Stop simulation associated with table selected rows. + */ + protected void stopSimulation() { + int[] selectedRows = queueUI.getQueueTable().getSelectedRows(); + SimulationJob[] jobsToStop = new SimulationJob[selectedRows.length]; + int index = 0; + + // to do in two pass, because each stopped simulation + // change selected rows + for (int selectedRow : selectedRows) { + jobsToStop[index++] = queueUI.getNewSimulationModel().getJob(selectedRow); + } + for (SimulationJob jobToStop : jobsToStop) { + jobToStop.stop(); + if (log.isInfoEnabled()) { + log.info(t("User stop simulation %s", jobToStop.getItem().getControl() + .getId())); + } + } + } + + /** + * Restart simulation. + */ + protected void restartSimulation() { + int[] selectedRows = queueUI.getQueueTableDone().getSelectedRows(); + SimulationJob[] jobsToRestart = new SimulationJob[selectedRows.length]; + int index = 0; + + // to do in two pass, because each simulation + // change selected rows + for (int selectedRow : selectedRows) { + jobsToRestart[index++] = queueUI.getDoneSimulationModel().getJob(selectedRow); + } + for (SimulationJob jobToRestart : jobsToRestart) { + + jobToRestart.restart(); + jobToRestart.getItem().getControl().setText(t("isisfish.simulation.restarting")); + if (log.isInfoEnabled()) { + log.info(t("User restart simulation %s", jobToRestart.getItem().getControl() + .getId())); + } + } + } + + /** + * View log of selected done jobs. + */ + protected void viewLog() { + if (queueUI.getQueueTableDone().getSelectedRow() >= 0) { + SimulationJob selectedJob = queueUI.getDoneSimulationModel().getJob(queueUI.getQueueTableDone().getSelectedRow()); + + String id = selectedJob.getItem().getControl().getId(); + try { + SimulationLoggerUtil.showSimulationLogConsole(queueUI, id); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error(t("Can't open log for %s", id), eee); + } + ErrorHelper.showErrorDialog(t("Can't open log for %s", id), eee); + } + } + } + + /** + * Remove all done jobs. + */ + protected void clearDoneJobs() { + SimulationService ss = SimulationService.getService(); + ss.clearJobDone(); + } +} Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueUI.jaxx 2015-05-20 12:58:46 UTC (rev 4228) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/queue/QueueUI.jaxx 2015-05-20 13:11:09 UTC (rev 4229) @@ -23,44 +23,42 @@ #L% --> <Table> - <import> - fr.ifremer.isisfish.simulator.launcher.SimulationServiceTableModel; - fr.ifremer.isisfish.simulator.launcher.SimulationService; - javax.swing.JProgressBar; - javax.swing.ListSelectionModel; - </import> - - <script><![CDATA[ - queueTable.setDefaultRenderer(JProgressBar.class, new ComponentTableCellRenderer()); - queueTableDone.setDefaultRenderer(JProgressBar.class, new ComponentTableCellRenderer()); - ]]> - </script> + <import> + fr.ifremer.isisfish.simulator.launcher.SimulationService + fr.ifremer.isisfish.simulator.launcher.SimulationServiceTableModel + </import> + <script><![CDATA[ + protected void $afterCompleteSetup() { + handler.init(this); + } + ]]></script> + <Boolean id='canStop' javaBean='false'/> <Boolean id='canShowLog' javaBean='false'/> <Boolean id='canClear' javaBean='false'/> <Boolean id='canRestart' javaBean='false'/> - <QueueAction id="queueAction" javaBean='new QueueAction(this)'/> + <QueueHandler id="handler" /> <SimulationServiceTableModel id="newSimulationModel" javaBean='new SimulationServiceTableModel(SimulationService.getService(), true)'/> <SimulationServiceTableModel id="doneSimulationModel" javaBean='new SimulationServiceTableModel(SimulationService.getService(), false)' - onTableChanged='queueAction.updateActions()' /> + onTableChanged='handler.updateActions()' /> <PauseButtonModel id="autoLaunchButtonModel" javaBean='new PauseButtonModel(SimulationService.getService())'/> - <DefaultListSelectionModel id="selectionModelQueueTable" onValueChanged='queueAction.updateActions()'/> - <DefaultListSelectionModel id="selectionModelQueueTableDone" onValueChanged='queueAction.updateActions()'/> + <DefaultListSelectionModel id="selectionModelQueueTable" onValueChanged='handler.updateActions()'/> + <DefaultListSelectionModel id="selectionModelQueueTableDone" onValueChanged='handler.updateActions()'/> <row> <cell columns="5" fill="both" weightx="1.0" weighty="0.5"> <JSplitPane oneTouchExpandable="true" orientation="VERTICAL" resizeWeight="0.5"> <JScrollPane> <JTable id="queueTable" model='{newSimulationModel}' - selectionMode="{ListSelectionModel.MULTIPLE_INTERVAL_SELECTION}" + selectionMode="{javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION}" selectionModel="{selectionModelQueueTable}"/> </JScrollPane> <JScrollPane> <JTable id="queueTableDone" model='{doneSimulationModel}' - selectionMode="{ListSelectionModel.SINGLE_SELECTION}" + selectionMode="{javax.swing.ListSelectionModel.SINGLE_SELECTION}" selectionModel="{selectionModelQueueTableDone}" /> </JScrollPane> </JSplitPane> @@ -71,16 +69,16 @@ <JToggleButton id="autoLaunchButton" text="isisfish.queue.simulationLaunch" model="{autoLaunchButtonModel}"/> </cell> <cell fill="horizontal" weightx="0.3"> - <JButton id="stopSimuButton" text="isisfish.queue.stopSimulation" onActionPerformed='queueAction.stopSimulation()' enabled='{isCanStop()}' /> + <JButton id="stopSimuButton" text="isisfish.queue.stopSimulation" onActionPerformed='handler.stopSimulation()' enabled='{isCanStop()}' /> </cell> <cell fill="horizontal" weightx="0.3"> - <JButton id="restartSimulationButton" text="isisfish.queue.restartSimulation" onActionPerformed='queueAction.restartSimulation()' enabled='{isCanRestart()}' /> + <JButton id="restartSimulationButton" text="isisfish.queue.restartSimulation" onActionPerformed='handler.restartSimulation()' enabled='{isCanRestart()}' /> </cell> <cell fill="horizontal" weightx="0.3"> - <JButton id="showLogButton" text="isisfish.queue.showLog" onActionPerformed='queueAction.viewLog()' enabled='{isCanShowLog()}' /> + <JButton id="showLogButton" text="isisfish.queue.showLog" onActionPerformed='handler.viewLog()' enabled='{isCanShowLog()}' /> </cell> <cell fill="horizontal" weightx="0.3"> - <JButton id="clearDoneJobsButton" text="isisfish.queue.clearDone" onActionPerformed='queueAction.clearDoneJobs()' enabled='{isCanClear()}' /> + <JButton id="clearDoneJobsButton" text="isisfish.queue.clearDone" onActionPerformed='handler.clearDoneJobs()' enabled='{isCanClear()}' /> </cell> </row> </Table>
participants (1)
-
echatellier@users.forge.codelutin.com