[英]Adding toolbar to org.eclipse.ui.forms.widgets.Section via plugin.xml
我正在創建一個Eclipse應用程序。 我創建了一個具有多個org.eclipse.ui.forms.widgets.Section
的Editor,並且每個Section都有自己的工具欄,當前僅在Editor代碼中聲明該工具欄。 我需要做的是將工具欄代碼與編輯器代碼分開。 分離工具欄代碼的最佳方法是什么。 由於存在多個toolItem,因此編輯器的代碼變得復雜。 我們可以在org.eclipse.ui.forms.widgets.Section
plugin.xml
定義工具欄嗎? 當前使用以下代碼行將工具欄添加到Section:
ToolBar toolBar = new ToolBar(section, SWT.FLAT | SWT.RIGHT);
該部分沒有任何擴展點。
您可以使用ToolBarManager
作為工具欄。 這樣,您就可以在工具欄中使用Action
類(和其他貢獻項目)。 這使您可以將代碼分成單獨的類。
例如,這是plugin.xml編輯器將“字母排序”按鈕添加到“所需插件”部分的方式:
private void createSectionToolbar(Section section, FormToolkit toolkit) {
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
ToolBar toolbar = toolBarManager.createControl(section);
final Cursor handCursor = Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND);
toolbar.setCursor(handCursor);
// Add sort action to the tool bar
fSortAction = new SortAction(fImportViewer, PDEUIMessages.RequiresSection_sortAlpha, null, null, this);
toolBarManager.add(fSortAction);
toolBarManager.update(true);
section.setTextClient(toolbar);
}
排序代碼在單獨的SortAction
類中,該類擴展了Action
。
Section.setTextClient
將工具欄放在節標題欄的右上方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.