需求如題,解決如下:
在ApplicationWorkbenchWindowAdvisor類中加上如下方法:
//屏蔽視圖上的右鍵菜單
public void postWindowOpen() {
PlatformUI.getWorkbench().getDisplay().addFilter(SWT.MouseUp,
new Listener() {
public void handleEvent(final Event event) {
if (event.button == 3&&event.widget == your editor ) {
int hwndCursor = OS.GetCapture();
OS.PostMessage(hwndCursor, OS.WM_LBUTTONDOWN,
hwndCursor, OS.HTCLIENT
| (OS.WM_MOUSEMOVE << 16));
}
}
});
}
加上如下方法後,雖然屏蔽掉了右鍵菜單,但是視圖還是可以拖動的,要使其不可以拖動或不可以關閉,應該在Perspective類中的public void createInitialLayout(IPageLayout layout)方法中設置:
IFolderLayout folderLayout = layout.createFolder("topRight", IPageLayout.RIGHT, 0.77f,editorArea);
folderLayout.addView(IEView.ID);
// 設置地圖視圖不能關閉、不能拖動
layout.getViewLayout(IEView.ID).setCloseable(false);
layout.getViewLayout(IEView.ID).setMoveable(false);