📄 longrunningoperation.java
字号:
/*
* Created on 2005-1-6
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.hnjchina.dialogs;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
/**
* @author limeiyong
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class LongRunningOperation implements IRunnableWithProgress{
//The total sleep time
private static final int TOTAL_TIME = 10000;
// The increment sleep time
private static final int INCREMENT = 500;
private boolean indeterminate;
public LongRunningOperation(boolean indeterminate) {
this.indeterminate = indeterminate;
}
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Running long running operation",indeterminate ? IProgressMonitor.UNKNOWN : TOTAL_TIME);
for (int total = 0; total < TOTAL_TIME && !monitor.isCanceled();total += INCREMENT)
{
Thread.sleep(INCREMENT);
monitor.worked(INCREMENT);
if (total == TOTAL_TIME / 2) monitor.subTask("Doing second half");
}
monitor.done();
if (monitor.isCanceled())
throw new InterruptedException("The long running operation was cancelled");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -