Preference in eclipse workbench (2)

Source: Internet
Author: User

(Original ENGLISH)

Translated by Frank

Preference in eclipse workbench (2)

 

Define the preference page in plugin. xml

Now we have defined preference. Next, we want to provide users with a method to set the value of preference. The preference page of the workbench can be found in the preferences dialog box, and the preference dialog box can be found in the window-> preferences menu group. To make your defined plug-ins look consistent with other Eclipse plug-ins, you should use plugin. XML to add a preference page to the preferences dialog box. The preference page defined in plugin. XML is as follows:

 

<extension point="org.eclipse.ui.preferencePages">
<page id="BadWordsPreferencePage"
name="Bad Words"
class="org.eclipse.ui.articles.badwordchecker.BadWordsPreferencePage">
</page>

<page id="BadWordsColorPreferencePage"
name="Colors"
class="org.eclipse.ui.articles.badwordchecker.BadWordsColorPreferencePage"
category="BadWordsPreferencePage">
</page>
</extension>

 

 

In the above definition, the preference name is set in the page list ( And specify the preference page class name ( ). This class must be consistent with iworkbenchpreferencepage, which means this class must use iworkbenchpreferencepage as the interface

 

 

 

 

 

 

 

 

 

 

 

 

In the second definition, there is a category ( In the preference dialog box, a page is used as a subpage of another page. This function is useful when you want to put a series of related pages together to reduce the number of preference pages. In the plugin. xml file, when the id value of the parent page is used as the category value of the page, the page becomes a child page of the parent page. If a page does not have a parent page, it serves as the root child page. As you can see, the preference dialog box is displayed as follows:

Figure 1. The preference dialog box for bad words and color preference is displayed.

Color Preference page

 

 

 

 

 

 

 

 

 

 

 

 

The color preference page is a simple example. It uses a simple fileld editor in jface to manage its values. In the beginning, we should set a preference page class. All classes in the preference dialog box must inherit from iworkbenchpreferencepage. Eclipse includes the preferencepage class, which implements the APIS required by most preference. When the OK button is pressed, preferencedialog stores the preference store. If you want to use preferencepage to replace the default dialog box in window-> preferences, you must ensure that the preference store is saved after the application is changed.

 

 

 

 

 

 

 

 

 

 

 

 

The definitions of classes on the preference page are as follows:

 

 

 

 

 

 

 

 

 

 

 

 

 

class BadWordsColorPreferencePage
extends PreferencePage
implements IWorkbenchPreferencePage

 

 

Once we define a page, we must initialize it. For this purpose, iworkbenchpreferencepage specifies the init (iworkbench) function. We will not use parameters for this page. Our implementation is to set preference for this page.

 

 

public void init(IWorkbench workbench) {
//Initialize the preference store we wish to use
setPreferenceStore(BadWordCheckerPlugin.getDefault().getPreferenceStore());

 

 

The other functions we must implement are createcontents (). All we need to do is to use colorfieldeditor to set preference. Similarly, we recommend that you implement debumults ults to reset the value of the plug-in so that the preference can be restored to the initial default state. I also need to implement the javasmok function, so that the plug-in can store the User-Defined prefenece in the preference store. Because colorfieldeditor has the code for reading the default settings off the shelf, and there is also an application for storing the results of a preference, our implementation is quite simple. The prenference storage result application is defined in performok, and the default setting for reading is performdefaults. You can call the corresponding method in colorfieldeditor. See the color preference page in Figure 2.

 

 

 

 

 

protected void performDefaults() {
colorEditor.loadDefault();
}
/**
* Save the color preference to the preference store.
*/
public boolean performOk() {
colorEditor.store();
return super.performOk();
}

 

Figure 2: The preference dialog box for color preference is displayed.

(To be continued)

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.