Disable/Remove SVN context menu items appearing in DiagramEditor [message #1695819] |
Tue, 19 May 2015 14:17 |
Saniya Mirajkar 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 |
Jerome Sivadier 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 .
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
|
|
|
Powered by
FUDForum. Page generated in 0.02049 seconds