簡體   English   中英

如何在Eclipse RCP向導中顯示錯誤消息?

[英]How to display error message in an Eclipse RCP wizard?

我想顯示一條錯誤消息,該消息出現在向導窗口頂部的向導中(如下面的屏幕快照中的“ 無法創建項目內容...”消息)。

截圖

根據我在互聯網上發現的信息,我必須使用setErrorMessage方法來執行此操作。

但是它在我的向導類中不存在:

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
    }

如何設置向導的錯誤消息?

JFace的Wizard有頁面。 您可以自己創建這些頁面,並擴展WizardPage 在該類中,您將找到setErrorMessage API。

一種更快的替代方法是使用TitleAreaDialog ,它不需要頁面。 您也可以在那里使用錯誤API。


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 !!!!!");
        }

    }

}

setErrorMessageWizardPage一種方法,但不包含在IWizardContainer.getCurrentPage返回的IWizardPage接口中。

通常是您的向導頁面類設置錯誤消息-它們可以調用setErrorMessage(text)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM