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 <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2379
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
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.
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;
private static LogManager logManager;
+ private static ImageManager imageManager;
+
public Activator() {
}
plugin = this;
setResourceManager(new ResourceManager());
setLogManager(new LogManager());
+ imageManager = ImageManager.getInstance();
}
public void stop(BundleContext context) throws Exception {
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
public interface IResourceModelChangedUIListener {
public void onResourceModelChange(
ModelChangeNotificationType notificationType, String resourceURI,
- Set<LocalResourceAttribute> changeSet);
+ Set<LocalResourceAttribute> valueChangeSet);
}
--- /dev/null
+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();
+ }
+}
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<LogEntry> entries = new LinkedList<LogEntry>();
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);
package oic.simulator.serviceprovider.manager;
-import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
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;
if (null == resource) {
return;
}
+
+ ModelChangeNotificationType notificationType;
// Fetch the resource attributes
Map<String, LocalResourceAttribute> 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<String, LocalResourceAttribute> resourceAttributeMapOld;
resourceAttributeMapOld = resource
.getResourceAttributesMap();
if (null == resourceAttributeMapOld) {
+ resource.setResourceAttributesMap(resourceAttributeMapNew);
+ resourceModelChangedUINotification(
+ ModelChangeNotificationType.ATTRIBUTE_ADDED,
+ resourceURI, null);
return;
}
- ModelChangeNotificationType notificationType;
- Set<LocalResourceAttribute> changeSet = new HashSet<LocalResourceAttribute>();
+ Set<LocalResourceAttribute> valueChangeSet = new HashSet<LocalResourceAttribute>();
notificationType = compareAndUpdateLocalAttributes(
resourceAttributeMapOld,
- resourceAttributeMapNew, changeSet);
+ resourceAttributeMapNew, valueChangeSet);
if (notificationType != ModelChangeNotificationType.NONE) {
// Update the UI listeners
resourceModelChangedUINotification(
- notificationType, resourceURI, changeSet);
+ notificationType, resourceURI,
+ valueChangeSet);
}
}
});
@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(
@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);
}
SimulatorResourceServer resourceServerN;
resourceServerN = SimulatorManager.createResource(
configFilePath, resourceModelChangeListener);
- if (null == resourceServerN) {
- return;
- }
SimulatorResource simulatorResource;
simulatorResource = fetchResourceData(resourceServerN);
if (null != simulatorResource) {
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();
}
Set<String> attNameSet = attributeMapN.keySet();
String attName;
- Object attValueObj;
ResourceAttribute attributeN;
LocalResourceAttribute attribute;
Iterator<String> attNameItr = attNameSet.iterator();
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<Object> valueList = new ArrayList<Object>();
- 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);
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<String> getValueList(ResourceAttribute attributeN) {
+ Object[] allowedValues = attributeN.getAllowedValues();
+ List<String> valueList = new ArrayList<String>();
+ 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() {
private void resourceModelChangedUINotification(
ModelChangeNotificationType notificationType, String resourceURI,
- Set<LocalResourceAttribute> changeSet) {
+ Set<LocalResourceAttribute> valueChangeSet) {
synchronized (resourceModelChangedUIListeners) {
if (resourceModelChangedUIListeners.size() > 0
&& notificationType != ModelChangeNotificationType.NONE
listener = listenerItr.next();
if (null != listener) {
listener.onResourceModelChange(notificationType,
- resourceURI, changeSet);
+ resourceURI, valueChangeSet);
}
}
}
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;
}
Set<String> attNameSet = attMap.keySet();
String attName;
LocalResourceAttribute attribute;
- // ResourceAttribute attributeClone;
Iterator<String> attNameItr = attNameSet.iterator();
while (attNameItr.hasNext()) {
attName = attNameItr.next();
attribute = attMap.get(attName);
if (null != attribute) {
- // attributeClone =
- // ResourceAttribute.clone(attribute);
attList.add(attribute);
}
}
private ModelChangeNotificationType compareAndUpdateLocalAttributes(
Map<String, LocalResourceAttribute> resourceAttributeMapOld,
Map<String, LocalResourceAttribute> resourceAttributeMapNew,
- Set<LocalResourceAttribute> changeSet) {
+ Set<LocalResourceAttribute> valueChangeSet) {
ModelChangeNotificationType notificationType = ModelChangeNotificationType.NONE;
if (null != resourceAttributeMapOld && null != resourceAttributeMapNew) {
Set<String> oldMapKeySet = resourceAttributeMapOld.keySet();
if (!oldValueStr.equals(newValueStr)) {
attributeOld.setAttributeValue(attValueNew);
notificationType = ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED;
- changeSet.add(attributeOld);
+ valueChangeSet.add(attributeOld);
}
}
}
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
}
public void notifyObserverRequest(SimulatorResource res, int observerId) {
- System.out.println("In notifyObserverRequest()");
if (null == res) {
return;
}
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() {
-package oic.simulator.serviceprovider.view.dialogs;
+package oic.simulator.serviceprovider.resource;
public enum DeleteCategory {
ALL, BY_TYPE, BY_URI, NONE
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 {
// Native object reference
private ResourceAttribute resourceAttribute;
- private String attributeName;
private Object attributeValue;
- private Type attValType;
- private Type attValBaseType;
- private List<Object> allowedValues;
-
- private Object minValue;
- private Object maxValue;
+ private List<String> attValues;
private int automationId;
}
public String getAttributeName() {
- return attributeName;
- }
-
- public void setAttributeName(String attributeName) {
- this.attributeName = attributeName;
+ return resourceAttribute.getName();
}
public Object getAttributeValue() {
this.attributeValue = attributeValue;
}
- public List<Object> getAllowedValues() {
- return allowedValues;
- }
-
- public void setAllowedValues(List<Object> allowedValues) {
- this.allowedValues = allowedValues;
- }
-
- public void setAllowedValues(String[] allowedValues) {
- List<Object> allowedValueList = null;
- if (null != allowedValues && allowedValues.length > 0) {
- allowedValueList = new ArrayList<Object>();
- 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() {
}
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<String> getAllValues() {
- List<String> valueList = new ArrayList<String>();
- if (null != allowedValues) {
- System.out.println("In getAllValues() - AllowedValues available");
- Iterator<Object> 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<String> getAttValues() {
+ return attValues;
+ }
+
+ public void setAttValues(List<String> 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
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
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<String, String> stdConfigFiles;
public StandardConfiguration() {
if (null == url) {
return;
}
- System.out.println("URL: " + url.toExternalForm());
try {
file = new File(FileLocator.resolve(url).toURI());
} catch (URISyntaxException | IOException e) {
return;
}
filePath = file.getAbsolutePath();
- System.out.println(filePath);
stdConfigFiles.put(fileName, filePath);
}
-
- // Print for debugging purpose
- Iterator<String> 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<String, String> getStandardResourceConfigurationList() {
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;
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";
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
}
String values[] = null;
- List<String> valueSet = attributeInSelection.getAllValues();
- System.out.println("Values obtained in getCellEditor: " + valueSet);
- values = convertListToString(valueSet);
+ List<String> valueSet = attributeInSelection.getAttValues();
+ values = convertListToStringArray(valueSet);
ComboBoxCellEditor comboEditor = new ComboBoxCellEditor(
viewer.getTable(), values, SWT.READ_ONLY);
int indexOfItem = 0;
LocalResourceAttribute att = (LocalResourceAttribute) element;
String valueString = String.valueOf(att.getAttributeValue());
- List<String> valueSet = att.getAllValues();
+ List<String> valueSet = att.getAttValues();
if (null != valueSet) {
indexOfItem = valueSet.indexOf(valueString);
}
viewer.update(element, null);
}
- public String[] convertListToString(List<String> valueList) {
+ public String[] convertListToStringArray(List<String> valueList) {
String[] strArr;
if (null != valueList && valueList.size() > 0) {
strArr = valueList.toArray(new String[1]);
@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
LocalResourceAttribute att = (LocalResourceAttribute) element;
boolean checked = (Boolean) value;
- System.out.println("Value:" + checked);
if (checked) {
// Start the automation
-
// Fetch the settings data
List<AutomationSettingHelper> automationSettings;
automationSettings = AutomationSettingHelper
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;
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();
@Override
public void run() {
if (null != attTblViewer) {
- updateViewer(checkSelection());
+ updateViewer(getData());
SimulatorResource resource = resourceManager
.getCurrentResourceInSelection();
Table tbl = attTblViewer.getTable();
public void onResourceModelChange(
final ModelChangeNotificationType notificationType,
final String resourceURI,
- final Set<LocalResourceAttribute> changeSet) {
+ final Set<LocalResourceAttribute> valueChangeSet) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
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
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);
}
}
}
@Override
public void run() {
- System.out.println("onAutomationcomplete Impl: uri:"
- + resourceURI + ",attname:" + attName);
if (null == resourceURI) {
return;
}
LocalResourceAttribute att = resourceManager
.getAttributeByResourceURI(resourceURI,
attName);
- System.out.println(att == null);
if (null == att) {
return;
} else {
addManagerListeners();
// Check whether there is any resource selected already
- List<LocalResourceAttribute> propertyList = checkSelection();
+ List<LocalResourceAttribute> propertyList = getData();
if (null != propertyList) {
updateViewer(propertyList);
}
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);
}
}
});
resourceManager.addAutomationUIListener(automationUIListener);
}
- private List<LocalResourceAttribute> checkSelection() {
+ private List<LocalResourceAttribute> getData() {
SimulatorResource resourceInSelection = resourceManager
.getCurrentResourceInSelection();
if (null != resourceInSelection) {
private IResourceSelectionChangedUIListener resourceSelectionChangedListener;
- private ResourceManager resourceManager;
+ private ResourceManager resourceManagerRef;
public MetaPropertiesView() {
- resourceManager = Activator.getDefault().getResourceManager();
+ resourceManagerRef = Activator.getDefault().getResourceManager();
resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() {
@Override
public void run() {
if (null != tableViewer) {
- updateViewer(checkSelection());
+ updateViewer(getData());
}
}
});
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);
addManagerListeners();
// Check whether there is any resource selected already
- List<MetaProperty> propertyList = checkSelection();
+ List<MetaProperty> propertyList = getData();
if (null != propertyList) {
updateViewer(propertyList);
}
}
- private List<MetaProperty> checkSelection() {
- SimulatorResource resourceInSelection = resourceManager
+ private List<MetaProperty> getData() {
+ SimulatorResource resourceInSelection = resourceManagerRef
.getCurrentResourceInSelection();
if (null != resourceInSelection) {
- List<MetaProperty> metaPropertyList = resourceManager
+ List<MetaProperty> metaPropertyList = resourceManagerRef
.getMetaProperties(resourceInSelection);
return metaPropertyList;
} else {
}
private void addManagerListeners() {
- resourceManager
+ resourceManagerRef
.addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
}
public void dispose() {
// Unregister the listener
if (null != resourceSelectionChangedListener) {
- resourceManager
+ resourceManagerRef
.removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
}
super.dispose();
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;
System.out.println("Resultant config file path is "
+ configFilePath);
count = createWizard.getResourceCount();
-
if (count <= 1) {
// Single resource creation
resourceManager.createResource(configFilePath);
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);
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;
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() {
public void run() {
if (null != tblViewer) {
changeButtonStatus();
- updateViewer(getData(resourceManager
+ updateViewer(getData(resourceManagerRef
.getCurrentResourceInSelection()));
}
}
@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));
}
private void updateViewer(Map<Integer, ObserverDetail> observer) {
- System.out.println(observer);
if (null != tblViewer) {
Table tbl = tblViewer.getTable();
if (null != observer && observer.size() > 0) {
addManagerListeners();
+ // Check whether there is any resource selected already
+ Map<Integer, ObserverDetail> observerList = getData(resourceManagerRef
+ .getCurrentResourceInSelection());
+ if (null != observerList) {
+ updateViewer(observerList);
+ }
}
public void createColumns(TableViewer tableViewer) {
@SuppressWarnings("unchecked")
Map.Entry<Integer, ObserverDetail> observer = (Map.Entry<Integer, ObserverDetail>) 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);
}
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;
public void dispose() {
// Unregister the listener
if (null != resourceSelectionChangedListener) {
- resourceManager
+ resourceManagerRef
.removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
}
if (null != resourceObserverListChangedListener) {
- resourceManager
+ resourceManagerRef
.removeObserverListChangedUIListener(resourceObserverListChangedListener);
}
super.dispose();
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);
}
}
// 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
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);
}
}
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;
}
private void populateResourceTypeCombo() {
-
List<String> resourceTypeList;
resourceTypeList = Activator.getDefault().getResourceManager()
.getResourceTypeList();
// By default, select the first item in the combo
if (resourceTypeCmb.getItemCount() > 0) {
resourceTypeCmb.select(0);
- deleteCandidate = resourceTypeCmb.getItem(resourceTypeCmb
- .getSelectionIndex());
+ deleteCandidate = resourceTypeCmb.getText();
}
}
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;