import oic.simulator.clientcontroller.manager.ResourceManager;
import oic.simulator.clientcontroller.remoteresource.AttributeElement;
import oic.simulator.clientcontroller.remoteresource.RemoteResource;
+import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation;
import oic.simulator.clientcontroller.utils.AttributeValueBuilder;
import oic.simulator.clientcontroller.utils.Utility;
import oic.simulator.clientcontroller.view.dialogs.PostRequestDialog;
public class AttributeEditingSupport {
private AttributeValueEditor attValueEditor;
- private PostRequestEditor postReqEditor;
+ private PostSelectionEditor postSelectionEditor;
public AttributeValueEditor createAttributeValueEditor(TreeViewer viewer,
TitleAreaDialog dialog) {
return attValueEditor;
}
- public PostRequestEditor createAutomationEditor(TreeViewer viewer) {
- postReqEditor = new PostRequestEditor(viewer);
- return postReqEditor;
+ public PostSelectionEditor createPostSelectionEditor(TreeViewer viewer) {
+ postSelectionEditor = new PostSelectionEditor(viewer);
+ return postSelectionEditor;
}
class AttributeValueEditor extends EditingSupport {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
- attributeElement.setPostState(true);
- viewer.refresh(element, true);
+ // Set the post state of the top-level
+ // attribute.
+ AttributeElement rootElement = getRootElement(attributeElement);
+ rootElement.setPostState(true);
+ viewer.refresh(rootElement, true);
}
});
}
@Override
public void modifyText(ModifyEvent event) {
- String newValue = comboBox.getText();
-
- if (null != newValue && !newValue.isEmpty()) {
- attributeElement.setPostState(true);
- } else {
- attributeElement.setPostState(false);
- }
-
- if (dialog instanceof PostRequestDialog) {
- viewer.update(attributeElement, null);
+ // Set the post state of the top-level attribute.
+ AttributeElement rootElement = getRootElement(attributeElement);
+ rootElement.setPostState(true);
+ if (AttributeValueEditor.this.dialog instanceof PostRequestDialog) {
+ viewer.update(rootElement, null);
}
}
});
}
}
- class PostRequestEditor extends EditingSupport {
+ class PostSelectionEditor extends EditingSupport {
private final TreeViewer viewer;
- public PostRequestEditor(TreeViewer viewer) {
+ public PostSelectionEditor(TreeViewer viewer) {
super(viewer);
this.viewer = viewer;
}
@Override
protected CellEditor getCellEditor(Object element) {
- SimulatorResourceAttribute att = null;
- if (element instanceof AttributeElement) {
- att = ((AttributeElement) element)
- .getSimulatorResourceAttribute();
+ if (element instanceof AttributeElement
+ && ((AttributeElement) element).getParent() instanceof ResourceRepresentation) {
+ return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
}
- if (null == att) {
- return null;
- }
-
- AttributeValue val = att.value();
- if (null == val) {
- return null;
- }
-
- TypeInfo type = val.typeInfo();
-
- if (type.mType == ValueType.RESOURCEMODEL
- || type.mBaseType == ValueType.RESOURCEMODEL) {
- return null;
- }
-
- return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
+ return null;
}
@Override
return;
}
- // Set the post state of the top-most parent of this attribute to
- // false.
+ // Update the post state of the top-most parent of this attribute.
TreeItem parent = item.getParentItem();
if (null != parent) {
while (parent.getParentItem() != null) {
}
}
}
+
+ private AttributeElement getRootElement(AttributeElement element) {
+ AttributeElement root = null;
+
+ Object parent = element.getParent();
+ if (parent instanceof ResourceRepresentation) {
+ return element;
+ }
+
+ while (!(parent instanceof ResourceRepresentation)) {
+ root = (AttributeElement) parent;
+ parent = ((AttributeElement) parent).getParent();
+ }
+
+ return root;
+ }
}