Events not working in Combo when in a CoolBar but works when in a ToolBar [message #465211] |
Thu, 08 December 2005 09:08 |
Olli Aalto 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);
item.setData(this);
item.setControl(box);
item.setWidth(500);
}
public void fill(CoolBar coolBar, int index) {
Control box = createAddressBox(coolBar);
createCoolItem(coolBar, index);
coolItem.setData(this);
coolItem.setControl(box);
Point toolBarSize = box.computeSize(SWT.DEFAULT, SWT.DEFAULT);
coolItem.setMinimumSize(toolBarSize);
coolItem.setPreferredSize(toolBarSize);
coolItem.setSize(toolBarSize);
}
public void setText(String text) {
if (addressBox != null)
addressBox.setText(text);
}
public void selectionChanged(IWorkbenchPart part, ISelection
selection) {
if (part instanceof FileTreeView || part instanceof
FileTableView) {
if (selection instanceof IStructuredSelection) {
Object element =
((IStructuredSelection)selection).getFirstElement();
if (element instanceof File) {
setText(((File)element).getAbsolutePath());
}
}
}
}
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 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) {
AddressBarEventHelper.fireEvent(addressBox.getText());
addressBox.add(addressBox.getText());
}
});
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);
}
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.04702 seconds