Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Building dynamic context menus using Eclipse Commands(How to build dynamic context menu based on the Outline view selection)
Building dynamic context menus using Eclipse Commands [message #881690] Tue, 05 June 2012 04:49 Go to next message
Ramesh Nachimuthu is currently offline Ramesh NachimuthuFriend
Messages: 10
Registered: May 2012
Junior Member
Hi,

I am trying to create a context menu for Outline View. This context menu should be dynamic based on the selection.
For example, If element X is selected , my context menu should show

Insert X1
Insert X2
Insert X3
Insert X4

Same way if element Y is selected, I should show

Insert Y1
Insert Y2.

This list is dynamically calculated based on the selection. Here all are 'Insert' action. So we are trying to create a command called 'Insert Command' and pass these X1 or X2 or Y1, etc as a parameter to this command. The context menu items should be created using the above 'Insert Command'.

We are facing three problems here,
1. How to pass these values (X1 or X2 or X3 etc) as a parameter to 'Insert Command'?
2. How to pass Domain Objects as a parameter to Command (not just String)?
3. How to create the list of menu items (Insert X1, Insert X2, Insert X3, etc) based on the single 'Insert Command'?.

See the attached image to see the UI how it will look.

Note: We are not trying to Enable/Disable context menu based on the selection. Our menu items will be which can be based on one paramterized command ('Insert Command')

This is easily achievable using Actions, but we wanted to use Eclipse Commands not Actions.

Regards,
Ramesh





[Updated on: Tue, 05 June 2012 04:52]

Report message to a moderator

Re: Building dynamic context menus using Eclipse Commands [message #881867 is a reply to message #881690] Tue, 05 June 2012 12:00 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

When you define your command, you can define that it takes a parameter. Commands like org.eclipse.ui.views.showView (org.eclipse.ui/plugins.xml) are defined that way.

Then you can place a dynamic element in your org.eclipse.ui.menus/menuContribution. Your dynamic class should subclass org.eclipse.ui.actions.CompoundContributionItem.

You can create your CommandContributionItems using CommandContributionItemParameters. You would normally get your domain object by querying activeMenuSelection or selection in your handler execute(*) method.

But what do the insert commands have to know? What difference is there between them? Is it like the PDE editor when you select a command element you can add 2 children, but when you select a handler element you can only add 1?

PW




Re: Building dynamic context menus using Eclipse Commands [message #882279 is a reply to message #881867] Wed, 06 June 2012 07:21 Go to previous messageGo to next message
Ramesh Nachimuthu is currently offline Ramesh NachimuthuFriend
Messages: 10
Registered: May 2012
Junior Member
Thank you Paul for your fast help,

I am able to contribute menu items using CommandContributionItems. It is exactly same as PDE Editor. In PDE editor, always we will get 'New' Sub Menu even if we have only one action under 'New'. But in my use case, I have to create 'Insert' Sub Menu only if there are more than two items to show under it, Otherwise I will show these insert actions as part of the main menu itself.

what do the insert commands have to know?

It should know the tree selection which is very easy and it should know what 'Insert' action the user has clicked. It will be helpful if I can get the actual domain objects which is used to create the menu item ( If 'Insert X' is the menu, I need domain object X not just the string 'X').

Inside my dynamic Menu Contributor class, we will get some list of Domain Objects based on the tree selection which we will use to create the dynamic list of menu items. We are trying to attach these domain objects with the menu items, so that inside my command handler I can get them easily.

Thanks with Regards,
Ramesh
Re: Building dynamic context menus using Eclipse Commands [message #883449 is a reply to message #882279] Fri, 08 June 2012 15:05 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

So your "Domain Objects" are instances of an object not related to the selection you actually opened the context menu on?

How can you create them without know the parent object?

PW


Re: Building dynamic context menus using Eclipse Commands [message #885473 is a reply to message #883449] Wed, 13 June 2012 04:26 Go to previous messageGo to next message
Ramesh Nachimuthu is currently offline Ramesh NachimuthuFriend
Messages: 10
Registered: May 2012
Junior Member
My Problem is getting complicated more now..

My Domain objects (List of Objects) are selected based on Tree Selection. But I want to attach each of them in different menu items in the same context menu.
For example domain objects list (X1, X2, X3) is created out of the tree selection then I want to attach X1 to 'Insert X1' option, X2 to 'Insert X2' option,X3 to 'Insert X3' option, in the same context menu. As on work around i am attaching string 'X1 or 'X2' as parameter then I am retrieving the domain Object again from the Tree selection inside my command handler.
Is there any other way to avoid this work around?.

I am facing one more issues.


I have to disable some menu items in the above dynamic context menu based some domain specific logic. For example I want to disable 'Insert X1' option but 'Insert X2' and 'Insert X3' should be active.


Regards,
Ramesh


[Updated on: Wed, 13 June 2012 04:28]

Report message to a moderator

Re: Building dynamic context menus using Eclipse Commands [message #885678 is a reply to message #885473] Wed, 13 June 2012 12:31 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

I still don't understand your domain objects. When you right click and chose a menu item, the current selection will be made available to your handler. What creates these "domain objects"? Why do they have to be retrieved instead of simply being created in the handler?

As for enabled/disabled, a command is enabled or disabled regardless of its parameterized menu items. So they're either all disabled or all enabled. Usually items that aren't applicable just aren't shown instead of making them disabled.

PW


Re: Building dynamic context menus using Eclipse Commands [message #886002 is a reply to message #885678] Thu, 14 June 2012 02:49 Go to previous messageGo to next message
Ramesh Nachimuthu is currently offline Ramesh NachimuthuFriend
Messages: 10
Registered: May 2012
Junior Member
Regarding Domain Objects,

We are building a UI Designer. Outline will show all the UI Elements in hierarchical
manner. We have to enable the user to add new elements to existing element using context menus. For example,

If a user select a 'Frame' in Outline, Context Menu should show the following
options, 'Insert Toolbar', 'Insert Header', 'Insert Menubar', 'Insert Button', etc. Same way, if user selects a 'Toolbar' in Outline context menu options will be 'Insert Toolbar Item' only . We have a common 'InsertElement' command with one handler which can take care of all insertions. I just have to pass one parameter to inform the Handler about what is being inserted(Button or Toolbar, Menubar ,etc).

I am able to create the Context Menu dynamically based on tree selection and Dynamic Contribution. Currently using "String' parameters I am passing this element names and inside the handler I am retrieving the 'Element details'. It works fine.

Regarding Enable/Disable,
According to our UI Guidline, we have to make the context menus consistent for particular contexts. In the above example, If the selected 'Frame' already has a 'Toolbar'(It can have only one toolbar) I should show the 'Insert Toolbar' menu item in disabled mode instead of simple removing it. This is for better user interactions and accessibility reasons.

I have one more use case as well,

In the same dynamic context menu, if there are only 3 or less than 3 Insert options then I should show them in direct context menu, If menu items are more than 3 then I have to create 'Insert' sub menu and put all insert menu items inside the 'Insert' Sub menu. Here insert menu items are dynamically contributed as stated earlier. I can use the same Dynamic Contributor to contribute to Main Menu as well as 'Insert' sub menu. DO you have any idea about how this can implemented?

All these things are easily possible with Actions Razz .
Thanks with Regards,
Ramesh

[Updated on: Thu, 14 June 2012 03:07]

Report message to a moderator

Re: Building dynamic context menus using Eclipse Commands [message #886194 is a reply to message #886002] Thu, 14 June 2012 12:19 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Ramesh Nachimuthu wrote on Wed, 13 June 2012 22:49

Regarding Enable/Disable,
According to our UI Guidline, we have to make the context menus consistent for particular contexts. In the above example, If the selected 'Frame' already has a 'Toolbar'(It can have only one toolbar) I should show the 'Insert Toolbar' menu item in disabled mode instead of simple removing it. This is for better user interactions and accessibility reasons.



I'll just point out that this is different than most standard UI guidelines. Context menu items should be focused on the current selection/context, or simply not there if they're not applicable.

But it's true that menu bar (main menu) menu items should change position much less frequently and should be disabled rather than invisible.

PW


Re: Building dynamic context menus using Eclipse Commands [message #886224 is a reply to message #886194] Thu, 14 June 2012 13:25 Go to previous message
Ramesh Nachimuthu is currently offline Ramesh NachimuthuFriend
Messages: 10
Registered: May 2012
Junior Member
Hi Paul,

Do you see any way to implement the Enable/Disable behaviour. We are also struggling with 'Insert' submenu. Dynamically we have to create it based on the menu item count.

[Updated on: Thu, 14 June 2012 13:25]

Report message to a moderator

Previous Topic:Updating statuses...
Next Topic:IHelpContentProducer implementation
Goto Forum:
  


Current Time: Fri Nov 28 19:46:17 GMT 2014

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

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