Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] ComboBoxCellEditor not working as expected

Title: Message
Hello
 
I am trying to use the ComboBoxCellEditor for a column in a table.
 
When the table first populates, the cells display the values as expected, however if the combo box is used to change the value of a cell, the new value is always that associated with index 0 in the list of possible values.
 
I have an object called CellValue, this has the following getters and setters:
 
  public String getItemType() {
    return (itemType==null?"":itemType);
  }
  public int getItemTypeIndex() {
    if (itemType == null) return 0;
    if (itemType.equals("text")) return 0;
    else if (itemType.equals("integer")) return 1;
    else if (itemType.equals("double")) return 2;
    return 0;
  }
  public void setItemType(String itemType) {
    System.out.println("CellValue.setItemType: itemType " + itemType);
    this.itemType = itemType.trim().toLowerCase();
  }
  public void setItemTypeIndex(int itemType) {
    System.out.println("CellValue.setItemTypeIndex: itemType " + itemType);
    switch (itemType) {
      case 0: setItemType("text");
      case 1: setItemType("integer");
      case 2: setItemType("double");
      default: setItemType("text");
    }
  }
The methods in my modifier are:
 
  public Object getValue(Object rowData, String property) {
    System.out.println("getValue: property "  + property);
    CellValue cellValue = (CellValue)rowData;
    if (CellValue.NAME.equals(property)) {
      return cellValue.getDataItemName();
    } else if (CellValue.VALUE.equals(property)) {
      return cellValue.getValue();
    } else if (CellValue.TYPE.equals(property)) {
      System.out.println("Type is " + cellValue.getItemTypeIndex());
      return new Integer(cellValue.getItemTypeIndex());
    } else if (CellValue.SHOW.equals(property)) {
      return (new Boolean(cellValue.isShowOnSheet()));
    }
    return null;
  }
 
  public void modify(Object rowData, String property, Object value) {
     System.out.println("CellValueModifier.modify: rowData " + rowData.getClass().toString() +
                        " value " + value.getClass().toString());
    if (rowData instanceof Item) rowData = ((Item)rowData).getData();
   
    CellValue cellValue = (CellValue)rowData;
    if (CellValue.NAME.equals(property)) {
      cellValue.setDataItemName((String)value);
    } else if (CellValue.VALUE.equals(property)) {
      cellValue.setValue((String)value);
    } else if (CellValue.TYPE.equals(property)) {
      cellValue.setItemTypeIndex(((Integer)value).intValue());
    } else if (CellValue.SHOW.equals(property)) {
      cellValue.setShowOnSheet(((Boolean)value).booleanValue());
    } 
   
    viewer.refresh();
  }
As you can see I have added a number of debug lines. The results I get are:
 

CellValueModifier.modify: rowData class org.eclipse.swt.widgets.TableItem value class java.lang.Integer

CellValue.setItemTypeIndex: itemType 2

CellValue.setItemType: itemType double

CellValue.setItemType: itemType text

CellValueModifier.modify: before refresh

CellValueModifier.modify: after refresh

The problem seams to be caused by the second setItemType method call. This is very strange as the only place I call this is in the setItemTypeIndex method and the trace shows that this is only called once.
 
I am doing something daft that I can't see or is there a problem here?
 
Thanks
 
Mike

Back to the top