簡體   English   中英

通過plugin.xml將工具欄添加到org.eclipse.ui.forms.widgets.Section

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM