ComboBoxViewerCellEditor problem [message #336846] |
Tue, 07 July 2009 15:14 |
Eclipse User |
|
|
|
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)
{
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.02893 seconds