I have an Eclipse plugin in which I need a toolbar within the text editor as like the toggle breadcrumb view. Is there any generic utility class in Eclipse that allows me to do this?
@Override
protected ISourceViewer createSourceViewer(Composite parent,
IVerticalRuler ruler,
int styles)
{
composite = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(1, true);
gridLayout.numColumns = 1;
gridLayout.marginHeight = 0;
gridLayout.marginWidth = 0;
composite.setLayout(gridLayout);
ToolBar toolBar = new ToolBar(composite, SWT.FLAT);
GridData gridData = new GridData(GridData.FILL, SWT.TOP, true, false);
toolBar.setLayoutData(gridData);
toolBarManager = new ToolBarManager(toolBar);
return super.createSourceViewer(composite, ruler, styles);
}
Assuming you have an text editor based on the
org.eclipse.ui.editors.text.TextEditorclass, then you must overrideAbstractDecoratedTextEditor.createSourceViewer(Composite parent, ...). BasicallyCompositeinparentwith aGridLayout(1, false). (This is needed as theCompositein theparentargument have aFillLayout).ToolBarManagerand do ‘mng.createControl(top)’ withGridData(FILL, TOP, true, false).Compositein top of withGridData(FILL, FILL, true, true).super.createSourceViewer(child, ...).