原創|其它|編輯:郝浩|2009-08-28 11:21:00.000|閱讀 1157 次
概述:通過設斷點跟蹤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@fc6vip.cn
文章轉載自:IT專家網