From: G S Senthil Kumar Date: Thu, 23 Jul 2015 15:36:06 +0000 (+0530) Subject: Base layout of eclipse plugin for service provider. X-Git-Tag: 1.2.0+RC1~764^2~48 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e7d6bd0eb1604e7d4fbcfff7fd4a71763f25a31c;p=platform%2Fupstream%2Fiotivity.git Base layout of eclipse plugin for service provider. Change-Id: I55bc75a2005cb0df7672bb0fc02b8190750ee4a2 Signed-off-by: G S Senthil Kumar Reviewed-on: https://gerrit.iotivity.org/gerrit/1853 Reviewed-by: Uze Choi Tested-by: Uze Choi --- diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/.classpath b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/.classpath new file mode 100644 index 0000000..95052f6 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/.project b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/.project new file mode 100644 index 0000000..9a2dee2 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/.project @@ -0,0 +1,28 @@ + + + ServiceProviderPlugin + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/META-INF/MANIFEST.MF b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/META-INF/MANIFEST.MF new file mode 100644 index 0000000..821a2e6 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +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, + . diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/build.properties b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/build.properties new file mode 100644 index 0000000..a36114b --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + libs/,\ + icons/ diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/sample.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/sample.gif new file mode 100644 index 0000000..34fb3c9 Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/sample.gif differ diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/plugin.xml b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/plugin.xml new file mode 100644 index 0000000..3d8eaf7 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/plugin.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/Activator.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/Activator.java new file mode 100644 index 0000000..26c3043 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/Activator.java @@ -0,0 +1,69 @@ +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; + } + +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceListChangedListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceListChangedListener.java new file mode 100644 index 0000000..3140ec1 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceListChangedListener.java @@ -0,0 +1,13 @@ +package oic.simulator.serviceprovider.listener; + +import java.util.List; + +public interface IResourceListChangedListener { + public void onResourceCreation(String resourceType, List resourceURI); + + public void onResourceDeletion(String resourceType, String resourceURI); + + public void onResourceDeletionByType(String resourceType); + + public void onAllResourceDeletion(); +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java new file mode 100644 index 0000000..5f20998 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java @@ -0,0 +1,394 @@ +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> resourceMap; + + private StandardConfiguration stdConfig; + + private IResourceListChangedListener resourceListChangedListener; + + static { + System.loadLibrary("SimulatorManager"); + } + + public ResourceManager() { + resourceMap = new HashMap>(); + 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 getResourceConfigurationList() { + List resourceConfigurationList = new ArrayList(); + Map configMap = stdConfig + .getStandardResourceConfigurationList(); + if (null != configMap) { + Set keySet = configMap.keySet(); + if (null != keySet) { + Iterator 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 resourceTypeMap; + resourceTypeMap = resourceMap.get(simulatorResource + .getResourceType()); + if (null == resourceTypeMap) { + resourceTypeMap = new HashMap(); + resourceMap.put(simulatorResource.getResourceType(), + resourceTypeMap); + } + resourceTypeMap.put(simulatorResource.getResourceURI(), + simulatorResource); + } + } + + private synchronized void addResourceToMap(String resourceType, + Map newResourceTypeMap) { + if (null != resourceType && null != newResourceTypeMap) { + Map 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 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 resourceURIList = new ArrayList(); + resourceURIList.add(resourceURI); + + resourceCreatedNotification(resourceType, resourceURIList); + } + } + + public synchronized void createResource(String configFilePath, + int noOfInstances) { + Map resourceTypeMap; + List resourceUriList; + Vector simulatorResourceServerVectorN = null; + simulatorResourceServerVectorN = SimulatorManager.createResource( + configFilePath, noOfInstances); + if (null != simulatorResourceServerVectorN) { + resourceTypeMap = new HashMap(); + resourceUriList = new ArrayList(); + Enumeration 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 uriSet = resourceTypeMap.keySet(); + if (null != uriSet) { + Iterator 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 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 attributeMapN; + attributeMapN = resourceModelN.getAttributes(); + if (null != attributeMapN) { + resourceAttributeMap = new HashMap(); + + Set attNameSet = attributeMapN.keySet(); + if (null != attNameSet) { + String attName; + SimulatorResourceAttribute attributeN; + ResourceAttribute attribute; + Iterator 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 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 typeSet = resourceMap.keySet(); + if (null != typeSet) { + Iterator typeItr = typeSet.iterator(); + String resourceType; + Map 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 getResourceTypeList() { + List typeList = null; + if (null != resourceMap && resourceMap.size() > 0) { + typeList = new ArrayList(); + Set typeSet = resourceMap.keySet(); + Iterator typeItr = typeSet.iterator(); + while (typeItr.hasNext()) { + typeList.add(typeItr.next()); + } + } + return typeList; + } +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/perspective/PerspectiveFactory.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/perspective/PerspectiveFactory.java new file mode 100644 index 0000000..8c21587 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/perspective/PerspectiveFactory.java @@ -0,0 +1,36 @@ +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); + } +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/AttributeValueType.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/AttributeValueType.java new file mode 100644 index 0000000..f6aeff5 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/AttributeValueType.java @@ -0,0 +1,6 @@ +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 +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ResourceAttribute.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ResourceAttribute.java new file mode 100644 index 0000000..979dcc0 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ResourceAttribute.java @@ -0,0 +1,76 @@ +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 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 getAllowedValues() { + return allowedValues; + } + + public void setAllowedValues(List 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; + } +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/SimulatorResource.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/SimulatorResource.java new file mode 100644 index 0000000..5d383ff --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/SimulatorResource.java @@ -0,0 +1,78 @@ +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 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 getResourceAttributesMap() { + return resourceAttributesMap; + } + + public void setResourceAttributesMap( + Map resourceAttributesMap) { + this.resourceAttributesMap = resourceAttributesMap; + } + +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java new file mode 100644 index 0000000..d6e3333 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java @@ -0,0 +1,58 @@ +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 standardResourceConfigurationMap; + + public StandardConfiguration() { + standardResourceConfigurationMap = new HashMap(); + } + + 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 getStandardResourceConfigurationList() { + return standardResourceConfigurationMap; + } + + public void setStandardResourceConfigurationList( + Map 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); + } + } +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java new file mode 100644 index 0000000..1cf302d --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java @@ -0,0 +1,10 @@ +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; +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Convertion.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Convertion.java new file mode 100644 index 0000000..644bb8b --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Convertion.java @@ -0,0 +1,46 @@ +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; + } +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java new file mode 100644 index 0000000..932fe27 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java @@ -0,0 +1,22 @@ +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 + + } + +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/LogView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/LogView.java new file mode 100644 index 0000000..4615aa2 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/LogView.java @@ -0,0 +1,22 @@ +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 + + } + +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MultiResourceOrchestrationView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MultiResourceOrchestrationView.java new file mode 100644 index 0000000..b7832f2 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MultiResourceOrchestrationView.java @@ -0,0 +1,22 @@ +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 + + } + +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java new file mode 100644 index 0000000..ecbb8e6 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java @@ -0,0 +1,312 @@ +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 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 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 + + } + +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java new file mode 100644 index 0000000..b2c23ba --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java @@ -0,0 +1,294 @@ +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 configList; configList = + * Activator.getDefault().getManager().getResourceConfigurationList(); + * if(null != configList) { Iterator itr = + * configList.iterator(); while(itr.hasNext()) { + * resourceTypeCmb.add(itr.next()); } } + */ + + // TODO: Temporarily adding a resourceType for testing + resourceTypeCmb.add("oic.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; + } + +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java new file mode 100644 index 0000000..5d1e74f --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java @@ -0,0 +1,32 @@ +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; + } + +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteCategory.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteCategory.java new file mode 100644 index 0000000..c9cb692 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteCategory.java @@ -0,0 +1,5 @@ +package oic.simulator.serviceprovider.view.dialogs; + +public enum DeleteCategory { + ALL, BY_TYPE, BY_URI, NONE +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java new file mode 100644 index 0000000..bf1b32a --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java @@ -0,0 +1,217 @@ +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 resourceTypeList; + resourceTypeList = Activator.getManager().getResourceTypeList(); + if (null != resourceTypeList) { + Iterator 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(); + } +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java new file mode 100644 index 0000000..3d8fa0b --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java @@ -0,0 +1,59 @@ +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(); + } +} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/ResourceWizardDialog.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/ResourceWizardDialog.java new file mode 100644 index 0000000..0463020 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/ResourceWizardDialog.java @@ -0,0 +1,35 @@ +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); + } + } + +}