How to fetch path of a file from preference page and print the Output on console via Button on Workbench?

后端 未结 1 1226
有刺的猬
有刺的猬 2020-12-22 09:04

I have made one preference page whose programming is:

public class SAML
extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage {

public SAML(         


        
相关标签:
1条回答
  • 2020-12-22 09:42

    You need two parts:

    • Code that initialize the default for the preference
    • Code that use the current value

    To set the default, you use the following code in the Activator:

    public class Activator extends AbstractUIPlugin {
        @Override
        public void start(BundleContext context) throws Exception {
            super.start(context);
            IPreferenceStore ps = getPreferenceStore();
            ps.setDefault(SHOW_IMAGE, true);
        }
        public static final String SHOW_IMAGE = "showImage";
    }
    

    Alternatively, you can use the org.eclipse.core.runtime.preferences extension point...

    Note that the code above assume that the type of the preference is Boolean - there are other methods for numbers, strings, etc... A file name is a string.

    To use the current value, just use

    if (Activator.getDefault().getPreferenceStore().getBoolean(Activator.SHOW_IMAGE)) {
        …
    }
    

    The following slides contains a little more information...

    0 讨论(0)
提交回复
热议问题