首先,在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)); ... |
该方法中其余部分代码,把父类的复制过来即可。 copyright dedecms
最后就是定义我们自己的UnCloseableEditorFolder了
Java代码: 内容来自dedecms
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等菜单 内容来自dedecms
Java代码: 内容来自dedecms
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, dedecms.com org.eclipse.ui.presentations.IPresentablePart) */ public void show(Control parent, Point displayCoordinates, IPresentablePart currentSelection) { super.show(parent, displayCoordinates, currentSelection); } } |
以上就是个人从事RCP几年来一点小小的心得体会。 dedecms.com
复制地址和好友共享








