@Override public void modify(Object element, String property, Object value) { TableItem tableItem = (TableItem) element; KeyValueModel keyValueModel = (KeyValueModel) tableItem.getData(); String string = (String) value; if (property.equals(DmConstants.COLUMN_PROPERTY_KEY)) { keyValueModel.setKey(string); } if (property.equals(DmConstants.COLUMN_PROPERTY_VALUE)) { keyValueModel.setValue(string); } tableViewer.refresh(); // 必须调用刷新,不然显示还是原来的 }
@Override public Object getValue(Object element, String property) { KeyValueModel keyValueModel = (KeyValueModel) element; if (property.equals(DmConstants.COLUMN_PROPERTY_INDEX)) { List<KeyValueModel> models = (List<KeyValueModel>) tableViewer.getInput(); return models == null ? "" : models.indexOf(keyValueModel) + 1; } if (property.equals(DmConstants.COLUMN_PROPERTY_KEY)) { return keyValueModel.getKey(); } if (property.equals(DmConstants.COLUMN_PROPERTY_VALUE)) { return keyValueModel.getValue(); } return keyValueModel; }