--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="lib" path="libs/ServiceProvider.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ServiceProviderPlugin</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: ServiceProviderPlugin
+Bundle-SymbolicName: ServiceProviderPlugin;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: oic.simulator.serviceprovider.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Bundle-ActivationPolicy: lazy
+Bundle-NativeCode: libs/libSimulatorManager.so
+Bundle-ClassPath: libs/ServiceProvider.jar,
+ .
--- /dev/null
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ libs/,\
+ icons/
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.perspectives">
+ <perspective
+ class="oic.simulator.serviceprovider.perspective.PerspectiveFactory"
+ icon="icons/sample.gif"
+ id="oic.simulator.serviceprovider.perspective"
+ name="Service Provider">
+ </perspective>
+ </extension>
+ <extension
+ point="org.eclipse.ui.views">
+ <category
+ id="oic.simulator.serviceprovider.category"
+ name="Service Provider">
+ </category>
+ <view
+ category="oic.simulator.serviceprovider.category"
+ class="oic.simulator.serviceprovider.view.ResourceManagerView"
+ icon="icons/sample.gif"
+ id="oic.simulator.serviceprovider.view.resourcemanager"
+ name="Resource Manager"
+ restorable="true">
+ </view>
+ <view
+ category="oic.simulator.serviceprovider.category"
+ class="oic.simulator.serviceprovider.view.AttributeView"
+ icon="icons/sample.gif"
+ id="oic.simulator.serviceprovider.view.attribute"
+ name="Attribute Manager"
+ restorable="true">
+ </view>
+ <view
+ category="oic.simulator.serviceprovider.category"
+ class="oic.simulator.serviceprovider.view.MultiResourceOrchestrationView"
+ icon="icons/sample.gif"
+ id="oic.simulator.serviceprovider.view.orchestration"
+ name="Multi-Resource Automation"
+ restorable="true">
+ </view>
+ <view
+ category="oic.simulator.serviceprovider.category"
+ class="oic.simulator.serviceprovider.view.LogView"
+ icon="icons/sample.gif"
+ id="oic.simulator.serviceprovider.view.log"
+ name="Simulator Log"
+ restorable="true">
+ </view>
+ </extension>
+ <extension
+ point="org.eclipse.ui.perspectiveExtensions">
+ <perspectiveExtension
+ targetID="*">
+ <perspectiveShortcut
+ id="oic.simulator.serviceprovider.perspective">
+ </perspectiveShortcut>
+ </perspectiveExtension>
+ <perspectiveExtension
+ targetID="oic.simulator.serviceprovider.perspective">
+ <viewShortcut
+ id="oic.simulator.serviceprovider.view.ResourceManagerView">
+ </viewShortcut>
+ <viewShortcut
+ id="oic.simulator.serviceprovider.view.AttributeView">
+ </viewShortcut>
+ <viewShortcut
+ id="oic.simulator.serviceprovider.view.MultiResourceOrchestrationView">
+ </viewShortcut>
+ <viewShortcut
+ id="oic.simulator.serviceprovider.view.LogView">
+ </viewShortcut>
+ <viewShortcut
+ id="org.eclipse.ui.views.PropertySheet">
+ </viewShortcut>
+ </perspectiveExtension>
+ </extension>
+
+</plugin>
--- /dev/null
+package oic.simulator.serviceprovider;
+
+import oic.simulator.serviceprovider.manager.ResourceManager;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "ServiceProviderPlugin"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ private static ResourceManager manager;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ setManager(new ResourceManager());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ public static ResourceManager getManager() {
+ return manager;
+ }
+
+ public static void setManager(ResourceManager manager) {
+ Activator.manager = manager;
+ }
+
+}
--- /dev/null
+package oic.simulator.serviceprovider.listener;
+
+import java.util.List;
+
+public interface IResourceListChangedListener {
+ public void onResourceCreation(String resourceType, List<String> resourceURI);
+
+ public void onResourceDeletion(String resourceType, String resourceURI);
+
+ public void onResourceDeletionByType(String resourceType);
+
+ public void onAllResourceDeletion();
+}
--- /dev/null
+package oic.simulator.serviceprovider.manager;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+
+import oic.simulator.serviceprovider.listener.IResourceListChangedListener;
+import oic.simulator.serviceprovider.resource.ResourceAttribute;
+import oic.simulator.serviceprovider.resource.SimulatorResource;
+import oic.simulator.serviceprovider.resource.StandardConfiguration;
+
+import org.iotivity.simulator.SimulatorManager;
+import org.iotivity.simulator.SimulatorResourceAttribute;
+import org.iotivity.simulator.SimulatorResourceModel;
+import org.iotivity.simulator.SimulatorResourceServer;
+
+public class ResourceManager {
+
+ private Map<String, Map<String, SimulatorResource>> resourceMap;
+
+ private StandardConfiguration stdConfig;
+
+ private IResourceListChangedListener resourceListChangedListener;
+
+ static {
+ System.loadLibrary("SimulatorManager");
+ }
+
+ public ResourceManager() {
+ resourceMap = new HashMap<String, Map<String, SimulatorResource>>();
+ stdConfig = new StandardConfiguration();
+
+ // Populate standard configuration file list
+ populateStandardConfigurationList();
+ }
+
+ public void populateStandardConfigurationList() {
+ // TODO: Add all the standard configuration files
+ // Ex: stdConfig.addResourceConfiguration(LIGHT, LIGHT_FILE);
+ }
+
+ public synchronized List<String> getResourceConfigurationList() {
+ List<String> resourceConfigurationList = new ArrayList<String>();
+ Map<String, String> configMap = stdConfig
+ .getStandardResourceConfigurationList();
+ if (null != configMap) {
+ Set<String> keySet = configMap.keySet();
+ if (null != keySet) {
+ Iterator<String> keyItr = keySet.iterator();
+ while (keyItr.hasNext()) {
+ resourceConfigurationList.add(keyItr.next());
+ }
+ }
+ }
+ return resourceConfigurationList;
+ }
+
+ public synchronized String getConfigFilePath(String resourceType) {
+ String path = null;
+ if (null != resourceType) {
+ path = stdConfig.getResourceConfigFilePath(resourceType);
+ }
+ return path;
+ }
+
+ private synchronized void addResourceToMap(
+ SimulatorResource simulatorResource) {
+ if (null != simulatorResource) {
+ Map<String, SimulatorResource> resourceTypeMap;
+ resourceTypeMap = resourceMap.get(simulatorResource
+ .getResourceType());
+ if (null == resourceTypeMap) {
+ resourceTypeMap = new HashMap<String, SimulatorResource>();
+ resourceMap.put(simulatorResource.getResourceType(),
+ resourceTypeMap);
+ }
+ resourceTypeMap.put(simulatorResource.getResourceURI(),
+ simulatorResource);
+ }
+ }
+
+ private synchronized void addResourceToMap(String resourceType,
+ Map<String, SimulatorResource> newResourceTypeMap) {
+ if (null != resourceType && null != newResourceTypeMap) {
+ Map<String, SimulatorResource> resourceTypeMap = resourceMap
+ .get(resourceType);
+ if (null != resourceTypeMap) {
+ resourceTypeMap.putAll(newResourceTypeMap);
+ } else {
+ resourceMap.put(resourceType, newResourceTypeMap);
+ }
+ }
+ }
+
+ private synchronized void removeResourceFromMap(String resourceType,
+ String resourceURI) {
+ if (null != resourceURI && null != resourceType) {
+ Map<String, SimulatorResource> resourceTypeMap = resourceMap
+ .get(resourceType);
+ if (null != resourceTypeMap) {
+ resourceTypeMap.remove(resourceURI);
+ if (resourceTypeMap.size() < 1) {
+ resourceMap.remove(resourceType);
+ }
+ }
+ }
+ }
+
+ public synchronized boolean isResourceExist(String resourceURI) {
+ boolean result = false;
+ if (null != resourceURI) {
+ SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+ if (null != resource) {
+ result = true;
+ }
+ }
+ return result;
+ }
+
+ public synchronized void createResource(String configFilePath) {
+ SimulatorResourceServer resourceServerN;
+ resourceServerN = SimulatorManager.createResource(configFilePath);
+
+ SimulatorResource simulatorResource;
+ simulatorResource = fetchResourceData(resourceServerN);
+ if (null != simulatorResource) {
+ addResourceToMap(simulatorResource);
+
+ String resourceType = simulatorResource.getResourceType();
+ String resourceURI = simulatorResource.getResourceURI();
+ List<String> resourceURIList = new ArrayList<String>();
+ resourceURIList.add(resourceURI);
+
+ resourceCreatedNotification(resourceType, resourceURIList);
+ }
+ }
+
+ public synchronized void createResource(String configFilePath,
+ int noOfInstances) {
+ Map<String, SimulatorResource> resourceTypeMap;
+ List<String> resourceUriList;
+ Vector<SimulatorResourceServer> simulatorResourceServerVectorN = null;
+ simulatorResourceServerVectorN = SimulatorManager.createResource(
+ configFilePath, noOfInstances);
+ if (null != simulatorResourceServerVectorN) {
+ resourceTypeMap = new HashMap<String, SimulatorResource>();
+ resourceUriList = new ArrayList<String>();
+ Enumeration<SimulatorResourceServer> uriItr = simulatorResourceServerVectorN
+ .elements();
+ SimulatorResourceServer resourceServerN;
+ SimulatorResource resource;
+ String uri;
+ while (uriItr.hasMoreElements()) {
+ resourceServerN = uriItr.nextElement();
+ resource = fetchResourceData(resourceServerN);
+ if (null != resource) {
+ uri = resource.getResourceURI();
+ resourceUriList.add(uri);
+ resourceTypeMap.put(uri, resource);
+ }
+ }
+
+ // Find the resourceType and add it to the local data structure and
+ // notify UI Listeners
+ if (resourceTypeMap.size() > 0) {
+ String resourceType;
+ Set<String> uriSet = resourceTypeMap.keySet();
+ if (null != uriSet) {
+ Iterator<String> itr = uriSet.iterator();
+ if (itr.hasNext()) {
+ SimulatorResource simResource = resourceTypeMap.get(itr
+ .next());
+ if (null != simResource) {
+ resourceType = simResource.getResourceType();
+
+ addResourceToMap(resourceType, resourceTypeMap);
+
+ resourceCreatedNotification(resourceType,
+ resourceUriList);
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ private synchronized SimulatorResource fetchResourceData(
+ SimulatorResourceServer resourceServerN) {
+ SimulatorResource simulatorResource = null;
+ if (null != resourceServerN) {
+ Map<String, ResourceAttribute> resourceAttributeMap = null;
+
+ simulatorResource = new SimulatorResource();
+ simulatorResource.setResourceServer(resourceServerN);
+ simulatorResource.setResourceURI(resourceServerN.getURI());
+ simulatorResource
+ .setResourceType(resourceServerN.getResourceType());
+ simulatorResource.setResourceName(resourceServerN.getName());
+ simulatorResource.setResourceInterface(resourceServerN
+ .getInterfaceType());
+
+ SimulatorResourceModel resourceModelN = resourceServerN.getModel();
+ if (null != resourceModelN) {
+ simulatorResource.setResourceModel(resourceModelN);
+
+ Map<String, SimulatorResourceAttribute> attributeMapN;
+ attributeMapN = resourceModelN.getAttributes();
+ if (null != attributeMapN) {
+ resourceAttributeMap = new HashMap<String, ResourceAttribute>();
+
+ Set<String> attNameSet = attributeMapN.keySet();
+ if (null != attNameSet) {
+ String attName;
+ SimulatorResourceAttribute attributeN;
+ ResourceAttribute attribute;
+ Iterator<String> attNameItr = attNameSet.iterator();
+ while (attNameItr.hasNext()) {
+ attName = attNameItr.next();
+ attributeN = attributeMapN.get(attName);
+ if (null != attributeN) {
+ attribute = new ResourceAttribute();
+ attribute.setAttributeName(attName);
+
+ // Other attribute details such as value,
+ // allowed values and range are based on type
+ // Type implementation is yet to be done
+ resourceAttributeMap.put(attName, attribute);
+ }
+ }
+ simulatorResource
+ .setResourceAttributesMap(resourceAttributeMap);
+ }
+ }
+ }
+ }
+ return simulatorResource;
+ }
+
+ private synchronized void resourceCreatedNotification(String resourceType,
+ List<String> resourceURIList) {
+ if (null != resourceType && null != resourceURIList
+ && null != resourceListChangedListener) {
+ resourceListChangedListener.onResourceCreation(resourceType,
+ resourceURIList);
+ }
+ }
+
+ public synchronized void deleteResourceByURI(String resourceURI) {
+ if (null != resourceURI) {
+ SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+ if (null != resource) {
+ String resourceType = resource.getResourceType();
+
+ // Unregister the resource from the platform
+ deleteResource(resource);
+
+ // Delete from the local data structure
+ deleteLocalResourceDetails(resourceType, resourceURI);
+
+ // Notify the UI listener for removing this resource from UI
+ resourceDeletedNotification(resourceType, resourceURI);
+ }
+ }
+ }
+
+ private synchronized SimulatorResource getSimulatorResourceByURI(
+ String resourceURI) {
+ SimulatorResource resource = null;
+ if (null != resourceURI) {
+ Set<String> typeSet = resourceMap.keySet();
+ if (null != typeSet) {
+ Iterator<String> typeItr = typeSet.iterator();
+ String resourceType;
+ Map<String, SimulatorResource> resourceTypeMap;
+ while (typeItr.hasNext()) {
+ resourceType = typeItr.next();
+ resourceTypeMap = resourceMap.get(resourceType);
+ if (null != resourceTypeMap) {
+ resource = resourceTypeMap.get(resourceURI);
+ if (null != resource) {
+ break;
+ }
+ }
+ }
+ }
+ }
+ return resource;
+ }
+
+ private synchronized void deleteResource(SimulatorResource resource) {
+ if (null != resource) {
+ SimulatorResourceServer resourceServerN = resource
+ .getResourceServer();
+ if (null != resourceServerN) {
+ SimulatorManager.deleteResource(resourceServerN);
+ }
+ }
+ }
+
+ public synchronized void deleteResourceByType(String resourceType) {
+ if (null != resourceType) {
+ // Unregister the resources from the platform
+ deleteResource(resourceType);
+
+ // Delete from the local data structure
+ deleteLocalResourceDetails(resourceType, null);
+
+ // Notify the UI listener for removing this resource from UI
+ resourceTypeDeletedNotification(resourceType);
+
+ }
+ }
+
+ private synchronized void deleteResource(String resourceType) {
+ if (null != resourceType) {
+ SimulatorManager.deleteResources(resourceType);
+ }
+ }
+
+ public synchronized void deleteAllResources() {
+ // Unregister the resources from the platform
+ deleteResource();
+
+ // Delete from the local data structure
+ deleteLocalResourceDetails(null, null);
+
+ // Notify the UI listener for removing this resource from UI
+ allResourcesDeletedNotification();
+ }
+
+ private synchronized void deleteResource() {
+ // SimulatorManager.deleteResources();
+ }
+
+ private synchronized void deleteLocalResourceDetails(String resourceType,
+ String resourceURI) {
+ if (null != resourceType && null != resourceURI) {
+ removeResourceFromMap(resourceType, resourceURI);
+ } else if (null != resourceType) {
+ resourceMap.remove(resourceType);
+ } else {
+ resourceMap.clear();
+ }
+ }
+
+ private synchronized void resourceDeletedNotification(String resourceType,
+ String resourceURI) {
+ if (null != resourceListChangedListener) {
+ resourceListChangedListener.onResourceDeletion(resourceType,
+ resourceURI);
+ }
+ }
+
+ private synchronized void resourceTypeDeletedNotification(
+ String resourceType) {
+ if (null != resourceListChangedListener) {
+ resourceListChangedListener.onResourceDeletionByType(resourceType);
+ }
+ }
+
+ private synchronized void allResourcesDeletedNotification() {
+ if (null != resourceListChangedListener) {
+ resourceListChangedListener.onAllResourceDeletion();
+ }
+ }
+
+ public synchronized IResourceListChangedListener getResourceListChangedListener() {
+ return resourceListChangedListener;
+ }
+
+ public synchronized void setResourceListChangedListener(
+ IResourceListChangedListener resourceListChangedListener) {
+ this.resourceListChangedListener = resourceListChangedListener;
+ }
+
+ public synchronized List<String> getResourceTypeList() {
+ List<String> typeList = null;
+ if (null != resourceMap && resourceMap.size() > 0) {
+ typeList = new ArrayList<String>();
+ Set<String> typeSet = resourceMap.keySet();
+ Iterator<String> typeItr = typeSet.iterator();
+ while (typeItr.hasNext()) {
+ typeList.add(typeItr.next());
+ }
+ }
+ return typeList;
+ }
+}
--- /dev/null
+package oic.simulator.serviceprovider.perspective;
+
+import oic.simulator.serviceprovider.view.AttributeView;
+import oic.simulator.serviceprovider.view.LogView;
+import oic.simulator.serviceprovider.view.MultiResourceOrchestrationView;
+import oic.simulator.serviceprovider.view.ResourceManagerView;
+
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+public class PerspectiveFactory implements IPerspectiveFactory {
+
+ public static final String PERSPECTIVE_ID = "oic.simulator.serviceprovider.perspective";
+ private IPageLayout factory;
+
+ @Override
+ public void createInitialLayout(IPageLayout factory) {
+ this.factory = factory;
+ factory.setEditorAreaVisible(false);
+ addViews();
+ factory.setFixed(false);
+ }
+
+ private void addViews() {
+ factory.addView(ResourceManagerView.VIEW_ID, IPageLayout.LEFT, 0.3f,
+ factory.getEditorArea());
+ factory.addView(IPageLayout.ID_PROP_SHEET, IPageLayout.BOTTOM, 0.6f,
+ ResourceManagerView.VIEW_ID);
+ factory.addView(AttributeView.VIEW_ID, IPageLayout.LEFT, 0.5f,
+ factory.getEditorArea());
+ factory.addView(LogView.VIEW_ID, IPageLayout.BOTTOM, 0.6f,
+ AttributeView.VIEW_ID);
+ factory.addView(MultiResourceOrchestrationView.VIEW_ID,
+ IPageLayout.RIGHT, 0.5f, AttributeView.VIEW_ID);
+ }
+}
--- /dev/null
+package oic.simulator.serviceprovider.resource;
+
+// TODO: Temporarily adding this enum in plugin. It will be removed once it is added to the java api sdk
+public enum AttributeValueType {
+ INTEGER, DOUBLE, STRING, BOOLEAN, ENUMERATION
+}
--- /dev/null
+package oic.simulator.serviceprovider.resource;
+
+import java.util.List;
+
+import org.iotivity.simulator.SimulatorResourceAttribute;
+
+public class ResourceAttribute {
+
+ // Native object reference
+ private SimulatorResourceAttribute resourceAttribute;
+
+ private String attributeName;
+ private Object attributeValue;
+ private AttributeValueType attributeType;
+ private List<Object> allowedValues;
+
+ private Object minValue;
+ private Object maxValue;
+
+ public SimulatorResourceAttribute getResourceAttribute() {
+ return resourceAttribute;
+ }
+
+ public void setResourceAttribute(
+ SimulatorResourceAttribute resourceAttribute) {
+ this.resourceAttribute = resourceAttribute;
+ }
+
+ public String getAttributeName() {
+ return attributeName;
+ }
+
+ public void setAttributeName(String attributeName) {
+ this.attributeName = attributeName;
+ }
+
+ public Object getAttributeValue() {
+ return attributeValue;
+ }
+
+ public void setAttributeValue(Object attributeValue) {
+ this.attributeValue = attributeValue;
+ }
+
+ public AttributeValueType getAttributeType() {
+ return attributeType;
+ }
+
+ public void setAttributeType(AttributeValueType attributeType) {
+ this.attributeType = attributeType;
+ }
+
+ public List<Object> getAllowedValues() {
+ return allowedValues;
+ }
+
+ public void setAllowedValues(List<Object> allowedValues) {
+ this.allowedValues = allowedValues;
+ }
+
+ public Object getMinValue() {
+ return minValue;
+ }
+
+ public void setMinValue(Object minValue) {
+ this.minValue = minValue;
+ }
+
+ public Object getMaxValue() {
+ return maxValue;
+ }
+
+ public void setMaxValue(Object maxValue) {
+ this.maxValue = maxValue;
+ }
+}
--- /dev/null
+package oic.simulator.serviceprovider.resource;
+
+import java.util.Map;
+
+import org.iotivity.simulator.SimulatorResourceModel;
+import org.iotivity.simulator.SimulatorResourceServer;
+
+public class SimulatorResource {
+ private String resourceURI;
+ private String resourceName;
+ private String resourceType;
+ private String resourceInterface;
+
+ // Reference to objects created in native layer
+ // Native methods can be invoked using these object references
+ private SimulatorResourceServer resourceServer;
+ private SimulatorResourceModel resourceModel;
+
+ private Map<String, ResourceAttribute> resourceAttributesMap;
+
+ public String getResourceURI() {
+ return resourceURI;
+ }
+
+ public void setResourceURI(String resourceURI) {
+ this.resourceURI = resourceURI;
+ }
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ public void setResourceName(String resourceName) {
+ this.resourceName = resourceName;
+ }
+
+ public String getResourceType() {
+ return resourceType;
+ }
+
+ public void setResourceType(String resourceType) {
+ this.resourceType = resourceType;
+ }
+
+ public String getResourceInterface() {
+ return resourceInterface;
+ }
+
+ public void setResourceInterface(String resourceInterface) {
+ this.resourceInterface = resourceInterface;
+ }
+
+ public SimulatorResourceServer getResourceServer() {
+ return resourceServer;
+ }
+
+ public void setResourceServer(SimulatorResourceServer resourceServer) {
+ this.resourceServer = resourceServer;
+ }
+
+ public SimulatorResourceModel getResourceModel() {
+ return resourceModel;
+ }
+
+ public void setResourceModel(SimulatorResourceModel resourceModel) {
+ this.resourceModel = resourceModel;
+ }
+
+ public Map<String, ResourceAttribute> getResourceAttributesMap() {
+ return resourceAttributesMap;
+ }
+
+ public void setResourceAttributesMap(
+ Map<String, ResourceAttribute> resourceAttributesMap) {
+ this.resourceAttributesMap = resourceAttributesMap;
+ }
+
+}
--- /dev/null
+package oic.simulator.serviceprovider.resource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class StandardConfiguration {
+
+ private String configuration_directory_path;
+
+ // A map of resourceType of standard resources as the key and the complete
+ // location of the file as
+ // the value
+ Map<String, String> standardResourceConfigurationMap;
+
+ public StandardConfiguration() {
+ standardResourceConfigurationMap = new HashMap<String, String>();
+ }
+
+ public String getConfiguration_directory_path() {
+ return configuration_directory_path;
+ }
+
+ public void setConfiguration_directory_path(
+ String configuration_directory_path) {
+ this.configuration_directory_path = configuration_directory_path;
+ }
+
+ public Map<String, String> getStandardResourceConfigurationList() {
+ return standardResourceConfigurationMap;
+ }
+
+ public void setStandardResourceConfigurationList(
+ Map<String, String> standardResourceConfigurationList) {
+ this.standardResourceConfigurationMap = standardResourceConfigurationList;
+ }
+
+ public void addResourceConfiguration(String resourceType,
+ String absolutePath) {
+ if (null != resourceType && resourceType.length() > 0
+ && null != absolutePath && absolutePath.length() > 0) {
+ standardResourceConfigurationMap.put(resourceType, absolutePath);
+ }
+ }
+
+ public String getResourceConfigFilePath(String resourceType) {
+ String path = null;
+ if (null != resourceType && resourceType.length() > 0) {
+ path = standardResourceConfigurationMap.get(resourceType);
+ }
+ return path;
+ }
+
+ public void removeResourceFromConfiguration(String resourceType) {
+ if (null != resourceType && resourceType.length() > 0) {
+ standardResourceConfigurationMap.remove(resourceType);
+ }
+ }
+}
--- /dev/null
+package oic.simulator.serviceprovider.utils;
+
+public class Constants {
+ public static final String UNDERSCORE = "_";
+ public static final String FORWARD_SLASH = "/";
+ public static final String OIC = "oic";
+ public static final String SIMULATOR = "simulator";
+
+ public static final int PROPER_RESOURCE_URI_TOKEN_COUNT = 5;
+}
--- /dev/null
+package oic.simulator.serviceprovider.utils;
+
+public class Convertion {
+
+ public static String uriToDisplayName(String uri) {
+ String result = null;
+ if (null != uri) {
+ String tokens[] = uri.split(Constants.FORWARD_SLASH);
+ System.out.println(uri);
+ System.out.println(tokens.length);
+ if (Constants.PROPER_RESOURCE_URI_TOKEN_COUNT == tokens.length) {
+ // Proper URI
+ result = tokens[2] + Constants.UNDERSCORE + tokens[4];
+ }
+ }
+ return result;
+ }
+
+ public static String displayNameToUri(String displayName) {
+ String result = null;
+ if (null != displayName) {
+ String tokens[] = displayName.split(Constants.UNDERSCORE);
+ if (2 == tokens.length) {
+ // Proper Display Name
+ result = Constants.FORWARD_SLASH + Constants.OIC
+ + Constants.FORWARD_SLASH + tokens[0]
+ + Constants.FORWARD_SLASH + Constants.SIMULATOR
+ + Constants.FORWARD_SLASH + tokens[1];
+ }
+ }
+ return result;
+ }
+
+ public static boolean isUriComplete(String uri) {
+ boolean uriComplete = false;
+ if (null != uri) {
+ String tokens[] = uri.split(Constants.FORWARD_SLASH);
+ System.out.println(uri);
+ System.out.println(tokens.length);
+ if (Constants.PROPER_RESOURCE_URI_TOKEN_COUNT == tokens.length) {
+ uriComplete = true;
+ }
+ }
+ return uriComplete;
+ }
+}
--- /dev/null
+package oic.simulator.serviceprovider.view;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.ViewPart;
+
+public class AttributeView extends ViewPart {
+
+ public static final String VIEW_ID = "oic.simulator.serviceprovider.view.attribute";
+
+ @Override
+ public void createPartControl(Composite arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setFocus() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
--- /dev/null
+package oic.simulator.serviceprovider.view;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.ViewPart;
+
+public class LogView extends ViewPart {
+
+ public static final String VIEW_ID = "oic.simulator.serviceprovider.view.log";
+
+ @Override
+ public void createPartControl(Composite arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setFocus() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
--- /dev/null
+package oic.simulator.serviceprovider.view;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.ViewPart;
+
+public class MultiResourceOrchestrationView extends ViewPart {
+
+ public static final String VIEW_ID = "oic.simulator.serviceprovider.view.orchestration";
+
+ @Override
+ public void createPartControl(Composite arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setFocus() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
--- /dev/null
+package oic.simulator.serviceprovider.view;
+
+import java.util.Iterator;
+import java.util.List;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.listener.IResourceListChangedListener;
+import oic.simulator.serviceprovider.manager.ResourceManager;
+import oic.simulator.serviceprovider.utils.Convertion;
+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;
+
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+
+public class ResourceManagerView extends ViewPart {
+
+ public static final String VIEW_ID = "oic.simulator.serviceprovider.view.resourcemanager";
+
+ private Button createButton;
+ private Button deleteButton;
+
+ private Tree resourceTreeHead;
+
+ private IResourceListChangedListener resourceListChangedListener;
+
+ public ResourceManagerView() {
+ resourceListChangedListener = new IResourceListChangedListener() {
+
+ @Override
+ public void onResourceCreation(String resourceType,
+ List<String> resourceURI) {
+ if (null != resourceTreeHead
+ && !(resourceTreeHead.isDisposed())
+ && null != resourceType && null != resourceURI) {
+ TreeItem resourceHead = null;
+ TreeItem[] items = resourceTreeHead.getItems();
+ if (null != items) {
+ for (TreeItem item : items) {
+ if (item.getText().equals(resourceType)) {
+ resourceHead = item;
+ break;
+ }
+ }
+ if (null == resourceHead) {
+ // Adding a new tree header
+ resourceHead = new TreeItem(resourceTreeHead,
+ SWT.NULL);
+ resourceHead.setText(resourceType);
+ }
+ // Add resources under the resourceHead
+ Iterator<String> uriItr = resourceURI.iterator();
+ while (uriItr.hasNext()) {
+ TreeItem newItem = new TreeItem(resourceHead,
+ SWT.NULL);
+ newItem.setText(Convertion.uriToDisplayName(uriItr
+ .next()));
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onResourceDeletion(String resourceType,
+ String resourceURI) {
+ if (null != resourceTreeHead
+ && !(resourceTreeHead.isDisposed())) {
+ TreeItem targetParent = null;
+ TreeItem[] headItems = resourceTreeHead.getItems();
+ if (null != headItems) {
+ for (TreeItem item : headItems) {
+ if (item.getText().equals(resourceType)) {
+ targetParent = item;
+ break;
+ }
+ }
+ if (null != targetParent) {
+ TreeItem[] items = targetParent.getItems();
+ for (TreeItem item : items) {
+ if (item.getText().equals(
+ Convertion
+ .uriToDisplayName(resourceURI))) {
+ item.dispose();
+ if (targetParent.getItemCount() < 1) {
+ targetParent.dispose();
+ }
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onResourceDeletionByType(String resourceType) {
+ if (null != resourceTreeHead
+ && !(resourceTreeHead.isDisposed())) {
+ TreeItem items[] = resourceTreeHead.getItems();
+ for (TreeItem item : items) {
+ if (item.getText().equals(resourceType)) {
+ item.dispose();
+ break;
+ }
+ }
+ }
+ }
+
+ public void onAllResourceDeletion() {
+ if (null != resourceTreeHead
+ && !(resourceTreeHead.isDisposed())) {
+ TreeItem[] items = resourceTreeHead.getItems();
+ if (null != items) {
+ for (TreeItem item : items) {
+ item.dispose();
+ }
+ }
+ }
+ }
+ };
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+ Composite compContent = new Composite(parent, SWT.NONE);
+ GridLayout baseLayout = new GridLayout(1, false);
+ compContent.setLayout(baseLayout);
+
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ compContent.setLayoutData(gd);
+
+ Composite buttonComp = new Composite(compContent, SWT.NONE);
+ buttonComp.setLayout(new GridLayout(2, false));
+
+ gd = new GridData();
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessHorizontalSpace = true;
+
+ buttonComp.setLayoutData(gd);
+
+ createButton = new Button(buttonComp, SWT.PUSH);
+ createButton.setText("Create");
+ createButton.setToolTipText("Create Simulator Resource(s)");
+
+ gd = new GridData();
+ gd.widthHint = 90;
+ createButton.setLayoutData(gd);
+
+ deleteButton = new Button(buttonComp, SWT.PUSH);
+ deleteButton.setText("Delete");
+ deleteButton.setToolTipText("Delete Simulator Resource(s)");
+
+ gd = new GridData();
+ gd.widthHint = 90;
+ deleteButton.setLayoutData(gd);
+
+ Group resourceGroup = new Group(compContent, SWT.NONE);
+ resourceGroup.setText("Created Resources");
+
+ Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+ resourceGroup.setBackground(color);
+
+ resourceGroup.setLayout(new GridLayout(1, false));
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ resourceGroup.setLayoutData(gd);
+
+ resourceTreeHead = new Tree(resourceGroup, SWT.SINGLE);
+
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+
+ resourceTreeHead.setLayoutData(gd);
+
+ addUIListeners();
+
+ addManagerListeners();
+ }
+
+ private void addUIListeners() {
+
+ createButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ CreateResourceWizard createWizard = new CreateResourceWizard();
+ ResourceWizardDialog wizardDialog = new ResourceWizardDialog(
+ PlatformUI.getWorkbench().getDisplay()
+ .getActiveShell(), createWizard);
+ int open = wizardDialog.open();
+ if (open == WizardDialog.OK) {
+ String configFilePath;
+ int count;
+ configFilePath = createWizard.getConfigFilePath();
+ count = createWizard.getResourceCount();
+
+ // Create the resource
+ if (null != configFilePath
+ && configFilePath.length() > 0) {
+ if (count <= 1) {
+ // Single resource creation
+ // TODO: Temporary code to show the resource
+ // in UI
+ Activator.getManager().createResource(
+ configFilePath);
+ } else {
+ // Multi resource creation
+ // Activator.getDefault().getManager().createResource(configFilePath,
+ // count);
+ }
+ }
+ }
+ }
+ });
+ }
+ });
+
+ deleteButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ DeleteResourceWizard deleteWizard = new DeleteResourceWizard();
+ ResourceWizardDialog wizardDialog = new ResourceWizardDialog(
+ PlatformUI.getWorkbench().getDisplay()
+ .getActiveShell(), deleteWizard);
+ int open = wizardDialog.open();
+ if (open == WizardDialog.OK) {
+ if (deleteWizard.getDeleteCategory() == DeleteCategory.BY_URI) {
+ String uri = deleteWizard.getDeleteCandidate();
+ boolean completeURI = Convertion
+ .isUriComplete(uri);
+ if (!completeURI) {
+ uri = Convertion.displayNameToUri(uri);
+ }
+ Activator.getManager().deleteResourceByURI(uri);
+ } else if (deleteWizard.getDeleteCategory() == DeleteCategory.BY_TYPE) {
+ Activator.getManager().deleteResourceByType(
+ deleteWizard.getDeleteCandidate());
+ } else if (deleteWizard.getDeleteCategory() == DeleteCategory.ALL) {
+ Activator.getManager().deleteAllResources();
+ }
+ }
+ }
+
+ });
+ }
+ });
+
+ resourceTreeHead.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ TreeItem[] selectedItems = resourceTreeHead.getSelection();
+ // Handling only single item selection events
+ if (1 == selectedItems.length) {
+ String selectedItem = selectedItems[0].getText();
+ // Check whether the selected item is a resource category or
+ // a specific resource
+ boolean category = isSelectedTreeItemACategory(selectedItem);
+ if (!category) {
+ // TODO: Show the properties in the properties view
+ }
+
+ }
+ }
+ });
+ }
+
+ private boolean isSelectedTreeItemACategory(String selectedItem) {
+ boolean category = false;
+ TreeItem[] items = resourceTreeHead.getItems();
+ if (null != items) {
+ for (TreeItem item : items) {
+ if (item.getText().equals(selectedItem)) {
+ category = true;
+ break;
+ }
+ }
+ }
+ return category;
+ }
+
+ public void addManagerListeners() {
+ ResourceManager manager = Activator.getManager();
+ manager.setResourceListChangedListener(resourceListChangedListener);
+ }
+
+ @Override
+ public void setFocus() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
--- /dev/null
+package oic.simulator.serviceprovider.view.dialogs;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+
+public class CreateResourcePage extends WizardPage {
+
+ private Button stdResourceRbtn;
+ private CCombo resourceTypeCmb;
+ private Button cusResourceRbtn;
+ private Text locationTxt;
+ private Button btnBrowse;
+ private Text noOfInstancesText;
+ private Label resourceTypeLbl;
+ private Label noOfInstancesLbl;
+ private Label locationLbl;
+
+ private String configFilePath = null;
+ private int resourceCount;
+
+ protected CreateResourcePage() {
+ super("Create Resource");
+ resourceCount = -1;
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ setPageComplete(false);
+ setTitle("Create Resource");
+ setMessage("Select a standard resource or custom resource to be created");
+ Composite compContent = new Composite(parent, SWT.NONE);
+ GridLayout gridLayout = new GridLayout(1, false);
+ compContent.setLayout(gridLayout);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ compContent.setLayoutData(gd);
+
+ Group configGroup = new Group(compContent, SWT.NONE);
+ gridLayout = new GridLayout(1, false);
+ gridLayout.verticalSpacing = 10;
+ gridLayout.marginTop = 5;
+ configGroup.setLayout(gridLayout);
+ gd = new GridData();
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessHorizontalSpace = true;
+ configGroup.setLayoutData(gd);
+ configGroup.setText("Configuration File Type");
+
+ stdResourceRbtn = new Button(configGroup, SWT.RADIO);
+ stdResourceRbtn.setText("Standard Configuration");
+
+ Composite stdConfigComp = new Composite(configGroup, SWT.NONE);
+ stdConfigComp.setLayout(new GridLayout(2, false));
+ gd = new GridData();
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessHorizontalSpace = true;
+ stdConfigComp.setLayoutData(gd);
+
+ resourceTypeLbl = new Label(stdConfigComp, SWT.NONE);
+ resourceTypeLbl.setText("ResourceType:");
+ resourceTypeLbl.setEnabled(false);
+
+ resourceTypeCmb = new CCombo(stdConfigComp, SWT.READ_ONLY | SWT.BORDER);
+ gd = new GridData();
+ gd.widthHint = 150;
+ resourceTypeCmb.setLayoutData(gd);
+ resourceTypeCmb.setEnabled(false);
+
+ cusResourceRbtn = new Button(configGroup, SWT.RADIO);
+ cusResourceRbtn.setText("Custom Configuration");
+
+ Composite cusConfigComp = new Composite(configGroup, SWT.NONE);
+ cusConfigComp.setLayout(new GridLayout(3, false));
+ gd = new GridData();
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessHorizontalSpace = true;
+ cusConfigComp.setLayoutData(gd);
+
+ locationLbl = new Label(cusConfigComp, SWT.NONE);
+ locationLbl.setText("Location:");
+ locationLbl.setEnabled(false);
+
+ locationTxt = new Text(cusConfigComp, SWT.BORDER);
+ gd = new GridData();
+ gd.minimumWidth = 300;
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessHorizontalSpace = true;
+ locationTxt.setLayoutData(gd);
+ locationTxt.setEnabled(false);
+
+ btnBrowse = new Button(cusConfigComp, SWT.NONE);
+ btnBrowse.setText("Browse");
+ gd = new GridData();
+ gd.widthHint = 80;
+ gd.horizontalAlignment = SWT.FILL;
+ btnBrowse.setLayoutData(gd);
+ btnBrowse.setEnabled(false);
+
+ Composite instanceComp = new Composite(compContent, SWT.NONE);
+ instanceComp.setLayout(new GridLayout(2, false));
+ gd = new GridData();
+ gd.horizontalAlignment = SWT.FILL;
+ gd.grabExcessHorizontalSpace = true;
+ instanceComp.setLayoutData(gd);
+
+ noOfInstancesLbl = new Label(instanceComp, SWT.NONE);
+ noOfInstancesLbl.setText("Number of Instances");
+
+ noOfInstancesText = new Text(instanceComp, SWT.BORDER);
+ gd = new GridData();
+ gd.widthHint = 50;
+ gd.horizontalAlignment = SWT.FILL;
+ noOfInstancesText.setLayoutData(gd);
+
+ // Adding the default value. It can be changed by the user.
+ noOfInstancesText.setText("1");
+
+ populateDataInUI();
+
+ addUIListeners();
+
+ setControl(compContent);
+ }
+
+ private void populateDataInUI() {
+ // Populate Resourcetype in Combo
+ populateResourceTypeCombo();
+ }
+
+ private void populateResourceTypeCombo() {
+ /*
+ * List<String> configList; configList =
+ * Activator.getDefault().getManager().getResourceConfigurationList();
+ * if(null != configList) { Iterator<String> itr =
+ * configList.iterator(); while(itr.hasNext()) {
+ * resourceTypeCmb.add(itr.next()); } }
+ */
+
+ // TODO: Temporarily adding a resourceType for testing
+ resourceTypeCmb.add("oic.light");
+
+ // By default, selecting the first item in the resourceType combo
+ if (resourceTypeCmb.getItemCount() > 0) {
+ resourceTypeCmb.select(0);
+ // TODO: Get the RAML configuration file path of the selected
+ // resource
+ // configFilePath =
+ // Activator.getManager().getConfigFilePath(resourceTypeCmb.getItem(0));
+ }
+ }
+
+ private void addUIListeners() {
+ stdResourceRbtn.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
+ // Set the configFilePath to the first item in the combo
+ if (resourceTypeCmb.getItemCount() > 0)
+ resourceTypeCmb.select(0);
+
+ // TODO: Temporarily adding some random config file path
+ // To be removed after implementing resource configuration
+ configFilePath = "/Samplelight";
+
+ setPageComplete(isSelectionDone());
+
+ // Change the visibility of widgets
+ resourceTypeLbl.setEnabled(true);
+ resourceTypeCmb.setEnabled(true);
+ locationLbl.setEnabled(false);
+ locationTxt.setEnabled(false);
+ btnBrowse.setEnabled(false);
+
+ }
+ });
+
+ cusResourceRbtn.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ setPageComplete(isSelectionDone());
+
+ // Change the visibility of widgets
+ locationLbl.setEnabled(true);
+ locationTxt.setEnabled(true);
+ btnBrowse.setEnabled(true);
+ resourceTypeLbl.setEnabled(false);
+ resourceTypeCmb.setEnabled(false);
+
+ }
+ });
+
+ btnBrowse.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ FileDialog fileDialog = new FileDialog(PlatformUI
+ .getWorkbench().getDisplay().getActiveShell(), SWT.NONE);
+ String configFileAbsolutePath = fileDialog.open();
+ locationTxt.setText(configFileAbsolutePath);
+ }
+ });
+
+ resourceTypeCmb.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int index = resourceTypeCmb.getSelectionIndex();
+ if (index >= 0) {
+ String selectedItem = resourceTypeCmb.getItem(index);
+ if (null != selectedItem) {
+ // TODO: Get the RAML configuration file path of the
+ // selected resource
+ // configFilePath =
+ // Activator.getDefault().getManager().getConfigFilePath(selectedItem);
+
+ setPageComplete(isSelectionDone());
+ }
+ }
+ }
+ });
+
+ locationTxt.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ configFilePath = locationTxt.getText();
+ setPageComplete(isSelectionDone());
+ }
+ });
+
+ noOfInstancesText.addListener(SWT.Verify, new Listener() {
+ @Override
+ public void handleEvent(Event e) {
+ String string = e.text;
+ char[] chars = new char[string.length()];
+ string.getChars(0, chars.length, chars, 0);
+ for (int i = 0; i < chars.length; i++) {
+ if (!('0' <= chars[i] && chars[i] <= '9')) {
+ e.doit = false;
+ return;
+ }
+ }
+ }
+ });
+
+ noOfInstancesText.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyReleased(KeyEvent e) {
+ setPageComplete(isSelectionDone());
+ }
+ });
+ }
+
+ public boolean isSelectionDone() {
+ boolean done = false;
+ try {
+ resourceCount = Integer.parseInt(noOfInstancesText.getText());
+ } catch (Exception e) {
+ resourceCount = -1;
+ }
+ if (cusResourceRbtn.getSelection()) {
+ configFilePath = locationTxt.getText();
+ }
+
+ if (null != configFilePath && configFilePath.length() > 0
+ && resourceCount >= 0) {
+ done = true;
+ }
+ return done;
+ }
+
+ public String getConfigFilePath() {
+ return configFilePath;
+ }
+
+ public int getResourceCount() {
+ return resourceCount;
+ }
+
+}
--- /dev/null
+package oic.simulator.serviceprovider.view.dialogs;
+
+import org.eclipse.jface.wizard.Wizard;
+
+public class CreateResourceWizard extends Wizard {
+
+ private CreateResourcePage page;
+
+ public CreateResourceWizard() {
+ setWindowTitle("Create resources");
+ }
+
+ @Override
+ public void addPages() {
+ page = new CreateResourcePage();
+ addPage(page);
+ }
+
+ public String getConfigFilePath() {
+ return page.getConfigFilePath();
+ }
+
+ public int getResourceCount() {
+ return page.getResourceCount();
+ }
+
+ @Override
+ public boolean performFinish() {
+ return true;
+ }
+
+}
--- /dev/null
+package oic.simulator.serviceprovider.view.dialogs;
+
+public enum DeleteCategory {
+ ALL, BY_TYPE, BY_URI, NONE
+}
--- /dev/null
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.Iterator;
+import java.util.List;
+
+import oic.simulator.serviceprovider.Activator;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Text;
+
+public class DeleteResourcePage extends WizardPage {
+
+ private Button allRbtn;
+ private Button byTypeRbtn;
+ private Button byUriRbtn;
+
+ private CCombo resourceTypeCmb;
+ private Text resourceUriTxt;
+
+ private DeleteCategory deleteCategory;
+
+ // It will hold either the resource type or resource uri
+ private String deleteCandidate;
+
+ protected DeleteResourcePage() {
+ super("Delete Resource");
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ System.out.println("delete wizard open");
+ setPageComplete(false);
+ setTitle("Delete Resource");
+ setMessage("Select the resource(s) to be deleted");
+
+ Composite compContent = new Composite(parent, SWT.NONE);
+ compContent.setLayout(new GridLayout(1, false));
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ compContent.setLayoutData(gd);
+
+ Group group = new Group(compContent, SWT.NONE);
+ group.setText("Select Category");
+ GridLayout gridLayout = new GridLayout(2, false);
+ gridLayout.verticalSpacing = 15;
+ gridLayout.marginTop = 10;
+ gridLayout.marginLeft = 10;
+ group.setLayout(gridLayout);
+ gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+ group.setLayoutData(gd);
+
+ allRbtn = new Button(group, SWT.RADIO);
+ allRbtn.setText("All resources");
+ gd = new GridData();
+ gd.horizontalSpan = 2;
+ gd.widthHint = 200;
+ allRbtn.setLayoutData(gd);
+
+ byTypeRbtn = new Button(group, SWT.RADIO);
+ byTypeRbtn.setText("All (By resource type)");
+ gd = new GridData();
+ gd.widthHint = 200;
+ byTypeRbtn.setLayoutData(gd);
+
+ resourceTypeCmb = new CCombo(group, SWT.READ_ONLY | SWT.BORDER);
+ gd = new GridData();
+ gd.widthHint = 200;
+ resourceTypeCmb.setLayoutData(gd);
+
+ byUriRbtn = new Button(group, SWT.RADIO);
+ byUriRbtn.setText("By Resource URI");
+ gd = new GridData();
+ gd.widthHint = 200;
+ byUriRbtn.setLayoutData(gd);
+
+ resourceUriTxt = new Text(group, SWT.BORDER);
+ gd = new GridData();
+ gd.widthHint = 300;
+ resourceUriTxt.setLayoutData(gd);
+
+ // Setting the initial visibility of controls
+ allRbtn.setSelection(false);
+ byTypeRbtn.setSelection(false);
+ byUriRbtn.setSelection(false);
+
+ resourceTypeCmb.setEnabled(false);
+ resourceUriTxt.setEnabled(false);
+
+ deleteCategory = DeleteCategory.NONE;
+
+ populateDataInUI();
+
+ addUIListeners();
+
+ setControl(compContent);
+ }
+
+ private void populateDataInUI() {
+ // Populate Resourcetype in Combo
+ populateResourceTypeCombo();
+ }
+
+ private void populateResourceTypeCombo() {
+
+ List<String> resourceTypeList;
+ resourceTypeList = Activator.getManager().getResourceTypeList();
+ if (null != resourceTypeList) {
+ Iterator<String> itr = resourceTypeList.iterator();
+ while (itr.hasNext()) {
+ resourceTypeCmb.add(itr.next());
+ }
+ }
+
+ // By default, select the first item in the combo
+ if (resourceTypeCmb.getItemCount() > 0) {
+ resourceTypeCmb.select(0);
+ deleteCandidate = resourceTypeCmb.getItem(resourceTypeCmb
+ .getSelectionIndex());
+ }
+ }
+
+ public void addUIListeners() {
+ allRbtn.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ // Update the visibility of controls
+ resourceTypeCmb.setEnabled(false);
+ resourceUriTxt.setEnabled(false);
+
+ deleteCategory = DeleteCategory.ALL;
+ deleteCandidate = null;
+ setPageComplete(isSelectionDone());
+ }
+ });
+
+ byTypeRbtn.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ // Update the visibility of controls
+ resourceTypeCmb.setEnabled(true);
+ resourceUriTxt.setEnabled(false);
+
+ deleteCategory = DeleteCategory.BY_TYPE;
+ setPageComplete(isSelectionDone());
+ }
+ });
+
+ byUriRbtn.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ // Update the visibility of controls
+ resourceUriTxt.setEnabled(true);
+ resourceTypeCmb.setEnabled(false);
+
+ deleteCategory = DeleteCategory.BY_URI;
+ setPageComplete(isSelectionDone());
+ }
+ });
+
+ resourceTypeCmb.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent arg0) {
+ setPageComplete(isSelectionDone());
+ }
+ });
+
+ resourceUriTxt.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent arg0) {
+ setPageComplete(isSelectionDone());
+ }
+ });
+ }
+
+ public boolean isSelectionDone() {
+ boolean done = false;
+ if (deleteCategory == DeleteCategory.ALL) {
+ done = true;
+ } else if (deleteCategory == DeleteCategory.BY_TYPE) {
+ int selectedItemIndex = resourceTypeCmb.getSelectionIndex();
+ if (selectedItemIndex >= 0) {
+ deleteCandidate = resourceTypeCmb.getItem(selectedItemIndex);
+ if (null != deleteCandidate && deleteCandidate.length() > 0) {
+ done = true;
+ }
+ }
+ } else if (deleteCategory == DeleteCategory.BY_URI) {
+ deleteCandidate = resourceUriTxt.getText();
+ if (null != deleteCandidate && deleteCandidate.length() > 0) {
+ done = true;
+ }
+ }
+ return done;
+ }
+
+ public DeleteCategory getDeleteCategory() {
+ return deleteCategory;
+ }
+
+ public String getDeleteCandidate() {
+ return deleteCandidate;
+ }
+
+ public void setFocusToTextBox() {
+ resourceUriTxt.setFocus();
+ }
+}
--- /dev/null
+package oic.simulator.serviceprovider.view.dialogs;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.utils.Convertion;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+public class DeleteResourceWizard extends Wizard {
+
+ private DeleteResourcePage page;
+
+ public DeleteResourceWizard() {
+ setWindowTitle("Delete resources");
+ }
+
+ @Override
+ public void addPages() {
+ page = new DeleteResourcePage();
+ addPage(page);
+ }
+
+ @Override
+ public boolean performFinish() {
+ // Check the existence of the resource if the user has entered the uri
+ if (page.getDeleteCategory() == DeleteCategory.BY_URI) {
+ // Check whether the uri is in full form or short form
+ // If it is in short form, expand it to its full form.
+ String uri = page.getDeleteCandidate();
+ boolean uriComplete = Convertion.isUriComplete(uri);
+ if (!uriComplete) {
+ uri = Convertion.displayNameToUri(uri);
+ }
+ boolean exist = Activator.getManager().isResourceExist(uri);
+ if (!exist) {
+ Shell activeShell = PlatformUI.getWorkbench().getDisplay()
+ .getActiveShell();
+ MessageDialog dialog = new MessageDialog(activeShell,
+ "Resource Not Found", null,
+ "No resource exist with the given URI.",
+ MessageDialog.INFORMATION, new String[] { "OK" }, 0);
+ dialog.open();
+ page.setFocusToTextBox();
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public DeleteCategory getDeleteCategory() {
+ return page.getDeleteCategory();
+ }
+
+ public String getDeleteCandidate() {
+ return page.getDeleteCandidate();
+ }
+}
--- /dev/null
+package oic.simulator.serviceprovider.view.dialogs;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+
+public class ResourceWizardDialog extends WizardDialog {
+
+ public ResourceWizardDialog(Shell parentShell, IWizard newWizard) {
+ super(parentShell, newWizard);
+ }
+
+ @Override
+ public boolean isHelpAvailable() {
+ return false;
+ }
+
+ @Override
+ public void finishPressed() {
+ super.finishPressed();
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ super.createButtonsForButtonBar(parent);
+ Button finishButton = getButton(IDialogConstants.FINISH_ID);
+ if (finishButton != null) {
+ finishButton.setText(IDialogConstants.OK_LABEL);
+ }
+ }
+
+}