From b9ec115c802fd90dd47b7c40685353c26bfeade7 Mon Sep 17 00:00:00 2001 From: G S Senthil Kumar Date: Thu, 17 Dec 2015 08:44:49 +0530 Subject: [PATCH] Removed collection resource and device support from simulator plug-in. 1. Collection resource and device related UI has been removed from service provider eclipse plug-in. 2. This check-in also includes refactoring and fixing of minor UI bugs. Change-Id: I1b12620202d3a861c251afb8ae4e14c5a96b7b44 Signed-off-by: G S Senthil Kumar Reviewed-on: https://gerrit.iotivity.org/gerrit/4635 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../ClientControllerPlugin/.classpath | 2 +- .../clientcontroller/manager/ResourceManager.java | 457 +------ .../manager/UiListenerHandler.java | 368 +++++ .../remoteresource/AttributeElement.java | 16 + .../remoteresource/DeviceAndPlatformInfo.java | 16 + .../remoteresource/RemoteResource.java | 29 +- .../remoteresource/RemoteResourceAttribute.java | 199 --- .../remoteresource/ResourceRepresentation.java | 16 + .../utils/AttributeValueStringConverter.java | 16 + .../clientcontroller/utils/Constants.java | 12 +- .../simulator/clientcontroller/utils/Utility.java | 16 + .../view/AttributeEditingSupport.java | 3 - .../clientcontroller/view/AttributeView.java | 42 +- .../clientcontroller/view/MetaPropertiesView.java | 14 +- .../clientcontroller/view/ResourceManagerView.java | 6 +- .../view/dialogs/PostRequestDialog.java | 1 + .../view/dialogs/PutRequestDialog.java | 2 +- .../listener/IDataChangeListener.java | 16 + .../listener/IPropertiesChangedListener.java | 2 - .../listener/ISelectionChangedListener.java | 3 - .../simulator/serviceprovider/manager/Data.java | 154 +-- .../serviceprovider/manager/ImageManager.java | 5 - .../serviceprovider/manager/ResourceManager.java | 930 +------------ .../serviceprovider/manager/UiListenerHandler.java | 19 - .../serviceprovider/model/AttributeElement.java | 16 + .../serviceprovider/model/CollectionResource.java | 221 --- .../serviceprovider/model/DeleteCategory.java | 24 - .../simulator/serviceprovider/model/Device.java | 117 -- .../model/ModelChangeNotificationType.java | 24 - .../simulator/serviceprovider/model/Resource.java | 91 +- .../serviceprovider/model/ResourceCategory.java | 21 - .../model/ResourceRepresentation.java | 16 + .../serviceprovider/model/ResourceType.java | 2 +- .../serviceprovider/model/SingleResource.java | 75 +- .../utils/AttributeValueStringConverter.java | 16 + .../simulator/serviceprovider/utils/Constants.java | 212 +-- .../simulator/serviceprovider/utils/Utility.java | 366 ++--- .../view/AttributeEditingSupport.java | 88 +- .../serviceprovider/view/AttributeView.java | 44 +- .../serviceprovider/view/MetaPropertiesView.java | 127 +- .../serviceprovider/view/ResourceManagerView.java | 1407 ++------------------ .../serviceprovider/view/ResourceObserverView.java | 9 +- .../view/dialogs/AddAttributeDialog.java | 44 +- .../view/dialogs/AddResourceToCollections.java | 206 --- .../view/dialogs/AddResourceToDevices.java | 205 --- .../serviceprovider/view/dialogs/AddResources.java | 207 --- .../view/dialogs/AddResourcesToCollectionPage.java | 169 --- .../CollectionResourceBasicDetailsPage.java | 343 ----- .../view/dialogs/CreateResourceWizard.java | 305 +---- .../view/dialogs/DeleteResourcePage.java | 197 +-- .../view/dialogs/DeleteResourceWizard.java | 26 +- .../serviceprovider/view/dialogs/DevicePage.java | 207 --- .../serviceprovider/view/dialogs/LoadRamlPage.java | 32 +- .../serviceprovider/view/dialogs/MainPage.java | 86 +- .../dialogs/RemoveResourceFromCollections.java | 206 --- .../view/dialogs/RemoveResourceFromDevices.java | 205 --- .../view/dialogs/RemoveResources.java | 207 --- .../view/dialogs/ResourceWizardDialog.java | 17 +- .../dialogs/SimpleResourceAddAttributePage.java | 25 +- .../dialogs/SimpleResourceBasicDetailsPage.java | 167 +-- .../dialogs/SimpleResourceOtherDetailsPage.java | 16 + .../view/dialogs/StartStopResourcePage.java | 17 +- .../view/dialogs/UpdatePropertiesPage.java | 36 +- .../dialogs/UpdateResourceInterfaceDialog.java | 122 ++ 64 files changed, 1432 insertions(+), 6833 deletions(-) create mode 100644 service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/UiListenerHandler.java delete mode 100644 service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/CollectionResource.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/DeleteCategory.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Device.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ModelChangeNotificationType.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceCategory.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToCollections.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToDevices.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResources.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourcesToCollectionPage.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CollectionResourceBasicDetailsPage.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DevicePage.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromCollections.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromDevices.java delete mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResources.java create mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateResourceInterfaceDialog.java diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/.classpath b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/.classpath index cdbd8da..0cd2918 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/.classpath +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/.classpath @@ -3,6 +3,6 @@ - + diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java index c417fca..51d59c4 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java @@ -29,15 +29,6 @@ import java.util.Set; import java.util.Vector; import oic.simulator.clientcontroller.Activator; -import oic.simulator.clientcontroller.listener.IConfigurationUpload; -import oic.simulator.clientcontroller.listener.IDevicePlatformInfoUIListener; -import oic.simulator.clientcontroller.listener.IFindResourceUIListener; -import oic.simulator.clientcontroller.listener.IGetUIListener; -import oic.simulator.clientcontroller.listener.IObserveUIListener; -import oic.simulator.clientcontroller.listener.IPostUIListener; -import oic.simulator.clientcontroller.listener.IPutUIListener; -import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener; -import oic.simulator.clientcontroller.listener.IVerificationUIListener; import oic.simulator.clientcontroller.remoteresource.DeviceAndPlatformInfo; import oic.simulator.clientcontroller.remoteresource.MetaProperty; import oic.simulator.clientcontroller.remoteresource.RemoteResource; @@ -77,43 +68,33 @@ import org.oic.simulator.client.SimulatorRemoteResource.VerificationType; */ public class ResourceManager { - private Set lastKnownSearchTypes; + private Set lastKnownSearchTypes; - private RemoteResource currentResourceInSelection; + private RemoteResource currentResourceInSelection; - private FindResourceListener findResourceListener; - private GetResponseListener getListener; - private PutResponseListener putListener; - private PostResponseListener postListener; - private ObserveNotificationListener observeListener; - private VerificationListener verifyListener; - private DeviceListener deviceListener; - private PlatformListener platformListener; + private FindResourceListener findResourceListener; + private GetResponseListener getListener; + private PutResponseListener putListener; + private PostResponseListener postListener; + private ObserveNotificationListener observeListener; + private VerificationListener verifyListener; + private DeviceListener deviceListener; + private PlatformListener platformListener; - private ResponseSynchronizerThread synchronizerThread; + private ResponseSynchronizerThread synchronizerThread; - private Thread threadHandle; - - private List findResourceUIListeners; - private List resourceSelectionChangedUIListeners; - private List getUIListeners; - private List putUIListeners; - private List postUIListeners; - private List observeUIListeners; - private List verificationUIListeners; - private List configUploadUIListeners; - private List devicePlatformInfoUIListeners; + private Thread threadHandle; // Map with Server ID as key and the complete object as the value - private Map resourceMap; - private List favoriteResources; + private Map resourceMap; + private List favoriteResources; // Maintaining a list of resource URIs for favorite resources feature. - private List favoriteURIList; + private List favoriteURIList; // Maintaining a list of observed resource URIs. - private List observedResourceURIList; + private List observedResourceURIList; - private Map hostDeviceAndPlatformMap; + private Map hostDeviceAndPlatformMap; public ResourceManager() { resourceMap = new HashMap(); @@ -122,16 +103,6 @@ public class ResourceManager { observedResourceURIList = new ArrayList(); hostDeviceAndPlatformMap = new HashMap(); - findResourceUIListeners = new ArrayList(); - resourceSelectionChangedUIListeners = new ArrayList(); - getUIListeners = new ArrayList(); - putUIListeners = new ArrayList(); - postUIListeners = new ArrayList(); - observeUIListeners = new ArrayList(); - verificationUIListeners = new ArrayList(); - configUploadUIListeners = new ArrayList(); - devicePlatformInfoUIListeners = new ArrayList(); - findResourceListener = new FindResourceListener() { @Override @@ -157,9 +128,6 @@ public class ResourceManager { return; } - // Fetch the resource data - // RemoteResource resource = - // fetchResourceDetails(resourceN); RemoteResource resource = new RemoteResource(); resource.setRemoteResourceRef(resourceN); @@ -188,7 +156,8 @@ public class ResourceManager { addResourceDetails(resource); // Notify the UI listener - newResourceFoundNotification(resource); + UiListenerHandler.getInstance() + .newResourceFoundNotification(resource); Activator .getDefault() @@ -250,7 +219,7 @@ public class ResourceManager { } }; - // TODO: Listeners for device and platform information. + // Listeners for device and platform information. deviceListener = new DeviceListener() { @Override @@ -274,7 +243,8 @@ public class ResourceManager { } // Notify UI listeners - deviceInfoReceivedNotification(); + UiListenerHandler.getInstance() + .deviceInfoReceivedNotification(); } }); } @@ -303,7 +273,8 @@ public class ResourceManager { } // Notify UI listeners - platformInfoReceivedNotification(); + UiListenerHandler.getInstance() + .platformInfoReceivedNotification(); } }); } @@ -314,7 +285,6 @@ public class ResourceManager { public void onGetResponse(final String uid, final SimulatorResult result, final SimulatorResourceModel resourceModelN) { - System.out.println(result); if (result != SimulatorResult.SIMULATOR_OK) { Activator .getDefault() @@ -335,7 +305,8 @@ public class ResourceManager { resourceModelN); if (null != resource) { // Notify the UI listeners - getCompleteNotification(resource); + UiListenerHandler.getInstance() + .getCompleteNotification(resource); } } }); @@ -368,7 +339,8 @@ public class ResourceManager { resourceModelN); if (null != resource) { // Notify the UI listeners - putCompleteNotification(resource); + UiListenerHandler.getInstance() + .putCompleteNotification(resource); } } }); @@ -400,7 +372,8 @@ public class ResourceManager { resourceModelN); if (null != resource) { // Notify the UI listeners - postCompleteNotification(resource); + UiListenerHandler.getInstance() + .postCompleteNotification(resource); } } }); @@ -421,7 +394,8 @@ public class ResourceManager { resourceModelN); if (null != resource) { // Notify the UI listeners - observeCompleteNotification(resource); + UiListenerHandler.getInstance() + .observeCompleteNotification(resource); } } }); @@ -445,7 +419,9 @@ public class ResourceManager { int autoType = resource.getAutomationtype(autoId); // Notify the listeners. - verificationStartedNotification(resource, autoType); + UiListenerHandler.getInstance() + .verificationStartedNotification(resource, + autoType); } }); } @@ -466,7 +442,9 @@ public class ResourceManager { int autoType = resource.getAutomationtype(autoId); // Notify the listeners. - verificationCompletedNotification(resource, autoType); + UiListenerHandler.getInstance() + .verificationCompletedNotification(resource, + autoType); } }); } @@ -486,7 +464,9 @@ public class ResourceManager { int autoType = resource.getAutomationtype(autoId); // Notify the listeners. - verificationAbortedNotification(resource, autoType); + UiListenerHandler.getInstance() + .verificationAbortedNotification(resource, + autoType); } }); } @@ -511,8 +491,6 @@ public class ResourceManager { return null; } - // if(!resource.isConfigUploaded() || null == - // resource.getResourceModelRef()) SimulatorResourceModel resourceModel = resource.getResourceModelRef(); if (null == resourceModel) { resource.setResourceModelRef(resourceModelN); @@ -588,112 +566,6 @@ public class ResourceManager { } } - public void addResourceSelectionChangedUIListener( - IResourceSelectionChangedUIListener resourceSelectionChangedUIListener) { - synchronized (resourceSelectionChangedUIListeners) { - resourceSelectionChangedUIListeners - .add(resourceSelectionChangedUIListener); - } - } - - public void addGetUIListener(IGetUIListener getUIListener) { - synchronized (getUIListeners) { - getUIListeners.add(getUIListener); - } - } - - public void addPutUIListener(IPutUIListener putUIListener) { - synchronized (putUIListeners) { - putUIListeners.add(putUIListener); - } - } - - public void addPostUIListener(IPostUIListener postUIListener) { - synchronized (postUIListeners) { - postUIListeners.add(postUIListener); - } - } - - public void addObserveUIListener(IObserveUIListener observeUIListener) { - synchronized (observeUIListeners) { - observeUIListeners.add(observeUIListener); - } - } - - public void addVerificationUIListener( - IVerificationUIListener verificationUIListener) { - synchronized (verificationUIListeners) { - verificationUIListeners.add(verificationUIListener); - } - } - - public void addConfigUploadUIListener(IConfigurationUpload configListener) { - synchronized (configUploadUIListeners) { - configUploadUIListeners.add(configListener); - } - } - - public void addDevicePlatformInfoUIListener( - IDevicePlatformInfoUIListener deviceUIListener) { - synchronized (devicePlatformInfoUIListeners) { - devicePlatformInfoUIListeners.add(deviceUIListener); - } - } - - public void removeDevicePlatformInfoUIListener( - IDevicePlatformInfoUIListener platformUIListener) { - synchronized (devicePlatformInfoUIListeners) { - devicePlatformInfoUIListeners.remove(platformUIListener); - } - } - - public void removeResourceSelectionChangedUIListener( - IResourceSelectionChangedUIListener listener) { - synchronized (resourceSelectionChangedUIListeners) { - if (null != listener - && resourceSelectionChangedUIListeners.size() > 0) { - resourceSelectionChangedUIListeners.remove(listener); - } - } - } - - public void removeGetUIListener(IGetUIListener getUIListener) { - synchronized (getUIListeners) { - getUIListeners.remove(getUIListener); - } - } - - public void removePutUIListener(IPutUIListener putUIListener) { - synchronized (putUIListeners) { - putUIListeners.remove(putUIListener); - } - } - - public void removePostUIListener(IPostUIListener postUIListener) { - synchronized (postUIListeners) { - postUIListeners.remove(postUIListener); - } - } - - public void removeObserveUIListener(IObserveUIListener observeUIListener) { - synchronized (observeUIListeners) { - observeUIListeners.remove(observeUIListener); - } - } - - public void removeVerificationUIListener( - IVerificationUIListener verificationUIListener) { - synchronized (verificationUIListeners) { - verificationUIListeners.remove(verificationUIListener); - } - } - - public void removeConfigUploadUIListener(IConfigurationUpload configListener) { - synchronized (configUploadUIListeners) { - configUploadUIListeners.remove(configListener); - } - } - public void addResourcetoFavorites(RemoteResource resource) { if (null == resource) { return; @@ -771,24 +643,6 @@ public class ResourceManager { } } - public void addFindresourceUIListener(IFindResourceUIListener listener) { - if (null == listener) { - return; - } - synchronized (findResourceUIListeners) { - findResourceUIListeners.add(listener); - } - } - - public void removeFindresourceUIListener(IFindResourceUIListener listener) { - if (null == listener) { - return; - } - synchronized (findResourceUIListeners) { - findResourceUIListeners.remove(listener); - } - } - private boolean isUidExist(String uid) { boolean exist; synchronized (resourceMap) { @@ -808,201 +662,6 @@ public class ResourceManager { return resource; } - private void newResourceFoundNotification(RemoteResource resource) { - synchronized (findResourceUIListeners) { - if (findResourceUIListeners.size() > 0) { - IFindResourceUIListener listener; - Iterator listenerItr = findResourceUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onNewResourceFound(resource); - } - } - } - } - } - - private void resourceSelectionChangedUINotification(RemoteResource resource) { - synchronized (resourceSelectionChangedUIListeners) { - if (resourceSelectionChangedUIListeners.size() > 0) { - IResourceSelectionChangedUIListener listener; - Iterator listenerItr = resourceSelectionChangedUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onResourceSelectionChange(resource); - } - } - } - } - } - - private void getCompleteNotification(RemoteResource resource) { - synchronized (getUIListeners) { - if (getUIListeners.size() > 0) { - IGetUIListener listener; - Iterator listenerItr = getUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onGetCompleted(resource); - } - } - } - } - } - - private void putCompleteNotification(RemoteResource resource) { - synchronized (putUIListeners) { - if (putUIListeners.size() > 0) { - IPutUIListener listener; - Iterator listenerItr = putUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onPutCompleted(resource); - } - } - } - } - } - - private void postCompleteNotification(RemoteResource resource) { - synchronized (postUIListeners) { - if (postUIListeners.size() > 0) { - IPostUIListener listener; - Iterator listenerItr = postUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onPostCompleted(resource); - } - } - } - } - } - - private void observeCompleteNotification(RemoteResource resource) { - synchronized (observeUIListeners) { - if (observeUIListeners.size() > 0) { - IObserveUIListener listener; - Iterator listenerItr = observeUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onObserveCompleted(resource); - } - } - } - } - } - - private void verificationStartedNotification(RemoteResource resource, - int autoType) { - synchronized (verificationUIListeners) { - if (verificationUIListeners.size() > 0) { - IVerificationUIListener listener; - Iterator listenerItr = verificationUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onVerificationStarted(resource, autoType); - } - } - } - } - } - - private void verificationAbortedNotification(RemoteResource resource, - int autoType) { - synchronized (verificationUIListeners) { - if (verificationUIListeners.size() > 0) { - IVerificationUIListener listener; - Iterator listenerItr = verificationUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onVerificationAborted(resource, autoType); - } - } - } - } - } - - private void verificationCompletedNotification(RemoteResource resource, - int autoType) { - synchronized (verificationUIListeners) { - if (verificationUIListeners.size() > 0) { - IVerificationUIListener listener; - Iterator listenerItr = verificationUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onVerificationCompleted(resource, autoType); - } - } - } - } - } - - private void configUploadedNotification(RemoteResource resource) { - synchronized (configUploadUIListeners) { - if (configUploadUIListeners.size() > 0) { - IConfigurationUpload listener; - Iterator listenerItr = configUploadUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onConfigurationUploaded(resource); - } - } - } - } - } - - private void deviceInfoReceivedNotification() { - synchronized (devicePlatformInfoUIListeners) { - if (devicePlatformInfoUIListeners.size() > 0) { - IDevicePlatformInfoUIListener listener; - Iterator listenerItr = devicePlatformInfoUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onDeviceInfoFound(); - } - } - } - } - } - - private void platformInfoReceivedNotification() { - synchronized (devicePlatformInfoUIListeners) { - if (devicePlatformInfoUIListeners.size() > 0) { - IDevicePlatformInfoUIListener listener; - Iterator listenerItr = devicePlatformInfoUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onPlatformInfoFound(); - } - } - } - } - } - public synchronized Set getLastKnownSearchTypes() { return lastKnownSearchTypes; } @@ -1070,7 +729,8 @@ public class ResourceManager { } // Change the current resource in selection setCurrentResourceInSelection(null); - resourceSelectionChangedUINotification(null); + UiListenerHandler.getInstance() + .resourceSelectionChangedUINotification(null); } else { Iterator typeItr = searchTypes.iterator(); String resType; @@ -1105,7 +765,8 @@ public class ResourceManager { type = itr.next(); if (searchTypes.contains(type)) { setCurrentResourceInSelection(null); - resourceSelectionChangedUINotification(null); + UiListenerHandler.getInstance() + .resourceSelectionChangedUINotification(null); break; } } @@ -1158,7 +819,8 @@ public class ResourceManager { public void run() { setCurrentResourceInSelection(resource); // Notify all observers for resource selection change event - resourceSelectionChangedUINotification(resource); + UiListenerHandler.getInstance() + .resourceSelectionChangedUINotification(resource); } }.start(); } @@ -1333,23 +995,6 @@ public class ResourceManager { metaProperties.add(new MetaProperty(Constants.PLATFORM_SYSTEM_TIME, platInfo.getSystemTime())); } - /* - * metaProperties.add(new MetaProperty(Constants.PLATFORM_ID, "")); - * metaProperties .add(new MetaProperty(Constants.PLATFORM_MANUFAC_NAME, - * "")); metaProperties .add(new - * MetaProperty(Constants.PLATFORM_MANUFAC_URL, "")); - * metaProperties.add(new MetaProperty(Constants.PLATFORM_MODEL_NO, - * "")); metaProperties.add(new - * MetaProperty(Constants.PLATFORM_DATE_OF_MANUFAC, "")); - * metaProperties.add(new MetaProperty(Constants.PLATFORM_VERSION, "")); - * metaProperties.add(new MetaProperty(Constants.PLATFORM_OS_VERSION, - * "")); metaProperties.add(new MetaProperty( - * Constants.PLATFORM_HARDWARE_VERSION, "")); metaProperties.add(new - * MetaProperty( Constants.PLATFORM_FIRMWARE_VERSION, "")); - * metaProperties .add(new MetaProperty(Constants.PLATFORM_SUPPORT_URL, - * "")); metaProperties .add(new - * MetaProperty(Constants.PLATFORM_SYSTEM_TIME, "")); - */ return metaProperties; } @@ -1534,11 +1179,6 @@ public class ResourceManager { return values; } - /* - * public String getAttributeValue(RemoteResource res, String attName) { if - * (null == res || null == attName) { return null; } return - * res.getAttributeValue(attName); } - */ public void sendGetRequest(RemoteResource resource) { if (null == resource) { return; @@ -1547,6 +1187,7 @@ public class ResourceManager { if (null == resourceN) { return; } + try { resourceN.get(null, getListener); } catch (SimulatorException e) { @@ -1757,7 +1398,7 @@ public class ResourceManager { resource.setConfigUploaded(true); // Notify the UI listeners - configUploadedNotification(resource); + UiListenerHandler.getInstance().configUploadedNotification(resource); return true; } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/UiListenerHandler.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/UiListenerHandler.java new file mode 100644 index 0000000..9bf34f6 --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/UiListenerHandler.java @@ -0,0 +1,368 @@ +package oic.simulator.clientcontroller.manager; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import oic.simulator.clientcontroller.listener.IConfigurationUpload; +import oic.simulator.clientcontroller.listener.IDevicePlatformInfoUIListener; +import oic.simulator.clientcontroller.listener.IFindResourceUIListener; +import oic.simulator.clientcontroller.listener.IGetUIListener; +import oic.simulator.clientcontroller.listener.IObserveUIListener; +import oic.simulator.clientcontroller.listener.IPostUIListener; +import oic.simulator.clientcontroller.listener.IPutUIListener; +import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener; +import oic.simulator.clientcontroller.listener.IVerificationUIListener; +import oic.simulator.clientcontroller.remoteresource.RemoteResource; + +public class UiListenerHandler { + private static UiListenerHandler uiHandler; + + private List findResourceUIListeners; + private List resourceSelectionChangedUIListeners; + private List getUIListeners; + private List putUIListeners; + private List postUIListeners; + private List observeUIListeners; + private List verificationUIListeners; + private List configUploadUIListeners; + private List devicePlatformInfoUIListeners; + + private UiListenerHandler() { + findResourceUIListeners = new ArrayList(); + resourceSelectionChangedUIListeners = new ArrayList(); + getUIListeners = new ArrayList(); + putUIListeners = new ArrayList(); + postUIListeners = new ArrayList(); + observeUIListeners = new ArrayList(); + verificationUIListeners = new ArrayList(); + configUploadUIListeners = new ArrayList(); + devicePlatformInfoUIListeners = new ArrayList(); + } + + public static UiListenerHandler getInstance() { + if (null == uiHandler) { + uiHandler = new UiListenerHandler(); + } + return uiHandler; + } + + public void addResourceSelectionChangedUIListener( + IResourceSelectionChangedUIListener resourceSelectionChangedUIListener) { + synchronized (resourceSelectionChangedUIListeners) { + resourceSelectionChangedUIListeners + .add(resourceSelectionChangedUIListener); + } + } + + public void addGetUIListener(IGetUIListener getUIListener) { + synchronized (getUIListeners) { + getUIListeners.add(getUIListener); + } + } + + public void addPutUIListener(IPutUIListener putUIListener) { + synchronized (putUIListeners) { + putUIListeners.add(putUIListener); + } + } + + public void addPostUIListener(IPostUIListener postUIListener) { + synchronized (postUIListeners) { + postUIListeners.add(postUIListener); + } + } + + public void addObserveUIListener(IObserveUIListener observeUIListener) { + synchronized (observeUIListeners) { + observeUIListeners.add(observeUIListener); + } + } + + public void addVerificationUIListener( + IVerificationUIListener verificationUIListener) { + synchronized (verificationUIListeners) { + verificationUIListeners.add(verificationUIListener); + } + } + + public void addConfigUploadUIListener(IConfigurationUpload configListener) { + synchronized (configUploadUIListeners) { + configUploadUIListeners.add(configListener); + } + } + + public void addDevicePlatformInfoUIListener( + IDevicePlatformInfoUIListener deviceUIListener) { + synchronized (devicePlatformInfoUIListeners) { + devicePlatformInfoUIListeners.add(deviceUIListener); + } + } + + public void removeDevicePlatformInfoUIListener( + IDevicePlatformInfoUIListener platformUIListener) { + synchronized (devicePlatformInfoUIListeners) { + devicePlatformInfoUIListeners.remove(platformUIListener); + } + } + + public void removeResourceSelectionChangedUIListener( + IResourceSelectionChangedUIListener listener) { + synchronized (resourceSelectionChangedUIListeners) { + if (null != listener + && resourceSelectionChangedUIListeners.size() > 0) { + resourceSelectionChangedUIListeners.remove(listener); + } + } + } + + public void removeGetUIListener(IGetUIListener getUIListener) { + synchronized (getUIListeners) { + getUIListeners.remove(getUIListener); + } + } + + public void removePutUIListener(IPutUIListener putUIListener) { + synchronized (putUIListeners) { + putUIListeners.remove(putUIListener); + } + } + + public void removePostUIListener(IPostUIListener postUIListener) { + synchronized (postUIListeners) { + postUIListeners.remove(postUIListener); + } + } + + public void removeObserveUIListener(IObserveUIListener observeUIListener) { + synchronized (observeUIListeners) { + observeUIListeners.remove(observeUIListener); + } + } + + public void removeVerificationUIListener( + IVerificationUIListener verificationUIListener) { + synchronized (verificationUIListeners) { + verificationUIListeners.remove(verificationUIListener); + } + } + + public void removeConfigUploadUIListener(IConfigurationUpload configListener) { + synchronized (configUploadUIListeners) { + configUploadUIListeners.remove(configListener); + } + } + + public void addFindresourceUIListener(IFindResourceUIListener listener) { + if (null == listener) { + return; + } + synchronized (findResourceUIListeners) { + findResourceUIListeners.add(listener); + } + } + + public void removeFindresourceUIListener(IFindResourceUIListener listener) { + if (null == listener) { + return; + } + synchronized (findResourceUIListeners) { + findResourceUIListeners.remove(listener); + } + } + + public void newResourceFoundNotification(RemoteResource resource) { + synchronized (findResourceUIListeners) { + if (findResourceUIListeners.size() > 0) { + IFindResourceUIListener listener; + Iterator listenerItr = findResourceUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onNewResourceFound(resource); + } + } + } + } + } + + public void resourceSelectionChangedUINotification(RemoteResource resource) { + synchronized (resourceSelectionChangedUIListeners) { + if (resourceSelectionChangedUIListeners.size() > 0) { + IResourceSelectionChangedUIListener listener; + Iterator listenerItr = resourceSelectionChangedUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onResourceSelectionChange(resource); + } + } + } + } + } + + public void getCompleteNotification(RemoteResource resource) { + synchronized (getUIListeners) { + if (getUIListeners.size() > 0) { + IGetUIListener listener; + Iterator listenerItr = getUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onGetCompleted(resource); + } + } + } + } + } + + public void putCompleteNotification(RemoteResource resource) { + synchronized (putUIListeners) { + if (putUIListeners.size() > 0) { + IPutUIListener listener; + Iterator listenerItr = putUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onPutCompleted(resource); + } + } + } + } + } + + public void postCompleteNotification(RemoteResource resource) { + synchronized (postUIListeners) { + if (postUIListeners.size() > 0) { + IPostUIListener listener; + Iterator listenerItr = postUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onPostCompleted(resource); + } + } + } + } + } + + public void observeCompleteNotification(RemoteResource resource) { + synchronized (observeUIListeners) { + if (observeUIListeners.size() > 0) { + IObserveUIListener listener; + Iterator listenerItr = observeUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onObserveCompleted(resource); + } + } + } + } + } + + public void verificationStartedNotification(RemoteResource resource, + int autoType) { + synchronized (verificationUIListeners) { + if (verificationUIListeners.size() > 0) { + IVerificationUIListener listener; + Iterator listenerItr = verificationUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onVerificationStarted(resource, autoType); + } + } + } + } + } + + public void verificationAbortedNotification(RemoteResource resource, + int autoType) { + synchronized (verificationUIListeners) { + if (verificationUIListeners.size() > 0) { + IVerificationUIListener listener; + Iterator listenerItr = verificationUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onVerificationAborted(resource, autoType); + } + } + } + } + } + + public void verificationCompletedNotification(RemoteResource resource, + int autoType) { + synchronized (verificationUIListeners) { + if (verificationUIListeners.size() > 0) { + IVerificationUIListener listener; + Iterator listenerItr = verificationUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onVerificationCompleted(resource, autoType); + } + } + } + } + } + + public void configUploadedNotification(RemoteResource resource) { + synchronized (configUploadUIListeners) { + if (configUploadUIListeners.size() > 0) { + IConfigurationUpload listener; + Iterator listenerItr = configUploadUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onConfigurationUploaded(resource); + } + } + } + } + } + + public void deviceInfoReceivedNotification() { + synchronized (devicePlatformInfoUIListeners) { + if (devicePlatformInfoUIListeners.size() > 0) { + IDevicePlatformInfoUIListener listener; + Iterator listenerItr = devicePlatformInfoUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onDeviceInfoFound(); + } + } + } + } + } + + public void platformInfoReceivedNotification() { + synchronized (devicePlatformInfoUIListeners) { + if (devicePlatformInfoUIListeners.size() > 0) { + IDevicePlatformInfoUIListener listener; + Iterator listenerItr = devicePlatformInfoUIListeners + .iterator(); + while (listenerItr.hasNext()) { + listener = listenerItr.next(); + if (null != listener) { + listener.onPlatformInfoFound(); + } + } + } + } + } +} diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java index 670d2a7..4d22e9e 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/AttributeElement.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.clientcontroller.remoteresource; import java.util.HashMap; diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/DeviceAndPlatformInfo.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/DeviceAndPlatformInfo.java index 73ca5ff..fb4e8c1 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/DeviceAndPlatformInfo.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/DeviceAndPlatformInfo.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.clientcontroller.remoteresource; import org.oic.simulator.DeviceInfo; diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResource.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResource.java index 977e0b2..c0b03cb 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResource.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResource.java @@ -33,7 +33,6 @@ public class RemoteResource { private SimulatorRemoteResource remoteResourceRef; private SimulatorResourceModel resourceModelRef; private ResourceRepresentation mResourceRepresentation; - // private Map resourceAttributesMap; private boolean configUploaded; @@ -55,14 +54,6 @@ public class RemoteResource { this.resourceModelRef = resourceModel; } - /* - * public Map getResourceAttributesMap() { - * return resourceAttributesMap; } - * - * public void setResourceAttributesMap( Map resourceAttributesMap) { - * this.resourceAttributesMap = resourceAttributesMap; } - */ public int getGetAutomtnId() { return getAutomtnId; } @@ -135,28 +126,12 @@ public class RemoteResource { this.observed = observed; } - /* - * public List getPutPostModel() { Map attMap = getResourceAttributesMap(); if (null == - * attMap || attMap.size() < 1) { return null; } List - * putPostModelList = new ArrayList(); String - * attName; RemoteResourceAttribute attribute; PutPostAttributeModel - * putPostModel; Iterator attItr = attMap.keySet().iterator(); while - * (attItr.hasNext()) { attName = attItr.next(); attribute = - * attMap.get(attName); putPostModel = - * PutPostAttributeModel.getModel(attribute); if (null != putPostModel) { - * putPostModelList.add(putPostModel); } } return putPostModelList; } - * - * public String getAttributeValue(String attName) { RemoteResourceAttribute - * attribute = resourceAttributesMap.get(attName); if (null == attribute) { - * return null; } return String.valueOf(attribute.getAttributeValue()); } - */ public int getAutomationtype(int autoId) { if (getAutomtnId == autoId) { return Constants.GET_AUTOMATION_INDEX; } else if (putAutomtnId == autoId) { return Constants.PUT_AUTOMATION_INDEX; - } else {// if(postAutomtnId == autoId) { + } else { return Constants.POST_AUTOMATION_INDEX; } } @@ -166,7 +141,7 @@ public class RemoteResource { getAutomtnInProgress = status; } else if (putAutomtnId == autoId) { putAutomtnInProgress = status; - } else {// if(postAutomtnId == autoId) { + } else { postAutomtnInProgress = status; } } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java deleted file mode 100644 index 0c16341..0000000 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/RemoteResourceAttribute.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.clientcontroller.remoteresource; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.oic.simulator.AttributeProperty.Type; -import org.oic.simulator.AttributeValue.ValueType; -import org.oic.simulator.SimulatorResourceAttribute; - -/** - * This class represents an attribute in the remote resource. - */ -public class RemoteResourceAttribute { - - // Native object reference - private SimulatorResourceAttribute resourceAttributeRef; - - private String attributeName; - private Object attributeValue; - - private ValueType attValType; - private ValueType attValBaseType; - private int depth; - - private Type valuesType; - private List allowedValues; - private Object minValue; - private Object maxValue; - - public SimulatorResourceAttribute getResourceAttributeRef() { - return resourceAttributeRef; - } - - public void setResourceAttributeRef( - SimulatorResourceAttribute resourceAttribute) { - this.resourceAttributeRef = 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 List getAllowedValues() { - return allowedValues; - } - - public void setAllowedValues(List allowedValues) { - this.allowedValues = allowedValues; - } - - public void setAllowedValues(String[] allowedValues) { - List allowedValueList = null; - if (null != allowedValues && allowedValues.length > 0) { - allowedValueList = new ArrayList(); - for (String value : allowedValues) { - allowedValueList.add(value); - } - } - this.allowedValues = allowedValueList; - } - - public Object getMinValue() { - return minValue; - } - - public void setMinValue(Object minValue) { - this.minValue = minValue; - } - - public Object getMaxValue() { - return maxValue; - } - - public void setMaxValue(Object maxValue) { - this.maxValue = maxValue; - } - - public static RemoteResourceAttribute clone( - RemoteResourceAttribute attribute) { - RemoteResourceAttribute clone = null; - if (null != attribute) { - clone = new RemoteResourceAttribute(); - clone.setAttributeName(attribute.getAttributeName()); - clone.setAttributeValue(attribute.getAttributeValue()); - clone.setAllowedValues(attribute.getAllowedValues()); - clone.setAttValBaseType(attribute.getAttValBaseType()); - clone.setAttValType(attribute.getAttValType()); - clone.setMinValue(attribute.getMinValue()); - clone.setMaxValue(attribute.getMaxValue()); - clone.setResourceAttributeRef(null); - } - return clone; - } - - // This method gives all known possible values of the attribute in string - // format. - // It takes allowed values or range of values whichever is available - public List getAllValues() { - List valueList = new ArrayList(); - if (null != allowedValues) { - Iterator values = allowedValues.iterator(); - Object value; - while (values.hasNext()) { - value = values.next(); - if (null != value) { - valueList.add(String.valueOf(value)); - } - } - } else if (null != minValue && null != maxValue) { - double min = (Double) minValue; - double max = (Double) maxValue; - for (double value = min; value <= max; value++) { - valueList.add(String.valueOf(value)); - } - } - if (valueList.size() < 1 && null != attributeValue) { - valueList.add(String.valueOf(attributeValue)); - } - return valueList; - } - - // Method added for debugging purpose - public static void printAttributes( - Map attributeMap) { - Iterator itr = attributeMap.keySet().iterator(); - String attName; - RemoteResourceAttribute att; - while (itr.hasNext()) { - attName = itr.next(); - att = attributeMap.get(attName); - System.out.println("AttributeName:" + attName); - System.out.println("AttributeValue:" - + att.getAttributeValue().toString()); - System.out.println("Allowed Values:" + att.getAllValues()); - } - } - - public ValueType getAttValType() { - return attValType; - } - - public void setAttValType(ValueType attValType) { - this.attValType = attValType; - } - - public ValueType getAttValBaseType() { - return attValBaseType; - } - - public void setAttValBaseType(ValueType attValBaseType) { - this.attValBaseType = attValBaseType; - } - - public Type getValuesType() { - return valuesType; - } - - public void setValuesType(Type valuesType) { - this.valuesType = valuesType; - } - - public int getDepth() { - return depth; - } - - public void setDepth(int depth) { - this.depth = depth; - } -} \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java index 724edbb..ef8cef7 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/remoteresource/ResourceRepresentation.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.clientcontroller.remoteresource; import java.util.HashMap; diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java index e15c5d2..ed9f42f 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/AttributeValueStringConverter.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.clientcontroller.utils; import java.util.Map; diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Constants.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Constants.java index eba2905..a23926e 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Constants.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Constants.java @@ -75,8 +75,7 @@ public class Constants { public static final String DEBUG = "Debug"; public static final String UNKNOWN = "Unknown"; - public static final String[] BROWSE_RAML_FILTER_EXTENSIONS = new String[] { - "*.raml", "*" }; + public static final String[] BROWSE_RAML_FILTER_EXTENSIONS = new String[] { "*.raml" }; public static final String[] SAVE_LOG_FILTER_EXTENSIONS = new String[] { "*.log", "*" }; @@ -103,4 +102,13 @@ public class Constants { public static final String PLATFORM_FIRMWARE_VERSION = "Firmware Version"; public static final String PLATFORM_SUPPORT_URL = "Support URL"; public static final String PLATFORM_SYSTEM_TIME = "System Time"; + + public static final String BASELINE_INTERFACE = "oic.if.baseline"; + public static final String LINKS_LIST_INTERFACE = "oic.if.ll"; + public static final String BATCH_INTERFACE = "oic.if.b"; + public static final String LINK_BATCH_INTERFACE = "oic.if.lb"; + public static final String READ_ONLY_INTERFACE = "oic.if.r"; + public static final String READ_WRITE_INTERFACE = "oic.if.rw"; + public static final String ACTUATOR_INTERFACE = "oic.if.a"; + public static final String SENSOR_INTERFACE = "oic.if.s"; } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java index 9c13390..cb731b9 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/utils/Utility.java @@ -17,9 +17,11 @@ package oic.simulator.clientcontroller.utils; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import org.oic.simulator.AttributeValue; @@ -161,4 +163,18 @@ public class Utility { return String.valueOf(value); } } + + public static Map getResourceInterfaces() { + Map ifTypes = null; + ifTypes = new HashMap(); + ifTypes.put(Constants.BASELINE_INTERFACE, "Baseline"); + ifTypes.put(Constants.LINKS_LIST_INTERFACE, "Links List"); + ifTypes.put(Constants.BATCH_INTERFACE, "Batch"); + ifTypes.put(Constants.LINK_BATCH_INTERFACE, "Link Batch"); + ifTypes.put(Constants.READ_ONLY_INTERFACE, "Read-Only"); + ifTypes.put(Constants.READ_WRITE_INTERFACE, "Read-Write"); + ifTypes.put(Constants.ACTUATOR_INTERFACE, "Actuator"); + ifTypes.put(Constants.SENSOR_INTERFACE, "Sensor"); + return ifTypes; + } } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java index 55f93d1..f304257 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeEditingSupport.java @@ -137,7 +137,6 @@ public class AttributeEditingSupport { if (dialog instanceof PostRequestDialog) { viewer.update(attributeElement, null); - // comboBox.setVisible(false); } } }); @@ -233,8 +232,6 @@ public class AttributeEditingSupport { public void updateAttributeValue(SimulatorResourceAttribute att, AttributeValue value) { - att.setValue(value); - IStructuredSelection selection = (IStructuredSelection) viewer .getSelection(); if (null == selection) { diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java index ec1ded7..3a0403a 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/AttributeView.java @@ -27,6 +27,7 @@ import oic.simulator.clientcontroller.listener.IPutUIListener; import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener; import oic.simulator.clientcontroller.listener.IVerificationUIListener; import oic.simulator.clientcontroller.manager.ResourceManager; +import oic.simulator.clientcontroller.manager.UiListenerHandler; import oic.simulator.clientcontroller.remoteresource.AttributeElement; import oic.simulator.clientcontroller.remoteresource.RemoteResource; import oic.simulator.clientcontroller.remoteresource.ResourceRepresentation; @@ -451,14 +452,12 @@ public class AttributeView extends ViewPart { getButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - if (resourceInSelection.isGetAutomtnInProgress()) { - MessageDialog - .openInformation(Display.getDefault() - .getActiveShell(), "GET Request", - "GET Automation is in progress. Please wait or stop the automation."); - } else { - resourceManager.sendGetRequest(resourceInSelection); - } + PlatformUI.getWorkbench().getDisplay().syncExec(new Thread() { + @Override + public void run() { + resourceManager.sendGetRequest(resourceInSelection); + } + }); } }); @@ -488,7 +487,6 @@ public class AttributeView extends ViewPart { PutRequestDialog putDialog = new PutRequestDialog( Display.getDefault().getActiveShell()); if (putDialog.open() == Window.OK) { - // Call the native PUT method resourceManager.sendPutRequest(resourceInSelection, putDialog.getUpdatedRepresentation() .getModel()); @@ -525,7 +523,6 @@ public class AttributeView extends ViewPart { PostRequestDialog postDialog = new PostRequestDialog( Display.getDefault().getActiveShell()); if (postDialog.open() == Window.OK) { - // Call the native POST method ResourceRepresentation representation = postDialog .getUpdatedRepresentation(); resourceManager.sendPostRequest( @@ -701,14 +698,16 @@ public class AttributeView extends ViewPart { } private void addManagerListeners() { - resourceManager - .addResourceSelectionChangedUIListener(resourceSelectionChangedListener); - resourceManager.addGetUIListener(getUIListener); - resourceManager.addPutUIListener(putUIListener); - resourceManager.addPostUIListener(postUIListener); - resourceManager.addObserveUIListener(observeUIListener); - resourceManager.addVerificationUIListener(verificationUIListener); - resourceManager.addConfigUploadUIListener(configUploadUIListener); + UiListenerHandler.getInstance().addResourceSelectionChangedUIListener( + resourceSelectionChangedListener); + UiListenerHandler.getInstance().addGetUIListener(getUIListener); + UiListenerHandler.getInstance().addPutUIListener(putUIListener); + UiListenerHandler.getInstance().addPostUIListener(postUIListener); + UiListenerHandler.getInstance().addObserveUIListener(observeUIListener); + UiListenerHandler.getInstance().addVerificationUIListener( + verificationUIListener); + UiListenerHandler.getInstance().addConfigUploadUIListener( + configUploadUIListener); } private void setVisibility(boolean visibility) { @@ -833,13 +832,14 @@ public class AttributeView extends ViewPart { public void dispose() { // Unregister the selection listener if (null != resourceSelectionChangedListener) { - resourceManager - .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener); + UiListenerHandler.getInstance() + .removeResourceSelectionChangedUIListener( + resourceSelectionChangedListener); } // Unregister the GET listener if (null != getUIListener) { - resourceManager.removeGetUIListener(getUIListener); + UiListenerHandler.getInstance().removeGetUIListener(getUIListener); } super.dispose(); diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/MetaPropertiesView.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/MetaPropertiesView.java index cbc51a8..82516dd 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/MetaPropertiesView.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/MetaPropertiesView.java @@ -22,6 +22,7 @@ import oic.simulator.clientcontroller.Activator; import oic.simulator.clientcontroller.listener.IDevicePlatformInfoUIListener; import oic.simulator.clientcontroller.listener.IResourceSelectionChangedUIListener; import oic.simulator.clientcontroller.manager.ResourceManager; +import oic.simulator.clientcontroller.manager.UiListenerHandler; import oic.simulator.clientcontroller.remoteresource.MetaProperty; import oic.simulator.clientcontroller.remoteresource.RemoteResource; @@ -323,10 +324,10 @@ public class MetaPropertiesView extends ViewPart { } private void addManagerListeners() { - resourceManager - .addResourceSelectionChangedUIListener(resourceSelectionChangedListener); - resourceManager - .addDevicePlatformInfoUIListener(devicePlatformInfoUIListener); + UiListenerHandler.getInstance().addResourceSelectionChangedUIListener( + resourceSelectionChangedListener); + UiListenerHandler.getInstance().addDevicePlatformInfoUIListener( + devicePlatformInfoUIListener); } class PropertycontentProvider implements IStructuredContentProvider { @@ -349,8 +350,9 @@ public class MetaPropertiesView extends ViewPart { public void dispose() { // Unregister the listener if (null != resourceSelectionChangedListener) { - resourceManager - .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener); + UiListenerHandler.getInstance() + .removeResourceSelectionChangedUIListener( + resourceSelectionChangedListener); } super.dispose(); } diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java index b059a4d..f970b73 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/ResourceManagerView.java @@ -22,6 +22,7 @@ import java.util.Set; import oic.simulator.clientcontroller.Activator; import oic.simulator.clientcontroller.listener.IFindResourceUIListener; import oic.simulator.clientcontroller.manager.ResourceManager; +import oic.simulator.clientcontroller.manager.UiListenerHandler; import oic.simulator.clientcontroller.remoteresource.RemoteResource; import oic.simulator.clientcontroller.utils.Constants; import oic.simulator.clientcontroller.view.dialogs.FindResourceWizard; @@ -641,14 +642,15 @@ public class ResourceManagerView extends ViewPart { } private void addManagerListeners() { - resourceManager.addFindresourceUIListener(findListener); + UiListenerHandler.getInstance().addFindresourceUIListener(findListener); } @Override public void dispose() { // Unregister the listener if (null != findListener) { - resourceManager.removeFindresourceUIListener(findListener); + UiListenerHandler.getInstance().removeFindresourceUIListener( + findListener); resourceManager.resourceSelectionChanged(null); } super.dispose(); diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java index f53a160..edee7a3 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PostRequestDialog.java @@ -74,6 +74,7 @@ public class PostRequestDialog extends TitleAreaDialog { @Override protected Control createDialogArea(Composite parent) { Composite compLayout = (Composite) super.createDialogArea(parent); + Composite container = new Composite(compLayout, SWT.NONE); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); GridLayout layout = new GridLayout(1, false); diff --git a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java index 2bf889d..d140caf 100644 --- a/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java +++ b/service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/view/dialogs/PutRequestDialog.java @@ -72,6 +72,7 @@ public class PutRequestDialog extends TitleAreaDialog { @Override protected Control createDialogArea(Composite parent) { Composite compLayout = (Composite) super.createDialogArea(parent); + Composite container = new Composite(compLayout, SWT.NONE); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); GridLayout layout = new GridLayout(1, false); @@ -252,5 +253,4 @@ public class PutRequestDialog extends TitleAreaDialog { public ResourceRepresentation getUpdatedRepresentation() { return updatedRepresentation; } - } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IDataChangeListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IDataChangeListener.java index 0c2ffbb..552ddc6 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IDataChangeListener.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IDataChangeListener.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.serviceprovider.listener; import oic.simulator.serviceprovider.model.AttributeElement; diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IPropertiesChangedListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IPropertiesChangedListener.java index 8b650fc..d45dca5 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IPropertiesChangedListener.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IPropertiesChangedListener.java @@ -22,6 +22,4 @@ package oic.simulator.serviceprovider.listener; */ public interface IPropertiesChangedListener { public void onResourcePropertyChange(); - - public void onDevicePropertyChange(); } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/ISelectionChangedListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/ISelectionChangedListener.java index 9746187..8276767 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/ISelectionChangedListener.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/ISelectionChangedListener.java @@ -16,7 +16,6 @@ package oic.simulator.serviceprovider.listener; -import oic.simulator.serviceprovider.model.Device; import oic.simulator.serviceprovider.model.Resource; /** @@ -25,6 +24,4 @@ import oic.simulator.serviceprovider.model.Resource; */ public interface ISelectionChangedListener { public void onResourceSelectionChange(Resource resource); - - public void onDeviceSelectionChange(Device dev); } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/Data.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/Data.java index fa079f4..2cd2eee 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/Data.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/Data.java @@ -24,26 +24,18 @@ import java.util.List; import java.util.Map; import java.util.Set; -import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.model.Device; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.model.SingleResource; public class Data { - private Map singleResourceMap; - - private Map collectionResourceMap; - - private Map deviceMap; + private Map singleResourceMap; // Holds resource type as key and a resource URI set as values. // Helps in performing operations based on resource type. - private Map> resTypeToResUriMap; + private Map> resTypeToResUriMap; public Data() { singleResourceMap = new HashMap(); - collectionResourceMap = new HashMap(); - deviceMap = new HashMap(); resTypeToResUriMap = new HashMap>(); } @@ -54,9 +46,6 @@ public class Data { if (resource instanceof SingleResource) { singleResourceMap.put(resource.getResourceURI(), (SingleResource) resource); - } else { - collectionResourceMap.put(resource.getResourceURI(), - (CollectionResource) resource); } addToTypeAndUriMap(resource); } @@ -65,35 +54,21 @@ public class Data { if (null == resource) { return; } - Set resTypes = resource.getResourceTypes(); - if (null == resTypes || resTypes.isEmpty()) { + String resType = resource.getResourceType(); + if (null == resType || resType.isEmpty()) { return; } String uri = resource.getResourceURI(); if (null == uri || uri.isEmpty()) { return; } - Iterator itr = resTypes.iterator(); - String rType; Set newTypeSet; - while (itr.hasNext()) { - rType = itr.next(); - newTypeSet = resTypeToResUriMap.get(rType); - if (null == newTypeSet) { - newTypeSet = new HashSet(); - resTypeToResUriMap.put(rType, newTypeSet); - } - newTypeSet.add(uri); - } - } - - public void addDevice(Device dev) { - if (null == dev) { - return; - } - synchronized (deviceMap) { - deviceMap.put(dev.getDeviceName(), dev); + newTypeSet = resTypeToResUriMap.get(resType); + if (null == newTypeSet) { + newTypeSet = new HashSet(); + resTypeToResUriMap.put(resType, newTypeSet); } + newTypeSet.add(uri); } public synchronized void deleteResource(Resource resource) { @@ -102,43 +77,29 @@ public class Data { } if (resource instanceof SingleResource) { singleResourceMap.remove(resource.getResourceURI()); - } else { - collectionResourceMap.remove(resource.getResourceURI()); } removeFromTypeAndUriMap(resource); } - public synchronized void deleteDevice(Device dev) { - if (null == dev) { - return; - } - deviceMap.remove(dev.getDeviceName()); - } - public synchronized void removeFromTypeAndUriMap(Resource resource) { if (null == resource) { return; } - Set resTypes = resource.getResourceTypes(); - if (null == resTypes || resTypes.isEmpty()) { + String resType = resource.getResourceType(); + if (null == resType || !resType.isEmpty()) { return; } String uri = resource.getResourceURI(); if (null == uri || uri.isEmpty()) { return; } - Iterator itr = resTypes.iterator(); - String rType; Set newTypeSet; - while (itr.hasNext()) { - rType = itr.next(); - newTypeSet = resTypeToResUriMap.get(rType); - if (null != newTypeSet) { - newTypeSet.remove(uri); - } - if (null == newTypeSet || newTypeSet.isEmpty()) { - resTypeToResUriMap.remove(rType); - } + newTypeSet = resTypeToResUriMap.get(resType); + if (null != newTypeSet) { + newTypeSet.remove(uri); + } + if (null == newTypeSet || newTypeSet.isEmpty()) { + resTypeToResUriMap.remove(resType); } } @@ -158,24 +119,8 @@ public class Data { return resources; } - public List getCollectionResources() { - List resources; - synchronized (collectionResourceMap) { - if (collectionResourceMap.isEmpty()) { - return null; - } - resources = new ArrayList(); - Set uriSet = collectionResourceMap.keySet(); - Iterator itr = uriSet.iterator(); - while (itr.hasNext()) { - resources.add(collectionResourceMap.get(itr.next())); - } - } - return resources; - } - public List getResources() { - if (singleResourceMap.isEmpty() && collectionResourceMap.isEmpty()) { + if (singleResourceMap.isEmpty()) { return null; } List resourceList = new ArrayList(); @@ -186,48 +131,22 @@ public class Data { resourceList.add(singleResourceMap.get(itr.next())); } } - synchronized (collectionResourceMap) { - Set uriSet = collectionResourceMap.keySet(); - Iterator itr = uriSet.iterator(); - while (itr.hasNext()) { - resourceList.add(collectionResourceMap.get(itr.next())); - } - } return resourceList; } - public List getDevices() { - List devices; - synchronized (deviceMap) { - if (deviceMap.isEmpty()) { - return null; - } - devices = new ArrayList(); - Set uriSet = deviceMap.keySet(); - Iterator itr = uriSet.iterator(); - while (itr.hasNext()) { - devices.add(deviceMap.get(itr.next())); - } - } - return devices; - } - public synchronized boolean isResourceExist(String resourceURI) { if (null == resourceURI || resourceURI.isEmpty()) { return false; } if ((null != singleResourceMap && singleResourceMap - .containsKey(resourceURI)) - || (null != collectionResourceMap && collectionResourceMap - .containsKey(resourceURI))) { + .containsKey(resourceURI))) { return true; } return false; } public synchronized boolean isAnyResourceExist() { - return ((null != singleResourceMap && !singleResourceMap.isEmpty()) || (null != collectionResourceMap && !collectionResourceMap - .isEmpty())); + return ((null != singleResourceMap && !singleResourceMap.isEmpty())); } public void changeResourceURI(Resource resource, String curURI, @@ -240,27 +159,10 @@ public class Data { singleResourceMap.remove(curURI); singleResourceMap.put(newURI, (SingleResource) resource); } - } else { - synchronized (collectionResourceMap) { - collectionResourceMap.remove(curURI); - collectionResourceMap - .put(newURI, (CollectionResource) resource); - } } resource.setResourceURI(newURI); } - public void changeDeviceName(Device dev, String curName, String newName) { - if (null == dev || null == curName || null == newName) { - return; - } - synchronized (deviceMap) { - deviceMap.remove(curName); - deviceMap.put(newName, dev); - } - dev.setDeviceName(newName); - } - public SingleResource getSingleResourceByURI(String resourceURI) { if (null == resourceURI) { return null; @@ -272,26 +174,12 @@ public class Data { return res; } - public CollectionResource getCollectionResourceByURI(String resourceURI) { - if (null == resourceURI) { - return null; - } - CollectionResource res; - synchronized (collectionResourceMap) { - res = collectionResourceMap.get(resourceURI); - } - return res; - } - public Resource getResourceByURI(String resourceURI) { Resource res = getSingleResourceByURI(resourceURI); - if (null == res) { - res = getCollectionResourceByURI(resourceURI); - } return res; } public synchronized int getResourceCount() { - return singleResourceMap.size() + collectionResourceMap.size(); + return singleResourceMap.size(); } } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java index 9e58424..5ae5c39 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ImageManager.java @@ -58,11 +58,6 @@ public class ImageManager { // Resource icons based on the resource type r.put(Constants.SINGLE_RESOURCE, ImageDescriptor.createFromURL(bundle .getEntry("/icons/single_resource.gif"))); - r.put(Constants.COLLECTION_RESOURCE, ImageDescriptor - .createFromURL(bundle - .getEntry("/icons/collection_resource.gif"))); - r.put(Constants.DEVICE, ImageDescriptor.createFromURL(bundle - .getEntry("/icons/device.gif"))); // Log View related icons r.put(Constants.DEBUG_LOG, ImageDescriptor.createFromURL(bundle diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java index a58e428..89df91f 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java @@ -28,8 +28,6 @@ import java.util.Vector; import oic.simulator.serviceprovider.Activator; import oic.simulator.serviceprovider.model.AttributeElement; -import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.model.Device; import oic.simulator.serviceprovider.model.MetaProperty; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.model.ResourceType; @@ -52,7 +50,6 @@ import org.oic.simulator.SimulatorManager; import org.oic.simulator.SimulatorResourceAttribute; import org.oic.simulator.SimulatorResourceModel; import org.oic.simulator.server.Observer; -import org.oic.simulator.server.SimulatorCollectionResource; import org.oic.simulator.server.SimulatorResource; import org.oic.simulator.server.SimulatorResource.AutoUpdateListener; import org.oic.simulator.server.SimulatorResource.AutoUpdateType; @@ -73,8 +70,6 @@ public class ResourceManager { private Resource currentResourceInSelection; - private Device currentDeviceInSelection; - private ResourceModelChangeListener resourceModelChangeListener; private AutoUpdateListener automationListener; @@ -517,14 +512,6 @@ public class ResourceManager { this.currentResourceInSelection = resource; } - public synchronized Device getCurrentDeviceInSelection() { - return currentDeviceInSelection; - } - - public synchronized void setCurrentDeviceInSelection(Device dev) { - this.currentDeviceInSelection = dev; - } - public boolean isResourceExist(String resourceURI) { return data.isResourceExist(resourceURI); } @@ -539,13 +526,14 @@ public class ResourceManager { if (null == resource) { return false; } - String resType = (String) resource.getResourceTypes().toArray()[0]; + try { - // 1. Create the resource. + // Create the resource. SimulatorResource jSimulatorResource = SimulatorManager .createResource(SimulatorResource.Type.SINGLE, resource.getResourceName(), - resource.getResourceURI(), resType); + resource.getResourceURI(), + resource.getResourceType()); if (null == jSimulatorResource || !(jSimulatorResource instanceof SimulatorSingleResource)) { return false; @@ -553,21 +541,21 @@ public class ResourceManager { SimulatorSingleResource jSimulatorSingleResource = (SimulatorSingleResource) jSimulatorResource; resource.setSimulatorResource(jSimulatorSingleResource); - // 2. Cancel observable property if requested by user. + // Cancel observable property if requested by user. if (!resource.isObservable()) { jSimulatorSingleResource.setObservable(false); } - // 3. Set the model change listener. + // Set the model change listener. jSimulatorSingleResource .setResourceModelChangeListener(resourceModelChangeListener); - // 4. Set the observer listener if the resource is observable. + // Set the observer listener if the resource is observable. if (resource.isObservable()) { jSimulatorSingleResource.setObserverListener(observer); } - // 5. Add attributes. + // Add attributes. if (null != attributes && !attributes.isEmpty()) { SimulatorResourceAttribute value; for (Map.Entry entry : attributes @@ -577,75 +565,20 @@ public class ResourceManager { jSimulatorSingleResource.addAttribute(value); } - // 6. Get the resource model java object reference. + // Get the resource model java object reference. resource.setResourceModel(jSimulatorSingleResource .getResourceModel()); resource.setResourceRepresentation(resource.getResourceModel()); } - // 6. Register the resource with the platform. + // Register the resource with the platform. jSimulatorSingleResource.start(); resource.setStarted(true); - } catch (SimulatorException e) { - Activator - .getDefault() - .getLogManager() - .log(Level.ERROR.ordinal(), new Date(), - Utility.getSimulatorErrorString(e, null)); - throw e; - } - - // 8. Add to local cache. - data.addResource(resource); - - // 9. Update UI listeners - UiListenerHandler.getInstance().resourceCreatedUINotification( - ResourceType.SINGLE); - return true; - } - - public boolean createCollectionResource(CollectionResource resource) - throws SimulatorException { - if (null == resource) { - return false; - } - String resType = (String) resource.getResourceTypes().toArray()[0]; - try { - // 1. Create the resource. - SimulatorResource jSimulatorResource = SimulatorManager - .createResource(SimulatorResource.Type.COLLECTION, - resource.getResourceName(), - resource.getResourceURI(), resType); - if (null == jSimulatorResource - || !(jSimulatorResource instanceof SimulatorCollectionResource)) { - return false; - } - SimulatorCollectionResource jSimulatorCollectionResource = (SimulatorCollectionResource) jSimulatorResource; - resource.setSimulatorResource(jSimulatorCollectionResource); - - // 2. Cancel observable property if requested by user. - if (!resource.isObservable()) { - jSimulatorCollectionResource.setObservable(false); - } - - // 3. Set the observer listener if the resource is observable. - if (resource.isObservable()) { - jSimulatorCollectionResource.setObserverListener(observer); - } - - // 4. Set the model change listener. - jSimulatorCollectionResource - .setResourceModelChangeListener(resourceModelChangeListener); - - // 5. Fetch the model and attributes. - resource.setResourceRepresentation(jSimulatorCollectionResource - .getResourceModel()); - - // 6. Register the resource with the platform. - jSimulatorCollectionResource.start(); - resource.setStarted(true); + // Get the resource interfaces + resource.setResourceInterfaces(Utility + .convertVectorToSet(jSimulatorSingleResource.getInterface())); } catch (SimulatorException e) { Activator .getDefault() @@ -655,12 +588,12 @@ public class ResourceManager { throw e; } - // 6. Add to local cache. + // Add to local cache. data.addResource(resource); - // 7. Update UI listeners + // Update UI listeners UiListenerHandler.getInstance().resourceCreatedUINotification( - ResourceType.COLLECTION); + ResourceType.SINGLE); return true; } @@ -669,7 +602,7 @@ public class ResourceManager { throws SimulatorException { Resource resource = null; try { - // 1. Create the resource + // Create the resource SimulatorResource jSimulatorResource = SimulatorManager .createResource(configFilePath); if (null == jSimulatorResource) { @@ -678,11 +611,11 @@ public class ResourceManager { if (jSimulatorResource instanceof SimulatorSingleResource) { resource = new SingleResource(); } else { - resource = new CollectionResource(); + return null; } resource.setSimulatorResource(jSimulatorResource); - // 2. Fetch and locally store the resource name and uri. + // Fetch and locally store the resource name and uri. String uri = jSimulatorResource.getURI(); if (null == uri || uri.trim().isEmpty()) { return null; @@ -727,7 +660,7 @@ public class ResourceManager { return false; } - // 1. Update resource URI and Name if they are changed. + // Update resource URI and Name if they are changed. String newUri = uri.trim(); String newName = name.trim(); @@ -745,17 +678,17 @@ public class ResourceManager { } } - // 2. Set the model change listener. + // Set the model change listener. jSimulatorSingleResource .setResourceModelChangeListener(resourceModelChangeListener); - // 3. Set the observer listener if the resource is observable. + // Set the observer listener if the resource is observable. if (jSimulatorSingleResource.isObservable()) { jSimulatorSingleResource.setObserverListener(observer); singleRes.setObservable(true); } - // 4. Fetch the resource model. + // Fetch the resource model. SimulatorResourceModel jResModel = jSimulatorSingleResource .getResourceModel(); if (null == jResModel) { @@ -763,25 +696,25 @@ public class ResourceManager { } singleRes.setResourceModel(jResModel); - // 5. Fetch the basic details of the resource. - singleRes.addResourceType(jSimulatorSingleResource + // Fetch the basic details of the resource. + singleRes.setResourceType(jSimulatorSingleResource .getResourceType()); singleRes .setResourceInterfaces(Utility .convertVectorToSet(jSimulatorSingleResource .getInterface())); - // 6. Fetch the resource attributes. + // Fetch the resource attributes. singleRes.setResourceRepresentation(jResModel); - // 7. Register the resource with the platform. + // Register the resource with the platform. jSimulatorSingleResource.start(); singleRes.setStarted(true); - // 8. Add to local cache. + // Add to local cache. data.addResource(singleRes); - // 9. Update UI listeners for single instance creation + // Update UI listeners for single instance creation if (!multiInstance) UiListenerHandler.getInstance().resourceCreatedUINotification( ResourceType.SINGLE); @@ -796,92 +729,6 @@ public class ResourceManager { return true; } - /** - * This method can set/change the resource uri and name of an already - * created resource which is not yet registered with the platform. This - * method registers the model change and observer listeners, registers the - * resource, fetches the resource attributes, updates the local cache and - * notifies the UI listeners. - */ - public boolean completeCollectionResourceCreationByRAML(Resource resource, - String uri, String name) throws SimulatorException { - if (null == resource || !(resource instanceof CollectionResource)) { - return false; - } - - CollectionResource collectionRes = (CollectionResource) resource; - - SimulatorCollectionResource jSimulatorCollectionResource = null; - - try { - jSimulatorCollectionResource = (SimulatorCollectionResource) resource - .getSimulatorResource(); - if (null == jSimulatorCollectionResource) { - return false; - } - - // 1. Update resource URI and Name if they are changed. - String newUri = uri.trim(); - String newName = name.trim(); - - if (!collectionRes.getResourceURI().equals(newUri)) { - jSimulatorCollectionResource.setURI(newUri); - collectionRes.setResourceURI(newUri); - } - if (!collectionRes.getResourceName().equals(newName)) { - jSimulatorCollectionResource.setName(newName); - collectionRes.setResourceName(newName); - } - - // 2. Set the model change listener. - jSimulatorCollectionResource - .setResourceModelChangeListener(resourceModelChangeListener); - - // 3. Fetch the resource model. - SimulatorResourceModel jResModel = jSimulatorCollectionResource - .getResourceModel(); - if (null == jResModel) { - return false; - } - collectionRes.setResourceModel(jResModel); - - // 4. Fetch the basic details of the resource. - collectionRes.addResourceType(jSimulatorCollectionResource - .getResourceType()); - collectionRes.setResourceInterfaces(Utility - .convertVectorToSet(jSimulatorCollectionResource - .getInterface())); - - // 5. Set the observer listener if the resource is observable. - if (jSimulatorCollectionResource.isObservable()) { - jSimulatorCollectionResource.setObserverListener(observer); - collectionRes.setObservable(true); - } - - // 6. Fetch the resource attributes. - collectionRes.setResourceRepresentation(jResModel); - - // 7. Register the resource with the platform. - jSimulatorCollectionResource.start(); - collectionRes.setStarted(true); - - // 8. Add to local cache. - data.addResource(collectionRes); - - // 9. Update UI listeners for single instance creation - UiListenerHandler.getInstance().resourceCreatedUINotification( - ResourceType.COLLECTION); - } catch (Exception e) { - Activator - .getDefault() - .getLogManager() - .log(Level.ERROR.ordinal(), new Date(), - Utility.getSimulatorErrorString(e, null)); - throw e; - } - return true; - } - public int createSingleResourceMultiInstances(String configFile, int count) throws SimulatorException { int createCount = 0; @@ -929,22 +776,6 @@ public class ResourceManager { return createCount; } - public Device createDevice(String deviceName, Set childs) { - // 1. Create device - Device dev = new Device(); - dev.setDeviceName(deviceName); - data.addDevice(dev); - - // 2. Add children to device - if (null != childs && !childs.isEmpty()) - addResourceToDevice(dev, childs); - - // 3. Update ui listeners - UiListenerHandler.getInstance().resourceListUpdateUINotification( - ResourceType.DEVICE); - return dev; - } - public List getResourceList() { List resourceList = data.getResources(); if (null == resourceList) { @@ -967,226 +798,6 @@ public class ResourceManager { return resourceList; } - public List getCollectionResourceList() { - List resourceList = data.getCollectionResources(); - if (null == resourceList) { - return null; - } - // Sort the list - Collections.sort(resourceList, Utility.collectionResourceComparator); - - return resourceList; - } - - public List getDeviceList() { - List deviceList = data.getDevices(); - if (null == deviceList) { - return null; - } - // Sort the list - Collections.sort(deviceList, Utility.deviceComparator); - return deviceList; - } - - // Returns the number of resources which are added properly to the - // collection. - public int addResourceToCollection(CollectionResource collectionParent, - Set childs) { - if (null == collectionParent || null == childs || childs.isEmpty()) { - return -1; - } - Iterator itr = childs.iterator(); - Resource res; - int count = childs.size(); - while (itr.hasNext()) { - res = itr.next(); - try { - addResourceToCollection(collectionParent, res); - } catch (SimulatorException e) { - count--; - } - } - return count; - } - - public void addResourceToCollection(CollectionResource collectionParent, - Resource child) throws SimulatorException { - if (null == collectionParent || null == child) { - return; - } - try { - // 1. Add child to collection - collectionParent.addChildResource(child); - - // 2. Add a reference to the collection in the child - if (child instanceof SingleResource) { - ((SingleResource) child) - .addCollectionMembership(collectionParent); - } else { - ((CollectionResource) child).addMembership(collectionParent); - } - } catch (SimulatorException e) { - Activator - .getDefault() - .getLogManager() - .log(Level.ERROR.ordinal(), new Date(), - Utility.getSimulatorErrorString(e, null)); - throw e; - } - } - - public int addResourceToCollection(Set collections, - Resource child) { - if (null == collections || collections.isEmpty() || null == child) { - return -1; - } - Iterator itr = collections.iterator(); - CollectionResource res; - int count = collections.size(); - while (itr.hasNext()) { - res = itr.next(); - try { - addResourceToCollection(res, child); - } catch (SimulatorException e) { - count--; - } - } - return count; - } - - public void addResourceToDevice(Device dev, Set childs) { - // 1. Add children to the device. - dev.addChildResource(childs); - - // 2. Add a reference to the device in all children. - Iterator itr = childs.iterator(); - Resource res; - while (itr.hasNext()) { - res = itr.next(); - if (res instanceof SingleResource) { - ((SingleResource) res).addDeviceMembership(dev); - } else { - ((CollectionResource) res).addDeviceMembership(dev); - } - } - } - - public void addResourceToDevice(Device dev, Resource child) { - // 1. Add child to the device. - dev.addChildResource(child); - - // 2. Add a reference to the device in the child. - if (child instanceof SingleResource) { - ((SingleResource) child).addDeviceMembership(dev); - } else { - ((CollectionResource) child).addDeviceMembership(dev); - } - } - - public void addResourceToDevice(Set devices, Resource child) { - // 1. Add device reference in child. - if (child instanceof SingleResource) - ((SingleResource) child).addDeviceMembership(devices); - else - ((CollectionResource) child).addDeviceMembership(devices); - - // 2. Add a reference to the child in all devices. - Iterator itr = devices.iterator(); - Device dev; - while (itr.hasNext()) { - dev = itr.next(); - dev.addChildResource(child); - } - } - - public int removeResourceFromCollection( - Set collections, Resource resource) { - // 1. Remove the reference of resource from all the collections. - Iterator itr = collections.iterator(); - CollectionResource colRes; - int count = collections.size(); - while (itr.hasNext()) { - colRes = itr.next(); - try { - removeResourceFromCollection(colRes, resource); - } catch (SimulatorException e) { - count--; - } - } - return count; - - } - - public void removeResourceFromDevice(Set devices, Resource resource) { - // 1. Remove the reference of resource from all the devices. - Iterator itr = devices.iterator(); - Device dev; - while (itr.hasNext()) { - dev = itr.next(); - dev.removeChildResource(resource); - } - - // 2. Remove the reference of devices from the resource. - resource.removeDeviceMembership(devices); - } - - // Returns the count of resources removed from the collection - public int removeResourcesFromCollection(CollectionResource colRes, - Set resources) { - Iterator itr = resources.iterator(); - Resource res; - int count = resources.size(); - while (itr.hasNext()) { - res = itr.next(); - try { - removeResourceFromCollection(colRes, res); - } catch (SimulatorException e) { - count--; - } - } - return count; - } - - public void removeResourcesFromDevice(Device dev, Set resources) { - Iterator itr = resources.iterator(); - Resource res; - while (itr.hasNext()) { - res = itr.next(); - res.removeDeviceMembership(dev); - } - dev.removeChildResource(resources); - } - - public void removeResourceFromCollection(CollectionResource parent, - Resource child) throws SimulatorException { - try { - // 1. Remove the child from the parent - parent.removeChildResource(child); - - // 2. Remove the reference to parent from child - if (child instanceof SingleResource) { - ((SingleResource) child).removeCollectionMembership(parent); - } else { - ((CollectionResource) child).removeMembership(parent); - } - } catch (SimulatorException e) { - Activator - .getDefault() - .getLogManager() - .log(Level.ERROR.ordinal(), new Date(), - Utility.getSimulatorErrorString(e, null)); - throw e; - } - } - - public void removeResourceFromDevice(Device parent, Resource child) { - // 1. Remove the reference to parent from child - child.removeDeviceMembership(parent); - - // 2. Remove the child from the parent - parent.removeChildResource(child); - } - public void removeSingleResources(Set resources) throws SimulatorException { if (null == resources) { @@ -1198,19 +809,8 @@ public class ResourceManager { } } - public void removeCollectionResources(Set resources) - throws SimulatorException { - if (null == resources) { - return; - } - Iterator itr = resources.iterator(); - while (itr.hasNext()) { - removeResource(itr.next()); - } - } - public void removeResource(Resource res) throws SimulatorException { - // 1. Unregister the resource from the platform. + // Unregister the resource from the platform. SimulatorResource simRes = res.getSimulatorResource(); try { simRes.stop(); @@ -1223,47 +823,10 @@ public class ResourceManager { throw e; } - Set collectionMembership; - Set deviceMembership; - - if (res instanceof SingleResource) { - collectionMembership = ((SingleResource) res) - .getCollectionMembership(); - deviceMembership = ((SingleResource) res).getDeviceMembership(); - } else { - collectionMembership = ((CollectionResource) res).getMembership(); - deviceMembership = ((CollectionResource) res).getDeviceMembership(); - } - - // 2. Delete from the collections to which this resource is a member. - if (null != collectionMembership && !collectionMembership.isEmpty()) { - removeResourceFromCollection(collectionMembership, res); - } - - // 3. Delete from the devices to which this resource is a member. - if (null != deviceMembership && !deviceMembership.isEmpty()) { - removeResourceFromDevice(deviceMembership, res); - } - - // 4. Delete this resource + // Delete this resource data.deleteResource(res); } - public void removeDevice(Device dev) { - Set childs = dev.getChildResources(); - if (null != childs && !childs.isEmpty()) { - // 1. Remove the reference from all the children. - Iterator itr = childs.iterator(); - Resource res; - while (itr.hasNext()) { - res = itr.next(); - res.removeDeviceMembership(dev); - } - } - // 2. Delete the device. - data.deleteDevice(dev); - } - public boolean isUriUnique(List properties) { if (null == properties) { return false; @@ -1280,233 +843,10 @@ public class ResourceManager { return false; } - public List getCollectionsForAddingToSingleResource( - SingleResource resource) { - List collectionResources = data - .getCollectionResources(); - if (null == collectionResources || collectionResources.isEmpty()) { - return null; - } - - Set collectionMembership; - collectionMembership = resource.getCollectionMembership(); - if (null == collectionMembership || collectionMembership.isEmpty()) { - return collectionResources; - } - - if (collectionMembership.size() == collectionResources.size()) { - return null; - } - - collectionResources.removeAll(collectionMembership); - - // Sort the list - Collections.sort(collectionResources, - Utility.collectionResourceComparator); - - return collectionResources; - } - - public List getSingleTypeResourcesForAddingToCollectionResource( - CollectionResource colRes) { - List singleResources = data.getSingleResources(); - if (null == singleResources || singleResources.isEmpty()) { - return null; - } - - Set childs; - childs = colRes.getSingleTypeChildResources(); - if (null == childs || childs.isEmpty()) { - return singleResources; - } - - if (childs.size() == singleResources.size()) { - return null; - } - - singleResources.removeAll(childs); - - // Sort the list - Collections.sort(singleResources, Utility.singleResourceComparator); - - return singleResources; - } - - public List getSingleTypeResourcesForAddingToDevice( - Device dev) { - List singleResources = data.getSingleResources(); - if (null == singleResources || singleResources.isEmpty()) { - return null; - } - - Set childs; - childs = dev.getSingleTypeChildResources(); - if (null == childs || childs.isEmpty()) { - return singleResources; - } - - if (childs.size() == singleResources.size()) { - return null; - } - - singleResources.removeAll(childs); - - // Sort the list - Collections.sort(singleResources, Utility.singleResourceComparator); - - return singleResources; - } - - public List getCollectionTypeResourcesForAddingToCollectionResource( - CollectionResource colRes) { - List collectionResources = data - .getCollectionResources(); - if (null == collectionResources || collectionResources.isEmpty()) { - return null; - } - - // Remove the colRes from the list - collectionResources.remove(colRes); - - Set childs; - childs = colRes.getCollectionTypeChildResources(); - if (null == childs || childs.isEmpty()) { - return collectionResources; - } - - if (childs.size() == collectionResources.size()) { - return null; - } - - collectionResources.removeAll(childs); - - // Sort the list - Collections.sort(collectionResources, - Utility.collectionResourceComparator); - - return collectionResources; - } - - public List getCollectionTypeResourcesForAddingToDevice( - Device dev) { - List collectionResources = data - .getCollectionResources(); - if (null == collectionResources || collectionResources.isEmpty()) { - return null; - } - - Set childs; - childs = dev.getCollectionTypeChildResources(); - if (null == childs || childs.isEmpty()) { - return collectionResources; - } - - if (childs.size() == collectionResources.size()) { - return null; - } - - collectionResources.removeAll(childs); - - // Sort the list - Collections.sort(collectionResources, - Utility.collectionResourceComparator); - - return collectionResources; - } - - public List getDevicesForAddingToResource(Resource resource) { - List devices = data.getDevices(); - if (null == devices || devices.isEmpty()) { - return null; - } - - Set deviceMembership; - if (resource instanceof SingleResource) { - deviceMembership = ((SingleResource) resource) - .getDeviceMembership(); - } else { - deviceMembership = ((CollectionResource) resource) - .getDeviceMembership(); - } - if (null == deviceMembership || deviceMembership.isEmpty()) { - return devices; - } - - if (devices.size() == deviceMembership.size()) { - return null; - } - - devices.removeAll(deviceMembership); - - // Sort the list - Collections.sort(devices, Utility.deviceComparator); - - return devices; - } - - public List getResourceReferences( - SingleResource resource) { - List resources = Utility - .getCollectionResourceListFromSet(resource - .getCollectionMembership()); - if (null == resources || resources.isEmpty()) { - return null; - } - - Collections.sort(resources, Utility.collectionResourceComparator); - - return resources; - } - - public List getDeviceReferences(Resource resource) { - Set deviceMembership; - if (resource instanceof SingleResource) { - deviceMembership = ((SingleResource) resource) - .getDeviceMembership(); - } else { - deviceMembership = ((CollectionResource) resource) - .getDeviceMembership(); - } - - List devices = Utility.getDeviceListFromSet(deviceMembership); - if (null == devices || devices.isEmpty()) { - return null; - } - - Collections.sort(devices, Utility.deviceComparator); - - return devices; - } - - public List getSingleTypeChilds(CollectionResource colRes) { - Set childs = colRes.getSingleTypeChildResources(); - return Utility.getSingleResourceListFromSet(childs); - } - - public List getSingleTypeChilds(Device dev) { - Set childs = dev.getSingleTypeChildResources(); - return Utility.getSingleResourceListFromSet(childs); - } - - public List getCollectionTypeChilds( - CollectionResource colRes) { - Set childs = colRes - .getCollectionTypeChildResources(); - return Utility.getCollectionResourceListFromSet(childs); - } - - public List getCollectionTypeChilds(Device dev) { - Set childs = dev.getCollectionTypeChildResources(); - return Utility.getCollectionResourceListFromSet(childs); - } - public void resourceSelectionChanged(final Resource selectedResource) { new Thread() { @Override public void run() { - - setCurrentDeviceInSelection(null); - if (null != selectedResource) { setCurrentResourceInSelection(selectedResource); } else { @@ -1520,25 +860,6 @@ public class ResourceManager { }.start(); } - public void deviceSelectionChanged(final Device selectedDevice) { - new Thread() { - @Override - public void run() { - - setCurrentResourceInSelection(null); - - if (null != selectedDevice) { - setCurrentDeviceInSelection(selectedDevice); - } else { - setCurrentDeviceInSelection(null); - } - // Notify all observers for resource selection change event - UiListenerHandler.getInstance() - .deviceSelectionChangedUINotification(selectedDevice); - } - }.start(); - } - public List getMetaProperties(Resource resource) { if (null != resource) { String propName; @@ -1553,19 +874,7 @@ public class ResourceManager { } else if (propName.equals(Constants.RESOURCE_URI)) { propValue = resource.getResourceURI(); } else if (propName.equals(Constants.RESOURCE_TYPE)) { - Set resTypes = resource.getResourceTypes(); - if (null != resTypes && !resTypes.isEmpty()) { - propValue = ""; - Iterator itr = resTypes.iterator(); - while (itr.hasNext()) { - propValue += itr.next(); - if (itr.hasNext()) { - propValue += ", "; - } - } - } else { - propValue = null; - } + propValue = resource.getResourceType(); } else { propValue = null; } @@ -1578,16 +887,6 @@ public class ResourceManager { return null; } - public List getMetaProperties(Device dev) { - if (null != dev) { - List metaPropertyList = new ArrayList(); - metaPropertyList.add(new MetaProperty(Constants.DEVICE_NAME, dev - .getDeviceName())); - return metaPropertyList; - } - return null; - } - public boolean startResource(Resource resource) throws SimulatorException { if (null == resource) { return false; @@ -1668,14 +967,6 @@ public class ResourceManager { return true; } - public boolean changeDeviceName(Device dev, String newName) { - if (null == dev || null == newName) { - return false; - } - data.changeDeviceName(dev, dev.getDeviceName(), newName); - return true; - } - public boolean changeResourceURI(Resource resource, String newURI) throws SimulatorException { if (null == resource || null == newURI) { @@ -1766,41 +1057,6 @@ public class ResourceManager { return true; } - public boolean updateDeviceProperties(Device dev, - List properties) { - if (null == dev || null == properties) { - return false; - } - - // Updating the properties - Iterator itr = properties.iterator(); - MetaProperty property; - String propName; - String propValue; - String devName = null; - while (itr.hasNext()) { - property = itr.next(); - if (null == property) { - continue; - } - propName = property.getPropName(); - propValue = property.getPropValue(); - if (propName.equals(Constants.DEVICE_NAME)) { - devName = propValue; - } - } - - if (!changeDeviceName(dev, devName)) { - return false; - } - - // Notify UI Listeners - UiListenerHandler.getInstance().propertiesChangedUINotification( - Device.class); - - return true; - } - public boolean attributeValueUpdated(SingleResource resource, String attributeName, AttributeValue value) { if (null != resource && null != attributeName && null != value) { @@ -1822,7 +1078,6 @@ public class ResourceManager { return false; } - // TODO: This method should get the status from the native layer. public boolean isResourceStarted(Resource resource) { if (null == resource) { return false; @@ -1856,26 +1111,6 @@ public class ResourceManager { return invalid; } - public boolean isPropertyValueInvalid(Device dev, - List properties, String propName) { - if (null == dev || null == properties || null == propName) { - return false; - } - boolean invalid = false; - MetaProperty prop; - Iterator itr = properties.iterator(); - while (itr.hasNext()) { - prop = itr.next(); - if (prop.getPropName().equals(propName)) { - String value = prop.getPropValue(); - if (null == value || value.trim().isEmpty()) { - invalid = true; - } - } - } - return invalid; - } - public boolean isPropValueChanged(Resource resource, List properties, String propName) { if (null == resource || null == properties || null == propName) { @@ -1898,28 +1133,6 @@ public class ResourceManager { return changed; } - public boolean isPropValueChanged(Device dev, - List properties, String propName) { - if (null == dev || null == properties || null == propName) { - return false; - } - boolean changed = false; - MetaProperty prop; - String oldValue; - Iterator itr = properties.iterator(); - while (itr.hasNext()) { - prop = itr.next(); - if (prop.getPropName().equals(propName)) { - oldValue = dev.getDeviceName(); - if (null != oldValue && !prop.getPropValue().equals(oldValue)) { - changed = true; - } - break; - } - } - return changed; - } - private String getPropertyValueFromResource(Resource resource, String propName) { if (null == resource || null == propName) { @@ -1930,81 +1143,12 @@ public class ResourceManager { } else if (propName.equals(Constants.RESOURCE_NAME)) { return resource.getResourceName(); } else if (propName.equals(Constants.RESOURCE_TYPE)) { - return resource.getResourceTypes().toString(); + return resource.getResourceType(); } else { return null; } } - public boolean isURIChanged(Resource resource, List properties) { - if (null == resource || null == properties) { - return false; - } - boolean changed = false; - MetaProperty prop; - Iterator itr = properties.iterator(); - while (itr.hasNext()) { - prop = itr.next(); - if (prop.getPropName().equals(Constants.RESOURCE_URI)) { - if (!prop.getPropValue().equals(resource.getResourceURI())) { - changed = true; - } - break; - } - } - return changed; - } - - public boolean startResource(SingleResource resource) { - if (null == resource || resource.isStarted()) { - return false; - } - boolean result; - SimulatorResource server = resource.getSimulatorResource(); - if (null == server) { - result = false; - } else { - try { - server.start(); - resource.setStarted(true); - result = true; - } catch (SimulatorException e) { - Activator - .getDefault() - .getLogManager() - .log(Level.ERROR.ordinal(), new Date(), - Utility.getSimulatorErrorString(e, null)); - result = false; - } - } - return result; - } - - public boolean stopResource(SingleResource resource) { - if (null == resource || !resource.isStarted()) { - return false; - } - boolean result; - SimulatorResource server = resource.getSimulatorResource(); - if (null == server) { - result = false; - } else { - try { - server.stop(); - resource.setStarted(false); - result = true; - } catch (SimulatorException e) { - Activator - .getDefault() - .getLogManager() - .log(Level.ERROR.ordinal(), new Date(), - Utility.getSimulatorErrorString(e, null)); - result = false; - } - } - return result; - } - public boolean isAttHasRangeOrAllowedValues(SimulatorResourceAttribute att) { if (null == att) { return false; @@ -2257,10 +1401,6 @@ public class ResourceManager { } } - public void shutdown() { - threadHandle.interrupt(); - } - public List getAllValuesOfAttribute(SimulatorResourceAttribute att) { if (null == att) { return null; @@ -2388,4 +1528,8 @@ public class ResourceManager { public int getResourceCount() { return data.getResourceCount(); } + + public void shutdown() { + threadHandle.interrupt(); + } } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/UiListenerHandler.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/UiListenerHandler.java index 7165945..1ed1cfc 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/UiListenerHandler.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/UiListenerHandler.java @@ -28,7 +28,6 @@ import oic.simulator.serviceprovider.listener.IPropertiesChangedListener; import oic.simulator.serviceprovider.listener.IResourceListChangedListener; import oic.simulator.serviceprovider.listener.ISelectionChangedListener; import oic.simulator.serviceprovider.model.AttributeElement; -import oic.simulator.serviceprovider.model.Device; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.model.ResourceType; import oic.simulator.serviceprovider.model.SingleResource; @@ -235,22 +234,6 @@ public class UiListenerHandler { } } - public void deviceSelectionChangedUINotification(Device dev) { - synchronized (selectionChangedUIListeners) { - if (selectionChangedUIListeners.size() > 0) { - ISelectionChangedListener listener; - Iterator listenerItr = selectionChangedUIListeners - .iterator(); - while (listenerItr.hasNext()) { - listener = listenerItr.next(); - if (null != listener) { - listener.onDeviceSelectionChange(dev); - } - } - } - } - } - public void attributeUpdatedUINotification(AttributeElement attribute) { synchronized (dataChangeListeners) { if (dataChangeListeners.size() > 0 && null != attribute) { @@ -359,8 +342,6 @@ public class UiListenerHandler { if (null != listener) { if (targetClass == Resource.class) { listener.onResourcePropertyChange(); - } else { - listener.onDevicePropertyChange(); } } } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java index e2b0b8c..8dc36a0 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/AttributeElement.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.serviceprovider.model; import java.util.HashMap; diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/CollectionResource.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/CollectionResource.java deleted file mode 100644 index ff41152..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/CollectionResource.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.serviceprovider.model; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.oic.simulator.SimulatorException; -import org.oic.simulator.server.SimulatorCollectionResource; -import org.oic.simulator.server.SimulatorResource; - -public class CollectionResource extends Resource { - private Set childResources; - private Set supportedResourceTypes; - - private Set membership; - - public CollectionResource() { - childResources = new HashSet(); - supportedResourceTypes = new HashSet(); - membership = new HashSet(); - setDeviceMembership(new HashSet()); - } - - public Set getSupportedResourceTypes() { - return supportedResourceTypes; - } - - public void setSupportedResourceTypes(Set supportedResourceTypes) { - this.supportedResourceTypes = supportedResourceTypes; - } - - public void addSupportedResourceType(String rType) { - if (null == supportedResourceTypes) { - supportedResourceTypes = new HashSet(); - } - supportedResourceTypes.add(rType); - } - - public void removeSupportedResourceType(String rType) { - if (null != supportedResourceTypes) { - supportedResourceTypes.remove(rType); - } - } - - public Set getChildResources() { - return childResources; - } - - public Set getSingleTypeChildResources() { - if (null == childResources || childResources.isEmpty()) { - return null; - } - Set resultSet = new HashSet(); - Iterator itr = childResources.iterator(); - Resource res; - while (itr.hasNext()) { - res = itr.next(); - if (null != res) { - if (res instanceof SingleResource) { - resultSet.add((SingleResource) res); - } - } - } - return resultSet; - } - - public Set getCollectionTypeChildResources() { - if (null == childResources || childResources.isEmpty()) { - return null; - } - Set resultSet = new HashSet(); - Iterator itr = childResources.iterator(); - Resource res; - while (itr.hasNext()) { - res = itr.next(); - if (null != res) { - if (res instanceof CollectionResource) { - resultSet.add((CollectionResource) res); - } - } - } - return resultSet; - } - - public void setChildResources(Set childResources) { - this.childResources = childResources; - } - - public void addChildResource(Resource resource) throws SimulatorException { - if (null == resource) { - return; - } - if (null == childResources) { - childResources = new HashSet(); - } - - // Native call to add child resource - SimulatorResource simRes; - simRes = resource.getSimulatorResource(); - ((SimulatorCollectionResource) simulatorResource) - .addChildResource(simRes); - - childResources.add(resource); - } - - public void addChildResource(Set resources) - throws SimulatorException { - if (null == resources || resources.isEmpty()) { - return; - } - if (null == childResources) { - childResources = new HashSet(); - } - - // Native call to add child resource - SimulatorResource simRes; - Resource res; - Iterator itr = resources.iterator(); - while (itr.hasNext()) { - res = itr.next(); - simRes = res.getSimulatorResource(); - ((SimulatorCollectionResource) simulatorResource) - .addChildResource(simRes); - - childResources.add(res); - } - } - - public void removeChildResource(Resource resource) - throws SimulatorException { - if (null == resource || null == childResources) { - return; - } - - // Native call to add child resource - SimulatorResource simRes; - simRes = resource.getSimulatorResource(); - ((SimulatorCollectionResource) simulatorResource) - .removeChildResource(simRes); - - childResources.remove(resource); - } - - public void removeChildResource(Set resources) - throws SimulatorException { - if (null == resources || null == childResources) { - return; - } - - // Native call to add child resource - SimulatorResource simRes; - Resource res; - Iterator itr = resources.iterator(); - while (itr.hasNext()) { - res = itr.next(); - simRes = res.getSimulatorResource(); - ((SimulatorCollectionResource) simulatorResource) - .removeChildResource(simRes); - - childResources.remove(res); - } - } - - public Set getMembership() { - return membership; - } - - public void setMembership(Set membership) { - this.membership = membership; - } - - public void addMembership(CollectionResource resource) { - if (null == resource) { - return; - } - if (null == membership) { - membership = new HashSet(); - } - membership.add(resource); - } - - public void addMembership(Set resources) { - if (null == resources) { - return; - } - if (null == membership) { - membership = new HashSet(); - } - membership.addAll(resources); - } - - public void removeMembership(CollectionResource resource) { - if (null == resource || null == membership) { - return; - } - membership.remove(resource); - } - - public void removeMembership(Set collections) { - if (null == collections || null == membership) { - return; - } - membership.removeAll(collections); - } -} \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/DeleteCategory.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/DeleteCategory.java deleted file mode 100644 index 831c65f..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/DeleteCategory.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.serviceprovider.model; - -/** - * Enumerates different types of supported delete operations. - */ -public enum DeleteCategory { - ALL, BY_TYPE, BY_URI, NONE -} \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Device.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Device.java deleted file mode 100644 index f1a9879..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Device.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.serviceprovider.model; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -public class Device { - private String deviceName; - - private Set childResources; - - public Device() { - childResources = new HashSet(); - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public Set getChildResources() { - return childResources; - } - - public void setChildResources(Set childResources) { - this.childResources = childResources; - } - - public void addChildResource(Resource resource) { - if (null == resource) { - return; - } - if (null == childResources) { - childResources = new HashSet(); - } - childResources.add(resource); - } - - public void addChildResource(Set resources) { - if (null == resources) { - return; - } - if (null == childResources) { - childResources = new HashSet(); - } - childResources.addAll(resources); - } - - public void removeChildResource(Resource resource) { - if (null == resource || null == childResources) { - return; - } - childResources.remove(resource); - } - - public void removeChildResource(Set resources) { - if (null == resources || null == childResources) { - return; - } - childResources.removeAll(resources); - } - - public Set getSingleTypeChildResources() { - if (null == childResources || childResources.isEmpty()) { - return null; - } - Set resultSet = new HashSet(); - Iterator itr = childResources.iterator(); - Resource res; - while (itr.hasNext()) { - res = itr.next(); - if (null != res) { - if (res instanceof SingleResource) { - resultSet.add((SingleResource) res); - } - } - } - return resultSet; - } - - public Set getCollectionTypeChildResources() { - if (null == childResources || childResources.isEmpty()) { - return null; - } - Set resultSet = new HashSet(); - Iterator itr = childResources.iterator(); - Resource res; - while (itr.hasNext()) { - res = itr.next(); - if (null != res) { - if (res instanceof CollectionResource) { - resultSet.add((CollectionResource) res); - } - } - } - return resultSet; - } -} \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ModelChangeNotificationType.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ModelChangeNotificationType.java deleted file mode 100644 index a5e624c..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ModelChangeNotificationType.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.serviceprovider.model; - -/** - * Enumerates the different types of operations for model change notifications. - */ -public enum ModelChangeNotificationType { - ATTRIBUTE_ADDED, ATTRIBUTE_REMOVED, ATTRIBUTE_VALUE_CHANGED, NONE, NO_ATTRIBUTES_IN_MODEL -} \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java index 3997498..732ca64 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/Resource.java @@ -34,17 +34,14 @@ public abstract class Resource { private String resourceURI; private String resourceName; - private Set resourceTypes; + private String resourceType; private Set resourceInterfaces; private boolean started; private boolean observable; - private Set deviceMembership; - private Map observers; public Resource() { - resourceTypes = new HashSet(); resourceInterfaces = new HashSet(); observers = new HashMap(); } @@ -81,16 +78,19 @@ public abstract class Resource { this.resourceName = resourceName; } - public Set getResourceTypes() { - return resourceTypes; + public String getResourceType() { + return resourceType; } - public void setResourceTypes(Set resourceTypes) { - this.resourceTypes = resourceTypes; + public void setResourceType(String resourceType) { + this.resourceType = resourceType; } public Set getResourceInterfaces() { - return resourceInterfaces; + if (null != resourceInterfaces) { + return new HashSet(resourceInterfaces); + } + return null; } public void setResourceInterfaces(Set resourceInterfaces) { @@ -113,30 +113,6 @@ public abstract class Resource { this.observable = observable; } - public void addResourceType(String resType) { - if (null == resType) { - return; - } - if (null == resourceTypes) { - resourceTypes = new HashSet(); - } - resourceTypes.add(resType); - } - - public void removeResourceType(String resType) { - if (null == resType || null == resourceTypes) { - return; - } - resourceTypes.remove(resType); - } - - public boolean isResourceTypeExist(String resType) { - if (null == resType || null == resourceTypes) { - return false; - } - return resourceTypes.contains(resType); - } - public void addInterfaceType(String ifType) { if (null == ifType) { return; @@ -184,55 +160,6 @@ public abstract class Resource { observers.remove(observer.getId()); } - public Set getDeviceMembership() { - return deviceMembership; - } - - public void setDeviceMembership(Set deviceMembership) { - this.deviceMembership = deviceMembership; - } - - public void addDeviceMembership(Device dev) { - if (null == dev) { - return; - } - if (null == deviceMembership) { - deviceMembership = new HashSet(); - } - deviceMembership.add(dev); - } - - public void addDeviceMembership(Set devices) { - if (null == devices) { - return; - } - if (null == deviceMembership) { - deviceMembership = new HashSet(); - } - deviceMembership.addAll(devices); - } - - public void removeDeviceMembership(Device dev) { - if (null == dev || null == deviceMembership) { - return; - } - deviceMembership.remove(dev); - } - - public void removeDeviceMembership(Set devices) { - if (null == devices || null == deviceMembership) { - return; - } - deviceMembership.removeAll(devices); - } - - public boolean isMemberOfAnyDevice() { - if (null == deviceMembership || deviceMembership.isEmpty()) { - return false; - } - return true; - } - public void setResourceRepresentation(SimulatorResourceModel resModel) throws NullPointerException { if (mResourceRepresentation == null) diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceCategory.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceCategory.java deleted file mode 100644 index b932abc..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceCategory.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.serviceprovider.model; - -public enum ResourceCategory { - SIMPLE, COLLECTION -} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java index acce7be..8b385c4 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceRepresentation.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.serviceprovider.model; import java.util.HashMap; diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceType.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceType.java index f9ec137..3d2de74 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceType.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/ResourceType.java @@ -17,5 +17,5 @@ package oic.simulator.serviceprovider.model; public enum ResourceType { - SINGLE, COLLECTION, DEVICE + SINGLE } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SingleResource.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SingleResource.java index b47b740..fcbbf3c 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SingleResource.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/model/SingleResource.java @@ -16,9 +16,6 @@ package oic.simulator.serviceprovider.model; -import java.util.HashSet; -import java.util.Set; - import org.oic.simulator.server.SimulatorResource.AutoUpdateType; /** @@ -26,77 +23,21 @@ import org.oic.simulator.server.SimulatorResource.AutoUpdateType; * information about the resource. */ public class SingleResource extends Resource { - private Set collectionMembership; - - private boolean getAllowed; - - private boolean putAllowed; - - private boolean postAllowed; - - private int automationId; - - private boolean resourceAutomationInProgress; - - private boolean attributeAutomationInProgress; - - private int automationUpdateInterval; - - private AutoUpdateType automationType; + private boolean getAllowed; - public SingleResource() { - setCollectionMembership(new HashSet()); - } + private boolean putAllowed; - public Set getCollectionMembership() { - return collectionMembership; - } + private boolean postAllowed; - public void setCollectionMembership( - Set collectionMembership) { - this.collectionMembership = collectionMembership; - } + private int automationId; - public void addCollectionMembership(CollectionResource resource) { - if (null == resource) { - return; - } - if (null == collectionMembership) { - collectionMembership = new HashSet(); - } - collectionMembership.add(resource); - } + private boolean resourceAutomationInProgress; - public void addCollectionMembership(Set resources) { - if (null == resources) { - return; - } - if (null == collectionMembership) { - collectionMembership = new HashSet(); - } - collectionMembership.addAll(resources); - } + private boolean attributeAutomationInProgress; - public void removeCollectionMembership(CollectionResource resource) { - if (null == resource || null == collectionMembership) { - return; - } - collectionMembership.remove(resource); - } - - public void removeCollectionMembership(Set collections) { - if (null == collections || null == collectionMembership) { - return; - } - collectionMembership.removeAll(collections); - } + private int automationUpdateInterval; - public boolean isMemberOfAnyCollection() { - if (null == collectionMembership || collectionMembership.isEmpty()) { - return false; - } - return true; - } + private AutoUpdateType automationType; public boolean isGetAllowed() { return getAllowed; diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java index fab87b9..4b5efb4 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/AttributeValueStringConverter.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.serviceprovider.utils; import java.util.Map; diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java index ebc12fc..2d59eb9 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java @@ -24,153 +24,155 @@ import org.oic.simulator.server.SimulatorResource.AutoUpdateType; */ public class Constants { - public static final String INT = "Int"; - public static final String DOUBLE = "Double"; - public static final String BOOL = "Boolean"; - public static final String STRING = "String"; - public static final String UNKNOWN = "Unknown"; + public static final String INT = "Int"; + public static final String DOUBLE = "Double"; + public static final String BOOL = "Boolean"; + public static final String STRING = "String"; + public static final String UNKNOWN = "Unknown"; - public static final String CONFIG_DIRECTORY_PATH = "/resource"; + public static final String CONFIG_DIRECTORY_PATH = "/resource"; - public static final String UNDERSCORE = "_"; - public static final String FORWARD_SLASH = "/"; + public static final String UNDERSCORE = "_"; + public static final String FORWARD_SLASH = "/"; - public static final String OIC_PREFIX = "/oic/r"; - public static final String SIMULATOR = "simulator"; + public static final String OIC_PREFIX = "/oic/r"; + public static final String SIMULATOR = "simulator"; - public static final String RESOURCE_URI = "Resource URI"; - public static final String RESOURCE_TYPE = "Resource Type"; - public static final String RESOURCE_TYPES = "Resource Types"; - public static final String RESOURCE_NAME = "Resource Name"; - public static final String RESOURCE_UID = "Resource ID"; - public static final String CONNECTIVITY_TYPE = "Connectivity Type"; + public static final String RESOURCE_URI = "Resource URI"; + public static final String RESOURCE_TYPE = "Resource Type"; + public static final String RESOURCE_TYPES = "Resource Types"; + public static final String RESOURCE_NAME = "Resource Name"; + public static final String RESOURCE_UID = "Resource ID"; + public static final String CONNECTIVITY_TYPE = "Connectivity Type"; + public static final String INTERFACE_TYPES = "Interface Types"; - public static final String[] META_PROPERTIES = { - RESOURCE_NAME, RESOURCE_URI, RESOURCE_TYPE }; + public static final String[] META_PROPERTIES = { + RESOURCE_NAME, RESOURCE_URI, RESOURCE_TYPE, INTERFACE_TYPES }; - public static final int META_PROPERTY_COUNT = META_PROPERTIES.length; + public static final int META_PROPERTY_COUNT = META_PROPERTIES.length; - public static final String ENABLE = "Enable"; - public static final String DISABLE = "Disable"; - public static final String ENABLED = "Enabled"; - public static final String DISABLED = "Disabled"; + public static final String ENABLE = "Enable"; + public static final String DISABLE = "Disable"; + public static final String ENABLED = "Enabled"; + public static final String DISABLED = "Disabled"; - public static final String AUTOMATION = "Automation"; - public static final String AUTOMATION_TYPE = "Automation Type"; - public static final String UPDATE_INTERVAL_IN_MS = "Update Interval(ms)"; + public static final String AUTOMATION = "Automation"; + public static final String AUTOMATION_TYPE = "Automation Type"; + public static final String UPDATE_INTERVAL_IN_MS = "Update Interval(ms)"; - public static final String[] AUTOMATION_SETTINGS = { - AUTOMATION_TYPE, UPDATE_INTERVAL_IN_MS }; + public static final String[] AUTOMATION_SETTINGS = { + AUTOMATION_TYPE, UPDATE_INTERVAL_IN_MS }; - public static final int AUTOMATION_SETTINGS_COUNT = AUTOMATION_SETTINGS.length; + public static final int AUTOMATION_SETTINGS_COUNT = AUTOMATION_SETTINGS.length; - public static final String START_RESOURCE_AUTOMATION = "Start Automation"; - public static final String STOP_RESOURCE_AUTOMATION = "Stop Automation"; + public static final String START_RESOURCE_AUTOMATION = "Start Automation"; + public static final String STOP_RESOURCE_AUTOMATION = "Stop Automation"; - public static final int DISPLAY_RESOURCE_URI_TOKEN_COUNT = 2; + public static final int DISPLAY_RESOURCE_URI_TOKEN_COUNT = 2; - public static final AutoUpdateType DEFAULT_AUTOMATION_TYPE = AutoUpdateType.ONE_TIME; + public static final AutoUpdateType DEFAULT_AUTOMATION_TYPE = AutoUpdateType.ONE_TIME; - public static final int DEFAULT_AUTOMATION_INTERVAL = 500; + public static final int DEFAULT_AUTOMATION_INTERVAL = 500; - public static final int PROPER_LOG_TIME_TOKEN_LENGTH = 3; + public static final int PROPER_LOG_TIME_TOKEN_LENGTH = 3; - public static final String[] BROWSE_RAML_FILTER_EXTENSIONS = new String[] { "*.raml" }; - public static final String[] SAVE_LOG_FILTER_EXTENSIONS = new String[] { - "*.log", "*" }; + public static final String[] BROWSE_RAML_FILTER_EXTENSIONS = new String[] { "*.raml" }; + public static final String[] SAVE_LOG_FILTER_EXTENSIONS = new String[] { + "*.log", "*" }; - public static final int LOG_SIZE = 1000; + public static final int LOG_SIZE = 1000; - public static final String INFO_LOG = "info_log"; - public static final String WARNING_LOG = "warning_log"; - public static final String ERROR_LOG = "error_log"; - public static final String DEBUG_LOG = "debug_log"; - public static final String UNKNOWN_LOG = "unknown_log"; + public static final String INFO_LOG = "info_log"; + public static final String WARNING_LOG = "warning_log"; + public static final String ERROR_LOG = "error_log"; + public static final String DEBUG_LOG = "debug_log"; + public static final String UNKNOWN_LOG = "unknown_log"; - public static final String INFO = "Info"; - public static final String WARNING = "Warning"; - public static final String ERROR = "Error"; - public static final String DEBUG = "Debug"; + public static final String INFO = "Info"; + public static final String WARNING = "Warning"; + public static final String ERROR = "Error"; + public static final String DEBUG = "Debug"; - public static final String CHECKED = "Checked"; - public static final String UNCHECKED = "Unchecked"; - public static final String NOTIFY_BUTTON_SELECTED = "Notify_Selected"; - public static final String NOTIFY_BUTTON_UNSELECTED = "Notify_Unselected"; + public static final String CHECKED = "Checked"; + public static final String UNCHECKED = "Unchecked"; + public static final String NOTIFY_BUTTON_SELECTED = "Notify_Selected"; + public static final String NOTIFY_BUTTON_UNSELECTED = "Notify_Unselected"; - public static final String CREATE_PAGE_TITLE = "Create Resource"; - public static final String CREATE_PAGE_MESSAGE = "Create a resource from RAML file"; + public static final String CREATE_PAGE_TITLE = "Create Resource"; + public static final String CREATE_PAGE_MESSAGE = "Create a resource from RAML file"; - public static final String DELETE_PAGE_TITLE = "Delete Resource"; - public static final String DELETE_PAGE_MESSAGE = "Select the resource(s) to be deleted"; + public static final String DELETE_PAGE_TITLE = "Delete Resource"; + public static final String DELETE_PAGE_MESSAGE = "Select the resource(s) to be deleted"; - public static final String RAML_FILE_PREFIX = "/resource/"; + public static final String RAML_FILE_PREFIX = "/resource/"; - public static final String RAML_FILE_EXTENSION = ".raml"; - public static final String JSON_FILE_EXTENSION = ".json"; + public static final String RAML_FILE_EXTENSION = ".raml"; + public static final String JSON_FILE_EXTENSION = ".json"; - public static final String SPLIT_BY_DOT_PATTERN = "\\."; + public static final String SPLIT_BY_DOT_PATTERN = "\\."; // Platform information - public static final String PLATFORM_ID = "Id"; - public static final String PLATFORM_MANUFAC_NAME = "Manufacturer Name"; - public static final String PLATFORM_MANUFAC_URL = "Manufacturer URL"; - public static final String PLATFORM_MODEL_NO = "Model Number"; - public static final String PLATFORM_DATE_OF_MANUFAC = "Date of Manufacture"; - public static final String PLATFORM_VERSION = "Version"; - public static final String PLATFORM_OS_VERSION = "OS Version"; - public static final String PLATFORM_HARDWARE_VERSION = "HardWare Version"; - public static final String PLATFORM_FIRMWARE_VERSION = "Firmware Version"; - public static final String PLATFORM_SUPPORT_URL = "Support URL"; - public static final String PLATFORM_SYSTEM_TIME = "System Time"; + public static final String PLATFORM_ID = "Id"; + public static final String PLATFORM_MANUFAC_NAME = "Manufacturer Name"; + public static final String PLATFORM_MANUFAC_URL = "Manufacturer URL"; + public static final String PLATFORM_MODEL_NO = "Model Number"; + public static final String PLATFORM_DATE_OF_MANUFAC = "Date of Manufacture"; + public static final String PLATFORM_VERSION = "Version"; + public static final String PLATFORM_OS_VERSION = "OS Version"; + public static final String PLATFORM_HARDWARE_VERSION = "HardWare Version"; + public static final String PLATFORM_FIRMWARE_VERSION = "Firmware Version"; + public static final String PLATFORM_SUPPORT_URL = "Support URL"; + public static final String PLATFORM_SYSTEM_TIME = "System Time"; // Device information - public static final String DEVICE_NAME = "Device Name"; - public static final String DEVICE_ID = "Device ID"; - public static final String DEVICE_SPEC_VERSION = "Spec Version"; - public static final String DEVICE_DMV = "Data Model Version"; + public static final String DEVICE_NAME = "Device Name"; + public static final String DEVICE_ID = "Device ID"; + public static final String DEVICE_SPEC_VERSION = "Spec Version"; + public static final String DEVICE_DMV = "Data Model Version"; - public static final String SAMPLE_LIGHT = "sample.light"; + public static final String SAMPLE_LIGHT = "sample.light"; - public static final String UPDATE_PROP_PAGE_TITLE = "Update Properties"; - public static final String UPDATE_PROP_PAGE_MESSAGE = "Update the default values of resource properties"; + public static final String UPDATE_PROP_PAGE_TITLE = "Update Properties"; + public static final String UPDATE_PROP_PAGE_MESSAGE = "Update the default values of resource properties"; - public static final String START_STOP_PAGE_TITLE = "Start/Stop Resource"; - public static final String START_STOP_PAGE_MESSAGE = "This page allows to start or stop the created resource(s)"; + public static final String START_STOP_PAGE_TITLE = "Start/Stop Resource"; + public static final String START_STOP_PAGE_MESSAGE = "This page allows to start or stop the created resource(s)"; - public static final String START_RESOURCE = "Start Resource"; - public static final String STOP_RESOURCE = "Stop Resource"; + public static final String START_RESOURCE = "Start Resource"; + public static final String STOP_RESOURCE = "Stop Resource"; - public static final String DELETE_RESOURCE = "Delete Resource"; + public static final String DELETE_RESOURCE = "Delete Resource"; - public static final String MAIN_PAGE_TITLE = "Create Resource"; - public static final String MAIN_PAGE_MESSAGE = "Simple resource or Collection resource"; + public static final String MAIN_PAGE_TITLE = "Create Resource"; + public static final String MAIN_PAGE_MESSAGE = "Create a Simple resource"; - public static final String SIMPLE_PAGE_TITLE = "Create Simple Resource"; - public static final String SIMPLE_PAGE_MESSAGE = "Either manually or from RAML file"; + public static final String SIMPLE_PAGE_TITLE = "Create Simple Resource"; + public static final String SIMPLE_PAGE_MESSAGE = "Either manually or from RAML file"; - public static final String SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_TITLE = "Create Simple Resource(Step 1 of 3)"; - public static final String SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE = "Fill basic details of the resource"; + public static final String SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_TITLE = "Create Simple Resource(Step 1 of 3)"; + public static final String SIMPLE_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE = "Fill basic details of the resource"; - public static final String SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_TITLE = "Create Simple Resource(Step 2 of 3)"; - public static final String SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_MESSAGE = "Add attributes to the resource"; + public static final String SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_TITLE = "Create Simple Resource(Step 2 of 3)"; + public static final String SIMPLE_RESOURCE_ADD_ATTRIBUTE_PAGE_MESSAGE = "Add attributes to the resource"; - public static final String SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_TITLE = "Create Simple Resource(Step 3 of 3)"; - public static final String SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_MESSAGE = "Fill other details of the resource"; + public static final String SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_TITLE = "Create Simple Resource(Step 3 of 3)"; + public static final String SIMPLE_RESOURCE_OTHER_DETAILS_PAGE_MESSAGE = "Fill other details of the resource"; - public static final String COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE = "Create Collection Resource"; - public static final String COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE = "Fill basic details of the resource"; + public static final String SINGLE_RESOURCE = "Single Resource"; + public static final String INVALID_URI_MESSAGE = "Resource URI should start with a '/' followed by atleast one character and it should not contain either # or ? or % or consecutive '/'."; + public static final int TREE_EXPANSION_LEVEL = 10; - public static final String COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_TITLE = "Create Collection Resource"; - public static final String COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_MESSAGE = "Add other resources to this collection resource"; + public static final String BASELINE_INTERFACE = "oic.if.baseline"; + public static final String LINKS_LIST_INTERFACE = "oic.if.ll"; + public static final String BATCH_INTERFACE = "oic.if.b"; + public static final String LINK_BATCH_INTERFACE = "oic.if.lb"; + public static final String READ_ONLY_INTERFACE = "oic.if.r"; + public static final String READ_WRITE_INTERFACE = "oic.if.rw"; + public static final String ACTUATOR_INTERFACE = "oic.if.a"; + public static final String SENSOR_INTERFACE = "oic.if.s"; - public static final String CREATE_DEVICE_PAGE_TITLE = "Create Device"; - public static final String CREATE_DEVICE_PAGE_MESSAGE = "Create a logical device which holds a group of resources"; + public static final String DEFAULT_SINGLE_RESOURCE_INTERFACE = "oic.if.baseline"; - public static final String DEVICE = "Create Device"; - public static final String SINGLE_RESOURCE = "Single Resource"; - public static final String COLLECTION_RESOURCE = "Collection Resource"; - public static final String INVALID_URI_MESSAGE = "Resource URI should start with a '/' followed by atleast one character and it should not contain either # or ? or % or consecutive '/'."; - public static final int TREE_EXPANSION_LEVEL = 10; + public static final int MAX_RESOURCE_COUNT = 200; - public static final int MAX_RESOURCE_COUNT = 200; } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java index cc74473..23be6db 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java @@ -20,15 +20,15 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.Date; import java.util.Enumeration; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.Vector; import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.model.Device; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.model.SingleResource; @@ -43,38 +43,6 @@ import org.oic.simulator.SimulatorException; */ public class Utility { - public static String fileNameToDisplay(String fileName) { - if (null == fileName || fileName.length() < 1) { - return null; - } - // Remove the RAML file standard prefix - int len = Constants.RAML_FILE_PREFIX.length(); - if (len > 0) { - if (fileName.startsWith(Constants.RAML_FILE_PREFIX)) { - fileName = fileName.substring(len); - } - } - - // Removing the file extension - int index = fileName.lastIndexOf('.'); - fileName = fileName.substring(0, index); - return fileName; - } - - public static String displayToFileName(String displayName) { - if (null == displayName || displayName.length() < 1) { - return null; - } - String fileName; - // Adding the prefix - fileName = Constants.RAML_FILE_PREFIX + displayName; - - // Adding the file extension - fileName = fileName + Constants.RAML_FILE_EXTENSION; - - return fileName; - } - public static String getAutomationStatus(boolean status) { if (status) { return Constants.ENABLED; @@ -147,31 +115,6 @@ public class Utility { return list; } - public static List getCollectionResourceListFromSet( - Set resources) { - if (null == resources) { - return null; - } - List list = new ArrayList(); - Iterator typeItr = resources.iterator(); - while (typeItr.hasNext()) { - list.add(typeItr.next()); - } - return list; - } - - public static List getDeviceListFromSet(Set devices) { - if (null == devices) { - return null; - } - List list = new ArrayList(); - Iterator typeItr = devices.iterator(); - while (typeItr.hasNext()) { - list.add(typeItr.next()); - } - return list; - } - public static Set convertVectorToSet(Vector vector) { if (null == vector || vector.isEmpty()) { return null; @@ -342,12 +285,12 @@ public class Utility { } public static Vector convertSetToVectorString( - Set allowedValues) { + Set allowedValues) { if (null == allowedValues || allowedValues.size() < 1) { return null; } Vector resultVec = new Vector(); - Iterator itr = allowedValues.iterator(); + Iterator itr = allowedValues.iterator(); try { while (itr.hasNext()) { resultVec.add((String) itr.next()); @@ -411,202 +354,97 @@ public class Utility { return resultSet; } - public static List convertCollectionTypeResourceListToBaseType( - List resources) { - if (null == resources || resources.isEmpty()) { - return null; - } - List resultSet = new ArrayList(); - Iterator itr = resources.iterator(); - while (itr.hasNext()) { - resultSet.add(itr.next()); - } - return resultSet; - } - - public static Comparator resourceComparator = new Comparator() { - public int compare( - Resource res1, - Resource res2) { - String s1 = res1 - .getResourceName(); - String s2 = res2 - .getResourceName(); - - String s1Part = s1 - .replaceAll( - "\\d", - ""); - String s2Part = s2 - .replaceAll( - "\\d", - ""); - - if (s1Part - .equalsIgnoreCase(s2Part)) { - return extractInt(s1) - - extractInt(s2); - } - return s1 - .compareTo(s2); - } - - int extractInt( - String s) { - String num = s - .replaceAll( - "\\D", - ""); - // return - // 0 - // if - // no - // digits - // found - return num - .isEmpty() ? 0 - : Integer - .parseInt(num); - } - }; - - public static Comparator singleResourceComparator = new Comparator() { - public int compare( - SingleResource res1, - SingleResource res2) { - String s1 = res1 - .getResourceName(); - String s2 = res2 - .getResourceName(); - - String s1Part = s1 - .replaceAll( - "\\d", - ""); - String s2Part = s2 - .replaceAll( - "\\d", - ""); - - if (s1Part - .equalsIgnoreCase(s2Part)) { - return extractInt(s1) - - extractInt(s2); - } - return s1 - .compareTo(s2); - } - - int extractInt( - String s) { - String num = s - .replaceAll( - "\\D", - ""); - // return - // 0 - // if - // no - // digits - // found - return num - .isEmpty() ? 0 - : Integer - .parseInt(num); - } - }; - - public static Comparator collectionResourceComparator = new Comparator() { - public int compare( - CollectionResource res1, - CollectionResource res2) { - String s1 = res1 - .getResourceName(); - String s2 = res2 - .getResourceName(); - - String s1Part = s1 - .replaceAll( - "\\d", - ""); - String s2Part = s2 - .replaceAll( - "\\d", - ""); - - if (s1Part - .equalsIgnoreCase(s2Part)) { - return extractInt(s1) - - extractInt(s2); - } - return s1 - .compareTo(s2); - } - - int extractInt( - String s) { - String num = s - .replaceAll( - "\\D", - ""); - // return - // 0 - // if - // no - // digits - // found - return num - .isEmpty() ? 0 - : Integer - .parseInt(num); - } - }; - - public static Comparator deviceComparator = new Comparator() { - public int compare( - Device res1, - Device res2) { - String s1 = res1 - .getDeviceName(); - String s2 = res2 - .getDeviceName(); - - String s1Part = s1 - .replaceAll( - "\\d", - ""); - String s2Part = s2 - .replaceAll( - "\\d", - ""); - - if (s1Part - .equalsIgnoreCase(s2Part)) { - return extractInt(s1) - - extractInt(s2); - } - return s1 - .compareTo(s2); - } - - int extractInt( - String s) { - String num = s - .replaceAll( - "\\D", - ""); - // return - // 0 - // if - // no - // digits - // found - return num - .isEmpty() ? 0 - : Integer - .parseInt(num); - } - }; + public static Comparator resourceComparator = new Comparator() { + public int compare( + Resource res1, + Resource res2) { + String s1 = res1 + .getResourceName(); + String s2 = res2 + .getResourceName(); + + String s1Part = s1 + .replaceAll( + "\\d", + ""); + String s2Part = s2 + .replaceAll( + "\\d", + ""); + + if (s1Part + .equalsIgnoreCase(s2Part)) { + return extractInt(s1) + - extractInt(s2); + } + return s1 + .compareTo(s2); + } + + int extractInt( + String s) { + String num = s + .replaceAll( + "\\D", + ""); + // return + // 0 + // if + // no + // digits + // found + return num + .isEmpty() ? 0 + : Integer + .parseInt(num); + } + }; + + public static Comparator singleResourceComparator = new Comparator() { + public int compare( + SingleResource res1, + SingleResource res2) { + String s1 = res1 + .getResourceName(); + String s2 = res2 + .getResourceName(); + + String s1Part = s1 + .replaceAll( + "\\d", + ""); + String s2Part = s2 + .replaceAll( + "\\d", + ""); + + if (s1Part + .equalsIgnoreCase(s2Part)) { + return extractInt(s1) + - extractInt(s2); + } + return s1 + .compareTo(s2); + } + + int extractInt( + String s) { + String num = s + .replaceAll( + "\\D", + ""); + // return + // 0 + // if + // no + // digits + // found + return num + .isEmpty() ? 0 + : Integer + .parseInt(num); + } + }; // This method only works for attributes whose values are of type int, // double, bool, string and 1-D array of primitive types @@ -682,4 +520,18 @@ public class Utility { return true; } + public static Map getResourceInterfaces( + Class resourceClass) { + Map ifTypes = null; + if (resourceClass == SingleResource.class) { + ifTypes = new HashMap(); + ifTypes.put(Constants.BASELINE_INTERFACE, "Baseline"); + ifTypes.put(Constants.READ_ONLY_INTERFACE, "Read-Only"); + ifTypes.put(Constants.READ_WRITE_INTERFACE, "Read-Write"); + ifTypes.put(Constants.ACTUATOR_INTERFACE, "Actuator"); + ifTypes.put(Constants.SENSOR_INTERFACE, "Sensor"); + } + return ifTypes; + } + } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java index d0d5378..4b956cf 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeEditingSupport.java @@ -16,13 +16,13 @@ package oic.simulator.serviceprovider.view; +import java.util.Date; import java.util.List; import oic.simulator.serviceprovider.Activator; import oic.simulator.serviceprovider.manager.ResourceManager; import oic.simulator.serviceprovider.model.AttributeElement; import oic.simulator.serviceprovider.model.AutomationSettingHelper; -import oic.simulator.serviceprovider.model.CollectionResource; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.model.ResourceRepresentation; import oic.simulator.serviceprovider.model.SingleResource; @@ -46,10 +46,13 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IPartListener2; +import org.eclipse.ui.IWorkbenchPartReference; import org.oic.simulator.AttributeProperty; import org.oic.simulator.AttributeValue; import org.oic.simulator.AttributeValue.TypeInfo; import org.oic.simulator.AttributeValue.ValueType; +import org.oic.simulator.ILogger.Level; import org.oic.simulator.InvalidArgsException; import org.oic.simulator.SimulatorResourceAttribute; import org.oic.simulator.server.SimulatorResource.AutoUpdateType; @@ -81,6 +84,82 @@ public class AttributeEditingSupport { public AttributeValueEditor(TreeViewer viewer) { super(viewer); this.viewer = viewer; + + // Using the part listener to refresh the viewer on various part + // events. + // If combo list is open, then click events on other parts of the + // view or outside the combo should hide the editor. + // Refreshing the viewer hides the combo and other editors which are + // active. + IPartListener2 partListener; + partListener = new IPartListener2() { + + @Override + public void partVisible(IWorkbenchPartReference partRef) { + } + + @Override + public void partOpened(IWorkbenchPartReference partRef) { + } + + @Override + public void partInputChanged(IWorkbenchPartReference partRef) { + } + + @Override + public void partHidden(IWorkbenchPartReference partRef) { + } + + @Override + public void partDeactivated(IWorkbenchPartReference partRef) { + String viewId = partRef.getId(); + if (viewId.equals(AttributeView.VIEW_ID)) { + refreshViewer(); + } + } + + @Override + public void partClosed(IWorkbenchPartReference partRef) { + } + + @Override + public void partBroughtToTop(IWorkbenchPartReference partRef) { + } + + @Override + public void partActivated(IWorkbenchPartReference partRef) { + String viewId = partRef.getId(); + if (viewId.equals(AttributeView.VIEW_ID)) { + refreshViewer(); + } + } + }; + + try { + Activator.getDefault().getWorkbench() + .getActiveWorkbenchWindow().getActivePage() + .addPartListener(partListener); + } catch (NullPointerException e) { + Activator + .getDefault() + .getLogManager() + .log(Level.ERROR.ordinal(), + new Date(), + "There is an error while configuring the listener for UI.\n" + + Utility.getSimulatorErrorString(e, + null)); + } + } + + public void refreshViewer() { + if (null == viewer) + return; + + Tree tree = viewer.getTree(); + if (null == tree || tree.isDisposed()) + return; + + viewer.refresh(); } @Override @@ -98,9 +177,10 @@ public class AttributeEditingSupport { return null; } - // If selected resource is a collection, then editor support is not + // If selected resource is not a single resource, then editor + // support is not // required. - if (res instanceof CollectionResource) { + if (!(res instanceof SingleResource)) { return null; } @@ -383,7 +463,7 @@ public class AttributeEditingSupport { return null; } - if (resource instanceof CollectionResource) { + if (!(resource instanceof SingleResource)) { return null; } if (((SingleResource) resource).isResourceAutomationInProgress()) { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java index d7cc732..1d80604 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java @@ -23,7 +23,6 @@ import oic.simulator.serviceprovider.listener.ISelectionChangedListener; import oic.simulator.serviceprovider.manager.ResourceManager; import oic.simulator.serviceprovider.manager.UiListenerHandler; import oic.simulator.serviceprovider.model.AttributeElement; -import oic.simulator.serviceprovider.model.Device; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.model.ResourceRepresentation; import oic.simulator.serviceprovider.model.SingleResource; @@ -37,6 +36,8 @@ import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewerColumn; import org.eclipse.jface.viewers.Viewer; 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.graphics.Image; import org.eclipse.swt.layout.GridData; @@ -115,23 +116,6 @@ public class AttributeView extends ViewPart { } }); } - - @Override - public void onDeviceSelectionChange(Device dev) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - if (null != attViewer) { - Tree tree = attViewer.getTree(); - if (null != tree && !tree.isDisposed()) { - // tbl.deselectAll(); - tree.removeAll(); - tree.setLinesVisible(false); - } - } - } - }); - } }; dataChangeListener = new IDataChangeListener() { @@ -293,6 +277,7 @@ public class AttributeView extends ViewPart { TreeColumn attValue = new TreeColumn(tree, SWT.NONE); attValue.setWidth(attTblColWidth[1]); attValue.setText(attTblHeaders[1]); + TreeViewerColumn attValueVwrCol = new TreeViewerColumn(attViewer, attValue); attValueVwrCol.setEditingSupport(attributeEditor @@ -305,6 +290,25 @@ public class AttributeView extends ViewPart { automation); automationVwrCol.setEditingSupport(attributeEditor .createAutomationEditor(attViewer)); + + addColumnListeners(); + } + + private void addColumnListeners() { + TreeColumn[] columns = attViewer.getTree().getColumns(); + for (TreeColumn column : columns) { + column.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + // Refreshing the viewer. If combo list is open, + // then click events on other parts of the view or outside + // the combo should hide the editor. + // Refreshing the viewer hides the combo and other editors + // which are active. + attViewer.refresh(); + } + }); + } } private void addManagerListeners() { @@ -386,7 +390,7 @@ public class AttributeView extends ViewPart { public Image getColumnImage(Object element, int col) { if (col == 2) { if (element instanceof AttributeElement) { - // Ignore for collection resource + // Ignore for non-single resource Resource res = resourceManager .getCurrentResourceInSelection(); if (res instanceof SingleResource) { @@ -433,7 +437,7 @@ public class AttributeView extends ViewPart { } case 2: { - // Ignore for collection resource + // Ignore for non-single resource Resource res = resourceManager .getCurrentResourceInSelection(); if (res instanceof SingleResource) { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java index 26160a5..ae70f4c 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java @@ -22,14 +22,12 @@ import oic.simulator.serviceprovider.Activator; import oic.simulator.serviceprovider.listener.ISelectionChangedListener; import oic.simulator.serviceprovider.manager.ResourceManager; import oic.simulator.serviceprovider.manager.UiListenerHandler; -import oic.simulator.serviceprovider.model.Device; import oic.simulator.serviceprovider.model.MetaProperty; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.utils.Constants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.EditingSupport; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.StyledCellLabelProvider; @@ -93,21 +91,6 @@ public class MetaPropertiesView extends ViewPart { } }); } - - @Override - public void onDeviceSelectionChange(final Device dev) { - Display.getDefault().asyncExec(new Runnable() { - - @Override - public void run() { - if (null != tableViewer) { - properties = getData(dev); - updateViewer(properties); - } - updateEditControls(dev); - } - }); - } }; } @@ -141,7 +124,7 @@ public class MetaPropertiesView extends ViewPart { if (editBtn.getText().equals("Edit")) { cancelBtn.setEnabled(true); editBtn.setText("Save"); - enable_edit = true; + setEnableEdit(true); } else { boolean result = false; Resource resourceInSelection = resourceManagerRef @@ -172,6 +155,7 @@ public class MetaPropertiesView extends ViewPart { boolean update = false; boolean uriChange = false; boolean nameChange = false; + if (resourceManagerRef.isPropValueChanged( resourceInSelection, properties, Constants.RESOURCE_NAME)) { @@ -189,9 +173,6 @@ public class MetaPropertiesView extends ViewPart { return; } - update = true; - uriChange = true; - if (resourceManagerRef .isResourceStarted(resourceInSelection)) { update = MessageDialog.openQuestion( @@ -202,17 +183,21 @@ public class MetaPropertiesView extends ViewPart { return; } } + + update = true; + uriChange = true; } if (update) { try { - result = Activator - .getDefault() - .getResourceManager() - .updateResourceProperties( - resourceManagerRef - .getCurrentResourceInSelection(), - properties, uriChange, - nameChange); + if (uriChange || nameChange) + result = Activator + .getDefault() + .getResourceManager() + .updateResourceProperties( + resourceManagerRef + .getCurrentResourceInSelection(), + properties, uriChange, + nameChange); } catch (SimulatorException ex) { result = false; } @@ -231,29 +216,10 @@ public class MetaPropertiesView extends ViewPart { updateViewer(properties); } } - } else { - Device dev = resourceManagerRef - .getCurrentDeviceInSelection(); - - // Null check - result = resourceManagerRef.isPropertyValueInvalid(dev, - properties, Constants.DEVICE_NAME); - if (result) { - MessageDialog.openError(parent.getShell(), - "Invalid Input", "Device Name is invalid."); - return; - } - - if (resourceManagerRef.isPropValueChanged(dev, - properties, Constants.DEVICE_NAME)) { - resourceManagerRef.updateDeviceProperties(dev, - properties); - } - } cancelBtn.setEnabled(false); editBtn.setText("Edit"); - enable_edit = false; + setEnableEdit(false); } } }); @@ -271,18 +237,12 @@ public class MetaPropertiesView extends ViewPart { .getCurrentResourceInSelection(); if (null != res) { properties = getData(res); - } else { - Device dev = resourceManagerRef - .getCurrentDeviceInSelection(); - if (null != dev) { - properties = getData(dev); - } } updateViewer(properties); cancelBtn.setEnabled(false); editBtn.setText("Edit"); - enable_edit = false; + setEnableEdit(false); } }); @@ -302,7 +262,7 @@ public class MetaPropertiesView extends ViewPart { if (editBtn.getText().equals("Save")) { editBtn.setText("Edit"); - enable_edit = false; + setEnableEdit(false); } if (null == obj) { @@ -324,34 +284,23 @@ public class MetaPropertiesView extends ViewPart { } } - private List getData(Device dev) { - if (null != dev) { - List metaPropertyList = resourceManagerRef - .getMetaProperties(dev); - return metaPropertyList; - } else { - return null; - } - } - private void updateViewer(List metaPropertyList) { if (null != tableViewer) { Table tbl = tableViewer.getTable(); + if (tbl.isDisposed()) { + return; + } if (null != metaPropertyList) { tableViewer.setInput(metaPropertyList.toArray()); - if (!tbl.isDisposed()) { - tbl.setLinesVisible(true); - } + tbl.setLinesVisible(true); } else { - if (!tbl.isDisposed()) { - tbl.removeAll(); - tbl.setLinesVisible(false); - } + tbl.removeAll(); + tbl.setLinesVisible(false); } } } - public void createColumns(TableViewer tableViewer) { + public void createColumns(final TableViewer tableViewer) { TableViewerColumn propName = new TableViewerColumn(tableViewer, SWT.NONE); propName.getColumn().setWidth(columnWidth[0]); @@ -369,15 +318,12 @@ public class MetaPropertiesView extends ViewPart { SWT.NONE); propValue.getColumn().setWidth(columnWidth[1]); propValue.getColumn().setText(columnHeaders[1]); - propValue.setLabelProvider(new ColumnLabelProvider() { + propValue.setLabelProvider(new StyledCellLabelProvider() { @Override - public String getText(Object element) { - MetaProperty prop = (MetaProperty) element; - if (null != prop) { - return prop.getPropValue(); - } else { - return ""; - } + public void update(ViewerCell cell) { + MetaProperty prop = (MetaProperty) cell.getElement(); + cell.setText(prop.getPropValue()); + super.update(cell); } }); propValue.setEditingSupport(new PropValueEditor(tableViewer)); @@ -430,8 +376,8 @@ public class MetaPropertiesView extends ViewPart { } @Override - protected CellEditor getCellEditor(Object element) { - if (!enable_edit) { + protected CellEditor getCellEditor(final Object element) { + if (!getEnableEdit()) { return null; } // Disabling edit for resource type @@ -439,6 +385,7 @@ public class MetaPropertiesView extends ViewPart { if (null != propName && propName.equals(Constants.RESOURCE_TYPE)) { return null; } + CellEditor editor = new TextCellEditor(viewer.getTable()); return editor; } @@ -451,10 +398,20 @@ public class MetaPropertiesView extends ViewPart { @Override protected void setValue(Object element, Object value) { MetaProperty prop = (MetaProperty) element; + if (prop.getPropName().equals(Constants.INTERFACE_TYPES)) { + return; + } prop.setPropValue(String.valueOf(value)); viewer.update(element, null); } + } + + private synchronized Boolean getEnableEdit() { + return enable_edit; + } + private synchronized void setEnableEdit(boolean value) { + enable_edit = value; } @Override diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java index a40717c..e3657b8 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java @@ -18,7 +18,6 @@ package oic.simulator.serviceprovider.view; import java.util.ArrayList; import java.util.List; -import java.util.Set; import oic.simulator.serviceprovider.Activator; import oic.simulator.serviceprovider.listener.IPropertiesChangedListener; @@ -26,23 +25,15 @@ import oic.simulator.serviceprovider.listener.IResourceListChangedListener; import oic.simulator.serviceprovider.manager.ResourceManager; import oic.simulator.serviceprovider.manager.UiListenerHandler; import oic.simulator.serviceprovider.model.AutomationSettingHelper; -import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.model.Device; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.model.ResourceType; import oic.simulator.serviceprovider.model.SingleResource; import oic.simulator.serviceprovider.utils.Constants; import oic.simulator.serviceprovider.utils.Utility; -import oic.simulator.serviceprovider.view.dialogs.AddResourceToCollections; -import oic.simulator.serviceprovider.view.dialogs.AddResourceToDevices; -import oic.simulator.serviceprovider.view.dialogs.AddResources; import oic.simulator.serviceprovider.view.dialogs.AutomationSettingDialog; import oic.simulator.serviceprovider.view.dialogs.CreateResourceWizard; import oic.simulator.serviceprovider.view.dialogs.DeleteResourceWizard; import oic.simulator.serviceprovider.view.dialogs.MainPage.Option; -import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromCollections; -import oic.simulator.serviceprovider.view.dialogs.RemoveResourceFromDevices; -import oic.simulator.serviceprovider.view.dialogs.RemoveResources; import oic.simulator.serviceprovider.view.dialogs.ResourceWizardDialog; import org.eclipse.jface.dialogs.MessageDialog; @@ -57,8 +48,6 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CTabFolder; -import org.eclipse.swt.custom.CTabItem; import org.eclipse.swt.events.MenuAdapter; import org.eclipse.swt.events.MenuEvent; import org.eclipse.swt.events.SelectionAdapter; @@ -74,7 +63,6 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.FilteredTree; import org.eclipse.ui.dialogs.PatternFilter; @@ -93,13 +81,6 @@ public class ResourceManagerView extends ViewPart { private Button deleteButton; private TreeViewer singleResTreeViewer; - private TreeViewer collectionResTreeViewer; - private TreeViewer deviceTreeViewer; - - private CTabFolder folder; - private CTabItem singleResTab; - private CTabItem collectionResTab; - private CTabItem deviceTab; private IResourceListChangedListener resourceListChangedListener; @@ -123,14 +104,6 @@ public class ResourceManagerView extends ViewPart { if (null != singleResTreeViewer) { singleResTreeViewer.refresh(); } - } else if (type == ResourceType.COLLECTION) { - if (null != collectionResTreeViewer) { - collectionResTreeViewer.refresh(); - } - } else { - if (null != deviceTreeViewer) { - deviceTreeViewer.refresh(); - } } // Trigger the visibility of delete button @@ -145,18 +118,13 @@ public class ResourceManagerView extends ViewPart { @Override public void run() { - if (null != singleResTreeViewer - && null != collectionResTreeViewer - && null != deviceTreeViewer) { - switch (type) { - case SINGLE: + switch (type) { + case SINGLE: + if (null != singleResTreeViewer) singleResTreeViewer.refresh(); - case COLLECTION: - collectionResTreeViewer.refresh(); - default: - deviceTreeViewer.refresh(); - } + break; } + // Trigger the visibility of delete button changeDeleteVisibility(); } @@ -169,17 +137,11 @@ public class ResourceManagerView extends ViewPart { @Override public void run() { - if (null != singleResTreeViewer - && null != collectionResTreeViewer - && null != deviceTreeViewer) { - switch (type) { - case SINGLE: + switch (type) { + case SINGLE: + if (null != singleResTreeViewer) singleResTreeViewer.refresh(); - case COLLECTION: - collectionResTreeViewer.refresh(); - default: - deviceTreeViewer.refresh(); - } + break; } } }); @@ -193,25 +155,8 @@ public class ResourceManagerView extends ViewPart { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { - if (null != singleResTreeViewer - && null != collectionResTreeViewer - && null != deviceTreeViewer) { + if (null != singleResTreeViewer) singleResTreeViewer.refresh(); - collectionResTreeViewer.refresh(); - deviceTreeViewer.refresh(); - } - } - }); - } - - @Override - public void onDevicePropertyChange() { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - if (null != deviceTreeViewer) { - deviceTreeViewer.refresh(); - } } }); } @@ -234,864 +179,46 @@ public class ResourceManagerView extends ViewPart { 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); - - // Create a Tab Folder. - folder = new CTabFolder(compContent, SWT.BORDER); - gd = new GridData(SWT.FILL, SWT.FILL, true, true); - folder.setLayoutData(gd); - folder.setSimple(false); - folder.setUnselectedCloseVisible(false); - folder.setUnselectedImageVisible(false); - folder.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - // Tab is switched. - singleResTreeViewer.setSelection(null); - collectionResTreeViewer.setSelection(null); - deviceTreeViewer.setSelection(null); - resourceManager.resourceSelectionChanged(null); - } - }); - - createSimpleResourcesArea(); - - createCollectionResourcesArea(); - - createDeviceArea(); - - folder.setSelection(singleResTab); - - addUIListeners(); - - addManagerListeners(); - - // If there is at least one resource exist, then enable the delete - // resource button - changeDeleteVisibility(); - } - - private void createSimpleResourcesArea() { - singleResTab = new CTabItem(folder, SWT.NULL); - singleResTab.setText("Simple Resources"); - - // Create a group to show all the discovered resources. - // Adding the group to the folder. - Group resourceGroup = new Group(folder, SWT.NONE); - // resourceGroup.setText("Discovered Resources"); - - Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - resourceGroup.setBackground(color); - - resourceGroup.setLayout(new GridLayout(1, false)); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); - resourceGroup.setLayoutData(gd); - - PatternFilter filter = new PatternFilter(); - FilteredTree filteredTree = new FilteredTree(resourceGroup, - SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true); - singleResTreeViewer = filteredTree.getViewer(); - singleResTreeViewer.getTree().setLayoutData( - new GridData(SWT.FILL, SWT.FILL, true, true)); - singleResTreeViewer - .setContentProvider(new SingleResourceContentProvider()); - singleResTreeViewer.setLabelProvider(new TreeLabelProvider()); - singleResTreeViewer.setInput(new Object()); - - singleResTreeViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent e) { - IStructuredSelection selection = (IStructuredSelection) e - .getSelection(); - if (null == selection) { - return; - } - - Resource res = null; - int size = selection.size(); - if (size == 1) { - res = (Resource) selection.getFirstElement(); - } - resourceManager.resourceSelectionChanged(res); - } - }); - - // TODO: Add menu items - addMenuToSimpleResources(); - - singleResTab.setControl(resourceGroup); - } - - private void addMenuToSimpleResources() { - if (null != singleResTreeViewer) { - final Tree resourceTreeHead = singleResTreeViewer.getTree(); - if (null != resourceTreeHead) { - // Below code creates menu entries and shows them on right - // clicking a resource - final Menu menu = new Menu(resourceTreeHead); - resourceTreeHead.setMenu(menu); - menu.addMenuListener(new MenuAdapter() { - @Override - public void menuShown(MenuEvent e) { - // Clear existing menu items - MenuItem[] items = menu.getItems(); - for (int index = 0; index < items.length; index++) { - items[index].dispose(); - } - - IStructuredSelection selection = ((IStructuredSelection) singleResTreeViewer - .getSelection()); - final SingleResource resource = (SingleResource) selection - .getFirstElement(); - if (null == resource) { - return; - } - - addAutomationMenu(menu, resource); - - // Menu to add resource to one or more collections. - MenuItem addToCollection = new MenuItem(menu, SWT.NONE); - addToCollection.setText("Add to Collection"); - addToCollection - .addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleCollections; - possibleCollections = resourceManager - .getCollectionsForAddingToSingleResource(resource); - if (null == possibleCollections - || possibleCollections - .isEmpty()) { - MessageDialog - .openError( - Display.getDefault() - .getActiveShell(), - "No possible candidates", - "There are no possible collections to which the resource can be added."); - return; - } - - AddResourceToCollections addToCollectionsDlg = new AddResourceToCollections( - Display.getDefault() - .getActiveShell(), - possibleCollections); - if (addToCollectionsDlg.open() != Window.OK) { - return; - } - - Set resultSet = addToCollectionsDlg - .getSelectedResourceList(); - - int addedCount = resourceManager - .addResourceToCollection( - resultSet, resource); - if (addedCount <= 0) { - MessageDialog - .openInformation(Display - .getDefault() - .getActiveShell(), - "Operation failed", - "Failed to add resources to the collection."); - return; - } - - collectionResTreeViewer.refresh(); - - deviceTreeViewer.refresh(); - - MessageDialog.openInformation( - Display.getDefault() - .getActiveShell(), - "Added", - "[" - + addedCount - + "/" - + resultSet.size() - + "] added to selected collections"); - } - }); - - // Menu to remove resource from one or more collections - // to which it is a member. - MenuItem removeFromCollection = new MenuItem(menu, - SWT.NONE); - removeFromCollection.setText("Remove from Collection"); - removeFromCollection - .addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleCollectionstoRemoveFrom; - possibleCollectionstoRemoveFrom = resourceManager - .getResourceReferences(resource); - if (null == possibleCollectionstoRemoveFrom - || possibleCollectionstoRemoveFrom - .isEmpty()) { - MessageDialog - .openError( - Display.getDefault() - .getActiveShell(), - "No possible candidates", - "Resource has not been added to any collections."); - return; - } - - RemoveResourceFromCollections removeFromCollectionsDlg = new RemoveResourceFromCollections( - Display.getDefault() - .getActiveShell(), - possibleCollectionstoRemoveFrom); - if (removeFromCollectionsDlg.open() != Window.OK) { - return; - } - - Set resultSet = removeFromCollectionsDlg - .getSelectedResourceList(); - - int removeCount = resourceManager - .removeResourceFromCollection( - resultSet, resource); - if (removeCount <= 0) { - MessageDialog - .openInformation(Display - .getDefault() - .getActiveShell(), - "Operation failed", - "Failed to remove resources from the collection."); - return; - } - - collectionResTreeViewer.refresh(); - - deviceTreeViewer.refresh(); - - MessageDialog.openInformation( - Display.getDefault() - .getActiveShell(), - "Removed", - "[" - + removeCount - + "/" - + resultSet.size() - + "] resource removed from selected collections"); - } - }); - - // Menu to add resource to one or more devices. - MenuItem addToDevice = new MenuItem(menu, SWT.NONE); - addToDevice.setText("Add to Device"); - addToDevice - .addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleDevices; - possibleDevices = resourceManager - .getDevicesForAddingToResource(resource); - if (null == possibleDevices - || possibleDevices.isEmpty()) { - MessageDialog - .openError( - Display.getDefault() - .getActiveShell(), - "No possible candidates", - "There are no possible devices to which the resource can be added."); - return; - } - - AddResourceToDevices addToDevicesDlg = new AddResourceToDevices( - Display.getDefault() - .getActiveShell(), - possibleDevices); - if (addToDevicesDlg.open() != Window.OK) { - return; - } - - Set resultSet = addToDevicesDlg - .getSelectedDeviceList(); - - resourceManager.addResourceToDevice( - resultSet, resource); - - deviceTreeViewer.refresh(); - - MessageDialog - .openInformation(Display - .getDefault() - .getActiveShell(), - "Added", - "Resource added to selected devices."); - } - }); - - // Menu to remove resource from one or more device to - // which it is a member. - MenuItem removeFromDevice = new MenuItem(menu, SWT.NONE); - removeFromDevice.setText("Remove from Device"); - removeFromDevice - .addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleDevices; - possibleDevices = resourceManager - .getDeviceReferences(resource); - if (null == possibleDevices - || possibleDevices.isEmpty()) { - MessageDialog - .openError( - Display.getDefault() - .getActiveShell(), - "No possible candidates", - "Resource has not been added to any devices."); - return; - } - - RemoveResourceFromDevices removeFromDevicesDlg = new RemoveResourceFromDevices( - Display.getDefault() - .getActiveShell(), - possibleDevices); - if (removeFromDevicesDlg.open() != Window.OK) { - return; - } - - Set resultSet = removeFromDevicesDlg - .getSelectedDeviceList(); - - resourceManager - .removeResourceFromDevice( - resultSet, resource); - - deviceTreeViewer.refresh(); - - MessageDialog - .openInformation(Display - .getDefault() - .getActiveShell(), - "Removed", - "Resource removed from selected devices"); - } - }); - - // Menu to remove resource from one or more device to - // which it is a member. - MenuItem deleteResource = new MenuItem(menu, SWT.NONE); - deleteResource.setText("Delete"); - deleteResource - .addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - try { - resourceManager - .removeResource(resource); - singleResTreeViewer.refresh(); - // if(refreshCollectionTree) - collectionResTreeViewer.refresh(); - // if(refreshDeviceTree) - deviceTreeViewer.refresh(); - - resourceManager - .resourceSelectionChanged(null); - - MessageDialog.openInformation( - Display.getDefault() - .getActiveShell(), - "Deleted", - "Resource deleted."); - } catch (SimulatorException e1) { - MessageDialog - .openInformation(Display - .getDefault() - .getActiveShell(), - "Deletion Failed", - "Failed to delete the resource."); - } - changeDeleteVisibility(); - } - }); - } - }); - } - } - } - - private void createCollectionResourcesArea() { - collectionResTab = new CTabItem(folder, SWT.NULL); - collectionResTab.setText("Collection Resources"); - - // Create a group to show all the discovered resources. - // Adding the group to the folder. - Group resourceGroup = new Group(folder, SWT.NONE); - // resourceGroup.setText("Discovered Resources"); - - Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - resourceGroup.setBackground(color); - - resourceGroup.setLayout(new GridLayout(1, false)); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); - resourceGroup.setLayoutData(gd); - - PatternFilter filter = new PatternFilter(); - FilteredTree filteredTree = new FilteredTree(resourceGroup, - SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true); - collectionResTreeViewer = filteredTree.getViewer(); - collectionResTreeViewer.getTree().setLayoutData( - new GridData(SWT.FILL, SWT.FILL, true, true)); - collectionResTreeViewer - .setContentProvider(new CollectionResourceContentProvider()); - collectionResTreeViewer.setLabelProvider(new TreeLabelProvider()); - collectionResTreeViewer.setInput(new Object()); - - collectionResTreeViewer - .addSelectionChangedListener(new ISelectionChangedListener() { - @Override - public void selectionChanged(SelectionChangedEvent e) { - IStructuredSelection selection = (IStructuredSelection) e - .getSelection(); - if (null == selection) { - return; - } - - Resource res = null; - int size = selection.size(); - if (size == 1) { - res = (Resource) selection.getFirstElement(); - } - resourceManager.resourceSelectionChanged(res); - } - }); - - // TODO: Add menu items - addMenuToCollectionResources(); - - collectionResTab.setControl(resourceGroup); - } - - private void addMenuToCollectionResources() { - if (null != collectionResTreeViewer) { - final Tree resourceTreeHead = collectionResTreeViewer.getTree(); - if (null != resourceTreeHead) { - // Below code creates menu entries and shows them on right - // clicking a resource - final Menu menu = new Menu(resourceTreeHead); - resourceTreeHead.setMenu(menu); - menu.addMenuListener(new MenuAdapter() { - @Override - public void menuShown(MenuEvent e) { - // Clear existing menu items - MenuItem[] items = menu.getItems(); - for (int index = 0; index < items.length; index++) { - items[index].dispose(); - } - - IStructuredSelection selection = ((IStructuredSelection) collectionResTreeViewer - .getSelection()); - final Resource resource = (Resource) selection - .getFirstElement(); - TreeItem[] treeItems = resourceTreeHead.getSelection(); - if (null == resource || null == treeItems) { - return; - } - - final TreeItem parent = treeItems[0].getParentItem(); - if (null == parent) { - System.out.println("No parent exist"); - // Selected item is a top-level collection - addMenuToTopLevelCollectionResources(menu, - (CollectionResource) resource); - } else { - if (resource instanceof SingleResource) - addAutomationMenu(menu, - (SingleResource) resource); - - MenuItem remFromParent = new MenuItem(menu, - SWT.NONE); - remFromParent.setText("Remove from Parent"); - remFromParent - .addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected( - SelectionEvent e) { - CollectionResource parentCollection = (CollectionResource) parent - .getData(); - String status; - try { - resourceManager - .removeResourceFromCollection( - parentCollection, - resource); - collectionResTreeViewer - .refresh(); - deviceTreeViewer.refresh(); - - resourceManager - .resourceSelectionChanged(null); - - status = "Resource removed from its parent"; - } catch (SimulatorException e1) { - status = "Failed to remove the resource from its parent"; - } - MessageDialog.openInformation( - Display.getDefault() - .getActiveShell(), - "Status", status); - } - }); - - if (resource instanceof SingleResource) { - // Menu Items for single resource will be added - // here. - } - } - } - }); - } - } - } - - private void addMenuToTopLevelCollectionResources(final Menu menu, - final CollectionResource colRes) { - // Menu to add one or more resources to the collection. - MenuItem addResources = new MenuItem(menu, SWT.CASCADE); - addResources.setText("Add Resources"); - - Menu addSubMenu = new Menu(menu); - addResources.setMenu(addSubMenu); - - MenuItem simpleResources = new MenuItem(addSubMenu, SWT.NONE); - simpleResources.setText("Simple"); - simpleResources.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleResources; - possibleResources = resourceManager - .getSingleTypeResourcesForAddingToCollectionResource(colRes); - if (null == possibleResources || possibleResources.isEmpty()) { - MessageDialog - .openError(Display.getDefault().getActiveShell(), - "No possible candidates", - "There are no possible simple resources that can be added."); - return; - } - - List resources = Utility - .convertSingleTypeResourceListToBaseType(possibleResources); - - AddResources addToCollectionsDlg = new AddResources(Display - .getDefault().getActiveShell(), resources); - if (addToCollectionsDlg.open() != Window.OK) { - return; - } - - Set resultSet = addToCollectionsDlg - .getSelectedResourceList(); - - int addedCount = resourceManager.addResourceToCollection( - colRes, resultSet); - if (addedCount <= 0) { - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Operation failed", - "Failed to add resources to the collection."); - return; - } - - collectionResTreeViewer.refresh(); - - deviceTreeViewer.refresh(); - - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Added", "[" + addedCount + "/" - + resultSet.size() - + "] resources added to the collection"); - } - }); - - MenuItem collectionResources = new MenuItem(addSubMenu, SWT.NONE); - collectionResources.setText("Collection"); - collectionResources.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleResources; - possibleResources = resourceManager - .getCollectionTypeResourcesForAddingToCollectionResource(colRes); - if (null == possibleResources || possibleResources.isEmpty()) { - MessageDialog - .openError(Display.getDefault().getActiveShell(), - "No possible candidates", - "There are no possible collections that can be added."); - return; - } - - List resources = Utility - .convertCollectionTypeResourceListToBaseType(possibleResources); - - AddResources addToCollectionsDlg = new AddResources(Display - .getDefault().getActiveShell(), resources); - if (addToCollectionsDlg.open() != Window.OK) { - return; - } - - Set resultSet = addToCollectionsDlg - .getSelectedResourceList(); - - int addedCount = resourceManager.addResourceToCollection( - colRes, resultSet); - if (addedCount <= 0) { - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Operation failed", - "Failed to add resources to the collection."); - return; - } - - collectionResTreeViewer.refresh(); - - deviceTreeViewer.refresh(); - - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Added", "[" + addedCount + "/" - + resultSet.size() - + "] resources added to the collection"); - } - }); - - // Menu to remove one or more resources from the collection. - MenuItem removeResources = new MenuItem(menu, SWT.CASCADE); - removeResources.setText("Remove Resources"); - - Menu removeSubMenu = new Menu(menu); - removeResources.setMenu(removeSubMenu); - - simpleResources = new MenuItem(removeSubMenu, SWT.NONE); - simpleResources.setText("Simple"); - simpleResources.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleResources; - possibleResources = resourceManager.getSingleTypeChilds(colRes); - if (null == possibleResources || possibleResources.isEmpty()) { - MessageDialog - .openError(Display.getDefault().getActiveShell(), - "No possible candidates", - "There are no possible simple resources which can be removed."); - return; - } - - List resources = Utility - .convertSingleTypeResourceListToBaseType(possibleResources); - - RemoveResources removeFromCollectionsDlg = new RemoveResources( - Display.getDefault().getActiveShell(), resources); - if (removeFromCollectionsDlg.open() != Window.OK) { - return; - } - - Set resultSet = removeFromCollectionsDlg - .getSelectedResourceList(); - - int removeCount = resourceManager - .removeResourcesFromCollection(colRes, resultSet); - if (removeCount <= 0) { - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Operation failed", - "Failed to remove resources from the collection."); - return; - } - - collectionResTreeViewer.refresh(); - - deviceTreeViewer.refresh(); - - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Removed", "[" + removeCount + "/" - + resultSet.size() - + "] resources removed from the collection"); - } - }); - - collectionResources = new MenuItem(removeSubMenu, SWT.NONE); - collectionResources.setText("Collection"); - collectionResources.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleResources; - possibleResources = resourceManager - .getCollectionTypeChilds(colRes); - if (null == possibleResources || possibleResources.isEmpty()) { - MessageDialog - .openError(Display.getDefault().getActiveShell(), - "No possible candidates", - "There are no possible collections which can be removed."); - return; - } - - List resources = Utility - .convertCollectionTypeResourceListToBaseType(possibleResources); - - RemoveResources removeFromCollectionsDlg = new RemoveResources( - Display.getDefault().getActiveShell(), resources); - if (removeFromCollectionsDlg.open() != Window.OK) { - return; - } - - Set resultSet = removeFromCollectionsDlg - .getSelectedResourceList(); - - int removeCount = resourceManager - .removeResourcesFromCollection(colRes, resultSet); - if (removeCount <= 0) { - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Operation failed", - "Failed to remove resources from the collection."); - return; - } - - collectionResTreeViewer.refresh(); - - deviceTreeViewer.refresh(); - - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Removed", "[" + removeCount + "/" - + resultSet.size() - + "] resources removed from the collection"); - } - }); - - // Menu to add resource to one or more devices. - MenuItem addToDevice = new MenuItem(menu, SWT.NONE); - addToDevice.setText("Add to Device"); - addToDevice.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleDevices; - possibleDevices = resourceManager - .getDevicesForAddingToResource(colRes); - if (null == possibleDevices || possibleDevices.isEmpty()) { - MessageDialog - .openError(Display.getDefault().getActiveShell(), - "No possible candidates", - "There are no possible devices to which the resource can be added."); - return; - } - - AddResourceToDevices addToDevicesDlg = new AddResourceToDevices( - Display.getDefault().getActiveShell(), possibleDevices); - if (addToDevicesDlg.open() != Window.OK) { - return; - } - - Set resultSet = addToDevicesDlg.getSelectedDeviceList(); - - resourceManager.addResourceToDevice(resultSet, colRes); - - deviceTreeViewer.refresh(); + Composite buttonComp = new Composite(compContent, SWT.NONE); + buttonComp.setLayout(new GridLayout(2, false)); - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Added", - "Resource added to selected devices."); - } - }); + gd = new GridData(); + gd.horizontalAlignment = SWT.FILL; + gd.grabExcessHorizontalSpace = true; - // Menu to remove resource from one or more device to which it is a - // member. - MenuItem removeFromDevice = new MenuItem(menu, SWT.NONE); - removeFromDevice.setText("Remove from Device"); - removeFromDevice.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleDevices; - possibleDevices = resourceManager.getDeviceReferences(colRes); - if (null == possibleDevices || possibleDevices.isEmpty()) { - MessageDialog.openError(Display.getDefault() - .getActiveShell(), "No possible candidates", - "Resource has not been added to any devices."); - return; - } + buttonComp.setLayoutData(gd); - RemoveResourceFromDevices removeFromDevicesDlg = new RemoveResourceFromDevices( - Display.getDefault().getActiveShell(), possibleDevices); - if (removeFromDevicesDlg.open() != Window.OK) { - return; - } + createButton = new Button(buttonComp, SWT.PUSH); + createButton.setText("Create"); + createButton.setToolTipText("Create Simulator Resource(s)"); - Set resultSet = removeFromDevicesDlg - .getSelectedDeviceList(); + gd = new GridData(); + gd.widthHint = 90; + createButton.setLayoutData(gd); - resourceManager.removeResourceFromDevice(resultSet, colRes); + deleteButton = new Button(buttonComp, SWT.PUSH); + deleteButton.setText("Delete"); + deleteButton.setToolTipText("Delete Simulator Resource(s)"); - deviceTreeViewer.refresh(); + gd = new GridData(); + gd.widthHint = 90; + deleteButton.setLayoutData(gd); - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Removed", - "Resource removed from selected devices"); - } - }); + createSimpleResourcesArea(compContent); - // Menu to remove resource from one or more device to which it is a - // member. - MenuItem deleteResource = new MenuItem(menu, SWT.NONE); - deleteResource.setText("Delete"); - deleteResource.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - /* - * boolean refreshCollectionTree = false; boolean - * refreshDeviceTree = false; - * if(resource.isMemberOfAnyCollection()) { - * refreshCollectionTree = true; } - * if(resource.isMemberOfAnyDevice()) { refreshDeviceTree = - * true; } - */ - try { - resourceManager.removeResource(colRes); - // if(refreshCollectionTree) - collectionResTreeViewer.refresh(); - // if(refreshDeviceTree) - deviceTreeViewer.refresh(); - - resourceManager.resourceSelectionChanged(null); - - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Deleted", "Resource deleted."); - } catch (SimulatorException e1) { - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Deletion Failed", - "Failed to delete the resource."); - } + addUIListeners(); - changeDeleteVisibility(); - } - }); + addManagerListeners(); + // If there is at least one resource exist, then enable the delete + // resource button + changeDeleteVisibility(); } - private void createDeviceArea() { - deviceTab = new CTabItem(folder, SWT.NULL); - deviceTab.setText("Devices"); - + private void createSimpleResourcesArea(Composite compContent) { // Create a group to show all the discovered resources. // Adding the group to the folder. - Group resourceGroup = new Group(folder, SWT.NONE); - // resourceGroup.setText("Discovered Resources"); + Group resourceGroup = new Group(compContent, SWT.NONE); Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); resourceGroup.setBackground(color); @@ -1103,14 +230,15 @@ public class ResourceManagerView extends ViewPart { PatternFilter filter = new PatternFilter(); FilteredTree filteredTree = new FilteredTree(resourceGroup, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true); - deviceTreeViewer = filteredTree.getViewer(); - deviceTreeViewer.getTree().setLayoutData( + singleResTreeViewer = filteredTree.getViewer(); + singleResTreeViewer.getTree().setLayoutData( new GridData(SWT.FILL, SWT.FILL, true, true)); - deviceTreeViewer.setContentProvider(new DeviceContentProvider()); - deviceTreeViewer.setLabelProvider(new TreeLabelProvider()); - deviceTreeViewer.setInput(new Object()); + singleResTreeViewer + .setContentProvider(new SingleResourceContentProvider()); + singleResTreeViewer.setLabelProvider(new TreeLabelProvider()); + singleResTreeViewer.setInput(new Object()); - deviceTreeViewer + singleResTreeViewer .addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent e) { @@ -1120,31 +248,21 @@ public class ResourceManagerView extends ViewPart { return; } + Resource res = null; int size = selection.size(); if (size == 1) { - Object obj = selection.getFirstElement(); - if (obj instanceof Device) { - resourceManager - .deviceSelectionChanged((Device) obj); - } else { - resourceManager - .resourceSelectionChanged((Resource) obj); - } - } else { - resourceManager.deviceSelectionChanged(null); + res = (Resource) selection.getFirstElement(); } + resourceManager.resourceSelectionChanged(res); } }); - // TODO: Add menu items - addMenuToDevices(); - - deviceTab.setControl(resourceGroup); + addMenuToSimpleResources(); } - private void addMenuToDevices() { - if (null != deviceTreeViewer) { - final Tree resourceTreeHead = deviceTreeViewer.getTree(); + private void addMenuToSimpleResources() { + if (null != singleResTreeViewer) { + final Tree resourceTreeHead = singleResTreeViewer.getTree(); if (null != resourceTreeHead) { // Below code creates menu entries and shows them on right // clicking a resource @@ -1159,252 +277,53 @@ public class ResourceManagerView extends ViewPart { items[index].dispose(); } - IStructuredSelection selection = ((IStructuredSelection) deviceTreeViewer + IStructuredSelection selection = ((IStructuredSelection) singleResTreeViewer .getSelection()); - final Object element = selection.getFirstElement(); - if (element instanceof Device) { - addMenuToDevices(menu, (Device) element); - } else { - final Resource resource = (Resource) element; - TreeItem[] treeItems = resourceTreeHead - .getSelection(); - if (null == resource || null == treeItems) { - return; - } + final SingleResource resource = (SingleResource) selection + .getFirstElement(); + if (null == resource) { + return; + } - if (resource instanceof SingleResource) - addAutomationMenu(menu, - (SingleResource) resource); - - final TreeItem parent = treeItems[0] - .getParentItem(); - MenuItem remFromParent = new MenuItem(menu, - SWT.NONE); - remFromParent.setText("Remove from Parent"); - remFromParent - .addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected( - SelectionEvent e) { - String status = "Resource removed from its parent."; - Object obj = parent.getData(); - if (obj instanceof Device) { - resourceManager - .removeResourceFromDevice( - (Device) obj, - resource); - } else { - try { - resourceManager - .removeResourceFromCollection( - (CollectionResource) obj, - resource); - collectionResTreeViewer - .refresh(); - status = "Resource removed from its parent"; - } catch (SimulatorException e1) { - status = "Failed to remove the resource from its parent"; - } - } - - deviceTreeViewer.refresh(); + addAutomationMenu(menu, resource); + + // Menu to remove the resource. + MenuItem deleteResource = new MenuItem(menu, SWT.NONE); + deleteResource.setText("Delete"); + deleteResource + .addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + try { + resourceManager + .removeResource(resource); + singleResTreeViewer.refresh(); + + resourceManager + .resourceSelectionChanged(null); MessageDialog.openInformation( Display.getDefault() .getActiveShell(), - "Status", status); + "Deleted", + "Resource deleted."); + } catch (SimulatorException e1) { + MessageDialog + .openInformation(Display + .getDefault() + .getActiveShell(), + "Deletion Failed", + "Failed to delete the resource."); } - }); - - if (resource instanceof SingleResource) { - // Menu Items for single resource will be added - // here. - } - } + changeDeleteVisibility(); + } + }); } }); } } } - private void addMenuToDevices(Menu menu, final Device dev) { - // Menu to add one or more resources to the collection. - MenuItem addResources = new MenuItem(menu, SWT.CASCADE); - addResources.setText("Add Resources"); - - Menu addSubMenu = new Menu(menu); - addResources.setMenu(addSubMenu); - - MenuItem simpleResources = new MenuItem(addSubMenu, SWT.NONE); - simpleResources.setText("Simple"); - simpleResources.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleResources; - possibleResources = resourceManager - .getSingleTypeResourcesForAddingToDevice(dev); - if (null == possibleResources || possibleResources.isEmpty()) { - MessageDialog - .openError(Display.getDefault().getActiveShell(), - "No possible candidates", - "There are no possible simple resources that can be added."); - return; - } - - List resources = Utility - .convertSingleTypeResourceListToBaseType(possibleResources); - - AddResources addDlg = new AddResources(Display.getDefault() - .getActiveShell(), resources); - if (addDlg.open() != Window.OK) { - return; - } - - Set resultSet = addDlg.getSelectedResourceList(); - - resourceManager.addResourceToDevice(dev, resultSet); - - deviceTreeViewer.refresh(); - - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Added", - "Single Resources added to the device"); - } - }); - - MenuItem collectionResources = new MenuItem(addSubMenu, SWT.NONE); - collectionResources.setText("Collection"); - collectionResources.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleResources; - possibleResources = resourceManager - .getCollectionTypeResourcesForAddingToDevice(dev); - if (null == possibleResources || possibleResources.isEmpty()) { - MessageDialog - .openError(Display.getDefault().getActiveShell(), - "No possible candidates", - "There are no possible collections that can be added."); - return; - } - - List resources = Utility - .convertCollectionTypeResourceListToBaseType(possibleResources); - - AddResources addDlg = new AddResources(Display.getDefault() - .getActiveShell(), resources); - if (addDlg.open() != Window.OK) { - return; - } - - Set resultSet = addDlg.getSelectedResourceList(); - - resourceManager.addResourceToDevice(dev, resultSet); - - deviceTreeViewer.refresh(); - - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Added", - "Collection Resources added to the device"); - } - }); - - // Menu to remove one or more resources from the collection. - MenuItem removeResources = new MenuItem(menu, SWT.CASCADE); - removeResources.setText("Remove Resources"); - - Menu removeSubMenu = new Menu(menu); - removeResources.setMenu(removeSubMenu); - - simpleResources = new MenuItem(removeSubMenu, SWT.NONE); - simpleResources.setText("Simple"); - simpleResources.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleResources; - possibleResources = resourceManager.getSingleTypeChilds(dev); - if (null == possibleResources || possibleResources.isEmpty()) { - MessageDialog - .openError(Display.getDefault().getActiveShell(), - "No possible candidates", - "There are no possible simple resources which can be removed."); - return; - } - - List resources = Utility - .convertSingleTypeResourceListToBaseType(possibleResources); - - RemoveResources removeDlg = new RemoveResources(Display - .getDefault().getActiveShell(), resources); - if (removeDlg.open() != Window.OK) { - return; - } - - Set resultSet = removeDlg.getSelectedResourceList(); - - resourceManager.removeResourcesFromDevice(dev, resultSet); - - collectionResTreeViewer.refresh(); - - deviceTreeViewer.refresh(); - - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Removed", - "Single Resources removed from the device"); - } - }); - - collectionResources = new MenuItem(removeSubMenu, SWT.NONE); - collectionResources.setText("Collection"); - collectionResources.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - List possibleResources; - possibleResources = resourceManager - .getCollectionTypeChilds(dev); - if (null == possibleResources || possibleResources.isEmpty()) { - MessageDialog - .openError(Display.getDefault().getActiveShell(), - "No possible candidates", - "There are no possible collections which can be removed."); - return; - } - - List resources = Utility - .convertCollectionTypeResourceListToBaseType(possibleResources); - - RemoveResources removeDlg = new RemoveResources(Display - .getDefault().getActiveShell(), resources); - if (removeDlg.open() != Window.OK) { - return; - } - - Set resultSet = removeDlg.getSelectedResourceList(); - - resourceManager.removeResourcesFromDevice(dev, resultSet); - - collectionResTreeViewer.refresh(); - - deviceTreeViewer.refresh(); - - MessageDialog.openInformation(Display.getDefault() - .getActiveShell(), "Removed", - "Collection Resources removed from the device"); - } - }); - - // Menu to remove the device. - MenuItem deleteDevice = new MenuItem(menu, SWT.NONE); - deleteDevice.setText("Delete"); - deleteDevice.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - resourceManager.removeDevice(dev); - deviceTreeViewer.refresh(); - } - }); - } - private void addAutomationMenu(final Menu menu, final SingleResource selectedResource) { MenuItem startItem = new MenuItem(menu, SWT.NONE); @@ -1500,8 +419,8 @@ public class ResourceManagerView extends ViewPart { public void run() { CreateResourceWizard createWizard = new CreateResourceWizard(); ResourceWizardDialog wizardDialog = new ResourceWizardDialog( - PlatformUI.getWorkbench().getDisplay() - .getActiveShell(), createWizard); + Display.getDefault().getActiveShell(), + createWizard); createWizard.setWizardDialog(wizardDialog); int open = wizardDialog.open(); if (open == WizardDialog.OK @@ -1509,22 +428,11 @@ public class ResourceManagerView extends ViewPart { Option option = createWizard.getMainPage() .getOption(); - if (option == Option.DEVICE) { - Device dev = createWizard.getCreatedDevice(); - if (null != dev) { - folder.setSelection(deviceTab); - deviceTreeViewer.setSelection( - new StructuredSelection(dev), true); - resourceManager.deviceSelectionChanged(dev); - deviceTreeViewer.expandToLevel(dev, - Constants.TREE_EXPANSION_LEVEL); - } - } else if (option == Option.SIMPLE_FROM_RAML + if (option == Option.SIMPLE_FROM_RAML || option == Option.SIMPLE) { SingleResource res = (SingleResource) createWizard .getCreatedResource(); if (null != res) { - folder.setSelection(singleResTab); boolean canSelect = true; if (option == Option.SIMPLE_FROM_RAML && createWizard.getResourceCount() > 1) { @@ -1538,19 +446,6 @@ public class ResourceManagerView extends ViewPart { .resourceSelectionChanged(res); } } - } else if (option == Option.COLLECTION_FROM_RAML - || option == Option.COLLECTION) { - CollectionResource res = (CollectionResource) createWizard - .getCreatedResource(); - if (null != res) { - folder.setSelection(collectionResTab); - collectionResTreeViewer.setSelection( - new StructuredSelection(res), true); - resourceManager - .resourceSelectionChanged(res); - collectionResTreeViewer.expandToLevel(res, - Constants.TREE_EXPANSION_LEVEL); - } } MessageDialog.openInformation(Display.getDefault() @@ -1581,8 +476,6 @@ public class ResourceManagerView extends ViewPart { int open = wizardDialog.open(); if (open == Window.OK) { singleResTreeViewer.refresh(); - collectionResTreeViewer.refresh(); - deviceTreeViewer.refresh(); MessageDialog.openInformation(Display.getDefault() .getActiveShell(), "Resource Deletion Status", deleteWizard @@ -1662,131 +555,14 @@ class SingleResourceContentProvider implements ITreeContentProvider { } } -class CollectionResourceContentProvider implements ITreeContentProvider { - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { - } - - @Override - public Object[] getChildren(Object parent) { - if (parent instanceof CollectionResource) { - CollectionResource cRes = (CollectionResource) parent; - Set childs = cRes.getChildResources(); - if (null == childs) { - return null; - } - return childs.toArray(); - } - return null; - } - - @Override - public Object[] getElements(Object parent) { - List resList; - resList = Activator.getDefault().getResourceManager() - .getCollectionResourceList(); - if (null == resList) { - resList = new ArrayList(); - } - return resList.toArray(); - } - - @Override - public Object getParent(Object child) { - return null; - } - - @Override - public boolean hasChildren(Object parent) { - if (parent instanceof CollectionResource) { - CollectionResource cRes = (CollectionResource) parent; - Set children = cRes.getChildResources(); - if (null != children && children.size() > 0) { - return true; - } - } - return false; - } -} - -class DeviceContentProvider implements ITreeContentProvider { - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { - } - - @Override - public Object[] getChildren(Object parent) { - if (parent instanceof Device) { - Device dev = (Device) parent; - Set children = dev.getChildResources(); - if (null != children && children.size() > 0) { - return children.toArray(); - } - } else if (parent instanceof CollectionResource) { - CollectionResource res = (CollectionResource) parent; - Set children = res.getChildResources(); - if (null != children && children.size() > 0) { - return children.toArray(); - } - } - return null; - } - - @Override - public Object[] getElements(Object parent) { - List deviceList; - deviceList = Activator.getDefault().getResourceManager() - .getDeviceList(); - if (null == deviceList) { - deviceList = new ArrayList(); - } - return deviceList.toArray(); - } - - @Override - public Object getParent(Object child) { - return null; - } - - @Override - public boolean hasChildren(Object parent) { - if (parent instanceof Device) { - Device dev = (Device) parent; - Set children = dev.getChildResources(); - if (null != children && children.size() > 0) { - return true; - } - } else if (parent instanceof CollectionResource) { - CollectionResource res = (CollectionResource) parent; - Set children = res.getChildResources(); - if (null != children && children.size() > 0) { - return true; - } - } - return false; - } -} - class TreeLabelProvider extends LabelProvider { @Override public String getText(Object element) { if (element instanceof Resource) { Resource res = (Resource) element; return res.getResourceName(); - } else { - Device dev = (Device) element; - return dev.getDeviceName(); } + return null; } @Override @@ -1794,12 +570,7 @@ class TreeLabelProvider extends LabelProvider { if (element instanceof SingleResource) { return Activator.getDefault().getImageRegistry() .get(Constants.SINGLE_RESOURCE); - } else if (element instanceof CollectionResource) { - return Activator.getDefault().getImageRegistry() - .get(Constants.COLLECTION_RESOURCE); - } else { - return Activator.getDefault().getImageRegistry() - .get(Constants.DEVICE); } + return null; } } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceObserverView.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceObserverView.java index e0d862f..b13e247 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceObserverView.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceObserverView.java @@ -25,7 +25,6 @@ import oic.simulator.serviceprovider.listener.IObserverListChangedListener; import oic.simulator.serviceprovider.listener.ISelectionChangedListener; import oic.simulator.serviceprovider.manager.ResourceManager; import oic.simulator.serviceprovider.manager.UiListenerHandler; -import oic.simulator.serviceprovider.model.Device; import oic.simulator.serviceprovider.model.ObserverDetail; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.utils.Constants; @@ -87,12 +86,6 @@ public class ResourceObserverView extends ViewPart { } }); } - - @Override - public void onDeviceSelectionChange(Device dev) { - // TODO Auto-generated method stub - - } }; resourceObserverListChangedListener = new IObserverListChangedListener() { @@ -156,7 +149,7 @@ public class ResourceObserverView extends ViewPart { createColumns(tblViewer); - // make lines and header visible + // Make lines and header visible final Table table = tblViewer.getTable(); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); table.setHeaderVisible(true); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java index 9280790..bbda598 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddAttributeDialog.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.serviceprovider.view.dialogs; import java.util.Iterator; @@ -78,7 +94,6 @@ public class AddAttributeDialog extends TitleAreaDialog { att = new AttributeHelper(); } else { attClone = att.clone(); - System.out.println("Cloned attribute's data:" + attClone); editOperation = true; } attHelper = att; @@ -99,9 +114,6 @@ public class AddAttributeDialog extends TitleAreaDialog { Composite container = new Composite(compLayout, SWT.NONE); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); GridLayout layout = new GridLayout(5, false); - /* - * layout.verticalSpacing = 10; layout.marginTop = 10; - */ container.setLayout(layout); Label attNameLbl = new Label(container, SWT.NULL); @@ -279,10 +291,7 @@ public class AddAttributeDialog extends TitleAreaDialog { updateControls(); dflValueTxt.setText(attHelper.getAttributeDflValue()); Type valuesType = attHelper.getValidValuesType(); - /* - * if (valuesType == Type.UNKNOWN) { noneBtn.setSelection(true); } - * else - */if (valuesType == Type.RANGE) { + if (valuesType == Type.RANGE) { rangeBtn.setSelection(true); noneBtn.setSelection(false); rangeOptionSelected(true); @@ -336,7 +345,6 @@ public class AddAttributeDialog extends TitleAreaDialog { @Override public void handleEvent(Event e) { String string = e.text; - System.out.println(string); char[] chars = new char[string.length()]; string.getChars(0, chars.length, chars, 0); for (int i = 0; i < chars.length; i++) { @@ -354,7 +362,6 @@ public class AddAttributeDialog extends TitleAreaDialog { } } } - // attHelper.setMin(minRangeTxt.getText() + string); } }); @@ -379,7 +386,6 @@ public class AddAttributeDialog extends TitleAreaDialog { } } } - // attHelper.setMax(maxRangeTxt.getText() + string); } }); @@ -389,7 +395,6 @@ public class AddAttributeDialog extends TitleAreaDialog { SingleTextInputDialog dialog = new SingleTextInputDialog( getShell(), "Add Attribute Value", "Attribute Value"); if (dialog.open() == Window.OK) { - System.out.println(dialog.getValue()); String value = dialog.getValue(); String type = attTypeCmb.getText(); if (!attHelper.isValueValid(value, type)) { @@ -406,7 +411,6 @@ public class AddAttributeDialog extends TitleAreaDialog { customValuesList.select(customValuesList.getItemCount() - 1); customValuesList.showSelection(); remBtn.setEnabled(true); - // attHelper.addValueToAllowedValues(value); } } } @@ -416,13 +420,8 @@ public class AddAttributeDialog extends TitleAreaDialog { @Override public void widgetSelected(SelectionEvent e) { int[] selection = customValuesList.getSelectionIndices(); - // String[] selectionStr = customValuesList.getSelection(); if (null != selection && selection.length > 0) { customValuesList.remove(selection); - /* - * for (String selected : selectionStr) { - * attHelper.removeValueFromAllowedValues(selected); } - */ } changeRemBtnVisibility(); @@ -446,7 +445,6 @@ public class AddAttributeDialog extends TitleAreaDialog { dflValueTxt.setText(""); String selected = attTypeCmb.getText(); - // attHelper.setAttributeType(selected); if (selected.equals(Constants.INT)) { enable(true); @@ -459,7 +457,6 @@ public class AddAttributeDialog extends TitleAreaDialog { customOptionSelected(false); detail.setText(defaultMessage + msgForDoubleType); } else if (selected.equals(Constants.BOOL)) { - // noneBtn.setSelection(true); enable(false); rangeOptionSelected(false); customOptionSelected(false); @@ -469,10 +466,8 @@ public class AddAttributeDialog extends TitleAreaDialog { rangeOptionSelected(false); cusValuesBtn.setEnabled(true); noneBtn.setEnabled(true); - // cusValuesBtn.setSelection(true); detail.setText(defaultMessage + msgForStringType); } else { - // noneBtn.setSelection(true); enable(false); rangeOptionSelected(false); customOptionSelected(false); @@ -701,11 +696,6 @@ public class AddAttributeDialog extends TitleAreaDialog { return false; } - /* - * @Override protected Point getInitialSize() { Point curSize = - * super.getInitialSize(); return new Point(curSize.x, curSize.y + 200); } - */ - @Override protected Point getInitialLocation(Point initialSize) { Rectangle shellBounds = Display.getDefault().getActiveShell() diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToCollections.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToCollections.java deleted file mode 100644 index 914e515..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToCollections.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.serviceprovider.view.dialogs; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.utils.Constants; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** - * This dialog is used for loading the RAML file. - */ -public class AddResourceToCollections extends TitleAreaDialog { - - private CheckboxTreeViewer treeViewer; - - List sourceList; - - Set selectedResourceList; - - public AddResourceToCollections(Shell parentShell, - List sourceList) { - super(parentShell); - this.sourceList = sourceList; - selectedResourceList = new HashSet(); - } - - @Override - public void create() { - super.create(); - setTitle("Add To Collections"); - setMessage("Select one or more collection resources to which the single resource will be added."); - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite compLayout = (Composite) super.createDialogArea(parent); - Composite container = new Composite(compLayout, SWT.NONE); - container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - GridLayout layout = new GridLayout(); - layout.verticalSpacing = 10; - layout.marginTop = 10; - container.setLayout(layout); - - Label lbl = new Label(container, SWT.NONE); - lbl.setText("Select Resources from:"); - GridData gd; - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - lbl.setLayoutData(gd); - - Group resourceGroup = new Group(container, SWT.NONE); - - Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - - resourceGroup.setLayout(new GridLayout()); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.heightHint = 300; - gd.horizontalSpan = 2; - resourceGroup.setLayoutData(gd); - - treeViewer = new CheckboxTreeViewer(resourceGroup); - treeViewer.getTree().setBackground(color); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessVerticalSpace = true; - gd.verticalAlignment = SWT.FILL; - // gd.heightHint = 300; - treeViewer.getTree().setLayoutData(gd); - treeViewer.setContentProvider(new TreeContentProvider()); - treeViewer.setLabelProvider(new TreeLabelProvider()); - treeViewer.setInput(new Object()); - treeViewer.addCheckStateListener(new ICheckStateListener() { - - @Override - public void checkStateChanged(CheckStateChangedEvent e) { - CollectionResource res = (CollectionResource) e.getElement(); - if (null != res) { - if (e.getChecked()) { - selectedResourceList.add(res); - System.out.println("Checked" + res.getResourceName()); - } else { - selectedResourceList.remove(res); - System.out.println("Unchecked:" + res.getResourceName()); - } - } - } - }); - - return compLayout; - } - - public Set getSelectedResourceList() { - return selectedResourceList; - } - - class TreeContentProvider implements ITreeContentProvider { - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { - } - - @Override - public Object[] getChildren(Object parent) { - return null; - } - - @Override - public Object[] getElements(Object parent) { - if (null == sourceList) { - sourceList = new ArrayList(); - } - return sourceList.toArray(); - } - - @Override - public Object getParent(Object child) { - return null; - } - - @Override - public boolean hasChildren(Object parent) { - return false; - } - } - - class TreeLabelProvider extends LabelProvider { - @Override - public String getText(Object element) { - CollectionResource res = (CollectionResource) element; - return res.getResourceName(); - } - - @Override - public Image getImage(Object element) { - if (element instanceof CollectionResource) { - return Activator.getDefault().getImageRegistry() - .get(Constants.COLLECTION_RESOURCE); - } else { - return null; - } - } - } - - @Override - protected void okPressed() { - if (selectedResourceList.isEmpty()) { - MessageDialog.openInformation( - Display.getDefault().getActiveShell(), - "No selection done.", "No resources are selected."); - return; - } - close(); - } - - @Override - public boolean isHelpAvailable() { - return false; - } -} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToDevices.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToDevices.java deleted file mode 100644 index 8eaaa5f..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourceToDevices.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.serviceprovider.view.dialogs; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.Device; -import oic.simulator.serviceprovider.utils.Constants; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** - * This dialog is used for loading the RAML file. - */ -public class AddResourceToDevices extends TitleAreaDialog { - - private CheckboxTreeViewer treeViewer; - - List sourceList; - - Set selectedDeviceList; - - public AddResourceToDevices(Shell parentShell, List sourceList) { - super(parentShell); - this.sourceList = sourceList; - selectedDeviceList = new HashSet(); - } - - @Override - public void create() { - super.create(); - setTitle("Add To Devices"); - setMessage("Select one or more devices to which the single resource will be added."); - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite compLayout = (Composite) super.createDialogArea(parent); - Composite container = new Composite(compLayout, SWT.NONE); - container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - GridLayout layout = new GridLayout(); - layout.verticalSpacing = 10; - layout.marginTop = 10; - container.setLayout(layout); - - Label lbl = new Label(container, SWT.NONE); - lbl.setText("Select Resources from:"); - GridData gd; - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - lbl.setLayoutData(gd); - - Group resourceGroup = new Group(container, SWT.NONE); - - Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - - resourceGroup.setLayout(new GridLayout()); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.heightHint = 300; - gd.horizontalSpan = 2; - resourceGroup.setLayoutData(gd); - - treeViewer = new CheckboxTreeViewer(resourceGroup); - treeViewer.getTree().setBackground(color); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessVerticalSpace = true; - gd.verticalAlignment = SWT.FILL; - // gd.heightHint = 300; - treeViewer.getTree().setLayoutData(gd); - treeViewer.setContentProvider(new TreeContentProvider()); - treeViewer.setLabelProvider(new TreeLabelProvider()); - treeViewer.setInput(new Object()); - treeViewer.addCheckStateListener(new ICheckStateListener() { - - @Override - public void checkStateChanged(CheckStateChangedEvent e) { - Device dev = (Device) e.getElement(); - if (null != dev) { - if (e.getChecked()) { - selectedDeviceList.add(dev); - System.out.println("Checked" + dev.getDeviceName()); - } else { - selectedDeviceList.remove(dev); - System.out.println("Unchecked:" + dev.getDeviceName()); - } - } - } - }); - - return compLayout; - } - - public Set getSelectedDeviceList() { - return selectedDeviceList; - } - - class TreeContentProvider implements ITreeContentProvider { - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { - } - - @Override - public Object[] getChildren(Object parent) { - return null; - } - - @Override - public Object[] getElements(Object parent) { - if (null == sourceList) { - sourceList = new ArrayList(); - } - return sourceList.toArray(); - } - - @Override - public Object getParent(Object child) { - return null; - } - - @Override - public boolean hasChildren(Object parent) { - return false; - } - } - - class TreeLabelProvider extends LabelProvider { - @Override - public String getText(Object element) { - Device dev = (Device) element; - return dev.getDeviceName(); - } - - @Override - public Image getImage(Object element) { - if (element instanceof Device) { - return Activator.getDefault().getImageRegistry() - .get(Constants.DEVICE); - } else { - return null; - } - } - } - - @Override - protected void okPressed() { - if (selectedDeviceList.isEmpty()) { - MessageDialog.openInformation( - Display.getDefault().getActiveShell(), - "No selection done.", "No devices are selected."); - return; - } - close(); - } - - @Override - public boolean isHelpAvailable() { - return false; - } -} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResources.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResources.java deleted file mode 100644 index 6e13f6c..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResources.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.serviceprovider.view.dialogs; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.model.Resource; -import oic.simulator.serviceprovider.utils.Constants; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** - * This dialog is used for loading the RAML file. - */ -public class AddResources extends TitleAreaDialog { - - private CheckboxTreeViewer treeViewer; - - List sourceList; - - Set selectedResourceList; - - public AddResources(Shell parentShell, List sourceList) { - super(parentShell); - this.sourceList = sourceList; - selectedResourceList = new HashSet(); - } - - @Override - public void create() { - super.create(); - setTitle("Add Resources"); - setMessage("Select one or more resources to be added."); - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite compLayout = (Composite) super.createDialogArea(parent); - Composite container = new Composite(compLayout, SWT.NONE); - container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - GridLayout layout = new GridLayout(); - layout.verticalSpacing = 10; - layout.marginTop = 10; - container.setLayout(layout); - - Label lbl = new Label(container, SWT.NONE); - lbl.setText("Select Resources from:"); - GridData gd; - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - lbl.setLayoutData(gd); - - Group resourceGroup = new Group(container, SWT.NONE); - - Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - - resourceGroup.setLayout(new GridLayout()); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.heightHint = 300; - gd.horizontalSpan = 2; - resourceGroup.setLayoutData(gd); - - treeViewer = new CheckboxTreeViewer(resourceGroup); - treeViewer.getTree().setBackground(color); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessVerticalSpace = true; - gd.verticalAlignment = SWT.FILL; - // gd.heightHint = 300; - treeViewer.getTree().setLayoutData(gd); - treeViewer.setContentProvider(new TreeContentProvider()); - treeViewer.setLabelProvider(new TreeLabelProvider()); - treeViewer.setInput(new Object()); - treeViewer.addCheckStateListener(new ICheckStateListener() { - - @Override - public void checkStateChanged(CheckStateChangedEvent e) { - Resource res = (Resource) e.getElement(); - if (null != res) { - if (e.getChecked()) { - selectedResourceList.add(res); - System.out.println("Checked" + res.getResourceName()); - } else { - selectedResourceList.remove(res); - System.out.println("Unchecked:" + res.getResourceName()); - } - } - } - }); - - return compLayout; - } - - public Set getSelectedResourceList() { - return selectedResourceList; - } - - class TreeContentProvider implements ITreeContentProvider { - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { - } - - @Override - public Object[] getChildren(Object parent) { - return null; - } - - @Override - public Object[] getElements(Object parent) { - if (null == sourceList) { - sourceList = new ArrayList(); - } - return sourceList.toArray(); - } - - @Override - public Object getParent(Object child) { - return null; - } - - @Override - public boolean hasChildren(Object parent) { - return false; - } - } - - class TreeLabelProvider extends LabelProvider { - @Override - public String getText(Object element) { - Resource res = (Resource) element; - return res.getResourceName(); - } - - @Override - public Image getImage(Object element) { - if (element instanceof CollectionResource) { - return Activator.getDefault().getImageRegistry() - .get(Constants.COLLECTION_RESOURCE); - } else { - return Activator.getDefault().getImageRegistry() - .get(Constants.SINGLE_RESOURCE); - } - } - } - - @Override - protected void okPressed() { - if (selectedResourceList.isEmpty()) { - MessageDialog.openInformation( - Display.getDefault().getActiveShell(), - "No selection done.", "No resources are selected."); - return; - } - close(); - } - - @Override - public boolean isHelpAvailable() { - return false; - } -} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourcesToCollectionPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourcesToCollectionPage.java deleted file mode 100644 index d745c38..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/AddResourcesToCollectionPage.java +++ /dev/null @@ -1,169 +0,0 @@ -package oic.simulator.serviceprovider.view.dialogs; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.model.Resource; -import oic.simulator.serviceprovider.model.SingleResource; -import oic.simulator.serviceprovider.utils.Constants; - -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; - -public class AddResourcesToCollectionPage extends WizardPage { - - private CheckboxTreeViewer treeViewer; - - Set selectedResourceList; - - protected AddResourcesToCollectionPage() { - super("Add Resources To Collection"); - selectedResourceList = new HashSet(); - } - - @Override - public void createControl(Composite parent) { - setPageComplete(false); - setTitle(Constants.COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_TITLE); - setMessage(Constants.COLLECTION_RESOURCE_ADD_OTHER_RESOURCES_PAGE_MESSAGE); - - Composite container = new Composite(parent, SWT.NONE); - GridLayout gridLayout = new GridLayout(); - container.setLayout(gridLayout); - GridData gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.heightHint = 300; - container.setLayoutData(gd); - - Group resourceGroup = new Group(container, SWT.NONE); - - Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - - resourceGroup.setLayout(new GridLayout()); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.heightHint = 300; - resourceGroup.setLayoutData(gd); - - treeViewer = new CheckboxTreeViewer(resourceGroup); - treeViewer.getTree().setBackground(color); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessVerticalSpace = true; - gd.verticalAlignment = SWT.FILL; - // gd.heightHint = 300; - treeViewer.getTree().setLayoutData(gd); - treeViewer.setContentProvider(new TreeContentProvider()); - treeViewer.setLabelProvider(new TreeLabelProvider()); - treeViewer.setInput(new Object()); - treeViewer.addCheckStateListener(new ICheckStateListener() { - - @Override - public void checkStateChanged(CheckStateChangedEvent e) { - Resource res = (Resource) e.getElement(); - if (null != res) { - if (e.getChecked()) { - selectedResourceList.add(res); - System.out.println("Checked" + res.getResourceName()); - } else { - selectedResourceList.remove(res); - System.out.println("Unchecked:" + res.getResourceName()); - } - } - } - }); - - setControl(container); - } - - @Override - public IWizardPage getNextPage() { - return null; - } - - public Set getSelectedResourceList() { - return selectedResourceList; - } - - class TreeContentProvider implements ITreeContentProvider { - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { - } - - @Override - public Object[] getChildren(Object parent) { - System.out.println("getChildren()"); - - return null; - } - - @Override - public Object[] getElements(Object parent) { - List resList; - resList = Activator.getDefault().getResourceManager() - .getResourceList(); - if (null == resList) { - resList = new ArrayList(); - } - return resList.toArray(); - } - - @Override - public Object getParent(Object child) { - return null; - } - - @Override - public boolean hasChildren(Object parent) { - return false; - } - } - - class TreeLabelProvider extends LabelProvider { - @Override - public String getText(Object element) { - Resource res = (Resource) element; - return res.getResourceName(); - } - - @Override - public Image getImage(Object element) { - if (element instanceof SingleResource) { - return Activator.getDefault().getImageRegistry() - .get(Constants.SINGLE_RESOURCE); - } else if (element instanceof CollectionResource) { - return Activator.getDefault().getImageRegistry() - .get(Constants.COLLECTION_RESOURCE); - } else { - return Activator.getDefault().getImageRegistry() - .get(Constants.DEVICE); - } - } - } -} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CollectionResourceBasicDetailsPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CollectionResourceBasicDetailsPage.java deleted file mode 100644 index 5f79415..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CollectionResourceBasicDetailsPage.java +++ /dev/null @@ -1,343 +0,0 @@ -package oic.simulator.serviceprovider.view.dialogs; - -import java.util.HashSet; -import java.util.Set; - -import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.utils.Constants; -import oic.simulator.serviceprovider.utils.Utility; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -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.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Text; - -public class CollectionResourceBasicDetailsPage extends WizardPage { - - private Text resNameTxt; - private Text resUriTxt; - private List resTypeslist; - private Button addToListBtn; - private Button remFromListBtn; - private Button observeBtn; - // private Button startBtn; - - private String resName; - private String resURI; - private Set resTypes; - // private boolean start; - private boolean observable; - private boolean anyResourceExist; - - protected CollectionResourceBasicDetailsPage() { - super("Basic Details"); - resTypes = new HashSet(); - anyResourceExist = Activator.getDefault().getResourceManager() - .isAnyResourceExist(); - } - - @Override - public void createControl(Composite parent) { - setPageComplete(false); - setTitle(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_TITLE); - setMessage(Constants.COLLECTION_RESOURCE_BASIC_DETAILS_PAGE_MESSAGE); - - Composite container = new Composite(parent, SWT.NONE); - GridLayout gridLayout = new GridLayout(); - container.setLayout(gridLayout); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); - container.setLayoutData(gd); - - Group resDetGrp = new Group(container, SWT.NONE); - resDetGrp.setText("Resource Details"); - gridLayout = new GridLayout(4, false); - resDetGrp.setLayout(gridLayout); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - resDetGrp.setLayoutData(gd); - - Label resNameLbl = new Label(resDetGrp, SWT.NULL); - resNameLbl.setText(Constants.RESOURCE_NAME); - gd = new GridData(); - resNameLbl.setLayoutData(gd); - - resNameTxt = new Text(resDetGrp, SWT.BORDER); - gd = new GridData(); - // gd.widthHint = 300; - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessHorizontalSpace = true; - gd.horizontalSpan = 3; - resNameTxt.setLayoutData(gd); - resNameTxt.setFocus(); - - Label resUriLbl = new Label(resDetGrp, SWT.NULL); - resUriLbl.setText(Constants.RESOURCE_URI); - - resUriTxt = new Text(resDetGrp, SWT.BORDER); - gd = new GridData(); - // gd.widthHint = 300; - gd.horizontalSpan = 3; - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessHorizontalSpace = true; - resUriTxt.setLayoutData(gd); - /* - * Composite resTypesComp = new Composite(compContent, SWT.NONE); - * gridLayout = new GridLayout(3, false); - * resTypesComp.setLayout(gridLayout); gd = new GridData(); - * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment = - * SWT.FILL; resTypesComp.setLayoutData(gd); - */ - - Label resTypesLbl = new Label(resDetGrp, SWT.NULL); - resTypesLbl.setText(Constants.RESOURCE_TYPES); - - resTypeslist = new List(resDetGrp, SWT.BORDER | SWT.MULTI - | SWT.V_SCROLL); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.horizontalSpan = 2; - gd.heightHint = 100; - /* gd.widthHint = 200; */ - resTypeslist.setLayoutData(gd); - // resTypeslist.setBackground(new Color()); - - Composite resTypesActionsComp = new Composite(resDetGrp, SWT.NONE); - gridLayout = new GridLayout(); - resTypesActionsComp.setLayout(gridLayout); - gd = new GridData(); - gd.verticalAlignment = SWT.TOP; - /* - * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment = - * SWT.FILL; - */ - resTypesActionsComp.setLayoutData(gd); - - addToListBtn = new Button(resTypesActionsComp, SWT.PUSH); - addToListBtn.setText("Add"); - gd = new GridData(); - gd.widthHint = 70; - addToListBtn.setLayoutData(gd); - - remFromListBtn = new Button(resTypesActionsComp, SWT.PUSH); - remFromListBtn.setText("Remove"); - gd = new GridData(); - gd.widthHint = 70; - remFromListBtn.setLayoutData(gd); - remFromListBtn.setEnabled(false); - - Group otherOptionsGrp = new Group(container, SWT.NONE); - otherOptionsGrp.setText("Other options"); - gridLayout = new GridLayout(); - otherOptionsGrp.setLayout(gridLayout); - gd = new GridData(SWT.FILL, SWT.FILL, true, true); - otherOptionsGrp.setLayoutData(gd); - - observeBtn = new Button(otherOptionsGrp, SWT.CHECK); - observeBtn.setText("Observable"); - observeBtn.setSelection(true); - observable = true; - - /* - * startBtn = new Button(otherOptionsGrp, SWT.CHECK); - * startBtn.setText("Start the resource immediately after creation"); - * startBtn.setSelection(true); - */ - - addUiListeners(); - - setControl(container); - } - - private void addUiListeners() { - - resUriTxt.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent arg0) { - resURI = resUriTxt.getText(); - if (null == resURI) { - return; - } - - if (anyResourceExist) - getWizard().getContainer().updateButtons(); - else - setPageComplete(isSelectionDone()); - } - }); - - resNameTxt.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent arg0) { - resName = resNameTxt.getText(); - if (null == resName) { - return; - } - if (anyResourceExist) - getWizard().getContainer().updateButtons(); - else - setPageComplete(isSelectionDone()); - } - }); - - addToListBtn.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - SingleTextInputDialog dialog = new SingleTextInputDialog( - getShell(), "Add Resource Type", "Resource Type"); - if (dialog.open() == Window.OK) { - System.out.println(dialog.getValue()); - String resType = dialog.getValue(); - // Duplicate check. - if (resTypes.contains(resType)) { - MessageDialog.openError(Display.getDefault() - .getActiveShell(), "Duplicate value", - "value already exist."); - return; - } - resTypeslist.add(resType); - resTypeslist.deselectAll(); - resTypeslist.select(resTypeslist.getItemCount() - 1); - resTypeslist.showSelection(); - remFromListBtn.setEnabled(true); - resTypes.add(resType); - if (anyResourceExist) - getWizard().getContainer().updateButtons(); - else - setPageComplete(isSelectionDone()); - } - } - }); - - remFromListBtn.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - int[] selection = resTypeslist.getSelectionIndices(); - String[] selectionStr = resTypeslist.getSelection(); - if (null != selection && selection.length > 0) { - resTypeslist.remove(selection); - for (String selected : selectionStr) { - resTypes.remove(selected); - } - } - changeVisibility(); - if (anyResourceExist) - getWizard().getContainer().updateButtons(); - else - setPageComplete(isSelectionDone()); - } - }); - - resTypeslist.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - changeVisibility(); - } - }); - - observeBtn.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - observable = observeBtn.getSelection(); - } - }); - - /* - * startBtn.addSelectionListener(new SelectionAdapter() { - * - * @Override public void widgetSelected(SelectionEvent e) { start = - * startBtn.getSelection(); } }); - */ - } - - private void changeVisibility() { - int[] selection = resTypeslist.getSelectionIndices(); - if (null != selection && selection.length > 0) { - remFromListBtn.setEnabled(true); - } else { - remFromListBtn.setEnabled(false); - } - } - - @Override - public boolean canFlipToNextPage() { - System.out.println("canFlipToNextPage()"); - if (!anyResourceExist) { - return false; - } - return isSelectionDone(); - } - - public boolean isSelectionDone() { - if (null == resName || resName.trim().length() < 1 || null == resURI - || resURI.trim().length() < 1 || null == resTypes - || resTypes.size() < 1) { - return false; - } - return true; - } - - @Override - public IWizardPage getNextPage() { - // Checking whether the uri is used by any other resource. - if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) { - MessageDialog - .openError(getShell(), "Resource URI in use", - "Entered resource URI is in use. Please try a different one."); - // TODO: Instead of MessageDialog, errors may be shown on wizard - // itself. - return null; - } - - if (!Utility.isUriValid(resURI)) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE); - return null; - } - - if (anyResourceExist) { - return ((CreateResourceWizard) getWizard()) - .getAddResourcesToCollectionPage(); - } - return null; - } - - public String getResName() { - return resName; - } - - public String getResURI() { - return resURI; - } - - public Set getResTypes() { - return resTypes; - } - - /* - * public boolean isStart() { return start; } - */ - - public boolean isObservable() { - return observable; - } - - public boolean isAnyResourceExist() { - return anyResourceExist; - } -} 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 index 0d7aa0b..bc5603f 100644 --- 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 @@ -25,12 +25,8 @@ import java.util.Map; import java.util.Set; import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.manager.UiListenerHandler; import oic.simulator.serviceprovider.model.AttributeHelper; -import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.model.Device; import oic.simulator.serviceprovider.model.Resource; -import oic.simulator.serviceprovider.model.ResourceType; import oic.simulator.serviceprovider.model.SingleResource; import oic.simulator.serviceprovider.utils.Constants; import oic.simulator.serviceprovider.utils.Utility; @@ -56,25 +52,20 @@ import org.oic.simulator.SimulatorResourceAttribute; */ public class CreateResourceWizard extends Wizard { - private MainPage mainPage; - private SimpleResourceBasicDetailsPage simpleResourceBasicDetailsPage; - private SimpleResourceAddAttributePage simpleResourceAddAttributePage; - private SimpleResourceOtherDetailsPage simpleResourceOtherDetailsPage; - private CollectionResourceBasicDetailsPage collectionResourceBasicDetailsPage; - private AddResourcesToCollectionPage addResourcesToCollectionPage; - private LoadRamlPage loadRamlPage; - private UpdatePropertiesPage updatePropPage; - private DevicePage devicePage; - private StartStopResourcePage startStopPage; + private MainPage mainPage; + private SimpleResourceBasicDetailsPage simpleResourceBasicDetailsPage; + private SimpleResourceAddAttributePage simpleResourceAddAttributePage; + private SimpleResourceOtherDetailsPage simpleResourceOtherDetailsPage; + private LoadRamlPage loadRamlPage; + private UpdatePropertiesPage updatePropPage; + private StartStopResourcePage startStopPage; - // private SingleResource simResource; - private String status; + private String status; - private WizardDialog wizDialog; - private boolean dlgForceClosed; + private WizardDialog wizDialog; + private boolean dlgForceClosed; - private Resource createdResource; - private Device createdDevice; + private Resource createdResource; public CreateResourceWizard() { setWindowTitle("Create resources"); @@ -92,23 +83,16 @@ public class CreateResourceWizard extends Wizard { simpleResourceBasicDetailsPage = new SimpleResourceBasicDetailsPage(); simpleResourceAddAttributePage = new SimpleResourceAddAttributePage(); simpleResourceOtherDetailsPage = new SimpleResourceOtherDetailsPage(); - collectionResourceBasicDetailsPage = new CollectionResourceBasicDetailsPage(); - addResourcesToCollectionPage = new AddResourcesToCollectionPage(); loadRamlPage = new LoadRamlPage(); updatePropPage = new UpdatePropertiesPage(); - devicePage = new DevicePage(); startStopPage = new StartStopResourcePage(); addPage(mainPage); addPage(simpleResourceBasicDetailsPage); addPage(simpleResourceAddAttributePage); addPage(simpleResourceOtherDetailsPage); - addPage(collectionResourceBasicDetailsPage); - if (Activator.getDefault().getResourceManager().isAnyResourceExist()) - addPage(addResourcesToCollectionPage); addPage(loadRamlPage); addPage(updatePropPage); - addPage(devicePage); addPage(startStopPage); } @@ -146,25 +130,14 @@ public class CreateResourceWizard extends Wizard { return createdResource; } - public Device getCreatedDevice() { - return createdDevice; - } - @Override public boolean canFinish() { - System.out.println("canFinish()"); IWizardPage curPage = this.getContainer().getCurrentPage(); - System.out.println(curPage.getName()); if ((curPage == updatePropPage && ((mainPage.getOption() == Option.SIMPLE_FROM_RAML) || !Activator .getDefault().getResourceManager().isAnyResourceExist())) - || (curPage == collectionResourceBasicDetailsPage - && !Activator.getDefault().getResourceManager() - .isAnyResourceExist() && collectionResourceBasicDetailsPage - .isSelectionDone()) - || curPage == addResourcesToCollectionPage || curPage == simpleResourceAddAttributePage || (curPage == loadRamlPage && loadRamlPage.isSelectionDone() && loadRamlPage - .isMultiResourceCreation()) || curPage == devicePage) { + .isMultiResourceCreation())) { return true; } return false; @@ -172,14 +145,11 @@ public class CreateResourceWizard extends Wizard { @Override public boolean performFinish() { - System.out.println("performFinish()"); final IWizardPage curPage = this.getContainer().getCurrentPage(); - System.out.println(curPage.getClass().getSimpleName()); - if (curPage == simpleResourceAddAttributePage) { // Handling Simple - // Resource Creation - // without RAML + // Handling Simple Resource Creation without RAML + if (curPage == simpleResourceAddAttributePage) { try { - getContainer().run(true, true, new IRunnableWithProgress() { + getContainer().run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) @@ -204,9 +174,8 @@ public class CreateResourceWizard extends Wizard { .log(Level.ERROR.ordinal(), new Date(), e.getMessage()); e.printStackTrace(); } - } else if (curPage == loadRamlPage) { // Handling multi-instance - // creation of simple resource - // with RAML + } else if (curPage == loadRamlPage) { + // Handling multiple instance creation of simple resource with RAML if ((loadRamlPage.getResourceCount() + Activator.getDefault() .getResourceManager().getResourceCount()) > Constants.MAX_RESOURCE_COUNT) { MessageDialog @@ -217,7 +186,7 @@ public class CreateResourceWizard extends Wizard { } try { - getContainer().run(true, true, new IRunnableWithProgress() { + getContainer().run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) @@ -244,7 +213,8 @@ public class CreateResourceWizard extends Wizard { .log(Level.ERROR.ordinal(), new Date(), e.getMessage()); e.printStackTrace(); } - } else if (curPage == updatePropPage) { // Handling the single instance + } else if (curPage == updatePropPage) { + // Handling the single instance String resName = updatePropPage.getResName(); String resURI = updatePropPage.getResURI(); if (null == resName || resName.trim().length() < 1) { @@ -257,9 +227,8 @@ public class CreateResourceWizard extends Wizard { "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE); return false; } - // creation of simple resource - // with RAML - // Checking whether the uri is used by any other resource. + // Creation of simple resource with RAML + // Checking whether the URI is used by any other resource. if (Activator.getDefault().getResourceManager() .isResourceExist(updatePropPage.getResURI())) { MessageDialog @@ -271,7 +240,7 @@ public class CreateResourceWizard extends Wizard { } try { - getContainer().run(true, true, new IRunnableWithProgress() { + getContainer().run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) @@ -296,155 +265,6 @@ public class CreateResourceWizard extends Wizard { .log(Level.ERROR.ordinal(), new Date(), e.getMessage()); e.printStackTrace(); } - } else if (curPage == collectionResourceBasicDetailsPage - || (curPage == addResourcesToCollectionPage && mainPage - .getOption() == Option.COLLECTION)) { - // Checking whether the uri is used by any other resource. - if (Activator - .getDefault() - .getResourceManager() - .isResourceExist( - collectionResourceBasicDetailsPage.getResURI())) { - MessageDialog - .openError(getShell(), "Resource URI in use", - "Entered resource URI is in use. Please try a different one."); - // TODO: Instead of MessageDialog, errors may be shown on - // wizard - // itself. - return false; - } - try { - getContainer().run(true, true, new IRunnableWithProgress() { - - @Override - public void run(IProgressMonitor monitor) - throws InvocationTargetException, - InterruptedException { - try { - monitor.beginTask( - "Collection Resource Creation Without RAML", - 3); - monitor.worked(1); - createCollectionResourceWithoutRAML((curPage == addResourcesToCollectionPage) ? true - : false); - monitor.worked(1); - if (curPage == addResourcesToCollectionPage) { - UiListenerHandler.getInstance() - .resourceListUpdateUINotification( - ResourceType.COLLECTION); - } - monitor.worked(1); - } finally { - monitor.done(); - } - } - }); - } catch (InvocationTargetException e) { - Activator.getDefault().getLogManager() - .log(Level.ERROR.ordinal(), new Date(), e.getMessage()); - e.printStackTrace(); - } catch (InterruptedException e) { - Activator.getDefault().getLogManager() - .log(Level.ERROR.ordinal(), new Date(), e.getMessage()); - e.printStackTrace(); - } - } else if (curPage == addResourcesToCollectionPage) { - try { - getContainer().run(true, true, new IRunnableWithProgress() { - - @Override - public void run(IProgressMonitor monitor) - throws InvocationTargetException, - InterruptedException { - try { - monitor.beginTask( - "Completing Collection Resource Creation With RAML", - 3); - monitor.worked(1); - completeResourceCreationWithRAML(); - monitor.worked(1); - - if (mainPage.getOption() == Option.COLLECTION_FROM_RAML) { - Resource res = loadRamlPage.getResource(); - if (null != res - && res instanceof CollectionResource) { - Set selectedResources = addResourcesToCollectionPage - .getSelectedResourceList(); - if (!selectedResources.isEmpty()) { - int addedCount = Activator - .getDefault() - .getResourceManager() - .addResourceToCollection( - (CollectionResource) res, - selectedResources); - if (addedCount > 0) { - - status += " and [" - + addedCount - + "/" - + selectedResources.size() - + "] resources added to the collection"; - - UiListenerHandler - .getInstance() - .resourceListUpdateUINotification( - ResourceType.COLLECTION); - } else { - status += " but failed to add resources to the collection"; - } - } - } - } - monitor.worked(1); - } finally { - monitor.done(); - } - } - }); - } catch (InvocationTargetException e) { - Activator.getDefault().getLogManager() - .log(Level.ERROR.ordinal(), new Date(), e.getMessage()); - e.printStackTrace(); - } catch (InterruptedException e) { - Activator.getDefault().getLogManager() - .log(Level.ERROR.ordinal(), new Date(), e.getMessage()); - e.printStackTrace(); - } - } else if (curPage == devicePage) { - final String devName = devicePage.getDeviceName(); - final Set resourceList = devicePage - .getSelectedResourceList(); - try { - getContainer().run(true, true, new IRunnableWithProgress() { - - @Override - public void run(IProgressMonitor monitor) - throws InvocationTargetException, - InterruptedException { - try { - monitor.beginTask("Device Creation", 3); - monitor.worked(1); - createdDevice = createDevice(devName, resourceList); - monitor.worked(1); - UiListenerHandler.getInstance() - .resourceListUpdateUINotification( - ResourceType.DEVICE); - status = "Device Created."; - monitor.worked(1); - } finally { - monitor.done(); - } - } - }); - } catch (InvocationTargetException e) { - Activator.getDefault().getLogManager() - .log(Level.ERROR.ordinal(), new Date(), e.getMessage()); - e.printStackTrace(); - } catch (InterruptedException e) { - Activator.getDefault().getLogManager() - .log(Level.ERROR.ordinal(), new Date(), e.getMessage()); - e.printStackTrace(); - } } return true; } @@ -461,18 +281,10 @@ public class CreateResourceWizard extends Wizard { return simpleResourceAddAttributePage; } - public CollectionResourceBasicDetailsPage getCollectionResourceBasicDetailsPage() { - return collectionResourceBasicDetailsPage; - } - public SimpleResourceOtherDetailsPage getSimpleResourceOtherDetailsPage() { return simpleResourceOtherDetailsPage; } - public AddResourcesToCollectionPage getAddResourcesToCollectionPage() { - return addResourcesToCollectionPage; - } - public LoadRamlPage getLoadRamlPage() { return loadRamlPage; } @@ -481,10 +293,6 @@ public class CreateResourceWizard extends Wizard { return updatePropPage; } - public DevicePage getDevicePage() { - return devicePage; - } - public StartStopResourcePage getStartStopPage() { return startStopPage; } @@ -502,7 +310,7 @@ public class CreateResourceWizard extends Wizard { // Basic resource details resource.setResourceURI(simpleResourceBasicDetailsPage.getResURI()); resource.setResourceName(simpleResourceBasicDetailsPage.getResName()); - resource.setResourceTypes(simpleResourceBasicDetailsPage.getResTypes()); + resource.setResourceType(simpleResourceBasicDetailsPage.getResType()); resource.setObservable(simpleResourceBasicDetailsPage.isObservable()); // Resource Attributes @@ -548,7 +356,7 @@ public class CreateResourceWizard extends Wizard { private void completeResourceCreationWithRAML() { try { - boolean result; + boolean result = false; Resource res = loadRamlPage.getResource(); if (res instanceof SingleResource) { result = Activator @@ -557,13 +365,6 @@ public class CreateResourceWizard extends Wizard { .completeSingleResourceCreationByRAML(res, updatePropPage.getResURI(), updatePropPage.getResName(), false); - } else { - result = Activator - .getDefault() - .getResourceManager() - .completeCollectionResourceCreationByRAML(res, - updatePropPage.getResURI(), - updatePropPage.getResName()); } if (result) { @@ -601,60 +402,4 @@ public class CreateResourceWizard extends Wizard { + Utility.getSimulatorErrorString(e, null); } } - - private void createCollectionResourceWithoutRAML(boolean childResExist) { - CollectionResource resource = new CollectionResource(); - // Basic resource details - resource.setResourceURI(collectionResourceBasicDetailsPage.getResURI()); - resource.setResourceName(collectionResourceBasicDetailsPage - .getResName()); - resource.setResourceTypes(collectionResourceBasicDetailsPage - .getResTypes()); - resource.setObservable(collectionResourceBasicDetailsPage - .isObservable()); - // resource.setStarted(simpleResourceBasicDetailsPage.isStart()); - - // Call method of ResourceManager and update the response in the status - // string. - try { - boolean result = Activator.getDefault().getResourceManager() - .createCollectionResource(resource); - if (result) { - status = "Resource created"; - // Adding child resources. - if (childResExist) { - Set selectedResources = addResourcesToCollectionPage - .getSelectedResourceList(); - if (!selectedResources.isEmpty()) { - int addedCount = Activator - .getDefault() - .getResourceManager() - .addResourceToCollection(resource, - selectedResources); - if (addedCount > 0) { - status += " and [" + addedCount + "/" - + selectedResources.size() - + "] resources added to the collection"; - } else { - status += " but failed to add resources to the collection."; - } - } - } - createdResource = resource; - } else { - status = "Failed to create resource."; - createdResource = null; - } - } catch (SimulatorException e) { - status = "Failed to create resource.\n" - + Utility.getSimulatorErrorString(e, null); - createdResource = null; - } - } - - private Device createDevice(String deviceName, Set childs) { - return Activator.getDefault().getResourceManager() - .createDevice(deviceName, childs); - } - } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java index daf260f..a362ada 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Set; import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.CollectionResource; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.model.SingleResource; import oic.simulator.serviceprovider.utils.Constants; @@ -31,6 +30,7 @@ import org.eclipse.jface.viewers.CheckboxTreeViewer; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TreeNodeContentProvider; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; @@ -48,29 +48,24 @@ import org.eclipse.swt.widgets.Label; */ public class DeleteResourcePage extends WizardPage { - private CheckboxTreeViewer collectionTreeViewer; - private CheckboxTreeViewer singleTreeViewer; + private CheckboxTreeViewer singleTreeViewer; - private List collectionSourceList; - private List singleSourceList; + private List singleSourceList; - private TreeViewContentHelper singleTreeViewContentHelper; - private TreeViewContentHelper collectionTreeViewContentHelper; + private TreeViewContentHelper singleTreeViewContentHelper; protected DeleteResourcePage() { super("Delete Resources"); singleSourceList = Activator.getDefault().getResourceManager() .getSingleResourceList(); - collectionSourceList = Activator.getDefault().getResourceManager() - .getCollectionResourceList(); } @Override public void createControl(Composite parent) { setPageComplete(false); setTitle("Delete Resources"); - setMessage("Select one or more single and/or collection resources for deletion."); + setMessage("Select one or more simple resources for deletion."); Composite container = new Composite(parent, SWT.NONE); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); @@ -79,15 +74,13 @@ public class DeleteResourcePage extends WizardPage { createSingleResourcesArea(container); - createCollectionResourcesArea(container); - setControl(container); } private void createSingleResourcesArea(Composite container) { Composite singleContainer = new Composite(container, SWT.NONE); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); - gd.horizontalSpan = 2; + gd.horizontalSpan = 4; singleContainer.setLayoutData(gd); GridLayout layout = new GridLayout(); singleContainer.setLayout(layout); @@ -125,16 +118,9 @@ public class DeleteResourcePage extends WizardPage { singleTreeViewer .setContentProvider(new SingleResourceContentProvider()); singleTreeViewer.setLabelProvider(new TreeLabelProvider()); - singleTreeViewer.setInput(new TreeContentProvider()); + singleTreeViewer.setInput(new TreeNodeContentProvider()); singleTreeViewer.addCheckStateListener(new ICheckStateListener() { - /* - * (non-Javadoc) - * - * @see - * org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged - * (org.eclipse.jface.viewers.CheckStateChangedEvent) - */ @Override public void checkStateChanged(CheckStateChangedEvent e) { Object element = e.getElement(); @@ -182,99 +168,6 @@ public class DeleteResourcePage extends WizardPage { } - private void createCollectionResourcesArea(Composite container) { - Composite collectionContainer = new Composite(container, SWT.NONE); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); - gd.horizontalSpan = 2; - collectionContainer.setLayoutData(gd); - GridLayout layout = new GridLayout(); - collectionContainer.setLayout(layout); - - Label lbl = new Label(collectionContainer, SWT.NONE); - lbl.setText("Collection Resources:"); - gd = new GridData(SWT.FILL, SWT.FILL, true, true); - // gd.grabExcessHorizontalSpace = true; - // gd.horizontalAlignment = SWT.FILL; - lbl.setLayoutData(gd); - - Group resourceGroup = new Group(collectionContainer, SWT.NONE); - - Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - - resourceGroup.setLayout(new GridLayout()); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.heightHint = 300; - gd.horizontalSpan = 2; - resourceGroup.setLayoutData(gd); - - if (null == collectionSourceList || collectionSourceList.isEmpty()) { - return; - } - - collectionTreeViewer = new CheckboxTreeViewer(resourceGroup); - collectionTreeViewer.getTree().setBackground(color); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessVerticalSpace = true; - gd.verticalAlignment = SWT.FILL; - - collectionTreeViewer.getTree().setLayoutData(gd); - collectionTreeViewer - .setContentProvider(new CollectionResourceContentProvider()); - collectionTreeViewer.setLabelProvider(new TreeLabelProvider()); - collectionTreeViewer.setInput(new TreeContentProvider()); - collectionTreeViewer.addCheckStateListener(new ICheckStateListener() { - - @Override - public void checkStateChanged(CheckStateChangedEvent e) { - Object element = e.getElement(); - if (element instanceof TreeViewContentHelper) { - collectionTreeViewer.setGrayed( - collectionTreeViewContentHelper, false); - collectionTreeViewer.setChecked( - collectionTreeViewContentHelper, e.getChecked()); - collectionTreeViewer.setSubtreeChecked(element, - e.getChecked()); - } else { - Object obj[] = collectionTreeViewer.getCheckedElements(); - if (null != obj && obj.length > 0) { - int checkedCount = obj.length; - boolean isParentGrayed = collectionTreeViewer - .getChecked(collectionTreeViewContentHelper); - boolean isParentChecked = collectionTreeViewer - .getChecked(collectionTreeViewContentHelper); - if (isParentChecked || isParentGrayed) { - checkedCount--; - } - if (checkedCount == collectionSourceList.size()) { - collectionTreeViewer.setGrayed( - collectionTreeViewContentHelper, false); - collectionTreeViewer.setChecked( - collectionTreeViewContentHelper, true); - } else { - if (checkedCount > 0) { - collectionTreeViewer.setGrayed( - collectionTreeViewContentHelper, true); - collectionTreeViewer.setChecked( - collectionTreeViewContentHelper, true); - } else { - collectionTreeViewer.setGrayed( - collectionTreeViewContentHelper, false); - collectionTreeViewer.setChecked( - collectionTreeViewContentHelper, false); - } - } - } - } - setPageComplete(isSelectionDone()); - } - }); - collectionTreeViewer.expandAll(); - } - public Set getSelectedSingleResourcesList() { final Set singles = new HashSet(); Display.getDefault().syncExec(new Runnable() { @@ -298,29 +191,6 @@ public class DeleteResourcePage extends WizardPage { return singles; } - public Set getSelectedCollectionResourcesList() { - final Set collections = new HashSet(); - Display.getDefault().syncExec(new Runnable() { - - @Override - public void run() { - if (null == collectionTreeViewer) { - return; - } - Object selection[] = collectionTreeViewer.getCheckedElements(); - if (null == selection || selection.length < 1) { - return; - } - for (Object obj : selection) { - if (obj instanceof Resource) { - collections.add((CollectionResource) obj); - } - } - } - }); - return collections; - } - class SingleResourceContentProvider implements ITreeContentProvider { @Override @@ -363,48 +233,6 @@ public class DeleteResourcePage extends WizardPage { } } - class CollectionResourceContentProvider implements ITreeContentProvider { - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { - } - - @Override - public Object[] getChildren(Object parent) { - if (parent instanceof TreeViewContentHelper) { - return ((TreeViewContentHelper) parent).getResources() - .toArray(); - } - return null; - } - - @Override - public Object[] getElements(Object parent) { - Object obj[] = new Object[1]; - collectionTreeViewContentHelper = new TreeViewContentHelper( - collectionSourceList); - obj[0] = collectionTreeViewContentHelper; - return obj; - } - - @Override - public Object getParent(Object child) { - return null; - } - - @Override - public boolean hasChildren(Object parent) { - if (parent instanceof TreeViewContentHelper) { - return true; - } - return false; - } - } - class TreeLabelProvider extends LabelProvider { @Override public String getText(Object element) { @@ -417,10 +245,7 @@ public class DeleteResourcePage extends WizardPage { @Override public Image getImage(Object element) { - if (element instanceof CollectionResource) { - return Activator.getDefault().getImageRegistry() - .get(Constants.COLLECTION_RESOURCE); - } else if (element instanceof SingleResource) { + if (element instanceof SingleResource) { return Activator.getDefault().getImageRegistry() .get(Constants.SINGLE_RESOURCE); } else { @@ -452,12 +277,6 @@ public class DeleteResourcePage extends WizardPage { return true; } } - if (null != collectionTreeViewer) { - Object obj[] = collectionTreeViewer.getCheckedElements(); - if (null != obj && obj.length > 0) { - return true; - } - } return false; } } \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java index f2001d7..c75065e 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java @@ -23,7 +23,6 @@ import java.util.Set; import oic.simulator.serviceprovider.Activator; import oic.simulator.serviceprovider.manager.ResourceManager; -import oic.simulator.serviceprovider.model.CollectionResource; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.model.SingleResource; @@ -52,6 +51,8 @@ public class DeleteResourceWizard extends Wizard { URL find = FileLocator.find(Activator.getDefault().getBundle(), path, null); setDefaultPageImageDescriptor(ImageDescriptor.createFromURL(find)); + + setNeedsProgressMonitor(true); } @Override @@ -66,7 +67,7 @@ public class DeleteResourceWizard extends Wizard { return false; } try { - getContainer().run(true, true, new IRunnableWithProgress() { + getContainer().run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) @@ -75,27 +76,6 @@ public class DeleteResourceWizard extends Wizard { .getResourceManager(); try { monitor.beginTask("Resource Deletion", 2); - Set collectionResources = page - .getSelectedCollectionResourcesList(); - if (null != collectionResources - && collectionResources.size() > 0) { - Activator - .getDefault() - .getResourceManager() - .removeCollectionResources( - collectionResources); - - Resource res = resourceManager - .getCurrentResourceInSelection(); - if (null != res - && res instanceof CollectionResource) { - if (collectionResources - .contains((CollectionResource) res)) { - resourceManager - .resourceSelectionChanged(null); - } - } - } monitor.worked(1); Set singleResources = page .getSelectedSingleResourcesList(); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DevicePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DevicePage.java deleted file mode 100644 index b6a194f..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DevicePage.java +++ /dev/null @@ -1,207 +0,0 @@ -package oic.simulator.serviceprovider.view.dialogs; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.Resource; -import oic.simulator.serviceprovider.model.SingleResource; -import oic.simulator.serviceprovider.utils.Constants; - -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -public class DevicePage extends WizardPage { - - private CheckboxTreeViewer treeViewer; - - private Text deviceNameTxt; - - private String deviceName; - - Set selectedResourceList; - - protected DevicePage() { - super("Devices"); - selectedResourceList = new HashSet(); - } - - @Override - public void createControl(Composite parent) { - setPageComplete(false); - setTitle(Constants.CREATE_DEVICE_PAGE_TITLE); - setMessage(Constants.CREATE_DEVICE_PAGE_MESSAGE); - - Composite container = new Composite(parent, SWT.NONE); - GridLayout gridLayout = new GridLayout(2, false); - container.setLayout(gridLayout); - GridData gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.heightHint = 300; - container.setLayoutData(gd); - - Label deviceNameLbl = new Label(container, SWT.NULL); - deviceNameLbl.setText("Device Name"); - - deviceNameTxt = new Text(container, SWT.BORDER); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - deviceNameTxt.setLayoutData(gd); - - Group resourceGroup = new Group(container, SWT.NONE); - - Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - - resourceGroup.setLayout(new GridLayout()); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.heightHint = 300; - gd.horizontalSpan = 2; - resourceGroup.setLayoutData(gd); - - treeViewer = new CheckboxTreeViewer(resourceGroup); - treeViewer.getTree().setBackground(color); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessVerticalSpace = true; - gd.verticalAlignment = SWT.FILL; - // gd.heightHint = 300; - treeViewer.getTree().setLayoutData(gd); - treeViewer.setContentProvider(new TreeContentProvider()); - treeViewer.setLabelProvider(new TreeLabelProvider()); - treeViewer.setInput(new Object()); - treeViewer.addCheckStateListener(new ICheckStateListener() { - - @Override - public void checkStateChanged(CheckStateChangedEvent e) { - Resource res = (Resource) e.getElement(); - if (null != res) { - if (e.getChecked()) { - selectedResourceList.add(res); - System.out.println("Checked" + res.getResourceName()); - } else { - selectedResourceList.remove(res); - System.out.println("Unchecked:" + res.getResourceName()); - } - } - } - }); - - setUiListeners(); - - setControl(container); - } - - private void setUiListeners() { - deviceNameTxt.addModifyListener(new ModifyListener() { - @Override - public void modifyText(ModifyEvent e) { - deviceName = deviceNameTxt.getText(); - setPageComplete(isSelectionDone()); - } - }); - } - - private boolean isSelectionDone() { - if (null != deviceName) { - deviceName = deviceName.trim(); - } - if (deviceName.isEmpty()) { - return false; - } - return true; - } - - @Override - public IWizardPage getNextPage() { - return null; - } - - public String getDeviceName() { - return deviceName; - } - - public Set getSelectedResourceList() { - return selectedResourceList; - } - -} - -class TreeContentProvider implements ITreeContentProvider { - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { - } - - @Override - public Object[] getChildren(Object parent) { - return null; - } - - @Override - public Object[] getElements(Object parent) { - List resList; - resList = Activator.getDefault().getResourceManager().getResourceList(); - if (null == resList) { - resList = new ArrayList(); - } - return resList.toArray(); - } - - @Override - public Object getParent(Object child) { - return null; - } - - @Override - public boolean hasChildren(Object parent) { - return false; - } -} - -class TreeLabelProvider extends LabelProvider { - @Override - public String getText(Object element) { - Resource res = (Resource) element; - return res.getResourceName(); - } - - @Override - public Image getImage(Object element) { - if (element instanceof SingleResource) { - return Activator.getDefault().getImageRegistry() - .get(Constants.SINGLE_RESOURCE); - } else { - return Activator.getDefault().getImageRegistry() - .get(Constants.COLLECTION_RESOURCE); - } - } -} \ No newline at end of file diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/LoadRamlPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/LoadRamlPage.java index 54e4fa2..5224274 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/LoadRamlPage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/LoadRamlPage.java @@ -21,7 +21,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.Date; import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.CollectionResource; import oic.simulator.serviceprovider.model.Resource; import oic.simulator.serviceprovider.model.SingleResource; import oic.simulator.serviceprovider.utils.Constants; @@ -215,12 +214,8 @@ public class LoadRamlPage extends WizardPage { resourceCount = -1; } if (null != configFilePath && configFilePath.trim().length() > 0) { - if (typeOfResource == Type.COLLECTION) { + if (resourceCount == 1) { done = true; - } else { - if (resourceCount == 1) { - done = true; - } } } return done; @@ -234,19 +229,15 @@ public class LoadRamlPage extends WizardPage { resourceCount = -1; } if (null != configFilePath && configFilePath.trim().length() > 0) { - if (typeOfResource == Type.COLLECTION) { + if (resourceCount >= 1) { done = true; - } else { - if (resourceCount >= 1) { - done = true; - } } } return done; } public boolean isMultiResourceCreation() { - if (typeOfResource != Type.COLLECTION && resourceCount > 1) { + if (typeOfResource == Type.SINGLE && resourceCount > 1) { return true; } return false; @@ -278,7 +269,7 @@ public class LoadRamlPage extends WizardPage { final CreateResourceWizard wizard = ((CreateResourceWizard) getWizard()); try { - getContainer().run(true, true, new IRunnableWithProgress() { + getContainer().run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { @@ -310,25 +301,16 @@ public class LoadRamlPage extends WizardPage { wizard.getWizardDialog().close(); return null; } else { - // Checking whether the resource is single or collection. + // Checking whether the resource is of type single. Option intendedResource = wizard.getMainPage().getOption(); - if ((intendedResource == Option.SIMPLE_FROM_RAML && resource instanceof CollectionResource)) { + if ((intendedResource == Option.SIMPLE_FROM_RAML && !(resource instanceof SingleResource))) { MessageDialog .openError( getShell(), "Invalid RAML", - "Uploaded RAML is of type collection. " + "Uploaded RAML is not of simple type. " + "Please upload the proper RAML of simple type."); return null; - } else if (intendedResource == Option.COLLECTION_FROM_RAML - && resource instanceof SingleResource) { - MessageDialog - .openError( - getShell(), - "Invalid RAML", - "Uploaded RAML is of type simple. " - + "Please upload the proper RAML of collection type."); - return null; } } UpdatePropertiesPage updatePageRef = wizard.getUpdatePropPage(); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/MainPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/MainPage.java index bd90dfd..0a6f022 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/MainPage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/MainPage.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.serviceprovider.view.dialogs; import oic.simulator.serviceprovider.utils.Constants; @@ -18,14 +34,11 @@ import org.oic.simulator.server.SimulatorResource.Type; public class MainPage extends WizardPage { private Button simpleBtn; - private Button collectionBtn; private Button simpleFromRamlBtn; - private Button collectionFromRamlBtn; - private Button deviceBtn; private Text description; public enum Option { - SIMPLE, SIMPLE_FROM_RAML, COLLECTION, COLLECTION_FROM_RAML, DEVICE, NONE + SIMPLE, SIMPLE_FROM_RAML } private Option option; @@ -51,15 +64,6 @@ public class MainPage extends WizardPage { simpleFromRamlBtn = new Button(compContent, SWT.RADIO); simpleFromRamlBtn.setText("Simple resource(From RAML)"); - collectionBtn = new Button(compContent, SWT.RADIO); - collectionBtn.setText("Collection resource"); - - collectionFromRamlBtn = new Button(compContent, SWT.RADIO); - collectionFromRamlBtn.setText("Collection resource(From RAML)"); - - deviceBtn = new Button(compContent, SWT.RADIO); - deviceBtn.setText("Device"); - Label lbl = new Label(compContent, SWT.NULL); lbl.setText("Details:"); gd = new GridData(); @@ -105,53 +109,11 @@ public class MainPage extends WizardPage { getWizard().getContainer().updateButtons(); } }); - - collectionBtn.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - description - .setText("Create a collection resource by manually entering all the details given below.\n" - + "\t1. Basic resource details: URI, Name, Resource Types, etc.\n" - + "\t2. Start/stop the resource.\n" - + "\t3. Adding existing simple resources to this collection."); - option = Option.COLLECTION; - getWizard().getContainer().updateButtons(); - } - }); - - collectionFromRamlBtn.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - description - .setText("Create a collection resource from RAML configuration file.\n" - + "\t1. Resource details, attributes, and other properties will be read from RAML.\n" - + "\t2. Supports multi-instance creation.\n" - + "\t3. For single instance creation, allows editing the URI and Name of the resource.\n" - + "\t4. Allows to start or stop the resource(s)."); - option = Option.COLLECTION_FROM_RAML; - getWizard().getContainer().updateButtons(); - } - }); - - deviceBtn.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - description - .setText("Create a logical device that acts as a top-level logical classification.\n" - + "\t1. Takes a device name for identication.\n" - + "\t2. One or more simple and collection resources can be added to it."); - option = Option.DEVICE; - getWizard().getContainer().updateButtons(); - } - }); } @Override public boolean canFlipToNextPage() { - if (option != Option.NONE) { - return true; - } - return false; + return true; } @Override @@ -170,18 +132,6 @@ public class MainPage extends WizardPage { page.initialSetup(Type.SINGLE); return page; } - if (collectionBtn.getSelection()) { - return createWizard.getCollectionResourceBasicDetailsPage(); - } - if (collectionFromRamlBtn.getSelection()) { - LoadRamlPage page = createWizard.getLoadRamlPage(); - page.initialSetup(Type.COLLECTION); - return page; - } - if (deviceBtn.getSelection()) { - DevicePage page = createWizard.getDevicePage(); - return page; - } return null; } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromCollections.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromCollections.java deleted file mode 100644 index 627a76f..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromCollections.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.serviceprovider.view.dialogs; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.utils.Constants; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** - * This dialog is used for loading the RAML file. - */ -public class RemoveResourceFromCollections extends TitleAreaDialog { - - private CheckboxTreeViewer treeViewer; - - List sourceList; - - Set selectedResourceList; - - public RemoveResourceFromCollections(Shell parentShell, - List sourceList) { - super(parentShell); - this.sourceList = sourceList; - selectedResourceList = new HashSet(); - } - - @Override - public void create() { - super.create(); - setTitle("Remove from Collections"); - setMessage("Select one or more collection resources from which the simple resource will be removed."); - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite compLayout = (Composite) super.createDialogArea(parent); - Composite container = new Composite(compLayout, SWT.NONE); - container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - GridLayout layout = new GridLayout(); - layout.verticalSpacing = 10; - layout.marginTop = 10; - container.setLayout(layout); - - Label lbl = new Label(container, SWT.NONE); - lbl.setText("Select Resources from:"); - GridData gd; - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - lbl.setLayoutData(gd); - - Group resourceGroup = new Group(container, SWT.NONE); - - Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - - resourceGroup.setLayout(new GridLayout()); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.heightHint = 300; - gd.horizontalSpan = 2; - resourceGroup.setLayoutData(gd); - - treeViewer = new CheckboxTreeViewer(resourceGroup); - treeViewer.getTree().setBackground(color); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessVerticalSpace = true; - gd.verticalAlignment = SWT.FILL; - // gd.heightHint = 300; - treeViewer.getTree().setLayoutData(gd); - treeViewer.setContentProvider(new TreeContentProvider()); - treeViewer.setLabelProvider(new TreeLabelProvider()); - treeViewer.setInput(new Object()); - treeViewer.addCheckStateListener(new ICheckStateListener() { - - @Override - public void checkStateChanged(CheckStateChangedEvent e) { - CollectionResource res = (CollectionResource) e.getElement(); - if (null != res) { - if (e.getChecked()) { - selectedResourceList.add(res); - System.out.println("Checked" + res.getResourceName()); - } else { - selectedResourceList.remove(res); - System.out.println("Unchecked:" + res.getResourceName()); - } - } - } - }); - - return compLayout; - } - - public Set getSelectedResourceList() { - return selectedResourceList; - } - - class TreeContentProvider implements ITreeContentProvider { - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { - } - - @Override - public Object[] getChildren(Object parent) { - return null; - } - - @Override - public Object[] getElements(Object parent) { - if (null == sourceList) { - sourceList = new ArrayList(); - } - return sourceList.toArray(); - } - - @Override - public Object getParent(Object child) { - return null; - } - - @Override - public boolean hasChildren(Object parent) { - return false; - } - } - - class TreeLabelProvider extends LabelProvider { - @Override - public String getText(Object element) { - CollectionResource res = (CollectionResource) element; - return res.getResourceName(); - } - - @Override - public Image getImage(Object element) { - if (element instanceof CollectionResource) { - return Activator.getDefault().getImageRegistry() - .get(Constants.COLLECTION_RESOURCE); - } else { - return null; - } - } - } - - @Override - protected void okPressed() { - if (selectedResourceList.isEmpty()) { - MessageDialog.openInformation( - Display.getDefault().getActiveShell(), - "No selection done.", "No resources are selected."); - return; - } - close(); - } - - @Override - public boolean isHelpAvailable() { - return false; - } -} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromDevices.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromDevices.java deleted file mode 100644 index 01bedd9..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResourceFromDevices.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.serviceprovider.view.dialogs; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.Device; -import oic.simulator.serviceprovider.utils.Constants; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** - * This dialog is used for loading the RAML file. - */ -public class RemoveResourceFromDevices extends TitleAreaDialog { - - private CheckboxTreeViewer treeViewer; - - List sourceList; - - Set selectedDeviceList; - - public RemoveResourceFromDevices(Shell parentShell, List sourceList) { - super(parentShell); - this.sourceList = sourceList; - selectedDeviceList = new HashSet(); - } - - @Override - public void create() { - super.create(); - setTitle("Remove from Device"); - setMessage("Select one or more devices from which the simple resource will be removed."); - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite compLayout = (Composite) super.createDialogArea(parent); - Composite container = new Composite(compLayout, SWT.NONE); - container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - GridLayout layout = new GridLayout(); - layout.verticalSpacing = 10; - layout.marginTop = 10; - container.setLayout(layout); - - Label lbl = new Label(container, SWT.NONE); - lbl.setText("Select Resources from:"); - GridData gd; - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - lbl.setLayoutData(gd); - - Group resourceGroup = new Group(container, SWT.NONE); - - Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - - resourceGroup.setLayout(new GridLayout()); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.heightHint = 300; - gd.horizontalSpan = 2; - resourceGroup.setLayoutData(gd); - - treeViewer = new CheckboxTreeViewer(resourceGroup); - treeViewer.getTree().setBackground(color); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessVerticalSpace = true; - gd.verticalAlignment = SWT.FILL; - // gd.heightHint = 300; - treeViewer.getTree().setLayoutData(gd); - treeViewer.setContentProvider(new TreeContentProvider()); - treeViewer.setLabelProvider(new TreeLabelProvider()); - treeViewer.setInput(new Object()); - treeViewer.addCheckStateListener(new ICheckStateListener() { - - @Override - public void checkStateChanged(CheckStateChangedEvent e) { - Device res = (Device) e.getElement(); - if (null != res) { - if (e.getChecked()) { - selectedDeviceList.add(res); - System.out.println("Checked" + res.getDeviceName()); - } else { - selectedDeviceList.remove(res); - System.out.println("Unchecked:" + res.getDeviceName()); - } - } - } - }); - - return compLayout; - } - - public Set getSelectedDeviceList() { - return selectedDeviceList; - } - - class TreeContentProvider implements ITreeContentProvider { - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { - } - - @Override - public Object[] getChildren(Object parent) { - return null; - } - - @Override - public Object[] getElements(Object parent) { - if (null == sourceList) { - sourceList = new ArrayList(); - } - return sourceList.toArray(); - } - - @Override - public Object getParent(Object child) { - return null; - } - - @Override - public boolean hasChildren(Object parent) { - return false; - } - } - - class TreeLabelProvider extends LabelProvider { - @Override - public String getText(Object element) { - Device res = (Device) element; - return res.getDeviceName(); - } - - @Override - public Image getImage(Object element) { - if (element instanceof Device) { - return Activator.getDefault().getImageRegistry() - .get(Constants.DEVICE); - } else { - return null; - } - } - } - - @Override - protected void okPressed() { - if (selectedDeviceList.isEmpty()) { - MessageDialog.openInformation( - Display.getDefault().getActiveShell(), - "No selection done.", "No devices are selected."); - return; - } - close(); - } - - @Override - public boolean isHelpAvailable() { - return false; - } -} diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResources.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResources.java deleted file mode 100644 index f76f8f9..0000000 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/RemoveResources.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package oic.simulator.serviceprovider.view.dialogs; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import oic.simulator.serviceprovider.Activator; -import oic.simulator.serviceprovider.model.CollectionResource; -import oic.simulator.serviceprovider.model.Resource; -import oic.simulator.serviceprovider.utils.Constants; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTreeViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -/** - * This dialog is used for loading the RAML file. - */ -public class RemoveResources extends TitleAreaDialog { - - private CheckboxTreeViewer treeViewer; - - List sourceList; - - Set selectedResourceList; - - public RemoveResources(Shell parentShell, List sourceList) { - super(parentShell); - this.sourceList = sourceList; - selectedResourceList = new HashSet(); - } - - @Override - public void create() { - super.create(); - setTitle("Remove Resources"); - setMessage("Select one or more resources to be removed."); - } - - @Override - protected Control createDialogArea(Composite parent) { - Composite compLayout = (Composite) super.createDialogArea(parent); - Composite container = new Composite(compLayout, SWT.NONE); - container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - GridLayout layout = new GridLayout(); - layout.verticalSpacing = 10; - layout.marginTop = 10; - container.setLayout(layout); - - Label lbl = new Label(container, SWT.NONE); - lbl.setText("Select Resources from:"); - GridData gd; - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - lbl.setLayoutData(gd); - - Group resourceGroup = new Group(container, SWT.NONE); - - Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE); - - resourceGroup.setLayout(new GridLayout()); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.heightHint = 300; - gd.horizontalSpan = 2; - resourceGroup.setLayoutData(gd); - - treeViewer = new CheckboxTreeViewer(resourceGroup); - treeViewer.getTree().setBackground(color); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.grabExcessVerticalSpace = true; - gd.verticalAlignment = SWT.FILL; - // gd.heightHint = 300; - treeViewer.getTree().setLayoutData(gd); - treeViewer.setContentProvider(new TreeContentProvider()); - treeViewer.setLabelProvider(new TreeLabelProvider()); - treeViewer.setInput(new Object()); - treeViewer.addCheckStateListener(new ICheckStateListener() { - - @Override - public void checkStateChanged(CheckStateChangedEvent e) { - Resource res = (Resource) e.getElement(); - if (null != res) { - if (e.getChecked()) { - selectedResourceList.add(res); - System.out.println("Checked" + res.getResourceName()); - } else { - selectedResourceList.remove(res); - System.out.println("Unchecked:" + res.getResourceName()); - } - } - } - }); - - return compLayout; - } - - public Set getSelectedResourceList() { - return selectedResourceList; - } - - class TreeContentProvider implements ITreeContentProvider { - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer arg0, Object arg1, Object arg2) { - } - - @Override - public Object[] getChildren(Object parent) { - return null; - } - - @Override - public Object[] getElements(Object parent) { - if (null == sourceList) { - sourceList = new ArrayList(); - } - return sourceList.toArray(); - } - - @Override - public Object getParent(Object child) { - return null; - } - - @Override - public boolean hasChildren(Object parent) { - return false; - } - } - - class TreeLabelProvider extends LabelProvider { - @Override - public String getText(Object element) { - Resource res = (Resource) element; - return res.getResourceName(); - } - - @Override - public Image getImage(Object element) { - if (element instanceof CollectionResource) { - return Activator.getDefault().getImageRegistry() - .get(Constants.COLLECTION_RESOURCE); - } else { - return Activator.getDefault().getImageRegistry() - .get(Constants.SINGLE_RESOURCE); - } - } - } - - @Override - protected void okPressed() { - if (selectedResourceList.isEmpty()) { - MessageDialog.openInformation( - Display.getDefault().getActiveShell(), - "No selection done.", "No resources are selected."); - return; - } - close(); - } - - @Override - public boolean isHelpAvailable() { - return false; - } -} 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 index d2aea9f..df8b03d 100644 --- 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 @@ -16,8 +16,6 @@ package oic.simulator.serviceprovider.view.dialogs; -import oic.simulator.serviceprovider.view.dialogs.MainPage.Option; - import org.eclipse.jface.wizard.IWizard; import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.WizardDialog; @@ -57,32 +55,19 @@ public class ResourceWizardDialog extends WizardDialog { .getSimpleResourceOtherDetailsPage(); SimpleResourceAddAttributePage simpleResourceAddAttributesPage = createWizard .getSimpleResourceAddAttributePage(); - CollectionResourceBasicDetailsPage collectionResourceBasicDetailsPage = createWizard - .getCollectionResourceBasicDetailsPage(); - AddResourcesToCollectionPage addResourcesToCollectionPage = createWizard - .getAddResourcesToCollectionPage(); LoadRamlPage loadRamlPage = createWizard.getLoadRamlPage(); UpdatePropertiesPage updatePropPage = createWizard .getUpdatePropPage(); - DevicePage devPage = createWizard.getDevicePage(); IWizardPage curPage = wizard.getContainer().getCurrentPage(); IWizardPage prevPage = null; if (curPage == loadRamlPage - || curPage == simpleResourceBasicDetailsPage - || curPage == collectionResourceBasicDetailsPage - || curPage == devPage) { + || curPage == simpleResourceBasicDetailsPage) { prevPage = mainPage; } else if (curPage == updatePropPage) { loadRamlPage.setResource(null); prevPage = loadRamlPage; - } else if (curPage == addResourcesToCollectionPage) { - if (mainPage.getOption() == Option.COLLECTION_FROM_RAML) { - prevPage = updatePropPage; - } else { - prevPage = collectionResourceBasicDetailsPage; - } } else if (curPage == simpleResourceAddAttributesPage) { prevPage = simpleResourceBasicDetailsPage; } else if (curPage == simpleResourceOtherDetailsPage) { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java index 9bbf836..a54853e 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceAddAttributePage.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.serviceprovider.view.dialogs; import java.util.ArrayList; @@ -83,7 +99,7 @@ public class SimpleResourceAddAttributePage extends WizardPage { createAttributeColumns(attTblViewer); - // make lines and header visible + // Make lines and header visible Table table = attTblViewer.getTable(); table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); table.setHeaderVisible(true); @@ -258,7 +274,7 @@ public class SimpleResourceAddAttributePage extends WizardPage { return; } // Opening the dialog for edit operation. - // Passing the attribute to pre-fill the UI controls. + // Passing the attribute to populate UI controls with data. Set rTypes = Utility.getAttributeTypes(); AddAttributeDialog dialog = new AddAttributeDialog(Display .getDefault().getActiveShell(), att, rTypes, attributes); @@ -273,8 +289,6 @@ public class SimpleResourceAddAttributePage extends WizardPage { att.setAllowedValues(newAtt.getAllowedValues()); } attTblViewer.update(att, null); - System.out.println("Attribute data after closing edit dialog: " - + att); } }); @@ -284,11 +298,9 @@ public class SimpleResourceAddAttributePage extends WizardPage { IStructuredSelection selection = (IStructuredSelection) attTblViewer .getSelection(); if (null != selection) { - System.out.println(selection.size()); Iterator itr = selection.iterator(); while (itr.hasNext()) { AttributeHelper att = (AttributeHelper) itr.next(); - System.out.println(att.getAttributeName()); attTblViewer.remove(att); attributes.remove(att); AttributeContentProvider provider = (AttributeContentProvider) attTblViewer @@ -308,7 +320,6 @@ public class SimpleResourceAddAttributePage extends WizardPage { @Override public void selectionChanged(SelectionChangedEvent event) { - System.out.println("table selection changed"); remBtn.setEnabled(true); IStructuredSelection selection = (IStructuredSelection) event .getSelection(); diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java index 60b4dea..f31dbbc 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceBasicDetailsPage.java @@ -1,14 +1,26 @@ -package oic.simulator.serviceprovider.view.dialogs; +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -import java.util.HashSet; -import java.util.Set; +package oic.simulator.serviceprovider.view.dialogs; import oic.simulator.serviceprovider.Activator; import oic.simulator.serviceprovider.utils.Constants; import oic.simulator.serviceprovider.utils.Utility; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; @@ -23,29 +35,22 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Text; public class SimpleResourceBasicDetailsPage extends WizardPage { - private Text resNameTxt; - private Text resUriTxt; - private List resTypeslist; - private Button addToListBtn; - private Button remFromListBtn; - private Button observeBtn; - // private Button startBtn; + private Text resNameTxt; + private Text resUriTxt; + private Text resTypeTxt; + private Button observeBtn; - private String resName; - private String resURI; - private Set resTypes; - private boolean observable; - - // private boolean start; + private String resName; + private String resURI; + private String resType; + private boolean observable; protected SimpleResourceBasicDetailsPage() { super("Basic Details"); - resTypes = new HashSet(); } @Override @@ -74,7 +79,6 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { resNameTxt = new Text(resDetGrp, SWT.BORDER); gd = new GridData(); - // gd.widthHint = 300; gd.horizontalAlignment = SWT.FILL; gd.grabExcessHorizontalSpace = true; gd.horizontalSpan = 3; @@ -86,56 +90,20 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { resUriTxt = new Text(resDetGrp, SWT.BORDER); gd = new GridData(); - // gd.widthHint = 300; gd.horizontalSpan = 3; gd.horizontalAlignment = SWT.FILL; gd.grabExcessHorizontalSpace = true; resUriTxt.setLayoutData(gd); - /* - * Composite resTypesComp = new Composite(compContent, SWT.NONE); - * gridLayout = new GridLayout(3, false); - * resTypesComp.setLayout(gridLayout); gd = new GridData(); - * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment = - * SWT.FILL; resTypesComp.setLayoutData(gd); - */ - - Label resTypesLbl = new Label(resDetGrp, SWT.NULL); - resTypesLbl.setText(Constants.RESOURCE_TYPES); - - resTypeslist = new List(resDetGrp, SWT.BORDER | SWT.MULTI - | SWT.V_SCROLL); - gd = new GridData(); - gd.grabExcessHorizontalSpace = true; - gd.horizontalAlignment = SWT.FILL; - gd.horizontalSpan = 2; - gd.heightHint = 100; - /* gd.widthHint = 200; */ - resTypeslist.setLayoutData(gd); - // resTypeslist.setBackground(new Color()); - Composite resTypesActionsComp = new Composite(resDetGrp, SWT.NONE); - gridLayout = new GridLayout(); - resTypesActionsComp.setLayout(gridLayout); - gd = new GridData(); - gd.verticalAlignment = SWT.TOP; - /* - * gd.grabExcessHorizontalSpace = true; gd.horizontalAlignment = - * SWT.FILL; - */ - resTypesActionsComp.setLayoutData(gd); - - addToListBtn = new Button(resTypesActionsComp, SWT.PUSH); - addToListBtn.setText("Add"); - gd = new GridData(); - gd.widthHint = 70; - addToListBtn.setLayoutData(gd); + Label resTypeLbl = new Label(resDetGrp, SWT.NULL); + resTypeLbl.setText(Constants.RESOURCE_TYPE); - remFromListBtn = new Button(resTypesActionsComp, SWT.PUSH); - remFromListBtn.setText("Remove"); + resTypeTxt = new Text(resDetGrp, SWT.BORDER); gd = new GridData(); - gd.widthHint = 70; - remFromListBtn.setLayoutData(gd); - remFromListBtn.setEnabled(false); + gd.horizontalSpan = 3; + gd.horizontalAlignment = SWT.FILL; + gd.grabExcessHorizontalSpace = true; + resTypeTxt.setLayoutData(gd); Group otherOptionsGrp = new Group(container, SWT.NONE); otherOptionsGrp.setText("Other options"); @@ -149,11 +117,6 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { observeBtn.setSelection(true); observable = true; - /* - * startBtn = new Button(otherOptionsGrp, SWT.CHECK); - * startBtn.setText("Start the resource immediately after creation"); - * startBtn.setSelection(true); - */ addUiListeners(); setControl(container); @@ -181,58 +144,14 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { } }); - addToListBtn.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - SingleTextInputDialog dialog = new SingleTextInputDialog( - getShell(), "Add Resource Type", "Resource Type"); - if (dialog.open() == Window.OK) { - System.out.println(dialog.getValue()); - String resType = dialog.getValue(); - // Duplicate check. - if (resTypes.contains(resType)) { - MessageDialog.openError(Display.getDefault() - .getActiveShell(), "Duplicate value", - "value already exist."); - return; - } - resTypeslist.add(resType); - resTypeslist.deselectAll(); - resTypeslist.select(resTypeslist.getItemCount() - 1); - resTypeslist.showSelection(); - remFromListBtn.setEnabled(true); - - resTypes.add(resType); - - getWizard().getContainer().updateButtons(); - } - } - }); - - remFromListBtn.addSelectionListener(new SelectionAdapter() { + resTypeTxt.addModifyListener(new ModifyListener() { @Override - public void widgetSelected(SelectionEvent e) { - int[] selection = resTypeslist.getSelectionIndices(); - String[] selectionStr = resTypeslist.getSelection(); - if (null != selection && selection.length > 0) { - resTypeslist.remove(selection); - for (String selected : selectionStr) { - resTypes.remove(selected); - } - } - - changeVisibility(); + public void modifyText(ModifyEvent arg0) { + resType = resTypeTxt.getText(); getWizard().getContainer().updateButtons(); } }); - resTypeslist.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - changeVisibility(); - } - }); - observeBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -241,23 +160,15 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { }); } - private void changeVisibility() { - int[] selection = resTypeslist.getSelectionIndices(); - if (null != selection && selection.length > 0) { - remFromListBtn.setEnabled(true); - } else { - remFromListBtn.setEnabled(false); - } - } - @Override public boolean canFlipToNextPage() { - if (null == resName || null == resURI || resTypes.size() < 1) { + if (null == resName || null == resURI || null == resType) { return false; } resName = resName.trim(); resURI = resURI.trim(); - if (resName.length() < 1 || resURI.length() < 1) { + resType = resType.trim(); + if (resName.length() < 1 || resURI.length() < 1 || resType.length() < 1) { return false; } return true; @@ -293,8 +204,8 @@ public class SimpleResourceBasicDetailsPage extends WizardPage { return resURI; } - public Set getResTypes() { - return resTypes; + public String getResType() { + return resType; } public boolean isObservable() { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceOtherDetailsPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceOtherDetailsPage.java index 41cd07b..4dc9f21 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceOtherDetailsPage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/SimpleResourceOtherDetailsPage.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.serviceprovider.view.dialogs; import oic.simulator.serviceprovider.utils.Constants; diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/StartStopResourcePage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/StartStopResourcePage.java index 4f2a3c8..a56bc8a 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/StartStopResourcePage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/StartStopResourcePage.java @@ -1,3 +1,19 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package oic.simulator.serviceprovider.view.dialogs; import oic.simulator.serviceprovider.utils.Constants; @@ -84,7 +100,6 @@ public class StartStopResourcePage extends WizardPage { @Override public IWizardPage getNextPage() { - System.out.println(this.getClass().getName() + ": getNextPage"); return null; } } diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePropertiesPage.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePropertiesPage.java index 116748f..6f93ff1 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePropertiesPage.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdatePropertiesPage.java @@ -16,12 +16,8 @@ package oic.simulator.serviceprovider.view.dialogs; -import oic.simulator.serviceprovider.Activator; import oic.simulator.serviceprovider.utils.Constants; -import oic.simulator.serviceprovider.utils.Utility; -import oic.simulator.serviceprovider.view.dialogs.MainPage.Option; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.wizard.IWizardPage; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; @@ -30,7 +26,6 @@ import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; @@ -138,13 +133,6 @@ public class UpdatePropertiesPage extends WizardPage { @Override public boolean canFlipToNextPage() { - CreateResourceWizard createWizard = (CreateResourceWizard) getWizard(); - if (isSelectionDone() - && (createWizard.getMainPage().getOption() == Option.COLLECTION_FROM_RAML) - && Activator.getDefault().getResourceManager() - .isAnyResourceExist()) { - return true; - } return false; } @@ -159,29 +147,7 @@ public class UpdatePropertiesPage extends WizardPage { @Override public IWizardPage getNextPage() { - if (null == resName || resName.trim().length() < 1) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "Invalid Resource Name.", "Resource name is invalid."); - return null; - } - - if (!Utility.isUriValid(resURI)) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "Invalid Resource URI.", Constants.INVALID_URI_MESSAGE); - return null; - } - - CreateResourceWizard createWizard = (CreateResourceWizard) getWizard(); - // Checking whether the uri is used by any other resource. - if (Activator.getDefault().getResourceManager().isResourceExist(resURI)) { - MessageDialog - .openError(getShell(), "Resource URI in use", - "Entered resource URI is in use. Please try a different one."); - // TODO: Instead of MessageDialog, errors may be shown on wizard - // itself. - return null; - } - return createWizard.getAddResourcesToCollectionPage(); + return null; } public void setResName(String resName) { diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateResourceInterfaceDialog.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateResourceInterfaceDialog.java new file mode 100644 index 0000000..a0d1b7c --- /dev/null +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateResourceInterfaceDialog.java @@ -0,0 +1,122 @@ +/* + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package oic.simulator.serviceprovider.view.dialogs; + +import java.util.ArrayList; +import java.util.Map; +import java.util.Set; + +import oic.simulator.serviceprovider.utils.Constants; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TrayDialog; +import org.eclipse.swt.SWT; +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.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Shell; + +/** + * Dialog for starting and stopping the automatic verifications. + */ +public class UpdateResourceInterfaceDialog extends TrayDialog { + private Map resourceIfStatus; + + public UpdateResourceInterfaceDialog(Shell shell, + Map resourceIfStatus) { + super(shell); + this.resourceIfStatus = resourceIfStatus; + } + + @Override + protected void configureShell(Shell shell) { + super.configureShell(shell); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + createAutomationGroup(composite); + getShell().setText("Resource Interfaces"); + return composite; + } + + /** + * Dynamically creates a check-box list for changing the resource interface + * selection. + */ + private void createAutomationGroup(Composite parent) { + Group group = new Group(parent, SWT.NONE); + group.setLayout(new GridLayout()); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.widthHint = 275; + group.setLayoutData(gd); + group.setText("Resource Interfaces"); + + Set keySet = resourceIfStatus.keySet(); + if (null == keySet) { + return; + } + ArrayList list = new ArrayList(keySet); + for (final String str : list) { + final Button checkbox = new Button(group, SWT.CHECK); + checkbox.setText(str); + checkbox.setSelection(resourceIfStatus.get(str)); + + // Disabling the check-box for baseline interface. + if (str.contains(Constants.DEFAULT_SINGLE_RESOURCE_INTERFACE)) { + checkbox.setEnabled(false); + } + + checkbox.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + Button btn = (Button) e.getSource(); + if (null == btn) { + return; + } + String btnText = btn.getText(); + resourceIfStatus.put(btnText, btn.getSelection()); + } + }); + } + } + + @Override + protected Button createButton(Composite parent, int id, String label, + boolean defaultButton) { + if (id == IDialogConstants.CANCEL_ID) { + return null; + } + return super.createButton(parent, id, label, defaultButton); + } + + @Override + public boolean isHelpAvailable() { + return false; + } + + public Map getResourceInterfaceStatus() { + return resourceIfStatus; + } +} -- 2.7.4