Bug 88427

Summary: [CellEditors] ComboBoxCellEditor API unclean if combo box has not style SWT.READ_ONLY applied
Product: [Eclipse Project] Platform Reporter: cr
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P4 CC: strider80, Tod_Creasey
Version: 3.0.1Keywords: helpwanted
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description cr CLA 2005-03-18 04:04:08 EST
If a combo box has not the stlye STW-READ_ONLY applied, one can assume, the 
combo box can be edited, put in custom values. But the implementation of the 
API does not support this behaviour. It only supports returning -1 
(doGetValue)if you type in a custom value. To pass a custom value to the combo 
box - only integer values are allowed (doSetValue) is not possible (you can 
only pass -1 for a custom value. 
 
If the combo box is not hidden, on can subclass the widget and work with the 
method's comboBox.getText()/setText() as a hack. 
 
I have implemented the method doGetValue() and doSetValue() the following way 
to get an editable combo box for my purposes: 
 
protected Object doGetValue() { 
    return comboBox.getText(); 
} 
 
 
protected void doSetValue(final Object value) { 
    Assert.isTrue(value instanceof String); 
    int selection = -1; 
 
    for (int i = 0; i < items.length; i++) { 
        final String currentItem = items[i]; 
 
        if (currentItem.equals(value.toString())) { 
            selection = i; 
        } 
    } 
 
    comboBox.select(selection); 
    comboBox.setText(value.toString()); 
} 
 
 
I the method getValue() of the CellEditor, return the same string as one in the 
items list or the custom object. 
 
A generally valid implementation and clean implementation is welcome! There is 
also a custom implementation in the EMF Framework with a list of object (not 
Strings) and a ILabelProvider to represent the objects in the combo box. Why?? 
There should be one in the JFace Framework which is not as limited as the one 
existing now!
Comment 1 Tod Creasey CLA 2005-03-18 09:31:06 EST
Should you wish to attach a suggested implementation we could look at it
Comment 2 cr CLA 2005-03-21 01:55:22 EST
I will be back next week with code ... 
Comment 3 Henno Vermeulen CLA 2013-01-18 05:22:02 EST
Similar issue is present in ComboBoxViewerCellEditor.