Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » ComboBoxViewerCellEditor problem
ComboBoxViewerCellEditor problem [message #19552] Wed, 08 July 2009 20:15 Go to next message
Peter Moogk is currently offline Peter Moogk
Messages: 15
Registered: July 2009
Junior Member
Hi,
I'm trying to use a cell editor within a table. My requirement is that
I would like the user to be able to select from a list of predefined
labels in the cell editor. The user should also be able to type in their
own value if the values in the list aren't what they want.

Initially, I tried to use a ComboBoxCellEditor cell editor. This class
returns an Integer value to the cell modifier, so there doesn't seem to be
a way to get a value that is typed in by the user.

I then tried using the ComboBoxViewerCellEditor cell editor. This
class returns a String value. When a predefined string in the combo is
selected the expected string value is returned in the modify method of the
cell modifier. However, when the user types some different value into the
combo box(ie. other than the ones in the combo list) a null value is
passed to the modify method of the cell modifer. I would have expected
the value to be the user specified string and not null. This null value
passed to the cell modifier causes the user entered value to get blanked
out in the table cell. So there does seem to be a way to capture the user
enter value. Am I doing something wrong in my code that creates this
ComboBoxViewerCellEditor class. Here is the code that I'm using to create
this cell editor. Alternative can someone point me to an example that
shows how to get user enter values from a combo cell editor. All of the
examples that I have come across only show the READ-ONLY combo box
scenario. Thanks!

Peter Moogk


public CellEditor[] createCellEditors(Composite parent)
{
CellEditor[] cellEditors = new CellEditor[3];
ComboBoxViewerCellEditor comboEditor = new ComboBoxViewerCellEditor(
parent );

cellEditors[0] = new TextCellEditor( parent );
cellEditors[1] = comboEditor;
cellEditors[2] = new TextCellEditor( parent );
comboEditor.setLabelProvider( new LabelProvider() );
comboEditor.setContenProvider( new ComboContentProvider() );
comboEditor.setInput( new String[]{ "item1", "item2"} );
return cellEditors;
}
}

private class ComboContentProvider implements IStructuredContentProvider
{
@Override
public Object[] getElements(Object inputElement)
{
Object[] result = null;
if( inputElement instanceof String[] )
{
result = (String[])inputElement; }
return result;
}

@Override
public void dispose()
{
}

@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
{
}
}
Re: ComboBoxViewerCellEditor problem [message #723296 is a reply to message #19552] Thu, 08 September 2011 09:18 Go to previous messageGo to next message
Bhuvan Mehta is currently offline Bhuvan Mehta
Messages: 38
Registered: July 2009
Member
Hello,

I am also facing the same issue, did you get any solution for the same?

--
Thanks and Regards,
Bhuvan
Re: ComboBoxViewerCellEditor problem [message #740734 is a reply to message #723296] Tue, 18 October 2011 20:55 Go to previous messageGo to next message
Peter Mising name is currently offline Peter Mising name
Messages: 1
Registered: October 2011
Junior Member
I just came across the same issue.

My EditingSupport class's setValue method is receiving null when the user types in their own value in a ComboBoxViewerCellEditor.

Can anyone acknowledge we are not doing something wrong?

Thanks,
Peter

Re: ComboBoxViewerCellEditor problem [message #811824 is a reply to message #740734] Fri, 02 March 2012 21:46 Go to previous message
Samantha Chan is currently offline Samantha Chan
Messages: 60
Registered: July 2009
Member
I got around this by doing this in the setValue(...) method:

protected void setValue(Object element, Object value) {

if (value == null)
value = ((CCombo)fCellEditor.getControl()).getText();


// continue the rest of setValue...
}
Previous Topic:Why ErrorDialog is not showing exception's stack trace from IStatus?
Next Topic:Add a listener in SWT Browser
Goto Forum:
  


Current Time: Sat Oct 25 03:04:50 GMT 2014

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

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