Integration of client side resource configuration changes and Handling of array-type...
authorG S Senthil Kumar <senthil.gs@samsung.com>
Sat, 20 Feb 2016 12:32:54 +0000 (18:02 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 22 Feb 2016 01:45:26 +0000 (01:45 +0000)
1. Integrated the native layer changes for remote resource
   RAML configuration with Client Controller plug-in.
2. Added UI Support to edit primitive array-type attribute values
   in both Service Provider and Client Controller plugins.
3. Includes minor bug fixes.

Change-Id: I0b601c1c823c7b764755de900263bc8e392befb9
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5089
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
24 files changed:
service/simulator/SConscript
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/listener/IVerificationUIListener.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/UiListenerHandler.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResource.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueBuilder.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueBuilder.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddInterfaceTypeDialog.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateResourceInterfaceDialog.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java

index fb948d1..2f262a5 100755 (executable)
@@ -78,7 +78,7 @@ simulator_env.AppendUnique(CXXFLAGS = ['-O2', '-Wall', '-fmessage-length=0', '-s
 ######################################################################
 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)
 
index 0956a68..33b1861 100644 (file)
@@ -16,6 +16,8 @@
 
 package oic.simulator.clientcontroller.listener;
 
+import org.oic.simulator.client.SimulatorRemoteResource.RequestType;
+
 import oic.simulator.clientcontroller.remoteresource.RemoteResource;
 
 /**
@@ -23,9 +25,12 @@ 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);
 }
index a2735c4..b47e793 100644 (file)
@@ -55,8 +55,9 @@ import org.oic.simulator.client.SimulatorRemoteResource.GetResponseListener;
 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;
@@ -438,12 +439,13 @@ public class ResourceManager {
                         // 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);
                     }
                 });
             }
@@ -461,12 +463,13 @@ public class ResourceManager {
                         // 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);
                     }
                 });
             }
@@ -483,12 +486,13 @@ public class ResourceManager {
                         // 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);
                     }
                 });
             }
@@ -514,7 +518,7 @@ public class ResourceManager {
         }
 
         resource.setResourceModelRef(resourceModelN);
-        resource.setResourceRepresentation(resourceModelN, false);
+        resource.setResourceRepresentation(resourceModelN);
 
         return resource;
     }
@@ -1390,7 +1394,7 @@ public class ResourceManager {
         return true;
     }
 
-    public void startAutomationRequest(VerificationType reqType,
+    public void startAutomationRequest(RequestType reqType,
             RemoteResource resource) {
         if (null == resource) {
             return;
@@ -1406,9 +1410,9 @@ public class ResourceManager {
         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);
@@ -1431,7 +1435,7 @@ public class ResourceManager {
         }
     }
 
-    public void stopAutomationRequest(VerificationType reqType,
+    public void stopAutomationRequest(RequestType reqType,
             RemoteResource resource) {
         if (null == resource) {
             return;
@@ -1441,10 +1445,10 @@ public class ResourceManager {
             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 {
@@ -1464,6 +1468,7 @@ public class ResourceManager {
 
     public boolean setConfigFilePath(RemoteResource resource,
             String configFilePath) throws SimulatorException {
+
         if (null == resource) {
             return false;
         }
@@ -1472,19 +1477,18 @@ public class ResourceManager {
             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()
@@ -1492,6 +1496,14 @@ public class ResourceManager {
                     .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);
index 9bf34f6..f17fe77 100644 (file)
@@ -4,6 +4,8 @@ import java.util.ArrayList;
 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;
@@ -268,7 +270,7 @@ public class UiListenerHandler {
     }
 
     public void verificationStartedNotification(RemoteResource resource,
-            int autoType) {
+            RequestType reqType) {
         synchronized (verificationUIListeners) {
             if (verificationUIListeners.size() > 0) {
                 IVerificationUIListener listener;
@@ -277,7 +279,7 @@ public class UiListenerHandler {
                 while (listenerItr.hasNext()) {
                     listener = listenerItr.next();
                     if (null != listener) {
-                        listener.onVerificationStarted(resource, autoType);
+                        listener.onVerificationStarted(resource, reqType);
                     }
                 }
             }
@@ -285,7 +287,7 @@ public class UiListenerHandler {
     }
 
     public void verificationAbortedNotification(RemoteResource resource,
-            int autoType) {
+            RequestType reqType) {
         synchronized (verificationUIListeners) {
             if (verificationUIListeners.size() > 0) {
                 IVerificationUIListener listener;
@@ -294,7 +296,7 @@ public class UiListenerHandler {
                 while (listenerItr.hasNext()) {
                     listener = listenerItr.next();
                     if (null != listener) {
-                        listener.onVerificationAborted(resource, autoType);
+                        listener.onVerificationAborted(resource, reqType);
                     }
                 }
             }
@@ -302,7 +304,7 @@ public class UiListenerHandler {
     }
 
     public void verificationCompletedNotification(RemoteResource resource,
-            int autoType) {
+            RequestType reqType) {
         synchronized (verificationUIListeners) {
             if (verificationUIListeners.size() > 0) {
                 IVerificationUIListener listener;
@@ -311,7 +313,7 @@ public class UiListenerHandler {
                 while (listenerItr.hasNext()) {
                     listener = listenerItr.next();
                     if (null != listener) {
-                        listener.onVerificationCompleted(resource, autoType);
+                        listener.onVerificationCompleted(resource, reqType);
                     }
                 }
             }
index c17c57e..c433d09 100644 (file)
@@ -177,8 +177,7 @@ public class AttributeElement {
         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;
 
@@ -192,7 +191,7 @@ public class AttributeElement {
                         .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,
@@ -213,7 +212,7 @@ public class 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(
@@ -233,7 +232,7 @@ public class 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(
@@ -253,7 +252,7 @@ public class 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(
@@ -264,16 +263,12 @@ public class 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());
             }
         }
     }
@@ -304,4 +299,113 @@ public class AttributeElement {
         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());
+        }
+    }
 }
index 4c7d6d5..9eeed04 100644 (file)
 
 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
@@ -27,24 +29,25 @@ import oic.simulator.clientcontroller.utils.Constants;
  */
 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;
@@ -54,6 +57,15 @@ public class RemoteResource {
         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;
     }
@@ -126,13 +138,13 @@ public class RemoteResource {
         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;
         }
     }
 
@@ -154,12 +166,11 @@ public class RemoteResource {
         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() {
index f2c3f18..7e36dea 100644 (file)
@@ -21,8 +21,10 @@ import java.util.Map;
 
 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>();
@@ -31,36 +33,82 @@ public class ResourceRepresentation {
         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;
index 7a3cca1..b12c0a7 100644 (file)
@@ -22,7 +22,7 @@ import org.oic.simulator.AttributeValue;
 
 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);
index 4f41e9c..1c3c839 100644 (file)
@@ -105,63 +105,22 @@ public class Utility {
         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() {
@@ -177,4 +136,22 @@ public class Utility {
         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
index 4c33cd8..0ad1227 100644 (file)
@@ -22,17 +22,23 @@ 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;
 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;
@@ -46,6 +52,7 @@ import oic.simulator.clientcontroller.remoteresource.RemoteResource;
 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
@@ -116,32 +123,60 @@ public class AttributeEditingSupport {
                 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
@@ -158,7 +193,33 @@ public class AttributeEditingSupport {
                 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) {
@@ -189,14 +250,45 @@ public class AttributeEditingSupport {
 
             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 {
@@ -221,6 +313,34 @@ public class AttributeEditingSupport {
             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) {
index 04ff981..24a2c28 100644 (file)
@@ -46,7 +46,7 @@ import org.oic.simulator.AttributeValue.ValueType;
 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;
@@ -228,13 +228,13 @@ public class AttributeView extends ViewPart {
 
             @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;
@@ -255,8 +255,7 @@ public class AttributeView extends ViewPart {
                                 .log(Level.INFO.ordinal(),
                                         new Date(),
                                         "["
-                                                + VerificationType.values()[autoType]
-                                                        .toString()
+                                                + reqType.toString()
                                                 + "] Verification Completed for \""
                                                 + remoteResource.getURI()
                                                 + "\".");
@@ -266,7 +265,7 @@ public class AttributeView extends ViewPart {
 
             @Override
             public void onVerificationAborted(final RemoteResource resource,
-                    final int autoType) {
+                    final RequestType reqType) {
 
                 if (null == resource) {
                     return;
@@ -287,8 +286,7 @@ public class AttributeView extends ViewPart {
                                 .log(Level.INFO.ordinal(),
                                         new Date(),
                                         "["
-                                                + VerificationType.values()[autoType]
-                                                        .toString()
+                                                + reqType
                                                 + "] Verification Aborted for \""
                                                 + remoteResource.getURI()
                                                 + "\".");
@@ -708,13 +706,13 @@ public class AttributeView extends ViewPart {
                                                 + "\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));
                                 }
                             }
@@ -725,7 +723,7 @@ public class AttributeView extends ViewPart {
         });
     }
 
-    private void automate(VerificationType type, boolean start) {
+    private void automate(RequestType type, boolean start) {
         if (start) {
             resourceManager.startAutomationRequest(type, resourceInSelection);
         } else {
@@ -853,9 +851,15 @@ public class AttributeView extends ViewPart {
                         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;
                     }
                 }
index 53ff50e..3d25093 100644 (file)
@@ -45,6 +45,7 @@ import java.util.Map;
 
 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;
@@ -139,6 +140,15 @@ public class PostRequestDialog extends TitleAreaDialog {
         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();
@@ -295,9 +305,15 @@ public class PostRequestDialog extends TitleAreaDialog {
                         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;
                     }
 
index 53eeaac..dbc8d4d 100644 (file)
@@ -45,6 +45,7 @@ import java.util.Map;
 
 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;
@@ -136,6 +137,15 @@ public class PutRequestDialog extends TitleAreaDialog {
         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();
@@ -268,9 +278,15 @@ public class PutRequestDialog extends TitleAreaDialog {
                         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;
                     }
                 }
diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java
new file mode 100644 (file)
index 0000000..1df6e5a
--- /dev/null
@@ -0,0 +1,277 @@
+/*
+ * 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;
+    }
+}
index e1a70cd..dd6b08f 100644 (file)
@@ -368,6 +368,13 @@ public class AttributeElement {
                     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);
             }
index 7c05136..38ac2c3 100644 (file)
@@ -22,7 +22,7 @@ import org.oic.simulator.AttributeValue;
 
 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);
index 03ddf8a..7fe5bb7 100644 (file)
@@ -462,63 +462,22 @@ public class Utility {
         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) {
@@ -561,4 +520,22 @@ public class Utility {
         }
         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
index af898e6..27fd7cb 100644 (file)
@@ -22,6 +22,7 @@ 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;
 import org.eclipse.swt.SWT;
@@ -30,6 +31,7 @@ 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 org.eclipse.ui.IPartListener2;
@@ -57,6 +59,7 @@ import oic.simulator.serviceprovider.model.SingleResource;
 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
@@ -219,39 +222,93 @@ public class AttributeEditingSupport {
                 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
@@ -268,7 +325,25 @@ public class AttributeEditingSupport {
                 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) {
@@ -291,10 +366,16 @@ public class AttributeEditingSupport {
                 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 {
@@ -319,8 +400,11 @@ public class AttributeEditingSupport {
                     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);
@@ -339,8 +423,11 @@ public class AttributeEditingSupport {
                                         (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",
index 56eac4b..48ac0a3 100644 (file)
@@ -428,9 +428,15 @@ public class AttributeView extends ViewPart {
                         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;
                     }
 
index 936df8f..56712dc 100644 (file)
@@ -253,11 +253,7 @@ public class MetaPropertiesView extends ViewPart {
                             } 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.");
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePrimitiveArrayAttributeDialog.java
new file mode 100644 (file)
index 0000000..4a3e9ff
--- /dev/null
@@ -0,0 +1,279 @@
+/*
+ * 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;
+    }
+}
index 926c93f..60b7349 100644 (file)
@@ -150,6 +150,10 @@ public class UpdateResourceInterfaceDialog extends TrayDialog {
                         return;
                     }
                     String ifType = addIfTypeDlg.getValue();
+                    if (null == ifType || ifType.isEmpty()) {
+                        return;
+                    }
+
                     ifTypesList.add(ifType);
                     ifTypesList.deselectAll();
                     ifTypesList.select(ifTypesList.getItemCount() - 1);
index efe406e..89f2dd6 100644 (file)
@@ -27,14 +27,6 @@ import org.oic.simulator.server.SimulatorResource;
  */
 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.
      *