######################################################################
simulator_src = [env.Glob('src/*.cpp')
,env.Glob('src/*/*.cpp')
-# ,env.Glob('java/jni/*.cpp')
+ ,env.Glob('java/jni/*.cpp')
]
simulatorsdk = simulator_env.SharedLibrary('SimulatorManager', simulator_src)
package oic.simulator.clientcontroller.listener;
+import org.oic.simulator.client.SimulatorRemoteResource.RequestType;
+
import oic.simulator.clientcontroller.remoteresource.RemoteResource;
/**
* the UI listeners.
*/
public interface IVerificationUIListener {
- public void onVerificationStarted(RemoteResource resource, int autoType);
+ public void onVerificationStarted(RemoteResource resource,
+ RequestType reqType);
- public void onVerificationAborted(RemoteResource resource, int autoType);
+ public void onVerificationAborted(RemoteResource resource,
+ RequestType reqType);
- public void onVerificationCompleted(RemoteResource resource, int autoType);
+ public void onVerificationCompleted(RemoteResource resource,
+ RequestType reqType);
}
import org.oic.simulator.client.SimulatorRemoteResource.ObserveNotificationListener;
import org.oic.simulator.client.SimulatorRemoteResource.PostResponseListener;
import org.oic.simulator.client.SimulatorRemoteResource.PutResponseListener;
+import org.oic.simulator.client.SimulatorRemoteResource.RequestType;
import org.oic.simulator.client.SimulatorRemoteResource.VerificationListener;
-import org.oic.simulator.client.SimulatorRemoteResource.VerificationType;
+import org.oic.simulator.client.SimulatorRequestModel;
import oic.simulator.clientcontroller.Activator;
import oic.simulator.clientcontroller.remoteresource.DeviceAndPlatformInfo;
// Update the automation status.
resource.updateAutomationStatus(autoId, true);
- int autoType = resource.getAutomationtype(autoId);
+ RequestType reqType = resource
+ .getAutomationtype(autoId);
// Notify the listeners.
UiListenerHandler.getInstance()
.verificationStartedNotification(resource,
- autoType);
+ reqType);
}
});
}
// Update the automation status.
resource.updateAutomationStatus(autoId, false);
- int autoType = resource.getAutomationtype(autoId);
+ RequestType reqType = resource
+ .getAutomationtype(autoId);
// Notify the listeners.
UiListenerHandler.getInstance()
.verificationCompletedNotification(resource,
- autoType);
+ reqType);
}
});
}
// Update the automation status.
resource.updateAutomationStatus(autoId, false);
- int autoType = resource.getAutomationtype(autoId);
+ RequestType reqType = resource
+ .getAutomationtype(autoId);
// Notify the listeners.
UiListenerHandler.getInstance()
.verificationAbortedNotification(resource,
- autoType);
+ reqType);
}
});
}
}
resource.setResourceModelRef(resourceModelN);
- resource.setResourceRepresentation(resourceModelN, false);
+ resource.setResourceRepresentation(resourceModelN);
return resource;
}
return true;
}
- public void startAutomationRequest(VerificationType reqType,
+ public void startAutomationRequest(RequestType reqType,
RemoteResource resource) {
if (null == resource) {
return;
try {
autoId = resourceN.startVerification(reqType, verifyListener);
if (autoId != -1) {
- if (reqType == VerificationType.GET) {
+ if (reqType == RequestType.GET) {
resource.setGetAutomtnId(autoId);
- } else if (reqType == VerificationType.PUT) {
+ } else if (reqType == RequestType.PUT) {
resource.setPutAutomtnId(autoId);
} else {
resource.setPostAutomtnId(autoId);
}
}
- public void stopAutomationRequest(VerificationType reqType,
+ public void stopAutomationRequest(RequestType reqType,
RemoteResource resource) {
if (null == resource) {
return;
return;
}
int autoId;
- if (reqType == VerificationType.GET) {
+ if (reqType == RequestType.GET) {
resource.setGetAutomtnInProgress(false);
autoId = resource.getGetAutomtnId();
- } else if (reqType == VerificationType.PUT) {
+ } else if (reqType == RequestType.PUT) {
resource.setPutAutomtnInProgress(false);
autoId = resource.getPutAutomtnId();
} else {
public boolean setConfigFilePath(RemoteResource resource,
String configFilePath) throws SimulatorException {
+
if (null == resource) {
return false;
}
return false;
}
try {
- SimulatorResourceModel configuredResourceModel;
- configuredResourceModel = resourceN.setConfigInfo(configFilePath);
- if (null == configuredResourceModel) {
+ Map<RequestType, SimulatorRequestModel> requestModels;
+ requestModels = resourceN.setConfigInfo(configFilePath);
+ if (null == requestModels) {
return false;
}
+ resource.getResourceRepresentation().updateAttributeProperties(
+ requestModels.get(RequestType.POST),
+ resource.getResourceModelRef());
+
// Store the resource model in the local cache
- /*
- * SimulatorResourceModel resourceModel = resource
- * .getResourceModelRef(); if (null != resourceModel) {
- * configuredResourceModel.update(resourceModel); }
- * resource.setResourceModelRef(configuredResourceModel);
- */
+ resource.setRequestModels(requestModels);
} catch (SimulatorException e) {
Activator
.getDefault()
.log(Level.ERROR.ordinal(), new Date(),
Utility.getSimulatorErrorString(e, null));
throw e;
+ } catch (Exception e) {
+ Activator
+ .getDefault()
+ .getLogManager()
+ .log(Level.ERROR.ordinal(),
+ new Date(),
+ Utility.getSimulatorErrorString(e,
+ "Error while configuring the attribute properties"));
}
// Update the status
resource.setConfigUploaded(true);
import java.util.Iterator;
import java.util.List;
+import org.oic.simulator.client.SimulatorRemoteResource.RequestType;
+
import oic.simulator.clientcontroller.listener.IConfigurationUpload;
import oic.simulator.clientcontroller.listener.IDevicePlatformInfoUIListener;
import oic.simulator.clientcontroller.listener.IFindResourceUIListener;
}
public void verificationStartedNotification(RemoteResource resource,
- int autoType) {
+ RequestType reqType) {
synchronized (verificationUIListeners) {
if (verificationUIListeners.size() > 0) {
IVerificationUIListener listener;
while (listenerItr.hasNext()) {
listener = listenerItr.next();
if (null != listener) {
- listener.onVerificationStarted(resource, autoType);
+ listener.onVerificationStarted(resource, reqType);
}
}
}
}
public void verificationAbortedNotification(RemoteResource resource,
- int autoType) {
+ RequestType reqType) {
synchronized (verificationUIListeners) {
if (verificationUIListeners.size() > 0) {
IVerificationUIListener listener;
while (listenerItr.hasNext()) {
listener = listenerItr.next();
if (null != listener) {
- listener.onVerificationAborted(resource, autoType);
+ listener.onVerificationAborted(resource, reqType);
}
}
}
}
public void verificationCompletedNotification(RemoteResource resource,
- int autoType) {
+ RequestType reqType) {
synchronized (verificationUIListeners) {
if (verificationUIListeners.size() > 0) {
IVerificationUIListener listener;
while (listenerItr.hasNext()) {
listener = listenerItr.next();
if (null != listener) {
- listener.onVerificationCompleted(resource, autoType);
+ listener.onVerificationCompleted(resource, reqType);
}
}
}
return (!(typeInfo.mType == AttributeValue.ValueType.ARRAY && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) && typeInfo.mType != AttributeValue.ValueType.RESOURCEMODEL);
}
- public void update(SimulatorResourceAttribute attribute,
- boolean ramlUploaded) {
+ public void update(SimulatorResourceAttribute attribute) {
if (attribute == null)
return;
.getKey());
if (attributeElement != null) {
attributeElement.update(new SimulatorResourceAttribute(
- entry.getKey(), entry.getValue()), ramlUploaded);
+ entry.getKey(), entry.getValue()));
} else {
// Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(this,
AttributeElement attributeElement = mChildAttributes
.get("[" + Integer.toString(i) + "]");
if (attributeElement != null) {
- attributeElement.update(indexAttribute, ramlUploaded);
+ attributeElement.update(indexAttribute);
} else {
// Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(
AttributeElement attributeElement = mChildAttributes
.get("[" + Integer.toString(i) + "]");
if (attributeElement != null) {
- attributeElement.update(indexAttribute, ramlUploaded);
+ attributeElement.update(indexAttribute);
} else {
// Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(
AttributeElement attributeElement = mChildAttributes
.get("[" + Integer.toString(i) + "]");
if (attributeElement != null) {
- attributeElement.update(indexAttribute, ramlUploaded);
+ attributeElement.update(indexAttribute);
} else {
// Display new attribute in UI
AttributeElement newAttribute = new AttributeElement(
}
}
} else {
- if (ramlUploaded) {
- mAttribute.setProperty(attribute.property());
- } else {
- String currentValue = new AttributeValueStringConverter(
- mAttribute.value()).toString();
- String newValue = new AttributeValueStringConverter(
- attribute.value()).toString();
- if (!currentValue.equals(newValue)) {
- mAttribute.setValue(attribute.value());
- }
+ String currentValue = new AttributeValueStringConverter(
+ mAttribute.value()).toString();
+ String newValue = new AttributeValueStringConverter(
+ attribute.value()).toString();
+ if (!currentValue.equals(newValue)) {
+ mAttribute.setValue(attribute.value());
}
}
}
if (mParent instanceof AttributeElement)
((AttributeElement) mParent).deepSetChildValue(mAttribute);
}
+
+ public void setAttributeProperty(SimulatorResourceAttribute attribute)
+ throws Exception {
+ if (attribute == null)
+ return;
+
+ AttributeValue.TypeInfo typeInfo = attribute.value().typeInfo();
+ if (typeInfo.mType == AttributeValue.ValueType.RESOURCEMODEL) {
+ SimulatorResourceModel resModel = (SimulatorResourceModel) attribute
+ .value().get();
+
+ ModelProperty modelProp = attribute.property().asModel();
+ mAttribute.setProperty(modelProp);
+
+ for (Map.Entry<String, AttributeValue> entry : resModel.get()
+ .entrySet()) {
+ AttributeElement attributeElement = mChildAttributes.get(entry
+ .getKey());
+ if (attributeElement != null) {
+ attributeElement
+ .setAttributeProperty(new SimulatorResourceAttribute(
+ entry.getKey(), entry.getValue(), modelProp
+ .get(entry.getKey())));
+ } else {
+ // Display new attribute in UI
+ AttributeElement newAttribute = new AttributeElement(this,
+ new SimulatorResourceAttribute(entry.getKey(),
+ entry.getValue(), modelProp.get(entry
+ .getKey())));
+ mChildAttributes.put(entry.getKey(), newAttribute);
+ }
+ }
+ } else if (typeInfo.mType == AttributeValue.ValueType.ARRAY
+ && typeInfo.mBaseType == AttributeValue.ValueType.RESOURCEMODEL) {
+
+ ArrayProperty arrayProp = attribute.property().asArray();
+ mAttribute.setProperty(arrayProp);
+
+ ModelProperty elementModelProp = arrayProp.getElementProperty()
+ .asModel();
+
+ if (typeInfo.mDepth == 1) {
+ SimulatorResourceModel[] resModelArray = (SimulatorResourceModel[]) attribute
+ .value().get();
+
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]),
+ elementModelProp);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.setAttributeProperty(indexAttribute);
+ } else {
+ // Display new attribute in UI
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ }
+ }
+ }
+ if (typeInfo.mDepth == 2) {
+ SimulatorResourceModel[][] resModelArray = (SimulatorResourceModel[][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]),
+ elementModelProp);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.setAttributeProperty(indexAttribute);
+ } else {
+ // Display new attribute in UI
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ }
+ }
+ }
+ if (typeInfo.mDepth == 3) {
+ SimulatorResourceModel[][][] resModelArray = (SimulatorResourceModel[][][]) attribute
+ .value().get();
+ for (int i = 0; i < resModelArray.length; i++) {
+ SimulatorResourceAttribute indexAttribute = new SimulatorResourceAttribute(
+ "[" + Integer.toString(i) + "]",
+ new AttributeValue(resModelArray[i]),
+ elementModelProp);
+ AttributeElement attributeElement = mChildAttributes
+ .get("[" + Integer.toString(i) + "]");
+ if (attributeElement != null) {
+ attributeElement.setAttributeProperty(indexAttribute);
+ } else {
+ // Display new attribute in UI
+ AttributeElement newAttribute = new AttributeElement(
+ this, indexAttribute);
+ mChildAttributes.put("[" + Integer.toString(i) + "]",
+ newAttribute);
+ }
+ }
+ }
+ } else {
+ mAttribute.setProperty(attribute.property());
+ }
+ }
}
package oic.simulator.clientcontroller.remoteresource;
+import java.util.Map;
+
import org.oic.simulator.SimulatorResourceModel;
import org.oic.simulator.client.SimulatorRemoteResource;
-
-import oic.simulator.clientcontroller.utils.Constants;
+import org.oic.simulator.client.SimulatorRemoteResource.RequestType;
+import org.oic.simulator.client.SimulatorRequestModel;
/**
* This class represents a remote resource. It maintains all the necessary
*/
public class RemoteResource {
- private boolean observed;
+ private boolean observed;
// Native object references
- private SimulatorRemoteResource remoteResourceRef;
- private SimulatorResourceModel resourceModelRef;
- private ResourceRepresentation mResourceRepresentation;
+ private SimulatorRemoteResource remoteResourceRef;
+ private SimulatorResourceModel resourceModelRef;
+ private Map<RequestType, SimulatorRequestModel> requestModels;
+ private ResourceRepresentation mResourceRepresentation;
- private boolean configUploaded;
+ private boolean configUploaded;
- private boolean getAutomtnInProgress;
- private boolean putAutomtnInProgress;
- private boolean postAutomtnInProgress;
+ private boolean getAutomtnInProgress;
+ private boolean putAutomtnInProgress;
+ private boolean postAutomtnInProgress;
- private int getAutomtnId;
- private int putAutomtnId;
- private int postAutomtnId;
+ private int getAutomtnId;
+ private int putAutomtnId;
+ private int postAutomtnId;
- private boolean isFavorite;
+ private boolean isFavorite;
public SimulatorResourceModel getResourceModelRef() {
return resourceModelRef;
this.resourceModelRef = resourceModel;
}
+ public Map<RequestType, SimulatorRequestModel> getRequestModels() {
+ return requestModels;
+ }
+
+ public void setRequestModels(
+ Map<RequestType, SimulatorRequestModel> requestModels) {
+ this.requestModels = requestModels;
+ }
+
public int getGetAutomtnId() {
return getAutomtnId;
}
this.observed = observed;
}
- public int getAutomationtype(int autoId) {
+ public RequestType getAutomationtype(int autoId) {
if (getAutomtnId == autoId) {
- return Constants.GET_AUTOMATION_INDEX;
+ return RequestType.GET;
} else if (putAutomtnId == autoId) {
- return Constants.PUT_AUTOMATION_INDEX;
+ return RequestType.PUT;
} else {
- return Constants.POST_AUTOMATION_INDEX;
+ return RequestType.POST;
}
}
this.isFavorite = isFavorite;
}
- public void setResourceRepresentation(SimulatorResourceModel resModel,
- boolean ramlUploaded) {
+ public void setResourceRepresentation(SimulatorResourceModel resModel) {
if (mResourceRepresentation == null)
mResourceRepresentation = new ResourceRepresentation(resModel);
else
- mResourceRepresentation.update(resModel, ramlUploaded);
+ mResourceRepresentation.update(resModel);
}
public ResourceRepresentation getResourceRepresentation() {
import org.oic.simulator.AttributeValue;
import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.ModelProperty;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.SimulatorResourceModel;
+import org.oic.simulator.client.SimulatorRequestModel;
public class ResourceRepresentation {
private Map<String, AttributeElement> mAttributes = new HashMap<String, AttributeElement>();
if (resourceModel != null && resourceModel.size() > 0) {
for (Map.Entry<String, AttributeValue> entry : resourceModel.get()
.entrySet())
- mAttributes.put(entry.getKey(),
- new AttributeElement(this,
- new SimulatorResourceAttribute(entry.getKey(),
- entry.getValue())));
+ if (isCoreAttribute(entry.getKey())) {
+ mAttributes.put(entry.getKey(), new AttributeElement(this,
+ new SimulatorResourceAttribute(entry.getKey(),
+ entry.getValue())));
+ }
}
}
+ private boolean isCoreAttribute(String attName) {
+ if (null == attName || attName.isEmpty()) {
+ return false;
+ }
+
+ if (attName.equalsIgnoreCase("if") || attName.equalsIgnoreCase("rt")
+ || attName.equalsIgnoreCase("p")
+ || attName.equalsIgnoreCase("n")
+ || attName.equalsIgnoreCase("id")) {
+ return false;
+ }
+
+ return true;
+ }
+
public Map<String, AttributeElement> getAttributes() {
return mAttributes;
}
- public void update(SimulatorResourceModel resourceModel,
- boolean ramlUploaded) {
+ public void update(SimulatorResourceModel resourceModel) {
for (Map.Entry<String, AttributeValue> entry : resourceModel.get()
.entrySet()) {
- AttributeElement attributeElement = mAttributes.get(entry.getKey());
- if (attributeElement != null) {
- attributeElement.update(
- new SimulatorResourceAttribute(entry.getKey(), entry
- .getValue()), ramlUploaded);
- } else {
- // Display new attribute in UI
- AttributeElement newAttribute = new AttributeElement(this,
- new SimulatorResourceAttribute(entry.getKey(),
- entry.getValue()));
- mAttributes.put(entry.getKey(), newAttribute);
+ if (isCoreAttribute(entry.getKey())) {
+ AttributeElement attributeElement = mAttributes.get(entry
+ .getKey());
+ if (attributeElement != null) {
+ attributeElement.update(new SimulatorResourceAttribute(
+ entry.getKey(), entry.getValue()));
+ } else {
+ // Display new attribute in UI
+ AttributeElement newAttribute = new AttributeElement(this,
+ new SimulatorResourceAttribute(entry.getKey(),
+ entry.getValue()));
+ mAttributes.put(entry.getKey(), newAttribute);
+ }
}
}
}
+ public boolean updateAttributeProperties(
+ SimulatorRequestModel requestModel,
+ SimulatorResourceModel resourceModelRef) throws Exception {
+ if (null == requestModel || null == resourceModelRef) {
+ return false;
+ }
+
+ ModelProperty modelProp = requestModel.getRequestBodyModel();
+ if (null == modelProp) {
+ return false;
+ }
+
+ for (Map.Entry<String, AttributeValue> entry : resourceModelRef.get()
+ .entrySet()) {
+ if (isCoreAttribute(entry.getKey())) {
+ AttributeElement attributeElement = mAttributes.get(entry
+ .getKey());
+ if (attributeElement != null) {
+ attributeElement
+ .setAttributeProperty(new SimulatorResourceAttribute(
+ entry.getKey(), entry.getValue(), modelProp
+ .get(entry.getKey())));
+ }
+ }
+ }
+
+ return true;
+ }
+
public SimulatorResourceModel getModel() {
if (null == mAttributes || mAttributes.isEmpty()) {
return null;
public class AttributeValueBuilder {
public static AttributeValue build(String valueString,
- AttributeValue.ValueType valueType) {
+ AttributeValue.ValueType valueType) throws Exception {
int depth = findDepth(valueString);
if (0 == depth) {
return handleDepth0(valueString, valueType);
if (null == val) {
return null;
}
+
Object value = val.get();
if (null == value) {
return null;
}
+
TypeInfo type = val.typeInfo();
if (type.mType == ValueType.RESOURCEMODEL
|| (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL)
|| (type.mType == ValueType.ARRAY && type.mDepth > 1)) {
return null;
}
- if (type.mType == ValueType.ARRAY) {
- if (type.mBaseType == ValueType.INTEGER) {
- Integer[] values = (Integer[]) value;
- if (null == values || values.length < 1) {
- return null;
- }
- List<Integer> list = new ArrayList<Integer>();
- for (Integer i : values) {
- list.add(i);
- }
- return list.toString();
- } else if (type.mBaseType == ValueType.DOUBLE) {
- Double[] values = (Double[]) value;
- if (null == values || values.length < 1) {
- return null;
- }
- List<Double> list = new ArrayList<Double>();
- for (Double i : values) {
- list.add(i);
- }
- return list.toString();
- } else if (type.mBaseType == ValueType.BOOLEAN) {
- Boolean[] values = (Boolean[]) value;
- if (null == values || values.length < 1) {
- return null;
- }
- List<Boolean> list = new ArrayList<Boolean>();
- for (Boolean i : values) {
- list.add(i);
- }
- return list.toString();
- } else if (type.mBaseType == ValueType.STRING) {
- String[] values = (String[]) value;
- if (null == values || values.length < 1) {
- return null;
- }
- List<String> list = new ArrayList<String>();
- for (String i : values) {
- list.add(i);
- }
- return list.toString();
- } else {
- return null;
- }
- } else {
- return String.valueOf(value);
- }
+
+ AttributeValueStringConverter converter = new AttributeValueStringConverter(
+ val);
+ return converter.toString();
}
public static Map<String, String> getResourceInterfaces() {
ifTypes.put(Constants.SENSOR_INTERFACE, "Sensor");
return ifTypes;
}
+
+ public static String removeWhiteSpacesInArrayValues(String value) {
+ if (null == value || value.isEmpty())
+ return null;
+
+ value = value.trim();
+
+ String token[] = value.split(",");
+ String result = "";
+ for (int i = 0; i < token.length; i++) {
+ result += token[i].trim();
+ if (i + 1 < token.length) {
+ result += ",";
+ }
+ }
+
+ return result;
+ }
}
\ No newline at end of file
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;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import java.util.List;
+import org.oic.simulator.ArrayProperty;
+import org.oic.simulator.AttributeProperty;
import org.oic.simulator.AttributeValue;
import org.oic.simulator.AttributeValue.TypeInfo;
import org.oic.simulator.AttributeValue.ValueType;
import oic.simulator.clientcontroller.utils.AttributeValueBuilder;
import oic.simulator.clientcontroller.utils.Utility;
import oic.simulator.clientcontroller.view.dialogs.PostRequestDialog;
+import oic.simulator.clientcontroller.view.dialogs.UpdatePrimitiveArrayAttributeDialog;
/**
* This class provides editing support to the resources attributes table in the
return null;
}
- String values[] = null;
- List<String> valueSet = resourceManager
- .getAllValuesOfAttribute(attribute);
- values = convertListToStringArray(valueSet);
-
- ComboBoxCellEditor comboEditor;
- comboEditor = new ComboBoxCellEditor(viewer.getTree(), values);
- comboBox = (CCombo) comboEditor.getControl();
- comboBox.addModifyListener(new ModifyListener() {
-
- @Override
- public void modifyText(ModifyEvent event) {
- String newValue = comboBox.getText();
-
- if (null != newValue && !newValue.isEmpty()) {
- attributeElement.setPostState(true);
- } else {
- attributeElement.setPostState(false);
+ CellEditor editor;
+ if (type.mType == ValueType.ARRAY && res.isConfigUploaded()
+ && isArrayAttributeValid(attribute)) {
+ editor = new TextCellEditor(viewer.getTree());
+ editor.setStyle(SWT.READ_ONLY);
+ final Text txt = (Text) editor.getControl();
+ txt.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ UpdatePrimitiveArrayAttributeDialog dialog = new UpdatePrimitiveArrayAttributeDialog(
+ Display.getDefault().getActiveShell(),
+ attribute);
+ if (dialog.open() == Window.OK) {
+ updateAttributeValue(attribute,
+ dialog.getNewValueObj());
+ }
+
+ // Update the viewer in a separate UI thread.
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ attributeElement.setPostState(true);
+ viewer.refresh(element, true);
+ }
+ });
}
-
- if (dialog instanceof PostRequestDialog) {
- viewer.update(attributeElement, null);
+ });
+ } else {
+ String values[] = null;
+ List<String> valueSet = resourceManager
+ .getAllValuesOfAttribute(attribute);
+ values = convertListToStringArray(valueSet);
+
+ editor = new ComboBoxCellEditor(viewer.getTree(), values);
+ comboBox = (CCombo) editor.getControl();
+ comboBox.addModifyListener(new ModifyListener() {
+
+ @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);
+ }
}
- }
- });
- return comboEditor;
+ });
+ }
+ return editor;
}
@Override
return 0;
}
+ final AttributeValue val = att.value();
+ if (null == val) {
+ return null;
+ }
+
+ final TypeInfo type = val.typeInfo();
+ if (type.mBaseType == ValueType.RESOURCEMODEL) {
+ return null;
+ }
+
String valueString = Utility.getAttributeValueAsString(att.value());
+ if (null == valueString) {
+ valueString = "";
+ }
+
+ if (type.mType == ValueType.ARRAY) {
+ ResourceManager resourceManager = Activator.getDefault()
+ .getResourceManager();
+
+ RemoteResource res = resourceManager
+ .getCurrentResourceInSelection();
+ if (null != res && res.isConfigUploaded()
+ && isArrayAttributeValid(att)) {
+ return valueString;
+ }
+ }
+
List<String> valueSet = Activator.getDefault().getResourceManager()
.getAllValuesOfAttribute(att);
if (null != valueSet) {
TypeInfo type = val.typeInfo();
+ if (type.mBaseType == ValueType.RESOURCEMODEL) {
+ return;
+ }
+
+ if (type.mType == ValueType.ARRAY) {
+ ResourceManager resourceManager = Activator.getDefault()
+ .getResourceManager();
+
+ RemoteResource res = resourceManager
+ .getCurrentResourceInSelection();
+ if (null != res && res.isConfigUploaded()
+ && isArrayAttributeValid(att)) {
+ return;
+ }
+ }
+
String oldValue = String.valueOf(Utility
.getAttributeValueAsString(val));
+ if (null == oldValue) {
+ oldValue = "";
+ }
+
String newValue = comboBox.getText();
+
+ if (type.mType == ValueType.ARRAY
+ && type.mBaseType != ValueType.RESOURCEMODEL) {
+ newValue = Utility.removeWhiteSpacesInArrayValues(newValue);
+ }
+
if (!oldValue.equals(newValue)) {
- // Get the AttriuteValue from the string
- AttributeValue attValue = AttributeValueBuilder.build(newValue,
- type.mBaseType);
boolean invalid = false;
+
+ // Get the AttriuteValue from the string
+ AttributeValue attValue = null;
+ try {
+ attValue = AttributeValueBuilder.build(newValue,
+ type.mBaseType);
+ } catch (Exception e) {
+ }
if (null == attValue) {
invalid = true;
} else {
viewer.update(element, null);
}
+ private boolean isArrayAttributeValid(
+ SimulatorResourceAttribute attribute) {
+ if (null == attribute)
+ return false;
+
+ AttributeValue val = attribute.value();
+ if (null == val)
+ return false;
+
+ AttributeProperty prop = attribute.property();
+ if (null == prop || !prop.isArray())
+ return false;
+
+ ArrayProperty arrProp = prop.asArray();
+ if (null == arrProp)
+ return false;
+
+ AttributeProperty elementProp = arrProp.getElementProperty();
+ if (null == elementProp)
+ return false;
+
+ TypeInfo info = val.typeInfo();
+ if (info.mBaseType == ValueType.RESOURCEMODEL)
+ return false;
+
+ return true;
+ }
+
public String[] convertListToStringArray(List<String> values) {
String[] strArr;
if (null != values && values.size() > 0) {
import org.oic.simulator.ILogger.Level;
import org.oic.simulator.SimulatorResourceAttribute;
import org.oic.simulator.client.SimulatorRemoteResource;
-import org.oic.simulator.client.SimulatorRemoteResource.VerificationType;
+import org.oic.simulator.client.SimulatorRemoteResource.RequestType;
import oic.simulator.clientcontroller.Activator;
import oic.simulator.clientcontroller.listener.IConfigurationUpload;
@Override
public void onVerificationStarted(final RemoteResource resource,
- final int autoType) {
+ final RequestType reqType) {
// Do Nothing. For Future Use.
}
@Override
public void onVerificationCompleted(final RemoteResource resource,
- final int autoType) {
+ final RequestType reqType) {
if (null == resource) {
return;
.log(Level.INFO.ordinal(),
new Date(),
"["
- + VerificationType.values()[autoType]
- .toString()
+ + reqType.toString()
+ "] Verification Completed for \""
+ remoteResource.getURI()
+ "\".");
@Override
public void onVerificationAborted(final RemoteResource resource,
- final int autoType) {
+ final RequestType reqType) {
if (null == resource) {
return;
.log(Level.INFO.ordinal(),
new Date(),
"["
- + VerificationType.values()[autoType]
- .toString()
+ + reqType
+ "] Verification Aborted for \""
+ remoteResource.getURI()
+ "\".");
+ "\nDo you want to proceed?");
if (answer) {
if (startGet || stopGet)
- automate(VerificationType.GET,
+ automate(RequestType.GET,
autoStatus.get(Constants.GET));
if (startPut || stopPut)
- automate(VerificationType.PUT,
+ automate(RequestType.PUT,
autoStatus.get(Constants.PUT));
if (startPost || stopPost)
- automate(VerificationType.POST,
+ automate(RequestType.POST,
autoStatus.get(Constants.POST));
}
}
});
}
- private void automate(VerificationType type, boolean start) {
+ private void automate(RequestType type, boolean start) {
if (start) {
resourceManager.startAutomationRequest(type, resourceInSelection);
} else {
SimulatorResourceAttribute attribute = attrElement
.getSimulatorResourceAttribute();
- if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
- return Utility.getAttributeValueAsString(attribute
- .value());
+ if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL) {
+ String value = Utility
+ .getAttributeValueAsString(attribute
+ .value());
+ if (null == value) {
+ value = "";
+ }
+ return value;
+ }
return null;
}
}
import org.oic.simulator.AttributeValue.ValueType;
import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.client.SimulatorRemoteResource.RequestType;
import oic.simulator.clientcontroller.Activator;
import oic.simulator.clientcontroller.remoteresource.AttributeElement;
updatedRepresentation = new ResourceRepresentation(
resource.getResourceModelRef());
+ if (resource.isConfigUploaded()) {
+ try {
+ updatedRepresentation.updateAttributeProperties(resource
+ .getRequestModels().get(RequestType.POST), resource
+ .getResourceModelRef());
+ } catch (Exception e1) {
+ }
+ }
+
attViewer.setInput(updatedRepresentation);
attViewer.expandAll();
SimulatorResourceAttribute attribute = attrElement
.getSimulatorResourceAttribute();
- if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
- return Utility.getAttributeValueAsString(attribute
- .value());
+ if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL) {
+ String value = Utility
+ .getAttributeValueAsString(attribute
+ .value());
+ if (null == value) {
+ value = "";
+ }
+ return value;
+ }
return null;
}
import org.oic.simulator.AttributeValue.ValueType;
import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.client.SimulatorRemoteResource.RequestType;
import oic.simulator.clientcontroller.Activator;
import oic.simulator.clientcontroller.remoteresource.AttributeElement;
updatedRepresentation = new ResourceRepresentation(
resource.getResourceModelRef());
+ if (resource.isConfigUploaded()) {
+ try {
+ updatedRepresentation.updateAttributeProperties(resource
+ .getRequestModels().get(RequestType.POST), resource
+ .getResourceModelRef());
+ } catch (Exception e1) {
+ }
+ }
+
attViewer.setInput(updatedRepresentation);
attViewer.expandAll();
SimulatorResourceAttribute attribute = attrElement
.getSimulatorResourceAttribute();
- if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
- return Utility.getAttributeValueAsString(attribute
- .value());
+ if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL) {
+ String value = Utility
+ .getAttributeValueAsString(attribute
+ .value());
+ if (null == value) {
+ value = "";
+ }
+ return value;
+ }
return null;
}
}
--- /dev/null
+/*
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.clientcontroller.view.dialogs;
+
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import org.oic.simulator.ArrayProperty;
+import org.oic.simulator.AttributeProperty;
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.DoubleProperty;
+import org.oic.simulator.IntegerProperty;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.StringProperty;
+
+import oic.simulator.clientcontroller.utils.AttributeValueBuilder;
+import oic.simulator.clientcontroller.utils.AttributeValueStringConverter;
+import oic.simulator.clientcontroller.utils.Utility;
+
+/**
+ * This class manages and shows the automation settings dialog from the
+ * attribute view.
+ */
+public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
+
+ private Text attNameTxt;
+ private Text currentValueTxt;
+ private Text newValueTxt;
+ private Text allowedValuesTxt;
+ private SimulatorResourceAttribute attribute;
+ private String newValue;
+
+ private AttributeValue newAttValueObj;
+
+ public UpdatePrimitiveArrayAttributeDialog(Shell parentShell,
+ SimulatorResourceAttribute attribute) {
+ super(parentShell);
+ this.attribute = attribute;
+ }
+
+ @Override
+ public void create() {
+ super.create();
+ setTitle("Modify Attribute's Value");
+ setMessage("Change the value of the array type attribute");
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite compLayout = (Composite) super.createDialogArea(parent);
+
+ Composite container = new Composite(compLayout, SWT.NONE);
+ container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ GridLayout layout = new GridLayout(2, false);
+ layout.verticalSpacing = 10;
+ layout.marginTop = 10;
+ container.setLayout(layout);
+
+ GridData gd;
+
+ Label attNameLbl = new Label(container, SWT.NONE);
+ attNameLbl.setText("Attribute Name");
+
+ attNameTxt = new Text(container, SWT.READ_ONLY | SWT.BORDER);
+ attNameTxt.setBackground(container.getBackground());
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ attNameTxt.setLayoutData(gd);
+
+ Label allowedValuesLbl = new Label(container, SWT.NONE);
+ allowedValuesLbl.setText("Allowed Values");
+
+ allowedValuesTxt = new Text(container, SWT.MULTI | SWT.READ_ONLY
+ | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
+ allowedValuesTxt.setBackground(container.getBackground());
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessVerticalSpace = true;
+ gd.verticalAlignment = SWT.FILL;
+ gd.minimumHeight = 30;
+ allowedValuesTxt.setLayoutData(gd);
+
+ Label curValueLbl = new Label(container, SWT.NONE);
+ curValueLbl.setText("Current Value");
+
+ currentValueTxt = new Text(container, SWT.MULTI | SWT.READ_ONLY
+ | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
+ currentValueTxt.setBackground(container.getBackground());
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessVerticalSpace = true;
+ gd.verticalAlignment = SWT.FILL;
+ gd.minimumHeight = 30;
+ currentValueTxt.setLayoutData(gd);
+
+ Label attNewValue = new Label(container, SWT.NONE);
+ attNewValue.setText("New Value");
+
+ newValueTxt = new Text(container, SWT.MULTI | SWT.BORDER | SWT.WRAP
+ | SWT.V_SCROLL);
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessVerticalSpace = true;
+ gd.verticalAlignment = SWT.FILL;
+ gd.minimumHeight = 60;
+ newValueTxt.setLayoutData(gd);
+ newValueTxt.setFocus();
+
+ Label hintHeader = new Label(container, SWT.NULL);
+ hintHeader.setText("Note:-");
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.horizontalSpan = 2;
+ hintHeader.setLayoutData(gd);
+
+ Label hint = new Label(container, SWT.NULL);
+ hint.setText("Array values should be comma-seperated and surrounded by square brackets.\n"
+ + "Ex: \"[value]\", \"[value1,value2]\", \"[[value1], [value2]]\"");
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.horizontalSpan = 2;
+ gd.horizontalIndent = 40;
+ hint.setLayoutData(gd);
+
+ populateData();
+
+ return compLayout;
+ }
+
+ private void populateData() {
+ // Set the Attribute Name.
+ attNameTxt.setText(attribute.name());
+
+ // Set the allowed values.
+ ArrayProperty arrProp = attribute.property().asArray();
+ AttributeProperty elementProp = arrProp.getElementProperty();
+
+ String values = "";
+ if (elementProp.isInteger()) {
+ IntegerProperty intProp = elementProp.asInteger();
+ if (intProp.hasRange()) {
+ values = "From " + intProp.min() + " To " + intProp.max();
+ } else if (intProp.hasValues()) {
+ int[] arr = intProp.getValues();
+ for (int i = 0; i < arr.length; i++) {
+ values += arr[i];
+ if (i + 1 < arr.length) {
+ values += ", ";
+ }
+ }
+
+ if (!values.isEmpty()) {
+ values = "[" + values + "]";
+ }
+ }
+ } else if (elementProp.isDouble()) {
+ DoubleProperty dblProp = elementProp.asDouble();
+ if (dblProp.hasRange()) {
+ values = "From " + dblProp.min() + " To " + dblProp.max();
+ } else if (dblProp.hasValues()) {
+ double[] arr = dblProp.getValues();
+ for (int i = 0; i < arr.length; i++) {
+ values += arr[i];
+ if (i + 1 < arr.length) {
+ values += ", ";
+ }
+ }
+
+ if (!values.isEmpty()) {
+ values = "[" + values + "]";
+ }
+ }
+ } else if (elementProp.isBoolean()) {
+ values = "[true, false]";
+ } else if (elementProp.isString()) {
+ StringProperty strProp = elementProp.asString();
+ if (strProp.hasValues()) {
+ String[] arr = strProp.getValues();
+ for (int i = 0; i < arr.length; i++) {
+ values += arr[i];
+ if (i + 1 < arr.length) {
+ values += ", ";
+ }
+ }
+
+ if (!values.isEmpty()) {
+ values = "[" + values + "]";
+ }
+ }
+ }
+ allowedValuesTxt.setText(values);
+
+ // Set the current value.
+ currentValueTxt.setText(new AttributeValueStringConverter(attribute
+ .value()).toString());
+ }
+
+ public String getNewValue() {
+ return newValue;
+ }
+
+ public AttributeValue getNewValueObj() {
+ return newAttValueObj;
+ }
+
+ @Override
+ protected void okPressed() {
+ // Validate the value
+ newValue = newValueTxt.getText();
+ if (null == newValue || newValue.isEmpty()) {
+ return;
+ }
+
+ // ArrayProperty arrProp = attribute.property().asArray();
+ try {
+ String value = Utility.removeWhiteSpacesInArrayValues(newValue);
+ if (value.startsWith("[") && value.endsWith("]")) {
+ newAttValueObj = AttributeValueBuilder.build(value, attribute
+ .value().typeInfo().mBaseType);
+ if (null != newAttValueObj/* && arrProp.validate(newAttValueObj) */) {
+ close();
+ return;
+ }
+ }
+ } catch (Exception e) {
+ }
+
+ MessageBox dialog = new MessageBox(Display.getDefault()
+ .getActiveShell(), SWT.ICON_ERROR | SWT.OK);
+ dialog.setText("Invalid Value");
+ dialog.setMessage("Either the value of its format is invalid.\n"
+ + "Format: Array values should be comma-seperated and surrounded by square brackets.\n"
+ + "Ex: \"[value]\", \"[value1,value2]\", \"[[value1], [value2]]\"");
+ dialog.open();
+
+ newValueTxt.setFocus();
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ public boolean isHelpAvailable() {
+ return false;
+ }
+}
attribute.value()).toString();
if (!currentValue.equals(newValue)) {
mAttribute.setValue(attribute.value());
+ if (mParent instanceof AttributeElement) {
+ try {
+ ((AttributeElement) mParent)
+ .deepSetChildValue(mAttribute);
+ } catch (InvalidArgsException e) {
+ }
+ }
UiListenerHandler.getInstance().attributeUpdatedUINotification(
this);
}
public class AttributeValueBuilder {
public static AttributeValue build(String valueString,
- AttributeValue.ValueType valueType) {
+ AttributeValue.ValueType valueType) throws Exception {
int depth = findDepth(valueString);
if (0 == depth) {
return handleDepth0(valueString, valueType);
if (null == val) {
return null;
}
+
Object value = val.get();
if (null == value) {
return null;
}
+
TypeInfo type = val.typeInfo();
if (type.mType == ValueType.RESOURCEMODEL
|| (type.mType == ValueType.ARRAY && type.mBaseType == ValueType.RESOURCEMODEL)
|| (type.mType == ValueType.ARRAY && type.mDepth > 1)) {
return null;
}
- if (type.mType == ValueType.ARRAY) {
- if (type.mBaseType == ValueType.INTEGER) {
- Integer[] values = (Integer[]) value;
- if (null == values || values.length < 1) {
- return null;
- }
- List<Integer> list = new ArrayList<Integer>();
- for (Integer i : values) {
- list.add(i);
- }
- return list.toString();
- } else if (type.mBaseType == ValueType.DOUBLE) {
- Double[] values = (Double[]) value;
- if (null == values || values.length < 1) {
- return null;
- }
- List<Double> list = new ArrayList<Double>();
- for (Double i : values) {
- list.add(i);
- }
- return list.toString();
- } else if (type.mBaseType == ValueType.BOOLEAN) {
- Boolean[] values = (Boolean[]) value;
- if (null == values || values.length < 1) {
- return null;
- }
- List<Boolean> list = new ArrayList<Boolean>();
- for (Boolean i : values) {
- list.add(i);
- }
- return list.toString();
- } else if (type.mBaseType == ValueType.STRING) {
- String[] values = (String[]) value;
- if (null == values || values.length < 1) {
- return null;
- }
- List<String> list = new ArrayList<String>();
- for (String i : values) {
- list.add(i);
- }
- return list.toString();
- } else {
- return null;
- }
- } else {
- return String.valueOf(value);
- }
+
+ AttributeValueStringConverter converter = new AttributeValueStringConverter(
+ val);
+ return converter.toString();
}
public static boolean isUriValid(String resURI) {
}
return ifTypes;
}
+
+ public static String removeWhiteSpacesInArrayValues(String value) {
+ if (null == value || value.isEmpty())
+ return null;
+
+ value = value.trim();
+
+ String token[] = value.split(",");
+ String result = "";
+ for (int i = 0; i < token.length; i++) {
+ result += token[i].trim();
+ if (i + 1 < token.length) {
+ result += ",";
+ }
+ }
+
+ return result;
+ }
}
\ No newline at end of file
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;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IPartListener2;
import oic.simulator.serviceprovider.utils.AttributeValueBuilder;
import oic.simulator.serviceprovider.utils.Utility;
import oic.simulator.serviceprovider.view.dialogs.AutomationSettingDialog;
+import oic.simulator.serviceprovider.view.dialogs.UpdatePrimitiveArrayAttributeDialog;
/**
* This class provides editing support to the resources attributes table in the
return null;
}
- String values[] = null;
- List<String> valueSet = resourceManager
- .getAllValuesOfAttribute(attribute);
- values = Utility.convertListToStringArray(valueSet);
-
- ComboBoxCellEditor comboEditor;
+ CellEditor editor;
if (type.mType == ValueType.ARRAY) {
- comboEditor = new ComboBoxCellEditor(viewer.getTree(), values);
+ editor = new TextCellEditor(viewer.getTree());
+ editor.setStyle(SWT.READ_ONLY);
+ final Text txt = (Text) editor.getControl();
+ txt.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ String currentAttValue = txt.getText();
+ UpdatePrimitiveArrayAttributeDialog dialog = new UpdatePrimitiveArrayAttributeDialog(
+ Display.getDefault().getActiveShell(),
+ attribute);
+ if (dialog.open() == Window.OK) {
+ updateAttributeValue(attribute,
+ dialog.getNewValueObj());
+
+ 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) {
+ try {
+ updateAttributeValue(attribute,
+ AttributeValueBuilder.build(
+ currentAttValue,
+ type.mBaseType));
+ } catch (Exception ex) {
+ }
+ MessageDialog
+ .openInformation(Display.getDefault()
+ .getActiveShell(),
+ "Operation failed",
+ "Failed to update the attribute value.");
+ }
+ }
+
+ // Update the viewer in a separate UI thread.
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ viewer.refresh(element, true);
+ }
+ });
+ }
+ });
} else {
- comboEditor = new ComboBoxCellEditor(viewer.getTree(), values,
+ String values[] = null;
+ List<String> valueSet = resourceManager
+ .getAllValuesOfAttribute(attribute);
+ values = Utility.convertListToStringArray(valueSet);
+
+ editor = new ComboBoxCellEditor(viewer.getTree(), values,
SWT.READ_ONLY);
- }
- comboBox = (CCombo) comboEditor.getControl();
- comboBox.addModifyListener(new ModifyListener() {
+ comboBox = (CCombo) editor.getControl();
+ comboBox.addModifyListener(new ModifyListener() {
- @Override
- public void modifyText(ModifyEvent event) {
- if (type.mType == ValueType.ARRAY) {
- return;
- }
- String oldValue = String.valueOf(Utility
- .getAttributeValueAsString(val));
- String newValue = comboBox.getText();
+ @Override
+ public void modifyText(ModifyEvent event) {
+ if (type.mType == ValueType.ARRAY) {
+ return;
+ }
+ String oldValue = String.valueOf(Utility
+ .getAttributeValueAsString(val));
+ if (null == oldValue) {
+ oldValue = "";
+ }
+ String newValue = comboBox.getText();
- attributeElement.setEditLock(true);
- compareAndUpdateAttribute(oldValue, newValue, element,
- attribute, type);
- attributeElement.setEditLock(false);
+ attributeElement.setEditLock(true);
+ compareAndUpdateAttribute(oldValue, newValue, element,
+ attribute, type);
+ attributeElement.setEditLock(false);
- comboBox.setVisible(false);
- }
- });
- return comboEditor;
+ comboBox.setVisible(false);
+ }
+ });
+ }
+ return editor;
}
@Override
return 0;
}
+ final AttributeValue val = att.value();
+ if (null == val) {
+ return null;
+ }
+
+ final TypeInfo type = val.typeInfo();
+ if (type.mBaseType == ValueType.RESOURCEMODEL) {
+ return null;
+ }
+
String valueString = Utility.getAttributeValueAsString(att.value());
+ if (null == valueString) {
+ valueString = "";
+ }
+
+ if (type.mType == ValueType.ARRAY) {
+ return valueString;
+ }
+
List<String> valueSet = Activator.getDefault().getResourceManager()
.getAllValuesOfAttribute(att);
if (null != valueSet) {
return;
}
if (!oldValue.equals(newValue)) {
- // Get the AttriuteValue from the string
- AttributeValue attValue = AttributeValueBuilder.build(newValue,
- type.mBaseType);
boolean invalid = false;
+
+ // Get the AttriuteValue from the string
+ AttributeValue attValue = null;
+ try {
+ attValue = AttributeValueBuilder.build(newValue,
+ type.mBaseType);
+ } catch (Exception e) {
+ }
+
if (null == attValue) {
invalid = true;
} else {
dialog.setMessage("Do you want to modify the value?");
int retval = dialog.open();
if (retval != SWT.OK) {
- attValue = AttributeValueBuilder.build(oldValue,
- type.mBaseType);
+ try {
+ attValue = AttributeValueBuilder.build(oldValue,
+ type.mBaseType);
+ } catch (Exception e) {
+ }
updateAttributeValue(att, attValue);
} else {
updateAttributeValue(att, attValue);
(SingleResource) resource,
result.name(), result.value());
if (!updated) {
- attValue = AttributeValueBuilder.build(oldValue,
- type.mBaseType);
+ try {
+ attValue = AttributeValueBuilder.build(
+ oldValue, type.mBaseType);
+ } catch (Exception e) {
+ }
updateAttributeValue(att, attValue);
MessageDialog.openInformation(Display.getDefault()
.getActiveShell(), "Operation failed",
SimulatorResourceAttribute attribute = attrElement
.getSimulatorResourceAttribute();
- if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL)
- return Utility.getAttributeValueAsString(attribute
- .value());
+ if (attribute.value().typeInfo().mBaseType != ValueType.RESOURCEMODEL) {
+ String value = Utility
+ .getAttributeValueAsString(attribute
+ .value());
+ if (null == value) {
+ value = "";
+ }
+ return value;
+ }
return null;
}
} catch (SimulatorException ex) {
result = false;
}
- if (result) {
- MessageDialog.openInformation(
- parent.getShell(), "Operation status",
- "Resource properties updated.");
- } else {
+ if (!result) {
MessageDialog.openInformation(
parent.getShell(), "Operation status",
"Failed to update the resource properties.");
/*
- * Copyright 2015 Samsung Electronics All Rights Reserved.
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
--- /dev/null
+/*
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package oic.simulator.serviceprovider.view.dialogs;
+
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import org.oic.simulator.ArrayProperty;
+import org.oic.simulator.AttributeProperty;
+import org.oic.simulator.AttributeValue;
+import org.oic.simulator.AttributeValue.TypeInfo;
+import org.oic.simulator.AttributeValue.ValueType;
+import org.oic.simulator.DoubleProperty;
+import org.oic.simulator.IntegerProperty;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.StringProperty;
+
+import oic.simulator.serviceprovider.utils.AttributeValueBuilder;
+import oic.simulator.serviceprovider.utils.AttributeValueStringConverter;
+import oic.simulator.serviceprovider.utils.Utility;
+
+/**
+ * This class manages and shows the automation settings dialog from the
+ * attribute view.
+ */
+public class UpdatePrimitiveArrayAttributeDialog extends TitleAreaDialog {
+
+ private Text attNameTxt;
+ private Text currentValueTxt;
+ private Text newValueTxt;
+ private Text allowedValuesTxt;
+ private SimulatorResourceAttribute attribute;
+ private String newValue;
+
+ private AttributeValue newAttValueObj;
+
+ public UpdatePrimitiveArrayAttributeDialog(Shell parentShell,
+ SimulatorResourceAttribute attribute) {
+ super(parentShell);
+ this.attribute = attribute;
+ }
+
+ @Override
+ public void create() {
+ super.create();
+ setTitle("Modify Attribute's Value");
+ setMessage("Change the value of the array type attribute");
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite compLayout = (Composite) super.createDialogArea(parent);
+
+ Composite container = new Composite(compLayout, SWT.NONE);
+ container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ GridLayout layout = new GridLayout(2, false);
+ layout.verticalSpacing = 10;
+ layout.marginTop = 10;
+ container.setLayout(layout);
+
+ GridData gd;
+
+ Label attNameLbl = new Label(container, SWT.NONE);
+ attNameLbl.setText("Attribute Name");
+
+ attNameTxt = new Text(container, SWT.READ_ONLY | SWT.BORDER);
+ attNameTxt.setBackground(container.getBackground());
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ attNameTxt.setLayoutData(gd);
+
+ Label allowedValuesLbl = new Label(container, SWT.NONE);
+ allowedValuesLbl.setText("Allowed Values");
+
+ allowedValuesTxt = new Text(container, SWT.MULTI | SWT.READ_ONLY
+ | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
+ allowedValuesTxt.setBackground(container.getBackground());
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessVerticalSpace = true;
+ gd.verticalAlignment = SWT.FILL;
+ gd.minimumHeight = 30;
+ allowedValuesTxt.setLayoutData(gd);
+
+ Label curValueLbl = new Label(container, SWT.NONE);
+ curValueLbl.setText("Current Value");
+
+ currentValueTxt = new Text(container, SWT.MULTI | SWT.READ_ONLY
+ | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
+ currentValueTxt.setBackground(container.getBackground());
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessVerticalSpace = true;
+ gd.verticalAlignment = SWT.FILL;
+ gd.minimumHeight = 30;
+ currentValueTxt.setLayoutData(gd);
+
+ Label attNewValue = new Label(container, SWT.NONE);
+ attNewValue.setText("New Value");
+
+ newValueTxt = new Text(container, SWT.MULTI | SWT.BORDER | SWT.WRAP
+ | SWT.V_SCROLL);
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessVerticalSpace = true;
+ gd.verticalAlignment = SWT.FILL;
+ gd.minimumHeight = 60;
+ newValueTxt.setLayoutData(gd);
+ newValueTxt.setFocus();
+
+ Label hintHeader = new Label(container, SWT.NULL);
+ hintHeader.setText("Note:-");
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.horizontalSpan = 2;
+ hintHeader.setLayoutData(gd);
+
+ Label hint = new Label(container, SWT.NULL);
+ hint.setText("Array values should be comma-seperated and surrounded by square brackets.\n"
+ + "Ex: \"[value]\", \"[value1,value2]\", \"[[value1], [value2]]\"");
+ gd = new GridData();
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.horizontalSpan = 2;
+ gd.horizontalIndent = 40;
+ hint.setLayoutData(gd);
+
+ populateData();
+
+ return compLayout;
+ }
+
+ private void populateData() {
+ // Set the Attribute Name.
+ attNameTxt.setText(attribute.name());
+
+ // Set the allowed values.
+ ArrayProperty arrProp = attribute.property().asArray();
+ AttributeProperty elementProp = arrProp.getElementProperty();
+
+ String values = "";
+ if (elementProp.isInteger()) {
+ IntegerProperty intProp = elementProp.asInteger();
+ if (intProp.hasRange()) {
+ values = "From " + intProp.min() + " To " + intProp.max();
+ } else if (intProp.hasValues()) {
+ int[] arr = intProp.getValues();
+ for (int i = 0; i < arr.length; i++) {
+ values += arr[i];
+ if (i + 1 < arr.length) {
+ values += ", ";
+ }
+ }
+
+ if (!values.isEmpty()) {
+ values = "[" + values + "]";
+ }
+ }
+ } else if (elementProp.isDouble()) {
+ DoubleProperty dblProp = elementProp.asDouble();
+ if (dblProp.hasRange()) {
+ values = "From " + dblProp.min() + " To " + dblProp.max();
+ } else if (dblProp.hasValues()) {
+ double[] arr = dblProp.getValues();
+ for (int i = 0; i < arr.length; i++) {
+ values += arr[i];
+ if (i + 1 < arr.length) {
+ values += ", ";
+ }
+ }
+
+ if (!values.isEmpty()) {
+ values = "[" + values + "]";
+ }
+ }
+ } else if (elementProp.isBoolean()) {
+ values = "[true, false]";
+ } else if (elementProp.isString()) {
+ StringProperty strProp = elementProp.asString();
+ if (strProp.hasValues()) {
+ String[] arr = strProp.getValues();
+ for (int i = 0; i < arr.length; i++) {
+ values += arr[i];
+ if (i + 1 < arr.length) {
+ values += ", ";
+ }
+ }
+
+ if (!values.isEmpty()) {
+ values = "[" + values + "]";
+ }
+ }
+ }
+ allowedValuesTxt.setText(values);
+
+ // Set the current value.
+ currentValueTxt.setText(new AttributeValueStringConverter(attribute
+ .value()).toString());
+ }
+
+ public String getNewValue() {
+ return newValue;
+ }
+
+ public AttributeValue getNewValueObj() {
+ return newAttValueObj;
+ }
+
+ @Override
+ protected void okPressed() {
+ // Validate the value
+ newValue = newValueTxt.getText();
+ if (null == newValue || newValue.isEmpty()) {
+ return;
+ }
+
+ ArrayProperty arrProp = attribute.property().asArray();
+ try {
+ String value = Utility.removeWhiteSpacesInArrayValues(newValue);
+ if (value.startsWith("[") && value.endsWith("]")) {
+ newAttValueObj = AttributeValueBuilder.build(value, attribute
+ .value().typeInfo().mBaseType);
+ if (null != newAttValueObj && arrProp.validate(newAttValueObj)) {
+ close();
+ return;
+ }
+ }
+ } catch (Exception e) {
+ }
+
+ MessageBox dialog = new MessageBox(Display.getDefault()
+ .getActiveShell(), SWT.ICON_ERROR | SWT.OK);
+ dialog.setText("Invalid Value");
+ dialog.setMessage("Given value is invalid.\nEither the entered value(s) are not in the allowed values or in improper format.\n"
+ + "Format: Array values should be comma-seperated and surrounded by square brackets.\n"
+ + "Ex: \"[value]\", \"[value1,value2]\", \"[[value1], [value2]]\"");
+ dialog.open();
+
+ newValueTxt.setFocus();
+ }
+
+ @Override
+ protected boolean isResizable() {
+ return true;
+ }
+
+ @Override
+ public boolean isHelpAvailable() {
+ return false;
+ }
+}
return;
}
String ifType = addIfTypeDlg.getValue();
+ if (null == ifType || ifType.isEmpty()) {
+ return;
+ }
+
ifTypesList.add(ifType);
ifTypesList.deselectAll();
ifTypesList.select(ifTypesList.getItemCount() - 1);
*/
public class SimulatorManager {
- static {
- System.loadLibrary("oc_logger");
- System.loadLibrary("octbstack");
- System.loadLibrary("oc");
- System.loadLibrary("RamlParser");
- System.loadLibrary("SimulatorManager");
- }
-
/**
* API for creating a resource from a RAML configuration file.
*