Skip to content

Commit 55ec079

Browse files
fedejeanner-mennig
andcommitted
Add button to cancel job family to the JobsView
The JobsView can be opened with Ctrl+3 -> "Job Factory" Co-authored-by: Robin Mennig <Robin.Mennig@vector.com>
1 parent 86a07a0 commit 55ec079

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

  • examples
    • org.eclipse.e4.ui.examples.job/src/org/eclipse/e4/ui/examples/jobs/views
    • org.eclipse.ui.examples.job/src/org/eclipse/ui/examples/jobs/views

examples/org.eclipse.e4.ui.examples.job/src/org/eclipse/e4/ui/examples/jobs/views/JobsView.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,19 @@ public void widgetSelected(SelectionEvent e) {
247247
}
248248
});
249249

250-
// join the running test jobs
250+
// Cancel the job family (all TestJobs have the same family)
251+
Button cancelFamily = new Button(group, SWT.PUSH);
252+
cancelFamily.setText("Cancel Job family"); //$NON-NLS-1$
253+
cancelFamily.setToolTipText("IJobManager.cancel() on test jobs"); //$NON-NLS-1$
254+
cancelFamily.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
255+
cancelFamily.addSelectionListener(new SelectionAdapter() {
256+
@Override
257+
public void widgetSelected(SelectionEvent e) {
258+
cancelTestJobs();
259+
}
260+
});
261+
262+
// Put all jobs to sleep
251263
Button sleep = new Button(group, SWT.PUSH);
252264
sleep.setText("Sleep"); //$NON-NLS-1$
253265
sleep.setToolTipText("Calls sleep() on all TestJobs"); //$NON-NLS-1$
@@ -259,7 +271,7 @@ public void widgetSelected(SelectionEvent e) {
259271
}
260272
});
261273

262-
// join the running test jobs
274+
// Wake up all jobs
263275
Button wake = new Button(group, SWT.PUSH);
264276
wake.setText("WakeUp"); //$NON-NLS-1$
265277
wake.setToolTipText("Calls wakeUp() on all TestJobs"); //$NON-NLS-1$
@@ -540,6 +552,14 @@ protected void joinTestJobs() {
540552
}
541553
}
542554

555+
private void cancelTestJobs() {
556+
try {
557+
progressService.busyCursorWhile(monitor -> Job.getJobManager().cancel(TestJob.FAMILY_TEST_JOB));
558+
} catch (InterruptedException | InvocationTargetException e) {
559+
e.printStackTrace();
560+
}
561+
}
562+
543563
protected void progressNoFork() {
544564
try {
545565
final long duration = getDuration();

examples/org.eclipse.ui.examples.job/src/org/eclipse/ui/examples/jobs/views/JobsView.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,28 @@ private void createPushButtonGroup(Composite parent) {
214214
join.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
215215
join.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> joinTestJobs()));
216216

217-
// join the running test jobs
217+
// Cancel the job family (all TestJobs have the same family)
218+
Button cancelFamily = new Button(group, SWT.PUSH);
219+
cancelFamily.setText("Cancel Job family"); //$NON-NLS-1$
220+
cancelFamily.setToolTipText("IJobManager.cancel() on test jobs"); //$NON-NLS-1$
221+
cancelFamily.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
222+
cancelFamily.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> cancelTestJobs()));
223+
224+
// Use a runnable context
218225
Button window = new Button(group, SWT.PUSH);
219226
window.setText("Runnable in Window"); //$NON-NLS-1$
220227
window.setToolTipText("Using a runnable context in the workbench window"); //$NON-NLS-1$
221228
window.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
222229
window.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> runnableInWindow()));
223230

224-
// join the running test jobs
231+
// Put all jobs to sleep
225232
Button sleep = new Button(group, SWT.PUSH);
226233
sleep.setText("Sleep"); //$NON-NLS-1$
227234
sleep.setToolTipText("Calls sleep() on all TestJobs"); //$NON-NLS-1$
228235
sleep.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
229236
sleep.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> doSleep()));
230237

231-
// join the running test jobs
238+
// Wake up all jobs
232239
Button wake = new Button(group, SWT.PUSH);
233240
wake.setText("WakeUp"); //$NON-NLS-1$
234241
wake.setToolTipText("Calls wakeUp() on all TestJobs"); //$NON-NLS-1$
@@ -542,6 +549,15 @@ protected void joinTestJobs() {
542549
}
543550
}
544551

552+
private void cancelTestJobs() {
553+
try {
554+
PlatformUI.getWorkbench().getProgressService()
555+
.busyCursorWhile(monitor -> Job.getJobManager().cancel(TestJob.FAMILY_TEST_JOB));
556+
} catch (InterruptedException | InvocationTargetException e) {
557+
e.printStackTrace();
558+
}
559+
}
560+
545561
protected void progressNoFork() {
546562
try {
547563
final long duration = getDuration();

0 commit comments

Comments
 (0)