2.wizardwizardpage添加好后,需要新建一个wizard类来管理它们。
package de.vogella.rcp.intro.wizards.wizard;import org.eclipse.jface.wizard.Wizard;public class MyWizard extends Wizard {protected MyPageOne one;protected MyPageTwo two;public MyWizard() {super();setNeedsProgressMonitor(true);}@Overridepublic String getWindowTitle() {return "Export My Data";}@Overridepublic void addPages() {one = new MyPageOne();two = new MyPageTwo();addPage(one);addPage(two);}@Overridepublic boolean performFinish() {// Print the result to the consoleSystem.out.println(one.getText1());System.out.println(two.getText1());return true;}}
@Override public boolean canFinish() {if (this.getContainer().getCurrentPage() instanceof FilePreprocessingWizardPage) // FilePreprocessingWizardPage为最后一个页面return true;elsereturn false; }
3.WizardDialogwizardDialog 一般用于管理向导页的按钮,如果你想将原有的next/finish/cancel等按钮重写,就需要新建这个类 。下面是我项目中遇到的代码,需求是:最后一个页不再显示next按钮,而是改为start,并执行相关功能 。第一页finish不可点 (这个由wizard类的canfinish方法控制):

文章插图
第二页finish可以点、next 变为start

文章插图
import org.eclipse.jface.dialogs.IDialogConstants;import org.eclipse.jface.wizard.IWizard;import org.eclipse.jface.wizard.IWizardPage;import org.eclipse.jface.wizard.WizardDialog;import org.eclipse.swt.widgets.Shell;import org.eclipse.swt.widgets.Button;public class InputFileWizardDialog extends WizardDialog { private Button startBtn; private Button nextButton; public InputFileWizardDialog(Shell parentShell, IWizard newWizard) {super(parentShell, newWizard); } @Override protected void buttonPressed(int buttonId) {switch (buttonId) {case IDialogConstants.HELP_ID: {helpPressed();break;}case IDialogConstants.BACK_ID: {backPressed();break;}case IDialogConstants.NEXT_ID: {nextPressed();break;}case IDialogConstants.FINISH_ID: {finishPressed();break;}} } @Override protected void nextPressed() {IWizardPage currentPage = getCurrentPage();IWizardPage nextPage = currentPage.getNextPage();if (currentPage instanceof FilePreprocessingWizardPage) {((FilePreprocessingWizardPage) currentPage).startButtonClick();}if (nextPage instanceof FilePreprocessingWizardPage) { // last pageif (nextPage.getControl() != null)nextPage.dispose();showPage(nextPage);startBtn = this.getButton(IDialogConstants.NEXT_ID);startBtn.setText("Start");startBtn.setEnabled(true);} } /*** The Back button has been pressed.*/ @Override protected void backPressed() {IWizardPage page = getCurrentPage().getPreviousPage();super.backPressed();if (!(page instanceof FilePreprocessingWizardPage)) { // last pagenextButton = this.getButton(IDialogConstants.NEXT_ID);nextButton.setText(IDialogConstants.NEXT_LABEL);} }}
4.最后,打开一个wizard一般写在一个按钮监听中 ,或者菜单功能里。
经验总结扩展阅读
- Windows10 + Eclipse C/C++开发环境配置极简教程
- 提高工作效率的神器:基于前端表格实现Chrome Excel扩展插件
- 苹果手机红包秒收怎么设置(苹果红包插件黑科技)
- 从0开始写一个简单的vite hmr 插件
- 钩子 【pytest官方文档】解读-插件开发之hooks 函数
- 插件化编程之WebAPI统一返回模型
- 浅谈 Golang 插件机制
- 中 ?打造企业自己代码规范IDEA插件
- 分享一个Vue实现图片水平瀑布流的插件
- 手机里有个恶意广告插件怎样清除