Global variables in Eclipse RCP

how can i solve this:

I have user info in my main RCP plugin. All other plugins must also have this information. The preference store is not possible because the preference store requires a host name that must be available globally.

Is it possible to implement global variables?

Thanks!

+3
source share
2 answers

There are several options.


A quick and dirty approach is to put the getter for your global variable in the activator of one of your plugins. Then you just get your global view:

SomePluginActivator.getDefault().getGlobalData()

, , .


workbench. , org.eclipse.ui . , , org.eclipse.ui.services. factory. factory . , . factory :

IMyGlobalService service = (IMyGlobalService) PlatformUI.getWorkbench().getService(IMyGlobalService.class);

. , , . factory , .


. , , , , , .


- OSGi. . OSGi, OSGi . workbench, Eclipse RCP . (: PDF).

+8

, , .

RCP, IEclipsePreferences? :

IEclipsePreferences rootNode = Platform.getPreferencesService().getRootNode();
rootNode.put("currentFileName", "my.file.name.txt");

- :

IEclipsePreferences rootNode = Platform.getPreferencesService().getRootNode();
String currentFileName = rootNode.get("currentFileName", null);
+1

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


All Articles