Eclipse 插件 - 如何在命令处理程序中打开向导页面?

Eclipse Plugin - How to open a wizard page in a command handler?

我为eclipse写了一个插件。我在工具栏菜单中有一个按钮。我希望按下它 - 将打开一个向导页面对话框。我已经写了一个扩展向导并实现 IWizardPage 的 class,我还写了所有 5 个相关页面,我只是找不到任何方法在命令处理程序中打开它。

这是我的代码片段:

命令处理程序:

public class AddProjectHandler extends AbstractHandler {

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {

        return null;
    }
}

向导页面管理器:

public class NewProjectWizardManager extends Wizard implements INewWizard {


    private NewProjectWizardPage1 _page1;
    private NewProjectWizardPage2 _page2;
    private NewProjectWizardPage3 _page3;
    private NewProjectWizardPage4 _page4;
    private NewProjectWizardPage5 _page5;

    // constructor
    public NewProjectWizardManager() {
        super();
        setWindowTitle("New Project");
    }

    @Override
    public void init(IWorkbench workbench, IStructuredSelection selection) {
    }

    @Override
    public boolean performCancel() {

        return true;
    }

    @Override
    public void addPages() {
        super.addPages();
        _page1 = new NewProjectWizardPage1();
        addPage(_page1);
        _page2 = new NewProjectWizardPage2(_page1);
        addPage(_page2);
        _page3 = new NewProjectWizardPage3(_page1);
        addPage(_page3);
        _page4 = new NewProjectWizardPage4();
        addPage(_page4);
        _page5 = new NewProjectWizardPage5(_page1);
        addPage(_page5);
    }

    @Override
    public boolean canFinish() {
        IWizardContainer container = getContainer();
        if (_page5.equals(container.getCurrentPage())) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public IWizardPage getNextPage(IWizardPage page) {
        IWizardPage nextPage = super.getNextPage(page);
        IWizardContainer container = getContainer();
        if (nextPage != null) {
            if (_page2.equals(container.getCurrentPage()) && _page2.isCheckFinishChecked())
                nextPage = super.getNextPage(super.getNextPage(nextPage));
        }
        return nextPage;
    }

    @Override
    public boolean performFinish() {
}
}

plugin.xml件:

<command
                categoryId="com.commands.category"
                description="Add new Project"
                id="com.commands.AddProject"
                name="Add new Project">
</command>


<handler
                class="com.handlers.AddProjectHandler"
                commandId="com.commands.AddProject">
</handler>

你有什么想法吗?

使用WizardDialog显示向导。类似于:

public Object execute(ExecutionEvent event) throws ExecutionException
{
  Shell activeShell = HandlerUtil.getActiveShell(event);

  IWizard wizard = new NewProjectWizardManager();

  WizardDialog dialog = new WizardDialog(activeShell, wizard);

  dialog.open();

  return null;
}

我从 org.eclipse.jdt.ui.actions.AbstractOpenWizardAction 中找到了下面的代码。 在 Eclipse3.4 之前,您可以扩展此 class 以创建一个 Action.but 操作,现在已弃用,我想知道 Eclipse.org 是否提供类似 AbstractOpenWizardAction 的东西以在命令处理程序模式下执行相同的工作。我还没找到。

public void run() {
    Shell shell = getShell();
    if (!(doCreateProjectFirstOnEmptyWorkspace(shell)))
        return;
    try {
        INewWizard wizard = createWizard();
        wizard.init(PlatformUI.getWorkbench(), getSelection());

        WizardDialog dialog = new WizardDialog(shell, wizard);
        PixelConverter converter = new PixelConverter(JFaceResources.getDialogFont());
        dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70),
                converter.convertHeightInCharsToPixels(20));
        dialog.create();
        int res = dialog.open();
        if ((res == 0) && (wizard instanceof NewElementWizard)) {
            this.fCreatedElement = ((NewElementWizard) wizard).getCreatedElement();
        }

        notifyResult(res == 0);
    } catch (CoreException e) {
        String title = NewWizardMessages.AbstractOpenWizardAction_createerror_title;
        String message = NewWizardMessages.AbstractOpenWizardAction_createerror_message;
        ExceptionHandler.handle(e, shell, title, message);
    }
}