[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Adding element in TableViewer and edit it

Well I think your problem is that JFace-TableViewers can't work with to equal objects (I know they are not the same instance but if you look at the RGB-class you'll see that equals and hashCode are overwritten).

Is it possible that the element you get the notify from has the same value, else please provide a *fully runnable snippet* for me to test.

Tom

Oliver schrieb:
The table is configured by this (3 columns the RGB values and 4th column a color chooser):

final CellEditor compEditor = new TextCellEditor(table);
final CellEditor colorCellEditor = new ColorCellEditor(table);

colorTable.setCellEditors(new CellEditor[] {
                                  compEditor, compEditor,
                                  compEditor, colorCellEditor
                                  });



Here the implementation of ICellModifier:

colorTable.setCellModifier(new ICellModifier() {
@Override
public boolean canModify(final Object element, final String property)
{
return true;
}
@Override
public Object getValue(final Object element, final String property)
{
final RGB rgb = (RGB) element;
if (COLUMN_RED.equals(property)) {
return Integer.toString(rgb.red);
}


   if (COLUMN_GREEN.equals(property)) {
     return Integer.toString(rgb.green);
   }

   if (COLUMN_BLUE.equals(property)) {
     return Integer.toString(rgb.blue);
   }

   if (COLUMN_RGB.equals(property)) {
     return rgb;
   }

@Override
public void modify(final Object element, final String property, final Object value)
{
isDirty = true;


   final RGB rgb = (RGB) ((TableItem) element).getData();

   if (COLUMN_RED.equals(property)) {
     try {
       rgb.red = limitRGB(Integer.parseInt((String) value));
     } catch (final NumberFormatException nfe) {
     }

     colorTable.update(rgb, null);
   } else if (COLUMN_GREEN.equals(property)) {
     try {
       rgb.green = limitRGB(Integer.parseInt((String) value));
     } catch (final NumberFormatException nfe) {
     }

     colorTable.update(rgb, null);
   } else if (COLUMN_BLUE.equals(property)) {
     try {
       rgb.blue = limitRGB(Integer.parseInt((String) value));
     } catch (final NumberFormatException nfe) {
     }

     colorTable.update(rgb, null);
   } else if (COLUMN_RGB.equals(property)) {
     final RGB col = (RGB) value;
     rgb.red = col.red;
     rgb.green = col.green;
     rgb.blue = col.blue;

colorTable.update(rgb, null);
} else {
throw new IllegalArgumentException("Unsupported property for editing: " + property);
}
}
});




--
B e s t S o l u t i o n . at
--------------------------------------------------------------------
Tom Schindl                                          JFace-Committer
--------------------------------------------------------------------