import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.window.Window;
Display.getDefault().getActiveShell(),
attribute);
if (dialog.open() == Window.OK) {
- updateAttributeValue(attribute,
+ updateAttributeValue(attributeElement, attribute,
dialog.getNewValueObj());
}
dialog.setMessage("Given value is invalid");
dialog.open();
} else {
- updateAttributeValue(att, attValue);
+ updateAttributeValue((AttributeElement) element, att,
+ attValue);
}
}
return strArr;
}
- public void updateAttributeValue(SimulatorResourceAttribute att,
- AttributeValue value) {
- IStructuredSelection selection = (IStructuredSelection) viewer
- .getSelection();
- if (null == selection) {
- return;
+ public void updateAttributeValue(AttributeElement attributeElement,
+ SimulatorResourceAttribute att, AttributeValue value) {
+ // Update the post status.
+ Object parent = attributeElement.getParent();
+ AttributeElement rootElement = attributeElement;
+ while (parent != null && parent instanceof AttributeElement) {
+ rootElement = (AttributeElement) parent;
+ parent = ((AttributeElement) parent).getParent();
}
+ rootElement.setPostState(true);
- Object obj = selection.getFirstElement();
- if (null == obj) {
- return;
- }
-
- Tree t = viewer.getTree();
- TreeItem item = t.getSelection()[0];
- if (null == item) {
- return;
- }
+ // Set the attribute value.
+ attributeElement.getSimulatorResourceAttribute().setValue(value);
- TreeItem parent = item.getParentItem();
- if (null != parent) {
- while (parent.getParentItem() != null) {
- parent = parent.getParentItem();
- }
- Object data = parent.getData();
- ((AttributeElement) data).setPostState(true);
- }
-
- if (item.getData() instanceof AttributeElement) {
- AttributeElement attributeElement = (AttributeElement) item
- .getData();
- attributeElement.getSimulatorResourceAttribute()
- .setValue(value);
-
- parent = item.getParentItem();
- if (null != parent) {
- Object data = parent.getData();
- try {
- ((AttributeElement) data).deepSetChildValue(att);
- } catch (InvalidArgsException e) {
- e.printStackTrace();
- }
+ // Update the hierarchy.
+ parent = attributeElement.getParent();
+ if (null != parent && parent instanceof AttributeElement) {
+ try {
+ ((AttributeElement) parent).deepSetChildValue(att);
+ } catch (InvalidArgsException e) {
+ e.printStackTrace();
}
}
}
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.window.Window;
attElement.setEditLock(true);
compareAndUpdateAttribute(oldValue, comboBox.getText(),
- element, att, type);
+ (AttributeElement) element, att, type);
attElement.setEditLock(false);
viewer.refresh();
Display.getDefault().getActiveShell(),
attribute);
if (dialog.open() == Window.OK) {
- updateAttributeValue(attribute,
+ updateAttributeValue(attributeElement, attribute,
dialog.getNewValueObj());
if (callNativeUpdateValue) {
Resource resource = resourceManager
.getCurrentResourceInSelection();
- SimulatorResourceAttribute result = getResultantAttribute();
+ SimulatorResourceAttribute result = getResultantAttribute(attributeElement);
if (null == result) {
Activator
.getDefault()
result.name(), result.value());
if (!updated) {
try {
- updateAttributeValue(attribute,
+ updateAttributeValue(attributeElement,
+ attribute,
AttributeValueBuilder.build(
currentAttValue,
type.mBaseType));
attributeElement.setEditLock(true);
compareAndUpdateAttribute(oldValue, newValue,
- element, attribute, type);
+ (AttributeElement) element, attribute, type);
attributeElement.setEditLock(false);
comboBox.setVisible(false);
String newValue = comboBox.getText();
((AttributeElement) element).setEditLock(true);
- compareAndUpdateAttribute(oldValue, newValue, element, att,
- type);
+ compareAndUpdateAttribute(oldValue, newValue,
+ (AttributeElement) element, att, type);
((AttributeElement) element).setEditLock(false);
}
}
public void compareAndUpdateAttribute(String oldValue, String newValue,
- Object element, SimulatorResourceAttribute att, TypeInfo type) {
- if (null == oldValue || null == newValue || null == element
+ AttributeElement attElement, SimulatorResourceAttribute att,
+ TypeInfo type) {
+ if (null == oldValue || null == newValue || null == attElement
|| null == att || null == type) {
return;
}
} else {
// To show the new value till decision made.
- updateAttributeValue(att, attValue);
- viewer.update(element, null);
+ updateAttributeValue(attElement, att, attValue);
+ viewer.update(attElement, null);
if (callNativeUpdateValue) {
MessageBox dialog = new MessageBox(viewer.getTree()
try {
attValue = AttributeValueBuilder.build(
oldValue, type.mBaseType);
- updateAttributeValue(att, attValue);
+ updateAttributeValue(attElement, att, attValue);
} catch (Exception e) {
Activator
.getDefault()
Resource resource = resourceManager
.getCurrentResourceInSelection();
- SimulatorResourceAttribute result = getResultantAttribute();
+ SimulatorResourceAttribute result = getResultantAttribute(attElement);
if (null == result) {
Activator
.getDefault()
try {
attValue = AttributeValueBuilder.build(
oldValue, type.mBaseType);
- updateAttributeValue(att, attValue);
+ updateAttributeValue(attElement, att,
+ attValue);
} catch (Exception e) {
Activator
.getDefault()
}
}
}
- viewer.update(element, null);
+ viewer.update(attElement, null);
}
- public void updateAttributeValue(SimulatorResourceAttribute att,
- AttributeValue value) {
- if (null == att || null == value) {
+ public void updateAttributeValue(AttributeElement attributeElement,
+ SimulatorResourceAttribute att, AttributeValue value) {
+ if (null == attributeElement || null == att || null == value) {
return;
}
- IStructuredSelection selection = (IStructuredSelection) viewer
- .getSelection();
- if (null == selection) {
- return;
- }
-
- Object obj = selection.getFirstElement();
- if (null == obj) {
- return;
- }
-
- Tree t = viewer.getTree();
- TreeItem item = t.getSelection()[0];
- if (null == item) {
- return;
- }
+ attributeElement.getSimulatorResourceAttribute().setValue(value);
- if (item.getData() instanceof AttributeElement) {
- AttributeElement attributeElement = (AttributeElement) item
- .getData();
- attributeElement.getSimulatorResourceAttribute()
- .setValue(value);
-
- TreeItem parent = item.getParentItem();
- if (null != parent) {
- Object data = parent.getData();
- try {
- ((AttributeElement) data).deepSetChildValue(att);
- } catch (InvalidArgsException e) {
- Activator
- .getDefault()
- .getLogManager()
- .log(Level.ERROR.ordinal(),
- new Date(),
- "There is an error while updating the attribute value.\n"
- + Utility
- .getSimulatorErrorString(
- e, null));
- }
+ Object parent = attributeElement.getParent();
+ if (null != parent && parent instanceof AttributeElement) {
+ AttributeElement parentElement = (AttributeElement) parent;
+ try {
+ parentElement.deepSetChildValue(att);
+ } catch (InvalidArgsException e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ "There is an error while updating the attribute value.\n"
+ + Utility.getSimulatorErrorString(
+ e, null));
}
}
}
- public SimulatorResourceAttribute getResultantAttribute() {
- IStructuredSelection selection = (IStructuredSelection) viewer
- .getSelection();
- if (null == selection) {
- return null;
- }
-
- Object obj = selection.getFirstElement();
- if (null == obj) {
- return null;
- }
-
- Tree t = viewer.getTree();
- TreeItem item = t.getSelection()[0];
- if (null == item) {
+ public SimulatorResourceAttribute getResultantAttribute(
+ AttributeElement attElement) {
+ if (null == attElement) {
return null;
}
SimulatorResourceAttribute result;
- TreeItem parent = item.getParentItem();
- if (null == parent) {
- Object data = item.getData();
- result = ((AttributeElement) data)
- .getSimulatorResourceAttribute();
- } else {
- while (parent.getParentItem() != null) {
- parent = parent.getParentItem();
- }
+ Object parent = attElement.getParent();
- // Parent will point to the top-level attribute of type
- Object data = parent.getData();
- result = ((AttributeElement) data)
- .getSimulatorResourceAttribute();
+ while (parent != null && parent instanceof AttributeElement) {
+ attElement = (AttributeElement) parent;
+ parent = ((AttributeElement) parent).getParent();
}
+ result = attElement.getSimulatorResourceAttribute();
return result;
}