001: package org.eclipse.ui.examples.jobs;
002:
003: import java.lang.reflect.InvocationTargetException;
004: import org.eclipse.core.runtime.IProgressMonitor;
005: import org.eclipse.jface.dialogs.IconAndMessageDialog;
006: import org.eclipse.jface.operation.IRunnableWithProgress;
007: import org.eclipse.swt.events.SelectionEvent;
008: import org.eclipse.swt.events.SelectionListener;
009: import org.eclipse.swt.graphics.Image;
010: import org.eclipse.swt.widgets.Button;
011: import org.eclipse.swt.widgets.Composite;
012: import org.eclipse.swt.widgets.Shell;
013: import org.eclipse.ui.PlatformUI;
014: import org.eclipse.ui.internal.progress.ProgressManager;
015:
016: /**
017: *BusyShowWhileDialog is a test of busyShowWhile in a modal dialog.
018: */
019: public class BusyShowWhileDialog extends IconAndMessageDialog {
020: /**
021: * @param parentShell
022: * @todo Generated comment
023: */
024: public BusyShowWhileDialog(Shell parentShell) {
025: super (parentShell);
026: message = "Busy While Test"; //$NON-NLS-1$
027: }
028:
029: /* (non-Javadoc)
030: * @see org.eclipse.jface.dialogs.IconAndMessageDialog#getImage()
031: */
032: protected Image getImage() {
033: return null;
034: }
035:
036: /* (non-Javadoc)
037: * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
038: */
039: protected void createButtonsForButtonBar(Composite parent) {
040: super .createButtonsForButtonBar(parent);
041: Button detailsButton = createButton(parent, 4,
042: "Start busy show while", false); //$NON-NLS-1$
043: detailsButton.addSelectionListener(new SelectionListener() {
044: /* (non-Javadoc)
045: * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
046: */
047: public void widgetSelected(SelectionEvent e) {
048: try {
049: ProgressManager.getInstance().busyCursorWhile(
050: new IRunnableWithProgress() {
051: /* (non-Javadoc)
052: * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
053: */
054: public void run(IProgressMonitor monitor)
055: throws InvocationTargetException,
056: InterruptedException {
057: long time = System
058: .currentTimeMillis();
059: long delay = PlatformUI
060: .getWorkbench()
061: .getProgressService()
062: .getLongOperationTime();
063: long end = time + delay + delay;
064: while (end > System
065: .currentTimeMillis()) {
066: final Shell myShell = BusyShowWhileDialog.this
067: .getShell();
068: myShell.getDisplay().asyncExec(
069: new Runnable() {
070: /* (non-Javadoc)
071: * @see java.lang.Runnable#run()
072: */
073: public void run() {
074: if (myShell
075: .isDisposed())
076: return;
077: myShell
078: .getDisplay()
079: .sleep();
080: myShell
081: .setText(String
082: .valueOf(System
083: .currentTimeMillis()));
084: }
085: });
086: }
087: }
088: });
089: } catch (InvocationTargetException error) {
090: error.printStackTrace();
091: } catch (InterruptedException error) {
092: //ignore - in this context it means cancelation
093: }
094: }
095:
096: /* (non-Javadoc)
097: * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
098: */
099: public void widgetDefaultSelected(SelectionEvent e) {
100: //do nothing
101: }
102: });
103: }
104: }
|