Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » combo box in toolbar
combo box in toolbar [message #387071] Wed, 13 October 2004 23:52 Go to next message
Eclipse UserFriend
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] Sun, 17 October 2004 01:47 Go to previous messageGo to next message
Jean-Michel Lemieux is currently offline Jean-Michel LemieuxFriend
Messages: 136
Registered: July 2009
Senior Member
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.
>
>
Re: combo box in toolbar [message #387354 is a reply to message #387293] Mon, 18 October 2004 15:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: kelly.francke.com

Jean-Michel,

Thanks for your answer, I was able to use your code and it saved me some
time. Just a note, I'm using
3.1M2 and had to tweak the code a bit to compile. For example, fill()
methods in ControlContribution
are final (and cannot be overridden).

Also, I was able to position the control all the way to the right by using
the FormLayout/FormData/
FormAttachment classes.

I appreciate your help very much. Thanks.
Re: combo box in toolbar [message #1810388 is a reply to message #387293] Fri, 09 August 2019 09:15 Go to previous message
Lalit Solanki is currently offline Lalit SolankiFriend
Messages: 153
Registered: April 2015
Senior Member
Hi Friends,

It is really usefull but I have need one help how to use your code into eclipse E4 ?

Any idea please help me.


Lalit
Previous Topic:[WARNING] Target location type 'Directory' is not supported
Next Topic:Eclipse in Maven Central
Goto Forum:
  


Current Time: Fri Apr 26 08:45:24 GMT 2024

Powered by FUDForum. Page generated in 0.03171 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top