Home » Modeling » EMF » Create Submenu for EMF Model(Create Submenu for EMF Model)
Create Submenu for EMF Model [message #889976] |
Wed, 20 June 2012 13:05 |
Markus G Messages: 23 Registered: June 2012 |
Junior Member |
|
|
Hi everyone,
my problem is the following: I have created an ecore metamodel and generated the editor for this and adjusted it a little bit to my needs.
What I want to do is offer additional operations for some of the elements. More specifically, I want to extend the right-click-menu of one kind of elements with an operation that opens a dialog which in turn changes an attribute of that element.
I am somehow having big trouble finding an example how to develop an additional ui-dialog-like plugin and adding this as an operation into the context-menu of my ecore model.
Does anyone possibly have an example of how that works?
Thanks a lot!
EDIT: I keep reading that supposedly this should be very simple. So if someone could point me to a walk-through of how to implement a simple plugin showing a pop-up menu which will appear as a contribution in the model's context menu to change an attribute of the selected item, that would be awesome.
Thanks
[Updated on: Wed, 20 June 2012 13:53] Report message to a moderator
|
|
| | | |
Re: Create Submenu for EMF Model [message #890169 is a reply to message #890019] |
Thu, 21 June 2012 11:07 |
Markus G Messages: 23 Registered: June 2012 |
Junior Member |
|
|
Awesome, that did the trick, thanks!
It brought me a step further, but I have a different problem.
I managed to change an attribute in MyEClass (to stick to the naming of your code snipplet), but the change is not displayed in my model. Actually, the model doesn't realize that is has been changed at all (I can't save the changes because the state is "already oldest change").
On top of that, I'd like to refresh all the viewers after having changed the attribute in my dialog-handler-function, as the attribute this changes is a filter. Classes with that attribute set are not being displayed in the model (I solved that changing the getChildren method of the parent-class).
So the two things I want to do is make the model realize it's been changed and refresh all viewers.
What's weird to me is that in the MyEClassImpl.java in the method setAttribute(), the
returns true so that
eNotify(new ENotificationImpl(this, Notification.SET, MyPackage.CLASS_ATTRIBUTE, oldAttributeValue, newAttributeValue));
is being executed. Still the model doesn't seem to realize the change.
Another thought concerning the view-refreshers: the command already exists in the editor menu "refresh". That does exactly what I want, refresh all viewers.
My problem is that I don't know how to access the right classes. All I have access for in my handler is the EClass and the selection, but how do I get to the corresponding AdapterFactory, ItemProvider or even the Model object?
Thanks for any help!
Markus
|
|
|
Re: Create Submenu for EMF Model [message #890173 is a reply to message #890169] |
Thu, 21 June 2012 11:14 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Markus,
Comments below.
On 21/06/2012 7:07 AM, Markus G wrote:
> Awesome, that did the trick, thanks!
>
> It brought me a step further, but I have a different problem.
> I managed to change an attribute in MyEClass (to stick to the naming
> of your code snipplet), but the change is not displayed in my model.
> Actually, the model doesn't realize that is has been changed at all (I
> can't save the changes because the state is "already oldest change").
> On top of that, I'd like to refresh all the viewers after having
> changed the attribute in my dialog-handler-function, as the attribute
> this changes is a filter. Classes with that attribute set are not
> being displayed in the model (I solved that changing the getChildren
> method of the parent-class).
If the object is being viewed, I'd expect there to be an adapter
attached to it that responds to notification. But keep in mind that if
you're making changes in an editor, you really should (must) use a
command, otherwise undo will be broken and the editor won't realize it's
gotten dirty.
>
> So the two things I want to do is make the model realize it's been
> changed and refresh all viewers.
>
> What's weird to me is that in the MyEClassImpl.java in the method
> setAttribute(), the eNotificationRequired() returns true so that
> eNotify(new ENotificationImpl(this, Notification.SET,
> MyPackage.CLASS_ATTRIBUTE, oldAttributeValue, newAttributeValue));
> is being executed. Still the model doesn't seem to realize the change.
Are there adapters in the object's eAdapers() list? They should update
the views automatically.
>
> Another thought concerning the view-refreshers: the command already
> exists in the editor menu "refresh". That does exactly what I want,
> refresh all viewers.
Yes, but that's brute force. You should only need to refresh the one
object, and that should happen automatically (as it does when you make
changes in the editor using, for example, the properties view).
>
> My problem is that I don't know how to access the right classes. All I
> have access for in my handler is the EClass and the selection, but how
> do I get to the corresponding AdapterFactory, ItemProvider or even the
> Model object?
You should be able to use
AdapterFactoryEditingDomain.getEditingDomainFor and then use it to
create a command (SetCommand) and use its command stack to execute that
command.
>
> Thanks for any help!
> Markus
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Create Submenu for EMF Model [message #890185 is a reply to message #890173] |
Thu, 21 June 2012 11:54 |
Markus G Messages: 23 Registered: June 2012 |
Junior Member |
|
|
Hi Ed,
thanks so much for the amazingly quick reply. It's very helpful to get answers to those specific questions, would take multiple amount of time to figure it out myself, so a big thanks for the help! I had it mixed up there, I thought that the setAttribute would itself create a command at some point, but of course it doesn't.
So that solved my first problem.
About refreshing the viewers:
The thing is that even if I set the filter attribute in the properties view, it doesn't refresh the whole viewer. The problem might be that my filter logic is implemented in the parent of my object, more specifically in its ItemProvider's getChildren() function. I've overridden that function to take the original Children-collection, check for the value of this one attribute, and if it's set, do not include it into its children. So I guess I would need to tell the editor to refresh my changed object's parent, then, wouldn't I?
Thanks,
Markus
EDIT: By parent, I mean the Class that MyClass is contained in. The relationship is containment.
[Updated on: Thu, 21 June 2012 11:59] Report message to a moderator
|
|
| | | | | | | | | |
Goto Forum:
Current Time: Thu Sep 26 20:42:42 GMT 2024
Powered by FUDForum. Page generated in 0.05238 seconds
|