Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Retrieve the AbstractUIPlugin from Bundle
Retrieve the AbstractUIPlugin from Bundle [message #757058] Wed, 16 November 2011 09:49 Go to next message
Jonathan  is currently offline Jonathan Friend
Messages: 15
Registered: July 2011
Junior Member
Hi all!
I have a (probably) simple question: how could I retrieve the AbstractUIPlugin(eclipse) from my Bundle(osgi) object ?...

thanks before,
Jonathan
Re: Retrieve the AbstractUIPlugin from Bundle [message #757094 is a reply to message #757058] Wed, 16 November 2011 13:48 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

What is it you really want to do? i.e. what problem are you trying to solve.

You can always find the bundle that class is in, and use org.osgi.framework.Bundle.loadClass(String) to get the Class object. But I don't see what good that will do you.

PW


Re: Retrieve the AbstractUIPlugin from Bundle [message #757101 is a reply to message #757094] Wed, 16 November 2011 14:03 Go to previous messageGo to next message
Jonathan  is currently offline Jonathan Friend
Messages: 15
Registered: July 2011
Junior Member
well I realize it was a little confused...sorry about that.

Indeed, I have extended the AbstractUIPlugIn class, added some method : getLogger() for instance.

I want to manage my own Logger's levels with a Dialog (the same way Eclipse manage "Tracing" in the run configuration).
So I have to retrieve all MY plugins to call the "getLogger()" on them and then call the "setLevel(Level.ERROR)" for instance.

My problem => I can retrieve all my org.osgi.framework.Bundle... great! But I would like the org.eclipse.ui.plugin.AbstractUIPlugin objects.

Here's what I currently do:
	public Bundle[] getMyInstalledBundles(){
		List<Bundle> myBundles = new ArrayList<Bundle>();
                //All installed bundles
		Bundle[] bundles = Activator.getInstance().getBundleContext().getBundles();
		
		for (Bundle bundle : bundles) {
			if(bundle.getSymbolicName().startsWith("com.my.company")){
				myBundles.add(bundle);
			}
		}
		return myBundles.toArray(new Bundle[0]);
	}


and here is what I'm looking for:

	public AbstractUIPlugIn[] getMyInstalledPlugIns(){
		List<AbstractUIPlugIn> myPlugIns = new ArrayList<AbstractUIPlugIn>();
                //All installed plugins
		AbstractUIPlugIn[] installedPlungins = SomethingToGetAllPlugins...;
		
		for (AbstractUIPlugIn plugin : installedPlungins ) {
			if(plugin .getSymbolicName().startsWith("com.my.company")){
				myPlugIns .add(plugin );
			}
		}
		return myPlugIns.toArray(new AbstractUIPlugIn[0]);
	}



thanks
Re: Retrieve the AbstractUIPlugin from Bundle [message #757105 is a reply to message #757101] Wed, 16 November 2011 14:11 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

oh. Java doesn't provide a way to get access to the object instance, and neither does OSGi, at least not that way.

You could

1) create a logger management plugin, and have everybody register with it. Then tell it to set the levels on your logger.

2) the first time a logger is created, have it set its level to whatever it should be, and then register itself against some useful interface as an OSGi service. Then when you need to set all of the levels, you just walk all of the ServiceReferences for your interface.

PW


Re: Retrieve the AbstractUIPlugin from Bundle [message #757108 is a reply to message #757105] Wed, 16 November 2011 14:17 Go to previous messageGo to next message
Jonathan  is currently offline Jonathan Friend
Messages: 15
Registered: July 2011
Junior Member
ok thank you for the reply Smile

Last question: why can I retrieve the "org.osgi.framework.Bundle" object, and I can't retrieve the AbstractUIPlugIn object ? Although it reprensent the same thing (one in a pure Osgi context, and the other in the Eclipse UI context)... am I wrong ?
Re: Retrieve the AbstractUIPlugin from Bundle [message #757123 is a reply to message #757108] Wed, 16 November 2011 15:43 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

The OSGi Bundle is the handle provided by the OSGi framework to that bundle. It was created by the OSGi framework.

AbstractUIPlugin subclasses are usually the bundle activator. Based on org.osgi.framework.BundleActivator it is a class OSGi framework can instantiate from the bundle when the bundle is started (part of a bundle lifecycle).

PW


Re: Retrieve the AbstractUIPlugin from Bundle [message #757845 is a reply to message #757108] Wed, 16 November 2011 14:41 Go to previous message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 2011-11-16 15:17, Jonathan wrote:
> Last question: why can I retrieve the "org.osgi.framework.Bundle"
> object, and I can't retrieve the AbstractUIPlugIn object ? Although it
> reprensent the same thing (one in a pure Osgi context, and the other in
> the Eclipse UI context)... am I wrong ?

You are wrong: The AbstractUIPlugIn type corresponds to the osgi
interface BundleActivator. An osgi Bundle allows you to create an osgi
BundleActivator, but it does not store a reference to it. It would be
useless anyway, because not all BundleActivator's are singletons.

HTH & Greetings from Bremen,

Daniel Krügler
Previous Topic:ModelProvider.validateChange limitations
Next Topic:Ant Security Exception when opening ant file
Goto Forum:
  


Current Time: Tue Apr 23 14:42:56 GMT 2024

Powered by FUDForum. Page generated in 0.03638 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top