Eclipse RCP编辑器如何关闭按钮

原创|其它|编辑:郝浩|2009-08-28 11:21:00.000|阅读 1156 次

概述:通过设断点跟踪Eclipse RCP的代码, 发现编辑器上的关闭按钮其实并不属于Editor控件的一部分,而是editor所属容器的,具体层次结构没有深入去研究,总之按钮是加在AbstractTabFolder这样一个控件上的。

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

  通过设断点跟踪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几年来一点小小的心得体会。


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com

文章转载自:IT专家网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP