Problem about getAdapter() method [message #143155] |
Sun, 18 July 2004 23:09  |
Eclipse User |
|
|
|
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?
I really appreciate your help.
Thank you
|
|
|
|
|
Re: Problem about getAdapter() method [message #143460 is a reply to message #143298] |
Mon, 19 July 2004 21:59  |
Eclipse User |
|
|
|
Karsten Becker wrote:
> 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
Thank you very much for your answer.
I have one more question.
What is the class org.eclipse.gef.ui.stackview.CommandStackInspectorPage
supposed to do?
I do not find javaDoc for it in GEF.
Thanks for your time.
|
|
|
Powered by
FUDForum. Page generated in 0.03007 seconds