In the displayed preference dialog box, go to the specified page.

Source: Internet
Author: User
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];}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.