EclipseRCP开发之屏蔽视图上的右键菜单

来源:互联网 发布:磐海数据有限公司咋样 编辑:程序博客网 时间:2024/05/29 15:26

需求如题,解决如下:

 

在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);
要想实现视图不可拖动,不可关闭,更多请查看另一片文章Eclipse RCP开发剪辑之perspective 。
原创粉丝点击