Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How can a viewer get the model of a GEF editor?
How can a viewer get the model of a GEF editor? [message #136486] Sun, 06 June 2004 10:26 Go to next message
Eclipse UserFriend
Originally posted by: beenmerg.yahoo.com

I have a working GEF editor. The editor extends
GraphicalEditorWithPalette. The editor works like every other editor with
a model:

protected void initializeGraphicalViewer() {
getGraphicalViewer().setContents(new MyModel());
}

Now I'm trying to make a viewer that displays a list of the names of all
the elements in the model. The viewer extends ViewPart and is a
TableViewer.

But how can the viewer get the model of the editor? At this moment the
viewer creates a dummy model on the fly. How can I get a reference to the
model that the GEF editor uses so I can use the real model in the viewer?

Many, many thanks in advance for the answer
Re: How can a viewer get the model of a GEF editor? [message #136498 is a reply to message #136486] Sun, 06 June 2004 12:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

Hello Jan,

What you are trying to do looks like an outline view of your editor...Wh=
y =

don't you provide an outline page ? The outline page can be bluid in the=
=

EditorPart class of your editor and so you can pass a reference to the =

model or to the GraphicalViewer in the constructor of the outline page. =
If =

you don't know how to build an outline page I can explain this to you he=
re =

or you can find examples on the net too.

But maybe the outline page is already used for another purpose ?
You could use some kind of multiple page outline page, like in the logic=
=

example...

If you really don't want to build an outline page, then I don't really =

know.

My ideas:
- Maybe you could get a reference to the EditorPart with its identificat=
or =

(but what if there are many Editors of this kind opened on different fil=
es =

?),
- Maybe you could listen to the workbench, I think the workbench can =

notify you when the active Editor changes. So when you recieve such an =

event, you check the id of the current editor and if it is your editor, =
=

you can get its model and display what you want.

I never did this so I am not sure.

I hope this has helped you,

r=E9gis



On Sun, 6 Jun 2004 10:26:59 +0000 (UTC), Jan Groot <beenmerg@yahoo.com> =
=

wrote:

> I have a working GEF editor. The editor extends
> GraphicalEditorWithPalette. The editor works like every other editor w=
ith
> a model:
>
> protected void initializeGraphicalViewer() {
> getGraphicalViewer().setContents(new MyModel());
> }
>
> Now I'm trying to make a viewer that displays a list of the names of a=
ll
> the elements in the model. The viewer extends ViewPart and is a
> TableViewer.
>
> But how can the viewer get the model of the editor? At this moment the=

> viewer creates a dummy model on the fly. How can I get a reference to =
the
> model that the GEF editor uses so I can use the real model in the view=
er?
>
> Many, many thanks in advance for the answer
>



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Re: How can a viewer get the model of a GEF editor? [message #136509 is a reply to message #136498] Sun, 06 June 2004 13:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

I know the ISelectionService service tracks the current selection and yo=
u =

can listen to it by writting:

getSite().getWorkbenchWindow().getSelectionService().addSele ctionListene=
r(this);

in the init method of an EditorPart (for a view part it should be the =

same)...

So it must also be some service to track the active editor and this =

service should be accessible from a ViewPart...that's what I am currentl=
y =

searching for...

r=E9gis

On Sun, 06 Jun 2004 14:54:49 +0200, <rlemaigr@ulb.ac.be> wrote:

> Hello Jan,
>
> What you are trying to do looks like an outline view of your =

> editor...Why don't you provide an outline page ? The outline page can =
be =

> bluid in the EditorPart class of your editor and so you can pass a =

> reference to the model or to the GraphicalViewer in the constructor of=
=

> the outline page. If you don't know how to build an outline page I can=
=

> explain this to you here or you can find examples on the net too.
>
> But maybe the outline page is already used for another purpose ?
> You could use some kind of multiple page outline page, like in the log=
ic =

> example...
>
> If you really don't want to build an outline page, then I don't really=
=

> know.
>
> My ideas:
> - Maybe you could get a reference to the EditorPart with its =

> identificator (but what if there are many Editors of this kind opened =
on =

> different files ?),
> - Maybe you could listen to the workbench, I think the workbench can =

> notify you when the active Editor changes. So when you recieve such an=
=

> event, you check the id of the current editor and if it is your editor=
, =

> you can get its model and display what you want.
>
> I never did this so I am not sure.
>
> I hope this has helped you,
>
> r=E9gis
>
>
>
> On Sun, 6 Jun 2004 10:26:59 +0000 (UTC), Jan Groot <beenmerg@yahoo.com=
> =

> wrote:
>
>> I have a working GEF editor. The editor extends
>> GraphicalEditorWithPalette. The editor works like every other editor =
=

>> with
>> a model:
>>
>> protected void initializeGraphicalViewer() {
>> getGraphicalViewer().setContents(new MyModel());
>> }
>>
>> Now I'm trying to make a viewer that displays a list of the names of =
all
>> the elements in the model. The viewer extends ViewPart and is a
>> TableViewer.
>>
>> But how can the viewer get the model of the editor? At this moment th=
e
>> viewer creates a dummy model on the fly. How can I get a reference to=
=

>> the
>> model that the GEF editor uses so I can use the real model in the =

>> viewer?
>>
>> Many, many thanks in advance for the answer
>>
>
>
>



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Re: How can a viewer get the model of a GEF editor? [message #136522 is a reply to message #136509] Sun, 06 June 2004 13:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rlemaigr.ulb.ac.be

Bingo ! (you say that in english too ? :D )

I think I have found it:
The service I was searching for is IPartService and you can get it from =
a =

ViewPart like that:
getSite().getWorkbenchWindow().getPartService()
and you can add an IPartListener by calling addPartListener(IPartListene=
r).


So you could add this line in the init method of your view:
getSite().getWorkbenchWindow().getPartService().addPartListe ner(this);

and then implement the IPartListener interface.
There is a method called partActivated(IWorkbenchPart) in this interface=
.. =

This should look like this:
public void partActivated(IWorkbenchPart activePart)
{
if(activePart instanceof YourEditorClass)
setInput(((YourEditorClass)activePart).getContents());
else
setInput(null);
}

and then the dispose method:
getSite().getWorkbenchWindow().getPartService().removePartLi stener(this)=
;


please let me know if it works or if you find a better way...I am =

interested too...

r=E9gis


On Sun, 06 Jun 2004 15:44:00 +0200, <rlemaigr@ulb.ac.be> wrote:

> I know the ISelectionService service tracks the current selection and =
=

> you can listen to it by writting:
>
> getSite().getWorkbenchWindow().getSelectionService().addSele ctionListe=
ner(this);
>
> in the init method of an EditorPart (for a view part it should be the =
=

> same)...
>
> So it must also be some service to track the active editor and this =

> service should be accessible from a ViewPart...that's what I am =

> currently searching for...
>
> r=E9gis
>
> On Sun, 06 Jun 2004 14:54:49 +0200, <rlemaigr@ulb.ac.be> wrote:
>
>> Hello Jan,
>>
>> What you are trying to do looks like an outline view of your =

>> editor...Why don't you provide an outline page ? The outline page can=
=

>> be bluid in the EditorPart class of your editor and so you can pass a=
=

>> reference to the model or to the GraphicalViewer in the constructor o=
f =

>> the outline page. If you don't know how to build an outline page I ca=
n =

>> explain this to you here or you can find examples on the net too.
>>
>> But maybe the outline page is already used for another purpose ?
>> You could use some kind of multiple page outline page, like in the =

>> logic example...
>>
>> If you really don't want to build an outline page, then I don't reall=
y =

>> know.
>>
>> My ideas:
>> - Maybe you could get a reference to the EditorPart with its =

>> identificator (but what if there are many Editors of this kind opened=
=

>> on different files ?),
>> - Maybe you could listen to the workbench, I think the workbench can =
=

>> notify you when the active Editor changes. So when you recieve such a=
n =

>> event, you check the id of the current editor and if it is your edito=
r, =

>> you can get its model and display what you want.
>>
>> I never did this so I am not sure.
>>
>> I hope this has helped you,
>>
>> r=E9gis
>>
>>
>>
>> On Sun, 6 Jun 2004 10:26:59 +0000 (UTC), Jan Groot <beenmerg@yahoo.co=
m> =

>> wrote:
>>
>>> I have a working GEF editor. The editor extends
>>> GraphicalEditorWithPalette. The editor works like every other editor=
=

>>> with
>>> a model:
>>>
>>> protected void initializeGraphicalViewer() {
>>> getGraphicalViewer().setContents(new MyModel());
>>> }
>>>
>>> Now I'm trying to make a viewer that displays a list of the names of=
=

>>> all
>>> the elements in the model. The viewer extends ViewPart and is a
>>> TableViewer.
>>>
>>> But how can the viewer get the model of the editor? At this moment t=
he
>>> viewer creates a dummy model on the fly. How can I get a reference t=
o =

>>> the
>>> model that the GEF editor uses so I can use the real model in the =

>>> viewer?
>>>
>>> Many, many thanks in advance for the answer
>>>
>>
>>
>>
>
>
>



-- =

Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Re: How can a viewer get the model of a GEF editor? [message #136580 is a reply to message #136522] Mon, 07 June 2004 09:56 Go to previous message
Eclipse UserFriend
Originally posted by: beenmerg.yahoo.com

WooHoo!!! Yesss, this works 100%!

Many thanks for all the time you have spent solving this problem.
Previous Topic:compatibility with eclipse 3.0
Next Topic:How to create Nodes in HalloGef Examples
Goto Forum:
  


Current Time: Thu Apr 25 13:28:27 GMT 2024

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

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

Back to the top