Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Get the selected menu item
Get the selected menu item [message #940285] Thu, 11 October 2012 09:54 Go to next message
Linus Pettersson is currently offline Linus Pettersson
Messages: 8
Registered: October 2012
Junior Member
Hi!

In a tree editor, when creating a node I right-click, choose New Child/Sibling and click on an item which is added to the model.

Can I somehow add a listener or something so I can see what menu item the user picked?

What I want to do is to store the X latest selected menu items in the New Child/Sibling menus.
Re: Get the selected menu item [message #940302 is a reply to message #940285] Thu, 11 October 2012 10:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Linus,

Comments below.

On 11/10/2012 3:54 PM, Linus Pettersson wrote:
> Hi!
>
> In a tree editor, when creating a node I right-click, choose New
> Child/Sibling and click on an item which is added to the model.
>
> Can I somehow add a listener or something so I can see what menu item
> the user picked?
No. But in generateCreateChildActions the actions are created so you
could create specialized ones in which you can monitor which ones are
executed...
>
> What I want to do is to store the X latest selected menu items in the
> New Child/Sibling menus.
Re: Get the selected menu item [message #940334 is a reply to message #940302] Thu, 11 October 2012 10:42 Go to previous messageGo to next message
Linus Pettersson is currently offline Linus Pettersson
Messages: 8
Registered: October 2012
Junior Member
Ok, thank you.

Are there any guides or something that can help us in creating the specialized actions?

I'm very new to this so it's kind of confusing.
Re: Get the selected menu item [message #940346 is a reply to message #940334] Thu, 11 October 2012 10:50 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Linus,

It's creating a new CreateChildAction/CreateSiblingAction action and
that has a run method that's invoked to execute the command. So you
could specialize each of those and specialize their run method to keep
track of when it runs.


On 11/10/2012 4:42 PM, Linus Pettersson wrote:
> Ok, thank you.
>
> Are there any guides or something that can help us in creating the
> specialized actions?
>
> I'm very new to this so it's kind of confusing.
Re: Get the selected menu item [message #940356 is a reply to message #940346] Thu, 11 October 2012 11:04 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 701
Registered: July 2009
Senior Member
Wouldnt it make more sense to listen to the command stack?
Re: Get the selected menu item [message #940407 is a reply to message #940356] Thu, 11 October 2012 11:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Erdal,

It's not so easy to determine things like the feature that was available
in the CommandParameter used to create the command. I'm not sure what
he's planning on doing with the information he wants to "store".


On 11/10/2012 5:04 PM, Erdal Karaca wrote:
> Wouldnt it make more sense to listen to the command stack?
Re: Get the selected menu item [message #941012 is a reply to message #940407] Fri, 12 October 2012 02:25 Go to previous messageGo to next message
Linus Pettersson is currently offline Linus Pettersson
Messages: 8
Registered: October 2012
Junior Member
Thank you for your answers. Sorry if I was unclear in my previous message, I will try to explain more below.

The issue that I'm trying to solve is that the New Child/Sibling menu items are very long and it's hard to find what you want. So, to make it a little easier I want to add the, say 5, latest used items to the top of the New Child/Sibling menu. So, I need to somehow know what menu items the user clicks in the New Child/Sibling menus.
Re: Get the selected menu item [message #947629 is a reply to message #941012] Wed, 17 October 2012 05:04 Go to previous messageGo to next message
Linus Pettersson is currently offline Linus Pettersson
Messages: 8
Registered: October 2012
Junior Member
What I've done now is to create a new class, like "CreateSpecialChildAction" that extends CreateChildAction. Then I just do the magic in the run() method. Seems to work OK so far.

Now I just have to figure out where the most logical place is to place my classes...
Re: Get the selected menu item [message #965766 is a reply to message #940285] Wed, 31 October 2012 09:43 Go to previous messageGo to next message
Linus Pettersson is currently offline Linus Pettersson
Messages: 8
Registered: October 2012
Junior Member
So, there is a problem.

I have created two new classes, CreateTrackableChildAction and CreateTrackableSiblingAction which extends CreateChildAction and CreateSiblingAction. In the run() method we capture the action and saves it in a static hashmap. So, the latest used children/siblings will be in these hashmaps. They are then added to the menu in the ElementsActionBarContributor. So far so good.

The issue now is that the latest siblings and children are very separated, I mean if you add a children to a node and then right click on one of the children of this node, this newly created child should show up amongst the "latest siblings". But it doesn't, of course. The "latest siblings" is only populated when the sibling menu is used...

Maybe this approach is not the best and maybe we need to re-think this. Maybe to traverse the tree instead and get the latest used children/siblings this way?


If I traverse the tree and get a node, how can I create a menu item for this? I should do "new CreateChildAction(activeEditorPart, selection, descriptor)" but how do I get the descriptor?
Re: Get the selected menu item [message #965802 is a reply to message #965766] Wed, 31 October 2012 10:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Linus,

Comments below.


On 31/10/2012 2:43 PM, Linus Pettersson wrote:
> So, there is a problem.
>
> I have created two new classes, CreateTrackableChildAction and
> CreateTrackableSiblingAction which extends CreateChildAction and
> CreateSiblingAction. In the run() method we capture the action and
> saves it in a static hashmap.
You'd need to ensure that you create a new command.
> So, the latest used children/siblings will be in these hashmaps. They
> are then added to the menu in the ElementsActionBarContributor. So far
> so good.
>
> The issue now is that the latest siblings and children are very
> separated, I mean if you add a children to a node and then right click
> on one of the children of this node, this newly created child should
> show up amongst the "latest siblings". But it doesn't, of course. The
> "latest siblings" is only populated when the sibling menu is used...
Sorry, I don't follow. In fact I really don't understand what design
you're trying to achieve...
>
> Maybe this approach is not the best and maybe we need to re-think
> this. Maybe to traverse the tree instead and get the latest used
> children/siblings this way?
What do you mean by "used"?
>
>
> If I traverse the tree and get a node, how can I create a menu item
> for this?
That's what's normally happening already for populating the context menu...
> I should do "new CreateChildAction(activeEditorPart, selection,
> descriptor)" but how do I get the descriptor?
You can see how the code in the action bar contributor currently gets
the descriptors.
Re: Get the selected menu item [message #965840 is a reply to message #965802] Wed, 31 October 2012 10:46 Go to previous messageGo to next message
Linus Pettersson is currently offline Linus Pettersson
Messages: 8
Registered: October 2012
Junior Member
Ed Merks wrote on Wed, 31 October 2012 10:09

....
> I should do "new CreateChildAction(activeEditorPart, selection,
> descriptor)" but how do I get the descriptor?
You can see how the code in the action bar contributor currently gets
the descriptors.


Well, yes it gets all the descriptors by calling "domain.getNewChildDescriptors(object, null);". It returns all the descriptors, but what if I just want to create one specific.



What I want to achieve. Let's say you're creating a tree and you right click > New Child and this list is veeery long. Then when you add a child through this menu, it then shows up at the top of the "New Child" menu. So, at the top of the "New Child" menu we display the 5 latest added children. The same goes for the "New Sibling" menu.

The problem is that as it works now, it keeps two lists, one for latest used children and one for the latest used siblings. The thing is that if you add a children B to a node A using the "New Child" menu, and then right click on another children to A it should show B in its list of latest used siblings.
The same issue appears if you add a sibling to B and then right click its parent, A, it should show up as a recently added children.

The above doesn't work though, as we keep the lists of children/siblings separate. Do you see the issue? Smile


Maybe our approach is bad and instead of storing lists of the recently added Children/Siblings we could traverse the tree instead and find the latest added elements and create menu items based on this?
Re: Get the selected menu item [message #965865 is a reply to message #965840] Wed, 31 October 2012 11:07 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25748
Registered: July 2009
Senior Member
Linus,

Comments below.

On 31/10/2012 3:46 PM, Linus Pettersson wrote:
> Ed Merks wrote on Wed, 31 October 2012 10:09
>> ....
>> > I should do "new CreateChildAction(activeEditorPart, selection, >
>> descriptor)" but how do I get the descriptor?
>> You can see how the code in the action bar contributor currently gets
>> the descriptors.
>
>
> Well, yes it gets all the descriptors by calling
> "domain.getNewChildDescriptors(object, null);". It returns all the
> descriptors, but what if I just want to create one specific.
There's no support for that. You'll have to find your specific one
among these.
>
>
>
> What I want to achieve. Let's say you're creating a tree and you right
> click > New Child and this list is veeery long. Then when you add a
> child through this menu, it then shows up at the top of the "New
> Child" menu. So, at the top of the "New Child" menu we display the 5
> latest added children. The same goes for the "New Sibling" menu.
So basically you want to sort the list where the most recently used ones
come first. You should look closely at what's in the descriptors
because those will be what you want to record and what you want to use
as the basis for sorting.
>
> The problem is that as it works now, it keeps two lists, one for
> latest used children and one for the latest used siblings. The thing
> is that if you add a children B to a node A using the "New Child"
> menu, and then right click on another children to A it should show B
> in its list of latest used siblings.
> The same issue appears if you add a sibling to B and then right click
> its parent, A, it should show up as a recently added children.
You can't reuse the actions. The object they'll add has already been
added. You need new commands with new descriptors. As I said, it sounds
like an ordering concern.
>
> The above doesn't work though, as we keep the lists of
> children/siblings separate. Do you see the issue? :)
>
>
> Maybe our approach is bad and instead of storing lists of the recently
> added Children/Siblings we could traverse the tree instead and find
> the latest added elements and create menu items based on this?
I imagine you should keep the information about the descriptor in a
list, and you should use that list to sort the new list of descriptors.
The descriptors of typically CommandParameter instances where the
feature and the value will be what you want to use as the basis for
sorting. Keep in mind that it's the eClass() of the value that will
help with finding the corresponding feature/object-of-that-class command
parameter in the new list.
Previous Topic:[Xcore] produces non-compiling Java code when using closures
Next Topic:Creating instance of domain EClass
Goto Forum:
  


Current Time: Mon Apr 21 08:56:21 EDT 2014

Powered by FUDForum. Page generated in 0.03786 seconds