From: <bea...@us...> - 2006-11-30 18:19:24
|
Revision: 342 http://svn.sourceforge.net/cishell/?rev=342&view=rev Author: bearsfan Date: 2006-11-30 10:19:10 -0800 (Thu, 30 Nov 2006) Log Message: ----------- All of the viewable functions for the scheduler viewer are there. Still need help with debugging, but checking it in to work on another bug. Modified Paths: -------------- 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/SchedulerTableItem.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java 2006-11-28 14:54:23 UTC (rev 341) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerTableItem.java 2006-11-30 18:19:10 UTC (rev 342) @@ -20,6 +20,7 @@ private SchedulerService schedulerService; private Algorithm algorithm; private Calendar cal; + private String algorithmLabel; private Table table; private TableItem tableItem; @@ -33,10 +34,10 @@ private String workBeingDone; private boolean cancelRequested; private boolean pauseRequested; + private boolean done; private boolean isCancellable; private boolean isPauseable; - private boolean isWorkTrackable; private AlgorithmProgressMonitor algorithmProgressMonitor; @@ -48,11 +49,17 @@ this.table = table; this.cancelRequested = 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); + } + + if (algorithm instanceof ProgressTrackable) { algorithmProgressMonitor = new AlgorithmProgressMonitor(); ((ProgressTrackable)algorithm).setProgressMonitor(algorithmProgressMonitor); @@ -67,28 +74,71 @@ pauseRequested = request; } - public void createTableEntry() { - final ServiceReference serviceReference = schedulerService.getServiceReference(algorithm); - if (serviceReference != null) { - final String label = (String)serviceReference.getProperty(AlgorithmProperty.LABEL); - + public void initTableEntry(final int tblNdx) { + done = false; + guiRun(new Runnable() { + public void run() { + drawTableEntry(tblNdx, uncheckedImage, 0); + } + }); + } + + public void finishTableEntry(final int tblNdx) { + done = true; + if (!tableItem.isDisposed()) { 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); + 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()); } }); } } + public void moveTableEntry(final int tblNdx) { + guiRun(new Runnable() { + public void run() { + Image image = tableItem.getImage(SchedulerView.COMPLETED_COLUMN); + int progressSelection = progressBar.getSelection(); + drawTableEntry(tblNdx, image, progressSelection); + } + }); + } + + private void drawTableEntry(final int tblNdx, final Image image, final int progressBarStatus) { + guiRun(new Runnable() { + public void run() { + if (tableItem != null) { + tableItem.dispose(); + } + tableItem = new TableItem(table, SWT.NONE, tblNdx); + tableItem.setImage(SchedulerView.COMPLETED_COLUMN, image); + tableItem.setText(SchedulerView.ALGORITHM_COLUMN, algorithmLabel); + setCalendar(); + + if (progressBar == null) { + progressBar = new ProgressBar(table, SWT.NONE); + } + progressBar.setSelection(progressBarStatus); + 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() { @@ -131,35 +181,11 @@ 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(int tblNdx) { + drawTableEntry(tblNdx, errorImage, progressBar.getSelection()); } - 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() { @@ -249,7 +275,26 @@ public boolean isWorkTrackable() { return isWorkTrackable(); } - + + public boolean isPaused() { + if (algorithmProgressMonitor.isPaused()) { + return false; + } + else { + return true; + } + } + + public boolean isRunning() { + if (cancelRequested || done) { + return false; + } + return true; + } + + public boolean isDone() { + return done; + } private class AlgorithmProgressMonitor implements ProgressMonitor { private int totalWorkUnits; @@ -259,7 +304,7 @@ } public void done() { - finishTableEntry(); + finishTableEntry(-1); } public boolean isCanceled() { @@ -275,10 +320,11 @@ } public void setPaused(boolean value) { - pauseRequested = value; + pauseRequested = value; } public void start(int capabilities, int totalWorkUnits) { + if ((capabilities & ProgressMonitor.CANCELLABLE) > 0){ isCancellable = true; } @@ -286,7 +332,6 @@ isPauseable = true; } if ((capabilities & ProgressMonitor.WORK_TRACKABLE) > 0){ - isWorkTrackable = true; guiRun(new Runnable() { public void run() { progressBar.dispose(); 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-11-28 14:54:23 UTC (rev 341) +++ trunk/clients/gui/org.cishell.reference.gui.scheduler/src/org/cishell/reference/gui/scheduler/SchedulerView.java 2006-11-30 18:19:10 UTC (rev 342) @@ -28,13 +28,21 @@ import org.cishell.framework.algorithm.ProgressTrackable; import org.cishell.framework.data.Data; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseMoveListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; 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.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; @@ -60,7 +68,7 @@ private Map tableItemToAlgorithmMap; private List algorithmDoneList; - //private static Composite parent; + private static Composite parent; //private Button scheduleButton; private Button removeButton; private Button removeAutomatically; @@ -108,7 +116,7 @@ * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ public void createPartControl(Composite parent) { - //this.parent = parent; + this.parent = parent; Composite control = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); @@ -173,6 +181,7 @@ removeAllCompleted.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { removeCompleted(); + refresh(); } }); @@ -216,10 +225,7 @@ " 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( @@ -227,14 +233,12 @@ " 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.addSelectionListener(new TableListener()); //table.addMouseListener(new ContextMenuListener()); @@ -282,45 +286,56 @@ public void algorithmError(Algorithm algorithm, Throwable error) { SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); - schedulerTableItem.errorTableEntry(); + schedulerTableItem.errorTableEntry(table.indexOf(schedulerTableItem.getTableItem())); + refresh(); } public void algorithmFinished(Algorithm algorithm, Data[] createdData) { SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); if (schedulerTableItem != null) { - schedulerTableItem.finishTableEntry(); + TableItem tableItem = schedulerTableItem.getTableItem(); + tableItemToAlgorithmMap.remove(tableItem); + + schedulerTableItem.finishTableEntry(-1); if (autoRemove) { schedulerTableItem.remove(); algorithmToGuiItemMap.remove(algorithm); } else { + tableItem = schedulerTableItem.getTableItem(); + tableItemToAlgorithmMap.put(tableItem, algorithm); algorithmDoneList.add(algorithm); } } + refresh(); } public void algorithmRescheduled(Algorithm algorithm, Calendar time) { SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); schedulerTableItem.reschedule(time); - + refresh(); } public void algorithmScheduled(Algorithm algorithm, Calendar cal) { SchedulerTableItem schedulerTableItem = new SchedulerTableItem(schedulerService, algorithm, cal, table); - schedulerTableItem.createTableEntry(); + schedulerTableItem.initTableEntry(0); algorithmToGuiItemMap.put(algorithm, schedulerTableItem); TableItem tableItem = schedulerTableItem.getTableItem(); tableItemToAlgorithmMap.put(tableItem, algorithm); + + refresh(); } public void algorithmStarted(Algorithm algorithm) { SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); schedulerTableItem.algorithmStarted(); + refresh(); } public void algorithmUnscheduled(Algorithm algorithm) { SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); schedulerTableItem.remove(); + refresh(); } public void schedulerCleared() { @@ -330,6 +345,7 @@ } algorithmToGuiItemMap.clear(); tableItemToAlgorithmMap.clear(); + refresh(); } public void schedulerRunStateChanged(boolean isRunning) { @@ -340,6 +356,7 @@ else { algorithmStateButton.setImage(playImage); } + refresh(); } /* @@ -395,18 +412,19 @@ // }); // // //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); + table.addKeyListener(new KeyAdapter() { + public void keyReleased(KeyEvent e) { + if (e.keyCode == SWT.DEL) { + removeSelection(); + refresh(); + } + } + }); + + //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() { @@ -443,11 +461,12 @@ algorithmDoneList.clear(); } - private void refresh() { + private void refresh() { for (Iterator i = algorithmToGuiItemMap.values().iterator(); i.hasNext();) { SchedulerTableItem schedulerTableItem = (SchedulerTableItem)i.next(); schedulerTableItem.refresh(); } + refreshUpAndDownButtons(); } private boolean algorithmIsProgressTrackable(Algorithm algorithm) { @@ -464,27 +483,106 @@ private void setEnabledMenuItems(Algorithm algorithm) { SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(algorithm); - MenuItem menuItem = menu.getItem(CANCEL_INDEX); - menuItem.setEnabled(schedulerTableItem.isCancellable()); + 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()); - menuItem = menu.getItem(PAUSE_INDEX); - menuItem.setEnabled(schedulerTableItem.isPauseable()); - menuItem = menu.getItem(START_INDEX); - menuItem.setEnabled(schedulerTableItem.isPauseable()); + 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()); + } + } } + + private void moveTableItems(int ndxToMove, int destNdx) { + TableItem item = table.getItem(ndxToMove); + if (item != null) { + Algorithm algorithm = (Algorithm) tableItemToAlgorithmMap + .get(item); + tableItemToAlgorithmMap.remove(item); - private class ContextMenuListener extends SelectionAdapter { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem) algorithmToGuiItemMap + .get(algorithm); + schedulerTableItem.moveTableEntry(destNdx); + table.setSelection(destNdx); + + TableItem tableItem = schedulerTableItem.getTableItem(); + tableItemToAlgorithmMap.put(tableItem, algorithm); + + refresh(); + } + } + + private void refreshUpAndDownButtons() { + guiRun(new Runnable() { + public void run() { + if (table.getItemCount() > 1 && table.getSelectionCount() == 1) { + if (table.getSelectionIndex() > 0) { + up.setEnabled(true); + } + else { + up.setEnabled(false); + } + if (table.getSelectionIndex() < table.getItemCount()-1) { + down.setEnabled(true); + } + else { + down.setEnabled(false); + } + } + else { + up.setEnabled(false); + down.setEnabled(false); + } + } + }); + } + + private void guiRun(Runnable run) { + if (Thread.currentThread() == Display.getDefault().getThread()) { + run.run(); + } else { + Display.getDefault().syncExec(run); + } + } + + + private class TableListener extends SelectionAdapter { public void widgetSelected(SelectionEvent e) { - TableItem item = table.getItem(table.getSelectionIndex()); - if (item != null) { - Algorithm algorithm = (Algorithm)tableItemToAlgorithmMap.get(item); + TableItem[] items = table.getSelection(); + for (int i = 0; i < items.length; ++i) { + TableItem item = items[i]; + Algorithm algorithm = (Algorithm) tableItemToAlgorithmMap + .get(item); if (algorithmIsProgressTrackable(algorithm)) { + removeButton.setEnabled(true); setEnabledMenuItems(algorithm); - } - else { + } else { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem) algorithmToGuiItemMap + .get(algorithm); + if (schedulerTableItem.isDone()) { + removeButton.setEnabled(true); + } else { + removeButton.setEnabled(false); + break; + } setEnabledMenuItems(algorithm); } } + refresh(); } } @@ -498,6 +596,7 @@ ProgressMonitor monitor = ((ProgressTrackable)algorithm).getProgressMonitor(); if (monitor != null) { monitor.setPaused(true); + setEnabledMenuItems(algorithm); } } } @@ -515,6 +614,7 @@ .getProgressMonitor(); if (monitor != null) { monitor.setCanceled(true); + setEnabledMenuItems(algorithm); } } } @@ -533,9 +633,99 @@ .getProgressMonitor(); if (monitor != null) { monitor.setPaused(false); + setEnabledMenuItems(algorithm); } } } } } + + private class UpButtonListener extends SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + 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(); +// } + } + } + } + + private class DownButtonListener extends SelectionAdapter { + public void widgetSelected(SelectionEvent e) { + int tblNdx = table.getSelectionIndex(); + if (tblNdx != -1) { + TableItem item = table.getItem(tblNdx); + if (item != null && tblNdx < table.getItemCount()-1) { + moveTableItems(tblNdx, tblNdx+1); + } + } + } + } + + private class ItemDragListener extends MouseAdapter implements MouseMoveListener { + private boolean down = false; + private Algorithm movingAlgorithm; + private int movingIndex; + private int currentIndex; + + //if the mouse is down (dragging), discover when it is dragged over + //a new table item and swap them if possible in the running queue + public void mouseMove(MouseEvent e) { + if (down && (movingAlgorithm != null)) { + SchedulerTableItem schedulerTableItem = (SchedulerTableItem)algorithmToGuiItemMap.get(movingAlgorithm); + TableItem movingTableItem = schedulerTableItem.getTableItem(); + + TableItem currentItem = table.getItem(new Point(e.x, e.y)); + + if (currentItem == null || movingTableItem.equals(currentItem)) { + return; + } + + movingIndex = table.indexOf(movingTableItem); + currentIndex = table.indexOf(currentItem); + + moveTableItems(movingIndex, currentIndex); + } + } + + //reset the selected item and set the flag that the mouse is down + public void mouseDown(MouseEvent e) { + 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); + } + } + + //unset the mouse down flag and clear the selected item + public void mouseUp(MouseEvent e) { + if (e.button == 1) { + down = false; + movingAlgorithm = null; + + Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_ARROW); + table.setCursor(cursor); + } + } + } } \ 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 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. |