1

我为eclipse写了一个插件。我在工具栏菜单中有一个按钮。我希望按下它 - 将打开一个向导页面对话框。我已经编写了一个扩展向导并实现 IWizardPage 的类,并且我还编写了所有 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>

你有什么主意吗?

4

2 回答 2

2

用于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;
}
于 2015-01-04T15:33:01.417 回答
0

我从 org.eclipse.jdt.ui.actions.AbstractOpenWizardAction 中找到了下面的代码。在 Eclipse3.4 之前,你可以扩展这个类来创建一个 Action。但是现在不推荐使用 action,我想知道 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);
    }
}
于 2017-04-26T08:24:25.650 回答