Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 364456

Summary: SWTBotWorkbenchPart cannot find toolbar buttons for editor
Product: [Technology] SWTBot Reporter: Tim Moore <tmm-bugs.eclipse>
Component: SWTBotAssignee: Project Inbox <swtbot-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Tim Moore CLA 2011-11-22 07:18:22 EST
Build Identifier: M20100909-0800

SWTBotWorkbenchPart.getToolbarButtons() has the following code:
---
PartPane obj = ((WorkbenchPartReference) partReference).getPane();
ToolBar toolbar = (ToolBar) obj.getToolBar();
---

But the implementation of getToolbar for EditorPane is:
---
public Control getToolBar() {
  return null;
}
---

So obviously that can never find any. Something like this in SWTBotWorkbenchPart.getToolbarButtons() allows Editor toolbars to be accessed as well:
---
final IToolBarManager toolbarMgr;
if (partReference instanceof IEditorReference) {
  toolbarMgr = ((IEditorReference) partReference).getEditor(false).getEditorSite().getActionBars().getToolBarManager();
}
else {
  toolbarMgr = ((IViewReference) partReference).getView(false).getViewSite().getActionBars().getToolBarManager();
}
final ToolItem[] items = ((ToolBarManager) toolbarMgr).getControl().getItems();
---

No doubt there is a more succinct solution, but this does at least appear to work.

Reproducible: Always