getting an Object out of a combo instead of a string [message #461817] |
Fri, 30 September 2005 17:13 |
Eclipse User |
|
|
|
Originally posted by: tmcguire.go-integral.com
I am used to Swing returning an object out of a combo when I get the
selected item.
If I have an IStructuredContent provider behind a Combo in SWT, why
can't I get an Object back from a statement like "myCombo.getItem(4)" ?
instead I'm doing the following, which works, but there must be an
easier way:
assnCombo.addSelectionListener(new SelectionListener(){
public void widgetSelected(SelectionEvent e) {
User[] users = (User[])userContentProvider.getElements(null);
User u = users[assnCombo.getSelectionIndex()];
artifact.setAssigned_to(u.getUser_id());
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
so, it there a prescribed way of doing this?
thank you kindly
|
|
|
Re: getting an Object out of a combo instead of a string [message #461818 is a reply to message #461817] |
Fri, 30 September 2005 17:20 |
Eclipse User |
|
|
|
Originally posted by: sunil_kamath.nohotspammail.com
"Tim McGuire" <tmcguire@go-integral.com> wrote in message
news:dhjrlg$sf3$1@news.eclipse.org...
>I am used to Swing returning an object out of a combo when I get the
>selected item.
>
> If I have an IStructuredContent provider behind a Combo in SWT, why can't
> I get an Object back from a statement like "myCombo.getItem(4)" ?
>
If you are using a ComboViewer, add a SelectionChangedListener to the viewer
instead of a SelectionListener to the Combo.
Then you will get your object.
---
Sunil
|
|
|
Re: getting an Object out of a combo instead of a string [message #461819 is a reply to message #461817] |
Fri, 30 September 2005 17:20 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Use a ComboViewer instead of an SWT Combobox and then you can get the
selection from the ComboViewer. It will already be the "object" in that
case. In fact you may already be doing this because you have a content
provider. If you do then just get it out of the IStructuredSelection
from the ComboViewer.
Tim McGuire wrote:
> I am used to Swing returning an object out of a combo when I get the
> selected item.
>
> If I have an IStructuredContent provider behind a Combo in SWT, why
> can't I get an Object back from a statement like "myCombo.getItem(4)" ?
>
> instead I'm doing the following, which works, but there must be an
> easier way:
>
> assnCombo.addSelectionListener(new SelectionListener(){
>
> public void widgetSelected(SelectionEvent e) {
> User[] users = (User[])userContentProvider.getElements(null);
> User u = users[assnCombo.getSelectionIndex()];
> artifact.setAssigned_to(u.getUser_id());
> }
>
> public void widgetDefaultSelected(SelectionEvent e) {
>
> }
>
> });
>
>
> so, it there a prescribed way of doing this?
>
> thank you kindly
>
--
Thanks,
Rich Kulp
|
|
|
Re: getting an Object out of a combo instead of a string [message #461844 is a reply to message #461818] |
Mon, 03 October 2005 04:50 |
Eclipse User |
|
|
|
Originally posted by: tmcguire.go-integral.com
Thanks Rich and Sunil,
That worked great once I figured out that I have to first cast the
selected Item to a StructuredSelection and then get the object from
StructuredSelection.getFirstElement.....
Tim
Sunil Kamath wrote:
> "Tim McGuire" <tmcguire@go-integral.com> wrote in message
> news:dhjrlg$sf3$1@news.eclipse.org...
>
>>I am used to Swing returning an object out of a combo when I get the
>>selected item.
>>
>>If I have an IStructuredContent provider behind a Combo in SWT, why can't
>>I get an Object back from a statement like "myCombo.getItem(4)" ?
>>
>
> If you are using a ComboViewer, add a SelectionChangedListener to the viewer
> instead of a SelectionListener to the Combo.
> Then you will get your object.
> ---
> Sunil
>
>
|
|
|
Re: getting an Object out of a combo instead of a string [message #461856 is a reply to message #461844] |
Mon, 03 October 2005 15:17 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Just a nit. :-) You should be casting to IStructuredSelection and not
StructuredSelection. It will be an IStructuredSelection but it is not
guarenteed to be a StructuredSelection.
Tim McGuire wrote:
> Thanks Rich and Sunil,
>
> That worked great once I figured out that I have to first cast the
> selected Item to a StructuredSelection and then get the object from
> StructuredSelection.getFirstElement.....
>
--
Thanks,
Rich Kulp
|
|
|
Powered by
FUDForum. Page generated in 0.03843 seconds