Eclipse RCP 屏蔽视图Tab上的右键
自定义RCP视图Tab的右键菜单(屏蔽右键):最近在做一个项目有此需求,经过研究Eclipse源码,发现可以通过下面方法实现。
定制Eclipse视图Tab的右键系统菜单(或者屏蔽Tab上的系统右键菜单)介绍:
1.在ApplicationWorkbenchWindowAdvisor类的preWindowOpen()方法中为 IWorkbenchWindowConfigurer添加一个自定义WorkbenchPresentationFactory工厂类;
2.在自定义WorkbenchPresentationFactory工厂类中实现public StackPresentation createViewPresentation(Composite parent,IStackPresentationSite site)方法:代码如下:
public StackPresentation createViewPresentation(Composite parent,
IStackPresentationSite site) {
/**XXXTabFolder继承于AbstractTabFolder.*/
XXXTabFolder folder = new XXXTabFolder(parent,
viewTabPosition | SWT.BORDER);
PresentablePartFolder partFolder = new PresentablePartFolder(folder);
folder.setUnselectedCloseVisible(false);
folder.setUnselectedImageVisible(true);
TabbedStackPresentation result = new TabbedStackPresentation(site,
partFolder, new XXXStandardSystemMenu(site));
/** XXXPropertyListener继承于AbstractPropertyListener. */
XXXPropertyListener themeListener = new EduPropertyListener(folder,
result.getTheme());
result.getTheme().addListener(themeListener);
/** XXXSimpleTabListener继承于AbstractBooleanListener. */
new XXXSimpleTabListener(result.getApiPreferences(),
IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
folder);
return result;
}
其中XXXStandardSystemMenu(site)就是定义我们自己的系统菜单(现在我是 屏蔽所有右键菜单)
public class XXXStandardSystemMenu implements ISystemMenu {
MenuManager menuManager = new MenuManager();
/**
* Create the standard view menu
*
* @param site
* the site to associate the view with
*/
public XXXStandardSystemMenu(IStackPresentationSite site) {
site.addSystemActions(menuManager);
}
public String getMoveMenuText() {
return WorkbenchMessages.ViewPane_moveView;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.internal.presentations.util.ISystemMenu#show(org.eclipse
* .swt.graphics.Point, org.eclipse.ui.presentations.IPresentablePart)
*/
public void show(Control parent, Point displayCoordinates,
IPresentablePart currentSelection) {
Menu aMenu = menuManager.createContextMenu(parent);
menuManager.removeAll();
aMenu.setLocation(displayCoordinates.x, displayCoordinates.y);
aMenu.setVisible(false);
}
/**
* Dispose resources associated with this menu
*/
public void dispose() {
menuManager.dispose();
menuManager.removeAll();
}
顺便说一句屏蔽编辑器右键也是一样的原理实现。
大体一个框架就出来了,具体的 实现可以去看eclipse源码。