Simulator Client controller plug-in changes:
authorG S Senthil Kumar <senthil.gs@samsung.com>
Tue, 13 Oct 2015 07:48:50 +0000 (13:18 +0530)
committerUze Choi <uzchoi@samsung.com>
Tue, 13 Oct 2015 09:34:02 +0000 (09:34 +0000)
1. Updated UI for finding resources: Removed standard/custom option,
   Included option to find all resources.
2. Changed the layout of UI for CRUDN operations.
3. Resolved a minor issue in favorite resources feature.
4. Updated the log view to show single line entries.

Change-Id: Ia1178177a9a4452cea00e8b78c2a98b20d1a8898
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3843
Reviewed-by: RadhaBhavani <radha.p@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Constants.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/AttributeView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/LogView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/FindResourcePage.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/logger/LogLabelProvider.java
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/logger/LoggerCallback.java

index c7d225fc91055304219aaa1e24a1978726119e4c..545f0a423d0c96f1293ffa854eb1b9f2114e46d3 100644 (file)
@@ -171,6 +171,15 @@ public class ResourceManager {
                         // Notify the UI listener
                         newResourceFoundNotification(resource);
 
+                        Activator
+                                .getDefault()
+                                .getLogManager()
+                                .log(Level.INFO.ordinal(),
+                                        new Date(),
+                                        "Resource Found ["
+                                                + resource.getResourceURI()
+                                                + "].");
+
                         // Send an initial GET request to get the resource
                         // attributes
                         try {
@@ -181,9 +190,8 @@ public class ResourceManager {
                                     .getLogManager()
                                     .log(Level.ERROR.ordinal(),
                                             new Date(),
-                                            "[" + e.getClass().getSimpleName()
-                                                    + "]" + e.code().toString()
-                                                    + "-" + e.message());
+                                            Utility.getSimulatorErrorString(e,
+                                                    null));
                         }
                     }
                 });
@@ -393,14 +401,10 @@ public class ResourceManager {
 
         resource.setResourceModel(resourceModelN);
         Map<String, RemoteResourceAttribute> attributeMap = fetchResourceAttributesFromModel(resourceModelN);
-
-        // TODO: For debugging
+        resource.setResourceAttributesMap(attributeMap);
+        // TODO: Printing the values for debugging
         if (null != attributeMap) {
             RemoteResourceAttribute.printAttributes(attributeMap);
-            System.out.println("Attributes found: " + (null != attributeMap));
-            System.out.println("No of attributes: " + attributeMap.size());
-
-            resource.setResourceAttributesMap(attributeMap);
         }
         return resource;
     }
@@ -545,7 +549,6 @@ public class ResourceManager {
         resource.setFavorite(true);
         synchronized (favoriteResources) {
             favoriteResources.add(resource);
-            favoriteURIList.add(resource.getResourceURI());
         }
     }
 
@@ -559,6 +562,15 @@ public class ResourceManager {
         }
     }
 
+    public void addResourceURItoFavorites(RemoteResource resource) {
+        if (null == resource) {
+            return;
+        }
+        synchronized (favoriteURIList) {
+            favoriteURIList.add(resource.getResourceURI());
+        }
+    }
+
     public void removeResourceURIFromFavorites(RemoteResource resource) {
         if (null == resource) {
             return;
@@ -671,11 +683,8 @@ public class ResourceManager {
                 Activator
                         .getDefault()
                         .getLogManager()
-                        .log(Level.ERROR.ordinal(),
-                                new Date(),
-                                "[" + e.getClass().getSimpleName() + "]"
-                                        + e.code().toString() + "-"
-                                        + e.message());
+                        .log(Level.ERROR.ordinal(), new Date(),
+                                Utility.getSimulatorErrorString(e, null));
                 return null;
             }
             if (null != attributeMapN) {
@@ -718,27 +727,6 @@ public class ResourceManager {
                                 }
                                 attribute.setAllowedValues(valueList);
                             }
-                            /*
-                             * Type baseType = attribute.getAttValBaseType();
-                             *
-                             * if(baseType == Type.INT) { //int[] values =
-                             * attributeN.getAllowedValues();
-                             * attribute.setAllowedValues
-                             * (attributeN.getAllowedValues()); } else
-                             * if(baseType == Type.DOUBLE) { double[] values =
-                             * attributeN.getAllowedValues();
-                             * attribute.setAllowedValues
-                             * (Utility.converArrayToList(values)); } else
-                             * if(baseType == Type.BOOL) { //boolean[] values =
-                             * attributeN.getAllowedValues(); List<Object> obj =
-                             * new ArrayList<Object>(); obj.add(true);
-                             * obj.add(false); attribute.setAllowedValues(obj);
-                             * } else if(baseType == Type.STRING) { String[]
-                             * values = attributeN.getAllowedValues();
-                             * attribute.
-                             * setAllowedValues(Utility.converArrayToList
-                             * (values)); }
-                             */
                         }
                         resourceAttributeMap.put(attName, attribute);
                     }
@@ -911,33 +899,6 @@ public class ResourceManager {
         }
     }
 
