您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“Eclipse RCP編輯器關(guān)閉按鈕的屏蔽方法是什么”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
通過設(shè)斷點(diǎn)跟蹤Eclipse RCP的代碼, 發(fā)現(xiàn)編輯器上的關(guān)閉按鈕其實(shí)并不屬于Editor控件的一部分,而是editor所屬容器的,具體層次結(jié)構(gòu)沒有深入去研究,總之按鈕是加在AbstractTabFolder這樣一個控件上的。RCP在啟動時,會通過默認(rèn)的WorkbenchPresentationFactory在生成GUI上的DefaultTabFolder,并且默認(rèn)具有關(guān)閉按鈕。因此屏蔽關(guān)閉按鈕就從此入手。
首先,在ApplicationWorkbenchWindowAdvisor類的preWindowOpen()方法中注冊我們自己定制的PresentationFactory。
Java代碼:
configurer.setPresentationFactory(new UnCloseableEditorPresentationFactory()); |
UnCloseableEditorPresentationFactory類繼承WorkbenchPresentationFactory類,為了不影響別的GUI功能,我們只需要重寫public StackPresentation createEditorPresentation(Composite parent, IStackPresentationSite site)方法中的關(guān)于設(shè)置TableFolder的部分,具體如下:
Java代碼:
DefaultTabFolder folder = new UnCloseableEditorFolder(parent, editorTabPosition | SWT.BORDER, site.supportsState(IStackPresentationSite.STATE_MINIMIZED), site.supportsState(IStackPresentationSite.STATE_MAXIMIZED)); ... |
該方法中其余部分代碼,把父類的復(fù)制過來即可。
***就是定義我們自己的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編輯器關(guān)閉按鈕的屏蔽方法是什么”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。