@Override public void modify(Object element, String property, Object value) { // SWT bug workaround if (element instanceof Item) { element = ((Item) element).getData(); } if (element instanceof String[]) { String[] elts = (String[]) element; String propertyName = elts[0].toString(); String oldValue = null; if (elts[1] != null) { oldValue = elts[1].toString(); } String newValue = null; if (value != null) { newValue = value.toString(); } if (oldValue == null && newValue == null) { // Do nothing } else if (oldValue != null && newValue == null) { XArchADTOperations.set("Set", xarch, ref, propertyName, null); } else if (oldValue == null && newValue != null) { set(propertyName, newValue); } else { // Both non-null: if (!oldValue.equals(newValue)) { set(propertyName, newValue); } } } }
private void set(String featureName, String stringValue) { IXArchADTTypeMetadata typeMetadata = xarch.getTypeMetadata(ref); IXArchADTFeature feature = typeMetadata.getFeatures().get(featureName); if (feature != null) { try { // If the feature is an enumeration type, then xarch.set will // automatically try to convert it to an enum and throw // IllegalArgumentException if it's not a valid value. XArchADTOperations.set("Set", xarch, ref, featureName, stringValue); } catch (IllegalArgumentException iae) { MessageBox messageBox = new MessageBox(parent.getShell(), SWT.OK | SWT.ICON_ERROR); messageBox.setMessage("Invalid value for this field."); messageBox.setText("Error"); messageBox.open(); } } else { throw new RuntimeException("This shouldn't happen."); } }