From 1c7e1fdb397d388e36851f070673342d51557fdc Mon Sep 17 00:00:00 2001 From: G S Senthil Kumar Date: Fri, 4 Sep 2015 17:27:21 +0530 Subject: [PATCH] Performed refactoring and code cleanup on service provider plug-in. 1. Removed unnecessary data duplication. 2. Combined together all image/icon related code into a single ImageManager class. 3. Removed unnecessary console log. Change-Id: Iaa9e8b319cdff13468b230aa6fe46f490264bc90 Signed-off-by: G S Senthil Kumar Reviewed-on: https://gerrit.iotivity.org/gerrit/2379 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- .../ServiceProviderPlugin/README.txt | 2 +- .../oic/simulator/serviceprovider/Activator.java | 18 +- .../listener/IResourceModelChangedUIListener.java | 2 +- .../serviceprovider/manager/ImageManager.java | 64 +++++++ .../serviceprovider/manager/LogManager.java | 17 -- .../serviceprovider/manager/ResourceManager.java | 196 ++++++++++----------- .../{view/dialogs => resource}/DeleteCategory.java | 2 +- .../resource/LocalResourceAttribute.java | 141 ++++----------- .../resource/ModelChangeNotificationType.java | 2 +- .../resource/StandardConfiguration.java | 13 +- .../simulator/serviceprovider/utils/Constants.java | 9 +- .../view/AttributeEditingSupport.java | 14 +- .../serviceprovider/view/AttributeView.java | 43 ++--- .../serviceprovider/view/MetaPropertiesView.java | 20 +-- .../serviceprovider/view/ResourceManagerView.java | 8 +- .../serviceprovider/view/ResourceObserverView.java | 60 +++---- .../view/dialogs/CreateResourcePage.java | 9 +- .../view/dialogs/DeleteResourcePage.java | 5 +- .../view/dialogs/DeleteResourceWizard.java | 1 + 19 files changed, 276 insertions(+), 350 deletions(-) create mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java rename service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/{view/dialogs => resource}/DeleteCategory.java (53%) diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/README.txt b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/README.txt index 39dc7af..d4a7bdb 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/README.txt +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/README.txt @@ -10,7 +10,7 @@ Pre-requisites 3.Import the Simulator Java SDK project from ~/iotivity/service/simulator/java/sdk/ into Eclipse IDE as given below. File -> Import -> Select 'Existing projects into Workspace' under General category -> click next -> Browse to the above mentioned location -> click Finish. - Export the sdk project as JAR file. + Export the sdk project as JAR file. Right click the project -> Export -> select 'JAR file' option under Java -> Next -> Finish. Copy the JAR file into the libs folder of the plug-in project. diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/Activator.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/Activator.java index 3298740..093fb78 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/Activator.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/Activator.java @@ -1,12 +1,9 @@ package oic.simulator.serviceprovider; -import java.net.URL; - +import oic.simulator.serviceprovider.manager.ImageManager; import oic.simulator.serviceprovider.manager.LogManager; import oic.simulator.serviceprovider.manager.ResourceManager; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -25,6 +22,8 @@ public class Activator extends AbstractUIPlugin { private static LogManager logManager; + private static ImageManager imageManager; + public Activator() { } @@ -33,6 +32,7 @@ public class Activator extends AbstractUIPlugin { plugin = this; setResourceManager(new ResourceManager()); setLogManager(new LogManager()); + imageManager = ImageManager.getInstance(); } public void stop(BundleContext context) throws Exception { @@ -71,13 +71,7 @@ public class Activator extends AbstractUIPlugin { Activator.logManager = logManager; } - public Image getImage(String imagePath) { - Image img = null; - if (null == imagePath || imagePath.length() < 1) { - return img; - } - URL imageURL = getBundle().getEntry(imagePath); - ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL); - return descriptor.createImage(); + public ImageManager getImageManager() { + return imageManager; } } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceModelChangedUIListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceModelChangedUIListener.java index 6a3b2c2..3340e9a 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceModelChangedUIListener.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceModelChangedUIListener.java @@ -8,5 +8,5 @@ import oic.simulator.serviceprovider.resource.LocalResourceAttribute; public interface IResourceModelChangedUIListener { public void onResourceModelChange( ModelChangeNotificationType notificationType, String resourceURI, - Set changeSet); + Set valueChangeSet); } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java new file mode 100644 index 0000000..4852717 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java @@ -0,0 +1,64 @@ +package oic.simulator.serviceprovider.manager; + +import java.net.URL; + +import oic.simulator.serviceprovider.Activator; +import oic.simulator.serviceprovider.utils.Constants; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.swt.graphics.Image; +import org.osgi.framework.Bundle; + +public class ImageManager { + + private static ImageManager imageManager; + + public static ImageManager getInstance() { + if (null == imageManager) { + imageManager = new ImageManager(); + } + return imageManager; + } + + static { + ImageRegistry r = Activator.getDefault().getImageRegistry(); + Bundle bundle = Activator.getDefault().getBundle(); + + r.put(Constants.CHECKED, ImageDescriptor.createFromURL(bundle + .getEntry("icons/checked.gif"))); + r.put(Constants.UNCHECKED, ImageDescriptor.createFromURL(bundle + .getEntry("icons/unchecked.gif"))); + + r.put(Constants.NOTIFY_BUTTON_UNSELECTED, ImageDescriptor + .createFromURL(bundle.getEntry("icons/button_free.PNG"))); + r.put(Constants.NOTIFY_BUTTON_SELECTED, ImageDescriptor + .createFromURL(bundle.getEntry("icons/button_pressed.PNG"))); + + // Resource icons based on the resource type + r.put(Constants.OIC_LIGHT, ImageDescriptor.createFromURL(bundle + .getEntry("/icons/light_16x16.png"))); + + // Log View related icons + r.put(Constants.DEBUG_LOG, ImageDescriptor.createFromURL(bundle + .getEntry("/icons/debug_log.gif"))); + r.put(Constants.INFO_LOG, ImageDescriptor.createFromURL(bundle + .getEntry("/icons/info_log.gif"))); + r.put(Constants.WARNING_LOG, ImageDescriptor.createFromURL(bundle + .getEntry("/icons/warning_log.gif"))); + r.put(Constants.ERROR_LOG, ImageDescriptor.createFromURL(bundle + .getEntry("/icons/error_log.gif"))); + r.put(Constants.UNKNOWN_LOG, ImageDescriptor.createFromURL(bundle + .getEntry("/icons/unknown_log.gif"))); + } + + public static Image getImage(String imagePath) { + Image img = null; + if (null == imagePath || imagePath.length() < 1) { + return img; + } + URL imageURL = Activator.getDefault().getBundle().getEntry(imagePath); + ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL); + return descriptor.createImage(); + } +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/LogManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/LogManager.java index 8563ff0..53ff8f3 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/LogManager.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/LogManager.java @@ -11,13 +11,11 @@ import oic.simulator.serviceprovider.Activator; import oic.simulator.serviceprovider.listener.ILogUIListener; import oic.simulator.serviceprovider.utils.Constants; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.swt.graphics.Image; import org.oic.simulator.ILogger; import org.oic.simulator.ILogger.Level; import org.oic.simulator.SimulatorManager; -import org.osgi.framework.Bundle; public class LogManager { private LinkedList entries = new LinkedList(); @@ -29,21 +27,6 @@ public class LogManager { private LogManagerSynchronizerThread synchronizerThread; private Thread threadHandle; - static { - ImageRegistry r = Activator.getDefault().getImageRegistry(); - Bundle bundle = Activator.getDefault().getBundle(); - r.put(Constants.DEBUG_LOG, ImageDescriptor.createFromURL(bundle - .getEntry("/icons/debug_log.gif"))); - r.put(Constants.INFO_LOG, ImageDescriptor.createFromURL(bundle - .getEntry("/icons/info_log.gif"))); - r.put(Constants.WARNING_LOG, ImageDescriptor.createFromURL(bundle - .getEntry("/icons/warning_log.gif"))); - r.put(Constants.ERROR_LOG, ImageDescriptor.createFromURL(bundle - .getEntry("/icons/error_log.gif"))); - r.put(Constants.UNKNOWN_LOG, ImageDescriptor.createFromURL(bundle - .getEntry("/icons/unknown_log.gif"))); - } - public LogManager() { synchronizerThread = new LogManagerSynchronizerThread(); threadHandle = new Thread(synchronizerThread); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java index 3b38019..702fb9c 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java @@ -1,6 +1,5 @@ package oic.simulator.serviceprovider.manager; -import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -25,7 +24,6 @@ import oic.simulator.serviceprovider.resource.StandardConfiguration; import oic.simulator.serviceprovider.utils.Constants; import oic.simulator.serviceprovider.utils.Utility; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; import org.oic.simulator.AutomationType; import org.oic.simulator.IAutomation; @@ -100,28 +98,39 @@ public class ResourceManager { if (null == resource) { return; } + + ModelChangeNotificationType notificationType; // Fetch the resource attributes Map resourceAttributeMapNew; resourceAttributeMapNew = fetchResourceAttributesFromModel(resourceModelN); if (null == resourceAttributeMapNew) { + resource.setResourceAttributesMap(null); + resourceModelChangedUINotification( + ModelChangeNotificationType.NO_ATTRIBUTES_IN_MODEL, + resourceURI, null); return; } + // Update the resource with new model data Map resourceAttributeMapOld; resourceAttributeMapOld = resource .getResourceAttributesMap(); if (null == resourceAttributeMapOld) { + resource.setResourceAttributesMap(resourceAttributeMapNew); + resourceModelChangedUINotification( + ModelChangeNotificationType.ATTRIBUTE_ADDED, + resourceURI, null); return; } - ModelChangeNotificationType notificationType; - Set changeSet = new HashSet(); + Set valueChangeSet = new HashSet(); notificationType = compareAndUpdateLocalAttributes( resourceAttributeMapOld, - resourceAttributeMapNew, changeSet); + resourceAttributeMapNew, valueChangeSet); if (notificationType != ModelChangeNotificationType.NONE) { // Update the UI listeners resourceModelChangedUINotification( - notificationType, resourceURI, changeSet); + notificationType, resourceURI, + valueChangeSet); } } }); @@ -137,24 +146,17 @@ public class ResourceManager { @Override public void run() { - System.out.println("onAutomationComplete() entry"); SimulatorResource resource = getSimulatorResourceByURI(resourceURI); if (null == resource) { return; } - System.out - .println("onAutomationComplete() resource is not null"); // Checking whether this notification is for an // attribute or a resource if (resource.isResourceAutomationInProgress()) { - System.out - .println("onAutomationComplete() for resource"); changeResourceLevelAutomationStatus(resource, false); // Notify the UI listeners automationCompleteUINotification(resourceURI, null); } else if (resource.isAttributeAutomationInProgress()) { - System.out - .println("onAutomationComplete() for attribute"); // Find the attribute with the given automation id LocalResourceAttribute attribute; attribute = getAttributeWithGivenAutomationId( @@ -180,32 +182,22 @@ public class ResourceManager { @Override public void onObserverChanged(final String resourceURI, final int status, final ObserverInfo observer) { - System.out.println("onObserverListChanged in Manager"); new Thread() { @Override public void run() { - if (null == resourceURI) { + if (null == resourceURI || null == observer) { return; } - System.out.println("URI:" + resourceURI); SimulatorResource resource = getSimulatorResourceByURI(resourceURI); if (null == resource) { return; } - System.out.println("Resource Exist"); // Update the observers information if (status == 0) { resource.addObserverInfo(observer); } else { resource.removeObserverInfo(observer); } - - System.out.println(observer.getAddress() + "," - + observer.getPort() + "," + observer.getId()); - - System.out.println(resource.getObserver()); - - System.out.println("status:" + status); // Notify the UI listeners observerListChangedUINotification(resourceURI); } @@ -459,9 +451,6 @@ public class ResourceManager { SimulatorResourceServer resourceServerN; resourceServerN = SimulatorManager.createResource( configFilePath, resourceModelChangeListener); - if (null == resourceServerN) { - return; - } SimulatorResource simulatorResource; simulatorResource = fetchResourceData(resourceServerN); if (null != simulatorResource) { @@ -471,11 +460,12 @@ public class ResourceManager { simulatorResource.getResourceURI()); resourceCreatedUINotification(); + // Set the observer for the created resource + resourceServerN.setObserverCallback(observer); + // Print the resource data simulatorResource.printResourceInfo(); } - // Set the observer for the created resource - resourceServerN.setObserverCallback(observer); } }.start(); } @@ -569,7 +559,6 @@ public class ResourceManager { Set attNameSet = attributeMapN.keySet(); String attName; - Object attValueObj; ResourceAttribute attributeN; LocalResourceAttribute attribute; Iterator attNameItr = attNameSet.iterator(); @@ -579,37 +568,15 @@ public class ResourceManager { if (null != attributeN) { attribute = new LocalResourceAttribute(); attribute.setResourceAttribute(attributeN); - attribute.setAttributeName(attName); - attValueObj = attributeN.getValue(); - if (null != attValueObj) { - attribute.setAttributeValue(attValueObj); + // Set the attribute value + Object valueObj = attributeN.getValue(); + if (null != valueObj) { + attribute.setAttributeValue(valueObj); } - // Set the attribute type - attribute.setAttValBaseType(attributeN.getBaseType()); - attribute.setAttValType(attributeN.getType()); - - // Set the range and allowed values - Range range = attributeN.getRange(); - if (null != range) { - attribute.setMinValue(range.getMin()); - attribute.setMaxValue(range.getMax()); - System.out.println("Fetching range"); - System.out.println(range.getMin() + "," - + range.getMax()); - } else { - Object[] values = attributeN.getAllowedValues(); - System.out.println("Size of allowed values:" - + values.length); - if (null != values && values.length > 0) { - List valueList = new ArrayList(); - for (Object obj : values) { - valueList.add(obj); - } - attribute.setAllowedValues(valueList); - } - } + // Set the attribute value list. + attribute.setAttValues(getValueList(attributeN)); // Initially disabling the automation attribute.setAutomationInProgress(false); @@ -632,6 +599,45 @@ public class ResourceManager { return resourceAttributeMap; } + // This method gives all known possible values of the attribute in string + // format. It takes allowed values or range of values whichever is available + private List getValueList(ResourceAttribute attributeN) { + Object[] allowedValues = attributeN.getAllowedValues(); + List valueList = new ArrayList(); + if (null != allowedValues && allowedValues.length > 0) { + for (Object value : allowedValues) { + if (null != value) { + valueList.add(String.valueOf(value)); + } + } + } else { + Type valueType = attributeN.getBaseType(); + Range range = attributeN.getRange(); + if (null != range) { + Object min = range.getMin(); + Object max = range.getMax(); + if (valueType == Type.INT) { + int minI = (Integer) min; + int maxI = (Integer) max; + for (int value = minI; value <= maxI; value++) { + valueList.add(String.valueOf(value)); + } + } else if (valueType == Type.DOUBLE) { + double minD = (Double) min; + double maxD = (Double) max; + for (double value = minD; value <= maxD; value++) { + valueList.add(String.valueOf(value)); + } + } + } + } + Object attValue = attributeN.getValue(); + if (valueList.size() < 1 && null != attValue) { + valueList.add(String.valueOf(attValue)); + } + return valueList; + } + public void deleteResourceByURI(final String resourceURI) { if (null != resourceURI) { new Thread() { @@ -832,7 +838,7 @@ public class ResourceManager { private void resourceModelChangedUINotification( ModelChangeNotificationType notificationType, String resourceURI, - Set changeSet) { + Set valueChangeSet) { synchronized (resourceModelChangedUIListeners) { if (resourceModelChangedUIListeners.size() > 0 && notificationType != ModelChangeNotificationType.NONE @@ -844,7 +850,7 @@ public class ResourceManager { listener = listenerItr.next(); if (null != listener) { listener.onResourceModelChange(notificationType, - resourceURI, changeSet); + resourceURI, valueChangeSet); } } } @@ -986,16 +992,9 @@ public class ResourceManager { propValue = resource.getResourceURI(); } else if (propName.equals(Constants.RESOURCE_TYPE)) { propValue = resource.getResourceType(); - } else if (propName.equals(Constants.RESOURCE_UID)) { - // propValue = resource.getResourceUID(); - propValue = "Dummy123"; // TODO: Temporarily adding dummy - // value to - // show in UI } else if (propName.equals(Constants.CONNECTIVITY_TYPE)) { - // propValue = resource.getConnectivityType(); - propValue = "IP"; // TODO: Temporarily adding dummy value to - // see - // show UI + // TODO: Temporarily ignoring till the implementation. + propValue = null; } else { propValue = null; } @@ -1019,14 +1018,11 @@ public class ResourceManager { Set attNameSet = attMap.keySet(); String attName; LocalResourceAttribute attribute; - // ResourceAttribute attributeClone; Iterator attNameItr = attNameSet.iterator(); while (attNameItr.hasNext()) { attName = attNameItr.next(); attribute = attMap.get(attName); if (null != attribute) { - // attributeClone = - // ResourceAttribute.clone(attribute); attList.add(attribute); } } @@ -1076,7 +1072,7 @@ public class ResourceManager { private ModelChangeNotificationType compareAndUpdateLocalAttributes( Map resourceAttributeMapOld, Map resourceAttributeMapNew, - Set changeSet) { + Set valueChangeSet) { ModelChangeNotificationType notificationType = ModelChangeNotificationType.NONE; if (null != resourceAttributeMapOld && null != resourceAttributeMapNew) { Set oldMapKeySet = resourceAttributeMapOld.keySet(); @@ -1108,7 +1104,7 @@ public class ResourceManager { if (!oldValueStr.equals(newValueStr)) { attributeOld.setAttributeValue(attValueNew); notificationType = ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED; - changeSet.add(attributeOld); + valueChangeSet.add(attributeOld); } } } @@ -1271,30 +1267,30 @@ public class ResourceManager { return status; } - public void stopResourceAutomationUIRequest(final String resourceURI) { + public boolean stopResourceAutomationUIRequest(final String resourceURI) { + SimulatorResource resource = getSimulatorResourceByURI(resourceURI); + if (null == resource) { + return false; + } + final int autoId = resource.getAutomationId(); + if (-1 == autoId) { + return false; + } + SimulatorResourceServer resourceServer = resource.getResourceServer(); + if (null == resourceServer) { + return false; + } + // Call native method + resourceServer.stopAutomation(autoId); + + // Notify the UI Listeners. Invoke the automation complete callback. Thread stopThread = new Thread() { public void run() { - SimulatorResource resource = getSimulatorResourceByURI(resourceURI); - if (null == resource) { - return; - } - int autoId = resource.getAutomationId(); - if (-1 == autoId) { - return; - } - SimulatorResourceServer resourceServer = resource - .getResourceServer(); - if (null == resourceServer) { - return; - } - // Call native method - resourceServer.stopAutomation(autoId); - - // Invoke the automation complete callback automationListener.onAutomationComplete(resourceURI, autoId); } }; stopThread.start(); + return true; } // Changes the automation state of the resource and its attributes @@ -1362,7 +1358,6 @@ public class ResourceManager { } public void notifyObserverRequest(SimulatorResource res, int observerId) { - System.out.println("In notifyObserverRequest()"); if (null == res) { return; } @@ -1377,19 +1372,12 @@ public class ResourceManager { if (null == resourceURI) { return null; } - URL url = Activator.getDefault().getBundle() - .getEntry(getImageURL(resourceURI)); - if (null == url) { + SimulatorResource resource = getSimulatorResourceByURI(resourceURI); + if (null == resource) { return null; } - return ImageDescriptor.createFromURL(url).createImage(); - } - - private String getImageURL(String resourceURI) { - // TODO: Hard-coding the image file name temporarily. - // It will be included in a separate class which manages all image - // resources - return "/icons/light_16x16.png"; + return Activator.getDefault().getImageRegistry() + .get(resource.getResourceType()); } public void shutdown() { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteCategory.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/DeleteCategory.java similarity index 53% rename from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteCategory.java rename to service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/DeleteCategory.java index ba2ff9d..5825062 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteCategory.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/DeleteCategory.java @@ -1,4 +1,4 @@ -package oic.simulator.serviceprovider.view.dialogs; +package oic.simulator.serviceprovider.resource; public enum DeleteCategory { ALL, BY_TYPE, BY_URI, NONE diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/LocalResourceAttribute.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/LocalResourceAttribute.java index ffd9499..1aea3e8 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/LocalResourceAttribute.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/LocalResourceAttribute.java @@ -1,11 +1,10 @@ package oic.simulator.serviceprovider.resource; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.oic.simulator.AutomationType; import org.oic.simulator.ResourceAttribute; +import org.oic.simulator.ResourceAttribute.Range; import org.oic.simulator.ResourceAttribute.Type; public class LocalResourceAttribute { @@ -13,14 +12,8 @@ public class LocalResourceAttribute { // Native object reference private ResourceAttribute resourceAttribute; - private String attributeName; private Object attributeValue; - private Type attValType; - private Type attValBaseType; - private List allowedValues; - - private Object minValue; - private Object maxValue; + private List attValues; private int automationId; @@ -39,11 +32,7 @@ public class LocalResourceAttribute { } public String getAttributeName() { - return attributeName; - } - - public void setAttributeName(String attributeName) { - this.attributeName = attributeName; + return resourceAttribute.getName(); } public Object getAttributeValue() { @@ -54,39 +43,16 @@ public class LocalResourceAttribute { this.attributeValue = attributeValue; } - public List getAllowedValues() { - return allowedValues; - } - - public void setAllowedValues(List allowedValues) { - this.allowedValues = allowedValues; - } - - public void setAllowedValues(String[] allowedValues) { - List allowedValueList = null; - if (null != allowedValues && allowedValues.length > 0) { - allowedValueList = new ArrayList(); - for (String value : allowedValues) { - allowedValueList.add(value); - } - } - this.allowedValues = allowedValueList; + public Object[] getAllowedValues() { + return resourceAttribute.getAllowedValues(); } public Object getMinValue() { - return minValue; - } - - public void setMinValue(Object minValue) { - this.minValue = minValue; + return resourceAttribute.getRange().getMin(); } public Object getMaxValue() { - return maxValue; - } - - public void setMaxValue(Object maxValue) { - this.maxValue = maxValue; + return resourceAttribute.getRange().getMax(); } public boolean isAutomationInProgress() { @@ -122,81 +88,36 @@ public class LocalResourceAttribute { } public Type getAttValType() { - return attValType; + return resourceAttribute.getType(); } - public void setAttValType(Type attValType) { - this.attValType = attValType; + public Type getAttValBaseType() { + return resourceAttribute.getBaseType(); } - public Type getAttValBaseType() { - return attValBaseType; - } - - public void setAttValBaseType(Type attValBaseType) { - this.attValBaseType = attValBaseType; - } - - public static LocalResourceAttribute clone(LocalResourceAttribute attribute) { - LocalResourceAttribute clone = null; - if (null != attribute) { - clone = new LocalResourceAttribute(); - clone.setAttributeName(attribute.getAttributeName()); - clone.setAttributeValue(attribute.getAttributeValue()); - clone.setAllowedValues(attribute.getAllowedValues()); - clone.setMinValue(attribute.getMinValue()); - clone.setMaxValue(attribute.getMaxValue()); - clone.setAutomationInProgress(attribute.isAutomationInProgress()); - clone.setAutomationType(attribute.getAutomationType()); - clone.setAutomationUpdateInterval(attribute - .getAutomationUpdateInterval()); - clone.setResourceAttribute(null); - } - return clone; - } - - // This method gives all known possible values of the attribute in string - // format. It takes allowed values or range of values whichever is available - public List getAllValues() { - List valueList = new ArrayList(); - if (null != allowedValues) { - System.out.println("In getAllValues() - AllowedValues available"); - Iterator values = allowedValues.iterator(); - Object value; - while (values.hasNext()) { - value = values.next(); - if (null != value) { - valueList.add(String.valueOf(value)); - } - } - } else if (null != minValue && null != maxValue) { - System.out.println("In getAllValues() - Range available"); - if (attValBaseType == Type.INT) { - int min = (Integer) minValue; - int max = (Integer) maxValue; - for (int value = min; value <= max; value++) { - valueList.add(String.valueOf(value)); - } - } else if (attValBaseType == Type.DOUBLE) { - double min = (Double) minValue; - double max = (Double) maxValue; - for (double value = min; value <= max; value++) { - valueList.add(String.valueOf(value)); - } - } - } - if (valueList.size() < 1 && null != attributeValue) { - valueList.add(String.valueOf(attributeValue)); - } - return valueList; + public List getAttValues() { + return attValues; + } + + public void setAttValues(List attValues) { + this.attValues = attValues; } public void printAttributeDetails() { - System.out.println("Attribute Name:" + attributeName); - System.out.println("Attribute Value:" + attributeValue); - System.out.println("Attribute Base Type:" + attValBaseType); - System.out.println("Attribute Type:" + attValType); - System.out.println("Allowed Values:" + allowedValues); - System.out.println("Range:" + minValue + " to " + maxValue); + System.out.println("Attribute Name:" + resourceAttribute.getName()); + System.out.println("Attribute Value:" + resourceAttribute.getValue()); + System.out.println("Attribute Base Type:" + + resourceAttribute.getBaseType()); + System.out.println("Attribute Type:" + resourceAttribute.getType()); + System.out.print("Allowed Values:"); + Object[] values = getAllowedValues(); + for (Object obj : values) { + System.out.print(obj); + } + Range range = resourceAttribute.getRange(); + if (null != range) { + System.out.println("Range:" + range.getMin() + " to " + + range.getMax()); + } } } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ModelChangeNotificationType.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ModelChangeNotificationType.java index 64deda9..3dc1c60 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ModelChangeNotificationType.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ModelChangeNotificationType.java @@ -1,5 +1,5 @@ package oic.simulator.serviceprovider.resource; public enum ModelChangeNotificationType { - ATTRIBUTE_ADDED, ATTRIBUTE_REMOVED, ATTRIBUTE_VALUE_CHANGED, NONE + ATTRIBUTE_ADDED, ATTRIBUTE_REMOVED, ATTRIBUTE_VALUE_CHANGED, NONE, NO_ATTRIBUTES_IN_MODEL } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java index 1b965ed..dc46487 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java @@ -17,7 +17,7 @@ import org.osgi.framework.Bundle; public class StandardConfiguration { // A map of filename of standard resources as the key and the complete - // location of the file(including the filename) as the value + // location of the file(including the filename) as the value. Map stdConfigFiles; public StandardConfiguration() { @@ -47,7 +47,6 @@ public class StandardConfiguration { if (null == url) { return; } - System.out.println("URL: " + url.toExternalForm()); try { file = new File(FileLocator.resolve(url).toURI()); } catch (URISyntaxException | IOException e) { @@ -55,18 +54,8 @@ public class StandardConfiguration { return; } filePath = file.getAbsolutePath(); - System.out.println(filePath); stdConfigFiles.put(fileName, filePath); } - - // Print for debugging purpose - Iterator itr = stdConfigFiles.keySet().iterator(); - String key; - while (itr.hasNext()) { - key = itr.next(); - System.out.println("FileName: " + key); - System.out.println("FilePath:" + stdConfigFiles.get(key)); - } } public Map getStandardResourceConfigurationList() { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java index b63a567..d71dea7 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java @@ -18,7 +18,7 @@ public class Constants { public static final String CONNECTIVITY_TYPE = "Connectivity Type"; public static final String[] META_PROPERTIES = { - RESOURCE_URI, RESOURCE_TYPE, RESOURCE_UID, CONNECTIVITY_TYPE }; + RESOURCE_URI, RESOURCE_TYPE, CONNECTIVITY_TYPE }; public static final int META_PROPERTY_COUNT = META_PROPERTIES.length; @@ -66,6 +66,11 @@ public class Constants { public static final String DEBUG = "Debug"; public static final String UNKNOWN = "Unknown"; + public static final String CHECKED = "Checked"; + public static final String UNCHECKED = "Unchecked"; + public static final String NOTIFY_BUTTON_SELECTED = "Notify_Selected"; + public static final String NOTIFY_BUTTON_UNSELECTED = "Notify_Unselected"; + public static final String CREATE_PAGE_TITLE = "Create Resource"; public static final String CREATE_PAGE_MESSAGE = "Select a standard resource or custom resource to be created"; @@ -77,4 +82,6 @@ public class Constants { public static final String RAML_FILE_EXTENSION = ".raml"; public static final String SPLIT_BY_DOT_PATTERN = "\\."; + + public static final String OIC_LIGHT = "oic.light"; } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java index 3d9a78b..faf2542 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java @@ -66,9 +66,8 @@ public class AttributeEditingSupport { } String values[] = null; - List valueSet = attributeInSelection.getAllValues(); - System.out.println("Values obtained in getCellEditor: " + valueSet); - values = convertListToString(valueSet); + List valueSet = attributeInSelection.getAttValues(); + values = convertListToStringArray(valueSet); ComboBoxCellEditor comboEditor = new ComboBoxCellEditor( viewer.getTable(), values, SWT.READ_ONLY); @@ -113,7 +112,7 @@ public class AttributeEditingSupport { int indexOfItem = 0; LocalResourceAttribute att = (LocalResourceAttribute) element; String valueString = String.valueOf(att.getAttributeValue()); - List valueSet = att.getAllValues(); + List valueSet = att.getAttValues(); if (null != valueSet) { indexOfItem = valueSet.indexOf(valueString); } @@ -133,7 +132,7 @@ public class AttributeEditingSupport { viewer.update(element, null); } - public String[] convertListToString(List valueList) { + public String[] convertListToStringArray(List valueList) { String[] strArr; if (null != valueList && valueList.size() > 0) { strArr = valueList.toArray(new String[1]); @@ -173,15 +172,12 @@ public class AttributeEditingSupport { @Override protected Object getValue(Object element) { - System.out.println("In getValue() automation"); LocalResourceAttribute att = (LocalResourceAttribute) element; return att.isAutomationInProgress(); } @Override protected void setValue(Object element, Object value) { - System.out.println("In setValue() automation"); - ResourceManager resourceManager = Activator.getDefault() .getResourceManager(); // As automation depends on the current resource in selection, its @@ -194,10 +190,8 @@ public class AttributeEditingSupport { LocalResourceAttribute att = (LocalResourceAttribute) element; boolean checked = (Boolean) value; - System.out.println("Value:" + checked); if (checked) { // Start the automation - // Fetch the settings data List automationSettings; automationSettings = AutomationSettingHelper diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java index 82956c8..b986900 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java @@ -8,8 +8,8 @@ import oic.simulator.serviceprovider.listener.IAutomationUIListener; import oic.simulator.serviceprovider.listener.IResourceModelChangedUIListener; import oic.simulator.serviceprovider.listener.IResourceSelectionChangedUIListener; import oic.simulator.serviceprovider.manager.ResourceManager; -import oic.simulator.serviceprovider.resource.ModelChangeNotificationType; import oic.simulator.serviceprovider.resource.LocalResourceAttribute; +import oic.simulator.serviceprovider.resource.ModelChangeNotificationType; import oic.simulator.serviceprovider.resource.SimulatorResource; import oic.simulator.serviceprovider.utils.Constants; @@ -50,16 +50,6 @@ public class AttributeView extends ViewPart { private ResourceManager resourceManager; - private static final Image CHECKED = Activator - .getDefault() - .getImage( - "icons/checked.gif"); - - private static final Image UNCHECKED = Activator - .getDefault() - .getImage( - "icons/unchecked.gif"); - public AttributeView() { resourceManager = Activator.getDefault().getResourceManager(); @@ -73,7 +63,7 @@ public class AttributeView extends ViewPart { @Override public void run() { if (null != attTblViewer) { - updateViewer(checkSelection()); + updateViewer(getData()); SimulatorResource resource = resourceManager .getCurrentResourceInSelection(); Table tbl = attTblViewer.getTable(); @@ -98,7 +88,7 @@ public class AttributeView extends ViewPart { public void onResourceModelChange( final ModelChangeNotificationType notificationType, final String resourceURI, - final Set changeSet) { + final Set valueChangeSet) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { @@ -110,6 +100,10 @@ public class AttributeView extends ViewPart { return; } if (!resourceURI.equals(resource.getResourceURI())) { + // This notification is for a different resource + // whose attributes are not + // currently not being shown in UI. So ignoring this + // notification. return; } // Refresh the table viewers which will display @@ -117,11 +111,13 @@ public class AttributeView extends ViewPart { if (null != attTblViewer) { if (notificationType == ModelChangeNotificationType.ATTRIBUTE_ADDED || notificationType == ModelChangeNotificationType.ATTRIBUTE_REMOVED) { - attTblViewer.refresh(); + updateViewer(getData()); + } else if (notificationType == ModelChangeNotificationType.NO_ATTRIBUTES_IN_MODEL) { + attTblViewer.setInput(null); } else if (notificationType == ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED) { - if (null != changeSet) { - attTblViewer.update(changeSet.toArray(), - null); + if (null != valueChangeSet) { + attTblViewer.update( + valueChangeSet.toArray(), null); } } } @@ -175,8 +171,6 @@ public class AttributeView extends ViewPart { @Override public void run() { - System.out.println("onAutomationcomplete Impl: uri:" - + resourceURI + ",attname:" + attName); if (null == resourceURI) { return; } @@ -200,7 +194,6 @@ public class AttributeView extends ViewPart { LocalResourceAttribute att = resourceManager .getAttributeByResourceURI(resourceURI, attName); - System.out.println(att == null); if (null == att) { return; } else { @@ -251,7 +244,7 @@ public class AttributeView extends ViewPart { addManagerListeners(); // Check whether there is any resource selected already - List propertyList = checkSelection(); + List propertyList = getData(); if (null != propertyList) { updateViewer(propertyList); } @@ -317,9 +310,11 @@ public class AttributeView extends ViewPart { public Image getImage(Object element) { LocalResourceAttribute att = (LocalResourceAttribute) element; if (att.isAutomationInProgress()) { - return CHECKED; + return Activator.getDefault().getImageRegistry() + .get(Constants.CHECKED); } else { - return UNCHECKED; + return Activator.getDefault().getImageRegistry() + .get(Constants.UNCHECKED); } } }); @@ -335,7 +330,7 @@ public class AttributeView extends ViewPart { resourceManager.addAutomationUIListener(automationUIListener); } - private List checkSelection() { + private List getData() { SimulatorResource resourceInSelection = resourceManager .getCurrentResourceInSelection(); if (null != resourceInSelection) { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java index 4944b31..8785d07 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java @@ -34,11 +34,11 @@ public class MetaPropertiesView extends ViewPart { private IResourceSelectionChangedUIListener resourceSelectionChangedListener; - private ResourceManager resourceManager; + private ResourceManager resourceManagerRef; public MetaPropertiesView() { - resourceManager = Activator.getDefault().getResourceManager(); + resourceManagerRef = Activator.getDefault().getResourceManager(); resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() { @@ -49,7 +49,7 @@ public class MetaPropertiesView extends ViewPart { @Override public void run() { if (null != tableViewer) { - updateViewer(checkSelection()); + updateViewer(getData()); } } }); @@ -66,7 +66,7 @@ public class MetaPropertiesView extends ViewPart { createColumns(tableViewer); - // make lines and header visible + // Make lines and header visible final Table table = tableViewer.getTable(); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); table.setHeaderVisible(true); @@ -77,18 +77,18 @@ public class MetaPropertiesView extends ViewPart { addManagerListeners(); // Check whether there is any resource selected already - List propertyList = checkSelection(); + List propertyList = getData(); if (null != propertyList) { updateViewer(propertyList); } } - private List checkSelection() { - SimulatorResource resourceInSelection = resourceManager + private List getData() { + SimulatorResource resourceInSelection = resourceManagerRef .getCurrentResourceInSelection(); if (null != resourceInSelection) { - List metaPropertyList = resourceManager + List metaPropertyList = resourceManagerRef .getMetaProperties(resourceInSelection); return metaPropertyList; } else { @@ -148,7 +148,7 @@ public class MetaPropertiesView extends ViewPart { } private void addManagerListeners() { - resourceManager + resourceManagerRef .addResourceSelectionChangedUIListener(resourceSelectionChangedListener); } @@ -173,7 +173,7 @@ public class MetaPropertiesView extends ViewPart { public void dispose() { // Unregister the listener if (null != resourceSelectionChangedListener) { - resourceManager + resourceManagerRef .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener); } super.dispose(); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java index 28cde2b..b15c3e3 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java @@ -6,10 +6,10 @@ import java.util.List; import oic.simulator.serviceprovider.Activator; import oic.simulator.serviceprovider.listener.IResourceListChangedUIListener; import oic.simulator.serviceprovider.manager.ResourceManager; +import oic.simulator.serviceprovider.resource.DeleteCategory; import oic.simulator.serviceprovider.utils.Constants; import oic.simulator.serviceprovider.utils.Utility; import oic.simulator.serviceprovider.view.dialogs.CreateResourceWizard; -import oic.simulator.serviceprovider.view.dialogs.DeleteCategory; import oic.simulator.serviceprovider.view.dialogs.DeleteResourceWizard; import oic.simulator.serviceprovider.view.dialogs.ResourceWizardDialog; @@ -194,7 +194,6 @@ public class ResourceManagerView extends ViewPart { System.out.println("Resultant config file path is " + configFilePath); count = createWizard.getResourceCount(); - if (count <= 1) { // Single resource creation resourceManager.createResource(configFilePath); @@ -315,10 +314,11 @@ public class ResourceManagerView extends ViewPart { stopItem.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - resourceManager + boolean status = resourceManager .stopResourceAutomationUIRequest(Utility .displayNameToUri(selectedItem)); - String statusMsg = "Automation stop requested!!!"; + String statusMsg = status ? "Automation stop requested!!!" + : "Automation stop failed."; MessageDialog.openInformation(Display .getDefault().getActiveShell(), "Automation Status", statusMsg); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceObserverView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceObserverView.java index 90ecf90..1a785c4 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceObserverView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceObserverView.java @@ -10,6 +10,7 @@ import oic.simulator.serviceprovider.listener.IResourceSelectionChangedUIListene import oic.simulator.serviceprovider.manager.ResourceManager; import oic.simulator.serviceprovider.resource.ObserverDetail; import oic.simulator.serviceprovider.resource.SimulatorResource; +import oic.simulator.serviceprovider.utils.Constants; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.CheckboxCellEditor; @@ -31,35 +32,24 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.ui.part.ViewPart; public class ResourceObserverView extends ViewPart { - public static final String VIEW_ID = "oic.simulator.serviceprovider.view.observer"; + public static final String VIEW_ID = "oic.simulator.serviceprovider.view.observer"; private TableViewer tblViewer; - private final String[] columnHeaders = { - "Client Address", "Port", "Notify" }; + private final String[] columnHeaders = { + "Client Address", "Port", "Notify" }; - private final Integer[] columnWidth = { - 150, 75, 50 }; + private final Integer[] columnWidth = { 150, 75, 50 }; private IResourceSelectionChangedUIListener resourceSelectionChangedListener; private IObserverListChangedUIListener resourceObserverListChangedListener; - private ResourceManager resourceManager; - - private static final Image NOTIFY_BUTTON_UNSELECTED = Activator - .getDefault() - .getImage( - "icons/button_free.PNG"); - - private static final Image NOTIFY_BUTTON_SELECTED = Activator - .getDefault() - .getImage( - "icons/button_pressed.PNG"); + private ResourceManager resourceManagerRef; public ResourceObserverView() { - resourceManager = Activator.getDefault().getResourceManager(); + resourceManagerRef = Activator.getDefault().getResourceManager(); resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() { @@ -71,7 +61,7 @@ public class ResourceObserverView extends ViewPart { public void run() { if (null != tblViewer) { changeButtonStatus(); - updateViewer(getData(resourceManager + updateViewer(getData(resourceManagerRef .getCurrentResourceInSelection())); } } @@ -87,17 +77,14 @@ public class ResourceObserverView extends ViewPart { @Override public void run() { - System.out.println("UI callback - observer"); if (null == resourceURI) { return; } - SimulatorResource resource = resourceManager + SimulatorResource resource = resourceManagerRef .getCurrentResourceInSelection(); if (null == resource) { return; } - System.out - .println("UI callback - observer - this resource"); if (resource.getResourceURI().equals(resourceURI)) { if (null != tblViewer) { updateViewer(getData(resource)); @@ -118,7 +105,6 @@ public class ResourceObserverView extends ViewPart { } private void updateViewer(Map observer) { - System.out.println(observer); if (null != tblViewer) { Table tbl = tblViewer.getTable(); if (null != observer && observer.size() > 0) { @@ -154,6 +140,12 @@ public class ResourceObserverView extends ViewPart { addManagerListeners(); + // Check whether there is any resource selected already + Map observerList = getData(resourceManagerRef + .getCurrentResourceInSelection()); + if (null != observerList) { + updateViewer(observerList); + } } public void createColumns(TableViewer tableViewer) { @@ -207,18 +199,20 @@ public class ResourceObserverView extends ViewPart { @SuppressWarnings("unchecked") Map.Entry observer = (Map.Entry) element; if (observer.getValue().isClicked()) { - return NOTIFY_BUTTON_SELECTED; + return Activator.getDefault().getImageRegistry() + .get(Constants.NOTIFY_BUTTON_SELECTED); } - return NOTIFY_BUTTON_UNSELECTED; + return Activator.getDefault().getImageRegistry() + .get(Constants.NOTIFY_BUTTON_UNSELECTED); } }); notifyColumn.setEditingSupport(new NotifyEditor(tableViewer)); } private void addManagerListeners() { - resourceManager + resourceManagerRef .addResourceSelectionChangedUIListener(resourceSelectionChangedListener); - resourceManager + resourceManagerRef .addObserverListChangedUIListener(resourceObserverListChangedListener); } @@ -278,14 +272,14 @@ public class ResourceObserverView extends ViewPart { viewer.refresh(); // Call Native Method - resourceManager.notifyObserverRequest( - resourceManager.getCurrentResourceInSelection(), observer - .getValue().getObserverInfo().getId()); + resourceManagerRef.notifyObserverRequest( + resourceManagerRef.getCurrentResourceInSelection(), + observer.getValue().getObserverInfo().getId()); } } private void changeButtonStatus() { - SimulatorResource resource = resourceManager + SimulatorResource resource = resourceManagerRef .getCurrentResourceInSelection(); if (null == resource) { return; @@ -305,12 +299,12 @@ public class ResourceObserverView extends ViewPart { public void dispose() { // Unregister the listener if (null != resourceSelectionChangedListener) { - resourceManager + resourceManagerRef .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener); } if (null != resourceObserverListChangedListener) { - resourceManager + resourceManagerRef .removeObserverListChangedUIListener(resourceObserverListChangedListener); } super.dispose(); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java index a1f3ead..11a305d 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java @@ -162,8 +162,9 @@ public class CreateResourcePage extends WizardPage { while (itr.hasNext()) { fileName = itr.next(); shortName = Utility.fileNameToDisplay(fileName); - System.out.println("Display name of " + fileName + " is " - + shortName); + if (null == shortName) { + continue; + } resourceTypeCmb.add(shortName); } } @@ -229,8 +230,6 @@ public class CreateResourcePage extends WizardPage { // Convert the selectedItem to the fully qualified file // name. selectedItem = Utility.displayToFileName(selectedItem); - System.out - .println("Selected file name:" + selectedItem); // Get the RAML configuration file path of the selected // resource @@ -280,10 +279,8 @@ public class CreateResourcePage extends WizardPage { resourceTypeCmb.select(0); String fileName = Utility.displayToFileName(resourceTypeCmb .getText()); - System.out.println("Selected file in combo:" + fileName); configFilePath = Activator.getDefault().getResourceManager() .getConfigFilePath(fileName); - System.out.println("Selected file's path:" + configFilePath); } } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java index 1272079..e40d570 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java @@ -4,6 +4,7 @@ import java.util.Iterator; import java.util.List; import oic.simulator.serviceprovider.Activator; +import oic.simulator.serviceprovider.resource.DeleteCategory; import oic.simulator.serviceprovider.utils.Constants; import org.eclipse.jface.wizard.WizardPage; @@ -111,7 +112,6 @@ public class DeleteResourcePage extends WizardPage { } private void populateResourceTypeCombo() { - List resourceTypeList; resourceTypeList = Activator.getDefault().getResourceManager() .getResourceTypeList(); @@ -125,8 +125,7 @@ public class DeleteResourcePage extends WizardPage { // By default, select the first item in the combo if (resourceTypeCmb.getItemCount() > 0) { resourceTypeCmb.select(0); - deleteCandidate = resourceTypeCmb.getItem(resourceTypeCmb - .getSelectionIndex()); + deleteCandidate = resourceTypeCmb.getText(); } } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java index 8b9a3b6..6b368dc 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java @@ -3,6 +3,7 @@ package oic.simulator.serviceprovider.view.dialogs; import java.net.URL; import oic.simulator.serviceprovider.Activator; +import oic.simulator.serviceprovider.resource.DeleteCategory; import oic.simulator.serviceprovider.utils.Utility; import org.eclipse.core.runtime.FileLocator; -- 2.7.4