温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Eclipse RCP编辑器关闭按钮的屏蔽方法是什么

发布时间:2021-07-13 15:13:15 来源:亿速云 阅读:153 作者:chen 栏目:编程语言

本篇内容介绍了“Eclipse RCP编辑器关闭按钮的屏蔽方法是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

通过设断点跟踪Eclipse RCP的代码, 发现编辑器上的关闭按钮其实并不属于Editor控件的一部分,而是editor所属容器的,具体层次结构没有深入去研究,总之按钮是加在AbstractTabFolder这样一个控件上的。RCP在启动时,会通过默认的WorkbenchPresentationFactory在生成GUI上的DefaultTabFolder,并且默认具有关闭按钮。因此屏蔽关闭按钮就从此入手。

首先,在ApplicationWorkbenchWindowAdvisor类的preWindowOpen()方法中注册我们自己定制的PresentationFactory。

Java代码:

configurer.setPresentationFactory(new UnCloseableEditorPresentationFactory());


UnCloseableEditorPresentationFactory类继承WorkbenchPresentationFactory类,为了不影响别的GUI功能,我们只需要重写public StackPresentation createEditorPresentation(Composite parent, IStackPresentationSite site)方法中的关于设置TableFolder的部分,具体如下:

Java代码:

DefaultTabFolder folder = new UnCloseableEditorFolder(parent,
 editorTabPosition | SWT.BORDER,         site.supportsState(IStackPresentationSite.STATE_MINIMIZED),           site.supportsState(IStackPresentationSite.STATE_MAXIMIZED)); ...

该方法中其余部分代码,把父类的复制过来即可。

***就是定义我们自己的UnCloseableEditorFolder了

Java代码:

public UnCloseableEditorFolder(Composite parent,
int flags,boolean allowMin, boolean allowMax)

以上就是需要定制的代码,另外,UnCloseableEditorPresentationFactory类中,我们还可以public StackPresentation createEditorPresentation(Composite parent, IStackPresentationSite site)中定制StandardViewSystemMenu,从而去掉RCP中编辑器folder上的菜单中的close,closeall,new editor等菜单

Java代码:

class StandardEditorSystemMenu extends StandardViewSystemMenu
{          /**      * @param site      */
 public StandardEditorSystemMenu(IStackPresentationSite site)
 {         super(site);            }
String getMoveMenuText()
{      return WorkbenchMessages.EditorPane_moveEditor;     }
 /* (non-Javadoc)      * @see org.eclipse.ui.internal.presentations.util.
ISystemMenu#show(org.eclipse.swt.widgets.Control, org.eclipse.swt.graphics.Point,
 org.eclipse.ui.presentations.IPresentablePart)      */
 public void show(Control parent, Point displayCoordinates,
 IPresentablePart currentSelection) {   super.show(parent, displayCoordinates,
 currentSelection);     } }


“Eclipse RCP编辑器关闭按钮的屏蔽方法是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI