Reputation: 1212
I want to add a combo box to the toolbar (coolbar) of eclipse using Eclipse Plug-in development API (not an RCP application). This combo box items should be dynamically added/removed.
I know that in RCP applications it is possible by following the link : http://www.thedeveloperspoint.com/?p=140
but I am looking at Eclipse plugin API.
Any help would be greatly appreciated.
Thanks
Syam
Upvotes: 2
Views: 4802
Reputation: 1706
As @Jonny mentioned above it may be necessary to reserve some space.
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar id="new">
<control
class="org.xy.composite.NewComposite"
id="org.xy.composite.newcomposite.id">
</control>
<command
commandId="newcomposite"
icon="resources/nothing.png"
label="nix"/>
</toolbar>
</menuContribution>
And with the command
this is possible
Upvotes: 0
Reputation: 11
To avoid headaches.. if anybody is facing the issue that eclipse only draws 7px height of the control I want to point to a workaround:
https://www.eclipse.org/forums/index.php/t/1076367/
Add another contribution with an icon to the same toolbar (i.e. com.company.module.toolbar) to reserve enough space.
Upvotes: 0
Reputation: 1212
This can be done by using 2 steps.
STEP 1: By using extension point mechanism create/add toolbar to the global toolbar (using locationURI as "toolbar:org.eclipse.ui.main.toolbar")
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="com.company.module.toolbar"
label="Sample">
<control
class="com.company.module.ui.ComboToolbarContribution"
id="ratata">
</control>
</toolbar>
</menuContribution>
</extension>
STEP 2: Implement the ComboToolbarContribution as follows.
package com.company.module.ui;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
public class ComboToolbarContribution extends
WorkbenchWindowControlContribution {
private Combo mReader;
public ComboToolbarContribution() {
}
@Override
protected Control createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
GridLayout glContainer = new GridLayout(1, false);
glContainer.marginTop = -1;
glContainer.marginHeight = 0;
glContainer.marginWidth = 0;
container.setLayout(glContainer);
GridData glReader = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
glReader.widthHint = 280;
mReader = new Combo(container, SWT.BORDER | SWT.READ_ONLY
| SWT.DROP_DOWN);
mReader.setLayoutData(glReader);
return container;
}
@Override
protected int computeWidth(Control control) {
return 300;
} }
With the above 2 steps a combo box will be added to the global toolbar and user need to provide the global access to the combo box.
Upvotes: 5