Eclipse plug-in for service provider.
authorG S Senthil Kumar <senthil.gs@samsung.com>
Mon, 10 Aug 2015 07:46:00 +0000 (13:16 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 10 Aug 2015 12:36:30 +0000 (12:36 +0000)
This change-set includes the following:
    1. Views for Properties, Attributes and Log.
    2. Support for manually changing the attributes' values.
    3. Attribute level and resource level automation support.
    4. Updates to exiting UI modules.
    5. Icons and images which are used in wizards and views.
    6. README file which explains how to import and run the plug-in.

Change-Id: I9f0a405da6ebeec932c9f5b1a2c53b92ab225de7
Signed-off-by: G S Senthil Kumar <senthil.gs@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2150
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
67 files changed:
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/.classpath
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/.project
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/META-INF/MANIFEST.MF
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/README.txt [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/build.properties
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/clear_d.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/clear_e.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/debug_log.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/delete_d.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/delete_e.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/error_log.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/export_log_d.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/export_log_e.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/filter_d.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/filter_e.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/info_log.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/lock_d.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/lock_e.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/log_details_e.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_16x16.png [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_32x32.png [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_64x64.png [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/prop_d.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/prop_e.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/trash_e.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/tree_mode_d.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/tree_mode_e.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/unknown_log.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/warning_log.gif [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/libs/Simulator.jar [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/plugin.xml
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogContentProvider.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogEntry.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogLabelProvider.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LoggerCallback.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/Activator.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IAutomationUIListener.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/ILogUIListener.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceListChangedListener.java [deleted file]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceListChangedUIListener.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceModelChangedUIListener.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceSelectionChangedUIListener.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/LogManager.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/perspective/PerspectiveFactory.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/AttributeValueType.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/AutomationSettingHelper.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/MetaProperty.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ModelChangeNotificationType.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ResourceAttribute.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/SimulatorResource.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/StandardConfiguration.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Constants.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Utility.java [moved from service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/utils/Convertion.java with 55% similarity]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/AttributeView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/LogDetailsDialog.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/LogView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MetaPropertiesView.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/MultiResourceOrchestrationView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/ResourceManagerView.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourcePage.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/CreateResourceWizard.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteCategory.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourcePage.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/DeleteResourceWizard.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/FilterDialog.java [new file with mode: 0644]
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/ResourceWizardDialog.java

index 95052f6..61b8255 100644 (file)
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-       <classpathentry exported="true" kind="lib" path="libs/ServiceProvider.jar"/>
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
-       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
-       <classpathentry kind="src" path="src"/>
-       <classpathentry kind="output" path="bin"/>
-</classpath>
+    <classpathentry kind="lib" path="libs/Simulator.jar"/>
+    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+    <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+    <classpathentry kind="src" path="src"/>
+    <classpathentry kind="output" path="bin"/>
+</classpath>
\ No newline at end of file
index 9a2dee2..65d5304 100644 (file)
@@ -1,28 +1,28 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-       <name>ServiceProviderPlugin</name>
-       <comment></comment>
-       <projects>
-       </projects>
-       <buildSpec>
-               <buildCommand>
-                       <name>org.eclipse.jdt.core.javabuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-               <buildCommand>
-                       <name>org.eclipse.pde.ManifestBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-               <buildCommand>
-                       <name>org.eclipse.pde.SchemaBuilder</name>
-                       <arguments>
-                       </arguments>
-               </buildCommand>
-       </buildSpec>
-       <natures>
-               <nature>org.eclipse.pde.PluginNature</nature>
-               <nature>org.eclipse.jdt.core.javanature</nature>
-       </natures>
-</projectDescription>
+    <name>ServiceProviderPlugin</name>
+    <comment></comment>
+    <projects>
+    </projects>
+    <buildSpec>
+        <buildCommand>
+            <name>org.eclipse.jdt.core.javabuilder</name>
+            <arguments>
+            </arguments>
+        </buildCommand>
+        <buildCommand>
+            <name>org.eclipse.pde.ManifestBuilder</name>
+            <arguments>
+            </arguments>
+        </buildCommand>
+        <buildCommand>
+            <name>org.eclipse.pde.SchemaBuilder</name>
+            <arguments>
+            </arguments>
+        </buildCommand>
+    </buildSpec>
+    <natures>
+        <nature>org.eclipse.pde.PluginNature</nature>
+        <nature>org.eclipse.jdt.core.javanature</nature>
+    </natures>
+</projectDescription>
\ No newline at end of file
index 821a2e6..08798e4 100644 (file)
@@ -9,5 +9,5 @@ Require-Bundle: org.eclipse.ui,
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Bundle-ActivationPolicy: lazy
 Bundle-NativeCode: libs/libSimulatorManager.so
-Bundle-ClassPath: libs/ServiceProvider.jar,
+Bundle-ClassPath: libs/Simulator.jar,
  .
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/README.txt b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/README.txt
new file mode 100644 (file)
index 0000000..bb5b937
--- /dev/null
@@ -0,0 +1,20 @@
+Service Provider eclipse plug-in
+
+Pre-requisites
+--------------
+    1.Build the IoTivity project for linux:
+        Run the "scons" command in iotivity home directory.
+        It generates the libraries in ~/iotivity/out/linux/<arch>/release directory.
+    2.Copy the libraries mentioned below into the libs folder of the plug-in project.
+        Required libraries: libSimulatorManager.so, liboc.so, liboctbstack.so, and liboc_logger.so
+
+Steps to run the plug-in
+------------------------
+    1.Import the plug-in project from ~/iotivity/service/simulator/java/eclipse-plugin/ into Eclipse IDE as given below.
+        File -> Import -> Select 'Existing projects into Workspace' under General category -> click next -> Browse to the above mentioned location ->
+        click Finish.
+    2.Set the LD_LIBRARY_PATH environment variable
+        Right click the project -> Properties -> Run/Debug Settings -> Edit -> select 'Environment' tab -> click on 'Select' -> check LD_LIBRARY_PATH option -> Ok.
+        Edit the LD_LIBRARY_PATH and add the complete path to the libs folder of the plug-in project -> Apply -> OK.
+        Then Apply -> OK to close the properties window.
+    2.Right click the project -> Run As Eclipse Application.
\ No newline at end of file
index a36114b..0a482ed 100644 (file)
@@ -3,4 +3,7 @@ output.. = bin/
 bin.includes = META-INF/,\
                .,\
                libs/,\
-                          icons/
+               icons/,\
+               plugin.xml,\
+               ,\
+               libs/Simulator.jar
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/clear_d.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/clear_d.gif
new file mode 100644 (file)
index 0000000..6775edf
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/clear_d.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/clear_e.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/clear_e.gif
new file mode 100644 (file)
index 0000000..af30a42
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/clear_e.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/debug_log.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/debug_log.gif
new file mode 100644 (file)
index 0000000..d90a29f
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/debug_log.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/delete_d.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/delete_d.gif
new file mode 100644 (file)
index 0000000..9e14298
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/delete_d.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/delete_e.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/delete_e.gif
new file mode 100644 (file)
index 0000000..b6922ac
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/delete_e.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/error_log.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/error_log.gif
new file mode 100644 (file)
index 0000000..9b048d6
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/error_log.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/export_log_d.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/export_log_d.gif
new file mode 100644 (file)
index 0000000..030b93e
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/export_log_d.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/export_log_e.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/export_log_e.gif
new file mode 100644 (file)
index 0000000..5a0837d
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/export_log_e.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/filter_d.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/filter_d.gif
new file mode 100644 (file)
index 0000000..ba6d891
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/filter_d.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/filter_e.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/filter_e.gif
new file mode 100644 (file)
index 0000000..1492b4e
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/filter_e.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/info_log.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/info_log.gif
new file mode 100644 (file)
index 0000000..3679f84
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/info_log.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/lock_d.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/lock_d.gif
new file mode 100644 (file)
index 0000000..b776478
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/lock_d.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/lock_e.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/lock_e.gif
new file mode 100644 (file)
index 0000000..68fd6cf
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/lock_e.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/log_details_e.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/log_details_e.gif
new file mode 100644 (file)
index 0000000..7ccc6a7
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/log_details_e.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_16x16.png b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_16x16.png
new file mode 100644 (file)
index 0000000..e6bbc36
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_16x16.png differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_32x32.png b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_32x32.png
new file mode 100644 (file)
index 0000000..d02a216
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_32x32.png differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_64x64.png b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_64x64.png
new file mode 100644 (file)
index 0000000..4fe3cbb
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/oic_logo_64x64.png differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/prop_d.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/prop_d.gif
new file mode 100644 (file)
index 0000000..ec394d6
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/prop_d.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/prop_e.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/prop_e.gif
new file mode 100644 (file)
index 0000000..d11c996
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/prop_e.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/trash_e.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/trash_e.gif
new file mode 100644 (file)
index 0000000..bf961b3
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/trash_e.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/tree_mode_d.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/tree_mode_d.gif
new file mode 100644 (file)
index 0000000..62bdbe2
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/tree_mode_d.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/tree_mode_e.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/tree_mode_e.gif
new file mode 100644 (file)
index 0000000..dda8bae
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/tree_mode_e.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/unknown_log.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/unknown_log.gif
new file mode 100644 (file)
index 0000000..a54ccfe
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/unknown_log.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/warning_log.gif b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/warning_log.gif
new file mode 100644 (file)
index 0000000..14009e9
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/icons/warning_log.gif differ
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/libs/Simulator.jar b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/libs/Simulator.jar
new file mode 100644 (file)
index 0000000..612bc7a
Binary files /dev/null and b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/libs/Simulator.jar differ
index 3d8eaf7..d1fd34e 100644 (file)
@@ -3,9 +3,9 @@
 <plugin>
    <extension
          point="org.eclipse.ui.perspectives">
-      <perspective 
-               class="oic.simulator.serviceprovider.perspective.PerspectiveFactory"
-            icon="icons/sample.gif"
+      <perspective
+            class="oic.simulator.serviceprovider.perspective.PerspectiveFactory"
+            icon="icons/oic_logo_16x16.png"
             id="oic.simulator.serviceprovider.perspective"
             name="Service Provider">
       </perspective>
    <extension
          point="org.eclipse.ui.views">
          <category
-               id="oic.simulator.serviceprovider.category"
-               name="Service Provider">                
+            id="oic.simulator.serviceprovider.category"
+            name="Service Provider">
          </category>
-         <view
-                       category="oic.simulator.serviceprovider.category"
+         <view category="oic.simulator.serviceprovider.category"
             class="oic.simulator.serviceprovider.view.ResourceManagerView"
-            icon="icons/sample.gif"
+            icon="icons/oic_logo_16x16.png"
             id="oic.simulator.serviceprovider.view.resourcemanager"
             name="Resource Manager"
             restorable="true">
          </view>
-         <view
-                       category="oic.simulator.serviceprovider.category"
+         <view category="oic.simulator.serviceprovider.category"
             class="oic.simulator.serviceprovider.view.AttributeView"
-            icon="icons/sample.gif"
+            icon="icons/oic_logo_16x16.png"
             id="oic.simulator.serviceprovider.view.attribute"
             name="Attribute Manager"
             restorable="true">
          </view>
-         <view
-                       category="oic.simulator.serviceprovider.category"
+         <view category="oic.simulator.serviceprovider.category"
             class="oic.simulator.serviceprovider.view.MultiResourceOrchestrationView"
-            icon="icons/sample.gif"
+            icon="icons/oic_logo_16x16.png"
             id="oic.simulator.serviceprovider.view.orchestration"
             name="Multi-Resource Automation"
             restorable="true">
          </view>
-         <view
-                       category="oic.simulator.serviceprovider.category"
+         <view category="oic.simulator.serviceprovider.category"
             class="oic.simulator.serviceprovider.view.LogView"
-            icon="icons/sample.gif"
+            icon="icons/oic_logo_16x16.png"
             id="oic.simulator.serviceprovider.view.log"
             name="Simulator Log"
             restorable="true">
          </view>
+         <view category="oic.simulator.serviceprovider.category"
+            class="oic.simulator.serviceprovider.view.MetaPropertiesView"
+            icon="icons/oic_logo_16x16.png"
+            id="oic.simulator.serviceprovider.view.metaproperties"
+            name="Properties"
+            restorable="true">
+         </view>
    </extension>
    <extension
          point="org.eclipse.ui.perspectiveExtensions">
       <perspectiveExtension
             targetID="oic.simulator.serviceprovider.perspective">
          <viewShortcut
-               id="oic.simulator.serviceprovider.view.ResourceManagerView">
+               id="oic.simulator.serviceprovider.view.resourcemanager">
          </viewShortcut>
          <viewShortcut
-               id="oic.simulator.serviceprovider.view.AttributeView">
+               id="oic.simulator.serviceprovider.view.attribute">
          </viewShortcut>
          <viewShortcut
-               id="oic.simulator.serviceprovider.view.MultiResourceOrchestrationView">
+               id="oic.simulator.serviceprovider.view.orchestration">
          </viewShortcut>
          <viewShortcut
-               id="oic.simulator.serviceprovider.view.LogView">
+               id="oic.simulator.serviceprovider.view.log">
          </viewShortcut>
-         <viewShortcut 
-                  id="org.eclipse.ui.views.PropertySheet">
+         <viewShortcut
+               id="oic.simulator.serviceprovider.view.metaproperties">
          </viewShortcut>
       </perspectiveExtension>
    </extension>
-
-</plugin>
+</plugin>
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogContentProvider.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogContentProvider.java
new file mode 100644 (file)
index 0000000..5d70e68
--- /dev/null
@@ -0,0 +1,46 @@
+package oic.simulator.logger;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+public class LogContentProvider implements ITreeContentProvider {
+
+    List<LogEntry> logEntryList = new ArrayList<LogEntry>();
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+        logEntryList = (List<LogEntry>) newInput;
+    }
+
+    @Override
+    public Object[] getChildren(Object element) {
+        return new Object[0];
+    }
+
+    @Override
+    public Object[] getElements(Object input) {
+        return logEntryList.toArray();
+    }
+
+    @Override
+    public Object getParent(Object element) {
+        return null;
+    }
+
+    @Override
+    public boolean hasChildren(Object element) {
+        return false;
+    }
+
+    @Override
+    public void dispose() {
+    }
+
+    public synchronized void addLog(LogEntry newElement) {
+        logEntryList.add(newElement);
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogEntry.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogEntry.java
new file mode 100644 (file)
index 0000000..989a273
--- /dev/null
@@ -0,0 +1,39 @@
+package oic.simulator.logger;
+
+import java.util.Date;
+
+import oic.simulator.serviceprovider.manager.LogManager;
+
+public class LogEntry {
+    private final int    severity;
+    private final Date   date;
+    private final String message;
+
+    public LogEntry(int severity, Date date, String message) {
+        this.severity = severity;
+        this.date = date;
+        this.message = message;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public int getSeverity() {
+        return severity;
+    }
+
+    @Override
+    public String toString() {
+        String newline = System.getProperty("line.separator");
+        String out = date.toString() + newline;
+        out += "Severity: " + LogManager.getSeverityName(severity) + newline;
+        out += "Message: " + message + newline;
+        out += "===============================" + newline + newline;
+        return out;
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogLabelProvider.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LogLabelProvider.java
new file mode 100644 (file)
index 0000000..7ec2759
--- /dev/null
@@ -0,0 +1,38 @@
+package oic.simulator.logger;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+import oic.simulator.serviceprovider.manager.LogManager;
+
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+public class LogLabelProvider extends LabelProvider implements
+        ITableLabelProvider {
+
+    DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
+
+    @Override
+    public Image getColumnImage(Object element, int columnIndex) {
+        if (columnIndex == 0) {
+            LogEntry entry = (LogEntry) element;
+            return LogManager.getSeverityIcon(entry.getSeverity());
+        }
+        return null;
+    }
+
+    @Override
+    public String getColumnText(Object element, int columnIndex) {
+        LogEntry entry = (LogEntry) element;
+        if (columnIndex == 0) {
+            return LogManager.getSeverityName(entry.getSeverity());
+        } else if (columnIndex == 1) {
+            return dateFormat.format(entry.getDate());
+        } else {
+            return entry.getMessage();
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LoggerCallback.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/logger/LoggerCallback.java
new file mode 100644 (file)
index 0000000..94168e0
--- /dev/null
@@ -0,0 +1,55 @@
+package oic.simulator.logger;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.oic.simulator.ILogger;
+
+public class LoggerCallback implements ILogger {
+
+    @Override
+    public void write(String time, int level, String message) {
+        if (null == time || level < 0 || null == message) {
+            return;
+        }
+        // Parse the time
+        Date date = parseTime(time);
+        if (null == date) {
+            return;
+        }
+        Activator activator = Activator.getDefault();
+        if (null == activator) {
+            return;
+        }
+        activator.getLogManager().log(level, date, message);
+    }
+
+    private Date parseTime(String time) {
+        Date date;
+        String[] token = time.split("\\.");
+        int h, m, s;
+        try {
+            if (token.length == Constants.PROPER_LOG_TIME_TOKEN_LENGTH) {
+                h = Integer.parseInt(token[0]);
+                m = Integer.parseInt(token[1]);
+                s = Integer.parseInt(token[2]);
+
+                Calendar calendar;
+                calendar = Calendar.getInstance();
+                calendar.set(Calendar.HOUR, h);
+                calendar.set(Calendar.MINUTE, m);
+                calendar.set(Calendar.SECOND, s);
+
+                date = calendar.getTime();
+            } else {
+                date = null;
+            }
+        } catch (NumberFormatException nfe) {
+            date = null;
+        }
+        return date;
+    }
+}
\ No newline at end of file
index 26c3043..c358680 100644 (file)
@@ -1,5 +1,6 @@
 package oic.simulator.serviceprovider;
 
+import oic.simulator.serviceprovider.manager.LogManager;
 import oic.simulator.serviceprovider.manager.ResourceManager;
 
 import org.eclipse.ui.plugin.AbstractUIPlugin;
@@ -16,54 +17,53 @@ public class Activator extends AbstractUIPlugin {
     // The shared instance
     private static Activator       plugin;
 
-    private static ResourceManager manager;
+    private static ResourceManager resourceManager;
+
+    private static LogManager      logManager;
 
-    /**
-     * The constructor
-     */
     public Activator() {
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
-     * )
-     */
     public void start(BundleContext context) throws Exception {
         super.start(context);
         plugin = this;
-        setManager(new ResourceManager());
+        setResourceManager(new ResourceManager());
+        setLogManager(new LogManager());
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
-     * )
-     */
     public void stop(BundleContext context) throws Exception {
         plugin = null;
+
+        // Stopping Resource Manager
+        if (null != resourceManager) {
+            resourceManager.shutdown();
+            resourceManager = null;
+        }
+        // Stopping Log Manager
+        if (null != logManager) {
+            logManager.shutdown();
+            logManager = null;
+        }
         super.stop(context);
     }
 
-    /**
-     * Returns the shared instance
-     *
-     * @return the shared instance
-     */
     public static Activator getDefault() {
         return plugin;
     }
 
-    public static ResourceManager getManager() {
-        return manager;
+    public ResourceManager getResourceManager() {
+        return resourceManager;
     }
 
-    public static void setManager(ResourceManager manager) {
-        Activator.manager = manager;
+    private static void setResourceManager(ResourceManager manager) {
+        Activator.resourceManager = manager;
     }
 
-}
+    public LogManager getLogManager() {
+        return logManager;
+    }
+
+    private static void setLogManager(LogManager logManager) {
+        Activator.logManager = logManager;
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IAutomationUIListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IAutomationUIListener.java
new file mode 100644 (file)
index 0000000..ecc2ee7
--- /dev/null
@@ -0,0 +1,7 @@
+package oic.simulator.serviceprovider.listener;
+
+public interface IAutomationUIListener {
+    public void onResourceAutomationStart(String resourceURI);
+
+    public void onAutomationComplete(String resourceURI, String attName);
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/ILogUIListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/ILogUIListener.java
new file mode 100644 (file)
index 0000000..dc539cd
--- /dev/null
@@ -0,0 +1,11 @@
+package oic.simulator.serviceprovider.listener;
+
+import java.util.List;
+
+import oic.simulator.logger.LogEntry;
+
+public interface ILogUIListener {
+    public void logAdded(LogEntry added);
+
+    public void logChanged(List<LogEntry> entry);
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceListChangedListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceListChangedListener.java
deleted file mode 100644 (file)
index 3140ec1..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-package oic.simulator.serviceprovider.listener;
-
-import java.util.List;
-
-public interface IResourceListChangedListener {
-    public void onResourceCreation(String resourceType, List<String> resourceURI);
-
-    public void onResourceDeletion(String resourceType, String resourceURI);
-
-    public void onResourceDeletionByType(String resourceType);
-
-    public void onAllResourceDeletion();
-}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceListChangedUIListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceListChangedUIListener.java
new file mode 100644 (file)
index 0000000..17ed87f
--- /dev/null
@@ -0,0 +1,7 @@
+package oic.simulator.serviceprovider.listener;
+
+public interface IResourceListChangedUIListener {
+    public void onResourceCreation();
+
+    public void onResourceDeletion();
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceModelChangedUIListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceModelChangedUIListener.java
new file mode 100644 (file)
index 0000000..7016df5
--- /dev/null
@@ -0,0 +1,8 @@
+package oic.simulator.serviceprovider.listener;
+
+import oic.simulator.serviceprovider.resource.ModelChangeNotificationType;
+
+public interface IResourceModelChangedUIListener {
+    public void onResourceModelChange(
+            ModelChangeNotificationType notificationType, String resourceURI);
+}
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceSelectionChangedUIListener.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/listener/IResourceSelectionChangedUIListener.java
new file mode 100644 (file)
index 0000000..4c844d6
--- /dev/null
@@ -0,0 +1,5 @@
+package oic.simulator.serviceprovider.listener;
+
+public interface IResourceSelectionChangedUIListener {
+    public void onResourceSelectionChange();
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/LogManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/LogManager.java
new file mode 100644 (file)
index 0000000..8563ff0
--- /dev/null
@@ -0,0 +1,253 @@
+package oic.simulator.serviceprovider.manager;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedList;
+
+import oic.simulator.logger.LogEntry;
+import oic.simulator.logger.LoggerCallback;
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.listener.ILogUIListener;
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+import org.oic.simulator.ILogger;
+import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.SimulatorManager;
+import org.osgi.framework.Bundle;
+
+public class LogManager {
+    private LinkedList<LogEntry>         entries           = new LinkedList<LogEntry>();
+    private ArrayList<ILogUIListener>    listeners         = new ArrayList<ILogUIListener>();
+    private LinkedList<LogEntry>         visibleEntries    = new LinkedList<LogEntry>();
+    private HashMap<Integer, Boolean>    visibleSeverities = new HashMap<Integer, Boolean>();
+
+    private ILogger                      logger;
+    private LogManagerSynchronizerThread synchronizerThread;
+    private Thread                       threadHandle;
+
+    static {
+        ImageRegistry r = Activator.getDefault().getImageRegistry();
+        Bundle bundle = Activator.getDefault().getBundle();
+        r.put(Constants.DEBUG_LOG, ImageDescriptor.createFromURL(bundle
+                .getEntry("/icons/debug_log.gif")));
+        r.put(Constants.INFO_LOG, ImageDescriptor.createFromURL(bundle
+                .getEntry("/icons/info_log.gif")));
+        r.put(Constants.WARNING_LOG, ImageDescriptor.createFromURL(bundle
+                .getEntry("/icons/warning_log.gif")));
+        r.put(Constants.ERROR_LOG, ImageDescriptor.createFromURL(bundle
+                .getEntry("/icons/error_log.gif")));
+        r.put(Constants.UNKNOWN_LOG, ImageDescriptor.createFromURL(bundle
+                .getEntry("/icons/unknown_log.gif")));
+    }
+
+    public LogManager() {
+        synchronizerThread = new LogManagerSynchronizerThread();
+        threadHandle = new Thread(synchronizerThread);
+        threadHandle.setName("OIC Simulator event queue");
+        threadHandle.start();
+
+        // Set the logger callback with the native layer
+        logger = new LoggerCallback();
+        SimulatorManager.setLogger(logger);
+    }
+
+    private static class LogManagerSynchronizerThread implements Runnable {
+
+        LinkedList<Runnable> eventQueue = new LinkedList<Runnable>();
+
+        @Override
+        public void run() {
+            while (!Thread.interrupted()) {
+
+                synchronized (this) {
+                    try {
+                        while (eventQueue.isEmpty()) {
+                            this.wait();
+                            break;
+                        }
+                    } catch (InterruptedException e) {
+                        return;
+                    }
+                }
+
+                Runnable pop;
+                synchronized (this) {
+                    pop = eventQueue.pop();
+                }
+                try {
+                    pop.run();
+                } catch (Exception e) {
+                    if (e instanceof InterruptedException) {
+                        return;
+                    }
+                    e.printStackTrace();
+                }
+            }
+        }
+
+        public void addToQueue(Runnable event) {
+            synchronized (this) {
+                eventQueue.add(event);
+                this.notify();
+            }
+        }
+    }
+
+    public void log(int severity, Date date, String msg) {
+        final LogEntry logEntry = new LogEntry(severity, date, msg);
+        synchronizerThread.addToQueue(new Runnable() {
+            @Override
+            public void run() {
+                boolean notify = false;
+                synchronized (entries) {
+                    entries.add(logEntry);
+                    Boolean showEntry = LogManager.this.visibleSeverities
+                            .get(logEntry.getSeverity());
+                    if (showEntry != null) {
+                        if (showEntry) {
+                            visibleEntries.add(logEntry);
+                            notify = true;
+                        }
+                    }
+                    if (entries.size() > Constants.LOG_SIZE) {
+                        entries.pop();
+                    }
+                    if (visibleEntries.size() > Constants.LOG_SIZE) {
+                        visibleEntries.pop();
+                        notify = true;
+                    }
+                }
+                if (notify) {
+                    notifyListeners(logEntry);
+                }
+            }
+        });
+    }
+
+    public void applyFilter(final HashMap<Integer, Boolean> visibleSeverities) {
+        synchronizerThread.addToQueue(new Runnable() {
+
+            @Override
+            public void run() {
+                LinkedList<LogEntry> newLogs = new LinkedList<LogEntry>();
+                synchronized (entries) {
+                    LogManager.this.visibleSeverities = visibleSeverities;
+                    for (LogEntry logEntry : entries) {
+                        if (LogManager.this.visibleSeverities.get(logEntry
+                                .getSeverity())) {
+                            newLogs.add(logEntry);
+                        }
+                    }
+                }
+                visibleEntries = newLogs;
+                notifyListeners();
+            }
+        });
+
+    }
+
+    private void notifyListeners() {
+        for (ILogUIListener l : listeners) {
+            l.logChanged(new ArrayList<LogEntry>(visibleEntries));
+        }
+    }
+
+    private void notifyListeners(LogEntry added) {
+        for (ILogUIListener l : listeners) {
+            l.logAdded(added);
+        }
+    }
+
+    public void clearLog() {
+        synchronizerThread.addToQueue(new Runnable() {
+
+            @Override
+            public void run() {
+                synchronized (entries) {
+                    entries = new LinkedList<LogEntry>();
+                    visibleEntries = new LinkedList<LogEntry>();
+                }
+                notifyListeners();
+            }
+        });
+    }
+
+    public void removeEntry(final LogEntry element) {
+        synchronizerThread.addToQueue(new Runnable() {
+
+            @Override
+            public void run() {
+                synchronized (entries) {
+                    entries.remove(element);
+                    visibleEntries.remove(element);
+                }
+                notifyListeners();
+            }
+        });
+    }
+
+    public ArrayList<LogEntry> getLogEntries() {
+        synchronized (entries) {
+            return new ArrayList<LogEntry>(entries);
+        }
+    }
+
+    public void addLogListener(final ILogUIListener listener) {
+        synchronizerThread.addToQueue(new Runnable() {
+            @Override
+            public void run() {
+                if (!listeners.contains(listener)) {
+                    listeners.add(listener);
+                }
+            }
+        });
+    }
+
+    public void removeLogListener(final ILogUIListener listener) {
+        synchronizerThread.addToQueue(new Runnable() {
+            @Override
+            public void run() {
+                if (!listeners.contains(listener)) {
+                    listeners.remove(listener);
+                }
+            }
+        });
+    }
+
+    public void shutdown() {
+        threadHandle.interrupt();
+    }
+
+    public static String getSeverityName(int severity) {
+        if (severity == Level.INFO.ordinal()) {
+            return Constants.INFO;
+        } else if (severity == Level.WARNING.ordinal()) {
+            return Constants.WARNING;
+        } else if (severity == Level.ERROR.ordinal()) {
+            return Constants.ERROR;
+        } else if (severity == Level.DEBUG.ordinal()) {
+            return Constants.DEBUG;
+        } else {
+            return Constants.UNKNOWN;
+        }
+    }
+
+    public static Image getSeverityIcon(int severity) {
+        ImageRegistry r = Activator.getDefault().getImageRegistry();
+        if (severity == Level.INFO.ordinal()) {
+            return r.get(Constants.INFO_LOG);
+        } else if (severity == Level.WARNING.ordinal()) {
+            return r.get(Constants.WARNING_LOG);
+        } else if (severity == Level.ERROR.ordinal()) {
+            return r.get(Constants.ERROR_LOG);
+        } else if (severity == Level.DEBUG.ordinal()) {
+            return r.get(Constants.DEBUG_LOG);
+        } else {
+            return r.get(Constants.UNKNOWN_LOG);
+        }
+    }
+}
\ No newline at end of file
index 5f20998..9f4c4e5 100644 (file)
@@ -1,23 +1,31 @@
 package oic.simulator.serviceprovider.manager;
 
 import java.util.ArrayList;
-import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.Vector;
 
-import oic.simulator.serviceprovider.listener.IResourceListChangedListener;
+import oic.simulator.serviceprovider.listener.IAutomationUIListener;
+import oic.simulator.serviceprovider.listener.IResourceListChangedUIListener;
+import oic.simulator.serviceprovider.listener.IResourceModelChangedUIListener;
+import oic.simulator.serviceprovider.listener.IResourceSelectionChangedUIListener;
+import oic.simulator.serviceprovider.resource.MetaProperty;
+import oic.simulator.serviceprovider.resource.ModelChangeNotificationType;
 import oic.simulator.serviceprovider.resource.ResourceAttribute;
 import oic.simulator.serviceprovider.resource.SimulatorResource;
 import oic.simulator.serviceprovider.resource.StandardConfiguration;
+import oic.simulator.serviceprovider.utils.Constants;
 
-import org.iotivity.simulator.SimulatorManager;
-import org.iotivity.simulator.SimulatorResourceAttribute;
-import org.iotivity.simulator.SimulatorResourceModel;
-import org.iotivity.simulator.SimulatorResourceServer;
+import org.oic.simulator.AutomationType;
+import org.oic.simulator.IAutomation;
+import org.oic.simulator.SimulatorManager;
+import org.oic.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.serviceprovider.IResourceModelChangedListener;
+import org.oic.simulator.serviceprovider.SimulatorResourceModel;
+import org.oic.simulator.serviceprovider.SimulatorResourceServer;
 
 public class ResourceManager {
 
@@ -25,7 +33,23 @@ public class ResourceManager {
 
     private StandardConfiguration                       stdConfig;
 
-    private IResourceListChangedListener                resourceListChangedListener;
+    private SimulatorResource                           currentResourceInSelection;
+
+    private List<IResourceListChangedUIListener>        resourceListChangedUIListeners;
+
+    private List<IResourceSelectionChangedUIListener>   resourceSelectionChangedUIListeners;
+
+    private List<IResourceModelChangedUIListener>       resourceModelChangedUIListeners;
+
+    private List<IAutomationUIListener>                 automationUIListeners;
+
+    private IResourceModelChangedListener               resourceModelChangeListener;
+
+    private IAutomation                                 automationListener;
+
+    private NotificationSynchronizerThread              synchronizerThread;
+
+    private Thread                                      threadHandle;
 
     static {
         System.loadLibrary("SimulatorManager");
@@ -35,22 +59,157 @@ public class ResourceManager {
         resourceMap = new HashMap<String, Map<String, SimulatorResource>>();
         stdConfig = new StandardConfiguration();
 
+        resourceListChangedUIListeners = new ArrayList<IResourceListChangedUIListener>();
+        resourceSelectionChangedUIListeners = new ArrayList<IResourceSelectionChangedUIListener>();
+        resourceModelChangedUIListeners = new ArrayList<IResourceModelChangedUIListener>();
+        automationUIListeners = new ArrayList<IAutomationUIListener>();
+
         // Populate standard configuration file list
         populateStandardConfigurationList();
+
+        resourceModelChangeListener = new IResourceModelChangedListener() {
+
+            @Override
+            public void onResourceModelChanged(final String resourceURI,
+                    final SimulatorResourceModel resourceModelN) {
+                synchronizerThread.addToQueue(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        if (null == resourceURI || null == resourceModelN) {
+                            return;
+                        }
+                        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+                        if (null == resource) {
+                            return;
+                        }
+                        // Fetch the resource attributes
+                        Map<String, ResourceAttribute> resourceAttributeMapNew;
+                        resourceAttributeMapNew = fetchResourceAttributesFromModel(resourceModelN);
+                        if (null == resourceAttributeMapNew) {
+                            return;
+                        }
+                        // Update the resource with new model data
+                        Map<String, ResourceAttribute> resourceAttributeMapOld;
+                        resourceAttributeMapOld = resource
+                                .getResourceAttributesMap();
+                        if (null == resourceAttributeMapOld) {
+                            return;
+                        }
+                        ModelChangeNotificationType notificationType;
+                        notificationType = compareAndUpdateLocalAttributes(
+                                resourceAttributeMapOld,
+                                resourceAttributeMapNew);
+                        if (notificationType != ModelChangeNotificationType.NONE) {
+                            // Update the UI listeners
+                            resourceModelChangedUINotification(
+                                    notificationType, resourceURI);
+                        }
+                    }
+                });
+            }
+        };
+
+        automationListener = new IAutomation() {
+
+            @Override
+            public void onAutomationComplete(final String resourceURI,
+                    final int automationId) {
+                synchronizerThread.addToQueue(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+                        if (null == resource) {
+                            return;
+                        }
+                        // Checking whether this notification is for an
+                        // attribute or a resource
+                        if (resource.isResourceAutomationInProgress()) {
+                            changeResourceLevelAutomationStatus(resource, false);
+                            // Notify the UI listeners
+                            automationCompleteUINotification(resourceURI, null);
+                        } else if (resource.isAttributeAutomationInProgress()) {
+                            // Find the attribute with the given automation id
+                            ResourceAttribute attribute;
+                            attribute = getAttributeWithGivenAutomationId(
+                                    resource, automationId);
+                            if (null != attribute) {
+                                attribute.setAutomationInProgress(false);
+                                resource.setAttributeAutomationInProgress(false);
+                                // Notify the UI listeners
+                                automationCompleteUINotification(resourceURI,
+                                        attribute.getAttributeName());
+                            }
+                        } else {
+                            // Ignoring the notification as there are no
+                            // known automation for the current resource.
+                        }
+                    }
+                });
+            }
+        };
+
+        synchronizerThread = new NotificationSynchronizerThread();
+        threadHandle = new Thread(synchronizerThread);
+        threadHandle.setName("Simulator service provider event queue");
+        threadHandle.start();
+    }
+
+    private static class NotificationSynchronizerThread implements Runnable {
+
+        LinkedList<Runnable> notificationQueue = new LinkedList<Runnable>();
+
+        @Override
+        public void run() {
+            while (!Thread.interrupted()) {
+                synchronized (this) {
+                    try {
+                        while (notificationQueue.isEmpty()) {
+                            this.wait();
+                            break;
+                        }
+                    } catch (InterruptedException e) {
+                        return;
+                    }
+                }
+
+                Runnable thread;
+                synchronized (this) {
+                    thread = notificationQueue.pop();
+                }
+                try {
+                    thread.run();
+                } catch (Exception e) {
+                    if (e instanceof InterruptedException) {
+                        return;
+                    }
+                    e.printStackTrace();
+                }
+            }
+        }
+
+        public void addToQueue(Runnable event) {
+            synchronized (this) {
+                notificationQueue.add(event);
+                this.notify();
+            }
+        }
     }
 
-    public void populateStandardConfigurationList() {
+    private void populateStandardConfigurationList() {
         // TODO: Add all the standard configuration files
         // Ex: stdConfig.addResourceConfiguration(LIGHT, LIGHT_FILE);
     }
 
-    public synchronized List<String> getResourceConfigurationList() {
+    // This method gives a list of RAML resource configurations available.
+    public List<String> getResourceConfigurationList() {
         List<String> resourceConfigurationList = new ArrayList<String>();
-        Map<String, String> configMap = stdConfig
-                .getStandardResourceConfigurationList();
-        if (null != configMap) {
-            Set<String> keySet = configMap.keySet();
-            if (null != keySet) {
+        synchronized (stdConfig) {
+            Map<String, String> configMap = stdConfig
+                    .getStandardResourceConfigurationList();
+            if (null != configMap) {
+                Set<String> keySet = configMap.keySet();
                 Iterator<String> keyItr = keySet.iterator();
                 while (keyItr.hasNext()) {
                     resourceConfigurationList.add(keyItr.next());
@@ -60,58 +219,138 @@ public class ResourceManager {
         return resourceConfigurationList;
     }
 
-    public synchronized String getConfigFilePath(String resourceType) {
+    public String getConfigFilePath(String resourceType) {
         String path = null;
         if (null != resourceType) {
-            path = stdConfig.getResourceConfigFilePath(resourceType);
+            synchronized (stdConfig) {
+                path = stdConfig.getResourceConfigFilePath(resourceType);
+            }
         }
         return path;
     }
 
-    private synchronized void addResourceToMap(
-            SimulatorResource simulatorResource) {
+    public void addResourceListChangedUIListener(
+            IResourceListChangedUIListener resourceListChangedUIListener) {
+        synchronized (resourceListChangedUIListeners) {
+            resourceListChangedUIListeners.add(resourceListChangedUIListener);
+        }
+    }
+
+    public void addResourceSelectionChangedUIListener(
+            IResourceSelectionChangedUIListener resourceSelectionChangedUIListener) {
+        synchronized (resourceSelectionChangedUIListeners) {
+            resourceSelectionChangedUIListeners
+                    .add(resourceSelectionChangedUIListener);
+        }
+    }
+
+    public void addResourceModelChangedUIListener(
+            IResourceModelChangedUIListener resourceModelChangedUIListener) {
+        synchronized (resourceModelChangedUIListeners) {
+            resourceModelChangedUIListeners.add(resourceModelChangedUIListener);
+        }
+    }
+
+    public void addAutomationUIListener(
+            IAutomationUIListener automationUIListener) {
+        synchronized (automationUIListeners) {
+            automationUIListeners.add(automationUIListener);
+        }
+    }
+
+    public void removeResourceListChangedUIListener(
+            IResourceListChangedUIListener listener) {
+        synchronized (resourceListChangedUIListeners) {
+            if (null != listener && resourceListChangedUIListeners.size() > 0) {
+                resourceListChangedUIListeners.remove(listener);
+            }
+        }
+    }
+
+    public void removeResourceSelectionChangedUIListener(
+            IResourceSelectionChangedUIListener listener) {
+        synchronized (resourceSelectionChangedUIListeners) {
+            if (null != listener
+                    && resourceSelectionChangedUIListeners.size() > 0) {
+                resourceSelectionChangedUIListeners.remove(listener);
+            }
+        }
+    }
+
+    public void removeResourceModelChangedUIListener(
+            IResourceModelChangedUIListener listener) {
+        synchronized (resourceModelChangedUIListeners) {
+            if (null != listener && resourceModelChangedUIListeners.size() > 0) {
+                resourceModelChangedUIListeners.remove(listener);
+            }
+        }
+    }
+
+    public void removeAutomationUIListener(IAutomationUIListener listener) {
+        synchronized (automationUIListeners) {
+            if (null != listener && automationUIListeners.size() > 0) {
+                automationUIListeners.remove(listener);
+            }
+        }
+    }
+
+    public synchronized SimulatorResource getCurrentResourceInSelection() {
+        return currentResourceInSelection;
+    }
+
+    public synchronized void setCurrentResourceInSelection(
+            SimulatorResource resource) {
+        this.currentResourceInSelection = resource;
+    }
+
+    private void addResourceToMap(SimulatorResource simulatorResource) {
         if (null != simulatorResource) {
-            Map<String, SimulatorResource> resourceTypeMap;
-            resourceTypeMap = resourceMap.get(simulatorResource
-                    .getResourceType());
-            if (null == resourceTypeMap) {
-                resourceTypeMap = new HashMap<String, SimulatorResource>();
-                resourceMap.put(simulatorResource.getResourceType(),
-                        resourceTypeMap);
+            synchronized (resourceMap) {
+                Map<String, SimulatorResource> resourceTypeMap;
+                resourceTypeMap = resourceMap.get(simulatorResource
+                        .getResourceType());
+                if (null == resourceTypeMap) {
+                    resourceTypeMap = new HashMap<String, SimulatorResource>();
+                    resourceMap.put(simulatorResource.getResourceType(),
+                            resourceTypeMap);
+                }
+                resourceTypeMap.put(simulatorResource.getResourceURI(),
+                        simulatorResource);
             }
-            resourceTypeMap.put(simulatorResource.getResourceURI(),
-                    simulatorResource);
         }
     }
 
-    private synchronized void addResourceToMap(String resourceType,
+    private void addResourceToMap(String resourceType,
             Map<String, SimulatorResource> newResourceTypeMap) {
         if (null != resourceType && null != newResourceTypeMap) {
-            Map<String, SimulatorResource> resourceTypeMap = resourceMap
-                    .get(resourceType);
-            if (null != resourceTypeMap) {
-                resourceTypeMap.putAll(newResourceTypeMap);
-            } else {
-                resourceMap.put(resourceType, newResourceTypeMap);
+            synchronized (resourceMap) {
+                Map<String, SimulatorResource> resourceTypeMap = resourceMap
+                        .get(resourceType);
+                if (null != resourceTypeMap) {
+                    resourceTypeMap.putAll(newResourceTypeMap);
+                } else {
+                    resourceMap.put(resourceType, newResourceTypeMap);
+                }
             }
         }
     }
 
-    private synchronized void removeResourceFromMap(String resourceType,
-            String resourceURI) {
+    private void removeResourceFromMap(String resourceType, String resourceURI) {
         if (null != resourceURI && null != resourceType) {
-            Map<String, SimulatorResource> resourceTypeMap = resourceMap
-                    .get(resourceType);
-            if (null != resourceTypeMap) {
-                resourceTypeMap.remove(resourceURI);
-                if (resourceTypeMap.size() < 1) {
-                    resourceMap.remove(resourceType);
+            synchronized (resourceMap) {
+                Map<String, SimulatorResource> resourceTypeMap = resourceMap
+                        .get(resourceType);
+                if (null != resourceTypeMap) {
+                    resourceTypeMap.remove(resourceURI);
+                    if (resourceTypeMap.size() < 1) {
+                        resourceMap.remove(resourceType);
+                    }
                 }
             }
         }
     }
 
-    public synchronized boolean isResourceExist(String resourceURI) {
+    public boolean isResourceExist(String resourceURI) {
         boolean result = false;
         if (null != resourceURI) {
             SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
@@ -122,55 +361,54 @@ public class ResourceManager {
         return result;
     }
 
-    public synchronized void createResource(String configFilePath) {
-        SimulatorResourceServer resourceServerN;
-        resourceServerN = SimulatorManager.createResource(configFilePath);
+    public void createResource(final String configFilePath) {
+        new Thread() {
+            @Override
+            public void run() {
+                SimulatorResourceServer resourceServerN;
+                resourceServerN = SimulatorManager.createResource(
+                        configFilePath, resourceModelChangeListener);
 
-        SimulatorResource simulatorResource;
-        simulatorResource = fetchResourceData(resourceServerN);
-        if (null != simulatorResource) {
-            addResourceToMap(simulatorResource);
-
-            String resourceType = simulatorResource.getResourceType();
-            String resourceURI = simulatorResource.getResourceURI();
-            List<String> resourceURIList = new ArrayList<String>();
-            resourceURIList.add(resourceURI);
-
-            resourceCreatedNotification(resourceType, resourceURIList);
-        }
-    }
-
-    public synchronized void createResource(String configFilePath,
-            int noOfInstances) {
-        Map<String, SimulatorResource> resourceTypeMap;
-        List<String> resourceUriList;
-        Vector<SimulatorResourceServer> simulatorResourceServerVectorN = null;
-        simulatorResourceServerVectorN = SimulatorManager.createResource(
-                configFilePath, noOfInstances);
-        if (null != simulatorResourceServerVectorN) {
-            resourceTypeMap = new HashMap<String, SimulatorResource>();
-            resourceUriList = new ArrayList<String>();
-            Enumeration<SimulatorResourceServer> uriItr = simulatorResourceServerVectorN
-                    .elements();
-            SimulatorResourceServer resourceServerN;
-            SimulatorResource resource;
-            String uri;
-            while (uriItr.hasMoreElements()) {
-                resourceServerN = uriItr.nextElement();
-                resource = fetchResourceData(resourceServerN);
-                if (null != resource) {
-                    uri = resource.getResourceURI();
-                    resourceUriList.add(uri);
-                    resourceTypeMap.put(uri, resource);
-                }
-            }
-
-            // Find the resourceType and add it to the local data structure and
-            // notify UI Listeners
-            if (resourceTypeMap.size() > 0) {
-                String resourceType;
-                Set<String> uriSet = resourceTypeMap.keySet();
-                if (null != uriSet) {
+                SimulatorResource simulatorResource;
+                simulatorResource = fetchResourceData(resourceServerN);
+                if (null != simulatorResource) {
+                    addResourceToMap(simulatorResource);
+
+                    resourceCreatedUINotification();
+                }
+            }
+        }.start();
+    }
+
+    public void createResource(final String configFilePath,
+            final int noOfInstances) {
+        new Thread() {
+            @Override
+            public void run() {
+                Map<String, SimulatorResource> resourceTypeMap;
+                SimulatorResourceServer[] simulatorResourceServers = null;
+                simulatorResourceServers = SimulatorManager.createResource(
+                        configFilePath, noOfInstances,
+                        resourceModelChangeListener);
+                if (null == simulatorResourceServers) {
+                    return;
+                }
+                resourceTypeMap = new HashMap<String, SimulatorResource>();
+                SimulatorResource resource;
+                String uri;
+                for (SimulatorResourceServer resourceServerN : simulatorResourceServers) {
+                    resource = fetchResourceData(resourceServerN);
+                    if (null != resource) {
+                        uri = resource.getResourceURI();
+                        resourceTypeMap.put(uri, resource);
+                    }
+                }
+
+                // Find the resourceType and add it to the local data
+                // structure and notify UI Listeners
+                if (resourceTypeMap.size() > 0) {
+                    String resourceType;
+                    Set<String> uriSet = resourceTypeMap.keySet();
                     Iterator<String> itr = uriSet.iterator();
                     if (itr.hasNext()) {
                         SimulatorResource simResource = resourceTypeMap.get(itr
@@ -179,23 +417,18 @@ public class ResourceManager {
                             resourceType = simResource.getResourceType();
 
                             addResourceToMap(resourceType, resourceTypeMap);
-
-                            resourceCreatedNotification(resourceType,
-                                    resourceUriList);
+                            resourceCreatedUINotification();
                         }
                     }
                 }
             }
-        }
-
+        }.start();
     }
 
-    private synchronized SimulatorResource fetchResourceData(
+    private SimulatorResource fetchResourceData(
             SimulatorResourceServer resourceServerN) {
         SimulatorResource simulatorResource = null;
         if (null != resourceServerN) {
-            Map<String, ResourceAttribute> resourceAttributeMap = null;
-
             simulatorResource = new SimulatorResource();
             simulatorResource.setResourceServer(resourceServerN);
             simulatorResource.setResourceURI(resourceServerN.getURI());
@@ -209,72 +442,122 @@ public class ResourceManager {
             if (null != resourceModelN) {
                 simulatorResource.setResourceModel(resourceModelN);
 
-                Map<String, SimulatorResourceAttribute> attributeMapN;
-                attributeMapN = resourceModelN.getAttributes();
-                if (null != attributeMapN) {
-                    resourceAttributeMap = new HashMap<String, ResourceAttribute>();
-
-                    Set<String> attNameSet = attributeMapN.keySet();
-                    if (null != attNameSet) {
-                        String attName;
-                        SimulatorResourceAttribute attributeN;
-                        ResourceAttribute attribute;
-                        Iterator<String> attNameItr = attNameSet.iterator();
-                        while (attNameItr.hasNext()) {
-                            attName = attNameItr.next();
-                            attributeN = attributeMapN.get(attName);
-                            if (null != attributeN) {
-                                attribute = new ResourceAttribute();
-                                attribute.setAttributeName(attName);
-
-                                // Other attribute details such as value,
-                                // allowed values and range are based on type
-                                // Type implementation is yet to be done
-                                resourceAttributeMap.put(attName, attribute);
-                            }
-                        }
-                        simulatorResource
-                                .setResourceAttributesMap(resourceAttributeMap);
-                    }
+                // Fetch the resource attributes
+                Map<String, ResourceAttribute> resourceAttributeMap;
+                resourceAttributeMap = fetchResourceAttributesFromModel(resourceModelN);
+                if (null != resourceAttributeMap) {
+                    simulatorResource
+                            .setResourceAttributesMap(resourceAttributeMap);
                 }
             }
         }
         return simulatorResource;
     }
 
-    private synchronized void resourceCreatedNotification(String resourceType,
-            List<String> resourceURIList) {
-        if (null != resourceType && null != resourceURIList
-                && null != resourceListChangedListener) {
-            resourceListChangedListener.onResourceCreation(resourceType,
-                    resourceURIList);
+    private Map<String, ResourceAttribute> fetchResourceAttributesFromModel(
+            SimulatorResourceModel resourceModelN) {
+        Map<String, ResourceAttribute> resourceAttributeMap = null;
+        if (null != resourceModelN) {
+            Map<String, SimulatorResourceAttribute> attributeMapN;
+            attributeMapN = resourceModelN.getAttributes();
+            if (null != attributeMapN) {
+                resourceAttributeMap = new HashMap<String, ResourceAttribute>();
+
+                Set<String> attNameSet = attributeMapN.keySet();
+                String attName;
+                Object attValueObj;
+                SimulatorResourceAttribute attributeN;
+                ResourceAttribute attribute;
+                Iterator<String> attNameItr = attNameSet.iterator();
+                while (attNameItr.hasNext()) {
+                    attName = attNameItr.next();
+                    attributeN = attributeMapN.get(attName);
+                    if (null != attributeN) {
+                        attribute = new ResourceAttribute();
+                        attribute.setResourceAttribute(attributeN);
+                        attribute.setAttributeName(attName);
+
+                        attValueObj = attributeN.getValue();
+                        if (null != attValueObj) {
+                            attribute.setAttributeValue(attValueObj);
+                        }
+
+                        // Read allowed values or min-max values of the
+                        // attribute
+                        // TODO: Temporarily reading the allowed values
+                        // as string
+                        // If attribute type is known, then appropriate
+                        // get method for that type will be called.
+                        String[] allowedValues = resourceModelN
+                                .getAllowedValues(attName);
+                        attribute.setAllowedValues(allowedValues);
+                        if (null == allowedValues || allowedValues.length < 1) {
+                            // TODO: Get the range(min-max) of the attribute
+                            // Implementation of GetRange is in progress
+                        }
+
+                        // Initially disabling the automation
+                        attribute.setAutomationInProgress(false);
+
+                        // TODO: Temporarily setting the interval to 500.
+                        // This value should come from the native layer.
+                        // Native implementation is in progress.
+                        attribute
+                                .setAutomationUpdateInterval(Constants.DEFAULT_AUTOMATION_INTERVAL);
+
+                        // Setting the default automation type
+                        attribute
+                                .setAutomationType(Constants.DEFAULT_AUTOMATION_TYPE);
+
+                        resourceAttributeMap.put(attName, attribute);
+                    }
+                }
+            }
         }
+        return resourceAttributeMap;
     }
 
-    public synchronized void deleteResourceByURI(String resourceURI) {
+    public void deleteResourceByURI(final String resourceURI) {
         if (null != resourceURI) {
-            SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
-            if (null != resource) {
-                String resourceType = resource.getResourceType();
+            new Thread() {
+                @Override
+                public void run() {
+                    SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+                    if (null != resource) {
+                        String resourceType = resource.getResourceType();
 
-                // Unregister the resource from the platform
-                deleteResource(resource);
+                        // Unregister the resource from the platform
+                        deleteResource(resource);
 
-                // Delete from the local data structure
-                deleteLocalResourceDetails(resourceType, resourceURI);
+                        // Delete from the local data structure
+                        deleteLocalResourceDetails(resourceType, resourceURI);
 
-                // Notify the UI listener for removing this resource from UI
-                resourceDeletedNotification(resourceType, resourceURI);
-            }
+                        // Notify the UI listener for removing this resource
+                        // from UI
+                        resourceDeletedUINotification();
+
+                        if (null != currentResourceInSelection
+                                && resource == currentResourceInSelection) {
+                            // Listeners might query the resource being deleted
+                            // if exists. So set the currently selection to
+                            // null.
+                            setCurrentResourceInSelection(null);
+
+                            // Notify all observers for resource selection
+                            // change event
+                            resourceSelectionChangedUINotification();
+                        }
+                    }
+                }
+            }.start();
         }
     }
 
-    private synchronized SimulatorResource getSimulatorResourceByURI(
-            String resourceURI) {
+    private SimulatorResource getSimulatorResourceByURI(String resourceURI) {
         SimulatorResource resource = null;
         if (null != resourceURI) {
-            Set<String> typeSet = resourceMap.keySet();
-            if (null != typeSet) {
+            synchronized (resourceMap) {
+                Set<String> typeSet = resourceMap.keySet();
                 Iterator<String> typeItr = typeSet.iterator();
                 String resourceType;
                 Map<String, SimulatorResource> resourceTypeMap;
@@ -293,7 +576,7 @@ public class ResourceManager {
         return resource;
     }
 
-    private synchronized void deleteResource(SimulatorResource resource) {
+    private void deleteResource(SimulatorResource resource) {
         if (null != resource) {
             SimulatorResourceServer resourceServerN = resource
                     .getResourceServer();
@@ -303,92 +586,562 @@ public class ResourceManager {
         }
     }
 
-    public synchronized void deleteResourceByType(String resourceType) {
+    public void deleteResourceByType(final String resourceType) {
         if (null != resourceType) {
-            // Unregister the resources from the platform
-            deleteResource(resourceType);
+            new Thread() {
+                @Override
+                public void run() {
+                    // Unregister the resources from the platform
+                    deleteResource(resourceType);
+
+                    // Delete from the local data structure
+                    deleteLocalResourceDetails(resourceType, null);
 
-            // Delete from the local data structure
-            deleteLocalResourceDetails(resourceType, null);
+                    // Notify the UI listener for removing this resource from UI
+                    resourceDeletedUINotification();
 
-            // Notify the UI listener for removing this resource from UI
-            resourceTypeDeletedNotification(resourceType);
+                    if (null != currentResourceInSelection
+                            && resourceType.equals(currentResourceInSelection
+                                    .getResourceType())) {
+                        // Listeners might query the resource being deleted if
+                        // exists. So set the currently selection to null.
+                        setCurrentResourceInSelection(null);
 
+                        // Notify all observers for resource selection change
+                        // event
+                        resourceSelectionChangedUINotification();
+                    }
+                }
+            }.start();
         }
     }
 
-    private synchronized void deleteResource(String resourceType) {
+    private void deleteResource(String resourceType) {
         if (null != resourceType) {
             SimulatorManager.deleteResources(resourceType);
         }
     }
 
-    public synchronized void deleteAllResources() {
-        // Unregister the resources from the platform
-        deleteResource();
+    public void deleteAllResources() {
+        new Thread() {
+            @Override
+            public void run() {
+                // Unregister the resources from the platform
+                deleteResource();
 
-        // Delete from the local data structure
-        deleteLocalResourceDetails(null, null);
+                // Delete from the local data structure
+                deleteLocalResourceDetails(null, null);
+
+                // Notify the UI listener for removing this resource from UI
+                resourceDeletedUINotification();
+
+                // Listeners might query the resource being deleted if exists.
+                // So set the currently selection to null.
+                setCurrentResourceInSelection(null);
 
-        // Notify the UI listener for removing this resource from UI
-        allResourcesDeletedNotification();
+                // Notify all observers for resource selection change event
+                resourceSelectionChangedUINotification();
+            }
+        }.start();
     }
 
-    private synchronized void deleteResource() {
-        // SimulatorManager.deleteResources();
+    private void deleteResource() {
+        SimulatorManager.deleteResources(null);
     }
 
-    private synchronized void deleteLocalResourceDetails(String resourceType,
+    private void deleteLocalResourceDetails(String resourceType,
             String resourceURI) {
         if (null != resourceType && null != resourceURI) {
             removeResourceFromMap(resourceType, resourceURI);
-        } else if (null != resourceType) {
-            resourceMap.remove(resourceType);
         } else {
-            resourceMap.clear();
+            synchronized (resourceMap) {
+                if (null != resourceType) {
+                    resourceMap.remove(resourceType);
+                } else {
+                    resourceMap.clear();
+                }
+            }
         }
     }
 
-    private synchronized void resourceDeletedNotification(String resourceType,
-            String resourceURI) {
-        if (null != resourceListChangedListener) {
-            resourceListChangedListener.onResourceDeletion(resourceType,
-                    resourceURI);
+    private void resourceCreatedUINotification() {
+        synchronized (resourceListChangedUIListeners) {
+            if (resourceListChangedUIListeners.size() > 0) {
+                IResourceListChangedUIListener listener;
+                Iterator<IResourceListChangedUIListener> listenerItr = resourceListChangedUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onResourceCreation();
+                    }
+                }
+            }
         }
     }
 
-    private synchronized void resourceTypeDeletedNotification(
-            String resourceType) {
-        if (null != resourceListChangedListener) {
-            resourceListChangedListener.onResourceDeletionByType(resourceType);
+    private void resourceDeletedUINotification() {
+        synchronized (resourceListChangedUIListeners) {
+            if (resourceListChangedUIListeners.size() > 0) {
+                IResourceListChangedUIListener listener;
+                Iterator<IResourceListChangedUIListener> listenerItr = resourceListChangedUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onResourceDeletion();
+                    }
+                }
+            }
         }
     }
 
-    private synchronized void allResourcesDeletedNotification() {
-        if (null != resourceListChangedListener) {
-            resourceListChangedListener.onAllResourceDeletion();
+    private void resourceSelectionChangedUINotification() {
+        synchronized (resourceSelectionChangedUIListeners) {
+            if (resourceSelectionChangedUIListeners.size() > 0) {
+                IResourceSelectionChangedUIListener listener;
+                Iterator<IResourceSelectionChangedUIListener> listenerItr = resourceSelectionChangedUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onResourceSelectionChange();
+                    }
+                }
+            }
         }
     }
 
-    public synchronized IResourceListChangedListener getResourceListChangedListener() {
-        return resourceListChangedListener;
+    private void resourceModelChangedUINotification(
+            ModelChangeNotificationType notificationType, String resourceURI) {
+        synchronized (resourceModelChangedUIListeners) {
+            if (resourceModelChangedUIListeners.size() > 0
+                    && notificationType != ModelChangeNotificationType.NONE
+                    && null != resourceURI) {
+                IResourceModelChangedUIListener listener;
+                Iterator<IResourceModelChangedUIListener> listenerItr = resourceModelChangedUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onResourceModelChange(notificationType,
+                                resourceURI);
+                    }
+                }
+            }
+        }
     }
 
-    public synchronized void setResourceListChangedListener(
-            IResourceListChangedListener resourceListChangedListener) {
-        this.resourceListChangedListener = resourceListChangedListener;
+    private void resourceAutomationStartedUINotification(String resourceURI) {
+        synchronized (automationUIListeners) {
+            if (automationUIListeners.size() > 0 && null != resourceURI) {
+                IAutomationUIListener listener;
+                Iterator<IAutomationUIListener> listenerItr = automationUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onResourceAutomationStart(resourceURI);
+                    }
+                }
+            }
+        }
     }
 
-    public synchronized List<String> getResourceTypeList() {
+    private void automationCompleteUINotification(String resourceURI,
+            String attName) {
+        synchronized (automationUIListeners) {
+            if (automationUIListeners.size() > 0 && null != resourceURI) {
+                IAutomationUIListener listener;
+                Iterator<IAutomationUIListener> listenerItr = automationUIListeners
+                        .iterator();
+                while (listenerItr.hasNext()) {
+                    listener = listenerItr.next();
+                    if (null != listener) {
+                        listener.onAutomationComplete(resourceURI, attName);
+                    }
+                }
+            }
+        }
+    }
+
+    public List<String> getResourceTypeList() {
         List<String> typeList = null;
-        if (null != resourceMap && resourceMap.size() > 0) {
-            typeList = new ArrayList<String>();
-            Set<String> typeSet = resourceMap.keySet();
-            Iterator<String> typeItr = typeSet.iterator();
-            while (typeItr.hasNext()) {
-                typeList.add(typeItr.next());
+        synchronized (resourceMap) {
+            if (resourceMap.size() > 0) {
+                typeList = new ArrayList<String>();
+                Set<String> typeSet = resourceMap.keySet();
+                Iterator<String> typeItr = typeSet.iterator();
+                while (typeItr.hasNext()) {
+                    typeList.add(typeItr.next());
+                }
             }
         }
         return typeList;
     }
-}
+
+    public boolean isTypeExist(String resType) {
+        synchronized (resourceMap) {
+            if (resourceMap.containsKey(resType)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public List<String> getURIListOfResourceType(String type) {
+        List<String> uriList = null;
+        synchronized (resourceMap) {
+            if (null != type) {
+                Map<String, SimulatorResource> typeMap = resourceMap.get(type);
+                if (null != typeMap) {
+                    Set<String> keySet = typeMap.keySet();
+                    uriList = new ArrayList<String>();
+                    Iterator<String> keyItr = keySet.iterator();
+                    while (keyItr.hasNext()) {
+                        uriList.add(keyItr.next());
+                    }
+                }
+            }
+        }
+        return uriList;
+    }
+
+    public void resourceSelectionChanged(final String selectedItem) {
+        new Thread() {
+            @Override
+            public void run() {
+                // Check whether the item selected is a resource or resource
+                // category
+                if (isTypeExist(selectedItem)) {
+                    // Given item is a resource Type
+                    setCurrentResourceInSelection(null);
+                } else {
+                    // Given item is a resource URI
+                    SimulatorResource resource = getSimulatorResourceByURI(selectedItem);
+                    if (null != resource) {
+                        setCurrentResourceInSelection(resource);
+                    } else {
+                        setCurrentResourceInSelection(null);
+                    }
+                }
+                // Notify all observers for resource selection change event
+                resourceSelectionChangedUINotification();
+            }
+        }.start();
+    }
+
+    public List<MetaProperty> getMetaProperties(SimulatorResource resource) {
+        if (null != resource) {
+            String propName;
+            String propValue;
+
+            List<MetaProperty> metaPropertyList = new ArrayList<MetaProperty>();
+
+            for (int index = 0; index < Constants.META_PROPERTY_COUNT; index++) {
+                propName = Constants.META_PROPERTIES[index];
+                if (propName.equals(Constants.RESOURCE_URI)) {
+                    propValue = resource.getResourceURI();
+                } else if (propName.equals(Constants.RESOURCE_TYPE)) {
+                    propValue = resource.getResourceType();
+                } else if (propName.equals(Constants.RESOURCE_UID)) {
+                    // propValue = resource.getResourceUID();
+                    propValue = "Dummy123"; // Temporarily adding dummy value to
+                    // see in UI
+                } else if (propName.equals(Constants.CONNECTIVITY_TYPE)) {
+                    // propValue = resource.getConnectivityType();
+                    propValue = "IP"; // Temporarily adding dummy value to see
+                    // in UI
+                } else {
+                    propValue = null;
+                }
+                if (null != propValue) {
+                    metaPropertyList.add(new MetaProperty(propName, propValue));
+                }
+            }
+
+            return metaPropertyList;
+        }
+        return null;
+    }
+
+    public List<ResourceAttribute> getAttributes(SimulatorResource resource) {
+        List<ResourceAttribute> attList = null;
+        if (null != resource) {
+            Map<String, ResourceAttribute> attMap = resource
+                    .getResourceAttributesMap();
+            if (null != attMap && attMap.size() > 0) {
+                attList = new ArrayList<ResourceAttribute>();
+                Set<String> attNameSet = attMap.keySet();
+                String attName;
+                ResourceAttribute attribute;
+                // ResourceAttribute attributeClone;
+                Iterator<String> attNameItr = attNameSet.iterator();
+                while (attNameItr.hasNext()) {
+                    attName = attNameItr.next();
+                    attribute = attMap.get(attName);
+                    if (null != attribute) {
+                        // attributeClone =
+                        // ResourceAttribute.clone(attribute);
+                        attList.add(attribute);
+                    }
+                }
+            }
+        }
+        return attList;
+    }
+
+    public void attributeValueUpdated(SimulatorResource resource,
+            String attributeName, String value) {
+        if (null != resource && null != attributeName && null != value) {
+            SimulatorResourceServer server = resource.getResourceServer();
+            if (null != server) {
+                server.updateAttributeStringN(attributeName, value);
+            }
+        }
+    }
+
+    private ModelChangeNotificationType compareAndUpdateLocalAttributes(
+            Map<String, ResourceAttribute> resourceAttributeMapOld,
+            Map<String, ResourceAttribute> resourceAttributeMapNew) {
+        ModelChangeNotificationType notificationType = ModelChangeNotificationType.NONE;
+        if (null != resourceAttributeMapOld && null != resourceAttributeMapNew) {
+            Set<String> oldMapKeySet = resourceAttributeMapOld.keySet();
+            Iterator<String> attributeMapOldItr = oldMapKeySet.iterator();
+            String attName;
+            ResourceAttribute attributeOld;
+            ResourceAttribute attributeNew;
+            Object attValueOld;
+            Object attValueNew;
+            String oldValueStr;
+            String newValueStr;
+            while (attributeMapOldItr.hasNext()) {
+                attName = attributeMapOldItr.next();
+                if (resourceAttributeMapNew.containsKey(attName)) {
+                    attributeOld = resourceAttributeMapOld.get(attName);
+                    attributeNew = resourceAttributeMapNew.get(attName);
+                    // Copy the attribute value from new to old if the value
+                    // has been changed
+                    // Comparing only the attribute's value considering the
+                    // fact that only the value can be changed
+                    if (null != attributeOld && null != attributeNew) {
+                        attValueOld = attributeOld.getAttributeValue();
+                        attValueNew = attributeNew.getAttributeValue();
+
+                        oldValueStr = String.valueOf(attValueOld);
+                        newValueStr = String.valueOf(attValueNew);
+
+                        if (null != oldValueStr && null != newValueStr) {
+                            if (!oldValueStr.equals(newValueStr)) {
+                                attributeOld.setAttributeValue(attValueNew);
+                                notificationType = ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED;
+                            }
+                        }
+                    }
+                    resourceAttributeMapNew.remove(attName);
+                } else {
+                    // Attribute doesn't exist in the new model. Hence
+                    // removing it from the model.
+                    resourceAttributeMapOld.remove(attName);
+                    notificationType = ModelChangeNotificationType.ATTRIBUTE_REMOVED;
+                }
+            }
+            // Check for new attributes in the new model
+            if (resourceAttributeMapNew.size() > 0) {
+                Set<String> remainingAttSet = resourceAttributeMapNew.keySet();
+                Iterator<String> remainingAttItr = remainingAttSet.iterator();
+                ResourceAttribute attribute;
+                while (remainingAttItr.hasNext()) {
+                    attName = remainingAttItr.next();
+                    if (null != attName) {
+                        attribute = resourceAttributeMapNew.get(attName);
+                        if (null != attribute) {
+                            resourceAttributeMapOld.put(attName, attribute);
+                        }
+                    }
+                }
+                notificationType = ModelChangeNotificationType.ATTRIBUTE_ADDED;
+            }
+        }
+        return notificationType;
+    }
+
+    public int startAutomation(SimulatorResource resource,
+            ResourceAttribute attribute, AutomationType autoType,
+            int autoUpdateInterval) {
+        int autoId = -1;
+        if (null != resource && null != attribute) {
+            SimulatorResourceServer resourceServerN = resource
+                    .getResourceServer();
+            if (null != resourceServerN) {
+                String attrName = attribute.getAttributeName();
+                autoId = resourceServerN.startAttributeAutomation(attrName,
+                        autoType.ordinal(), automationListener);
+                if (-1 != autoId) {
+                    attribute.setAutomationId(autoId);
+                } else {
+                    attribute.setAutomationInProgress(false);
+                    resource.setAttributeAutomationInProgress(false);
+                }
+            }
+        }
+        return autoId;
+    }
+
+    public void stopAutomation(SimulatorResource resource, int autoId) {
+        if (null != resource) {
+            SimulatorResourceServer resourceServerN = resource
+                    .getResourceServer();
+            if (null != resourceServerN) {
+                resourceServerN.stopAutomation(autoId);
+            }
+        }
+    }
+
+    private ResourceAttribute getAttributeWithGivenAutomationId(
+            SimulatorResource resource, int automationId) {
+        ResourceAttribute targetAttribute = null;
+        if (null != resource) {
+            Map<String, ResourceAttribute> attributeMap = resource
+                    .getResourceAttributesMap();
+            if (null != attributeMap) {
+                Set<String> attNameSet = attributeMap.keySet();
+                Iterator<String> attNameItr = attNameSet.iterator();
+                String attName;
+                ResourceAttribute attribute;
+                while (attNameItr.hasNext()) {
+                    attName = attNameItr.next();
+                    if (null != attName) {
+                        attribute = attributeMap.get(attName);
+                        if (null != attribute) {
+                            if (attribute.isAutomationInProgress()
+                                    && (attribute.getAutomationId() == automationId)) {
+                                targetAttribute = attribute;
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return targetAttribute;
+    }
+
+    public boolean startResourceAutomationUIRequest(final String resourceURI) {
+        if (null == resourceURI) {
+            return false;
+        }
+        boolean status = false;
+        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+        if (null != resource) {
+            changeResourceLevelAutomationStatus(resource, true);
+
+            // Invoke the native automation method
+            SimulatorResourceServer resourceServer = resource
+                    .getResourceServer();
+            if (null != resourceServer) {
+                // TODO: Temporarily handling the normal one-time automation for
+                // resources
+                int autoId = resourceServer.startResourceAutomation(
+                        AutomationType.NORMAL.ordinal(), automationListener);
+                if (-1 == autoId) {
+                    // Automation request failed and hence status is being
+                    // rolled back
+                    changeResourceLevelAutomationStatus(resource, false);
+                } else {
+                    // Automation request accepted.
+                    resource.setAutomationId(autoId);
+
+                    // Notify the UI listeners in a different thread.
+                    Thread notifyThread = new Thread() {
+                        public void run() {
+                            resourceAutomationStartedUINotification(resourceURI);
+                        };
+                    };
+                    notifyThread.setPriority(Thread.MAX_PRIORITY);
+                    notifyThread.start();
+
+                    status = true;
+                }
+            }
+        }
+        return status;
+    }
+
+    public void stopResourceAutomationUIRequest(final String resourceURI) {
+        Thread stopThread = new Thread() {
+            public void run() {
+                SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+                if (null == resource) {
+                    return;
+                }
+                int autoId = resource.getAutomationId();
+                if (-1 == autoId) {
+                    return;
+                }
+                SimulatorResourceServer resourceServer = resource
+                        .getResourceServer();
+                if (null == resourceServer) {
+                    return;
+                }
+                // Call native method
+                resourceServer.stopAutomation(autoId);
+
+                // Invoke the automation complete callback
+                automationListener.onAutomationComplete(resourceURI, autoId);
+            }
+        };
+        stopThread.start();
+    }
+
+    // Changes the automation state of the resource and its attributes
+    private void changeResourceLevelAutomationStatus(
+            SimulatorResource resource, boolean status) {
+
+        Map<String, ResourceAttribute> attributeMap = resource
+                .getResourceAttributesMap();
+        if (null != attributeMap) {
+            Set<String> attrNameSet = attributeMap.keySet();
+            Iterator<String> attrNameItr = attrNameSet.iterator();
+            String attrName;
+            ResourceAttribute attribute;
+            while (attrNameItr.hasNext()) {
+                attrName = attrNameItr.next();
+                attribute = attributeMap.get(attrName);
+                if (null != attribute) {
+                    attribute.setAutomationInProgress(status);
+                }
+            }
+        }
+        resource.setResourceAutomationInProgress(status);
+    }
+
+    public boolean isResourceAutomationStarted(String resourceURI) {
+        boolean status = false;
+        if (null == resourceURI) {
+            return status;
+        }
+
+        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+        if (null != resource) {
+            status = resource.isResourceAutomationInProgress();
+        }
+        return status;
+    }
+
+    public boolean isAttributeAutomationStarted(String resourceURI) {
+        boolean status = false;
+        if (null == resourceURI) {
+            return status;
+        }
+        SimulatorResource resource = getSimulatorResourceByURI(resourceURI);
+        if (null != resource) {
+            status = resource.isAttributeAutomationInProgress();
+        }
+        return status;
+    }
+
+    public void shutdown() {
+        threadHandle.interrupt();
+    }
+}
\ No newline at end of file
index 8c21587..cb8954e 100644 (file)
@@ -2,6 +2,7 @@ package oic.simulator.serviceprovider.perspective;
 
 import oic.simulator.serviceprovider.view.AttributeView;
 import oic.simulator.serviceprovider.view.LogView;
+import oic.simulator.serviceprovider.view.MetaPropertiesView;
 import oic.simulator.serviceprovider.view.MultiResourceOrchestrationView;
 import oic.simulator.serviceprovider.view.ResourceManagerView;
 
@@ -24,13 +25,13 @@ public class PerspectiveFactory implements IPerspectiveFactory {
     private void addViews() {
         factory.addView(ResourceManagerView.VIEW_ID, IPageLayout.LEFT, 0.3f,
                 factory.getEditorArea());
-        factory.addView(IPageLayout.ID_PROP_SHEET, IPageLayout.BOTTOM, 0.6f,
+        factory.addView(MetaPropertiesView.VIEW_ID, IPageLayout.BOTTOM, 0.65f,
                 ResourceManagerView.VIEW_ID);
-        factory.addView(AttributeView.VIEW_ID, IPageLayout.LEFT, 0.5f,
+        factory.addView(AttributeView.VIEW_ID, IPageLayout.LEFT, 0.7f,
                 factory.getEditorArea());
-        factory.addView(LogView.VIEW_ID, IPageLayout.BOTTOM, 0.6f,
+        factory.addView(LogView.VIEW_ID, IPageLayout.BOTTOM, 0.65f,
                 AttributeView.VIEW_ID);
         factory.addView(MultiResourceOrchestrationView.VIEW_ID,
-                IPageLayout.RIGHT, 0.5f, AttributeView.VIEW_ID);
+                IPageLayout.RIGHT, 0.6f, AttributeView.VIEW_ID);
     }
-}
+}
\ No newline at end of file
index f6aeff5..5798035 100644 (file)
@@ -1,6 +1,6 @@
 package oic.simulator.serviceprovider.resource;
 
-// TODO: Temporarily adding this enum in plugin. It will be removed once it is added to the java api sdk 
+// TODO: Temporarily adding this enum in plug-in. It will be removed once it is added to the java api sdk 
 public enum AttributeValueType {
-    INTEGER, DOUBLE, STRING, BOOLEAN, ENUMERATION
-}
+    INTEGER, DOUBLE, STRING, BOOLEAN
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/AutomationSettingHelper.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/AutomationSettingHelper.java
new file mode 100644 (file)
index 0000000..0d0d9eb
--- /dev/null
@@ -0,0 +1,111 @@
+package oic.simulator.serviceprovider.resource;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import oic.simulator.serviceprovider.utils.Constants;
+
+import org.oic.simulator.AutomationType;
+
+public class AutomationSettingHelper {
+    private String       settingID;
+    private String       settingValue;
+    private List<String> allowedValues;
+
+    public String getSettingID() {
+        return settingID;
+    }
+
+    public void setSettingID(String settingID) {
+        this.settingID = settingID;
+    }
+
+    public String getSettingValue() {
+        return settingValue;
+    }
+
+    public void setSettingValue(String settingValue) {
+        this.settingValue = settingValue;
+    }
+
+    public List<String> getAllowedValues() {
+        return allowedValues;
+    }
+
+    public void setAllowedValues(List<String> allowedValues) {
+        this.allowedValues = allowedValues;
+    }
+
+    public void addAllowedValue(String newText) {
+        if (null != allowedValues) {
+            allowedValues.add(newText);
+        }
+    }
+
+    public static List<AutomationSettingHelper> getAutomationSettings(
+            ResourceAttribute attribute) {
+        List<AutomationSettingHelper> settingList = null;
+        boolean invalidSetting;
+        if (null != attribute) {
+            settingList = new ArrayList<AutomationSettingHelper>();
+            for (int count = 0; count < Constants.AUTOMATION_SETTINGS_COUNT; count++) {
+                invalidSetting = false;
+                AutomationSettingHelper setting = new AutomationSettingHelper();
+                if (Constants.AUTOMATION_SETTINGS[count]
+                        .equals(Constants.AUTOMATION)) {
+                    setting.setSettingID(Constants.AUTOMATION);
+                    setting.setSettingValue(attribute.isAutomationInProgress() ? Constants.ENABLE
+                            : Constants.DISABLE);
+                    List<String> valueList = new ArrayList<String>();
+                    valueList.add(Constants.ENABLE);
+                    valueList.add(Constants.DISABLE);
+                    setting.setAllowedValues(valueList);
+                } else if (Constants.AUTOMATION_SETTINGS[count]
+                        .equals(Constants.AUTOMATION_TYPE)) {
+                    setting.setSettingID(Constants.AUTOMATION_TYPE);
+                    setting.setSettingValue(attribute.getAutomationType()
+                            .toString());
+                    List<String> valueList = new ArrayList<String>();
+                    valueList.add(AutomationType.NORMAL.toString());
+                    valueList.add(AutomationType.RECURRENT.toString());
+                    setting.setAllowedValues(valueList);
+                } else if (Constants.AUTOMATION_SETTINGS[count]
+                        .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
+                    setting.setSettingID(Constants.UPDATE_INTERVAL_IN_MS);
+                    setting.setSettingValue(String.valueOf(attribute
+                            .getAutomationUpdateInterval()));
+                    List<String> valueList = new ArrayList<String>();
+                    for (int index = 1; index <= 10; index++) {
+                        valueList.add(String.valueOf(index * 500));
+                    }
+                    setting.setAllowedValues(valueList);
+                } else {
+                    invalidSetting = true;
+                }
+                if (!invalidSetting) {
+                    settingList.add(setting);
+                }
+            }
+        }
+        return settingList;
+    }
+
+    public static void updateAutomationStatus(
+            List<AutomationSettingHelper> localSettingList, String status) {
+        if (null != localSettingList && null != status) {
+            Iterator<AutomationSettingHelper> settingItr = localSettingList
+                    .iterator();
+            AutomationSettingHelper setting;
+            while (settingItr.hasNext()) {
+                setting = settingItr.next();
+                if (null != setting) {
+                    if (setting.getSettingID().equals(Constants.AUTOMATION)) {
+                        setting.setSettingValue(status);
+                        break;
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/MetaProperty.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/MetaProperty.java
new file mode 100644 (file)
index 0000000..bff71e7
--- /dev/null
@@ -0,0 +1,27 @@
+package oic.simulator.serviceprovider.resource;
+
+public class MetaProperty {
+    private String propName;
+    private String propValue;
+
+    public MetaProperty(String propName, String propValue) {
+        this.propName = propName;
+        this.propValue = propValue;
+    }
+
+    public String getPropValue() {
+        return propValue;
+    }
+
+    public void setPropValue(String propValue) {
+        this.propValue = propValue;
+    }
+
+    public String getPropName() {
+        return propName;
+    }
+
+    public void setPropName(String propName) {
+        this.propName = propName;
+    }
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ModelChangeNotificationType.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/resource/ModelChangeNotificationType.java
new file mode 100644 (file)
index 0000000..64deda9
--- /dev/null
@@ -0,0 +1,5 @@
+package oic.simulator.serviceprovider.resource;
+
+public enum ModelChangeNotificationType {
+    ATTRIBUTE_ADDED, ATTRIBUTE_REMOVED, ATTRIBUTE_VALUE_CHANGED, NONE
+}
\ No newline at end of file
index 979dcc0..02b0fab 100644 (file)
@@ -1,8 +1,13 @@
 package oic.simulator.serviceprovider.resource;
 
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
-import org.iotivity.simulator.SimulatorResourceAttribute;
+import org.oic.simulator.AutomationType;
+import org.oic.simulator.SimulatorResourceAttribute;
 
 public class ResourceAttribute {
 
@@ -17,6 +22,14 @@ public class ResourceAttribute {
     private Object                     minValue;
     private Object                     maxValue;
 
+    private int                        automationId;
+
+    private boolean                    automationInProgress;
+
+    private int                        automationUpdateInterval;
+
+    private AutomationType             automationType;
+
     public SimulatorResourceAttribute getResourceAttribute() {
         return resourceAttribute;
     }
@@ -58,6 +71,17 @@ public class ResourceAttribute {
         this.allowedValues = allowedValues;
     }
 
+    public void setAllowedValues(String[] allowedValues) {
+        List<Object> allowedValueList = null;
+        if (null != allowedValues && allowedValues.length > 0) {
+            allowedValueList = new ArrayList<Object>();
+            for (String value : allowedValues) {
+                allowedValueList.add(value);
+            }
+        }
+        this.allowedValues = allowedValueList;
+    }
+
     public Object getMinValue() {
         return minValue;
     }
@@ -73,4 +97,85 @@ public class ResourceAttribute {
     public void setMaxValue(Object maxValue) {
         this.maxValue = maxValue;
     }
-}
+
+    public boolean isAutomationInProgress() {
+        return automationInProgress;
+    }
+
+    public void setAutomationInProgress(boolean automationInProgress) {
+        this.automationInProgress = automationInProgress;
+    }
+
+    public int getAutomationUpdateInterval() {
+        return automationUpdateInterval;
+    }
+
+    public void setAutomationUpdateInterval(int automationUpdateInterval) {
+        this.automationUpdateInterval = automationUpdateInterval;
+    }
+
+    public AutomationType getAutomationType() {
+        return automationType;
+    }
+
+    public void setAutomationType(AutomationType automationType) {
+        this.automationType = automationType;
+    }
+
+    public int getAutomationId() {
+        return automationId;
+    }
+
+    public void setAutomationId(int automationId) {
+        this.automationId = automationId;
+    }
+
+    public static ResourceAttribute clone(ResourceAttribute attribute) {
+        ResourceAttribute clone = null;
+        if (null != attribute) {
+            clone = new ResourceAttribute();
+            clone.setAttributeName(attribute.getAttributeName());
+            clone.setAttributeValue(attribute.getAttributeValue());
+            clone.setAllowedValues(attribute.getAllowedValues());
+            clone.setAttributeType(attribute.getAttributeType());
+            clone.setMinValue(attribute.getMinValue());
+            clone.setMaxValue(attribute.getMaxValue());
+            clone.setAutomationInProgress(attribute.isAutomationInProgress());
+            clone.setAutomationType(attribute.getAutomationType());
+            clone.setAutomationUpdateInterval(attribute
+                    .getAutomationUpdateInterval());
+            clone.setResourceAttribute(null);
+        }
+        return clone;
+    }
+
+    // This method gives all known possible values of the attribute
+    // It takes allowed values or range of values whichever is available
+    public Set<Object> getValues() {
+        Set<Object> valueList = new HashSet<Object>();
+        if (null != allowedValues) {
+            Iterator<Object> values = allowedValues.iterator();
+            while (values.hasNext()) {
+                valueList.add(values.next());
+            }
+        } else if (null != minValue && null != maxValue) {
+            if (attributeValue.getClass() == Integer.class) {
+                int min = (Integer) minValue;
+                int max = (Integer) maxValue;
+                for (int value = min; value <= max; value++) {
+                    valueList.add(value);
+                }
+            } else if (attributeValue.getClass() == Double.class) {
+                double min = (Double) minValue;
+                double max = (Double) maxValue;
+                for (double value = min; value <= max; value++) {
+                    valueList.add(value);
+                }
+            }
+        }
+        if (valueList.size() < 1) {
+            valueList.add(attributeValue);
+        }
+        return valueList;
+    }
+}
\ No newline at end of file
index 5d383ff..f1f5171 100644 (file)
@@ -2,8 +2,9 @@ package oic.simulator.serviceprovider.resource;
 
 import java.util.Map;
 
-import org.iotivity.simulator.SimulatorResourceModel;
-import org.iotivity.simulator.SimulatorResourceServer;
+import org.oic.simulator.AutomationType;
+import org.oic.simulator.serviceprovider.SimulatorResourceModel;
+import org.oic.simulator.serviceprovider.SimulatorResourceServer;
 
 public class SimulatorResource {
     private String                         resourceURI;
@@ -11,11 +12,20 @@ public class SimulatorResource {
     private String                         resourceType;
     private String                         resourceInterface;
 
-    // Reference to objects created in native layer
-    // Native methods can be invoked using these object references
+    // Native Object references
     private SimulatorResourceServer        resourceServer;
     private SimulatorResourceModel         resourceModel;
 
+    private int                            automationId;
+
+    private boolean                        resourceAutomationInProgress;
+
+    private boolean                        attributeAutomationInProgress;
+
+    private int                            automationUpdateInterval;
+
+    private AutomationType                 automationType;
+
     private Map<String, ResourceAttribute> resourceAttributesMap;
 
     public String getResourceURI() {
@@ -75,4 +85,45 @@ public class SimulatorResource {
         this.resourceAttributesMap = resourceAttributesMap;
     }
 
-}
+    public int getAutomationUpdateInterval() {
+        return automationUpdateInterval;
+    }
+
+    public void setAutomationUpdateInterval(int automationUpdateInterval) {
+        this.automationUpdateInterval = automationUpdateInterval;
+    }
+
+    public AutomationType getAutomationType() {
+        return automationType;
+    }
+
+    public void setAutomationType(AutomationType automationType) {
+        this.automationType = automationType;
+    }
+
+    public int getAutomationId() {
+        return automationId;
+    }
+
+    public void setAutomationId(int automationId) {
+        this.automationId = automationId;
+    }
+
+    public boolean isResourceAutomationInProgress() {
+        return resourceAutomationInProgress;
+    }
+
+    public void setResourceAutomationInProgress(
+            boolean resourceAutomationInProgress) {
+        this.resourceAutomationInProgress = resourceAutomationInProgress;
+    }
+
+    public boolean isAttributeAutomationInProgress() {
+        return attributeAutomationInProgress;
+    }
+
+    public void setAttributeAutomationInProgress(
+            boolean attributeAutomationInProgress) {
+        this.attributeAutomationInProgress = attributeAutomationInProgress;
+    }
+}
\ No newline at end of file
index d6e3333..2695713 100644 (file)
@@ -8,8 +8,7 @@ public class StandardConfiguration {
     private String      configuration_directory_path;
 
     // A map of resourceType of standard resources as the key and the complete
-    // location of the file as
-    // the value
+    // location of the file as the value
     Map<String, String> standardResourceConfigurationMap;
 
     public StandardConfiguration() {
@@ -55,4 +54,4 @@ public class StandardConfiguration {
             standardResourceConfigurationMap.remove(resourceType);
         }
     }
-}
+}
\ No newline at end of file
index 1cf302d..14d0b5a 100644 (file)
@@ -1,10 +1,72 @@
 package oic.simulator.serviceprovider.utils;
 
+import org.oic.simulator.AutomationType;
+
 public class Constants {
-    public static final String UNDERSCORE                      = "_";
-    public static final String FORWARD_SLASH                   = "/";
-    public static final String OIC                             = "oic";
-    public static final String SIMULATOR                       = "simulator";
+    public static final String         UNDERSCORE                       = "_";
+    public static final String         FORWARD_SLASH                    = "/";
+
+    public static final String         OIC                              = "oic";
+    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_UID                     = "Resource ID";
+    public static final String         CONNECTIVITY_TYPE                = "Connectivity Type";
+
+    public static final String[]       META_PROPERTIES                  = {
+            RESOURCE_URI, RESOURCE_TYPE, RESOURCE_UID, CONNECTIVITY_TYPE };
+
+    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         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, AUTOMATION_TYPE, UPDATE_INTERVAL_IN_MS         };
+
+    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 int            PROPER_RESOURCE_URI_TOKEN_COUNT  = 5;
+    public static final int            DISPLAY_RESOURCE_URI_TOKEN_COUNT = 2;
+
+    public static final AutomationType DEFAULT_AUTOMATION_TYPE          = AutomationType.NORMAL;
+
+    public static final int            DEFAULT_AUTOMATION_INTERVAL      = 500;
+
+    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 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                             = "Info";
+    public static final String         WARNING                          = "Warning";
+    public static final String         ERROR                            = "Error";
+    public static final String         DEBUG                            = "Debug";
+    public static final String         UNKNOWN                          = "Unknown";
+
+    public static final String         CREATE_PAGE_TITLE                = "Create Resource";
+    public static final String         CREATE_PAGE_MESSAGE              = "Select a standard resource or custom resource to be created";
 
-    public static final int    PROPER_RESOURCE_URI_TOKEN_COUNT = 5;
-}
+    public static final String         DELETE_PAGE_TITLE                = "Delete Resource";
+    public static final String         DELETE_PAGE_MESSAGE              = "Select the resource(s) to be deleted";
+}
\ No newline at end of file
@@ -1,13 +1,11 @@
 package oic.simulator.serviceprovider.utils;
 
-public class Convertion {
+public class Utility {
 
     public static String uriToDisplayName(String uri) {
         String result = null;
         if (null != uri) {
             String tokens[] = uri.split(Constants.FORWARD_SLASH);
-            System.out.println(uri);
-            System.out.println(tokens.length);
             if (Constants.PROPER_RESOURCE_URI_TOKEN_COUNT == tokens.length) {
                 // Proper URI
                 result = tokens[2] + Constants.UNDERSCORE + tokens[4];
@@ -20,7 +18,7 @@ public class Convertion {
         String result = null;
         if (null != displayName) {
             String tokens[] = displayName.split(Constants.UNDERSCORE);
-            if (2 == tokens.length) {
+            if (Constants.DISPLAY_RESOURCE_URI_TOKEN_COUNT == tokens.length) {
                 // Proper Display Name
                 result = Constants.FORWARD_SLASH + Constants.OIC
                         + Constants.FORWARD_SLASH + tokens[0]
@@ -35,12 +33,47 @@ public class Convertion {
         boolean uriComplete = false;
         if (null != uri) {
             String tokens[] = uri.split(Constants.FORWARD_SLASH);
-            System.out.println(uri);
-            System.out.println(tokens.length);
             if (Constants.PROPER_RESOURCE_URI_TOKEN_COUNT == tokens.length) {
                 uriComplete = true;
             }
         }
         return uriComplete;
     }
-}
+
+    public static String getAutomationStatus(boolean status) {
+        if (status) {
+            return Constants.ENABLED;
+        } else {
+            return Constants.DISABLED;
+        }
+    }
+
+    public static String getAutomationString(boolean status) {
+        if (status) {
+            return Constants.ENABLE;
+        } else {
+            return Constants.DISABLE;
+        }
+    }
+
+    public static boolean getAutomationBoolean(String status) {
+        if (null != status) {
+            if (status.equals(Constants.ENABLE)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static int getUpdateIntervalFromString(String value) {
+        int result = Constants.DEFAULT_AUTOMATION_INTERVAL;
+        if (null != value) {
+            try {
+                result = Integer.parseInt(value);
+            } catch (NumberFormatException nfe) {
+                // Do nothing
+            }
+        }
+        return result;
+    }
+}
\ No newline at end of file
index 932fe27..ec47066 100644 (file)
 package oic.simulator.serviceprovider.view;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.listener.IAutomationUIListener;
+import oic.simulator.serviceprovider.listener.IResourceModelChangedUIListener;
+import oic.simulator.serviceprovider.listener.IResourceSelectionChangedUIListener;
+import oic.simulator.serviceprovider.manager.ResourceManager;
+import oic.simulator.serviceprovider.resource.AutomationSettingHelper;
+import oic.simulator.serviceprovider.resource.ModelChangeNotificationType;
+import oic.simulator.serviceprovider.resource.ResourceAttribute;
+import oic.simulator.serviceprovider.resource.SimulatorResource;
+import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
+
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CellLabelProvider;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Point;
+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.Table;
 import org.eclipse.ui.part.ViewPart;
+import org.oic.simulator.AutomationType;
 
 public class AttributeView extends ViewPart {
 
-    public static final String VIEW_ID = "oic.simulator.serviceprovider.view.attribute";
+    public static final String                  VIEW_ID            = "oic.simulator.serviceprovider.view.attribute";
+
+    private TableViewer                         attTblViewer;
+    private TableViewer                         automtnSettingsTblViewer;
+
+    private IResourceSelectionChangedUIListener resourceSelectionChangedListener;
+    private IResourceModelChangedUIListener     resourceModelChangedUIListener;
+    private IAutomationUIListener               automationUIListener;
+
+    private Label                               newValueLbl;
+    private CCombo                              valueCmb;
+    private Button                              submitButton;
+    private Button                              clearButton;
+
+    private ResourceAttribute                   attributeInSelection;
+    private AttributeAutomationSettingEditor    automationSettingEditor;
+    private List<AutomationSettingHelper>       localSettingList;
+
+    private final String[]                      attTblHeaders      = { "Name",
+            "Value", "Automation Status"                          };
+    private final String[]                      settingTblHeaders  = {
+            "Setting", "Value"                                    };
+    private final Integer[]                     attTblColWidth     = { 150,
+            190, 150                                              };
+    private final Integer[]                     settingTblColWidth = { 140, 85 };
+
+    private ResourceManager                     resourceManager;
+
+    public AttributeView() {
+
+        resourceManager = Activator.getDefault().getResourceManager();
+
+        resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() {
+
+            @Override
+            public void onResourceSelectionChange() {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        if (null != attTblViewer) {
+                            updateViewer(checkSelection());
+                        }
+                    }
+                });
+            }
+        };
+
+        resourceModelChangedUIListener = new IResourceModelChangedUIListener() {
+
+            @Override
+            public void onResourceModelChange(
+                    final ModelChangeNotificationType notificationType,
+                    final String resourceURI) {
+                Display.getDefault().asyncExec(new Runnable() {
+                    @Override
+                    public void run() {
+                        // Handle the notification only if it is for the current
+                        // resource in selection
+                        SimulatorResource resource = resourceManager
+                                .getCurrentResourceInSelection();
+                        if (null == resource) {
+                            return;
+                        }
+                        if (!resourceURI.equals(resource.getResourceURI())) {
+                            return;
+                        }
+                        // Refresh the table viewers which will display
+                        // the updated values
+                        if (null != attTblViewer) {
+                            attTblViewer.refresh();
+                        }
+                        // If this call has a new value for the current
+                        // attribute
+                        // in selection, then update it in the combo box
+                        if (notificationType != ModelChangeNotificationType.ATTRIBUTE_VALUE_CHANGED) {
+                            return;
+                        }
+                        if (null != valueCmb && !valueCmb.isDisposed()
+                                && null != attributeInSelection) {
+                            Map<String, ResourceAttribute> attributeMap = resource
+                                    .getResourceAttributesMap();
+                            if (null != attributeMap) {
+                                ResourceAttribute attribute = attributeMap
+                                        .get(attributeInSelection
+                                                .getAttributeName());
+                                if (null != attribute) {
+                                    Object valueObj = attribute
+                                            .getAttributeValue();
+                                    if (null != valueObj) {
+                                        String valueStr = String
+                                                .valueOf(valueObj);
+                                        int index = valueCmb.indexOf(valueStr);
+                                        if (index != -1) {
+                                            valueCmb.select(index);
+                                        } else {
+                                            valueCmb.add(valueStr);
+                                            valueCmb.select(valueCmb
+                                                    .indexOf(valueStr));
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                });
+            }
+        };
+
+        automationUIListener = new IAutomationUIListener() {
+
+            @Override
+            public void onResourceAutomationStart(final String resourceURI) {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        if (null == resourceURI) {
+                            return;
+                        }
+                        SimulatorResource resource = resourceManager
+                                .getCurrentResourceInSelection();
+                        if (null == resource) {
+                            return;
+                        }
+                        String uri = resource.getResourceURI();
+                        // Checking whether attributes view is currently
+                        // displaying the attributes of the
+                        // resource whose automation has just started
+                        if (null != uri && uri.equals(resourceURI)) {
+                            Table tbl;
+                            tbl = attTblViewer.getTable();
+                            if (!tbl.isDisposed()) {
+                                attTblViewer.refresh();
+                            }
+
+                            // If any attribute is in selection, then update
+                            // the automation setting to enable.
+                            if (null != attributeInSelection) {
+                                tbl = automtnSettingsTblViewer.getTable();
+                                if (!tbl.isDisposed()) {
+                                    // Change the local automation settings
+                                    AutomationSettingHelper
+                                            .updateAutomationStatus(
+                                                    localSettingList,
+                                                    Constants.ENABLE);
+                                    automtnSettingsTblViewer.refresh();
+                                }
+                            }
+
+                            // Disable the manual change UI controls
+                            setVisibilityForManualValueChange(false);
+                        }
+                    }
+                });
+            }
+
+            @Override
+            public void onAutomationComplete(final String resourceURI,
+                    final String attName) {
+                // This method notifies the completion of attribute level
+                // automation.
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        if (null == resourceURI) {
+                            return;
+                        }
+                        // Check if the given resourceURI is the uri of the
+                        // resource whose attributes are currently being
+                        // displayed by this view.
+                        SimulatorResource resource = resourceManager
+                                .getCurrentResourceInSelection();
+                        if (null == resource) {
+                            return;
+                        }
+                        String uri = resource.getResourceURI();
+                        if (null != uri && uri.equals(resourceURI)) {
+                            Table tbl;
+                            tbl = attTblViewer.getTable();
+                            if (!tbl.isDisposed()) {
+                                attTblViewer.refresh();
+                            }
+
+                            if (null != attributeInSelection) {
+                                if (null == attName
+                                        || attributeInSelection
+                                                .getAttributeName().equals(
+                                                        attName)) {
+                                    tbl = automtnSettingsTblViewer.getTable();
+                                    if (!tbl.isDisposed()) {
+                                        // Change the local automation settings
+                                        AutomationSettingHelper
+                                                .updateAutomationStatus(
+                                                        localSettingList,
+                                                        Constants.DISABLE);
+                                        automtnSettingsTblViewer.refresh();
+                                    }
+                                    setVisibilityForManualValueChange(true);
+                                }
+                            }
+                        }
+                    }
+                });
+            }
+        };
+    }
+
+    @Override
+    public void createPartControl(Composite parent) {
+        Color color = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
+
+        parent.setLayout(new GridLayout(2, false));
+        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        parent.setLayoutData(gd);
+
+        Group attGroup = new Group(parent, SWT.NONE);
+        attGroup.setLayout(new GridLayout(1, false));
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        gd.horizontalSpan = 2;
+        gd.minimumHeight = 175;
+        attGroup.setLayoutData(gd);
+        attGroup.setText("Attributes");
+        attGroup.setBackground(color);
+
+        attTblViewer = new TableViewer(attGroup, SWT.MULTI | SWT.H_SCROLL
+                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+
+        createAttributeColumns(attTblViewer);
+
+        // make lines and header visible
+        Table table = attTblViewer.getTable();
+        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        table.setHeaderVisible(true);
+        table.setLinesVisible(true);
+
+        attTblViewer.setContentProvider(new AttributeContentProvider());
+
+        Group automationSettingsTableGrp = new Group(parent, SWT.NONE);
+        automationSettingsTableGrp.setLayout(new GridLayout(1, false));
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        automationSettingsTableGrp.setLayoutData(gd);
+        automationSettingsTableGrp.setText("Automation Settings");
+        automationSettingsTableGrp.setBackground(color);
+
+        automtnSettingsTblViewer = new TableViewer(automationSettingsTableGrp,
+                SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION
+                        | SWT.BORDER);
+
+        createSettingColumns(automtnSettingsTblViewer);
+
+        // make lines visible
+        table = automtnSettingsTblViewer.getTable();
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        table.setLayoutData(gd);
+        table.setHeaderVisible(true);
+        table.setLinesVisible(true);
+
+        automtnSettingsTblViewer
+                .setContentProvider(new AttributeContentProvider());
+
+        Composite rightViewComp = new Composite(parent, SWT.NONE);
+        rightViewComp.setLayout(new GridLayout(1, false));
+
+        Group valueUpdateGroup = new Group(rightViewComp, SWT.NONE);
+        valueUpdateGroup.setLayout(new GridLayout(2, false));
+        gd = new GridData();
+        gd.horizontalAlignment = SWT.FILL;
+        gd.grabExcessHorizontalSpace = true;
+        gd.horizontalSpan = 2;
+        valueUpdateGroup.setLayoutData(gd);
+        valueUpdateGroup.setText("Change Attribute Value");
+        valueUpdateGroup.setBackground(color);
+
+        newValueLbl = new Label(valueUpdateGroup, SWT.NONE);
+        newValueLbl.setText("Select New Value");
+
+        valueCmb = new CCombo(valueUpdateGroup, SWT.BORDER);
+        gd = new GridData();
+        gd.widthHint = 100;
+        valueCmb.setLayoutData(gd);
+
+        submitButton = new Button(rightViewComp, SWT.PUSH);
+        gd = new GridData();
+        gd.widthHint = 150;
+        gd.verticalIndent = 10;
+        gd.horizontalSpan = 2;
+        gd.horizontalAlignment = SWT.CENTER;
+        submitButton.setLayoutData(gd);
+        submitButton.setText("Apply Changes");
+
+        clearButton = new Button(rightViewComp, SWT.PUSH);
+        gd = new GridData();
+        gd.widthHint = 150;
+        gd.verticalIndent = 10;
+        gd.horizontalSpan = 2;
+        gd.horizontalAlignment = SWT.CENTER;
+        clearButton.setLayoutData(gd);
+        clearButton.setText("Reset Changes");
+
+        addUIListeners();
+
+        addManagerListeners();
+
+        // Check whether there is any resource selected already
+        List<ResourceAttribute> propertyList = checkSelection();
+        if (null != propertyList) {
+            updateViewer(propertyList);
+        }
+
+        setSettingSubmitVisibility(false);
+    }
+
+    public void createAttributeColumns(TableViewer tableViewer) {
+        TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
+        attName.getColumn().setWidth(attTblColWidth[0]);
+        attName.getColumn().setText(attTblHeaders[0]);
+        attName.setLabelProvider(new ColumnLabelProvider() {
+            @Override
+            public String getText(Object element) {
+                if (element instanceof ResourceAttribute) {
+                    ResourceAttribute attribute = (ResourceAttribute) element;
+                    if (null != attribute) {
+                        return attribute.getAttributeName();
+                    }
+                }
+                return "";
+            }
+        });
+
+        TableViewerColumn attValue = new TableViewerColumn(tableViewer,
+                SWT.NONE);
+        attValue.getColumn().setWidth(attTblColWidth[1]);
+        attValue.getColumn().setText(attTblHeaders[1]);
+        attValue.setLabelProvider(new ColumnLabelProvider() {
+            @Override
+            public String getText(Object element) {
+                if (element instanceof ResourceAttribute) {
+                    ResourceAttribute attribute = (ResourceAttribute) element;
+                    if (null != attribute) {
+                        Object val = attribute.getAttributeValue();
+                        if (null != val) {
+                            return String.valueOf(val);
+                        }
+                    }
+                }
+                return "";
+            }
+        });
+
+        TableViewerColumn automationStatus = new TableViewerColumn(tableViewer,
+                SWT.NONE);
+        automationStatus.getColumn().setWidth(attTblColWidth[2]);
+        automationStatus.getColumn().setText(attTblHeaders[2]);
+        automationStatus.setLabelProvider(new ColumnLabelProvider() {
+            @Override
+            public String getText(Object element) {
+                if (element instanceof ResourceAttribute) {
+                    ResourceAttribute attribute = (ResourceAttribute) element;
+                    if (null != attribute) {
+                        boolean progress = attribute.isAutomationInProgress();
+                        return Utility.getAutomationStatus(progress);
+                    }
+                }
+                return "";
+            }
+        });
+    }
+
+    public void createSettingColumns(TableViewer tableViewer) {
+        TableViewerColumn key = new TableViewerColumn(tableViewer, SWT.NONE);
+        key.getColumn().setWidth(settingTblColWidth[0]);
+        key.getColumn().setText(settingTblHeaders[0]);
+        key.setLabelProvider(new StyledCellLabelProvider() {
+            @Override
+            public void update(ViewerCell cell) {
+                Object element = cell.getElement();
+                if (element instanceof AutomationSettingHelper) {
+                    AutomationSettingHelper setting = (AutomationSettingHelper) element;
+                    cell.setText(setting.getSettingID());
+                }
+            }
+        });
+
+        TableViewerColumn value = new TableViewerColumn(tableViewer, SWT.NONE);
+        value.getColumn().setWidth(settingTblColWidth[1]);
+        value.getColumn().setText(settingTblHeaders[1]);
+        value.setLabelProvider(new CellLabelProvider() {
+            @Override
+            public void update(ViewerCell cell) {
+                Object element = cell.getElement();
+                if (element instanceof AutomationSettingHelper) {
+                    AutomationSettingHelper setting = (AutomationSettingHelper) element;
+                    if (null != setting) {
+                        cell.setText(String.valueOf(setting.getSettingValue()));
+                    }
+                }
+            }
+        });
+        automationSettingEditor = new AttributeAutomationSettingEditor(
+                tableViewer);
+        value.setEditingSupport(automationSettingEditor);
+    }
+
+    private void addUIListeners() {
+        attTblViewer
+                .addSelectionChangedListener(new ISelectionChangedListener() {
+
+                    @Override
+                    public void selectionChanged(SelectionChangedEvent e) {
+                        IStructuredSelection selection = (IStructuredSelection) attTblViewer
+                                .getSelection();
+                        Object firstElement = selection.getFirstElement();
+                        if (firstElement instanceof ResourceAttribute) {
+                            ResourceAttribute attribute = (ResourceAttribute) firstElement;
+
+                            // Store the attribute selection
+                            attributeInSelection = attribute;
+
+                            // Change the visibility of the manual change
+                            // controls according to the automation status
+                            if (attribute.isAutomationInProgress()) {
+                                setVisibilityForManualValueChange(false);
+                            } else {
+                                setVisibilityForManualValueChange(true);
+                            }
+
+                            // Hide the visibility of submit and clear buttons
+                            setSettingSubmitVisibility(false);
+
+                            if (null != attribute) {
+                                if (null != automtnSettingsTblViewer) {
+                                    localSettingList = AutomationSettingHelper
+                                            .getAutomationSettings(attribute);
+                                    if (null != localSettingList) {
+                                        automtnSettingsTblViewer.getTable()
+                                                .setLinesVisible(true);
+                                        automtnSettingsTblViewer
+                                                .setInput(localSettingList
+                                                        .toArray());
+                                    }
+                                }
+                                // Populate the attribute value combo
+                                if (null != valueCmb && !valueCmb.isDisposed()) {
+                                    // Clear the existing combo list contents
+                                    valueCmb.removeAll();
+                                    Set<Object> valueList = attribute
+                                            .getValues();
+                                    Object value;
+                                    if (null != valueList) {
+                                        Iterator<Object> valueItr = valueList
+                                                .iterator();
+                                        while (valueItr.hasNext()) {
+                                            value = valueItr.next();
+                                            if (null != value) {
+                                                // Casting the value to String
+                                                // for showing in combo
+                                                valueCmb.add(String
+                                                        .valueOf(value));
+                                            }
+                                        }
+                                        // Setting the selection to the current
+                                        // value of the attribute
+                                        String attValue = String
+                                                .valueOf(attribute
+                                                        .getAttributeValue());
+                                        int index = valueCmb.indexOf(attValue);
+                                        if (index != -1) {
+                                            valueCmb.select(index);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                });
+
+        valueCmb.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                if (null != attributeInSelection) {
+                    // attributeInSelection.setAttributeValue(valueCmb.getText());
+                    if (!valueCmb.getText().equals(
+                            String.valueOf(attributeInSelection
+                                    .getAttributeValue()))) {
+                        // Enable the submit and clear button controls
+                        setSettingSubmitVisibility(true);
+                    } else {
+                        setSettingSubmitVisibility(false);
+                    }
+                }
+            }
+        });
+
+        submitButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+
+                if (null != attributeInSelection && null != localSettingList) {
+                    if (attributeInSelection.isAutomationInProgress()
+                            || valueCmb.getText().equals(
+                                    String.valueOf(attributeInSelection
+                                            .getAttributeValue()))) {
+                        // Change in automation settings
+                        Iterator<AutomationSettingHelper> settingItr = localSettingList
+                                .iterator();
+
+                        // These variables will hold the new automation
+                        // settings.
+                        boolean autoEnable = false;
+                        AutomationType autoType = AutomationType.NORMAL;
+                        int autoUpdateInterval = Constants.DEFAULT_AUTOMATION_INTERVAL;
+
+                        // These variables will hold the old automation settings
+                        // and are used to roll-back the settings
+                        // if automation fails.
+                        boolean autoEnablePrev = false;
+                        AutomationType autoTypePrev = AutomationType.NORMAL;
+                        int autoUpdateIntervalPrev = Constants.DEFAULT_AUTOMATION_INTERVAL;
+
+                        String id;
+                        String value;
+                        AutomationSettingHelper setting;
+                        while (settingItr.hasNext()) {
+                            setting = settingItr.next();
+                            id = setting.getSettingID();
+                            value = setting.getSettingValue();
+                            if (id.equals(Constants.AUTOMATION)) {
+                                autoEnable = Utility
+                                        .getAutomationBoolean(value);
+                                autoEnablePrev = attributeInSelection
+                                        .isAutomationInProgress();
+
+                                attributeInSelection
+                                        .setAutomationInProgress(autoEnable);
+                                // Automation is disabled and hence the manual
+                                // controls should be enabled
+                                if (!autoEnable) {
+                                    setVisibilityForManualValueChange(true);
+                                }
+                            } else if (id.equals(Constants.AUTOMATION_TYPE)) {
+                                autoType = AutomationType.valueOf(value);
+                                autoTypePrev = attributeInSelection
+                                        .getAutomationType();
+
+                                attributeInSelection
+                                        .setAutomationType(autoType);
+                            } else if (id
+                                    .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
+                                autoUpdateInterval = Utility
+                                        .getUpdateIntervalFromString(value);
+                                autoUpdateIntervalPrev = attributeInSelection
+                                        .getAutomationUpdateInterval();
+
+                                attributeInSelection
+                                        .setAutomationUpdateInterval(autoUpdateInterval);
+                            }
+                        }
+
+                        // Updating the automation status in the resource
+                        SimulatorResource resource = resourceManager
+                                .getCurrentResourceInSelection();
+                        resource.setAttributeAutomationInProgress(autoEnable);
+
+                        if (autoEnable) {
+                            // Send automation enable request
+                            int autoId = resourceManager.startAutomation(
+                                    resource, attributeInSelection, autoType,
+                                    autoUpdateInterval);
+                            if (-1 == autoId) {
+                                // Automation failed
+                                // Roll-back the attribute model and automation
+                                // settings
+                                settingItr = localSettingList.iterator();
+                                while (settingItr.hasNext()) {
+                                    setting = settingItr.next();
+                                    id = setting.getSettingID();
+                                    value = setting.getSettingValue();
+                                    if (id.equals(Constants.AUTOMATION)) {
+                                        setting.setSettingValue(Utility
+                                                .getAutomationString(autoEnablePrev));
+                                    } else if (id
+                                            .equals(Constants.AUTOMATION_TYPE)) {
+                                        setting.setSettingValue(autoTypePrev
+                                                .toString());
+                                    } else if (id
+                                            .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
+                                        setting.setSettingValue(String
+                                                .valueOf(autoUpdateIntervalPrev));
+                                    }
+                                }
+
+                                attributeInSelection
+                                        .setAutomationInProgress(autoEnablePrev);
+                                attributeInSelection
+                                        .setAutomationType(autoTypePrev);
+                                attributeInSelection
+                                        .setAutomationUpdateInterval(autoUpdateIntervalPrev);
+
+                                automtnSettingsTblViewer.refresh();
+
+                                // Automation is disabled and hence the manual
+                                // controls should be enabled
+                                setVisibilityForManualValueChange(true);
+                            }
+                        } else {
+                            // Send automation disable request
+                            int autoId = attributeInSelection.getAutomationId();
+                            resourceManager.stopAutomation(resource, autoId);
+                        }
+                    } else {
+                        // Change in attribute value manually
+                        String input = valueCmb.getText();
+                        if (null != input && input.length() > 0) {
+                            attributeInSelection.setAttributeValue(input);
+
+                            SimulatorResource resource = resourceManager
+                                    .getCurrentResourceInSelection();
+                            resourceManager.attributeValueUpdated(resource,
+                                    attributeInSelection.getAttributeName(),
+                                    input);
+                        }
+                    }
+                }
+
+                attTblViewer.refresh();
+
+                setSettingSubmitVisibility(false);
+            }
+        });
+
+        clearButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                if (null != attributeInSelection) {
+                    // Update the settings table
+                    List<AutomationSettingHelper> settingList = AutomationSettingHelper
+                            .getAutomationSettings(attributeInSelection);
+                    if (null != settingList) {
+                        // clear the existing table contents
+                        Table tbl = automtnSettingsTblViewer.getTable();
+                        if (!tbl.isDisposed()) {
+                            tbl.removeAll();
+                            localSettingList = settingList;
+                            automtnSettingsTblViewer.setInput(localSettingList
+                                    .toArray());
+                        }
+                    }
+                    // Update the allowed values combo
+                    if (!valueCmb.isDisposed()) {
+                        valueCmb.setText(String.valueOf(attributeInSelection
+                                .getAttributeValue()));
+                        setVisibilityForManualValueChange(!attributeInSelection
+                                .isAutomationInProgress());
+                    }
+                }
+                setSettingSubmitVisibility(false);
+            }
+        });
+    }
+
+    private void addManagerListeners() {
+        resourceManager
+                .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
+        resourceManager
+                .addResourceModelChangedUIListener(resourceModelChangedUIListener);
+        resourceManager.addAutomationUIListener(automationUIListener);
+    }
+
+    private void setSettingSubmitVisibility(boolean visible) {
+        if (!submitButton.isDisposed())
+            submitButton.setEnabled(visible);
+        if (!clearButton.isDisposed())
+            clearButton.setEnabled(visible);
+    }
+
+    private List<ResourceAttribute> checkSelection() {
+        SimulatorResource resourceInSelection = resourceManager
+                .getCurrentResourceInSelection();
+        if (null != resourceInSelection) {
+            List<ResourceAttribute> attList = resourceManager
+                    .getAttributes(resourceInSelection);
+            return attList;
+        } else {
+            return null;
+        }
+    }
+
+    private void updateViewer(List<ResourceAttribute> attList) {
+        Table tbl;
+        if (null != attList) {
+            tbl = attTblViewer.getTable();
+            if (null != tbl && !tbl.isDisposed()) {
+                tbl.setLinesVisible(true);
+                attTblViewer.setInput(attList.toArray());
+            }
+        } else {
+            // Clear the attributes table viewer
+            if (null != attTblViewer) {
+                tbl = attTblViewer.getTable();
+                if (null != tbl && !tbl.isDisposed()) {
+                    // tbl.deselectAll();
+                    tbl.removeAll();
+                    tbl.setLinesVisible(false);
+                }
+            }
+        }
+
+        attributeInSelection = null;
+
+        // Clear the Settings table viewer
+        if (null != automtnSettingsTblViewer) {
+            tbl = automtnSettingsTblViewer.getTable();
+            if (null != tbl && !tbl.isDisposed()) {
+                // tbl.deselectAll();
+                tbl.removeAll();
+                tbl.setLinesVisible(false);
+            }
+        }
+        // Clear the value list combo
+        if (!valueCmb.isDisposed()) {
+            valueCmb.removeAll();
+            valueCmb.setEnabled(false);
+        }
+
+        // Hide the visibility of submit and clear buttons
+        setSettingSubmitVisibility(false);
+    }
+
+    class AttributeContentProvider implements IStructuredContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getElements(Object element) {
+            return (Object[]) element;
+        }
+
+    }
+
+    class AttributeAutomationSettingEditor extends EditingSupport {
+
+        private final TableViewer       viewer;
+
+        private AutomationSettingHelper currentSettingInSelection;
+
+        public AttributeAutomationSettingEditor(TableViewer viewer) {
+            super(viewer);
+            this.viewer = viewer;
+        }
+
+        @Override
+        protected boolean canEdit(Object element) {
+            return true;
+        }
+
+        @Override
+        protected CellEditor getCellEditor(Object element) {
+            ComboBoxCellEditor combo = null;
+            if (null != element) {
+                List<String> valueList;
+                boolean readOnly = true;
+                AutomationSettingHelper setting = (AutomationSettingHelper) element;
+
+                currentSettingInSelection = setting;
+
+                String settingID = setting.getSettingID();
+                if (settingID.equals(Constants.UPDATE_INTERVAL_IN_MS)) {
+                    readOnly = false;
+                }
+                valueList = setting.getAllowedValues();
+                if (null == valueList) {
+                    valueList = new ArrayList<String>();
+                }
+                // Convert list to String[] for passing it to ComboBoxCellEditor
+                String[] values;
+                values = valueList.toArray(new String[1]);
+                if (readOnly) {
+                    combo = new ComboBoxCellEditor(viewer.getTable(), values,
+                            SWT.READ_ONLY);
+                } else {
+                    combo = new ComboBoxCellEditor(viewer.getTable(), values);
+                }
+
+                // If resource level automation is enabled, then all setting
+                // should be disabled
+                SimulatorResource resourceInSelection;
+                resourceInSelection = resourceManager
+                        .getCurrentResourceInSelection();
+                if (null != resourceInSelection
+                        && resourceInSelection.isResourceAutomationInProgress()) {
+                    CCombo c = (CCombo) combo.getControl();
+                    c.setEnabled(false);
+                } else {
+                    // Enable the automation type and update interval combo
+                    // boxes only if the current value of automation is 'enable'
+                    if (settingID.equals(Constants.AUTOMATION_TYPE)
+                            || settingID
+                                    .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
+                        if (!showSettings()) {
+                            // Disable the combo box
+                            CCombo c = (CCombo) combo.getControl();
+                            c.setEnabled(false);
+                        }
+                    }
+                }
+                // Enabling editing support in update interval combo box
+                if (settingID.equals(Constants.UPDATE_INTERVAL_IN_MS)) {
+                    final CCombo c = (CCombo) combo.getControl();
+                    c.addVerifyListener(new VerifyListener() {
+                        @Override
+                        public void verifyText(VerifyEvent e) {
+                            String text = c.getText();
+                            String newText = text.substring(0, e.start)
+                                    + e.text + text.substring(e.end);
+                            try {
+                                if (newText.length() != 0) {
+                                    Integer.parseInt(newText);
+                                }
+                            } catch (NumberFormatException ex) {
+                                e.doit = false;
+                            }
+                        }
+                    });
+                    c.addTraverseListener(new TraverseListener() {
+                        @Override
+                        public void keyTraversed(TraverseEvent e) {
+                            if (e.detail == SWT.TRAVERSE_RETURN) {
+                                e.doit = false;
+                                e.detail = SWT.TRAVERSE_NONE;
+                                String newText = c.getText();
+                                try {
+                                    Integer.parseInt(newText);
+                                    if (null != currentSettingInSelection
+                                            && currentSettingInSelection
+                                                    .getSettingID()
+                                                    .equals(Constants.UPDATE_INTERVAL_IN_MS)) {
+                                        currentSettingInSelection
+                                                .addAllowedValue(newText);
+                                    }
+                                    c.add(newText);
+                                    c.setSelection(new Point(0, newText
+                                            .length()));
+                                    currentSettingInSelection
+                                            .setSettingValue(newText);
+                                } catch (NumberFormatException ex) {
+                                }
+                            }
+                        }
+                    });
+                }
+            }
+
+            return combo;
+        }
+
+        @Override
+        protected Object getValue(Object element) {
+            // This method returns the index of the item selected in the combo
+            // box
+            int index;
+            AutomationSettingHelper setting = (AutomationSettingHelper) element;
+            List<String> itemList = setting.getAllowedValues();
+            String currentValue = setting.getSettingValue();
+            index = itemList.indexOf(currentValue);
+            return index;
+        }
+
+        @Override
+        protected void setValue(Object element, Object value) {
+            AutomationSettingHelper setting = (AutomationSettingHelper) element;
+            int index = (Integer) value;
+            List<String> valueList = setting.getAllowedValues();
+            if (null != valueList) {
+                String targetValue;
+                if (index != -1) {
+                    targetValue = valueList.get(index);
+                    setting.setSettingValue(targetValue);
+
+                    if (setting.getSettingID().equals(Constants.AUTOMATION)) {
+
+                        if (attributeInSelection.isAutomationInProgress()) {
+                            // settingsVisibility = false;
+                            setVisibilityForManualValueChange(false);
+                        } else {
+                            if (targetValue.equals(Constants.ENABLE)) {
+                                // settingsVisibility = true;
+                                setVisibilityForManualValueChange(false);
+                            } else {
+                                // settingsVisibility = false;
+                                setVisibilityForManualValueChange(true);
+                            }
+                        }
+
+                        // If status is changed, then enable the submit and
+                        // clear buttons
+                        if (!targetValue.equals(Utility
+                                .getAutomationString(attributeInSelection
+                                        .isAutomationInProgress()))) {
+                            setSettingSubmitVisibility(true);
+                        } else {
+                            setSettingSubmitVisibility(false);
+                        }
+                    }
+                }
+            }
+            viewer.refresh();
+        }
+    }
+
+    private boolean showSettings() {
+        boolean show = false;
+        if (!attributeInSelection.isAutomationInProgress()) {
+            AutomationSettingHelper setting;
+            Iterator<AutomationSettingHelper> list = localSettingList
+                    .iterator();
+            while (list.hasNext()) {
+                setting = list.next();
+                if (setting.getSettingID().equals(Constants.AUTOMATION)) {
+                    if (setting.getSettingValue().equals(Constants.ENABLE)) {
+                        show = true;
+                    }
+                    break;
+                }
+            }
+        }
+        return show;
+    }
+
+    // Disable the appropriate controls which are used for manual value change
+    private void setVisibilityForManualValueChange(boolean visibility) {
+        if (null != valueCmb && !valueCmb.isDisposed()) {
+            valueCmb.setEnabled(visibility);
+        }
+        if (null != newValueLbl && !newValueLbl.isDisposed()) {
+            newValueLbl.setEnabled(visibility);
+        }
+    }
 
     @Override
-    public void createPartControl(Composite arg0) {
-        // TODO Auto-generated method stub
+    public void dispose() {
+        // Unregister the selection listener
+        if (null != resourceSelectionChangedListener) {
+            resourceManager
+                    .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
+        }
 
+        // Unregister the model change listener
+        if (null != resourceModelChangedUIListener) {
+            resourceManager
+                    .removeResourceModelChangedUIListener(resourceModelChangedUIListener);
+        }
+
+        // Unregister the automation complete listener
+        if (null != automationUIListener) {
+            resourceManager.removeAutomationUIListener(automationUIListener);
+        }
+
+        super.dispose();
     }
 
     @Override
     public void setFocus() {
-        // TODO Auto-generated method stub
 
     }
-
-}
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/LogDetailsDialog.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/LogDetailsDialog.java
new file mode 100644 (file)
index 0000000..c5d4e49
--- /dev/null
@@ -0,0 +1,123 @@
+package oic.simulator.serviceprovider.view;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class LogDetailsDialog extends Dialog {
+    private final String severity;
+    private final Date   date;
+    private final String message;
+    private final Image  severityIcon;
+
+    public LogDetailsDialog(Shell parentShell, String severity,
+            Image severityIcon, Date date, String message) {
+        super(parentShell);
+        this.severity = severity;
+        this.severityIcon = severityIcon;
+        this.message = message;
+        this.date = date;
+    }
+
+    @Override
+    protected boolean isResizable() {
+        return true;
+    }
+
+    @Override
+    protected void configureShell(Shell shell) {
+        super.configureShell(shell);
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        getShell().setText("Logged event details");
+
+        Composite container = (Composite) super.createDialogArea(parent);
+
+        GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
+        container.setLayoutData(layoutData);
+        container.setLayout(new GridLayout(2, false));
+
+        GridData gd;
+
+        Label l1 = new Label(container, SWT.NONE);
+        l1.setText("Severity:");
+        gd = new GridData();
+        gd.widthHint = 100;
+        l1.setLayoutData(gd);
+
+        Composite y = new Composite(container, SWT.NONE);
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        y.setLayoutData(gd);
+        y.setLayout(new RowLayout(SWT.HORIZONTAL));
+
+        Label l2 = new Label(y, SWT.NONE);
+        l2.setImage(severityIcon);
+        l2.setLayoutData(new RowData());
+        Label l3 = new Label(y, SWT.NONE);
+        l3.setText(severity);
+        l3.setLayoutData(new RowData());
+
+        Label l4 = new Label(container, SWT.NONE);
+        l4.setText("Date:");
+        gd = new GridData();
+        gd.widthHint = 100;
+        l4.setLayoutData(gd);
+
+        Label l5 = new Label(container, SWT.NONE);
+        DateFormat dateFormat = DateFormat.getDateTimeInstance(
+                DateFormat.SHORT, DateFormat.SHORT);
+        l5.setText(dateFormat.format(date));
+        gd = new GridData();
+        gd.grabExcessHorizontalSpace = true;
+        l5.setLayoutData(gd);
+
+        new Label(container, SWT.NONE); // separator
+
+        Label l6 = new Label(container, SWT.NONE);
+        l6.setText("Message details");
+        gd = new GridData();
+        gd.horizontalSpan = 2;
+        l6.setLayoutData(gd);
+
+        Text text = new Text(container, SWT.MULTI | SWT.READ_ONLY
+                | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
+        if (message != null) {
+            text.setText(message);
+        } else {
+            text.setText("No description available");
+        }
+        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+        gd.horizontalSpan = 2;
+        gd.heightHint = 350;
+        gd.widthHint = 500;
+        text.setLayoutData(gd);
+
+        return container;
+    }
+
+    @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);
+    }
+}
index 4615aa2..99af2ee 100644 (file)
 package oic.simulator.serviceprovider.view;
 
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.HashMap;
+import java.util.List;
+
+import oic.simulator.logger.LogContentProvider;
+import oic.simulator.logger.LogEntry;
+import oic.simulator.logger.LogLabelProvider;
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.listener.ILogUIListener;
+import oic.simulator.serviceprovider.manager.LogManager;
+import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.view.dialogs.FilterDialog;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.dialogs.FilteredTree;
+import org.eclipse.ui.dialogs.PatternFilter;
 import org.eclipse.ui.part.ViewPart;
+import org.oic.simulator.ILogger.Level;
 
 public class LogView extends ViewPart {
 
-    public static final String VIEW_ID = "oic.simulator.serviceprovider.view.log";
+    public static final String        VIEW_ID              = "oic.simulator.serviceprovider.view.log";
+
+    private LogManager                logManager;
+    private ILogUIListener            logListener;
+
+    private LogContentProvider        treeContentProvider;
+
+    private FilteredTree              tree;
+    private TreeColumn                severityColumn;
+    private TreeColumn                dateColumn;
+    private TreeColumn                messageColumn;
+
+    private IAction                   exportLogAction;
+    private IAction                   clearLogAction;
+    private IAction                   deleteLogAction;
+    private IAction                   scrollLockAction;
+    private IAction                   logDetailsAction;
+    private IAction                   filterAction;
+    private IAction                   activateViewAction;
+    private IAction                   showTextFilter;
+    private IContributionItem         groupByAction;
+
+    private HashMap<Integer, Boolean> shownSeverities      = new HashMap<Integer, Boolean>();
+
+    private boolean                   activateOnChange     = false;
+
+    private boolean                   hideTextFilter       = false;
+
+    private boolean                   scrollLockDisabled;
+
+    public static final int           ORDER_BY_TIME        = 0;
+    public static final int           ORDER_BY_SEVERITY    = 1;
+    public static final int           ORDER_BY_MESSAGE     = 2;
+
+    int                               sortCandidate        = ORDER_BY_TIME;
+
+    SortAction                        sortByTimeAction     = new SortAction(
+                                                                   "Order by Time",
+                                                                   ORDER_BY_TIME);
+    SortAction                        sortBySeverityAction = new SortAction(
+                                                                   "Order by Severity",
+                                                                   ORDER_BY_SEVERITY);
+    SortAction                        sortByMessageAction  = new SortAction(
+                                                                   "Order by Message",
+                                                                   ORDER_BY_MESSAGE);
+
+    private ViewerComparator          dateComparator;
+    private ViewerComparator          severityComparator;
+    private ViewerComparator          messageComparator;
+
+    private TreeColumn                sortColumn           = null;
+    private static int                DOWN                 = 1;
+    private static int                UP                   = -1;
+    private int                       sortDirection        = DOWN;
+
+    public LogView() {
+
+        logListener = new ILogUIListener() {
+
+            @Override
+            public void logChanged(final List<LogEntry> entry) {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        TreeViewer viewer = tree.getViewer();
+                        if (viewer.getControl().isDisposed()) {
+                            return;
+                        }
+                        viewer.setInput(entry);
+                        updateTree(false);
+                    }
+                });
+            }
+
+            @Override
+            public void logAdded(final LogEntry added) {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        TreeViewer viewer = tree.getViewer();
+                        if (viewer.getControl().isDisposed()) {
+                            return;
+                        }
+                        LogContentProvider provider = (LogContentProvider) viewer
+                                .getContentProvider();
+                        provider.addLog(added);
+                        tree.getViewer().add(viewer.getInput(), added);
+                        @SuppressWarnings("unchecked")
+                        List<LogEntry> input = (List<LogEntry>) viewer
+                                .getInput();
+                        if (input.size() > Constants.LOG_SIZE) {
+                            viewer.remove(viewer.getInput(), 0);
+                        }
+                        updateTree(true);
+                    }
+                });
+            }
+
+            private void updateTree(boolean needscroll) {
+                if (activateOnChange) {
+                    IWorkbenchPage page = Activator.getDefault().getWorkbench()
+                            .getActiveWorkbenchWindow().getActivePage();
+                    if (page != null) {
+                        page.bringToTop(LogView.this);
+                    }
+                }
+                if (scrollLockDisabled && needscroll) {
+                    Tree tree2 = tree.getViewer().getTree();
+                    if (tree2.getItemCount() > 0) {
+                        TreeItem item = tree2.getItem(tree2.getItemCount() - 1);
+                        tree2.setTopItem(item);
+                        deleteLogAction.setEnabled(true);
+                    }
+                }
+            }
+        };
+
+        logManager = Activator.getDefault().getLogManager();
+
+        // Initially state of scroll lock
+        scrollLockDisabled = true;
+    }
 
     @Override
-    public void createPartControl(Composite arg0) {
-        // TODO Auto-generated method stub
+    public void createPartControl(Composite parent) {
+        PatternFilter filter = new PatternFilter() {
+
+            DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
+
+            @Override
+            protected boolean isLeafMatch(Viewer viewer, Object element) {
+                if (element instanceof LogEntry) {
+                    LogEntry logEntry = (LogEntry) element;
+                    String severity = LogManager.getSeverityName(logEntry
+                            .getSeverity());
+                    String date = dateFormat.format(logEntry.getDate());
+                    String message = logEntry.getMessage();
+                    return wordMatches(severity) || wordMatches(date)
+                            || wordMatches(message);
+                }
+                return false;
+            }
+        };
+        filter.setIncludeLeadingWildcard(true);
+        tree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL
+                | SWT.V_SCROLL | SWT.FULL_SELECTION, filter, true);
+
+        setupFilteredTree();
+
+        createColumnComparators();
+
+        createActions();
+
+        setDefaultShownSeverities();
+
+        IActionBars actionBars = getViewSite().getActionBars();
+        IToolBarManager toolBarManager = actionBars.getToolBarManager();
+        toolBarManager.add(exportLogAction);
+        toolBarManager.add(clearLogAction);
+        toolBarManager.add(deleteLogAction);
+        toolBarManager.add(scrollLockAction);
+        toolBarManager
+                .add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+
+        IMenuManager mgr = actionBars.getMenuManager();
+        mgr.add(groupByAction);
+        mgr.add(new Separator());
+        mgr.add(filterAction);
+        mgr.add(new Separator());
+        mgr.add(activateViewAction);
+        mgr.add(showTextFilter);
+
+        addManagerListeners();
+
+        if (sortCandidate == ORDER_BY_TIME) {
+            sortByTimeAction.run();
+        } else if (sortCandidate == ORDER_BY_SEVERITY) {
+            sortBySeverityAction.run();
+        } else { // order_selected == ORDER_BY_NONE
+            sortByMessageAction.run();
+        }
+
+    }
+
+    private void setupFilteredTree() {
+        tree.setLayoutData(new GridData(GridData.FILL_BOTH));
+        final Tree innerTree = tree.getViewer().getTree();
+        innerTree.setLinesVisible(true);
+
+        severityColumn = new TreeColumn(innerTree, SWT.LEFT);
+        severityColumn.setText("Severity");
+        severityColumn.setWidth(110);
+        severityColumn.addSelectionListener(new SelectionAdapter() {
+
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                sortBySeverityAction.run();
+            }
+        });
+        dateColumn = new TreeColumn(innerTree, SWT.LEFT);
+        dateColumn.setText("Time");
+        dateColumn.setWidth(110);
+        dateColumn.addSelectionListener(new SelectionAdapter() {
+
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                sortByTimeAction.run();
+            }
+        });
+        messageColumn = new TreeColumn(innerTree, SWT.LEFT);
+        messageColumn.setText("Message");
+        messageColumn.setWidth(180);
+        messageColumn.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                sortByMessageAction.run();
+            }
+        });
+
+        innerTree.setHeaderVisible(true);
+
+        treeContentProvider = new LogContentProvider();
+
+        tree.getViewer().setContentProvider(treeContentProvider);
+        tree.getViewer().setLabelProvider(new LogLabelProvider());
+
+        tree.getViewer().setInput(logManager.getLogEntries());
+
+        tree.getViewer().addSelectionChangedListener(
+                new ISelectionChangedListener() {
+
+                    @Override
+                    public void selectionChanged(SelectionChangedEvent event) {
+                        deleteLogAction.setEnabled(!tree.getViewer()
+                                .getSelection().isEmpty());
+                        logDetailsAction.setEnabled(!tree.getViewer()
+                                .getSelection().isEmpty());
+                    }
+                });
+
+        tree.getViewer().getTree().addKeyListener(new KeyListener() {
+
+            @Override
+            public void keyReleased(KeyEvent e) {
+            }
+
+            @Override
+            public void keyPressed(KeyEvent e) {
+                if (e.character == (char) 127) { // If delete key is pressed
+                    if (deleteLogAction.isEnabled()) {
+                        deleteLogAction.run();
+                    }
+                }
+            }
+        });
+
+        tree.getViewer().addDoubleClickListener(new IDoubleClickListener() {
+
+            @Override
+            public void doubleClick(DoubleClickEvent event) {
+                logDetailsAction.run();
+            }
+        });
+    }
+
+    private void createColumnComparators() {
+        dateComparator = new ViewerComparator() {
+
+            @Override
+            public int compare(Viewer viewer, Object e1, Object e2) {
+                LogEntry l1 = (LogEntry) e1;
+                LogEntry l2 = (LogEntry) e2;
+                return l1.getDate().compareTo(l2.getDate()) * sortDirection;
+            }
+        };
+
+        severityComparator = new ViewerComparator() {
 
+            @Override
+            public int compare(Viewer viewer, Object e1, Object e2) {
+                LogEntry l1 = (LogEntry) e1;
+                LogEntry l2 = (LogEntry) e2;
+                if (l1.getSeverity() < l2.getSeverity()) {
+                    return -1 * sortDirection;
+                }
+                if (l1.getSeverity() > l2.getSeverity()) {
+                    return 1 * sortDirection;
+                }
+                return 0;
+            }
+        };
+
+        messageComparator = new ViewerComparator() {
+
+            @Override
+            public int compare(Viewer viewer, Object e1, Object e2) {
+                LogEntry l1 = (LogEntry) e1;
+                LogEntry l2 = (LogEntry) e2;
+                return l1.getMessage().compareTo(l2.getMessage())
+                        * sortDirection;
+            }
+        };
+
+    }
+
+    private void setDefaultShownSeverities() {
+        shownSeverities.put(Level.INFO.ordinal(), true);
+        shownSeverities.put(Level.DEBUG.ordinal(), true);
+        shownSeverities.put(Level.WARNING.ordinal(), true);
+        shownSeverities.put(Level.ERROR.ordinal(), true);
+    }
+
+    private void addManagerListeners() {
+        logManager.addLogListener(logListener);
+        logManager.applyFilter(shownSeverities);
+    }
+
+    private void createActions() {
+        exportLogAction = createExportLogAction();
+        clearLogAction = createClearLogAction();
+        deleteLogAction = createDeleteLogAction();
+        scrollLockAction = createScrollLockAction();
+        logDetailsAction = createLogDetailsAction();
+
+        filterAction = createFilterAction();
+        activateViewAction = createActivateViewAction();
+        showTextFilter = createShowTextFilter();
+        groupByAction = createGroupByAction();
+    }
+
+    private IAction createExportLogAction() {
+        Action action = new Action("Export log") {
+            @Override
+            public void run() {
+                FileDialog fd = new FileDialog(Display.getDefault()
+                        .getActiveShell(), SWT.SAVE);
+                fd.setOverwrite(true);
+                fd.setFileName("OIC_Simulator_ServerLog.log");
+                fd.setFilterExtensions(Constants.SAVE_LOG_FILTER_EXTENSIONS);
+                String name = fd.open();
+                List<LogEntry> logEntries = logManager.getLogEntries();
+                StringBuilder sb = new StringBuilder();
+                for (LogEntry entry : logEntries) {
+                    sb.append(entry.toString());
+                }
+                String data = sb.toString();
+                BufferedWriter out = null;
+                try {
+                    out = new BufferedWriter(new FileWriter(name));
+                    out.write(data);
+                } catch (IOException e) {
+                    e.printStackTrace();
+                    MessageDialog.openError(
+                            Display.getDefault().getActiveShell(),
+                            "Export error",
+                            "Could not export log. IO exception: "
+                                    + e.getMessage());
+                } finally {
+                    try {
+                        out.close();
+                    } catch (IOException e) {
+                        // Error occurred during close. Ignoring
+                    }
+                }
+            }
+        };
+        action.setToolTipText("Export log");
+
+        action.setImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/export_log_e.gif"));
+        action.setDisabledImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/export_log_d.gif"));
+        action.setEnabled(true);
+
+        return action;
+    }
+
+    private IAction createClearLogAction() {
+        Action action = new Action("Clear log") {
+
+            @Override
+            public void run() {
+                logManager.clearLog();
+            }
+        };
+        action.setToolTipText("Clear log");
+
+        action.setImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/clear_e.gif"));
+        action.setDisabledImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/clear_d.gif"));
+        action.setEnabled(true);
+        return action;
+    }
+
+    private IAction createDeleteLogAction() {
+        Action action = new Action("Delete log entry") {
+
+            @Override
+            @SuppressWarnings("unchecked")
+            public void run() {
+                IStructuredSelection selection = (IStructuredSelection) tree
+                        .getViewer().getSelection();
+                List<LogEntry> entries = (List<LogEntry>) tree.getViewer()
+                        .getInput();
+                LogEntry selectedEntry = (LogEntry) selection.getFirstElement();
+                if (null != selectedEntry) {
+                    LogEntry toBeShownEntry = null;
+                    for (LogEntry entry : entries) {
+                        if (entry.equals(selectedEntry)) {
+                            int size = entries.size();
+                            int index = entries.indexOf(selectedEntry);
+                            if (index + 1 < size) {
+                                toBeShownEntry = entries.get(index + 1);
+                            } else if (index > 0) {
+                                toBeShownEntry = entries.get(index - 1);
+                            }
+                            break;
+                        }
+                    }
+                    logManager.removeEntry(selectedEntry);
+                    if (null != toBeShownEntry) {
+                        tree.getViewer().setSelection(
+                                new StructuredSelection(toBeShownEntry));
+                    }
+                }
+            }
+        };
+        action.setToolTipText("Delete log entry");
+        action.setImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/delete_e.gif"));
+        action.setDisabledImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/delete_d.gif"));
+        action.setEnabled(false);
+        return action;
+    }
+
+    private IAction createScrollLockAction() {
+        Action action = new Action("Scroll lock") {
+
+            @Override
+            public void run() {
+                scrollLockDisabled = !this.isChecked();
+            };
+
+            @Override
+            public int getStyle() {
+                return IAction.AS_CHECK_BOX;
+            }
+        };
+        action.setToolTipText("Scroll lock");
+        action.setImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/lock_e.gif"));
+        action.setDisabledImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/lock_d.gif"));
+        action.setEnabled(true);
+        return action;
+    }
+
+    private IAction createLogDetailsAction() {
+        Action action = new Action("Details...") {
+
+            @Override
+            public void run() {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        LogEntry x = (LogEntry) ((IStructuredSelection) tree
+                                .getViewer().getSelection()).getFirstElement();
+
+                        new LogDetailsDialog(Display.getDefault()
+                                .getActiveShell(), LogManager.getSeverityName(x
+                                .getSeverity()), LogManager.getSeverityIcon(x
+                                .getSeverity()), x.getDate(), x.getMessage())
+                                .open();
+                    }
+                });
+            }
+        };
+        action.setToolTipText("Details...");
+        action.setImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/log_details_e.gif"));
+        action.setDisabledImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/log_details_e.gif"));
+        action.setEnabled(false);
+        return action;
+    }
+
+    private IAction createFilterAction() {
+        Action action = new Action("Filters ...") {
+
+            @Override
+            public void run() {
+                FilterDialog fd = new FilterDialog(Display.getDefault()
+                        .getActiveShell(), shownSeverities);
+                if (fd.open() == Window.OK) {
+                    logManager.applyFilter(shownSeverities);
+                }
+                tree.getViewer().refresh();
+            }
+        };
+        action.setToolTipText("Filters ...");
+
+        action.setImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/filter_e.gif"));
+        action.setDisabledImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/filter_d.gif"));
+        action.setEnabled(true);
+        return action;
+    }
+
+    private IAction createActivateViewAction() {
+        Action action = new Action("Activate view on new events",
+                IAction.AS_CHECK_BOX) {
+
+            @Override
+            public void run() {
+                activateOnChange = this.isChecked();
+            }
+        };
+        action.setChecked(activateOnChange);
+        action.setToolTipText("Activate view on new events");
+
+        action.setImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/prop_e.gif"));
+        action.setDisabledImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/prop_d.gif"));
+        action.setEnabled(true);
+        return action;
+    }
+
+    private IAction createShowTextFilter() {
+        Action action = new Action("Show text filter", IAction.AS_CHECK_BOX) {
+
+            @Override
+            public void run() {
+                Text filterControl = tree.getFilterControl();
+                Composite filterComposite = filterControl.getParent();
+                GridData gd = (GridData) filterComposite.getLayoutData();
+                boolean visible = isChecked();
+                gd.exclude = !visible;
+                filterComposite.setVisible(visible);
+                filterControl.setText("");
+                if (visible) {
+                    filterControl.selectAll();
+                    setFocus();
+                }
+                tree.layout(false);
+                hideTextFilter = !visible;
+            }
+        };
+        action.setToolTipText("Show text filter");
+
+        action.setImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/tree_mode_e.gif"));
+        action.setDisabledImageDescriptor(ImageDescriptor.createFromFile(
+                this.getClass(), "/icons/tree_mode_d.gif"));
+        action.setEnabled(true);
+        action.setChecked(!hideTextFilter);
+        if (hideTextFilter) {
+            action.run();
+        }
+        return action;
+    }
+
+    private IContributionItem createGroupByAction() {
+        IMenuManager manager = new MenuManager("Order by");
+        manager.add(sortByTimeAction);
+        manager.add(sortBySeverityAction);
+        manager.add(sortByMessageAction);
+        return manager;
+    }
+
+    class SortAction extends Action {
+
+        private final int sortBy;
+
+        public SortAction(String text, int sortBy) {
+            super(text, IAction.AS_RADIO_BUTTON);
+            this.sortBy = sortBy;
+
+            if (sortCandidate == sortBy) {
+                setChecked(true);
+            }
+        }
+
+        @Override
+        public void run() {
+            sortBySeverityAction.setChecked(false);
+            sortByTimeAction.setChecked(false);
+            sortCandidate = sortBy;
+            setChecked(true);
+
+            ViewerComparator comparator;
+            TreeColumn column;
+            if (sortBy == ORDER_BY_SEVERITY) {
+                comparator = severityComparator;
+                column = severityColumn;
+            } else if (sortBy == ORDER_BY_TIME) {
+                comparator = dateComparator;
+                column = dateColumn;
+            } else { // Order by message
+                comparator = messageComparator;
+                column = messageColumn;
+            }
+            TreeViewer viewer = tree.getViewer();
+            viewer.setComparator(comparator);
+            viewer.getTree().setSortColumn(column);
+            if (column.equals(sortColumn)) { // reverse sorting order
+                sortDirection = viewer.getTree().getSortDirection() == SWT.UP ? DOWN
+                        : UP;
+                viewer.getTree().setSortDirection(
+                        sortDirection == UP ? SWT.UP : SWT.DOWN);
+                viewer.refresh();
+            } else { // set this column as the one to sort by
+                sortDirection = DOWN;
+                viewer.getTree().setSortDirection(SWT.DOWN);
+            }
+            sortColumn = column;
+            refresh();
+        }
+    }
+
+    private void refresh() {
+        tree.getViewer().refresh();
     }
 
     @Override
     public void setFocus() {
-        // TODO Auto-generated method stub
-
+        tree.setFocus();
     }
 
-}
+    @Override
+    public void dispose() {
+        logManager.removeLogListener(logListener);
+        super.dispose();
+    }
+}
\ No newline at end of file
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
new file mode 100644 (file)
index 0000000..936d17d
--- /dev/null
@@ -0,0 +1,185 @@
+package oic.simulator.serviceprovider.view;
+
+import java.util.List;
+
+import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.listener.IResourceSelectionChangedUIListener;
+import oic.simulator.serviceprovider.manager.ResourceManager;
+import oic.simulator.serviceprovider.resource.MetaProperty;
+import oic.simulator.serviceprovider.resource.SimulatorResource;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+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.Table;
+import org.eclipse.ui.part.ViewPart;
+
+public class MetaPropertiesView extends ViewPart {
+
+    public static final String                  VIEW_ID       = "oic.simulator.serviceprovider.view.metaproperties";
+
+    private TableViewer                         tableViewer;
+
+    private final String[]                      columnHeaders = { "Property",
+            "Value"                                          };
+
+    private final Integer[]                     columnWidth   = { 150, 150 };
+
+    private IResourceSelectionChangedUIListener resourceSelectionChangedListener;
+
+    private ResourceManager                     resourceManager;
+
+    public MetaPropertiesView() {
+
+        resourceManager = Activator.getDefault().getResourceManager();
+
+        resourceSelectionChangedListener = new IResourceSelectionChangedUIListener() {
+
+            @Override
+            public void onResourceSelectionChange() {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        if (null != tableViewer) {
+                            updateViewer(checkSelection());
+                        }
+                    }
+                });
+            }
+        };
+    }
+
+    @Override
+    public void createPartControl(Composite parent) {
+        parent.setLayout(new GridLayout(1, false));
+
+        tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
+                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+
+        createColumns(tableViewer);
+
+        // make lines and header visible
+        final Table table = tableViewer.getTable();
+        table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        table.setHeaderVisible(true);
+        table.setLinesVisible(true);
+
+        tableViewer.setContentProvider(new PropertycontentProvider());
+
+        addManagerListeners();
+
+        // Check whether there is any resource selected already
+        List<MetaProperty> propertyList = checkSelection();
+        if (null != propertyList) {
+            updateViewer(propertyList);
+        }
+
+    }
+
+    private List<MetaProperty> checkSelection() {
+        SimulatorResource resourceInSelection = resourceManager
+                .getCurrentResourceInSelection();
+        if (null != resourceInSelection) {
+            List<MetaProperty> metaPropertyList = resourceManager
+                    .getMetaProperties(resourceInSelection);
+            return metaPropertyList;
+        } else {
+            return null;
+        }
+    }
+
+    private void updateViewer(List<MetaProperty> metaPropertyList) {
+        if (null != tableViewer) {
+            Table tbl = tableViewer.getTable();
+            if (null != metaPropertyList) {
+                tableViewer.setInput(metaPropertyList.toArray());
+                if (!tbl.isDisposed()) {
+                    tbl.setLinesVisible(true);
+                }
+            } else {
+                if (!tbl.isDisposed()) {
+                    tbl.removeAll();
+                    tbl.setLinesVisible(false);
+                }
+            }
+        }
+    }
+
+    public void createColumns(TableViewer tableViewer) {
+        TableViewerColumn propName = new TableViewerColumn(tableViewer,
+                SWT.NONE);
+        propName.getColumn().setWidth(columnWidth[0]);
+        propName.getColumn().setText(columnHeaders[0]);
+        propName.setLabelProvider(new ColumnLabelProvider() {
+            @Override
+            public String getText(Object element) {
+                MetaProperty prop = (MetaProperty) element;
+                if (null != prop) {
+                    return prop.getPropName();
+                } else {
+                    return "";
+                }
+            }
+        });
+
+        TableViewerColumn propValue = new TableViewerColumn(tableViewer,
+                SWT.NONE);
+        propValue.getColumn().setWidth(columnWidth[1]);
+        propValue.getColumn().setText(columnHeaders[1]);
+        propValue.setLabelProvider(new ColumnLabelProvider() {
+            @Override
+            public String getText(Object element) {
+                MetaProperty prop = (MetaProperty) element;
+                if (null != prop) {
+                    return prop.getPropValue();
+                } else {
+                    return "";
+                }
+            }
+        });
+    }
+
+    private void addManagerListeners() {
+        resourceManager
+                .addResourceSelectionChangedUIListener(resourceSelectionChangedListener);
+    }
+
+    class PropertycontentProvider implements IStructuredContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+        }
+
+        @Override
+        public Object[] getElements(Object element) {
+            return (Object[]) element;
+        }
+
+    }
+
+    @Override
+    public void dispose() {
+        // Unregister the listener
+        if (null != resourceSelectionChangedListener) {
+            resourceManager
+                    .removeResourceSelectionChangedUIListener(resourceSelectionChangedListener);
+        }
+        super.dispose();
+    }
+
+    @Override
+    public void setFocus() {
+    }
+}
\ No newline at end of file
index b7832f2..99659a4 100644 (file)
@@ -9,14 +9,11 @@ public class MultiResourceOrchestrationView extends ViewPart {
 
     @Override
     public void createPartControl(Composite arg0) {
-        // TODO Auto-generated method stub
-
+        // TODO: To be done
     }
 
     @Override
     public void setFocus() {
-        // TODO Auto-generated method stub
-
+        // TODO To be done
     }
-
-}
+}
\ No newline at end of file
index ecbb8e6..b620623 100644 (file)
@@ -1,19 +1,27 @@
 package oic.simulator.serviceprovider.view;
 
-import java.util.Iterator;
+import java.util.ArrayList;
 import java.util.List;
 
 import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.listener.IResourceListChangedListener;
+import oic.simulator.serviceprovider.listener.IResourceListChangedUIListener;
 import oic.simulator.serviceprovider.manager.ResourceManager;
-import oic.simulator.serviceprovider.utils.Convertion;
+import oic.simulator.serviceprovider.utils.Constants;
+import oic.simulator.serviceprovider.utils.Utility;
 import oic.simulator.serviceprovider.view.dialogs.CreateResourceWizard;
 import oic.simulator.serviceprovider.view.dialogs.DeleteCategory;
 import oic.simulator.serviceprovider.view.dialogs.DeleteResourceWizard;
 import oic.simulator.serviceprovider.view.dialogs.ResourceWizardDialog;
 
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MenuAdapter;
+import org.eclipse.swt.events.MenuEvent;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.graphics.Color;
@@ -23,118 +31,86 @@ 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.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;
 import org.eclipse.ui.part.ViewPart;
 
 public class ResourceManagerView extends ViewPart {
 
-    public static final String           VIEW_ID = "oic.simulator.serviceprovider.view.resourcemanager";
+    public static final String             VIEW_ID = "oic.simulator.serviceprovider.view.resourcemanager";
 
-    private Button                       createButton;
-    private Button                       deleteButton;
+    private Button                         createButton;
+    private Button                         deleteButton;
 
-    private Tree                         resourceTreeHead;
+    private TreeViewer                     treeViewer;
 
-    private IResourceListChangedListener resourceListChangedListener;
+    private IResourceListChangedUIListener resourceListChangedListener;
+
+    private ResourceManager                resourceManager;
 
     public ResourceManagerView() {
-        resourceListChangedListener = new IResourceListChangedListener() {
 
-            @Override
-            public void onResourceCreation(String resourceType,
-                    List<String> resourceURI) {
-                if (null != resourceTreeHead
-                        && !(resourceTreeHead.isDisposed())
-                        && null != resourceType && null != resourceURI) {
-                    TreeItem resourceHead = null;
-                    TreeItem[] items = resourceTreeHead.getItems();
-                    if (null != items) {
-                        for (TreeItem item : items) {
-                            if (item.getText().equals(resourceType)) {
-                                resourceHead = item;
-                                break;
-                            }
-                        }
-                        if (null == resourceHead) {
-                            // Adding a new tree header
-                            resourceHead = new TreeItem(resourceTreeHead,
-                                    SWT.NULL);
-                            resourceHead.setText(resourceType);
-                        }
-                        // Add resources under the resourceHead
-                        Iterator<String> uriItr = resourceURI.iterator();
-                        while (uriItr.hasNext()) {
-                            TreeItem newItem = new TreeItem(resourceHead,
-                                    SWT.NULL);
-                            newItem.setText(Convertion.uriToDisplayName(uriItr
-                                    .next()));
-                        }
-                    }
-                }
-            }
+        resourceManager = Activator.getDefault().getResourceManager();
+
+        resourceListChangedListener = new IResourceListChangedUIListener() {
 
             @Override
-            public void onResourceDeletion(String resourceType,
-                    String resourceURI) {
-                if (null != resourceTreeHead
-                        && !(resourceTreeHead.isDisposed())) {
-                    TreeItem targetParent = null;
-                    TreeItem[] headItems = resourceTreeHead.getItems();
-                    if (null != headItems) {
-                        for (TreeItem item : headItems) {
-                            if (item.getText().equals(resourceType)) {
-                                targetParent = item;
-                                break;
-                            }
-                        }
-                        if (null != targetParent) {
-                            TreeItem[] items = targetParent.getItems();
-                            for (TreeItem item : items) {
-                                if (item.getText().equals(
-                                        Convertion
-                                                .uriToDisplayName(resourceURI))) {
-                                    item.dispose();
-                                    if (targetParent.getItemCount() < 1) {
-                                        targetParent.dispose();
-                                    }
-                                    break;
-                                }
-                            }
+            public void onResourceCreation() {
+                Display.getDefault().asyncExec(new Runnable() {
+
+                    @Override
+                    public void run() {
+                        if (null != treeViewer) {
+                            treeViewer.refresh();
+                            treeViewer.expandAll();
                         }
+
+                        // Trigger the visibility of delete button
+                        changeDeleteVisibility();
                     }
-                }
+                });
             }
 
             @Override
-            public void onResourceDeletionByType(String resourceType) {
-                if (null != resourceTreeHead
-                        && !(resourceTreeHead.isDisposed())) {
-                    TreeItem items[] = resourceTreeHead.getItems();
-                    for (TreeItem item : items) {
-                        if (item.getText().equals(resourceType)) {
-                            item.dispose();
-                            break;
-                        }
-                    }
-                }
-            }
+            public void onResourceDeletion() {
+                Display.getDefault().asyncExec(new Runnable() {
 
-            public void onAllResourceDeletion() {
-                if (null != resourceTreeHead
-                        && !(resourceTreeHead.isDisposed())) {
-                    TreeItem[] items = resourceTreeHead.getItems();
-                    if (null != items) {
-                        for (TreeItem item : items) {
-                            item.dispose();
+                    @Override
+                    public void run() {
+                        if (null != treeViewer) {
+                            treeViewer.refresh();
+                            treeViewer.expandAll();
                         }
+
+                        // Trigger the visibility of delete button
+                        changeDeleteVisibility();
                     }
-                }
+                });
             }
         };
     }
 
+    public void changeDeleteVisibility() {
+        if (null == treeViewer) {
+            return;
+        }
+        boolean visibility;
+        Tree tree = treeViewer.getTree();
+        if (null != tree && !tree.isDisposed() && tree.getItemCount() > 0) {
+            visibility = true;
+        } else {
+            visibility = false;
+        }
+        if (null != deleteButton && !deleteButton.isDisposed()) {
+            deleteButton.setEnabled(visibility);
+        }
+    }
+
     @Override
     public void createPartControl(Composite parent) {
         Composite compContent = new Composite(parent, SWT.NONE);
@@ -179,15 +155,23 @@ public class ResourceManagerView extends ViewPart {
         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
         resourceGroup.setLayoutData(gd);
 
-        resourceTreeHead = new Tree(resourceGroup, SWT.SINGLE);
-
-        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-
-        resourceTreeHead.setLayoutData(gd);
+        PatternFilter filter = new PatternFilter();
+        FilteredTree filteredTree = new FilteredTree(resourceGroup,
+                SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE, filter, true);
+        treeViewer = filteredTree.getViewer();
+        treeViewer.getTree().setLayoutData(
+                new GridData(SWT.FILL, SWT.FILL, true, true));
+        treeViewer.setContentProvider(new TreeContentProvider());
+        treeViewer.setLabelProvider(new TreeLabelProvider());
+        treeViewer.setInput(new Object());
 
         addUIListeners();
 
         addManagerListeners();
+
+        // If there is at least one resource exist, then enable the delete
+        // resource button
+        changeDeleteVisibility();
     }
 
     private void addUIListeners() {
@@ -210,20 +194,13 @@ public class ResourceManagerView extends ViewPart {
                             configFilePath = createWizard.getConfigFilePath();
                             count = createWizard.getResourceCount();
 
-                            // Create the resource
-                            if (null != configFilePath
-                                    && configFilePath.length() > 0) {
-                                if (count <= 1) {
-                                    // Single resource creation
-                                    // TODO: Temporary code to show the resource
-                                    // in UI
-                                    Activator.getManager().createResource(
-                                            configFilePath);
-                                } else {
-                                    // Multi resource creation
-                                    // Activator.getDefault().getManager().createResource(configFilePath,
-                                    // count);
-                                }
+                            if (count <= 1) {
+                                // Single resource creation
+                                resourceManager.createResource(configFilePath);
+                            } else {
+                                // Multi-resource creation
+                                resourceManager.createResource(configFilePath,
+                                        count);
                             }
                         }
                     }
@@ -244,69 +221,210 @@ public class ResourceManagerView extends ViewPart {
                                         .getActiveShell(), deleteWizard);
                         int open = wizardDialog.open();
                         if (open == WizardDialog.OK) {
-                            if (deleteWizard.getDeleteCategory() == DeleteCategory.BY_URI) {
+                            DeleteCategory deleteCategory = deleteWizard
+                                    .getDeleteCategory();
+                            if (deleteCategory == DeleteCategory.BY_URI) {
                                 String uri = deleteWizard.getDeleteCandidate();
-                                boolean completeURI = Convertion
+                                boolean completeURI = Utility
                                         .isUriComplete(uri);
                                 if (!completeURI) {
-                                    uri = Convertion.displayNameToUri(uri);
+                                    uri = Utility.displayNameToUri(uri);
                                 }
-                                Activator.getManager().deleteResourceByURI(uri);
-                            } else if (deleteWizard.getDeleteCategory() == DeleteCategory.BY_TYPE) {
-                                Activator.getManager().deleteResourceByType(
-                                        deleteWizard.getDeleteCandidate());
-                            } else if (deleteWizard.getDeleteCategory() == DeleteCategory.ALL) {
-                                Activator.getManager().deleteAllResources();
+                                resourceManager.deleteResourceByURI(uri);
+                            } else if (deleteCategory == DeleteCategory.BY_TYPE) {
+                                resourceManager
+                                        .deleteResourceByType(deleteWizard
+                                                .getDeleteCandidate());
+                            } else if (deleteCategory == DeleteCategory.ALL) {
+                                resourceManager.deleteAllResources();
                             }
                         }
                     }
-
                 });
             }
         });
 
-        resourceTreeHead.addSelectionListener(new SelectionAdapter() {
-            @Override
-            public void widgetSelected(SelectionEvent e) {
-                TreeItem[] selectedItems = resourceTreeHead.getSelection();
-                // Handling only single item selection events
-                if (1 == selectedItems.length) {
-                    String selectedItem = selectedItems[0].getText();
-                    // Check whether the selected item is a resource category or
-                    // a specific resource
-                    boolean category = isSelectedTreeItemACategory(selectedItem);
-                    if (!category) {
-                        // TODO: Show the properties in the properties view
+        if (null != treeViewer) {
+            final Tree resourceTreeHead = treeViewer.getTree();
+            if (null != resourceTreeHead) {
+                // Below code adds a listener to the tree for selection changes
+                // and notifies the resource manager
+                resourceTreeHead.addSelectionListener(new SelectionAdapter() {
+                    @Override
+                    public void widgetSelected(SelectionEvent e) {
+                        TreeItem selectedItem = (TreeItem) e.item;
+                        if (null != selectedItem) {
+                            String selectedItemText = selectedItem.getText();
+                            if (!isSelectedTreeItemACategory(selectedItemText)) {
+                                selectedItemText = Utility
+                                        .displayNameToUri(selectedItemText);
+                            }
+                            // Propagate this selection change event to manager
+                            resourceManager
+                                    .resourceSelectionChanged(selectedItemText);
+                        }
                     }
-
-                }
+                });
+                // 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();
+                        }
+                        final String selectedItem = resourceTreeHead
+                                .getSelection()[0].getText();
+                        if (isSelectedTreeItemACategory(selectedItem)) {
+                            return;
+                        }
+                        MenuItem startItem = new MenuItem(menu, SWT.NONE);
+                        startItem.setText(Constants.START_RESOURCE_AUTOMATION);
+                        startItem.addSelectionListener(new SelectionAdapter() {
+                            @Override
+                            public void widgetSelected(SelectionEvent e) {
+                                // Block starting resource level
+                                // automation if any attribute level
+                                // automation is in progress for the
+                                // selected resource
+                                boolean started = resourceManager.isAttributeAutomationStarted(Utility
+                                        .displayNameToUri(selectedItem));
+                                if (started) {
+                                    MessageDialog
+                                            .openInformation(
+                                                    Display.getDefault()
+                                                            .getActiveShell(),
+                                                    "Attribute automation is in progress",
+                                                    "Attribute level automation for this resource is already in progress!!!\nPlease stop all "
+                                                            + "running attribute level automations to start resource level automation.");
+                                } else {
+                                    boolean status = resourceManager
+                                            .startResourceAutomationUIRequest(Utility
+                                                    .displayNameToUri(selectedItem));
+                                    String statusMsg = status ? "Automation started successfully!!!"
+                                            : "Automation request failed!!!";
+                                    MessageDialog.openInformation(Display
+                                            .getDefault().getActiveShell(),
+                                            "Automation Status", statusMsg);
+                                }
+                            }
+                        });
+
+                        MenuItem stopItem = new MenuItem(menu, SWT.NONE);
+                        stopItem.setText(Constants.STOP_RESOURCE_AUTOMATION);
+                        stopItem.addSelectionListener(new SelectionAdapter() {
+                            @Override
+                            public void widgetSelected(SelectionEvent e) {
+                                resourceManager
+                                        .stopResourceAutomationUIRequest(Utility
+                                                .displayNameToUri(selectedItem));
+                                String statusMsg = "Automation stop requested!!!";
+                                MessageDialog.openInformation(Display
+                                        .getDefault().getActiveShell(),
+                                        "Automation Status", statusMsg);
+                            }
+                        });
+
+                        // Set the initial visibility of menu items
+                        boolean status = resourceManager
+                                .isResourceAutomationStarted(Utility
+                                        .displayNameToUri(selectedItem));
+                        startItem.setEnabled(!status);
+                        stopItem.setEnabled(status);
+                    }
+                });
             }
-        });
+        }
     }
 
     private boolean isSelectedTreeItemACategory(String selectedItem) {
         boolean category = false;
-        TreeItem[] items = resourceTreeHead.getItems();
-        if (null != items) {
-            for (TreeItem item : items) {
-                if (item.getText().equals(selectedItem)) {
-                    category = true;
-                    break;
-                }
-            }
+        if (null != selectedItem) {
+            category = resourceManager.isTypeExist(selectedItem);
         }
         return category;
     }
 
     public void addManagerListeners() {
-        ResourceManager manager = Activator.getManager();
-        manager.setResourceListChangedListener(resourceListChangedListener);
+        resourceManager
+                .addResourceListChangedUIListener(resourceListChangedListener);
     }
 
     @Override
     public void setFocus() {
-        // TODO Auto-generated method stub
+    }
+
+    @Override
+    public void dispose() {
+        // Unregister the listener
+        if (null != resourceListChangedListener) {
+            resourceManager
+                    .removeResourceListChangedUIListener(resourceListChangedListener);
+            resourceManager.resourceSelectionChanged(null);
+        }
+        super.dispose();
+    }
+}
+
+class TreeContentProvider implements ITreeContentProvider {
+
+    @Override
+    public void dispose() {
+    }
+
+    @Override
+    public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+    }
 
+    @Override
+    public Object[] getChildren(Object parent) {
+        String resType = (String) parent;
+        List<String> members;
+        members = Activator.getDefault().getResourceManager()
+                .getURIListOfResourceType(resType);
+        if (null == members) {
+            members = new ArrayList<String>();
+        }
+        return members.toArray();
+    }
+
+    @Override
+    public Object[] getElements(Object parent) {
+        List<String> deptTypes;
+        deptTypes = Activator.getDefault().getResourceManager()
+                .getResourceTypeList();
+        if (null == deptTypes) {
+            deptTypes = new ArrayList<String>();
+        }
+        return deptTypes.toArray();
     }
 
+    @Override
+    public Object getParent(Object child) {
+        return null;
+    }
+
+    @Override
+    public boolean hasChildren(Object parent) {
+        String resType = (String) parent;
+        if (Activator.getDefault().getResourceManager().isTypeExist(resType)) {
+            return true;
+        }
+        return false;
+    }
 }
+
+class TreeLabelProvider extends LabelProvider {
+    @Override
+    public String getText(Object element) {
+        String value = (String) element;
+        if (!Activator.getDefault().getResourceManager().isTypeExist(value)) {
+            value = Utility.uriToDisplayName(value);
+        }
+        return value;
+    }
+}
\ No newline at end of file
index b2c23ba..345c0dd 100644 (file)
@@ -1,5 +1,7 @@
 package oic.simulator.serviceprovider.view.dialogs;
 
+import oic.simulator.serviceprovider.utils.Constants;
+
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
@@ -44,8 +46,8 @@ public class CreateResourcePage extends WizardPage {
     @Override
     public void createControl(Composite parent) {
         setPageComplete(false);
-        setTitle("Create Resource");
-        setMessage("Select a standard resource or custom resource to be created");
+        setTitle(Constants.CREATE_PAGE_TITLE);
+        setMessage(Constants.CREATE_PAGE_MESSAGE);
         Composite compContent = new Composite(parent, SWT.NONE);
         GridLayout gridLayout = new GridLayout(1, false);
         compContent.setLayout(gridLayout);
@@ -140,7 +142,7 @@ public class CreateResourcePage extends WizardPage {
     }
 
     private void populateDataInUI() {
-        // Populate Resourcetype in Combo
+        // Populate Resource-type in Combo
         populateResourceTypeCombo();
     }
 
@@ -211,6 +213,8 @@ public class CreateResourcePage extends WizardPage {
             public void widgetSelected(SelectionEvent e) {
                 FileDialog fileDialog = new FileDialog(PlatformUI
                         .getWorkbench().getDisplay().getActiveShell(), SWT.NONE);
+                fileDialog
+                        .setFilterExtensions(Constants.BROWSE_RAML_FILTER_EXTENSIONS);
                 String configFileAbsolutePath = fileDialog.open();
                 locationTxt.setText(configFileAbsolutePath);
             }
@@ -265,7 +269,7 @@ public class CreateResourcePage extends WizardPage {
         });
     }
 
-    public boolean isSelectionDone() {
+    private boolean isSelectionDone() {
         boolean done = false;
         try {
             resourceCount = Integer.parseInt(noOfInstancesText.getText());
@@ -277,7 +281,7 @@ public class CreateResourcePage extends WizardPage {
         }
 
         if (null != configFilePath && configFilePath.length() > 0
-                && resourceCount >= 0) {
+                && resourceCount >= 1) {
             done = true;
         }
         return done;
@@ -290,5 +294,4 @@ public class CreateResourcePage extends WizardPage {
     public int getResourceCount() {
         return resourceCount;
     }
-
-}
+}
\ No newline at end of file
index 5d1e74f..5beab41 100644 (file)
@@ -1,5 +1,13 @@
 package oic.simulator.serviceprovider.view.dialogs;
 
+import java.net.URL;
+
+import oic.simulator.serviceprovider.Activator;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.wizard.Wizard;
 
 public class CreateResourceWizard extends Wizard {
@@ -8,6 +16,10 @@ public class CreateResourceWizard extends Wizard {
 
     public CreateResourceWizard() {
         setWindowTitle("Create resources");
+        IPath path = new Path("/icons/oic_logo_64x64.png");
+        URL find = FileLocator.find(Activator.getDefault().getBundle(), path,
+                null);
+        setDefaultPageImageDescriptor(ImageDescriptor.createFromURL(find));
     }
 
     @Override
@@ -28,5 +40,4 @@ public class CreateResourceWizard extends Wizard {
     public boolean performFinish() {
         return true;
     }
-
-}
+}
\ No newline at end of file
index bf1b32a..1272079 100644 (file)
@@ -4,6 +4,7 @@ import java.util.Iterator;
 import java.util.List;
 
 import oic.simulator.serviceprovider.Activator;
+import oic.simulator.serviceprovider.utils.Constants;
 
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
@@ -39,10 +40,9 @@ public class DeleteResourcePage extends WizardPage {
 
     @Override
     public void createControl(Composite parent) {
-        System.out.println("delete wizard open");
         setPageComplete(false);
-        setTitle("Delete Resource");
-        setMessage("Select the resource(s) to be deleted");
+        setTitle(Constants.DELETE_PAGE_TITLE);
+        setMessage(Constants.DELETE_PAGE_MESSAGE);
 
         Composite compContent = new Composite(parent, SWT.NONE);
         compContent.setLayout(new GridLayout(1, false));
@@ -113,7 +113,8 @@ public class DeleteResourcePage extends WizardPage {
     private void populateResourceTypeCombo() {
 
         List<String> resourceTypeList;
-        resourceTypeList = Activator.getManager().getResourceTypeList();
+        resourceTypeList = Activator.getDefault().getResourceManager()
+                .getResourceTypeList();
         if (null != resourceTypeList) {
             Iterator<String> itr = resourceTypeList.iterator();
             while (itr.hasNext()) {
@@ -160,6 +161,7 @@ public class DeleteResourcePage extends WizardPage {
             public void widgetSelected(SelectionEvent e) {
                 // Update the visibility of controls
                 resourceUriTxt.setEnabled(true);
+                resourceUriTxt.setFocus();
                 resourceTypeCmb.setEnabled(false);
 
                 deleteCategory = DeleteCategory.BY_URI;
@@ -214,4 +216,4 @@ public class DeleteResourcePage extends WizardPage {
     public void setFocusToTextBox() {
         resourceUriTxt.setFocus();
     }
-}
+}
\ No newline at end of file
index 3d8fa0b..8b9a3b6 100644 (file)
@@ -1,9 +1,15 @@
 package oic.simulator.serviceprovider.view.dialogs;
 
+import java.net.URL;
+
 import oic.simulator.serviceprovider.Activator;
-import oic.simulator.serviceprovider.utils.Convertion;
+import oic.simulator.serviceprovider.utils.Utility;
 
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
 import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.PlatformUI;
@@ -14,6 +20,10 @@ public class DeleteResourceWizard extends Wizard {
 
     public DeleteResourceWizard() {
         setWindowTitle("Delete resources");
+        IPath path = new Path("/icons/oic_logo_64x64.png");
+        URL find = FileLocator.find(Activator.getDefault().getBundle(), path,
+                null);
+        setDefaultPageImageDescriptor(ImageDescriptor.createFromURL(find));
     }
 
     @Override
@@ -29,11 +39,12 @@ public class DeleteResourceWizard extends Wizard {
             // Check whether the uri is in full form or short form
             // If it is in short form, expand it to its full form.
             String uri = page.getDeleteCandidate();
-            boolean uriComplete = Convertion.isUriComplete(uri);
+            boolean uriComplete = Utility.isUriComplete(uri);
             if (!uriComplete) {
-                uri = Convertion.displayNameToUri(uri);
+                uri = Utility.displayNameToUri(uri);
             }
-            boolean exist = Activator.getManager().isResourceExist(uri);
+            boolean exist = Activator.getDefault().getResourceManager()
+                    .isResourceExist(uri);
             if (!exist) {
                 Shell activeShell = PlatformUI.getWorkbench().getDisplay()
                         .getActiveShell();
@@ -56,4 +67,4 @@ public class DeleteResourceWizard extends Wizard {
     public String getDeleteCandidate() {
         return page.getDeleteCandidate();
     }
-}
+}
\ No newline at end of file
diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/FilterDialog.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/FilterDialog.java
new file mode 100644 (file)
index 0000000..e0f4397
--- /dev/null
@@ -0,0 +1,75 @@
+package oic.simulator.serviceprovider.view.dialogs;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Map;
+
+import oic.simulator.serviceprovider.manager.LogManager;
+
+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;
+
+public class FilterDialog extends TrayDialog {
+    private Map<Integer, Boolean> severities;
+
+    public FilterDialog(Shell shell, Map<Integer, Boolean> severities) {
+        super(shell);
+        this.severities = severities;
+    }
+
+    @Override
+    protected void configureShell(Shell shell) {
+        super.configureShell(shell);
+    }
+
+    @Override
+    protected Control createDialogArea(Composite parent) {
+        Composite composite = (Composite) super.createDialogArea(parent);
+        createSeverityGroup(composite);
+        getShell().setText("Filter details");
+        return composite;
+    }
+
+    /**
+     * Dynamically creates a check-box list for severity levels for user to
+     * choose from
+     */
+    private void createSeverityGroup(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("Severity Levels");
+
+        ArrayList<Integer> arrayList = new ArrayList<Integer>(
+                severities.keySet());
+        Collections.sort(arrayList);
+        for (final Integer i : arrayList) {
+            final Button checkbox = new Button(group, SWT.CHECK);
+            checkbox.setText(LogManager.getSeverityName(i));
+            checkbox.setSelection(severities.get(i));
+            checkbox.addSelectionListener(new SelectionAdapter() {
+
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    severities.put(i, checkbox.getSelection());
+                }
+            });
+        }
+    }
+
+    @Override
+    public boolean isHelpAvailable() {
+        return false;
+    }
+}
\ No newline at end of file