我为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>
你有什么想法吗?
答案 0 :(得分: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;
}
答案 1 :(得分:0)
我在org.eclipse.jdt.ui.actions.AbstractOpenWizardAction中找到了以下代码。 在Eclipse3.4之前,您可以扩展此类以创建Action.but现在不推荐使用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);
}
}