backButton = new Button(shell, SWT.PUSH);
backButton.setText("后台运行");
backButton.setBounds(264, 110, 80, 24);
backButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
final Work work = WorkDialog.this.work;
if (work != null && work.isBackable()) {
ThreadUtils.execute(new Runnable(){
public void run() {
try {
work.back();
} catch (final Throwable t) {
shell.getDisplay().asyncExec(new Runnable() {
public void run() {
MessageDialog.openError(shell, "后台运行", "后台运行传输项失败! 原因: " + t.getMessage());
}
});
}
}
});
}
}
});
abortButton = new Button(shell, SWT.PUSH);
abortButton.setText("中止");
abortButton.setBounds(348, 110, 80, 24);
abortButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
final Work work = WorkDialog.this.work;
if (work != null && work.isAbortable()) {
ThreadUtils.execute(new Runnable(){
public void run() {
try {
work.abort();
} catch (final Throwable t) {
shell.getDisplay().asyncExec(new Runnable() {
public void run() {
MessageDialog.openError(shell, "中止", "中止传输项失败! 原因: " + t.getMessage());
}
});
}
}
});
}
}
});
workListener = new WorkAdapter() { // 只在非UI线程执行
public void onForeWorking(WorkEvent event) {
if (UIUtils.isNonUIThread(event.getThread())) {
showWork(event.getWork());
}
}
public void onBackWorking(WorkEvent event) {
onWorked(event);
}
public void onWorked(WorkEvent event) {
if (UIUtils.isNonUIThread(event.getThread())) {
try {
if (Worker.getWorker().isForeWorking()) {
Work work = Worker.getWorker().getForeWorks().iterator().next();
showWork(work);
return;
}
} catch (Throwable t) {
// ignore