Some time you may need to do some long running operation in one of the pages in your wizard. Probably the best solution would be to redesign the flow of an application in such way that this operation can be performed outside the wizard as a background task (using Eclipse Jobs API). If you really need to place this inside wizard than in order to not freeze your application completely with such operation you can use IRunnableWithProgress. Sample usage of this interface is presented below.
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Logger;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
/**
* Wizard Page with long running operation
*
*/
public class DummyWizardPage extends WizardPage {
private Logger logger = Logger.getLogger(DummyWizardPage.class.getName());
protected DummyWizardPage(String pageName) {
super(pageName);
}
/**
* {@inheritDoc}
*/
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
Button button = new Button(composite, SWT.PUSH);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
try {
// Invoking long running operation
getContainer().run(true, false,
new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException,
InterruptedException {
// Some time consuming operation
}
});
} catch (InvocationTargetException e) {
logger.warning(e.getMessage());
} catch (InterruptedException e) {
logger.warning(e.getMessage());
}
}
});
// Setting control for Wizard Page
setControl(composite);
}
}