Eclipse插件RCP桌面应用开发的点点滴滴( 三 )


按钮监听:Button button = new Button(parent, SWT.PUSH);button.setText("Open Wizard");button.addSelectionListener(new SelectionAdapter() {@Overridepublic void widgetSelected(SelectionEvent e) {WizardDialog wizardDialog = new WizardDialog(parent.getShell(),new MyWizard());if (wizardDialog.open() == Window.OK) {System.out.println("Ok pressed");} else {System.out.println("Cancel pressed");}}});
菜单功能,这里用的是E4的handle机制import org.eclipse.e4.core.di.annotations.Execute;import org.eclipse.ui.IWorkbench;import org.eclipse.jface.window.Window;import org.eclipse.jface.wizard.WizardDialog;import org.eclipse.swt.widgets.Shell;public class InputFilesAssistantHandle { @Execute public void execute(IWorkbench iWorkbench, Shell shell) {WizardDialog wizardDialog = new WizardDialog(shell, new MyWizard());WizardDialog.setDefaultImage(ApplicationContext.getImage(Constant.PLUGIN_ID, "icons/module/cn_icon.png"));if (wizardDialog.open() == Window.OK) {} else {} }}
①可以通过setDefaultImage来设置向导的图标
效果:
Eclipse插件RCP桌面应用开发的点点滴滴

文章插图
进阶:① wizardpage 的动态刷新 、 联动你的wizardpages 初始化是在wizard打开的时候,而不是点next或back时再初始化。所以,如果你想将两个wizardpage进行联动,通过上面的代码难以实现。阅读源码会发现,
源码private void updateForPage(IWizardPage page) {// ensure this page belongs to the current wizardif (wizard != page.getWizard()) {setWizard(page.getWizard());}// ensure that page control has been created// (this allows lazy page control creation)if (page.getControl() == null) {page.createControl(pageContainer);// the page is responsible for ensuring the created control is accessable// via getControl.Assert.isNotNull(page.getControl());// ensure the dialog is large enough for this pageupdateSize(page);}// make the new page visibleIWizardPage oldPage = currentPage;currentPage = page;currentPage.setVisible(true);if (oldPage != null) {oldPage.setVisible(false);}// update the dialog controlsupdate();}
点next或back按钮后,页面之所以不会再初始化,是因为他会有个判断page.getControl() == null,因此我们只要将想办法在调转到某个WizardPage的时候,将其control设置为null就可以了.所以,在点next 或 back 按钮时 ,可以加如下代码:// 对参数页必须重绘IWizardPage page = getNextPage();if (page.getControl() != null) page.dispose();
并在你想要刷新的页面中重写dispose方法:public void dispose() {super.dispose();
setControl(null);}
二、未完待续 。。。
【Eclipse插件RCP桌面应用开发的点点滴滴】

经验总结扩展阅读