Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » getting an Object out of a combo instead of a string
getting an Object out of a combo instead of a string [message #461817] Fri, 30 September 2005 17:13 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
Previous Topic:Multiline FieldEditor text area?
Next Topic:The Exception when the code that swing call the code that swt
Goto Forum:
  


Current Time: Fri Mar 29 05:11:36 GMT 2024

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

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

Back to the top