In some cases, the execution of our actions depends on that some configurations are ready to run, that is, to check whether the environment is configured properly. We can do this: make a judgment in the action run, and then guide the user to the configuration page for Environment configuration. The user experience is very good.
Public class startactiondelegate implements iworkbenchwindowactiondelegate {private iworkbenchwindow window; Public void dispose () {}/ ** @ see tables # Init (iworkbenchwindow) */Public void Init (iworkbenchwindow window) {This. window = Window;}/** @ see iactiondelegate # Run (iaction) */Public void run (iaction action) {// check whether the preference has been configured with the Tomcat home directory ipreferencestore Pref = tomcatlauncherplugin. getdefault (). getpreferencestore (); string apphome = Pref. getstring (tomcat_pref_home_key); If ("". equals (apphome) {// app home is not configured // direct the user to the preference configuration page string pageid = "com. sysdeo. eclipse. tomcat. page3 "; preferencemanager manager = platformui. getworkbench (). getpreferencemanager (); shell parentshell = platformui. getworkbench (). getactiveworkbenchwindow (). getshell (); preferencedialog Pd = new preferencedialog (shell, manager); PD. setselectednode (pageid); // set the selected page PD. open ();/*** the preceding code can be used to replace * preferencesutil. createpreferencedialogon (getshell (), pageid, new string [] {pageid, "com. sysdeo. eclipse. tomcat. page4 "}, null ). open (); */return;} else {// to-do something }}
The following preference page is displayed after you click starttomcataction:
PS: the code is modified based on tomcatplugin.
Appendix:
It is also possible to use the following method:
protected boolean showPreferencePage(GenericServerComposite composite) {PreferenceManager manager = PlatformUI.getWorkbench().getPreferenceManager();IPreferenceNode node = manager.find("org.eclipse.jdt.ui.preferences.JavaBasePreferencePage").findSubNode("org.eclipse.jdt.debug.ui.preferences.VMPreferencePage"); //$NON-NLS-1$//$NON-NLS-2$PreferenceManager manager2 = new PreferenceManager();manager2.addToRoot(node);final PreferenceDialog dialog = new PreferenceDialog(composite.getShell(), manager2);final boolean[] result = new boolean[] { false };BusyIndicator.showWhile(composite.getDisplay(), new Runnable() {public void run() {dialog.create();if (dialog.open() == Window.OK)result[0] = true;}});return result[0];}