|
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.
|