Here is a sample of how to create a toolbar for a section, make sure the toolbar is created before section.setClient()
.
protected void createToolbar(Section section) {
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
toolBarManager.add(new Action("print") {
@Override
public void run() {
System.out.println("PRINT");
}
});
createSectionToolbar(section, toolBarManager);
}
/**
* create a toolbar in the passed section
*
* @param section
* @param toolBarManager
*/
protected void createSectionToolbar(Section section, ToolBarManager toolBarManager) {
Composite toolbarComposite = toolkit.createComposite(section);
toolbarComposite.setBackground(null);
toolBarManager.createControl(toolbarComposite);
section.clientVerticalSpacing = 0;
section.descriptionVerticalSpacing = 0;
section.setTextClient(toolbarComposite);
}
If you want to add declared commands from the plugin.xml
to the toolbar, have a look at CommandContributionItem
.
toolBarManager.add(new CommandContributionItem(new CommandContributionItemParameter(getSite(), "id", "commandId", SWT.NONE)));