通过 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
的编辑器,每个部分都有自己的工具栏,目前仅在编辑器代码中声明。我需要做的是将工具栏代码与编辑器代码分开。分离工具栏代码的最佳方法是什么。由于有多个toolItem,编辑器的代码变得复杂。我们可以在 plugin.xml
中为 org.eclipse.ui.forms.widgets.Section
定义工具栏吗?
当前使用以下代码行将工具栏添加到部分:
ToolBar toolBar = new ToolBar(section, SWT.FLAT | SWT.RIGHT);
部分没有任何扩展点。
工具栏可以使用ToolBarManager
。这使您可以在工具栏中使用 Action
classes(和其他贡献项)。这使您可以将代码分隔成单独的 classes.
例如,plugin.xml 编辑器将 'alphabetic sort' 按钮添加到 'Required Plug-ins' 部分的方式如下:
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);
}
排序代码位于扩展 Action
.
的单独 SortAction
class 中
Section.setTextClient
将工具栏放在节标题栏的右上角。
我正在创建 Eclipse 应用程序。我创建了一个具有多个 org.eclipse.ui.forms.widgets.Section
的编辑器,每个部分都有自己的工具栏,目前仅在编辑器代码中声明。我需要做的是将工具栏代码与编辑器代码分开。分离工具栏代码的最佳方法是什么。由于有多个toolItem,编辑器的代码变得复杂。我们可以在 plugin.xml
中为 org.eclipse.ui.forms.widgets.Section
定义工具栏吗?
当前使用以下代码行将工具栏添加到部分:
ToolBar toolBar = new ToolBar(section, SWT.FLAT | SWT.RIGHT);
部分没有任何扩展点。
工具栏可以使用ToolBarManager
。这使您可以在工具栏中使用 Action
classes(和其他贡献项)。这使您可以将代码分隔成单独的 classes.
例如,plugin.xml 编辑器将 'alphabetic sort' 按钮添加到 'Required Plug-ins' 部分的方式如下:
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);
}
排序代码位于扩展 Action
.
SortAction
class 中
Section.setTextClient
将工具栏放在节标题栏的右上角。