Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Events not working in Combo when in a CoolBar but works when in a ToolBar
Events not working in Combo when in a CoolBar but works when in a ToolBar [message #465211] Thu, 08 December 2005 09:08 Go to next message
Olli Aalto is currently offline Olli AaltoFriend
Messages: 11
Registered: July 2009
Junior Member
Hi, I'm building a RCP application and it has a Windows Explorer-like
filesystem navigation. A tree at the left, a table at the right and an
editable drop-down list at the top.

I'm using SelectionListeners for most of the communication between the
components and one custom class for sending events from the Combo to
both the tree and the table.

Now I have used a ContributionItem implementation I found somewhere here
in the newsgroups. It worked fine but the Combo was little silly looking
because it was too narrow, came about half way across the window.

I started investigating the involved classes, mainly the
ContributionItem, and found that it had 3 fill-methods. All for
different situations. At the time I was putting it to a ToolBar which
was inside a CoolBar. I started playing around with the different
fill-methods and very soon found out that the one which took a CoolBar
as a parameter gave me the desired look. I had also took the
ContributionItem away from the ToolBar. And then I found that the Combo
or the tree and the table were updating anymore. For some reason the
Combo was no longer generating SelectionEvents and my implementation of
ContributionItem, which implements ISelectionListener, wasn't receiving
any events either.

Ok, now I backtracked and put back the fill-method which took a ToolBar
as a parameter and put the class back in a ToolBar. And it worked!?

Now depending on where a I put it I get either the looks or the
functionality. :(

I'll paste the class here if someone wants to take a look.

public class AddressBarContributionItem extends ContributionItem
implements ISelectionListener {

private Combo addressBox;

private ToolItem item;

private CoolItem coolItem;

public void fill(ToolBar parent, int index) {
createToolItem(parent, index);
Control box = createAddressBox(parent);

public void fill(CoolBar coolBar, int index) {
Control box = createAddressBox(coolBar);
createCoolItem(coolBar, index);
Point toolBarSize = box.computeSize(SWT.DEFAULT, SWT.DEFAULT);

public void setText(String text) {
if (addressBox != null)

public void selectionChanged(IWorkbenchPart part, ISelection
selection) {
if (part instanceof FileTreeView || part instanceof
FileTableView) {
if (selection instanceof IStructuredSelection) {
Object element =
if (element instanceof File) {

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;
Label addressLabel = new Label(top, SWT.NONE);
addressLabel.setText("Address: ");
addressBox = new Combo(top, SWT.DROP_DOWN);
addressBox.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent
selectionEvent) {
addressBox.setLayoutData(new GridData(GridData.FILL,
GridData.BEGINNING, true, false));
return top;

private void createCoolItem(CoolBar coolBar, int index) {
int flags = SWT.DROP_DOWN;
if (index >= 0) {
coolItem = new CoolItem(coolBar, flags, index);
else {
coolItem = new CoolItem(coolBar, flags);

private void createToolItem(ToolBar parent, int index) {
int flags = SWT.DROP_DOWN;
if (index >= 0) {
item = new ToolItem(parent, flags, index);
else {
item = new ToolItem(parent, flags);
Re: Events not working in Combo when in a CoolBar but works when in a ToolBar [message #465285 is a reply to message #465211] Thu, 08 December 2005 14:15 Go to previous message
Olli Aalto is currently offline Olli AaltoFriend
Messages: 11
Registered: July 2009
Junior Member
Hmm, actually it's not the events, but somehow Combo's setText and
getText don't work as I'd thought. When I type something to the
addressBar and press enter, the widgetDefaultSelected is called as
should be, but when there the addressBar.getText does not return the
current text in the component.

Similarilly when I select something in the filesystem tree I get a
SelectionEvent which then in turn calls addressBar.setText with the text
from the selected element(which is the selected file's path). Again the
addressBar.setText does nothing visible. The next getText will return
the just set text as should be, but when I type something else it still
returns the old text for some reason.

I'll investigate this some more.

Previous Topic:Multiple Browsers in SWT application with different sessions
Next Topic:tableItem
Goto Forum:

Current Time: Tue Apr 20 07:39:35 GMT 2021

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

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

Back to the top