Eclipse RCP编辑器关闭按钮的屏蔽方法
创始人
2024-03-31 10:20:46
0

通过设断点跟踪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)

 {   super(parent, flags, allowMin, allowMax);  } 

 @SuppressWarnings("restriction")

 public AbstractTabItem add(int index, int flags)

{   return super.add(index, flags ^ SWT.CLOSE);  }

以上就是需要定制的代码,另外,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);     } }

 以上就是个人从事RCP几年来一点小小的心得体会。

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...