Eclipse RCP 之屏蔽視圖上的右鍵菜單

 

需求如題,解決如下:

 

在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);

發佈了10 篇原創文章 · 獲贊 13 · 訪問量 34萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章