이미지출처 : www.mobilefish.com
EclipseRCP 백그라운드잡 템플릿 (EclipseRCP Background Job Template)
Code:
Job job = new Job("Title") { |
protected IStatus run(IProgressMonitor monitor) { |
monitor.beginTask(TaskName, totalWork); |
monitor.subTask(SubTaskName); |
monitor.worked(work); |
if (monitor.isCanceled()){ |
return Status.CANCEL_STATUS; |
} |
// try { Thread.sleep(1000); } catch (Exception e) { } |
Display.getDefault().asyncExec(new Runnable() { |
public void run() { |
// UI Update Jobs |
} |
}); |
|
return endJob(monitor); |
} |
}; |
|
// job.setUser(true); |
job.schedule(); |
|
public boolean isModal(Job job) { |
Boolean isModal = (Boolean)job.getProperty( |
IProgressConstants.PROPERTY_IN_DIALOG); |
if(isModal == null) return false; |
return isModal.booleanValue(); |
} |
protected Action getCompletedAction() { |
return new Action("View status") { |
public void run() { |
|
MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), |
dialogTitle, |
dialogContent); |
} |
}; |
} |
|
protected void showResults() { |
Display.getDefault().asyncExec(new Runnable() { |
public void run() { |
getCompletedAction().run(); |
} |
}); |
} |
|
protected IStatus endJob(IProgressMonitor monitor) { |
if (isModal(this)) { |
// The progress dialog is still open so |
// just open the message |
showResults(); |
} else { |
setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE); |
setProperty(IProgressConstants.ACTION_PROPERTY, |
getCompletedAction()); |
} |
monitor.done(); |
return Status.OK_STATUS; |
|
} |
by 月風