-    // TODO: Temporarily used to display the resource in the UI
-    public List<String> getURIList() {
-        List<String> list = new ArrayList<String>();
-        synchronized (resourceMap) {
-            /*
-             * Set<String> idSet = resourceMap.keySet(); Iterator<String> idItr
-             * = idSet.iterator(); String sId; RemoteResource resource;
-             * while(idItr.hasNext()) { sId = idItr.next(); resource =
-             * resourceMap.get(sId); if(null == resource) { continue; }
-             * list.add(resource.getResourceURI()); }
-             */
-            Set<String> uriSet = resourceMap.keySet();
-            Iterator<String> uriItr = uriSet.iterator();
-            String uri;
-            while (uriItr.hasNext()) {
-                uri = uriItr.next();
-                if (null != uri) {
-                    list.add(uri);
-                }
-            }
-
-            // Sort the types
-            Collections.sort(list);
-        }
-        return list;
-    }
-
     public synchronized Set<String> getLastKnownSearchTypes() {
         return lastKnownSearchTypes;
     }
@@ -948,45 +909,59 @@ public class ResourceManager {
     }
 
     public boolean findResourceRequest(Set<String> searchTypes) {
-        if (null == searchTypes || searchTypes.size() < 1) {
-            return false;
-        }
         boolean result = false;
-        Iterator<String> searchItr = searchTypes.iterator();
-        String rType;
-        while (searchItr.hasNext()) {
-            rType = searchItr.next();
+        if (null == searchTypes || searchTypes.size() < 1) {
             try {
-                SimulatorManager.findResource(rType, findResourceListener);
+                SimulatorManager.findResource(findResourceListener);
                 result = true;
             } catch (SimulatorException e) {
                 Activator
                         .getDefault()
                         .getLogManager()
-                        .log(Level.ERROR.ordinal(),
-                                new Date(),
-                                "[" + e.getClass().getSimpleName() + "]"
-                                        + e.code().toString() + "-"
-                                        + e.message());
+                        .log(Level.ERROR.ordinal(), new Date(),
+                                Utility.getSimulatorErrorString(e, null));
+            }
+        } else {
+            Iterator<String> searchItr = searchTypes.iterator();
+            String rType;
+            while (searchItr.hasNext()) {
+                rType = searchItr.next();
+                try {
+                    SimulatorManager.findResource(rType, findResourceListener);
+                    result = true;
+                } catch (SimulatorException e) {
+                    Activator
+                            .getDefault()
+                            .getLogManager()
+                            .log(Level.ERROR.ordinal(), new Date(),
+                                    Utility.getSimulatorErrorString(e, null));
+                }
             }
         }
         return result;
     }
 
     public void deleteResources(final Set<String> searchTypes) {
-        if (null == searchTypes || searchTypes.size() < 1) {
-            return;
-        }
         new Thread() {
             public void run() {
-                Iterator<String> typeItr = searchTypes.iterator();
-                String resType;
-                while (typeItr.hasNext()) {
-                    resType = typeItr.next();
-                    deleteResourcesByType(resType);
+                if (null == searchTypes || searchTypes.size() < 1) {
+                    // Delete all cached details of resources
+                    resourceMap.clear();
+                    favoriteResources.clear();
 
                     // Change the current resource in selection
-                    updateCurrentResourceInSelection(searchTypes);
+                    setCurrentResourceInSelection(null);
+                    resourceSelectionChangedUINotification(null);
+                } else {
+                    Iterator<String> typeItr = searchTypes.iterator();
+                    String resType;
+                    while (typeItr.hasNext()) {
+                        resType = typeItr.next();
+                        deleteResourcesByType(resType);
+
+                        // Change the current resource in selection
+                        updateCurrentResourceInSelection(searchTypes);
+                    }
                 }
             }
         }.start();
@@ -1040,10 +1015,10 @@ public class ResourceManager {
                 if (null != types) {
                     exist = types.contains(resourceType);
                     if (exist) {
-                        // Remove the resource
-                        keyItr.remove();
                         // Remove the resource from favorites list.
                         removeResourceFromFavorites(resource);
+                        // Remove the resource
+                        keyItr.remove();
                     }
                 }
             }
@@ -1116,13 +1091,6 @@ public class ResourceManager {
         return autoStatus;
     }
 
-    public Map<String, String> getDummyAttributes() {
-        Map<String, String> attributes = new HashMap<String, String>();
-        attributes.put("intensity", "1");
-        attributes.put("power", "off");
-        return attributes;
-    }
-
     public List<RemoteResource> getResourceList() {
         List<RemoteResource> resourceList = new ArrayList<RemoteResource>();
         synchronized (resourceMap) {
@@ -1190,10 +1158,8 @@ public class ResourceManager {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
         }
     }
 
@@ -1225,10 +1191,8 @@ public class ResourceManager {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
         }
         System.out.println("ResourceManager: called native put");
     }
@@ -1265,10 +1229,8 @@ public class ResourceManager {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
         }
     }
 
@@ -1298,17 +1260,16 @@ public class ResourceManager {
                     Activator
                             .getDefault()
                             .getLogManager()
-                            .log(Level.ERROR.ordinal(), new Date(),
-                                    e.getMessage());
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    Utility.getSimulatorErrorString(e,
+                                            "Failed to convert the attribute value."));
                 } catch (SimulatorException e) {
                     Activator
                             .getDefault()
                             .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
+                            .log(Level.ERROR.ordinal(), new Date(),
+                                    Utility.getSimulatorErrorString(e, null));
                 }
             } else if (attType == Type.DOUBLE) {
                 double attValue;
@@ -1319,17 +1280,16 @@ public class ResourceManager {
                     Activator
                             .getDefault()
                             .getLogManager()
-                            .log(Level.ERROR.ordinal(), new Date(),
-                                    e.getMessage());
+                            .log(Level.ERROR.ordinal(),
+                                    new Date(),
+                                    Utility.getSimulatorErrorString(e,
+                                            "Failed to convert the attribute value."));
                 } catch (SimulatorException e) {
                     Activator
                             .getDefault()
                             .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
+                            .log(Level.ERROR.ordinal(), new Date(),
+                                    Utility.getSimulatorErrorString(e, null));
                 }
             } else if (attType == Type.BOOL) {
                 boolean attValue;
@@ -1340,11 +1300,8 @@ public class ResourceManager {
                     Activator
                             .getDefault()
                             .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
+                            .log(Level.ERROR.ordinal(), new Date(),
+                                    Utility.getSimulatorErrorString(e, null));
                 }
             } else if (attType == Type.STRING) {
                 String attValue;
@@ -1355,11 +1312,8 @@ public class ResourceManager {
                     Activator
                             .getDefault()
                             .getLogManager()
-                            .log(Level.ERROR.ordinal(),
-                                    new Date(),
-                                    "[" + e.getClass().getSimpleName() + "]"
-                                            + e.code().toString() + "-"
-                                            + e.message());
+                            .log(Level.ERROR.ordinal(), new Date(),
+                                    Utility.getSimulatorErrorString(e, null));
                 }
             }
         }
