|
Re: Problem about getAdapter() method [message #143298 is a reply to message #143155] |
Mon, 19 July 2004 14:09 |
Eclipse User |
|
|
|
Originally posted by: News.Karsten-Becker.de
Wei Zhang wrote:
> Dear fellows working in GEF,
>
> There are the following source in class LogicEditor.java in the example of
> org.eclipse.gef.examples.logic_2.1.2:
>
> public Object getAdapter(Class type){
> if (type == CommandStackInspectorPage.class)
> return new CommandStackInspectorPage(getCommandStack());
> if (type == IContentOutlinePage.class)
> return new OutlinePage(new TreeViewer());
> if (type == ZoomManager.class)
> return (
> (ScalableFreeformRootEditPart) getGraphicalViewer()
> .getRootEditPart())
> .getZoomManager();
> return super.getAdapter(type);
> }
>
> I am not sure what the method getAdapter() is supposed to do, what is
> the purpose of the class CommandStackInspectorPage.class,
> And in what kind of situation, the statement if (type ==
> CommandStackInspectorPage.class) will return true?
It will return true if both classes are the same. The getAdapter()
method is part of the IAdaptable Interface. It is needed to provide a
extension point with the need to directly implement an Interface.
For example this lines:
> if (type == IContentOutlinePage.class)
> return new OutlinePage(new TreeViewer());
To provide an extension to the workbench one might have done something
like this:
if (unknownClass instanceOf IMyInterface){
//Go, use it..
}
But this is to inflexible. Think of what Interfaces a Editor need to
Implement to provide a IContentOutlinePage...
But if you have the getAdapter method you Just say:
IMyInterface myInt=unknownClass.getAdapter(IMyInterface.class);
if (myInt!=null){
//Go, use it
}
That is much more flexible and doesn't force the unknownClass to
directly implement an Interface, but to provide an Object that
implements that Interface.
In case of IContentOutlinePage it asks every Editor whether it is an
IAdaptable and when, whether he knows about the IContentOutlinePage.clas...
Karsten
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.27204 seconds