1 11 package org.eclipse.ui.progress; 12 13 import org.eclipse.core.runtime.IStatus; 14 import org.eclipse.core.runtime.jobs.IJobChangeEvent; 15 import org.eclipse.core.runtime.jobs.JobChangeAdapter; 16 import org.eclipse.swt.widgets.Display; 17 import org.eclipse.ui.PlatformUI; 18 19 25 public abstract class WorkbenchJob extends UIJob { 26 27 37 public WorkbenchJob(Display jobDisplay, String name) { 38 super(jobDisplay, name); 39 addDefaultJobChangeListener(); 40 } 41 42 47 public WorkbenchJob(String name) { 48 super(name); 49 addDefaultJobChangeListener(); 50 } 51 52 57 private void addDefaultJobChangeListener() { 58 addJobChangeListener(new JobChangeAdapter() { 59 62 public void done(IJobChangeEvent event) { 63 64 if (!PlatformUI.isWorkbenchRunning()) { 66 return; 67 } 68 69 if (event.getResult().getCode() == IStatus.OK) { 70 performDone(event); 71 } 72 } 73 }); 74 } 75 76 83 public void performDone(IJobChangeEvent event) { 84 } 86 87 90 public boolean shouldSchedule() { 91 return super.shouldSchedule() && PlatformUI.isWorkbenchRunning(); 92 } 93 94 97 public boolean shouldRun() { 98 return super.shouldRun() && PlatformUI.isWorkbenchRunning(); 99 } 100 101 } 102 | Popular Tags |