@@ -1387,10 +1341,8 @@ public class ResourceManager {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
         }
         System.out.println("Observer called.");
     }
@@ -1413,10 +1365,8 @@ public class ResourceManager {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
         }
     }
 
@@ -1454,10 +1404,8 @@ public class ResourceManager {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
         }
     }
 
@@ -1486,10 +1434,8 @@ public class ResourceManager {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
         }
     }
 
@@ -1507,10 +1453,8 @@ public class ResourceManager {
             Activator
                     .getDefault()
                     .getLogManager()
-                    .log(Level.ERROR.ordinal(),
-                            new Date(),
-                            "[" + e.getClass().getSimpleName() + "]"
-                                    + e.code().toString() + "-" + e.message());
+                    .log(Level.ERROR.ordinal(), new Date(),
+                            Utility.getSimulatorErrorString(e, null));
             return;
         }
         // Update the status
index 27cbdc8391e9adfaa83d7a4b244b15a03dd1954d..8a908cc2aa9c5088d72a91ec1636ae6b6cb94c27 100644 (file)
@@ -152,6 +152,7 @@ public class RemoteResourceAttribute {
         return valueList;
     }
 
+    // Method added for debugging purpose
     public static void printAttributes(
             Map<String, RemoteResourceAttribute> attributeMap) {
         Iterator<String> itr = attributeMap.keySet().iterator();
index 3fe81ac214eb4ff39951a4780b220ed3f66f943c..53e73e5ed94ccd97c1944f6cab6d2fd3a76f1fa6 100644 (file)
@@ -51,6 +51,8 @@ public class Constants {
     public static final String         GET                           = "Get";
     public static final String         PUT                           = "Put";
     public static final String         POST                          = "Post";
+    public static final String         OBSERVE                       = "Observe";
+    public static final String         STOP_OBSERVE                  = "Stop Observe";
 
     public static final String         ENABLE                        = "Enable";
     public static final String         DISABLE                       = "Disable";
index 8baed7cd07efc0df3e961301ec87765f74a961f4..254f1f876c44070446e1f47fc032fb23a44a5b09 100644 (file)
 package oic.simulator.clientcontroller.utils;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
+import org.oic.simulator.SimulatorException;
+
 /**
  * This class has common utility methods.
  */
@@ -55,25 +58,39 @@ public class Utility {
         return strArr;
     }
 
-    /*
-     * public static List<Object> converArrayToList(int[] arr) { if(null == arr
-     * || arr.length < 1) { return null; } List<Object> valueList = new
-     * ArrayList<Object>(); for(Object val:arr) { valueList.add(val); } return
-     * valueList; }
-     * 
-     * public static List<Object> converArrayToList(double[] arr) { if(null ==
-     * arr || arr.length < 1) { return null; } List<Object> valueList = new
-     * ArrayList<Object>(); for(Object val:arr) { valueList.add(val); } return
-     * valueList; }
-     * 
-     * public static List<Object> converArrayToList(boolean[] arr) { if(null ==
-     * arr || arr.length < 1) { return null; } List<Object> valueList = new
-     * ArrayList<Object>(); for(Object val:arr) { valueList.add(val); } return
-     * valueList; }
-     * 
-     * public static List<Object> converArrayToList(String[] arr) { if(null ==
-     * arr || arr.length < 1) { return null; } List<Object> valueList = new
-     * ArrayList<Object>(); for(Object val:arr) { valueList.add(val); } return
-     * valueList; }
-     */
+    public static Set<String> splitStringByComma(String text) {
+        Set<String> tokenSet = null;
+        if (null != text) {
+            String[] token = text.split(",");
+            if (null != token) {
+                tokenSet = new HashSet<String>();
+                for (String tok : token) {
+                    tok = tok.trim();
+                    if (tok.length() > 0) {
+                        tokenSet.add(tok);
+                    }
+                }
+            }
+        }
+        return tokenSet;
+    }
+
+    public static String getSimulatorErrorString(Exception e, String info) {
+        if (null == e) {
+            return null;
+        }
+        String detail;
+        if (e instanceof SimulatorException) {
+            SimulatorException simEx = (SimulatorException) e;
+            detail = simEx.message() + "\n";
+            detail += "Exception Type: " + simEx.getClass().getSimpleName()
+                    + "\n";
+            detail += "Error code: " + simEx.code().toString();
+        } else {
+            detail = info + "\n";
+            detail += "Exception Type: " + e.getClass().getSimpleName() + "\n";
+            detail += "Message: " + e.getMessage();
+        }
+        return detail;
+    }
 }
\ No newline at end of file
index 255d9f1f32d9a0c52b25ef9a06acb8fd5df3e5ea..af503cef69720c057515f87122ceb26b64387b72 100644 (file)
@@ -268,7 +268,7 @@ public class AttributeView extends ViewPart {
 
                     @Override
                     public void run() {
-                        changeReqBtnVisibility(autoType, false);
+                        // changeReqBtnVisibility(autoType, false);
                     }
                 });
             }
