return null;
}
- AttributeElement attributeElement = ((AttributeElement) element);
+ final AttributeElement attributeElement = ((AttributeElement) element);
attribute = attributeElement.getSimulatorResourceAttribute();
if (null == attribute) {
return null;
String oldValue = String.valueOf(Utility
.getAttributeValueAsString(val));
String newValue = comboBox.getText();
- if (!oldValue.equals(newValue)) {
- // Get the AttriuteValue from the string
- AttributeValue value = AttributeValueBuilder.build(
- newValue, type.mBaseType);
- boolean invalid = false;
- if (null == value) {
- invalid = true;
- } else {
- TypeInfo resTypeInfo = value.typeInfo();
- if (type.mDepth != resTypeInfo.mDepth
- || type.mType != resTypeInfo.mType
- || type.mBaseType != resTypeInfo.mBaseType) {
- invalid = true;
- }
- }
- if (invalid) {
- MessageBox dialog = new MessageBox(viewer.getTree()
- .getShell(), SWT.ICON_ERROR | SWT.OK);
- dialog.setText("Invalid Value");
- dialog.setMessage("Given value is invalid");
- dialog.open();
- } else {
- updateAttributeValue(attribute, value);
- MessageBox dialog = new MessageBox(viewer.getTree()
- .getShell(), SWT.ICON_QUESTION | SWT.OK
- | SWT.CANCEL);
- dialog.setText("Confirm action");
- dialog.setMessage("Do you want to modify the value?");
- int retval = dialog.open();
- if (retval != SWT.OK) {
- value = AttributeValueBuilder.build(oldValue,
- type.mBaseType);
- updateAttributeValue(attribute, value);
- } else {
- ResourceManager resourceManager;
- resourceManager = Activator.getDefault()
- .getResourceManager();
-
- Resource resource = resourceManager
- .getCurrentResourceInSelection();
-
- SimulatorResourceAttribute result = getResultantValue(value);
-
- resourceManager.attributeValueUpdated(
- (SingleResource) resource,
- result.name(), result.value());
- }
- }
- viewer.update(element, null);
- comboBox.setVisible(false);
- }
+ attributeElement.setEditLock(true);
+ compareAndUpdateAttribute(oldValue, newValue, element,
+ attribute, type);
+ attributeElement.setEditLock(false);
+
+ comboBox.setVisible(false);
}
});
return comboEditor;
@Override
protected void setValue(Object element, Object value) {
- SimulatorResourceAttribute att = null;
-
- if (element instanceof AttributeElement) {
- att = ((AttributeElement) element)
- .getSimulatorResourceAttribute();
- }
-
- if (att == null) {
- return;
- }
+ }
- AttributeValue val = att.value();
- if (null == val) {
+ public void compareAndUpdateAttribute(String oldValue, String newValue,
+ Object element, SimulatorResourceAttribute att, TypeInfo type) {
+ if (null == oldValue || null == newValue || null == element
+ || null == att || null == type) {
return;
}
- TypeInfo type = val.typeInfo();
- if (type.mType == ValueType.ARRAY) {
- int index;
- try {
- index = Integer.parseInt(String.valueOf(value));
- } catch (NumberFormatException nfe) {
- index = -1;
+ if (!oldValue.equals(newValue)) {
+ // Get the AttriuteValue from the string
+ AttributeValue attValue = AttributeValueBuilder.build(newValue,
+ type.mBaseType);
+ boolean invalid = false;
+ if (null == attValue) {
+ invalid = true;
+ } else {
+ TypeInfo resTypeInfo = attValue.typeInfo();
+ if (type.mDepth != resTypeInfo.mDepth
+ || type.mType != resTypeInfo.mType
+ || type.mBaseType != resTypeInfo.mBaseType) {
+ invalid = true;
+ }
}
- if (index == -1) {
- String oldValue = String.valueOf(Utility
- .getAttributeValueAsString(val));
- String newValue = comboBox.getText();
- if (!oldValue.equals(newValue)) {
- // Get the AttriuteValue from the string
- AttributeValue attValue = AttributeValueBuilder.build(
- newValue, type.mBaseType);
- boolean invalid = false;
- if (null == attValue) {
- invalid = true;
- } else {
- TypeInfo resTypeInfo = attValue.typeInfo();
- if (type.mDepth != resTypeInfo.mDepth
- || type.mType != resTypeInfo.mType
- || type.mBaseType != resTypeInfo.mBaseType) {
- invalid = true;
- }
- }
- if (invalid) {
- MessageBox dialog = new MessageBox(viewer.getTree()
- .getShell(), SWT.ICON_ERROR | SWT.OK);
- dialog.setText("Invalid Value");
- dialog.setMessage("Given value is invalid");
- dialog.open();
- } else {
- updateAttributeValue(att, attValue);
- MessageBox dialog = new MessageBox(viewer.getTree()
- .getShell(), SWT.ICON_QUESTION | SWT.OK
- | SWT.CANCEL);
- dialog.setText("Confirm action");
- dialog.setMessage("Do you want to modify the value?");
- int retval = dialog.open();
- if (retval != SWT.OK) {
- attValue = AttributeValueBuilder.build(
- oldValue, type.mBaseType);
- updateAttributeValue(att, attValue);
- } else {
- ResourceManager resourceManager;
- resourceManager = Activator.getDefault()
- .getResourceManager();
-
- Resource resource = resourceManager
- .getCurrentResourceInSelection();
-
- SimulatorResourceAttribute result = getResultantValue(attValue);
-
- resourceManager.attributeValueUpdated(
+ if (invalid) {
+ MessageBox dialog = new MessageBox(viewer.getTree()
+ .getShell(), SWT.ICON_ERROR | SWT.OK);
+ dialog.setText("Invalid Value");
+ dialog.setMessage("Given value is invalid");
+ dialog.open();
+ } else {
+ MessageBox dialog = new MessageBox(viewer.getTree()
+ .getShell(), SWT.ICON_QUESTION | SWT.OK
+ | SWT.CANCEL);
+ dialog.setText("Confirm action");
+ dialog.setMessage("Do you want to modify the value?");
+ int retval = dialog.open();
+ if (retval != SWT.OK) {
+ attValue = AttributeValueBuilder.build(oldValue,
+ type.mBaseType);
+ updateAttributeValue(att, attValue);
+ } else {
+ updateAttributeValue(att, attValue);
+
+ ResourceManager resourceManager;
+ resourceManager = Activator.getDefault()
+ .getResourceManager();
+
+ Resource resource = resourceManager
+ .getCurrentResourceInSelection();
+
+ SimulatorResourceAttribute result = getResultantAttribute();
+
+ boolean updated = resourceManager
+ .attributeValueUpdated(
(SingleResource) resource,
result.name(), result.value());
- }
+ if (!updated) {
+ attValue = AttributeValueBuilder.build(oldValue,
+ type.mBaseType);
+ updateAttributeValue(att, attValue);
+ MessageDialog.openInformation(Display.getDefault()
+ .getActiveShell(), "Operation failed",
+ "Failed to update the attribute value.");
}
}
}
}
-
viewer.update(element, null);
}
public void updateAttributeValue(SimulatorResourceAttribute att,
AttributeValue value) {
- att.setValue(value);
-
IStructuredSelection selection = (IStructuredSelection) viewer
.getSelection();
if (null == selection) {
}
}
- public SimulatorResourceAttribute getResultantValue(
- AttributeValue newValue) {
+ public SimulatorResourceAttribute getResultantAttribute() {
IStructuredSelection selection = (IStructuredSelection) viewer
.getSelection();
if (null == selection) {
MessageDialog.openInformation(Display.getDefault()
.getActiveShell(), "Automation Status",
"Automation start failed!!");
- } else {
- // viewer.update(element, null);
}
}
} else {
MessageDialog.openInformation(Display.getDefault()
.getActiveShell(), "Automation Status",
"Automation stopped.");
- // viewer.update(element, null);
}
}
}