Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Updating a ViewPart from Model or EditingDomain
Updating a ViewPart from Model or EditingDomain [message #418675] Wed, 23 April 2008 19:09 Go to next message
Maurice O'Connor is currently offline Maurice O'ConnorFriend
Messages: 86
Registered: July 2009
Member
Hi!

I have a new ViewPart written with a Combo box in it. I'd like to update
the Combo in the ViewPart based on information from the model underlying
the diagram in the active editor, ensuring that it is refreshed with each
change to the model (not just when an item is manipulated on the diagram).

Does anyone have any hints obout this? I've scoured far and wide for info
about ViewParts, listeners and notifications, but I can't figure out how
to get the information from the model into my ViewPart.

Thanks!

Maurice
Re: Updating a ViewPart from Model or EditingDomain [message #418676 is a reply to message #418675] Wed, 23 April 2008 19:17 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Maurice,

It's often good just to populate the combo when it needs to be shown.
Have you looked into JFace data binding at all? They might have stuff
for that and in EMF 2.4 we provide plugins that let you use EMF objects
with JFace's data binding framework...


Maurice O'Connor wrote:
> Hi!
>
> I have a new ViewPart written with a Combo box in it. I'd like to
> update the Combo in the ViewPart based on information from the model
> underlying the diagram in the active editor, ensuring that it is
> refreshed with each change to the model (not just when an item is
> manipulated on the diagram).
>
> Does anyone have any hints obout this? I've scoured far and wide for
> info about ViewParts, listeners and notifications, but I can't figure
> out how to get the information from the model into my ViewPart.
>
> Thanks!
>
> Maurice
>
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Updating a ViewPart from Model or EditingDomain [message #418677 is a reply to message #418676] Wed, 23 April 2008 19:35 Go to previous messageGo to next message
Maurice O'Connor is currently offline Maurice O'ConnorFriend
Messages: 86
Registered: July 2009
Member
Ed Merks wrote:

> Maurice,

> It's often good just to populate the combo when it needs to be shown.
> Have you looked into JFace data binding at all? They might have stuff
> for that and in EMF 2.4 we provide plugins that let you use EMF objects
> with JFace's data binding framework...


Thanks Ed, a "read" approach is fine for me, to have the ViewPart examine
the model directly, iterating over the nodes, when the user refreshes the
Combo box for example.

My problem, though, is how exactly to examine the model underlying the
diagram from the ViewPart.

Any tips about which classes to look at etc.? I assume there is some
static method I can call from the ViewPart which will allow me access to
the model for the active editor.

Maurice
Re: Updating a ViewPart from Model or EditingDomain [message #418679 is a reply to message #418677] Wed, 23 April 2008 19:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Maurice,

Does the view take the editor's selection as input? If the selection
is an EObject you an use eResource().getResourceSet() to work your way
up to all the objects that are available. Or maybe it's a
org.eclipse.gmf.runtime.notation.View and want to call getElement?


Maurice O'Connor wrote:
> Ed Merks wrote:
>
>> Maurice,
>
>> It's often good just to populate the combo when it needs to be
>> shown. Have you looked into JFace data binding at all? They might
>> have stuff for that and in EMF 2.4 we provide plugins that let you
>> use EMF objects with JFace's data binding framework...
>
>
> Thanks Ed, a "read" approach is fine for me, to have the ViewPart
> examine the model directly, iterating over the nodes, when the user
> refreshes the Combo box for example.
> My problem, though, is how exactly to examine the model underlying the
> diagram from the ViewPart.
>
> Any tips about which classes to look at etc.? I assume there is some
> static method I can call from the ViewPart which will allow me access
> to the model for the active editor.
>
> Maurice
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Updating a ViewPart from Model or EditingDomain [message #418692 is a reply to message #418679] Thu, 24 April 2008 10:38 Go to previous messageGo to next message
Maurice O'Connor is currently offline Maurice O'ConnorFriend
Messages: 86
Registered: July 2009
Member
> Does the view take the editor's selection as input? If the selection
> is an EObject you an use eResource().getResourceSet() to work your way
> up to all the objects that are available. Or maybe it's a
> org.eclipse.gmf.runtime.notation.View and want to call getElement?

Hey Ed,

The view is an org.eclipse.ui.part.ViewPart. It doesn't currently take a
selection as input (or use an ISelectionListener). It is supposed to
display some general information about the model, not information about
something specifically selected in the editor. So when the model opens, it
is immediately populated.

Implementing ISelectionListener and accessing the selected EObject might
work (I've done this elsewhere) but what if nothing is selected in the
diagram? Read access to the EditingDomain/model (hope that's the correct
term!) underlying the diagram would be ideal.

Maurice
Re: Updating a ViewPart from Model or EditingDomain [message #418693 is a reply to message #418692] Thu, 24 April 2008 11:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Maurice,

EMF's generated editors implement IEditingDomainProvider which provides
access to the editing domain and hence the underlying resource set. I'm
not sure what general interface or class all GMF editors implement that
would provide access to the editing domain, but that would be the way to
go then. So the idea would be you'd have a part listener that would
listen to the active editor changing?


Maurice O'Connor wrote:
>
>> Does the view take the editor's selection as input? If the
>> selection is an EObject you an use eResource().getResourceSet() to
>> work your way up to all the objects that are available. Or maybe
>> it's a org.eclipse.gmf.runtime.notation.View and want to call
>> getElement?
>
> Hey Ed,
>
> The view is an org.eclipse.ui.part.ViewPart. It doesn't currently take
> a selection as input (or use an ISelectionListener). It is supposed to
> display some general information about the model, not information
> about something specifically selected in the editor. So when the model
> opens, it is immediately populated.
>
> Implementing ISelectionListener and accessing the selected EObject
> might work (I've done this elsewhere) but what if nothing is selected
> in the diagram? Read access to the EditingDomain/model (hope that's
> the correct term!) underlying the diagram would be ideal.
>
> Maurice
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Updating a ViewPart from Model or EditingDomain [message #418699 is a reply to message #418693] Thu, 24 April 2008 14:33 Go to previous messageGo to next message
Maurice O'Connor is currently offline Maurice O'ConnorFriend
Messages: 86
Registered: July 2009
Member
Ed Merks wrote:

> Maurice,

> EMF's generated editors implement IEditingDomainProvider which provides
> access to the editing domain and hence the underlying resource set. I'm
> not sure what general interface or class all GMF editors implement that
> would provide access to the editing domain, but that would be the way to
> go then. So the idea would be you'd have a part listener that would
> listen to the active editor changing?

OK, I'm not sure how wise this is, but it appears to work. Firstly, I am
using GMF - and I probably should have mentioned this. Being a GMF/EMF
noob, it appears I posted on the wrong group ;)

In GMF tips (http://wiki.eclipse.org/GMF_Tips) I saw some stuff about how
to share the EditingDomain over multiple diagrams. I adapted this to my
need, adding the extension point to plugin.xml and changing the code in
DocumentProvider.

Then I could access the editing domain from my ViewPart code with:

TransactionalEditingDomain transactionalEditingDomain =
TransactionalEditingDomain.Registry.INSTANCE.getEditingDomai n( "SharedEditingDomain");

I'm going to switch my questions to the GMF group, as I figure they should
really be posted there. Thanks for your advice!

Maurice
Re: Updating a ViewPart from Model or EditingDomain [message #418704 is a reply to message #418699] Thu, 24 April 2008 16:36 Go to previous message
Maurice O'Connor is currently offline Maurice O'ConnorFriend
Messages: 86
Registered: July 2009
Member
Gonna cross-post this from .gmf, since the 'solution' I posted previously
is overkill, messy and led to lots of weird hanging etc.

So, for any hapless newbies following in my footsteps.

Scratch the above junk about sharing the TransactionalEditingDomain. No
need to do this for a ViewPart. In the ViewPart I wrote:

Object o = this.getSite().getPage().getActiveEditor().getEditorInput();

EditingDomain editingDomain =
MyGeneratedDiagramEditorPlugin.getInstance().getDocumentProv ider().getDiagramDocument(o).getEditingDomain();

Using the EditingDomain I can grab the ResourceSet and iterate over it,
locating the nodes I need to access. Gnarly!

Maurice
Previous Topic:Serialization of EObject into an XML String and vice versa (without Persistence to disk)
Next Topic:Emfatic
Goto Forum:
  


Current Time: Sat Apr 20 03:49:32 GMT 2024

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

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

Back to the top