Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » About Eclipse IAdaptable, IAdapterFactory, IAdapterManager
About Eclipse IAdaptable, IAdapterFactory, IAdapterManager [message #190857] Fri, 06 February 2004 20:37 Go to next message
Eclipse UserFriend
Originally posted by: charleszq.eastday.com

Hi there,

I'm now confused by the usage of IAdaptable, IAdapterFactory,
IAdapterManager, does anyone have some resource links or sample codes?
Thanks.

Actually, I just wanna know the architecture of the Eclipse framework, when
does a view, say, the property sheet view, asks the framework an instance of
IPropertySource? How can I write my own IAdapterFactory, and register it
into an IAdapterManager, and make my own view ask the framework for some
adapter via the getAdapter method of an instance of IAdaptable?

Thanks.

Charles
Re: About Eclipse IAdaptable, IAdapterFactory, IAdapterManager [message #190980 is a reply to message #190857] Sat, 07 February 2004 11:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pnehrer.freeshell.org

Charles,

the Property Sheet view, specifically, listens to selection changes and
attempts to display the properties of the currently selected object. To
get the properties, it uses the IPropertySource protocol. When the
selection changes, it asks the selected object for that interface (or an
adapter for that interface).

Consider this scenario:
1. Suppose you have a view, or something else, that serves as a
selection provider -- it provides your model objects, say class
MyModelObject.
2. Create an adapter class that implements IPropertySource, say
MyModelObjectPropertySource. This one in particular would probably be
instance-specific -- it'll wrap a specific MyModelObject instance. Thus,
let's assume it'll have a public constructor with signature
MyModelObjectPropertySource(MyModelObject).
3. Create an adapter factory class for your model objects. You may want
to use it for adapters other than IPropertySource. E.g.,
....
public class MyAdapterFactory implements IAdapterFactory {

private static final Class[] ADAPTER_LIST = { IPropertySource.class };

public Object getAdapter(Object adaptableObject, Class adapterType) {
if(IPropertySource.class.equals(adapterType)) {
if(adaptableObject instanceof MyModelObject)
return new
MyModelObjectPropertySource((MyModelObject)adaptableObject);
}

return null;
}

public Class[] getAdapterList() {
return ADAPTER_LIST;
}
}

4. In your plug-in class, instantiate your adapter factory and register it:
....
private MyAdapterFactory myFactory;
....
public void startup() throws CoreException {
super.startup();
workbenchAdapterFactory = new WorkbenchAdapterFactory();
IAdapterManager mgr = Platform.getAdapterManager();
mgr.registerAdapters(workbenchAdapterFactory, IRSSElement.class);
...
}

And to be nice, unregister on shutdown:
public void shutdown() throws CoreException {
IAdapterManager mgr = Platform.getAdapterManager();
mgr.unregisterAdapters(workbenchAdapterFactory);
super.shutdown();
}

Now, when your MyModelObject is selected and the Property Sheet view is
open, it will display your properties as implemented in
MyModelObjectPropertySource.

Hope this helps.
--Peter

Charles wrote:
> Hi there,
>
> I'm now confused by the usage of IAdaptable, IAdapterFactory,
> IAdapterManager, does anyone have some resource links or sample codes?
> Thanks.
>
> Actually, I just wanna know the architecture of the Eclipse framework, when
> does a view, say, the property sheet view, asks the framework an instance of
> IPropertySource? How can I write my own IAdapterFactory, and register it
> into an IAdapterManager, and make my own view ask the framework for some
> adapter via the getAdapter method of an instance of IAdaptable?
>
> Thanks.
>
> Charles
>
>
Re: About Eclipse IAdaptable, IAdapterFactory, IAdapterManager [message #190988 is a reply to message #190980] Sat, 07 February 2004 11:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: pnehrer.freeshell.org

Sorry, Step 4 should say:

4. In your plug-in class, instantiate your adapter factory and register it:
....
private MyAdapterFactory myFactory;
....
public void startup() throws CoreException {
super.startup();
myFactory = new MyAdapterFactory();
IAdapterManager mgr = Platform.getAdapterManager();
mgr.registerAdapters(myFactory, MyModelObject.class);
...
}

And to be nice, unregister on shutdown:
public void shutdown() throws CoreException {
IAdapterManager mgr = Platform.getAdapterManager();
mgr.unregisterAdapters(myFactory);
super.shutdown();
}
Re: About Eclipse IAdaptable, IAdapterFactory, IAdapterManager [message #191052 is a reply to message #190988] Sat, 07 February 2004 22:09 Go to previous message
Eclipse UserFriend
Originally posted by: charleszq.eastday.com

Thank you, Peter, that really helps. I'm really confused by where to
register my Adapter Factory. So if I'm doing RCP program with Eclipse 3.0, I
should register my factory in my WorkbenchAdvisor.

Thanks.

Charles

"Peter Nehrer" <pnehrer@freeshell.org> wrote in message
news:c032mn$en8$2@eclipse.org...
> Sorry, Step 4 should say:
>
> 4. In your plug-in class, instantiate your adapter factory and register
it:
> ...
> private MyAdapterFactory myFactory;
> ...
> public void startup() throws CoreException {
> super.startup();
> myFactory = new MyAdapterFactory();
> IAdapterManager mgr = Platform.getAdapterManager();
> mgr.registerAdapters(myFactory, MyModelObject.class);
> ...
> }
>
> And to be nice, unregister on shutdown:
> public void shutdown() throws CoreException {
> IAdapterManager mgr = Platform.getAdapterManager();
> mgr.unregisterAdapters(myFactory);
> super.shutdown();
> }
>
Previous Topic:Import statement on Panther not same as XP?
Next Topic:Moving from windows to Linux
Goto Forum:
  


Current Time: Mon May 12 13:16:21 EDT 2025

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

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

Back to the top