Reputation: 18760
I want to display an error message, which appear in a wizard at the top of the wizard window (like Cannot create project content... message in the screenshot below).
According to what I found on the internets, I have to use the method setErrorMessage
to do this.
But it doesn't exist in my wizard class:
import org.eclipse.jface.wizard.Wizard;
public class MyWizard extends Wizard {
public MyWizard() {
super();
setErrorMessage("Error message"); // No such method
getContainer().getCurrentPage().setErrorMessage("Error message 2"); // This also doesn't exist
}
How can I set the error message of a wizard?
Upvotes: 2
Views: 3370
Reputation: 8960
JFace's Wizard
s have pages. You create these pages yourself, extending WizardPage
. In that class you will find the setErrorMessage
API.
A faster alternative would be to use a TitleAreaDialog
, which doesn't require pages. You can use the error API there as well.
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.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
*
* @author ggrec
*
*/
public class TestWizard extends Wizard
{
// ==================== 3. Static Methods ====================
public static void main(final String[] args)
{
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
final WizardDialog dialog = new WizardDialog(shell, new TestWizard());
dialog.open();
if (!display.readAndDispatch())
display.sleep();
display.dispose();
}
// ==================== 4. Constructors ====================
private TestWizard()
{
}
// ==================== 5. Creators ====================
@Override
public void addPages()
{
addPage(new TestPage());
// Or, you could make a local var out of the page,
// and set the error message here.
}
// ==================== 6. Action Methods ====================
@Override
public boolean performFinish()
{
return true;
}
// =======================================================
// 19. Inline Classes
// =======================================================
private class TestPage extends WizardPage
{
private TestPage()
{
super(TestPage.class.getCanonicalName());
}
@Override
public void createControl(final Composite parent)
{
setControl(new Composite(parent, SWT.NULL));
setErrorMessage("HOUSTON, WE'RE GOING DOWN !!!!!");
}
}
}
Upvotes: 3
Reputation: 111217
setErrorMessage
is a method in WizardPage
but it is not included in the IWizardPage
interface that IWizardContainer.getCurrentPage
returns.
It is usually your wizard page classes that set the error message - which they can do be calling setErrorMessage(text)
Upvotes: 4