Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Disable/Remove SVN context menu items appearing in DiagramEditor
icon4.gif  Disable/Remove SVN context menu items appearing in DiagramEditor [message #1695819] Tue, 19 May 2015 14:17 Go to next message
Saniya Mirajkar is currently offline Saniya MirajkarFriend
Messages: 31
Registered: August 2012
Member
Hi ,

I have recently upgraded my code from graphiti version 0.9 to 0.11.

I have handled changes to migrate my code base to new version.
After migration I now see new context menu items realted to Logviewer/ SVN such as :Open with Log Viewer,Validate, Team,Comapre with,Replace with etc. along with my custom context menu options as in attached image.

I want to remove the this extra context menu options.
I already use the following code to remove Delete,Update and Remove context menu items in my ToolBehaviour provider class.

public IContextButtonPadData getContextButtonPad(
			final IPictogramElementContext context_) {
		final IContextButtonPadData data = super.getContextButtonPad(context_);
		final PictogramElement pe = context_.getPictogramElement();

		// Set the generic context buttons
		// default remove,delete and update buttons on context pad are removed
		setGenericContextButtons(data, pe, 0);
		return data;

	}


I do not get from where this extra options are added and how do I remove those context menu options?

[Updated on: Wed, 20 May 2015 06:58]

Report message to a moderator

Re: Disable/Remove SVN context menu items appearing in DiagramEditor [message #1695901 is a reply to message #1695819] Wed, 20 May 2015 08:14 Go to previous message
Jerome Sivadier is currently offline Jerome SivadierFriend
Messages: 15
Registered: May 2015
Junior Member
Hello Saniya,

There are several ways to customize the context menu. The first one is to use the ToolBehavior as you mentioned but several menu options can be added automatically by Eclipse as the "Team" ones.
To deal with these problems you can either customize the context menu provider or delegate the menu management to your ActionBarContributor.

If you want to customize the context menu provider, you need to override the DiagramBehavior#createContextMenuProvider (http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.graphiti.doc%2Fjavadoc%2Forg%2Feclipse%2Fgraphiti%2Fui%2Feditor%2FDiagramBehavior.html) with a class which can extend DiagramEditorContextMenuProvider, see the method #buildContextMenu() (http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.graphiti.doc%2Fjavadoc%2Forg%2Feclipse%2Fgraphiti%2Fui%2Feditor%2FDiagramEditorContextMenuProvider.html).

If you want to delegate the management to your ActionBarContributor you can make your custom DiagramEditor class implement IMenuListener, then create a context menu for the graphical viewer and implement the "menuAboutToShow" method accordingly. Below are my own implementations of the two methods mentioned previously.

public class EditorPopupBarManager extends MenuManager implements IMenuListener2 {
	
	public EditorPopupBarManager(String text, IMenuListener primaryMenuListener) {
		super(text);
		this.addMenuListener(primaryMenuListener);
		initContribution();
	}
	
	
	/**
	 * Location for the contribution
	 */
	public static final String POPUP_LOCATION = "popup:my.menu";
	
	
	private void initContribution() {
		this.addMenuListener(this);
	}
	
	@Override
	public void dispose() {
		// release the contribution manager
		IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class);
		menuService.releaseContributions(this);
		super.dispose();
		
	}
	
	@Override
	public void menuAboutToShow(IMenuManager manager) {
		// add new
		IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class);
		menuService.populateContributionManager(this, POPUP_LOCATION);
	}
	
	@Override
	public void menuAboutToHide(IMenuManager manager) {
	}
}

/**
  * Creates a context menu for the given graphical viewer
  * @param graphicalViewer a graphical viewer
  */
protected void createContextMenuFor(GraphicalViewer graphicalViewer) {
	MenuManager contextMenu = new EditorPopupBarManager("#PopUp", this);
	contextMenu.setRemoveAllWhenShown(true);
	Menu menu = contextMenu.createContextMenu(graphicalViewer.getControl());
	graphicalViewer.getControl().setMenu(menu);
}

@Override
public void menuAboutToShow(IMenuManager menu) {
	// Call the action bar's menu about to show method
	getActionBarContributor().menuAboutToShow(menu);
}


To use the second method you will need to have somehow a "getActionBarContributor()" method returning the ActionBarContributor linked with your Editor Smile.

I do not know which method is the best, or if there are other methods but I use the second one in my project.

Regards,
Jérôme

[Updated on: Wed, 20 May 2015 08:23]

Report message to a moderator

Previous Topic:Example/Tutorial for Non-Emf model in Graphiti
Next Topic:child shape inside parent shape
Goto Forum:
  


Current Time: Tue Mar 19 09:16:45 GMT 2024

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

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

Back to the top