|
From: <bea...@us...> - 2006-12-21 22:23:54
|
Revision: 363
http://svn.sourceforge.net/cishell/?rev=363&view=rev
Author: bearsfan
Date: 2006-12-21 14:23:48 -0800 (Thu, 21 Dec 2006)
Log Message:
-----------
Cleaned some of the code up, added documentation
Modified Paths:
--------------
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/SchedulerTableItem.java
trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java
Modified: 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 2006-12-21 20:05:06 UTC (rev 362)
+++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerContentModel.java 2006-12-21 22:23:48 UTC (rev 363)
@@ -12,6 +12,9 @@
import org.cishell.framework.data.Data;
+/**
+ * Listens for notification from the scheduler and notifies all registered objects
+ */
public class SchedulerContentModel implements SchedulerListener {
private static final SchedulerContentModel INSTANCE = new SchedulerContentModel();
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 20:05:06 UTC (rev 362)
+++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java 2006-12-21 22:23:48 UTC (rev 363)
@@ -13,6 +13,10 @@
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
+/**
+ * Controls a single item in the table per algorithm, and monitors the algorithm
+ * if it is monitorable.
+ */
public class SchedulerTableItem {
private Algorithm algorithm;
private Calendar cal;
@@ -41,7 +45,14 @@
private AlgorithmProgressMonitor algorithmProgressMonitor;
- public SchedulerTableItem( String algorithmLabel, Algorithm algorithm, Calendar cal) {
+ /**
+ * Initializes flags and records the current algorithm to monitor
+ *
+ * @param algorithmLabel
+ * @param algorithm
+ * @param cal
+ */
+ public SchedulerTableItem(String algorithmLabel, Algorithm algorithm, Calendar cal) {
this.algorithm = algorithm;
this.cal = cal;
@@ -64,14 +75,28 @@
}
}
+ /**
+ * Request a cancel for the running algorithm
+ * @param request Cancel request
+ */
public void requestCancel(boolean request) {
cancelRequested = request;
}
+ /**
+ * Request the algorithm to pause
+ * @param request Pause request
+ */
public void requestPause(boolean request) {
pauseRequested = request;
}
+ /**
+ * Initialize the table entry with the parent table and location
+ * in the table
+ * @param table The parent table
+ * @param tblNdx The entry number to insert the table
+ */
public void initTableEntry(final Table table, final int tblNdx) {
guiRun(new Runnable() {
public void run() {
@@ -80,6 +105,10 @@
});
}
+ /**
+ * Mark the algorithm as finished
+ * @param table The parent table
+ */
public void finishTableEntry(final Table table) {
done = true;
@@ -96,16 +125,27 @@
}
}
+ /**
+ * Moves this entry to the provided index
+ * @param table The parent table
+ * @param tblNdx The target index into the table
+ */
public void moveTableEntry(final Table table, final int tblNdx) {
guiRun(new Runnable() {
public void run() {
- //Image image = tableItem.getImage(SchedulerView.COMPLETED_COLUMN);
progressSelection = progressBar.getSelection();
drawTableEntry(table, tblNdx);
}
});
}
-
+
+ /**
+ * Draws a table entry with the current state provided
+ * the parent table and index of the new entry
+ *
+ * @param table Parent table
+ * @param tblNdx Index into the table
+ */
private void drawTableEntry(final Table table, final int tblNdx) {
guiRun(new Runnable() {
public void run() {
@@ -128,19 +168,15 @@
setCalendar();
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 {
+ 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);
}
tableEditor = new TableEditor(table);
@@ -151,6 +187,9 @@
});
}
+ /**
+ * Sets the calendar entry for the current table.
+ */
private void setCalendar() {
guiRun(new Runnable() {
public void run() {
@@ -162,22 +201,39 @@
});
}
+ /**
+ * Notification of the start of the algorithm
+ *
+ * @param table The parent table
+ */
public void algorithmStarted(Table table) {
done = false;
started = true;
drawTableEntry(table, table.indexOf(tableItem));
}
+ /**
+ * Notification of rescheduling of the algorithm
+ * @param cal The rescheduled time
+ */
public void reschedule(Calendar cal) {
this.cal = cal;
setCalendar();
}
-
+
+ /**
+ * Notification of an error during algorithm execution
+ * @param table Parent table
+ */
public void errorTableEntry(Table table) {
encounteredError = true;
drawTableEntry(table, table.indexOf(tableItem));
}
+ /**
+ * Refresh the table item
+ *
+ */
public void refresh() {
guiRun(new Runnable() {
public void run() {
@@ -191,6 +247,10 @@
});
}
+ /**
+ * Removes the current table item
+ *
+ */
public void remove() {
guiRun(new Runnable() {
public void run() {
@@ -200,12 +260,17 @@
});
}
+ /**
+ * Returns the current table item
+ * @return current table item
+ */
public TableItem getTableItem() {
return tableItem;
}
- /*
- * return a properly formatted date from the given Calendar
+ /**
+ * A properly formatted date from the given Calendar
+ * @return formatted calendar
*/
private String getDateString(Calendar time) {
String month = (time.get(Calendar.MONTH) + 1) + "";
@@ -223,8 +288,9 @@
return month + "/" + day + "/" + year;
}
- /*
- * return a properly formatted time from the given Calendar
+ /**
+ * A properly formatted time from the given Calendar
+ * @return formatted calendar
*/
private String getTimeString(Calendar time) {
String minute = time.get(Calendar.MINUTE) + "";
@@ -252,6 +318,10 @@
return hour + ":" + minute + ":" + second + " " + amPmString;
}
+ /**
+ * Insures that the current thread is sync'd with the UI thread
+ * @param run
+ */
private void guiRun(Runnable run) {
if (Thread.currentThread() == Display.getDefault().getThread()) {
run.run();
@@ -260,20 +330,38 @@
}
}
+ /**
+ * Whether or not the current algorithm is cancellable, if the algorithm
+ * is done, it will return false.
+ * @return cancellable state
+ */
public boolean isCancellable() {
if (done) return false;
return isCancellable;
}
- public boolean isPauseable() {
+ /**
+ * Whether or not the current algorithm is pausable, if the algorithm
+ * is done, it will return false.
+ * @return Pausable state
+ */
+ public boolean isPausable() {
if (done) return false;
return isPauseable;
}
+ /**
+ * Whether or not the current algorithm is work trackable
+ * @return Trackable state
+ */
public boolean isWorkTrackable() {
return isWorkTrackable();
}
+ /**
+ * Whether or not the current algorithm is paused
+ * @return Paused state
+ */
public boolean isPaused() {
if (algorithmProgressMonitor.isPaused() && !done) {
return true;
@@ -283,6 +371,11 @@
}
}
+ /**
+ * Whether or not the current algorithm is running
+ *
+ * @return Running state
+ */
public boolean isRunning() {
if (cancelRequested) {
return false;
@@ -290,14 +383,19 @@
return true;
}
+ /**
+ * The algorithm done state
+ * @return Done state
+ */
public boolean isDone() {
return done;
}
- public Algorithm getAlgorithm() {
- return this.algorithm;
- }
-
+
+ /**
+ * Monitors an algorithm
+ *
+ */
private class AlgorithmProgressMonitor implements ProgressMonitor {
private int totalWorkUnits;
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 20:05:06 UTC (rev 362)
+++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java 2006-12-21 22:23:48 UTC (rev 363)
@@ -568,46 +568,35 @@
* @param algorithm
*/
private void setEnabledMenuItems(Algorithm algorithm) {
- SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm);
-
- //if (!schedulerTableItem.isRunning()) {
- for (int i = 0; i < menu.getItemCount(); ++i) {
- MenuItem menuItem = menu.getItem(i);
- menuItem.setEnabled(false);
- }
- //}
- //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);
- }
+ SchedulerTableItem schedulerTableItem = (SchedulerTableItem) algorithmToGuiItemMap
+ .get(algorithm);
- 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);
- }
+ for (int i = 0; i < menu.getItemCount(); ++i) {
+ MenuItem menuItem = menu.getItem(i);
+ menuItem.setEnabled(false);
+ }
+ if (schedulerTableItem.isRunning()
+ && schedulerTableItem.isCancellable()) {
+ MenuItem menuItem = menu.getItem(CANCEL_INDEX);
+ menuItem.setEnabled(true);
+ }
+
+ if (schedulerTableItem.isPausable()) {
+ if (schedulerTableItem.isPaused()) {
+ MenuItem menuItem = menu.getItem(RESUME_INDEX);
+ menuItem.setEnabled(true);
+ } else {
+ MenuItem menuItem = menu.getItem(PAUSE_INDEX);
+ menuItem.setEnabled(true);
}
- //else {
- // MenuItem menuItem = menu.getItem(PAUSE_INDEX);
- // menuItem.setEnabled(false);
- // menuItem = menu.getItem(RESUME_INDEX);
- // menuItem.setEnabled(false);
- //}
- //}
- }
+ }
+ }
+ /**
+ * Moves a table item to another slot
+ * @param ndxToMove Original table item to move
+ * @param destNdx Destination of table item
+ */
private void moveTableItems(int ndxToMove, int destNdx) {
TableItem item = table.getItem(ndxToMove);
if (item != null) {
@@ -627,6 +616,11 @@
}
}
+ /**
+ * Refreshes the up and down buttons depending on the items selected and location
+ * in the table
+ *
+ */
private void refreshUpAndDownButtons() {
guiRun(new Runnable() {
public void run() {
@@ -652,6 +646,10 @@
});
}
+ /**
+ * Insures that the current thread is the UI thread
+ * @param run Thread to sync with
+ */
private void guiRun(Runnable run) {
if (Thread.currentThread() == Display.getDefault().getThread()) {
run.run();
@@ -660,12 +658,19 @@
}
}
+ /**
+ * When the view is disposed, this will persist the current items
+ * it manages, and removes itself from the monitor
+ */
public void dispose() {
schedulerContentModel.persistObject(this.getClass().getName(), algorithmToGuiItemMap);
schedulerContentModel.deregister(this);
}
-
+ /**
+ * Any interaction to the table will be checked for enabling and
+ * disabling items in the table.
+ */
private class TableListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent e) {
TableItem[] items = table.getSelection();
@@ -693,6 +698,9 @@
}
+ /**
+ * Pauses an algorithm if it is pausable
+ */
private class PauseListener implements Listener {
public void handleEvent(Event event) {
TableItem item = table.getItem(table.getSelectionIndex());
@@ -709,6 +717,11 @@
}
}
+ /**
+ * Cancels an algorithm if it is cancellable
+ * @author bmarkine
+ *
+ */
private class CancelListener implements Listener {
public void handleEvent(Event event) {
TableItem item = table.getItem(table.getSelectionIndex());
@@ -727,8 +740,10 @@
}
}
- private class StartListener implements Listener {
-
+ /**
+ * Starts an algorithm to start
+ */
+ private class StartListener implements Listener {
public void handleEvent(Event event) {
TableItem item = table.getItem(table.getSelectionIndex());
if (item != null) {
@@ -746,6 +761,9 @@
}
}
+ /**
+ * Moves a table item up on the table
+ */
private class UpButtonListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent e) {
int tblNdx = table.getSelectionIndex();
@@ -755,6 +773,10 @@
}
}
+ /**
+ * Moves a table item down on the table
+ *
+ */
private class DownButtonListener extends SelectionAdapter {
public void widgetSelected(SelectionEvent e) {
int tblNdx = table.getSelectionIndex();
@@ -767,6 +789,9 @@
}
}
+ /**
+ * Listens for mouse dragging to move the items around the table
+ */
private class ItemDragListener extends MouseAdapter implements MouseMoveListener {
private boolean down = false;
private Algorithm movingAlgorithm;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|