Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.eclipse.e4.ui.progress/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.e4.ui.progress;singleton:=true
Bundle-Version: 0.5.200.qualifier
Bundle-Version: 0.6.0.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,23 @@ public void runInUI(IRunnableContext context,
public void busyCursorWhile(IRunnableWithProgress runnable)
throws InvocationTargetException, InterruptedException;

/**
* Same as {@link #busyCursorWhile(IRunnableWithProgress)}, but the Cancel
* button of the progress dialog is disabled from the start if
* <code>cancelable</code> is <code>false</code>. User input is blocked in the
* same way in both cases, so prefer a cancelable operation or a
* {@link Job} for operations that may take long.
*
* @param runnable The runnable to execute and show the progress for.
* @param cancelable <code>true</code> if the user may cancel the operation,
* <code>false</code> if it can't be canceled
* @throws InvocationTargetException if executed operation failed
* @throws InterruptedException if operation is interrupted
* @since 0.6
*/
public void busyCursorWhile(IRunnableWithProgress runnable, boolean cancelable)
throws InvocationTargetException, InterruptedException;

/**
* This specialization of IRunnableContext#run(boolean, boolean,
* IRunnableWithProgress) might run the runnable asynchronously
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public Image getIconFor(Job job) {
@Override
public void busyCursorWhile(final IRunnableWithProgress runnable)
throws InvocationTargetException, InterruptedException {
busyCursorWhile(runnable, true);
}

@Override
public void busyCursorWhile(final IRunnableWithProgress runnable, final boolean cancelable)
throws InvocationTargetException, InterruptedException {
final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog(
ProgressManagerUtil.getDefaultParent(), this, progressManager,
contentProviderFactory, finishedJobs);
Expand All @@ -133,7 +139,7 @@ public void busyCursorWhile(final IRunnableWithProgress runnable)
try {
dialog.setOpenOnRun(false);
setUserInterfaceActive(false);
dialog.run(true, true, runnable);
dialog.run(true, cancelable, runnable);
} catch (InvocationTargetException e1) {
invokes[0] = e1;
} catch (InterruptedException e2) {
Expand Down Expand Up @@ -257,22 +263,29 @@ public IStatus getStatus() {
private void busyCursorWhile(Runnable dialogWaitRunnable,
ProgressMonitorJobsDialog dialog) {
// create the job that will open the dialog after a delay
scheduleProgressMonitorJob(dialog);
final Display display = getDisplay();
if (display == null) {
return;
Job showDialogJob = scheduleProgressMonitorJob(dialog);
try {
final Display display = getDisplay();
if (display == null) {
return;
}
// show a busy cursor until the dialog opens
BusyIndicator.showWhile(display, dialogWaitRunnable);
} finally {
// In case the dialog hasn't popped up yet, cancel it so it doesn't pop up after
// the operation finishes or unwinds with an exception.
showDialogJob.cancel();
}
// show a busy cursor until the dialog opens
BusyIndicator.showWhile(display, dialogWaitRunnable);
}

/**
* Schedule the job that will open the progress monitor dialog
*
* @param dialog
* the dialog to open
* @return the job that was scheduled to open the dialog
*/
private void scheduleProgressMonitorJob(
private Job scheduleProgressMonitorJob(
final ProgressMonitorJobsDialog dialog) {

Job updateJob = UIJob.create(ProgressMessages.ProgressManager_openJobName, monitor -> {
Expand All @@ -283,7 +296,7 @@ private void scheduleProgressMonitorJob(
});
updateJob.setSystem(true);
updateJob.schedule(getLongOperationTime());

return updateJob;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,12 @@ ImageData[] getImageData(URL fileSystemPath, ImageLoader loader) {
@Override
public void busyCursorWhile(final IRunnableWithProgress runnable)
throws InvocationTargetException, InterruptedException {
busyCursorWhile(runnable, true);
}

@Override
public void busyCursorWhile(final IRunnableWithProgress runnable, final boolean cancelable)
throws InvocationTargetException, InterruptedException {
final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog(ProgressManagerUtil.getDefaultParent());
dialog.setOpenOnRun(false);
final InvocationTargetException[] invokes = new InvocationTargetException[1];
Expand All @@ -928,7 +934,7 @@ public void busyCursorWhile(final IRunnableWithProgress runnable)
try {
dialog.setOpenOnRun(false);
setUserInterfaceActive(false);
dialog.run(true, true, runnable);
dialog.run(true, cancelable, runnable);
} catch (InvocationTargetException e1) {
invokes[0] = e1;
} catch (InterruptedException e2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ public void busyCursorWhile(IRunnableWithProgress runnable) throws InvocationTar
getWorkbenchProgressService().busyCursorWhile(runnable);
}

@Override
public void busyCursorWhile(IRunnableWithProgress runnable, boolean cancelable)
throws InvocationTargetException, InterruptedException {
getWorkbenchProgressService().busyCursorWhile(runnable, cancelable);
}

@Override
public void schedule(Job job, long delay, boolean useHalfBusyCursor) {
job.addJobChangeListener(getJobChangeListener(useHalfBusyCursor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ void runInUI(IRunnableContext context, IRunnableWithProgress runnable, IScheduli
*/
void busyCursorWhile(IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException;

/**
* Same as {@link #busyCursorWhile(IRunnableWithProgress)}, but the Cancel
* button of the progress dialog is disabled from the start if
* <code>cancelable</code> is <code>false</code>. User input is blocked in the
* same way in both cases, so prefer a cancelable operation or a
* {@link Job} for operations that may take long.
*
* @param runnable The runnable to execute and show the progress for.
* @param cancelable <code>true</code> if the user may cancel the operation,
* <code>false</code> if it can't be canceled
* @throws InvocationTargetException if executed operation failed
* @throws InterruptedException if operation is interrupted
* @since 3.141
*/
void busyCursorWhile(IRunnableWithProgress runnable, boolean cancelable)
throws InvocationTargetException, InterruptedException;

/**
* This specialization of IRunnableContext#run(boolean, boolean,
* IRunnableWithProgress) might run the runnable asynchronously if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Export-Package: org.eclipse.e4.ui.examples.jobs,
Require-Bundle: org.eclipse.core.resources,
org.eclipse.core.runtime,
org.eclipse.jface.text,
org.eclipse.e4.ui.progress;bundle-version="0.1.0",
org.eclipse.e4.ui.progress;bundle-version="0.6.0",
org.eclipse.swt;bundle-version="3.133.0",
org.eclipse.e4.ui.di,
org.eclipse.jface;bundle-version="3.10.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class JobsView {
private Text quantityField, delayField, rescheduleDelay;
private Button schedulingRuleField;
private Button noPromptField;
private Button cancelableField;

Composite parent;

Expand All @@ -79,13 +80,14 @@ protected void busyCursorWhile() {
try {
final long duration = getDuration();
final boolean shouldLock = lockField.getSelection();
final boolean cancelable = cancelableField.getSelection();
progressService.busyCursorWhile(
monitor -> {
if (shouldLock)
doRunInWorkspace(duration, monitor);
else
doRun(duration, monitor);
});
}, cancelable);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
Expand Down Expand Up @@ -201,7 +203,13 @@ public void widgetSelected(SelectionEvent e) {
});

// busy cursor while
Button busyWhile = new Button(group, SWT.PUSH);
Composite busyWhileRow = new Composite(group, SWT.NONE);
GridLayout busyWhileLayout = new GridLayout(2, false);
busyWhileLayout.marginWidth = 0;
busyWhileLayout.marginHeight = 0;
busyWhileRow.setLayout(busyWhileLayout);
busyWhileRow.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Button busyWhile = new Button(busyWhileRow, SWT.PUSH);
busyWhile.setText("busyCursorWhile"); //$NON-NLS-1$
busyWhile.setToolTipText("Uses IProgressService.busyCursorWhile"); //$NON-NLS-1$
busyWhile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Expand All @@ -211,6 +219,10 @@ public void widgetSelected(SelectionEvent e) {
busyCursorWhile();
}
});
cancelableField = new Button(busyWhileRow, SWT.CHECK);
cancelableField.setText("cancelable"); //$NON-NLS-1$
cancelableField.setToolTipText("Whether the Cancel button of busyCursorWhile is enabled"); //$NON-NLS-1$
cancelableField.setSelection(true);
// progress monitor dialog with fork=false
Button noFork = new Button(group, SWT.PUSH);
noFork.setText("runInUI"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ public class JobsView extends ViewPart {
private Text quantityField, delayField, rescheduleDelay;
private Button schedulingRuleField;
private Button noPromptField;
private Button cancelableField;

protected void busyCursorWhile() {
try {
final long duration = getDuration();
final boolean shouldLock = lockField.getSelection();
final boolean cancelable = cancelableField.getSelection();
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(
monitor -> {
if (shouldLock)
doRunInWorkspace(duration, monitor);
else
doRun(duration, monitor);
});
}, cancelable);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
Expand Down Expand Up @@ -188,11 +190,21 @@ private void createPushButtonGroup(Composite parent) {
touch.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
touch.addSelectionListener(SelectionListener.widgetSelectedAdapter(_ -> touchWorkspace()));
// busy cursor while
Button busyWhile = new Button(group, SWT.PUSH);
Composite busyWhileRow = new Composite(group, SWT.NONE);
GridLayout busyWhileLayout = new GridLayout(2, false);
busyWhileLayout.marginWidth = 0;
busyWhileLayout.marginHeight = 0;
busyWhileRow.setLayout(busyWhileLayout);
busyWhileRow.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Button busyWhile = new Button(busyWhileRow, SWT.PUSH);
busyWhile.setText("busyCursorWhile"); //$NON-NLS-1$
busyWhile.setToolTipText("Uses IProgressService.busyCursorWhile"); //$NON-NLS-1$
busyWhile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
busyWhile.addSelectionListener(SelectionListener.widgetSelectedAdapter(_ -> busyCursorWhile()));
cancelableField = new Button(busyWhileRow, SWT.CHECK);
cancelableField.setText("cancelable"); //$NON-NLS-1$
cancelableField.setToolTipText("Whether the Cancel button of busyCursorWhile is enabled"); //$NON-NLS-1$
cancelableField.setSelection(true);
// progress monitor dialog with fork=false
Button noFork = new Button(group, SWT.PUSH);
noFork.setText("runInUI"); //$NON-NLS-1$
Expand Down
Loading
Loading