Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » customizing conext menu
customizing conext menu [message #1078247] Fri, 02 August 2013 18:50 Go to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi everyone,

hope that this is the right forum for my Question.

I'm currently developing a EMF/GMF Editor which opens the following context menu while right clicking on elements:

index.php/fa/15818/0/

I would like to customize this by removing stuff like Wizard, Run as, Debug as and so on..This menu entries seams to appear in every explorer view.. Is there a way to remove it for the editor?

Cheers,
Phil
Re: customizing conext menu [message #1088761 is a reply to message #1078247] Sat, 17 August 2013 16:14 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
No ideas or wrong forum?
Re: customizing conext menu [message #1088770 is a reply to message #1088761] Sat, 17 August 2013 16:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Phil,

It's better to ask on a more specific forum such as eclipse.tools.emf or
eclipse.modeling.gmf. Sorry I overlooked your post....

The entries on on the menu because of the behavior in the generated
XyzActionBarContributor (where Xyz depends on your GenPackage's Prefix
property. You'll find the lofic in the generated void
selectionChangedGen(SelectionChangedEvent event) method...


On 17/08/2013 6:14 PM, Phil H wrote:
> No ideas or wrong forum?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: customizing conext menu [message #1089241 is a reply to message #1088770] Sun, 18 August 2013 11:38 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

I already asked in the EMF Forum (http://www.eclipse.org/forums/index.php/m/1071096/#msg_1071096), but there you couldn't helped me so I thought this would be a good place to ask Wink

Unfortunately I couldn't find the method you mentioned in my generated actionbarcontributor class. As I mentioned in another post, org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor.menuAboutToShow(IMenuManager menuManager) seems to be the place where additions (isn't it the stuff like Wizard etc.?) is added. Is it possible to alter this?

Cheers,
Phil
Re: customizing conext menu [message #1091957 is a reply to message #1089241] Thu, 22 August 2013 06:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Phil,

All generated editors generate a class that extends
EditingDomainActionBarContibutor that implements
ISelectionChangedListener and implement that method, so you must be able
to find it. And of course you can override any methods you like.


On 18/08/2013 1:38 PM, Phil H wrote:
> Hi Ed,
>
> I already asked in the EMF Forum
> (http://www.eclipse.org/forums/index.php/m/1071096/#msg_1071096), but
> there you couldn't helped me so I thought this would be a good place
> to ask ;)
>
> Unfortunately I couldn't find the method you mentioned in my generated
> actionbarcontributor class. As I mentioned in another post,
> org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor.menuAboutToShow(IMenuManager
> menuManager) seems to be the place where additions (isn't it the stuff
> like Wizard etc.?) is added. Is it possible to alter this?
>
> Cheers,
> Phil


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: customizing conext menu [message #1094395 is a reply to message #1091957] Sun, 25 August 2013 16:39 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

so you mean this method: public void selectionChanged(SelectionChangedEvent event) ? I had a look at this method, but couldn't find any hint how to remove Wizard etc.

As the doc metnioned it seems only be responsible for the New Child/Sibling menu:

"...by querying for the children and siblings that can be added to the selected object and updating the menus accordingly."

Cheers

Re: customizing conext menu [message #1100120 is a reply to message #1094395] Mon, 02 September 2013 18:04 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Any further suggestions on this?
Re: customizing conext menu [message #1100477 is a reply to message #1100120] Tue, 03 September 2013 06:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Phil,

There are all kinds of example in the existing code. JFace supports
things like object contributions, so that also a possible approach.

On 02/09/2013 8:04 PM, Phil H wrote:
> Any further suggestions on this?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: customizing conext menu [message #1100720 is a reply to message #1100477] Tue, 03 September 2013 13:51 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
What kind of examples do you mean? I was able to figure out how to remove some entries, but there are still entries like "run as", "debug as", "Team" and so on (see attached image).

I thought maybe commeting out "getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer));" in createContextMenuFor(StructuredViewer viewer) would do the trick, but it hasn't changed anything.
I also checked my plugin dependencies, but couldn't find anything which could contribute this menu entries.

I don't really understand how your Jface approach should work. How can object contribution remove menu entries from ymmeditor?
  • Attachment: menus.png
    (Size: 8.50KB, Downloaded 162 times)
Re: customizing conext menu [message #1100850 is a reply to message #1100720] Tue, 03 September 2013 17:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Phil,

Are you still trying to remove things or to add things? Maybe someone
else can explain how to remove things; I've not tried to do that... If
you look in the plugin.xml for org.eclipse.emf.ecore.editor, you'll see
how it contributes actions that appear in every contact menu, e.g., this
contribution for creating a dynamic instance form an EClass.

<extension point="org.eclipse.ui.popupMenus">
....
<objectContribution
id="org.eclipse.emf.ecore.editor.CreateDynamicInstance"
objectClass="org.eclipse.emf.ecore.EClass">
<action
id="org.eclipse.emf.ecore.editor.CreateDynamicInstanceAction"
label="%_UI_CreateDynamicInstance_menu_item"
menubarPath="additions"
class="org.eclipse.emf.ecore.action.CreateDynamicInstanceAction"
enablesFor="1"/>
</objectContribution>
</extension>

On 03/09/2013 3:51 PM, Phil H wrote:
> What kind of examples do you mean? I was able to figure out how to remove some entries, but there are still entries like "run as", "debug as", "Team" and so on (see attached image).
>
> I thought maybe commeting out "getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer));" in createContextMenuFor(StructuredViewer viewer) would do the trick, but it hasn't changed anything.
> I also checked my plugin dependencies, but couldn't find anything which could contribute this menu entries.
>
> I don't really understand how your Jface approach should work. How can object contribution remove menu entries from ymmeditor?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: customizing conext menu [message #1102080 is a reply to message #1100850] Thu, 05 September 2013 10:30 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
I want to remove it! In the GMF Editor this menu entries don't appear, so there must be added somewhere in the EMF code..But it's hard to track where so I thing it's not possible to remove them..
Re: customizing conext menu [message #1102095 is a reply to message #1102080] Thu, 05 September 2013 10:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Phil,

They're not contributed directly by EMF code, but the generated editor,
in the createContextMenu method, calls
org.eclipse.ui.IWorkbenchPartSite.registerContextMenu(MenuManager,
ISelectionProvider) so that "registered contributions" appear in the
context menu.


On 05/09/2013 12:30 PM, Phil H wrote:
> I want to remove it! In the GMF Editor this menu entries don't appear,
> so there must be added somewhere in the EMF code..But it's hard to
> track where so I thing it's not possible to remove them..


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: customizing conext menu [message #1102194 is a reply to message #1102095] Thu, 05 September 2013 13:48 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

as mentioned before, commenting out getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer)) in createContextMenuFor(StructuredViewer viewer) doesn't change anything. Is this normal or should this normally remove the menu entries?
Re: customizing conext menu [message #1102204 is a reply to message #1102194] Thu, 05 September 2013 14:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Phil,

I just tested your assertion and it appears to be false. In any case,
EMF does not add those entries; they must come from registrations...


On 05/09/2013 3:48 PM, Phil H wrote:
> Hi Ed,
>
> as mentioned before, commenting out
> getSite().registerContextMenu(contextMenu, new
> UnwrappingSelectionProvider(viewer)) in
> createContextMenuFor(StructuredViewer viewer) doesn't change anything.
> Is this normal or should this normally remove the menu entries?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: customizing conext menu [message #1102234 is a reply to message #1102204] Thu, 05 September 2013 14:52 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

what do you mean with false? My assertion or what you mentioned before?

So with registrations you mean the extensions defined in the plugin.xml of the generated editor project?
Re: customizing conext menu [message #1102261 is a reply to message #1102234] Thu, 05 September 2013 15:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Phil,

Your assertion is false: commenting out that call results, for me, in a
context menu with only the things directly contributed by the generated
code (and the base classes the generate code extends).

By registrations I mean other plugins (i.e., neither EMF and nor your
generated plugins) that contribute menu items that target the context
menus throughout Eclipse.


On 05/09/2013 4:52 PM, Phil H wrote:
> Hi Ed,
>
> what do you mean with false? My assertion or what you mentioned before?
>
> So with registrations you mean the extensions defined in the
> plugin.xml of the generated editor project?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: customizing conext menu [message #1102293 is a reply to message #1078247] Thu, 05 September 2013 15:57 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hmm, that is really odd..So you don't have any menu entries like Wizards, Run As, Debus As, Team and son anymore?

I can't remember that I've added additional plugins..At all I give up with this..
Re: customizing conext menu [message #1102307 is a reply to message #1102293] Thu, 05 September 2013 16:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Phi,

Comments below.

On 05/09/2013 5:57 PM, Phil H wrote:
> Hmm, that is really odd..So you don't have any menu entries like
> Wizards, Run As, Debus As, Team and son anymore?
No, those are contributed by other things in the platform and that call
registers the context menu to receive those contributions...
>
> I can't remember that I've added additional plugins..At all I give up
> with this..
When you launch, any plugin included in the launch configuration can
register extension in their plugin.xmls that contribute to these menu
items; by default that's all your bundles in the workspace and all the
bundles in your target platform, i.e., the debugger framework, the team
framework, and so on.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: customizing conext menu [message #1103034 is a reply to message #1102307] Fri, 06 September 2013 10:08 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Hi Ed,

you're right, I just found out that there is another class which calling this method. Commeting out this removed all the contributed stuff like "Wizards" etc., but unfortunately also the menuitem which I contributed in the plugin.xml isn't shown anymore.

Just calling getSite().registerContextMenu("myCommandId", contextMenu, new UnwrappingSelectionProvider(viewer)); hasn't worked.

So I thought about filtering out the unwanted contributions with this code:

protected void createContextMenuFor(StructuredViewer viewer) {
	MenuManager contextMenu = new MenuManager("#PopUp") {
		@Override
		public IContributionItem[] getItems() {

			IContributionItem[] items = super.getItems();
			List<IContributionItem> filteredItems = new ArrayList<IContributionItem>();
			for (IContributionItem item : items) {
				if (item != null && item.getId() != null && ((item.getId().startsWith("org.itea2"))))
				      filteredItems.add(item);
				}
				items = new IContributionItem[filteredItems.size()];
				return filteredItems.toArray(items);
			}
		};
	contextMenu.add(new Separator("additions"));
	contextMenu.setRemoveAllWhenShown(true);
	contextMenu.addMenuListener(this);
	Menu menu = contextMenu.createContextMenu(viewer.getControl());
	viewer.getControl().setMenu(menu);
	getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer));

	int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
	Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() };
	viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
	viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(getEditingDomain(), viewer));
}


This works fine for my menuitem, but it turned out that using this filter (it doesn't matter which string is used in item.getId().startsWith("org.itea2")) results in a context menu without the EMF menu items like "New Child", "undo" etc.

Is there any workaround for this?

[Updated on: Fri, 06 September 2013 10:14]

Report message to a moderator

Re: customizing conext menu [message #1103691 is a reply to message #1103034] Sat, 07 September 2013 05:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Phil,

Comment below.

On 06/09/2013 12:08 PM, Phil H wrote:
> Hi Ed,
>
> you're right, I just found out that there is another class which
> calling this method. Commeting out this removed all the contributed
> stuff like "Wizards" etc., but unfortunately also the menuitem which I
> contributed in the plugin.xml isn't shown anymore.
Yes, that's to ge expected.
>
> Just calling getSite().registerContextMenu("myCommandId", contextMenu,
> new UnwrappingSelectionProvider(viewer)); hasn't worked.
No, the ID you use is important.
>
> So I thought about filtering out the unwanted contributions with this
> code:
>
>
> protected void createContextMenuFor(StructuredViewer viewer) {
> MenuManager contextMenu = new MenuManager("#PopUp") {
> @Override
> public IContributionItem[] getItems() {
>
> IContributionItem[] items = super.getItems();
> List<IContributionItem> filteredItems = new
> ArrayList<IContributionItem>();
> for (IContributionItem item : items) {
> if (item != null && item.getId() != null &&
> ((item.getId().startsWith("org.itea2"))))
> filteredItems.add(item);
> }
> items = new IContributionItem[filteredItems.size()];
> return filteredItems.toArray(items);
> }
> };
> contextMenu.add(new Separator("additions"));
> contextMenu.setRemoveAllWhenShown(true);
> contextMenu.addMenuListener(this);
> Menu menu = contextMenu.createContextMenu(viewer.getControl());
> viewer.getControl().setMenu(menu);
> getSite().registerContextMenu(contextMenu, new
> UnwrappingSelectionProvider(viewer));
>
> int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
> Transfer[] transfers = new Transfer[] {
> LocalTransfer.getInstance() };
> viewer.addDragSupport(dndOperations, transfers, new
> ViewerDragAdapter(viewer));
> viewer.addDropSupport(dndOperations, transfers, new
> EditingDomainViewerDropAdapter(getEditingDomain(), viewer));
> }
>
>
> This works fine for my menuitem, but it turned out that using this
> filter (it doesn't matter which sring is used in
> item.getId().startsWith("org.itea2")) results in a context menu
> without the EMF menu items like "New Child", "undo" etc.
>
> Is there any workaround for this?
It looks like your filter filters out pretty much everything. Are you
actually using a debugger to observe what your filter is doing?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: customizing conext menu [message #1104080 is a reply to message #1103691] Sat, 07 September 2013 20:57 Go to previous message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
It seems that the EMF menu items have no ID, so the following has done the trick:

if ((item != null) && ((item.getId() == null) || (item.getId().startsWith("org.itea2")))) {
       filteredItems.add(item);
}
Previous Topic:Error Log - Problem occurred when invoking org.eclipse.ui.navigator
Next Topic:Eclipse Console Caret Position
Goto Forum:
  


Current Time: Thu Apr 18 03:59:33 GMT 2024

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

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

Back to the top