[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.rcp] Re: Singletons and IConfigurationElement.createExecutableExtension
|
The common way for a plugin to provide a singleton to other plugins
(say, some kind of ThemeManager) is to have it on your Activator:
public ThemeManager getThemeManager() {
if (themeManager == null) {
// create and initialize
}
return themeManager;
}
But it's a good practice not to export your Activator class (keep it
internal) so then you export a public static class that can delegate:
public class MyPluginHelper {
private MyPluginHelper() {
}
public ThemeManager getThemeManager() {
return MyActivator.getDefault().getThemeManager();
}
}
The thing with IConfigurationElement#createExecutableExtension(*) is
that it is a new instance. You could, of course, use it to delegate to
your singletons (but the question is why):
public class ContributedClass {
public ThemeManager getThemeManager() {
return MyActivator.getDefault().getThemeManager();
}
}
Then it doesn't matter how many instances your IConfigurationElement
creates, you'll deal with one that matters.
What are you trying to do, exactly? You have an RCP app that uses
singletons (like IThemeManager) that you would like contributed by
another plugin at runtime?
PW
--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/workbench.htm