@@ -280,7 +280,7 @@ public class AttributeView extends ViewPart {
 
                     @Override
                     public void run() {
-                        changeReqBtnVisibility(autoType, true);
+                        // changeReqBtnVisibility(autoType, true);
                     }
                 });
             }
@@ -292,7 +292,7 @@ public class AttributeView extends ViewPart {
 
                     @Override
                     public void run() {
-                        changeReqBtnVisibility(autoType, true);
+                        // changeReqBtnVisibility(autoType, true);
                     }
                 });
             }
@@ -370,12 +370,14 @@ public class AttributeView extends ViewPart {
     }
 
     private void updateObserve(RemoteResource resource) {
-        if (null == resource) {
+        if (null == resource || observeResButton.isDisposed()) {
             return;
         }
         boolean observed = resource.isObserved();
-        if (!observeResButton.isDisposed()) {
-            observeResButton.setSelection(observed);
+        if (observed) {
+            observeResButton.setText(Constants.STOP_OBSERVE);
+        } else {
+            observeResButton.setText(Constants.OBSERVE);
         }
     }
 
@@ -383,7 +385,7 @@ public class AttributeView extends ViewPart {
     public void createPartControl(Composite parent) {
         Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
 
-        parent.setLayout(new GridLayout(2, false));
+        parent.setLayout(new GridLayout());
         GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
         parent.setLayoutData(gd);
 
@@ -402,9 +404,7 @@ public class AttributeView extends ViewPart {
 
         setupAttributeTable(attGroup);
 
-        setupMessageArea(parent);
-
-        setupResourceLevelOpsArea(parent);
+        setupRequestControls(parent);
 
         setUIListeners();
 
@@ -419,20 +419,19 @@ public class AttributeView extends ViewPart {
         }
     }
 
-    private void setupMessageArea(Composite parent) {
+    private void setupRequestControls(Composite parent) {
         GridData gd;
         Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
-        Group msgTypesGrp = new Group(parent, SWT.NONE);
+        Composite opsComp = new Composite(parent, SWT.NONE);
         gd = new GridData();
         gd.grabExcessHorizontalSpace = true;
         gd.horizontalAlignment = SWT.FILL;
-        msgTypesGrp.setLayoutData(gd);
-        GridLayout grid = new GridLayout(3, false);
-        msgTypesGrp.setLayout(grid);
-        msgTypesGrp.setText("Request Types");
-        msgTypesGrp.setBackground(color);
+        opsComp.setLayoutData(gd);
+        GridLayout grid = new GridLayout(5, false);
+        opsComp.setLayout(grid);
+        opsComp.setBackground(color);
 
-        getButton = new Button(msgTypesGrp, SWT.PUSH);
+        getButton = new Button(opsComp, SWT.PUSH);
         getButton.setText("GET");
         gd = new GridData();
         gd.grabExcessHorizontalSpace = true;
@@ -440,7 +439,7 @@ public class AttributeView extends ViewPart {
         gd.widthHint = 50;
         getButton.setLayoutData(gd);
 
-        putButton = new Button(msgTypesGrp, SWT.PUSH);
+        putButton = new Button(opsComp, SWT.PUSH);
         putButton.setText("PUT");
         gd = new GridData();
         gd.grabExcessHorizontalSpace = true;
@@ -448,41 +447,27 @@ public class AttributeView extends ViewPart {
         gd.widthHint = 50;
         putButton.setLayoutData(gd);
 
-        postButton = new Button(msgTypesGrp, SWT.PUSH);
+        postButton = new Button(opsComp, SWT.PUSH);
         postButton.setText("POST");
         gd = new GridData();
         gd.grabExcessHorizontalSpace = true;
         gd.horizontalAlignment = SWT.FILL;
         gd.widthHint = 50;
         postButton.setLayoutData(gd);
-    }
 
-    private void setupResourceLevelOpsArea(Composite parent) {
-        GridData gd;
-        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
-        Group resOpsGrp = new Group(parent, SWT.NONE);
+        observeResButton = new Button(opsComp, SWT.PUSH);
+        observeResButton.setText(Constants.OBSERVE);
         gd = new GridData();
         gd.grabExcessHorizontalSpace = true;
         gd.horizontalAlignment = SWT.FILL;
-        resOpsGrp.setLayoutData(gd);
-        GridLayout grid = new GridLayout(2, false);
-        resOpsGrp.setLayout(grid);
-        resOpsGrp.setText("Resource-Level Operations");
-        resOpsGrp.setBackground(color);
+        observeResButton.setLayoutData(gd);
 
-        automateButton = new Button(resOpsGrp, SWT.PUSH);
+        automateButton = new Button(opsComp, SWT.PUSH);
         automateButton.setText("Automation");
         gd = new GridData();
         gd.grabExcessHorizontalSpace = true;
         gd.horizontalAlignment = SWT.FILL;
         automateButton.setLayoutData(gd);
-
-        observeResButton = new Button(resOpsGrp, SWT.CHECK);
-        observeResButton.setText("Observe");
-        gd = new GridData();
-        gd.grabExcessHorizontalSpace = true;
-        gd.horizontalAlignment = SWT.FILL;
-        observeResButton.setLayoutData(gd);
     }
 
     private void setupAttributeTable(Group attGroup) {
@@ -631,12 +616,13 @@ public class AttributeView extends ViewPart {
         observeResButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                boolean checked = observeResButton.getSelection();
-                if (checked) {
+                if (observeResButton.getText().equals(Constants.OBSERVE)) {
                     resourceManager.sendObserveRequest(resourceInSelection);
+                    observeResButton.setText(Constants.STOP_OBSERVE);
                 } else {
                     resourceManager
                             .sendCancelObserveRequest(resourceInSelection);
+                    observeResButton.setText(Constants.OBSERVE);
                 }
             }
         });
index 3c4d76eb4d0e1580b2d78b0d5a6a91c2e17af9ff..a2a7d2e53197a734ca37033d2e1c941da4afa346 100644 (file)
@@ -21,6 +21,7 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 
@@ -444,7 +445,13 @@ public class LogView extends ViewPart {
                             out.close();
                         }
                     } catch (IOException e) {
-                        System.out.println("Error occurred during close.");
+                        Activator
+                                .getDefault()
+                                .getLogManager()
+                                .log(Level.ERROR.ordinal(),
+                                        new Date(),
+                                        "[" + e.getClass().getSimpleName()
+                                                + "]" + e.getMessage());
                     }
                 }
             }
index 2082a42f74b2a95cae6ee81a56bfc14de0c1dfe6..8652adbb6915c66d1dc697a1ae9989c263f4d3e7 100644 (file)
@@ -97,7 +97,6 @@ public class ResourceManagerView extends ViewPart {
 
             @Override
             public void onNewResourceFound(final RemoteResource resource) {
-                System.out.println("View: onNewResourceFound");
                 if (null == resource) {
                     return;
                 }
@@ -123,16 +122,12 @@ public class ResourceManagerView extends ViewPart {
 
                         // Close the find dialog
                         if (null != findDialog) {
-                            boolean status = findDialog.close();
-                            System.out
-                                    .println("dialog close status: " + status);
+                            findDialog.close();
                         }
 
                         // Close the refresh dialog
                         if (null != refreshDialog) {
-                            boolean status = refreshDialog.close();
-                            System.out
-                                    .println("dialog close status: " + status);
+                            refreshDialog.close();
                         }
                     }
                 });
@@ -182,11 +177,6 @@ public class ResourceManagerView extends ViewPart {
         folder.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                /*
-                 * CTabItem selectedTab = folder.getSelection(); if(selectedTab
-                 * == foundResTab) { System.out.println("Found resources tab");
-                 * } else { System.out.println("Favorite resources tab"); }
-                 */
                 // Tab is switched.
                 treeViewer.setSelection(null);
                 favTreeViewer.setSelection(null);
@@ -355,11 +345,11 @@ public class ResourceManagerView extends ViewPart {
                                         if (null == resource) {
                                             return;
                                         }
-                                        System.out.println("Selected resource:"
-                                                + resource.getResourceURI());
                                         if (!resource.isFavorite()) {
                                             resourceManager
                                                     .addResourcetoFavorites(resource);
+                                            resourceManager
+                                                    .addResourceURItoFavorites(resource);
                                         } else {
                                             resourceManager
                                                     .removeResourceFromFavorites(resource);
@@ -467,38 +457,37 @@ public class ResourceManagerView extends ViewPart {
 
                             Set<String> searchTypes = findWizard
                                     .getSearchTypes();
-                            if (null != searchTypes) {
-                                System.out.println(searchTypes);
-                                // Call native method to clear existing
-                                // resources of
-                                // the given search types.
-                                resourceManager.deleteResources(searchTypes);
-
-                                // Update the tree
-                                treeViewer.refresh();
-                                favTreeViewer.refresh();
-
-                                // Call native method to find Resources
-                                boolean result = resourceManager
-                                        .findResourceRequest(searchTypes);
-                                if (result) {
-                                    searchUIOperation(false);
-                                } else {
-                                    MessageDialog
-                                            .openError(Display.getDefault()
-                                                    .getActiveShell(),
-                                                    "Find Resource status",
-                                                    "Operation failed due to some problems in core layer.");
-                                }
-
-                                // Store this information for refresh
-                                // functionality
-                                resourceManager
-                                        .setLastKnownSearchTypes(searchTypes);
+                            // Delete cached details of resources based on the
+                            // given search types.
+                            // If there are no resource types to search, then
+                            // all resources
+                            // will be deleted.
+                            resourceManager.deleteResources(searchTypes);
+
+                            // Update the tree
+                            treeViewer.refresh();
+                            favTreeViewer.refresh();
 
-                                // Change the refresh visibility
-                                refreshButton.setEnabled(true);
+                            // Call native method to find Resources
+                            boolean result = resourceManager
+                                    .findResourceRequest(searchTypes);
+                            if (result) {
+                                searchUIOperation(false);
+                            } else {
+                                MessageDialog
+                                        .openError(Display.getDefault()
+                                                .getActiveShell(),
+                                                "Find Resource status",
+                                                "Operation failed due to some problems in core layer.");
                             }
+
+                            // Store this information for refresh
+                            // functionality
+                            resourceManager
+                                    .setLastKnownSearchTypes(searchTypes);
+
+                            // Change the refresh visibility
+                            refreshButton.setEnabled(true);
                         }
                     }
                 });
@@ -510,13 +499,12 @@ public class ResourceManagerView extends ViewPart {
             public void widgetSelected(SelectionEvent e) {
                 Set<String> searchTypes = resourceManager
                         .getLastKnownSearchTypes();
-                if (null == searchTypes) {
-                    return;
-                }
                 setFoundResource(false);
 
-                // Call native method to clear existing resources of the given
-                // search types.
+                // Delete cached details of resources based on the given search
+                // types.
+                // If there are no resource types to search, then all resources
+                // will be deleted.
                 resourceManager.deleteResources(searchTypes);
 
                 // Update the tree
@@ -554,8 +542,6 @@ public class ResourceManagerView extends ViewPart {
                     if (null == resource) {
                         return;
                     }
-                    System.out.println("Selected resource: "
-                            + resource.getResourceURI());
                     resourceManager.resourceSelectionChanged(resource);
                 }
             }
@@ -608,7 +594,6 @@ public class ResourceManagerView extends ViewPart {
                         try {
                             Thread.sleep(Constants.FIND_RESOURCES_TIMEOUT * 1000);
                         } catch (InterruptedException e) {
-                            System.out.println("Interrupted during sleep.");
                             return;
                         }
 
@@ -695,7 +680,6 @@ class TreeContentProvider implements ITreeContentProvider {
 
     @Override
     public Object[] getElements(Object parent) {
-        System.out.println("Inside getElements()");
         List<RemoteResource> resourceList = Activator.getDefault()
                 .getResourceManager().getResourceList();
         return resourceList.toArray();
@@ -731,7 +715,6 @@ class FavTreeContentProvider implements ITreeContentProvider {
 
     @Override
     public Object[] getElements(Object parent) {
-        System.out.println("Inside getElements()");
         List<RemoteResource> resourceList = Activator.getDefault()
                 .getResourceManager().getFavResourceList();
         return resourceList.toArray();
index d851d11cd63ec311bd516db711d1b2e38fb4afb4..379161ff637e49ed16ee1d655a552947eb632184 100644 (file)
 
 package oic.simulator.clientcontroller.view.dialogs;
 
-import java.util.HashSet;
 import java.util.Set;
 
 import oic.simulator.clientcontroller.utils.Constants;
+import oic.simulator.clientcontroller.utils.Utility;
 
 import org.eclipse.jface.wizard.WizardPage;
 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.events.SelectionAdapter;
@@ -41,17 +40,13 @@ import org.eclipse.swt.widgets.Text;
  */
 public class FindResourcePage extends WizardPage {
 
-    private Button      stdResTypeRbtn;
-    private CCombo      resourceTypeCmb;
-    private Button      cusResTypeRbtn;
+    private Button      allRbtn;
+    private Button      resTypeRbtn;
     private Text        resTypeTxt;
-    private Label       stdRTypeLbl;
-    private Label       cusRTypeLbl;
+    private Label       resTypeLbl;
 
     private Set<String> typesToSearch;
 
-    private String      dummyRType;
-
     protected FindResourcePage() {
         super("Find Resource");
     }
@@ -69,7 +64,7 @@ public class FindResourcePage extends WizardPage {
         compContent.setLayoutData(gd);
 
         Group configGroup = new Group(compContent, SWT.NONE);
-        gridLayout = new GridLayout(1, false);
+        gridLayout = new GridLayout(2, false);
         gridLayout.verticalSpacing = 10;
         gridLayout.marginTop = 5;
         configGroup.setLayout(gridLayout);
@@ -79,41 +74,25 @@ public class FindResourcePage extends WizardPage {
         configGroup.setLayoutData(gd);
         configGroup.setText("Resource Type");
 
-        stdResTypeRbtn = new Button(configGroup, SWT.RADIO);
-        stdResTypeRbtn.setText("Standard OIC Resources");
-
-        Composite stdConfigComp = new Composite(configGroup, SWT.NONE);
-        stdConfigComp.setLayout(new GridLayout(2, false));
+        allRbtn = new Button(configGroup, SWT.RADIO);
+        allRbtn.setText("All");
         gd = new GridData();
-        gd.horizontalAlignment = SWT.FILL;
-        gd.grabExcessHorizontalSpace = true;
-        stdConfigComp.setLayoutData(gd);
-
-        stdRTypeLbl = new Label(stdConfigComp, SWT.NONE);
-        stdRTypeLbl.setText("ResourceType:");
-        stdRTypeLbl.setEnabled(false);
+        gd.horizontalSpan = 2;
+        allRbtn.setLayoutData(gd);
 
-        resourceTypeCmb = new CCombo(stdConfigComp, SWT.READ_ONLY | SWT.BORDER);
+        resTypeRbtn = new Button(configGroup, SWT.RADIO);
+        resTypeRbtn.setText("Specific Resource types (seperated by commas)");
         gd = new GridData();
-        gd.widthHint = 150;
-        resourceTypeCmb.setLayoutData(gd);
-        resourceTypeCmb.setEnabled(false);
+        gd.horizontalSpan = 2;
+        resTypeRbtn.setLayoutData(gd);
 
-        cusResTypeRbtn = new Button(configGroup, SWT.RADIO);
-        cusResTypeRbtn.setText("Custom Resources");
+        resTypeLbl = new Label(configGroup, SWT.NONE);
+        resTypeLbl.setText("Resource Types:");
+        resTypeLbl.setEnabled(false);
 
-        Composite cusConfigComp = new Composite(configGroup, SWT.NONE);
-        cusConfigComp.setLayout(new GridLayout(2, false));
-        gd = new GridData();
-        gd.horizontalAlignment = SWT.FILL;
-        gd.grabExcessHorizontalSpace = true;
-        cusConfigComp.setLayoutData(gd);
-
-        cusRTypeLbl = new Label(cusConfigComp, SWT.NONE);
-        cusRTypeLbl.setText("Enter ResourceType:");
-        cusRTypeLbl.setEnabled(false);
-
-        resTypeTxt = new Text(cusConfigComp, SWT.BORDER);
+        resTypeTxt = new Text(configGroup, SWT.BORDER);
+        resTypeTxt.setToolTipText("Ex: sample.light, hall.fridge");
+        resTypeTxt.setMessage("Ex: sample.light, hall.fridge");
         gd = new GridData();
         gd.minimumWidth = 200;
         gd.horizontalAlignment = SWT.FILL;
@@ -121,142 +100,58 @@ public class FindResourcePage extends WizardPage {
         resTypeTxt.setLayoutData(gd);
         resTypeTxt.setEnabled(false);
 
-        populateDataInUI();
-
         addUIListeners();
 
         setControl(compContent);
     }
 
-    private void populateDataInUI() {
-        // Populate Standard resource-types in Combo
-        populateResourceTypeCombo();
-    }
-
-    private void populateResourceTypeCombo() {
-        /*
-         * List<String> configList; configList =
-         * Activator.getDefault().getManager().getResourceConfigurationList();
-         * if(null != configList) { Iterator<String> itr =
-         * configList.iterator(); while(itr.hasNext()) {
-         * resourceTypeCmb.add(itr.next()); } }
-         */
-
-        // TODO: Temporarily adding a resourceType for testing
-        resourceTypeCmb.add("oic.r.light");
-       // resourceTypeCmb.add("sample.light");
-
-        // By default, selecting the first item in the resourceType combo
-        if (resourceTypeCmb.getItemCount() > 0) {
-            resourceTypeCmb.select(0);
-            // TODO: Get the RAML configuration file path of the selected
-            // resource
-            // configFilePath =
-            // Activator.getManager().getConfigFilePath(resourceTypeCmb.getItem(0));
-        }
-    }
-
     private void addUIListeners() {
-        stdResTypeRbtn.addSelectionListener(new SelectionAdapter() {
+        allRbtn.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                // Clear the existing items from the search list
-                if (null != typesToSearch)
-                    typesToSearch.clear();
-
-                // Set the configFilePath to the first item in the combo
-                if (resourceTypeCmb.getItemCount() > 0) {
-                    resourceTypeCmb.select(0);
-                    addSearchType(resourceTypeCmb.getText());
-                }
-
-                setPageComplete(isSelectionDone());
-
+                typesToSearch = null;
+                setPageComplete(true);
                 // Change the visibility of widgets
-                changeVisibility(true);
+                changeVisibility(false);
             }
         });
 
-        cusResTypeRbtn.addSelectionListener(new SelectionAdapter() {
+        resTypeRbtn.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                // Clear the existing items from the search list
-                if (null != typesToSearch)
-                    typesToSearch.clear();
-
-                addSearchType(resTypeTxt.getText());
-
-                setPageComplete(isSelectionDone());
+                String typeText = resTypeTxt.getText();
+                if (null != typeText && typeText.length() > 0) {
+                    typesToSearch = Utility.splitStringByComma(typeText);
+                }
 
+                if (null != typesToSearch && typesToSearch.size() > 0) {
+                    setPageComplete(true);
+                } else {
+                    setPageComplete(false);
+                }
                 // Change the visibility of widgets
-                changeVisibility(false);
-
+                changeVisibility(true);
                 resTypeTxt.setFocus();
             }
         });
 
-        resourceTypeCmb.addSelectionListener(new SelectionAdapter() {
-            @Override
-            public void widgetSelected(SelectionEvent e) {
-                int index = resourceTypeCmb.getSelectionIndex();
-                if (index < 0) {
-                    return;
-                }
-                String resourceType = resourceTypeCmb.getItem(index);
-                addSearchType(resourceType);
-                setPageComplete(isSelectionDone());
-            }
-        });
-
         resTypeTxt.addModifyListener(new ModifyListener() {
             @Override
             public void modifyText(ModifyEvent e) {
-                String resourceType = resTypeTxt.getText();
-                if (null != dummyRType) {
-                    removeSearchType(dummyRType);
+                String typeText = resTypeTxt.getText();
+                typesToSearch = Utility.splitStringByComma(typeText);
+                if (null != typesToSearch && typesToSearch.size() > 0) {
+                    setPageComplete(true);
+                } else {
+                    setPageComplete(false);
                 }
-                dummyRType = resourceType;
-                addSearchType(resourceType);
-                setPageComplete(isSelectionDone());
             }
         });
     }
 
     private void changeVisibility(boolean standard) {
-        stdRTypeLbl.setEnabled(standard);
-        resourceTypeCmb.setEnabled(standard);
-        cusRTypeLbl.setEnabled(!standard);
-        resTypeTxt.setEnabled(!standard);
-    }
-
-    private boolean isSelectionDone() {
-        if (null == typesToSearch || typesToSearch.size() < 1) {
-            return false;
-        }
-        return true;
-    }
-
-    private void addSearchType(String resourceType) {
-        if (null == resourceType)
-            return;
-        resourceType = resourceType.trim();
-        if (resourceType.length() < 1) {
-            return;
-        }
-        if (null == typesToSearch) {
-            typesToSearch = new HashSet<String>();
-        }
-        typesToSearch.add(resourceType);
-    }
-
-    private void removeSearchType(String resourceType) {
-        if (null == resourceType || null == typesToSearch)
-            return;
-        resourceType = resourceType.trim();
-        if (resourceType.length() < 1) {
-            return;
-        }
-        typesToSearch.remove(resourceType);
+        resTypeLbl.setEnabled(standard);
+        resTypeTxt.setEnabled(standard);
     }
 
     public Set<String> getSearchTypes() {
index ca80ad1f4c09133acce3820ef842b77a57ea1db7..d2abfbb8e0ed40cc5be2d45c3f1f85358b4dbcbc 100644 (file)
@@ -50,7 +50,12 @@ public class LogLabelProvider extends LabelProvider implements
         } else if (columnIndex == 1) {
             return dateFormat.format(entry.getDate());
         } else {
-            return entry.getMessage();
+            String msg = entry.getMessage();
+            int pos = msg.indexOf('\n');
+            if (pos != -1) {
+                msg = msg.substring(0, pos);
+            }
+            return msg;
         }
     }
 
index 81110b07609857bf386e6c876d88722ac1f56ac1..ac2e8ed30963c76b3c95276007cfa588673142d1 100644 (file)
@@ -58,7 +58,7 @@ public class LoggerCallback implements ILogger {
 
                 Calendar calendar;
                 calendar = Calendar.getInstance();
-                calendar.set(Calendar.HOUR, h);
+                calendar.set(Calendar.HOUR_OF_DAY, h);
                 calendar.set(Calendar.MINUTE, m);
                 calendar.set(Calendar.SECOND, s);