From 48e78b6725bb3d9e6862ce62d7439bd81f09baa1 Mon Sep 17 00:00:00 2001 From: G S Senthil Kumar Date: Tue, 13 Oct 2015 13:18:50 +0530 Subject: [PATCH] Simulator Client controller plug-in changes: 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/3843 Reviewed-by: RadhaBhavani Reviewed-by: Uze Choi Tested-by: Uze Choi --- .../clientcontroller/manager/ResourceManager.java | 244 ++++++++------------- .../remoteresource/RemoteResourceAttribute.java | 1 + .../clientcontroller/utils/Constants.java | 2 + .../simulator/clientcontroller/utils/Utility.java | 59 +++-- .../clientcontroller/view/AttributeView.java | 66 +++--- .../simulator/clientcontroller/view/LogView.java | 9 +- .../clientcontroller/view/ResourceManagerView.java | 91 ++++---- .../view/dialogs/FindResourcePage.java | 189 ++++------------ .../src/oic/simulator/logger/LogLabelProvider.java | 7 +- .../src/oic/simulator/logger/LoggerCallback.java | 2 +- 10 files changed, 255 insertions(+), 415 deletions(-) diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java index c7d225f..545f0a4 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java @@ -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 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 obj = - * new ArrayList(); 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 getURIList() { - List list = new ArrayList(); - synchronized (resourceMap) { - /* - * Set idSet = resourceMap.keySet(); Iterator 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 uriSet = resourceMap.keySet(); - Iterator 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 getLastKnownSearchTypes() { return lastKnownSearchTypes; } @@ -948,45 +909,59 @@ public class ResourceManager { } public boolean findResourceRequest(Set searchTypes) { - if (null == searchTypes || searchTypes.size() < 1) { - return false; - } boolean result = false; - Iterator 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 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 searchTypes) { - if (null == searchTypes || searchTypes.size() < 1) { - return; - } new Thread() { public void run() { - Iterator 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 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 getDummyAttributes() { - Map attributes = new HashMap(); - attributes.put("intensity", "1"); - attributes.put("power", "off"); - return attributes; - } - public List getResourceList() { List resourceList = new ArrayList(); 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 diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java index 27cbdc8..8a908cc 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java @@ -152,6 +152,7 @@ public class RemoteResourceAttribute { return valueList; } + // Method added for debugging purpose public static void printAttributes( Map attributeMap) { Iterator itr = attributeMap.keySet().iterator(); diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Constants.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Constants.java index 3fe81ac..53e73e5 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Constants.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Constants.java @@ -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"; diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java index 8baed7c..254f1f8 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java @@ -17,10 +17,13 @@ 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 converArrayToList(int[] arr) { if(null == arr - * || arr.length < 1) { return null; } List valueList = new - * ArrayList(); for(Object val:arr) { valueList.add(val); } return - * valueList; } - * - * public static List converArrayToList(double[] arr) { if(null == - * arr || arr.length < 1) { return null; } List valueList = new - * ArrayList(); for(Object val:arr) { valueList.add(val); } return - * valueList; } - * - * public static List converArrayToList(boolean[] arr) { if(null == - * arr || arr.length < 1) { return null; } List valueList = new - * ArrayList(); for(Object val:arr) { valueList.add(val); } return - * valueList; } - * - * public static List converArrayToList(String[] arr) { if(null == - * arr || arr.length < 1) { return null; } List valueList = new - * ArrayList(); for(Object val:arr) { valueList.add(val); } return - * valueList; } - */ + public static Set splitStringByComma(String text) { + Set tokenSet = null; + if (null != text) { + String[] token = text.split(","); + if (null != token) { + tokenSet = new HashSet(); + 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 diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java index 255d9f1..af503ce 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java @@ -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); } } }); diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/LogView.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/LogView.java index 3c4d76e..a2a7d2e 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/LogView.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/LogView.java @@ -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()); } } } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java index 2082a42..8652adb 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java @@ -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 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 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 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 resourceList = Activator.getDefault() .getResourceManager().getFavResourceList(); return resourceList.toArray(); diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/FindResourcePage.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/FindResourcePage.java index d851d11..379161f 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/FindResourcePage.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/FindResourcePage.java @@ -16,14 +16,13 @@ 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 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 configList; configList = - * Activator.getDefault().getManager().getResourceConfigurationList(); - * if(null != configList) { Iterator 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(); - } - 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 getSearchTypes() { diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/logger/LogLabelProvider.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/logger/LogLabelProvider.java index ca80ad1..d2abfbb 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/logger/LogLabelProvider.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/logger/LogLabelProvider.java @@ -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; } } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/logger/LoggerCallback.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/logger/LoggerCallback.java index 81110b0..ac2e8ed 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/logger/LoggerCallback.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/logger/LoggerCallback.java @@ -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); -- 2.7.4