From: <bea...@us...> - 2006-12-21 20:05:12
|
Revision: 362 http://svn.sourceforge.net/cishell/?rev=362&view=rev Author: bearsfan Date: 2006-12-21 12:05:06 -0800 (Thu, 21 Dec 2006) Log Message: ----------- Added play pause buttons to scheduler view, as well as making the view hideable. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.scheduler/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.scheduler/plugin.xml trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/Activator.java trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/pause.png trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/play.png trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerContentModel.java Modified: trunk/clients/gui/org.cishell.reference.gui.scheduler/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/META-INF/MANIFEST.MF 2006-12-21 18:17:26 UTC (rev 361) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/META-INF/MANIFEST.MF 2006-12-21 20:05:06 UTC (rev 362) @@ -11,5 +11,6 @@ Import-Package: org.cishell.app.service.scheduler, org.cishell.framework, org.cishell.framework.algorithm, - org.cishell.framework.data + org.cishell.framework.data, + org.cishell.reference.gui.workspace Export-Package: org.cishell.reference.gui.scheduler Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/pause.png =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/pause.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/play.png =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/play.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/clients/gui/org.cishell.reference.gui.scheduler/plugin.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/plugin.xml 2006-12-21 18:17:26 UTC (rev 361) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/plugin.xml 2006-12-21 20:05:06 UTC (rev 362) @@ -1,6 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.2"?> <plugin> + <extension + point="org.eclipse.ui.startup"> + <startup class="org.cishell.reference.gui.scheduler.Activator"/> + </extension> + <extension point="org.eclipse.ui.views"> <view Modified: trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/Activator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/Activator.java 2006-12-21 18:17:26 UTC (rev 361) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/Activator.java 2006-12-21 20:05:06 UTC (rev 362) @@ -3,19 +3,29 @@ import java.io.File; import org.cishell.app.service.scheduler.SchedulerService; +import org.cishell.reference.gui.workspace.CIShellApplication; import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IStartup; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; + /** * The activator class controls the plug-in life cycle */ -public class Activator extends AbstractUIPlugin { +public class Activator extends AbstractUIPlugin implements IStartup { public static final String PLUGIN_ID = "org.cishell.reference.gui.scheduler"; private static Activator plugin; private static BundleContext context; + private boolean waitForBundleContext; public Activator() { plugin = this; @@ -23,7 +33,10 @@ public void start(BundleContext context) throws Exception { super.start(context); - Activator.context = context; + Activator.context = context; + if (waitForBundleContext) { + earlyStartup(); + } } public void stop(BundleContext context) throws Exception { @@ -61,4 +74,49 @@ return null; } } + + public void earlyStartup() { + if (context != null) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + Action scheduler = new SchedulerAction(); + IMenuManager manager = CIShellApplication.getMenuManager(); + manager = manager.findMenuUsingPath("tools"); + manager.appendToGroup("start", scheduler); + SchedulerView view = SchedulerView.getDefault(); + boolean visible = view != null + && PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getActivePage() + .isPartVisible(view); + scheduler.setChecked(visible); + CIShellApplication.getMenuManager().update(true); + } + }); + waitForBundleContext = false; + } + else { + waitForBundleContext = true; + } + } + + private class SchedulerAction extends Action { + public SchedulerAction(){ + super("Scheduler", IAction.AS_CHECK_BOX); + setId("scheduler"); + } + + public void run(){ + if(this.isChecked()){ + try { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(SchedulerView.ID_VIEW); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + else{ + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(SchedulerView.getDefault()); + } + } + } + } Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerContentModel.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerContentModel.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerContentModel.java 2006-12-21 20:05:06 UTC (rev 362) @@ -0,0 +1,119 @@ +package org.cishell.reference.gui.scheduler; + +import java.util.Calendar; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Vector; + +import org.cishell.app.service.scheduler.SchedulerListener; +import org.cishell.app.service.scheduler.SchedulerService; +import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.data.Data; + + +public class SchedulerContentModel implements SchedulerListener { + private static final SchedulerContentModel INSTANCE = new SchedulerContentModel(); + + private SchedulerService schedulerService; + private List schedulerListenerList; + private Map classNameToPersistentMap; + + private boolean isRunning; + + private SchedulerContentModel(){ + schedulerService = Activator.getSchedulerService(); + if (schedulerService != null) { + schedulerService.addSchedulerListener(this); + } + schedulerListenerList = new Vector(); + + classNameToPersistentMap = new Hashtable(); + } + + public static SchedulerContentModel getInstance(){ + return INSTANCE; + } + + public void register(SchedulerListener listener) { + schedulerListenerList.add(listener); + } + + public void deregister(SchedulerListener listener) { + schedulerListenerList.remove(listener); + } + + public void persistObject(String className, Object o) { + classNameToPersistentMap.put(className, o); + } + + public Object getPersistedObject(String className) { + return classNameToPersistentMap.get(className); + } + + public boolean isRunning() { + return schedulerService.isRunning(); + } + + public void algorithmError(Algorithm algorithm, Throwable error) { + for (int i = 0; i < schedulerListenerList.size(); ++i) { + SchedulerListener schedulerListener = (SchedulerListener)schedulerListenerList.get(i); + schedulerListener.algorithmError(algorithm, error); + } + } + + public void algorithmFinished(Algorithm algorithm, Data[] createdData) { + for (int i = 0; i < schedulerListenerList.size(); ++i) { + SchedulerListener schedulerListener = (SchedulerListener)schedulerListenerList.get(i); + schedulerListener.algorithmFinished(algorithm, createdData); + } + } + + public void algorithmRescheduled(Algorithm algorithm, Calendar time) { + for (int i = 0; i < schedulerListenerList.size(); ++i) { + SchedulerListener schedulerListener = (SchedulerListener)schedulerListenerList.get(i); + schedulerListener.algorithmRescheduled(algorithm, time); + } + } + + public void algorithmScheduled(Algorithm algorithm, Calendar time) { + for (int i = 0; i < schedulerListenerList.size(); ++i) { + SchedulerListener schedulerListener = (SchedulerListener)schedulerListenerList.get(i); + schedulerListener.algorithmScheduled(algorithm, time); + } + } + + public void algorithmStarted(Algorithm algorithm) { + for (int i = 0; i < schedulerListenerList.size(); ++i) { + SchedulerListener schedulerListener = (SchedulerListener)schedulerListenerList.get(i); + schedulerListener.algorithmStarted(algorithm); + } + } + + public void algorithmUnscheduled(Algorithm algorithm) { + for (int i = 0; i < schedulerListenerList.size(); ++i) { + SchedulerListener schedulerListener = (SchedulerListener)schedulerListenerList.get(i); + schedulerListener.algorithmUnscheduled(algorithm); + } + } + + public void schedulerCleared() { + for (int i = 0; i < schedulerListenerList.size(); ++i) { + SchedulerListener schedulerListener = (SchedulerListener)schedulerListenerList.get(i); + schedulerListener.schedulerCleared(); + } + } + + public void schedulerRunStateChanged(boolean isRunning) { + if (this.isRunning != isRunning) { + this.isRunning = isRunning; + schedulerService.setRunning(isRunning); + } + else { + for (int i = 0; i < schedulerListenerList.size(); ++i) { + SchedulerListener schedulerListener = (SchedulerListener)schedulerListenerList.get(i); + schedulerListener.schedulerRunStateChanged(this.isRunning); + } + } + } +} Modified: trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java 2006-12-21 18:17:26 UTC (rev 361) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java 2006-12-21 20:05:06 UTC (rev 362) @@ -2,9 +2,7 @@ import java.util.Calendar; -import org.cishell.app.service.scheduler.SchedulerService; import org.cishell.framework.algorithm.Algorithm; -import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.algorithm.ProgressMonitor; import org.cishell.framework.algorithm.ProgressTrackable; import org.eclipse.swt.SWT; @@ -14,50 +12,50 @@ import org.eclipse.swt.widgets.ProgressBar; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; -import org.osgi.framework.ServiceReference; public class SchedulerTableItem { - private SchedulerService schedulerService; private Algorithm algorithm; - private Calendar cal; + private Calendar cal; private String algorithmLabel; - private Table table; private TableItem tableItem; private TableEditor tableEditor; + private int progressSelection; private ProgressBar progressBar; private static Image checkedImage = Activator.createImage("check.gif"); private static Image uncheckedImage = Activator.createImage("uncheck.gif"); private static Image errorImage = Activator.createImage("error.gif"); + + private boolean encounteredError; private String workBeingDone; private boolean cancelRequested; private boolean pauseRequested; + private boolean started; private boolean done; private boolean isCancellable; private boolean isPauseable; + private boolean isWorkTrackable; private AlgorithmProgressMonitor algorithmProgressMonitor; - public SchedulerTableItem(SchedulerService schedulerService, Algorithm algorithm, - Calendar cal, Table table) { - this.schedulerService = schedulerService; + public SchedulerTableItem( String algorithmLabel, Algorithm algorithm, Calendar cal) { this.algorithm = algorithm; this.cal = cal; - this.table = table; + this.encounteredError = false; + this.cancelRequested = false; + this.started = false; this.done = false; this.isCancellable = false; this.isPauseable = false; + this.isWorkTrackable = false; - final ServiceReference serviceReference = schedulerService.getServiceReference(algorithm); - if (serviceReference != null) { - algorithmLabel = (String)serviceReference.getProperty(AlgorithmProperty.LABEL); - } + this.algorithmLabel = algorithmLabel; if (algorithm instanceof ProgressTrackable) { @@ -74,62 +72,77 @@ pauseRequested = request; } - public void initTableEntry(final int tblNdx) { - done = false; + public void initTableEntry(final Table table, final int tblNdx) { guiRun(new Runnable() { public void run() { - drawTableEntry(tblNdx, uncheckedImage, 0); + drawTableEntry(table, tblNdx); } }); } - public void finishTableEntry(final int tblNdx) { + public void finishTableEntry(final Table table) { done = true; + if (!tableItem.isDisposed()) { guiRun(new Runnable() { public void run() { - int currentTblNdx; - if (tblNdx == -1) { - currentTblNdx = table.indexOf(tableItem); - } - else { - currentTblNdx = tblNdx; - } - tableItem.dispose(); progressBar.dispose(); progressBar = new ProgressBar(table, SWT.NONE); - drawTableEntry(currentTblNdx, checkedImage, progressBar - .getMaximum()); + + progressSelection = progressBar.getMaximum(); + drawTableEntry(table, table.indexOf(tableItem)); } }); } } - public void moveTableEntry(final int tblNdx) { + public void moveTableEntry(final Table table, final int tblNdx) { guiRun(new Runnable() { public void run() { - Image image = tableItem.getImage(SchedulerView.COMPLETED_COLUMN); - int progressSelection = progressBar.getSelection(); - drawTableEntry(tblNdx, image, progressSelection); + //Image image = tableItem.getImage(SchedulerView.COMPLETED_COLUMN); + progressSelection = progressBar.getSelection(); + drawTableEntry(table, tblNdx); } }); } - private void drawTableEntry(final int tblNdx, final Image image, final int progressBarStatus) { + private void drawTableEntry(final Table table, final int tblNdx) { guiRun(new Runnable() { public void run() { if (tableItem != null) { tableItem.dispose(); } tableItem = new TableItem(table, SWT.NONE, tblNdx); - tableItem.setImage(SchedulerView.COMPLETED_COLUMN, image); + + if (done) { + tableItem.setImage(SchedulerView.COMPLETED_COLUMN, checkedImage); + } + else if (encounteredError) { + tableItem.setImage(SchedulerView.COMPLETED_COLUMN, errorImage); + } + else { + tableItem.setImage(SchedulerView.COMPLETED_COLUMN, uncheckedImage); + } + tableItem.setText(SchedulerView.ALGORITHM_COLUMN, algorithmLabel); setCalendar(); - if (progressBar == null) { + if (started) { + //if (progressBar == null || progressBar.isDisposed()) { + if (progressBar != null) + progressBar.dispose(); + if (isWorkTrackable || done) { + progressBar = new ProgressBar(table, SWT.NONE); + progressBar.setSelection(progressSelection); + } else { + progressBar = new ProgressBar(table, + SWT.INDETERMINATE); + } + //} + } + else { progressBar = new ProgressBar(table, SWT.NONE); } - progressBar.setSelection(progressBarStatus); tableEditor = new TableEditor(table); tableEditor.grabHorizontal = tableEditor.grabVertical = true; tableEditor.setEditor(progressBar, tableItem, @@ -137,23 +150,7 @@ } }); } - - private void createIndeterminateProgressBar() { - if (!tableItem.isDisposed()) { - guiRun(new Runnable() { - public void run() { - progressBar.dispose(); - progressBar = new ProgressBar(table, SWT.INDETERMINATE); - tableEditor = new TableEditor(table); - tableEditor.grabHorizontal = tableEditor.grabVertical = true; - tableEditor.setEditor(progressBar, tableItem, - SchedulerView.PERCENT_COLUMN); - } - }); - } - } - private void setCalendar() { guiRun(new Runnable() { public void run() { @@ -165,32 +162,31 @@ }); } - public void algorithmStarted() { - if (!(algorithm instanceof ProgressTrackable)) { - createIndeterminateProgressBar(); - } else { - ProgressMonitor monitor = ((ProgressTrackable) algorithm) - .getProgressMonitor(); - if (monitor == null) { - createIndeterminateProgressBar(); - } - } - } + public void algorithmStarted(Table table) { + done = false; + started = true; + drawTableEntry(table, table.indexOf(tableItem)); + } public void reschedule(Calendar cal) { this.cal = cal; setCalendar(); } - public void errorTableEntry(int tblNdx) { - drawTableEntry(tblNdx, errorImage, progressBar.getSelection()); + public void errorTableEntry(Table table) { + encounteredError = true; + drawTableEntry(table, table.indexOf(tableItem)); } public void refresh() { guiRun(new Runnable() { public void run() { - tableEditor.grabHorizontal = tableEditor.grabVertical = true; - tableEditor.setEditor(progressBar, tableItem, SchedulerView.PERCENT_COLUMN); + if (!progressBar.isDisposed()) { + progressBar.setSelection(progressSelection); + tableEditor.grabHorizontal = tableEditor.grabVertical = true; + tableEditor.setEditor(progressBar, tableItem, + SchedulerView.PERCENT_COLUMN); + } } }); } @@ -265,10 +261,12 @@ } public boolean isCancellable() { + if (done) return false; return isCancellable; } public boolean isPauseable() { + if (done) return false; return isPauseable; } @@ -277,16 +275,16 @@ } public boolean isPaused() { - if (algorithmProgressMonitor.isPaused()) { - return false; + if (algorithmProgressMonitor.isPaused() && !done) { + return true; } else { - return true; + return false; } } public boolean isRunning() { - if (cancelRequested || done) { + if (cancelRequested) { return false; } return true; @@ -295,6 +293,10 @@ public boolean isDone() { return done; } + + public Algorithm getAlgorithm() { + return this.algorithm; + } private class AlgorithmProgressMonitor implements ProgressMonitor { private int totalWorkUnits; @@ -304,7 +306,7 @@ } public void done() { - finishTableEntry(-1); + done = true; } public boolean isCanceled() { @@ -332,8 +334,11 @@ isPauseable = true; } if ((capabilities & ProgressMonitor.WORK_TRACKABLE) > 0){ + refresh(); + isWorkTrackable = true; guiRun(new Runnable() { public void run() { + Table table = (Table)progressBar.getParent(); progressBar.dispose(); progressBar = new ProgressBar(table, SWT.NONE); progressBar.setSelection(progressBar.getMinimum()); @@ -347,15 +352,16 @@ } public void worked(final int work) { - if (!progressBar.isDisposed()) { - final int totalWorkUnits = this.totalWorkUnits; - guiRun(new Runnable() { - public void run() { - int progress = (int) (progressBar.getMaximum() * ((double) work / (double) totalWorkUnits)); - progressBar.setSelection(progress); + // final int totalWorkUnits = this.totalWorkUnits; + guiRun(new Runnable() { + public void run() { + if (!progressBar.isDisposed()) { + progressSelection = (int) (progressBar.getMaximum() * ((double) work / (double) totalWorkUnits)); + // progressBar.setSelection(progress); } - }); - } + } + }); + refresh(); } } -} +} \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java 2006-12-21 18:17:26 UTC (rev 361) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java 2006-12-21 20:05:06 UTC (rev 362) @@ -7,23 +7,24 @@ * http://www.apache.org/licenses/LICENSE-2.0.html * * Created on Aug 21, 2006 at Indiana University. + * Changed on Dec 19, 2006 at Indiana University * * Contributors: - * Weixia(Bonnie) Huang, Bruce Herr + * Weixia(Bonnie) Huang, Bruce Herr, Ben Markines * School of Library and Information Science, Indiana University * ***************************************************************************/ package org.cishell.reference.gui.scheduler; -import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.Hashtable; import java.util.Iterator; -import java.util.List; import java.util.Map; +import java.util.Set; import org.cishell.app.service.scheduler.SchedulerListener; -import org.cishell.app.service.scheduler.SchedulerService; import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.algorithm.ProgressMonitor; import org.cishell.framework.algorithm.ProgressTrackable; import org.cishell.framework.data.Data; @@ -51,25 +52,31 @@ import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import org.eclipse.ui.part.ViewPart; +import org.osgi.framework.ServiceReference; /** + * Creates and maintains the overall GUI for the scheduler. Controls the + * table and controls (moving, removing, etc.). + * * @author Ben Markines (bma...@cs...) */ public class SchedulerView extends ViewPart implements SchedulerListener { + private static SchedulerView schedulerView; + public static final String ID_VIEW = "org.cishell.reference.gui.scheduler.SchedulerView"; + private static Image upImage = Activator.createImage("up.gif"); private static Image downImage = Activator.createImage("down.gif"); - private static Image playImage = Activator.createImage("play.jpeg"); - private static Image pauseImage = Activator.createImage("pause.jpeg"); + private static Image playImage = Activator.createImage("play.png"); + private static Image pauseImage = Activator.createImage("pause.png"); + - private SchedulerService schedulerService; + private SchedulerContentModel schedulerContentModel; private Map algorithmToGuiItemMap; private Map tableItemToAlgorithmMap; - private List algorithmDoneList; private static Composite parent; - //private Button scheduleButton; private Button removeButton; private Button removeAutomatically; private Button up; @@ -77,15 +84,15 @@ private Menu menu; - private Button algorithmStateButton; - private boolean isActive; + private Button pauseStateButton; + private Button playStateButton; private Table table; private boolean autoRemove; - public static final int PAUSE_INDEX = 0; - public static final int CANCEL_INDEX = 1; - public static final int START_INDEX = 2; + public static final int RESUME_INDEX = 0; + public static final int PAUSE_INDEX = 1; + public static final int CANCEL_INDEX = 2; private PauseListener pauseListener; private CancelListener cancelListener; @@ -99,65 +106,45 @@ /** - * Constructor + * Registers itself to a model, and creates the map from algorithm to + * GUI item. */ public SchedulerView() { - schedulerService = Activator.getSchedulerService(); - if (schedulerService != null) { - schedulerService.addSchedulerListener(this); - } - algorithmToGuiItemMap = new Hashtable(); - tableItemToAlgorithmMap = new Hashtable(); - algorithmDoneList = new ArrayList(); - isActive = true; + schedulerContentModel = SchedulerContentModel.getInstance(); + + schedulerContentModel.register(this); + algorithmToGuiItemMap = (Map)schedulerContentModel.getPersistedObject(this.getClass().getName()); + if (algorithmToGuiItemMap == null) { + algorithmToGuiItemMap = Collections.synchronizedMap(new Hashtable()); + } + else { + algorithmToGuiItemMap = Collections.synchronizedMap(algorithmToGuiItemMap); + } + schedulerView = this; } + + /** + * Get the current scheduler view + * @return The scheduler view + */ + public static SchedulerView getDefault() { + return schedulerView; + } /** - * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) - */ + * Creates buttons, table, and registers listeners + * + * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) + * @param parent The SWT parent + */ public void createPartControl(Composite parent) { this.parent = parent; Composite control = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 4; - control.setLayout(layout); - //create the buttons - //scheduleButton = new Button(control, SWT.PUSH); - //scheduleButton.setText("Schedule..."); - //scheduleButton.setToolTipText( - // "Reschedule the selected item to another " + "date/time"); - //scheduleButton.setEnabled(false); - /* - scheduleButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - //this button is only enabled if a single selection is made - SchedulerItem item = currentSelection[0]; - SchedulerDialog dialog = new SchedulerDialog(); - Algorithm algorithm = item.getAlgorithm(); - IVC.getInstance().getScheduler().block(algorithm); - - boolean success = dialog.open(); - - if (success) { - Calendar date = dialog.getDate(); - boolean rescheduled = IVC.getInstance().getScheduler() - .reschedule(algorithm, date); - - if (rescheduled) { - //a new item is created on reschedule, get rid of the old one - //first set the name, this is a bit of a hack right now.. - model.getMostRecentAddition().setName(item.getName()); - model.remove(item); - } - } - - IVC.getInstance().getScheduler().unblock(algorithm); - } - }); - */ removeButton = new Button(control, SWT.PUSH); removeButton.setText("Remove From List"); removeButton.setEnabled(true); @@ -168,6 +155,7 @@ } }); + removeAutomatically = new Button(control, SWT.CHECK); removeAutomatically.setText("Remove completed automatically"); removeAutomatically.addSelectionListener(new SelectionAdapter() { @@ -179,31 +167,42 @@ Button removeAllCompleted = new Button(control, SWT.PUSH); removeAllCompleted.setText("Remove all completed"); removeAllCompleted.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - removeCompleted(); - refresh(); - } - }); + public void widgetSelected(SelectionEvent e) { + removeCompleted(); + refresh(); + } + }); -// algorithmStateButton = new Button(control, SWT.PUSH); -// algorithmStateButton.setImage(pauseImage); -// algorithmStateButton.addSelectionListener(new SelectionAdapter() { -// public void widgetSelected(SelectionEvent e) { -// if (isActive) { -// schedulerService.setRunning(false); -// } -// else { -// schedulerService.setRunning(true); -// } -// } -// }); + playStateButton = new Button(control, SWT.PUSH); + playStateButton.setImage(playImage); + playStateButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + //schedulerService.setRunning(true); + schedulerContentModel.schedulerRunStateChanged(true); + } + }); + pauseStateButton = new Button(control, SWT.PUSH); + pauseStateButton.setImage(pauseImage); + pauseStateButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + //schedulerService.setRunning(false); + schedulerContentModel.schedulerRunStateChanged(false); + } + }); - GridData removeAllCompletedData = new GridData(); - removeAllCompletedData.horizontalAlignment = SWT.RIGHT; + if (schedulerContentModel.isRunning()) { + playStateButton.setEnabled(false); + } + else { + pauseStateButton.setEnabled(false); + } + + GridData removeAllCompletedData = new GridData(); + removeAllCompletedData.horizontalAlignment = SWT.RIGHT; removeAllCompleted.setLayoutData(removeAllCompletedData); - //composite for up and down buttons and table + // composite for up and down buttons for table entries Composite tableComposite = new Composite(control, SWT.NONE); GridLayout tableCompositeLayout = new GridLayout(); tableCompositeLayout.numColumns = 2; @@ -237,15 +236,19 @@ // Create the table createTable(tableComposite); + createTableEntries(table); table.addSelectionListener(new TableListener()); - //table.addMouseListener(new ContextMenuListener()); - //Set right click menu menu = new Menu(table); menu.setVisible(false); + MenuItem startItem = new MenuItem(menu, SWT.PUSH); + startItem.setText("resume"); + startListener = new StartListener(); + startItem.addListener(SWT.Selection, startListener); + MenuItem pauseItem = new MenuItem(menu, SWT.PUSH); pauseItem.setText("pause"); pauseListener = new PauseListener(); @@ -256,27 +259,10 @@ cancelListener = new CancelListener(); cancelItem.addListener(SWT.Selection, cancelListener); - MenuItem startItem = new MenuItem(menu, SWT.PUSH); - startItem.setText("start"); - startListener = new StartListener(); - startItem.addListener(SWT.Selection, startListener); - table.setMenu(menu); GridData gridData = new GridData(GridData.FILL_BOTH); table.setLayoutData(gridData); - - /* - IMenuManager menu = IVCApplication.getMenuManager(); - IContributionItem item = menu.findUsingPath("tools/scheduler"); - if(item != null){ - final IAction action = ((ActionContributionItem) item).getAction(); - action.setChecked(true); - } - - //initialize based on data in the model - refreshView(); - */ } public void setFocus() { @@ -284,84 +270,169 @@ } - public void algorithmError(Algorithm algorithm, Throwable error) { - SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); - schedulerTableItem.errorTableEntry(table.indexOf(schedulerTableItem.getTableItem())); + /** + * Notifies the corresponding table item of the offending algorithm + * @param algorithm The algorithm that errored + * @param error The throwable object + */ + public void algorithmError(final Algorithm algorithm, Throwable error) { + guiRun(new Runnable() { + public void run() { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); + if (schedulerTableItem != null) + schedulerTableItem.errorTableEntry(table); + } + }); refresh(); } + /** + * Notifies the corresponding table entry when an algorithm has completed + * its' task + * + * @param algorithm The finished task + * @param createData List of data objects created + */ public void algorithmFinished(Algorithm algorithm, Data[] createdData) { SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); if (schedulerTableItem != null) { - TableItem tableItem = schedulerTableItem.getTableItem(); - tableItemToAlgorithmMap.remove(tableItem); - - schedulerTableItem.finishTableEntry(-1); + schedulerTableItem.finishTableEntry(table); + tableItemToAlgorithmMap.put(schedulerTableItem.getTableItem(), algorithm); if (autoRemove) { schedulerTableItem.remove(); + TableItem tableItem = schedulerTableItem.getTableItem(); + tableItemToAlgorithmMap.remove(tableItem); algorithmToGuiItemMap.remove(algorithm); - } else { - tableItem = schedulerTableItem.getTableItem(); - tableItemToAlgorithmMap.put(tableItem, algorithm); - algorithmDoneList.add(algorithm); - } + } } refresh(); } + /** + * Notifies the corresponding table item of an algorithm being rescheduled + * @param algorithm The task that is rescheduled + * @param time The rescheduled time + */ public void algorithmRescheduled(Algorithm algorithm, Calendar time) { SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); - schedulerTableItem.reschedule(time); + if (schedulerTableItem != null) + schedulerTableItem.reschedule(time); refresh(); } - public void algorithmScheduled(Algorithm algorithm, Calendar cal) { - SchedulerTableItem schedulerTableItem = new SchedulerTableItem(schedulerService, algorithm, cal, table); - schedulerTableItem.initTableEntry(0); - algorithmToGuiItemMap.put(algorithm, schedulerTableItem); + /** + * Creates a table item for the the algorithm, and adds an entry to the + * appropriate maps. + * @param algorithm The task that is to execute + * @param cal When the task will begin execution + */ + public void algorithmScheduled(final Algorithm algorithm, final Calendar cal) { + final Table table = this.table; + guiRun(new Runnable() { + public void run() { + ServiceReference serviceReference = Activator + .getSchedulerService().getServiceReference(algorithm); + String algorithmLabel = ""; + if (serviceReference != null) { + algorithmLabel = (String) serviceReference + .getProperty(AlgorithmProperty.LABEL); + } + + SchedulerTableItem schedulerTableItem = new SchedulerTableItem( + algorithmLabel, algorithm, cal); + schedulerTableItem.initTableEntry(table, 0); + algorithmToGuiItemMap.put(algorithm, schedulerTableItem); + + TableItem tableItem = schedulerTableItem.getTableItem(); + tableItemToAlgorithmMap.put(tableItem, algorithm); + } + }); - TableItem tableItem = schedulerTableItem.getTableItem(); - tableItemToAlgorithmMap.put(tableItem, algorithm); - refresh(); } - - public void algorithmStarted(Algorithm algorithm) { - SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); - schedulerTableItem.algorithmStarted(); + + /** + * Notifies the corresponding table item that an algorithm has started + * @param algorithm The task that is started + */ + public void algorithmStarted(final Algorithm algorithm) { + guiRun(new Runnable() { + public void run() { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem) algorithmToGuiItemMap + .get(algorithm); + schedulerTableItem.algorithmStarted(table); + TableItem tableItem = schedulerTableItem.getTableItem(); + tableItemToAlgorithmMap.put(tableItem, algorithm); + } + }); refresh(); } + /** + * Notifies the corresponding table item that an algorithm became unscheduled + * @param algorithm The task that became unscheduled + */ public void algorithmUnscheduled(Algorithm algorithm) { SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); schedulerTableItem.remove(); refresh(); } + /** + * Clear the current scheduler of all jobs + */ public void schedulerCleared() { - for (Iterator i = algorithmToGuiItemMap.values().iterator(); i.hasNext();) { - SchedulerTableItem schedulerTableItem = (SchedulerTableItem)i.next(); + for (Iterator i = algorithmToGuiItemMap.values().iterator(); i + .hasNext();) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem) i + .next(); schedulerTableItem.remove(); - } - algorithmToGuiItemMap.clear(); - tableItemToAlgorithmMap.clear(); + } + algorithmToGuiItemMap.clear(); + tableItemToAlgorithmMap.clear(); refresh(); } + /** + * Notification of the state of the scheduler has changed + * @param isRunning Flag determining if the scheduler is running + */ public void schedulerRunStateChanged(boolean isRunning) { - isActive = isRunning; - if (isActive) { - algorithmStateButton.setImage(pauseImage); + if (isRunning) { + pauseStateButton.setEnabled(true); + playStateButton.setEnabled(false); } else { - algorithmStateButton.setImage(playImage); + playStateButton.setEnabled(true); + pauseStateButton.setEnabled(false); } refresh(); } - - /* - * Create the Table control - */ + + /** + * This will create the table entries if there are any in the map + * @param table The parent table to create the entries + */ + private void createTableEntries(Table table) { + Set keys = algorithmToGuiItemMap.keySet(); + + tableItemToAlgorithmMap = Collections.synchronizedMap(new Hashtable()); + + for (Iterator i = keys.iterator(); i.hasNext();) { + Algorithm algorithm = (Algorithm) i.next(); + SchedulerTableItem schedulerTableItem = (SchedulerTableItem) algorithmToGuiItemMap + .get(algorithm); + schedulerTableItem.initTableEntry(table, 0); + + TableItem tableItem = schedulerTableItem.getTableItem(); + tableItemToAlgorithmMap.put(tableItem, algorithm); + } + } + + /** + * Create the Table control + * @param parent The parent of the Table + */ private void createTable(Composite parent) { int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION; @@ -395,23 +466,6 @@ column.setText("% Complete"); column.setWidth(120); -// //selection listener to keep currentSelection variable up to date -// table.addSelectionListener(new SelectionAdapter() { -// public void widgetSelected(SelectionEvent e) { -// TableItem[] selection = table.getSelection(); -// currentSelection = new SchedulerItem[selection.length]; -// -// for (int i = 0; i < selection.length; i++) { -// SchedulerItem item = SchedulerItem.getSchedulerItem(selection[i]); -// currentSelection[i] = item; -// } -// -// updateUpAndDown(); -// refreshButtons(); -// } -// }); -// -// //key listener to allow you to remove items with the delete key table.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if (e.keyCode == SWT.DEL) { @@ -427,48 +481,77 @@ table.addMouseListener(dragListener); } + /** + * Remove all of the table items that are selected + */ private void removeSelection() { - TableItem[] tableItems = table.getSelection(); - - for (int i = 0; i < tableItems.length; ++i) { - for (Iterator j = algorithmToGuiItemMap.keySet().iterator(); j.hasNext();) { - Algorithm algorithm = (Algorithm)j.next(); - SchedulerTableItem schedulerTableItem = - (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); - if (tableItems[i].equals(schedulerTableItem.getTableItem())) { - if (algorithmIsProgressTrackable(algorithm)) { - ProgressMonitor monitor = ((ProgressTrackable)algorithm).getProgressMonitor(); - monitor.setCanceled(true); - } - schedulerTableItem.remove(); - algorithmToGuiItemMap.remove(algorithm); - break; - } - } - } - } - + TableItem[] tableItems = table.getSelection(); + for (int i = 0; i < tableItems.length; ++i) { + for (Iterator j = algorithmToGuiItemMap.keySet().iterator(); j + .hasNext();) { + Algorithm algorithm = (Algorithm) j.next(); + SchedulerTableItem schedulerTableItem = (SchedulerTableItem) algorithmToGuiItemMap + .get(algorithm); + if (tableItems[i].equals(schedulerTableItem.getTableItem())) { + if (algorithmIsProgressTrackable(algorithm)) { + ProgressMonitor monitor = ((ProgressTrackable) algorithm) + .getProgressMonitor(); + monitor.setCanceled(true); + } + schedulerTableItem.remove(); + algorithmToGuiItemMap.remove(algorithm); + break; + } + } + } + } + + /** + * Removes the elements that have completed + * + */ private void removeCompleted() { - for (Iterator i = algorithmDoneList.iterator(); i.hasNext();) { - Object pid = i.next(); - SchedulerTableItem schedulerTableItem = - (SchedulerTableItem)algorithmToGuiItemMap.get(pid); - if (schedulerTableItem != null) { + for (Iterator i = algorithmToGuiItemMap.values().iterator(); i + .hasNext();) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem) i + .next(); + if (schedulerTableItem.isDone()) { + i.remove(); schedulerTableItem.remove(); - algorithmToGuiItemMap.remove(pid); } - } - algorithmDoneList.clear(); - } + } + } - private void refresh() { - for (Iterator i = algorithmToGuiItemMap.values().iterator(); i.hasNext();) { - SchedulerTableItem schedulerTableItem = (SchedulerTableItem)i.next(); + /** + * Cleans the tableItemToAlgorithmMap of disposed items. Refreshes + * each active table item. Refreshes the up and down buttons. + * + */ + private void refresh() { + for (Iterator i = tableItemToAlgorithmMap.keySet().iterator(); i + .hasNext();) { + final TableItem tableItem = (TableItem) i.next(); + if (tableItem.isDisposed()) { + i.remove(); + } + } + + for (Iterator i = algorithmToGuiItemMap.values().iterator(); i + .hasNext();) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem) i + .next(); schedulerTableItem.refresh(); - } - refreshUpAndDownButtons(); - } + } + refreshUpAndDownButtons(); + } + /** + * Check whether or not the algorithm implements the interface + * ProgressTrackable + * + * @param algorithm The algorithm to interrogate + * @return Whether or not the algorithm is trackable + */ private boolean algorithmIsProgressTrackable(Algorithm algorithm) { if (algorithm != null) { ProgressMonitor monitor = ((ProgressTrackable) algorithm) @@ -480,31 +563,49 @@ return false; } + /** + * Given an + * @param algorithm + */ private void setEnabledMenuItems(Algorithm algorithm) { SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); - if (!schedulerTableItem.isRunning()) { + //if (!schedulerTableItem.isRunning()) { for (int i = 0; i < menu.getItemCount(); ++i) { MenuItem menuItem = menu.getItem(i); menuItem.setEnabled(false); } - } - else { - MenuItem menuItem = menu.getItem(CANCEL_INDEX); - menuItem.setEnabled(schedulerTableItem.isCancellable()); + //} + //else { + if (schedulerTableItem.isRunning() && schedulerTableItem.isCancellable()) { + MenuItem menuItem = menu.getItem(CANCEL_INDEX); + menuItem.setEnabled(true); + //} + //else { + // MenuItem menuItem = menu.getItem(CANCEL_INDEX); + // menuItem.setEnabled(false); + } - if (schedulerTableItem.isPaused()) { - menuItem = menu.getItem(PAUSE_INDEX); - menuItem.setEnabled(schedulerTableItem.isPauseable()); - menuItem = menu.getItem(START_INDEX); - menuItem.setEnabled(false); - } else { - menuItem = menu.getItem(PAUSE_INDEX); - menuItem.setEnabled(false); - menuItem = menu.getItem(START_INDEX); - menuItem.setEnabled(schedulerTableItem.isPauseable()); + if (schedulerTableItem.isPauseable()) { + if (schedulerTableItem.isPaused()) { + //MenuItem menuItem = menu.getItem(PAUSE_INDEX); + //menuItem.setEnabled(false); + MenuItem menuItem = menu.getItem(RESUME_INDEX); + menuItem.setEnabled(true); + } else { + MenuItem menuItem = menu.getItem(PAUSE_INDEX); + menuItem.setEnabled(true); + //menuItem = menu.getItem(RESUME_INDEX); + //menuItem.setEnabled(false); + } } - } + //else { + // MenuItem menuItem = menu.getItem(PAUSE_INDEX); + // menuItem.setEnabled(false); + // menuItem = menu.getItem(RESUME_INDEX); + // menuItem.setEnabled(false); + //} + //} } private void moveTableItems(int ndxToMove, int destNdx) { @@ -516,7 +617,7 @@ SchedulerTableItem schedulerTableItem = (SchedulerTableItem) algorithmToGuiItemMap .get(algorithm); - schedulerTableItem.moveTableEntry(destNdx); + schedulerTableItem.moveTableEntry(table, destNdx); table.setSelection(destNdx); TableItem tableItem = schedulerTableItem.getTableItem(); @@ -558,6 +659,11 @@ Display.getDefault().syncExec(run); } } + + public void dispose() { + schedulerContentModel.persistObject(this.getClass().getName(), algorithmToGuiItemMap); + schedulerContentModel.deregister(this); + } private class TableListener extends SelectionAdapter { @@ -567,17 +673,17 @@ TableItem item = items[i]; Algorithm algorithm = (Algorithm) tableItemToAlgorithmMap .get(item); - if (algorithmIsProgressTrackable(algorithm)) { - removeButton.setEnabled(true); - setEnabledMenuItems(algorithm); - } else { - SchedulerTableItem schedulerTableItem = (SchedulerTableItem) algorithmToGuiItemMap - .get(algorithm); - if (schedulerTableItem.isDone()) { + if (algorithm != null) { + if (algorithmIsProgressTrackable(algorithm)) { removeButton.setEnabled(true); } else { - removeButton.setEnabled(false); - break; + SchedulerTableItem schedulerTableItem = (SchedulerTableItem) algorithmToGuiItemMap + .get(algorithm); + if (schedulerTableItem.isDone()) { + removeButton.setEnabled(true); + } else { + removeButton.setEnabled(false); + } } setEnabledMenuItems(algorithm); } @@ -645,24 +751,6 @@ int tblNdx = table.getSelectionIndex(); if (tblNdx != -1) { moveTableItems(tblNdx, tblNdx-1); -// -// TableItem item = table.getItem(tblNdx); -// if (item != null && tblNdx > 0) { -// Algorithm algorithm = (Algorithm) tableItemToAlgorithmMap -// .get(item); -// tableItemToAlgorithmMap.remove(item); -// item.dispose(); -// -// SchedulerTableItem schedulerTableItem = (SchedulerTableItem) algorithmToGuiItemMap -// .get(algorithm); -// schedulerTableItem.createTableEntry(tblNdx-1); -// table.setSelection(tblNdx-1); -// -// TableItem tableItem = schedulerTableItem.getTableItem(); -// tableItemToAlgorithmMap.put(tableItem, algorithm); -// -// refresh(); -// } } } } @@ -707,11 +795,11 @@ //reset the selected item and set the flag that the mouse is down public void mouseDown(MouseEvent e) { + TableItem item = table.getItem(new Point(e.x, e.y)); + if(item == null) return; + if (e.button == 1) { down = true; - - TableItem item = table.getItem(new Point(e.x, e.y)); - if(item == null) return; movingAlgorithm = (Algorithm) tableItemToAlgorithmMap.get(item); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |