|
Re: How to use the progress monitor with a custom wizard [message #903484 is a reply to message #903398] |
Thu, 23 August 2012 19:59 |
Thorsten Schlathölter Messages: 312 Registered: February 2012 Location: Düsseldorf |
Senior Member |
|
|
Hi Gary,
its as simple as that. Use the wd.run() method to execute the code that needs the progress indicator. As soon as you begin the using the IProgressMonitor, the bar will become visible.
Here is a very simple example:
Wizard testWizard = new Wizard() {
@Override
public boolean performFinish() {
return false;
}
};
WizardPage page = new WizardPage("name","title",null) {
@Override
public void createControl(Composite arg0) {
Button button = new Button(arg0, SWT.PUSH);
setControl(button);
button.setText("press me");
button.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent arg0) {
try {
getContainer().run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor arg0)
throws InvocationTargetException,
InterruptedException {
int amount = 10;
arg0.beginTask("Task1", 10);
for (int i=0; i<amount;i++)
{
arg0.internalWorked(1);
Thread.sleep(2000);
if (arg0.isCanceled())
{
break;
}
}
}
});
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
}
});
}
};
testWizard.setNeedsProgressMonitor(true);
testWizard.addPage(page);
WizardDialog dialog = new WizardDialog(null, testWizard);
dialog.open();
[Updated on: Thu, 23 August 2012 20:04] Report message to a moderator
|
|
|
|
Re: How to use the progress monitor with a custom wizard [message #903849 is a reply to message #903542] |
Sun, 26 August 2012 12:26 |
Thorsten Schlathölter Messages: 312 Registered: February 2012 Location: Düsseldorf |
Senior Member |
|
|
Hi Gary,
the standard progress monitor functionality of WizardDialog is not intended for that purpose. In fact as soon as you start a run() operation via the WizardDialog, all wizard controls are disabled until the run() method has been completed. So you wouldn't even be able to press the next button. To accomplish the above requirement you have to manage the progress control yourself.
Here is a simple example which might already suit your needs:
package org.eclipse.swt.snippets;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.ProgressMonitorPart;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Snippet {
private class ProgressWizardPage extends WizardPage
{
public ProgressWizardPage(String pageName) {
super(pageName);
}
@Override
public void createControl(Composite arg0) {
Button button = new Button(arg0, SWT.PUSH);
setControl(button);
button.setText(getName()+": simple page control");
}
}
private class ProgressWizardDialog extends WizardDialog
{
ProgressMonitorPart part;
int pageCount = 1;
public ProgressWizardDialog(Shell parentShell, IWizard newWizard) {
super(parentShell, newWizard);
}
@Override
protected ProgressMonitorPart createProgressMonitorPart(
Composite composite, GridLayout pmlayout) {
part = super.createProgressMonitorPart(composite, pmlayout);
return part;
}
@Override
protected void nextPressed() {
super.nextPressed();
pageCount++;
updateWizardProgress();
}
@Override
protected void backPressed() {
super.backPressed();
pageCount--;
updateWizardProgress();
}
private void updateWizardProgress() {
getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
getProgressMonitor().beginTask("Completion: ", getWizard().getPageCount());
getProgressMonitor().worked(pageCount);
}
});
}
@Override
protected Control createContents(Composite parent) {
Control ret = super.createContents(parent);
part.setVisible(true);
updateWizardProgress();
return ret;
}
};
public static void main(String[] args) {
new Snippet().run();
}
public void run()
{
Display display = new Display();
final Wizard testWizard = new Wizard() {
@Override
public boolean performFinish() {
return false;
}
};
testWizard.setNeedsProgressMonitor(true);
for (int i=0;i<15;i++)
{
testWizard.addPage(new ProgressWizardPage("page"+i));
}
ProgressWizardDialog dialog = new ProgressWizardDialog(null, testWizard);
dialog.open();
display.dispose();
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.07615 seconds