From: <bea...@us...> - 2006-11-21 22:05:02
|
Revision: 335 http://svn.sourceforge.net/cishell/?rev=335&view=rev Author: bearsfan Date: 2006-11-21 14:04:58 -0800 (Tue, 21 Nov 2006) Log Message: ----------- Initial check in of scheduler viewer. Disabling the scheduler is not active. Grid is missing from the table. Start, pause, remove, and cancel are enabled. Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.scheduler/.classpath trunk/clients/gui/org.cishell.reference.gui.scheduler/.project trunk/clients/gui/org.cishell.reference.gui.scheduler/META-INF/ trunk/clients/gui/org.cishell.reference.gui.scheduler/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.scheduler/build.properties trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/ trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/check.gif trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/down.gif trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/error.gif trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/log_icon.gif trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/pause.jpeg trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/play.jpeg trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/uncheck.gif trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/up.gif trunk/clients/gui/org.cishell.reference.gui.scheduler/plugin.xml trunk/clients/gui/org.cishell.reference.gui.scheduler/src/ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/ 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: trunk/clients/gui/org.cishell.reference.gui.scheduler/.classpath =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/.classpath (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/.classpath 2006-11-21 22:04:58 UTC (rev 335) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath> Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/.project =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/.project (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/.project 2006-11-21 22:04:58 UTC (rev 335) @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.cishell.reference.gui.log</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/META-INF/MANIFEST.MF (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/META-INF/MANIFEST.MF 2006-11-21 22:04:58 UTC (rev 335) @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Scheduler GUI Plug-in +Bundle-SymbolicName: org.cishell.reference.gui.scheduler;singleton:=true +Bundle-Version: 0.2.1 +Bundle-Activator: org.cishell.reference.gui.scheduler.Activator +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime +Eclipse-LazyStart: true +Import-Package: org.cishell.app.service.scheduler, + org.cishell.framework, + org.cishell.framework.algorithm, + org.cishell.framework.data +Export-Package: org.cishell.reference.gui.scheduler Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/build.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/build.properties (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/build.properties 2006-11-21 22:04:58 UTC (rev 335) @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + icons/,\ + plugin.xml Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/check.gif =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/check.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/down.gif =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/down.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/error.gif =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/error.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/log_icon.gif =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/log_icon.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/pause.jpeg =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/pause.jpeg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/play.jpeg =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/play.jpeg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/uncheck.gif =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/uncheck.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/up.gif =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.scheduler/icons/up.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.scheduler/plugin.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/plugin.xml (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/plugin.xml 2006-11-21 22:04:58 UTC (rev 335) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.2"?> +<plugin> + <extension + point="org.eclipse.ui.views"> + <view + allowMultiple="false" + class="org.cishell.reference.gui.scheduler.SchedulerView" + icon="icons/log_icon.gif" + id="org.cishell.reference.gui.scheduler.SchedulerView" + name="Console"/> + </extension> +</plugin> Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/Activator.java 2006-11-21 22:04:58 UTC (rev 335) @@ -0,0 +1,64 @@ +package org.cishell.reference.gui.scheduler; + +import java.io.File; + +import org.cishell.app.service.scheduler.SchedulerService; +import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.graphics.Image; +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 static final String PLUGIN_ID = "org.cishell.reference.gui.scheduler"; + private static Activator plugin; + private static BundleContext context; + + public Activator() { + plugin = this; + } + + public void start(BundleContext context) throws Exception { + super.start(context); + Activator.context = context; + } + + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + public static Activator getDefault() { + return plugin; + } + + public static BundleContext getContext() { + return context; + } + + protected static SchedulerService getSchedulerService() { + ServiceReference serviceReference = context.getServiceReference(SchedulerService.class.getName()); + SchedulerService manager = null; + + if (serviceReference != null) { + manager = (SchedulerService) context.getService(serviceReference); + } + + return manager; + } + + public static Image createImage(String name){ + if(Platform.isRunning()){ + return AbstractUIPlugin. + imageDescriptorFromPlugin(PLUGIN_ID, + File.separator + "icons" + File.separator + name). + createImage(); + } + else { + return null; + } + } +} Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java 2006-11-21 22:04:58 UTC (rev 335) @@ -0,0 +1,316 @@ +package org.cishell.reference.gui.scheduler; + +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; +import org.eclipse.swt.custom.TableEditor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; +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 Table table; + private TableItem tableItem; + private TableEditor tableEditor; + 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 String workBeingDone; + private boolean cancelRequested; + private boolean pauseRequested; + + 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; + this.algorithm = algorithm; + this.cal = cal; + this.table = table; + + this.cancelRequested = false; + + this.isCancellable = false; + this.isPauseable = false; + this.isWorkTrackable = false; + + if (algorithm instanceof ProgressTrackable) { + algorithmProgressMonitor = new AlgorithmProgressMonitor(); + ((ProgressTrackable)algorithm).setProgressMonitor(algorithmProgressMonitor); + } + } + + public void requestCancel(boolean request) { + cancelRequested = request; + } + + public void requestPause(boolean request) { + pauseRequested = request; + } + + public void createTableEntry() { + final ServiceReference serviceReference = schedulerService.getServiceReference(algorithm); + if (serviceReference != null) { + final String label = (String)serviceReference.getProperty(AlgorithmProperty.LABEL); + + guiRun(new Runnable() { + public void run() { + tableItem = new TableItem(table, SWT.NONE); + tableItem.setImage(SchedulerView.COMPLETED_COLUMN, uncheckedImage); + tableItem.setText(SchedulerView.ALGORITHM_COLUMN, label); + setCalendar(); + + //progressBar = new ProgressBar(table, SWT.INDETERMINATE); + progressBar = new ProgressBar(table, SWT.NONE); + tableEditor = new TableEditor(table); + tableEditor.grabHorizontal = tableEditor.grabVertical = true; + tableEditor.setEditor(progressBar, tableItem, SchedulerView.PERCENT_COLUMN); + } + }); + } + } + + 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() { + final String date = getDateString(cal); + final String time = getTimeString(cal); + tableItem.setText(SchedulerView.DATE_COLUMN, date); + tableItem.setText(SchedulerView.TIME_COLUMN, time); + } + }); + } + + public void algorithmStarted() { + if (!(algorithm instanceof ProgressTrackable)) { + createIndeterminateProgressBar(); + } else { + ProgressMonitor monitor = ((ProgressTrackable) algorithm) + .getProgressMonitor(); + if (monitor == null) { + createIndeterminateProgressBar(); + } + } + } + + public void reschedule(Calendar cal) { + this.cal = cal; + setCalendar(); + } + + public void finishTableEntry() { + if (!tableItem.isDisposed()) { + guiRun(new Runnable() { + public void run() { + tableItem.setImage(SchedulerView.COMPLETED_COLUMN, + checkedImage); + + progressBar.dispose(); + progressBar = new ProgressBar(table, SWT.NONE); + progressBar.setSelection(progressBar.getMaximum()); + tableEditor = new TableEditor(table); + tableEditor.grabHorizontal = tableEditor.grabVertical = true; + tableEditor.setEditor(progressBar, tableItem, + SchedulerView.PERCENT_COLUMN); + } + }); + } + } + + public void errorTableEntry() { + guiRun(new Runnable() { + public void run() { + tableItem.setImage(SchedulerView.COMPLETED_COLUMN, errorImage); + } + }); + finishTableEntry(); + } + + public void refresh() { + guiRun(new Runnable() { + public void run() { + tableEditor.grabHorizontal = tableEditor.grabVertical = true; + tableEditor.setEditor(progressBar, tableItem, SchedulerView.PERCENT_COLUMN); + } + }); + } + + public void remove() { + guiRun(new Runnable() { + public void run() { + progressBar.dispose(); + tableItem.dispose(); + } + }); + } + + public TableItem getTableItem() { + return tableItem; + } + + /* + * return a properly formatted date from the given Calendar + */ + private String getDateString(Calendar time) { + String month = (time.get(Calendar.MONTH) + 1) + ""; + String day = time.get(Calendar.DAY_OF_MONTH) + ""; + String year = time.get(Calendar.YEAR) + ""; + + if (month.length() == 1) { + month = "0" + month; + } + + if (day.length() == 1) { + day = "0" + day; + } + + return month + "/" + day + "/" + year; + } + + /* + * return a properly formatted time from the given Calendar + */ + private String getTimeString(Calendar time) { + String minute = time.get(Calendar.MINUTE) + ""; + String hour = time.get(Calendar.HOUR) + ""; + String second = time.get(Calendar.SECOND) + ""; + int ampm = time.get(Calendar.AM_PM); + String amPmString = "PM"; + + if (ampm == Calendar.AM) { + amPmString = "AM"; + } + + if (minute.length() == 1) { + minute = "0" + minute; + } + + if (hour.length() == 1) { + hour = "0" + hour; + } + + if (second.length() == 1) { + second = "0" + second; + } + + return hour + ":" + minute + ":" + second + " " + amPmString; + } + + private void guiRun(Runnable run) { + if (Thread.currentThread() == Display.getDefault().getThread()) { + run.run(); + } else { + Display.getDefault().syncExec(run); + } + } + + public boolean isCancellable() { + return isCancellable; + } + + public boolean isPauseable() { + return isPauseable; + } + + public boolean isWorkTrackable() { + return isWorkTrackable(); + } + + + private class AlgorithmProgressMonitor implements ProgressMonitor { + private int totalWorkUnits; + + public void describeWork(String currentWork) { + workBeingDone = currentWork; + } + + public void done() { + finishTableEntry(); + } + + public boolean isCanceled() { + return cancelRequested; + } + + public boolean isPaused() { + return pauseRequested; + } + + public void setCanceled(boolean value) { + cancelRequested = value; + } + + public void setPaused(boolean value) { + pauseRequested = value; + } + + public void start(int capabilities, int totalWorkUnits) { + if ((capabilities & ProgressMonitor.CANCELLABLE) > 0){ + isCancellable = true; + } + if ((capabilities & ProgressMonitor.PAUSEABLE) > 0){ + isPauseable = true; + } + if ((capabilities & ProgressMonitor.WORK_TRACKABLE) > 0){ + isWorkTrackable = true; + guiRun(new Runnable() { + public void run() { + progressBar.dispose(); + progressBar = new ProgressBar(table, SWT.NONE); + progressBar.setSelection(progressBar.getMinimum()); + tableEditor = new TableEditor(table); + tableEditor.grabHorizontal = tableEditor.grabVertical = true; + tableEditor.setEditor(progressBar, tableItem, SchedulerView.PERCENT_COLUMN); + } + }); + } + this.totalWorkUnits = totalWorkUnits; + } + + 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); + } + }); + } + } + } +} Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java 2006-11-21 22:04:58 UTC (rev 335) @@ -0,0 +1,541 @@ +/* **************************************************************************** + * CIShell: Cyberinfrastructure Shell, An Algorithm Integration Framework. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Apache License v2.0 which accompanies + * this distribution, and is available at: + * http://www.apache.org/licenses/LICENSE-2.0.html + * + * Created on Aug 21, 2006 at Indiana University. + * + * Contributors: + * Weixia(Bonnie) Huang, Bruce Herr + * 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.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +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.ProgressMonitor; +import org.cishell.framework.algorithm.ProgressTrackable; +import org.cishell.framework.data.Data; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.part.ViewPart; + + +/** + * @author Ben Markines (bma...@cs...) + */ +public class SchedulerView extends ViewPart implements SchedulerListener { + 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 SchedulerService schedulerService; + + 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; + private Button down; + + private Menu menu; + + private Button algorithmStateButton; + private boolean isActive; + + 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; + + private PauseListener pauseListener; + private CancelListener cancelListener; + private StartListener startListener; + + public static final int COMPLETED_COLUMN = 0; + public static final int ALGORITHM_COLUMN = 1; + public static final int DATE_COLUMN = 2; + public static final int TIME_COLUMN = 3; + public static final int PERCENT_COLUMN = 4; + + + /** + * Constructor + */ + public SchedulerView() { + schedulerService = Activator.getSchedulerService(); + if (schedulerService != null) { + schedulerService.addSchedulerListener(this); + } + algorithmToGuiItemMap = new Hashtable(); + tableItemToAlgorithmMap = new Hashtable(); + algorithmDoneList = new ArrayList(); + isActive = true; + } + + /** + * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) + */ + 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); + removeButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + removeSelection(); + refresh(); + } + }); + + removeAutomatically = new Button(control, SWT.CHECK); + removeAutomatically.setText("Remove completed automatically"); + removeAutomatically.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + autoRemove = removeAutomatically.getSelection(); + } + }); + + Button removeAllCompleted = new Button(control, SWT.PUSH); + removeAllCompleted.setText("Remove all completed"); + removeAllCompleted.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + removeCompleted(); + } + }); + +// 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); +// } +// } +// }); + + + GridData removeAllCompletedData = new GridData(); + removeAllCompletedData.horizontalAlignment = SWT.RIGHT; + removeAllCompleted.setLayoutData(removeAllCompletedData); + + //composite for up and down buttons and table + Composite tableComposite = new Composite(control, SWT.NONE); + GridLayout tableCompositeLayout = new GridLayout(); + tableCompositeLayout.numColumns = 2; + tableComposite.setLayout(tableCompositeLayout); + + GridData compositeData = new GridData(GridData.FILL_BOTH); + compositeData.horizontalSpan = 4; + tableComposite.setLayoutData(compositeData); + + //up and down buttons + Composite upAndDown = new Composite(tableComposite, SWT.NONE); + GridLayout upAndDownLayout = new GridLayout(); + upAndDownLayout.numColumns = 1; + upAndDown.setLayout(upAndDownLayout); + + up = new Button(upAndDown, SWT.PUSH); + up.setToolTipText( + "Moves the selected item up in the queue if possible. Only" + + " queued items can be moved without rescheduling."); + up.setEnabled(false); + up.setImage(upImage); + + /* + up.addSelectionListener(new UpButtonListener()); + */ + + down = new Button(upAndDown, SWT.PUSH); + down.setToolTipText( + "Moves the selected item down in the queue if possible. Only" + + " queued items can be moved without rescheduling."); + down.setEnabled(false); + down.setImage(downImage); + /* + down.addSelectionListener(new DownButtonListener()); + */ + + // Create the table + createTable(tableComposite); + + table.addSelectionListener(new ContextMenuListener()); + //table.addMouseListener(new ContextMenuListener()); + + + //Set right click menu + menu = new Menu(table); + menu.setVisible(false); + + MenuItem pauseItem = new MenuItem(menu, SWT.PUSH); + pauseItem.setText("pause"); + pauseListener = new PauseListener(); + pauseItem.addListener(SWT.Selection, pauseListener); + + MenuItem cancelItem = new MenuItem(menu, SWT.PUSH); + cancelItem.setText("cancel"); + 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() { + // TODO Auto-generated method stub + + } + + public void algorithmError(Algorithm algorithm, Throwable error) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); + schedulerTableItem.errorTableEntry(); + } + + public void algorithmFinished(Algorithm algorithm, Data[] createdData) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); + if (schedulerTableItem != null) { + schedulerTableItem.finishTableEntry(); + if (autoRemove) { + schedulerTableItem.remove(); + algorithmToGuiItemMap.remove(algorithm); + } else { + algorithmDoneList.add(algorithm); + } + } + } + + public void algorithmRescheduled(Algorithm algorithm, Calendar time) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); + schedulerTableItem.reschedule(time); + + } + + public void algorithmScheduled(Algorithm algorithm, Calendar cal) { + SchedulerTableItem schedulerTableItem = new SchedulerTableItem(schedulerService, algorithm, cal, table); + schedulerTableItem.createTableEntry(); + algorithmToGuiItemMap.put(algorithm, schedulerTableItem); + + TableItem tableItem = schedulerTableItem.getTableItem(); + tableItemToAlgorithmMap.put(tableItem, algorithm); + } + + public void algorithmStarted(Algorithm algorithm) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); + schedulerTableItem.algorithmStarted(); + } + + public void algorithmUnscheduled(Algorithm algorithm) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); + schedulerTableItem.remove(); + } + + public void schedulerCleared() { + for (Iterator i = algorithmToGuiItemMap.values().iterator(); i.hasNext();) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem)i.next(); + schedulerTableItem.remove(); + } + algorithmToGuiItemMap.clear(); + tableItemToAlgorithmMap.clear(); + } + + public void schedulerRunStateChanged(boolean isRunning) { + isActive = isRunning; + if (isActive) { + algorithmStateButton.setImage(pauseImage); + } + else { + algorithmStateButton.setImage(playImage); + } + } + + /* + * Create the Table control + */ + private void createTable(Composite parent) { + int style = SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | + SWT.FULL_SELECTION; + + table = new Table(parent, style); + table.setLinesVisible(true); + table.setHeaderVisible(true); + + // 1st column with checkboxes for completion + TableColumn column = new TableColumn(table, SWT.CENTER, 0); + column.setText("!"); + column.setWidth(20); + + // 2nd column with Algorithm name + column = new TableColumn(table, SWT.LEFT, 1); + column.setText("Algorithm Name"); + column.setWidth(150); + + // 3rd column with date + column = new TableColumn(table, SWT.LEFT, 2); + column.setText("Date"); + column.setWidth(90); + + // 4th column with time + column = new TableColumn(table, SWT.LEFT, 3); + column.setText("Time"); + column.setWidth(90); + + // 5th column with task PercentComplete + column = new TableColumn(table, SWT.CENTER, 4); + 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) { +// removeSelection(); +// } +// } +// }); +// +// //listener for dragging of items up and down in the running queue +// ItemDragListener dragListener = new ItemDragListener(); +// table.addMouseMoveListener(dragListener); +// table.addMouseListener(dragListener); + } + + 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; + } + } + } + } + + private void removeCompleted() { + for (Iterator i = algorithmDoneList.iterator(); i.hasNext();) { + Object pid = i.next(); + SchedulerTableItem schedulerTableItem = + (SchedulerTableItem)algorithmToGuiItemMap.get(pid); + if (schedulerTableItem != null) { + schedulerTableItem.remove(); + algorithmToGuiItemMap.remove(pid); + } + } + algorithmDoneList.clear(); + } + + private void refresh() { + for (Iterator i = algorithmToGuiItemMap.values().iterator(); i.hasNext();) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem)i.next(); + schedulerTableItem.refresh(); + } + } + + private boolean algorithmIsProgressTrackable(Algorithm algorithm) { + if (algorithm != null) { + ProgressMonitor monitor = ((ProgressTrackable) algorithm) + .getProgressMonitor(); + if (monitor != null) { + return true; + } + } + return false; + } + + private void setEnabledMenuItems(Algorithm algorithm) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); + + MenuItem menuItem = menu.getItem(CANCEL_INDEX); + menuItem.setEnabled(schedulerTableItem.isCancellable()); + + menuItem = menu.getItem(PAUSE_INDEX); + menuItem.setEnabled(schedulerTableItem.isPauseable()); + menuItem = menu.getItem(START_INDEX); + menuItem.setEnabled(schedulerTableItem.isPauseable()); + } + + private class ContextMenuListener extends SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + TableItem item = table.getItem(table.getSelectionIndex()); + if (item != null) { + Algorithm algorithm = (Algorithm)tableItemToAlgorithmMap.get(item); + if (algorithmIsProgressTrackable(algorithm)) { + setEnabledMenuItems(algorithm); + } + else { + setEnabledMenuItems(algorithm); + } + } + } + } + + + private class PauseListener implements Listener { + public void handleEvent(Event event) { + TableItem item = table.getItem(table.getSelectionIndex()); + if (item != null) { + Algorithm algorithm = (Algorithm)tableItemToAlgorithmMap.get(item); + if (algorithm instanceof ProgressTrackable) { + ProgressMonitor monitor = ((ProgressTrackable)algorithm).getProgressMonitor(); + if (monitor != null) { + monitor.setPaused(true); + } + } + } + } + } + + private class CancelListener implements Listener { + public void handleEvent(Event event) { + TableItem item = table.getItem(table.getSelectionIndex()); + if (item != null) { + Algorithm algorithm = (Algorithm) tableItemToAlgorithmMap + .get(item); + if (algorithm instanceof ProgressTrackable) { + ProgressMonitor monitor = ((ProgressTrackable) algorithm) + .getProgressMonitor(); + if (monitor != null) { + monitor.setCanceled(true); + } + } + } + } + } + + private class StartListener implements Listener { + + public void handleEvent(Event event) { + TableItem item = table.getItem(table.getSelectionIndex()); + if (item != null) { + Algorithm algorithm = (Algorithm) tableItemToAlgorithmMap + .get(item); + if (algorithm instanceof ProgressTrackable) { + ProgressMonitor monitor = ((ProgressTrackable) algorithm) + .getProgressMonitor(); + if (monitor != null) { + monitor.setPaused(false); + } + } + } + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |