combo box in toolbar [message #387071] |
Wed, 13 October 2004 19:52  |
Eclipse User |
|
|
|
Originally posted by: kelly.francke.com
Hi, I need advice on these:
1. I'm trying to add a label + combo box to the main tool bar by extending
the ControlContribution
class. Is this supported?
2. Can I add a label + combo box on the right top corner of the workbench
window (same line as the
toolbar but all the way to the right)?
I will appreciate any infomation. Thanks.
|
|
|
Re: combo box in toolbar [message #387293 is a reply to message #387071] |
Sat, 16 October 2004 21:47   |
Eclipse User |
|
|
|
Kelly Muñiz wrote:
> Hi, I need advice on these:
>
> 1. I'm trying to add a label + combo box to the main tool bar by extending
> the ControlContribution
> class. Is this supported?
Yes this is the right approach. Here is an example:
package customToolbar;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
public class AddressBarContributionItem extends ContributionItem {
protected Combo addressBox;
protected ToolItem item;
protected IAction action;
protected CoolItem coolItem;
public AddressBarContributionItem(IAction action) {
this.action = action;
}
public void fill(ToolBar parent, int index) {
item = new ToolItem(parent, SWT.SEPARATOR);
Control box = createAddressBox(parent);
item.setControl(box);
item.setWidth(500);
}
public void fill(CoolBar coolBar, int index) {
// if (coolItem == null && coolBar != null) {
Control box = createAddressBox(coolBar);
int flags = SWT.DROP_DOWN;
if (index >= 0) {
coolItem = new CoolItem(coolBar, flags, index);
} else {
coolItem = new CoolItem(coolBar, flags);
}
// sets the back reference
coolItem.setData(this);
// Add the toolbar to the CoolItem widget
coolItem.setControl(box);
// If the toolbar item exists then adjust the size of the cool
// item
Point toolBarSize = box.computeSize(SWT.DEFAULT, SWT.DEFAULT);
// Set the preffered size to the size of the toolbar plus trim
coolItem.setMinimumSize(toolBarSize);
coolItem.setPreferredSize(toolBarSize);
coolItem.setSize(toolBarSize);
// }
}
private Control createAddressBox(Composite parent) {
Composite top = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = 0;
layout.verticalSpacing = layout.horizontalSpacing = 0;
layout.numColumns = 2;
top.setLayout(layout);
Label l = new Label(top, SWT.NONE);
l.setText("Help:");
addressBox = new Combo(top, SWT.DROP_DOWN);
addressBox.setText("Type a question here");
action.setText("Type a question here");
addressBox.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.keyCode == '\r') {
Event event = new Event();
event.data = addressBox.getText();
action.runWithEvent(event);
addressBox.add(addressBox.getText());
}
}
});
addressBox.setLayoutData(new GridData(GridData.FILL,
GridData.BEGINNING, true, false));
return top;
}
public void fill(Composite parent) {
createAddressBox(parent);
}
/**
* Sets the address bar text
*/
public void setText(String text) {
if(addressBox != null)
addressBox.setText(text);
}
}
> 2. Can I add a label + combo box on the right top corner of the workbench
> window (same line as the
> toolbar but all the way to the right)?
With a bit of hacking but not really supported. First you override
WorkbenchAdvisor.createWindowContents() and build the entire UI
yourself. You can however call helpers to create the canonical coolbar,
menu bar, and status line. Use a CBanner to put two toolbars one beside
the other. Very nasty hacking, but it will work. I've done it but
have not been able to get correct resizing of the right toolbar. Also,
beware that the workbench has many tricky layouts and control wrappers
that you won't get if you build the UI yourself :)
> I will appreciate any infomation. Thanks.
>
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02660 seconds