Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Problem about getAdapter() method
Problem about getAdapter() method [message #143155] Mon, 19 July 2004 03:09 Go to next message
zhang wei is currently offline zhang weiFriend
Messages: 84
Registered: July 2009
Member
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 #143298 is a reply to message #143155] Mon, 19 July 2004 14:09 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Problem about getAdapter() method [message #143450 is a reply to message #143298] Tue, 20 July 2004 01:24 Go to previous messageGo to next message
zhang wei is currently offline zhang weiFriend
Messages: 84
Registered: July 2009
Member
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

Thanks a lot
Re: Problem about getAdapter() method [message #143460 is a reply to message #143298] Tue, 20 July 2004 01:59 Go to previous message
zhang wei is currently offline zhang weiFriend
Messages: 84
Registered: July 2009
Member
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.
Previous Topic:Problems printing images
Next Topic:GEF and RCP application Help
Goto Forum:
  


Current Time: Fri Apr 26 07:55:56 GMT 2024

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

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

Back to the top