Eclipse: Inside a plugin, how do I access another repository of plugin preferences?

I have an Eclipse plugin with a checkbox on the plugin settings page. This flag is used to enable or disable the editor that is launched from this plug-in.

However, the problem is that I would also like to enable and disable this “launch editor” from another plug-in by following steps that change the checkbox value on the aforementioned preferences page.

Here is the problem, how do I access this local preference store from another plugin?

I tried things like ..

View myView = (View) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("ViewID");

But that ` myView` always seems to be zero. And also, what would I do with the view, since this is the plugin I want.

Platform.getBundle('bundleName')...  

The same thing here, you need a plugin, not an appropriate package.

No matter what I try, nothing works.
Does anyone have any idea?

+3
source share
4 answers

There are two ways to do this:

public class TestPlugin extends AbstractUIPlugin {
private static TestPlugin plugin;

public static final String PREF_TEST = "test_preference";
/**
 * The constructor.
 */
public TestPlugin() {
    plugin = this;
}

 /**
   * This method is called upon plug-in activation
 */

public void start(BundleContext context) throws Exception {
    super.start(context);
}

/**
 * This method is called when the plug-in is stopped
 */
public void stop(BundleContext context) throws Exception {
    super.stop(context);
    plugin = null;
}

/**
 * Returns the shared instance.
 */
public static TestPlugin getDefault() {
    return plugin;
}
}

TestPlugin, :

TestPlugin.getDefault().getPluginPreferences().getDefaultBoolean(TestPlugin.PREF_TEST);
+1

:

ServiceTracker tracker = new ServiceTracker(ToolkitPlugin.getDefault().getBundle().getBundleContext(),
                                            IProxyService.class.getName(), null);
tracker.open();
proxyService = (IProxyService) tracker.getService();
proxyService.addProxyChangeListener(this);
0

.

prefs . prefs , ActivatorA.

IPreferenceStore = ActivatorA.getDefault(). getPreferenceStore();

, , , api ActivatorA, , .

public IPreferenceStore getSharedPrefs() {   return ActivatorA.getDefault(). getPreferenceStore(); }

The second plugin will find a general store by doing this

IPreferenceStore sharedPrefs = ActivatorA.getSharedPrefs ();

Good luck.

0
source

Source: https://habr.com/ru/post/1723871/


All Articles