From b8574f23bc481770c5dedd2c3b08305a7b6e6c6d Mon Sep 17 00:00:00 2001
From: Stefano Borini <sborini@enthought.com>
Date: Tue, 22 Aug 2017 11:31:40 +0100
Subject: [PATCH] Added extension point for UI hooks

---
 force_bdss/factory_registry_plugin.py | 31 +++++++++++++++++++++++++--
 force_bdss/ids.py                     |  1 +
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/force_bdss/factory_registry_plugin.py b/force_bdss/factory_registry_plugin.py
index 67e7851..3042d07 100644
--- a/force_bdss/factory_registry_plugin.py
+++ b/force_bdss/factory_registry_plugin.py
@@ -9,6 +9,7 @@ from .data_sources.i_data_source_factory import (
     IDataSourceFactory)
 from .kpi.i_kpi_calculator_factory import IKPICalculatorFactory
 from .mco.i_mco_factory import IMCOFactory
+from .ui_hooks.i_ui_hooks_factory import IUIHooksFactory
 
 
 FACTORY_REGISTRY_PLUGIN_ID = "force.bdss.plugins.factory_registry"
@@ -50,6 +51,11 @@ class FactoryRegistryPlugin(Plugin):
         id=ExtensionPointID.NOTIFICATION_LISTENER_FACTORIES
     )
 
+    ui_hooks_factories = ExtensionPoint(
+        List(IUIHooksFactory),
+        id=ExtensionPointID.UI_HOOK_FACTORIES
+    )
+
     def data_source_factory_by_id(self, id):
         """Finds a given data source factory by means of its id.
         The ID is as obtained by the function factory_id() in the
@@ -140,13 +146,13 @@ class FactoryRegistryPlugin(Plugin):
 
     def notification_listener_factory_by_id(self, id):
         """Finds a given notification listener by means of its id.
-        The ID is as obtained by the function bundle_id() in the
+        The ID is as obtained by the function factory_id() in the
         plugin api.
 
         Parameters
         ----------
         id: str
-            The identifier returned by the bundle_id() function.
+            The identifier returned by the factory_id() function.
 
         Raises
         ------
@@ -157,3 +163,24 @@ class FactoryRegistryPlugin(Plugin):
                 return nl
 
         raise KeyError(id)
+
+    def ui_hook_factory_by_id(self, id):
+        """Finds a given UI Hook factory by means of its id.
+        The ID is as obtained by the function factory_id() in the
+        plugin api.
+
+        Parameters
+        ----------
+        id: str
+            The identifier returned by the factory_id() function.
+
+        Raises
+        ------
+        KeyError: if the entry is not found.
+        """
+        for hook in self.ui_hooks_factories:
+            if hook.id == id:
+                return hook
+
+        raise KeyError(id)
+
diff --git a/force_bdss/ids.py b/force_bdss/ids.py
index 336b64a..d8657fd 100644
--- a/force_bdss/ids.py
+++ b/force_bdss/ids.py
@@ -14,6 +14,7 @@ class ExtensionPointID:
     KPI_CALCULATOR_FACTORIES = 'force.bdss.kpi_calculator.factories'
     NOTIFICATION_LISTENER_FACTORIES = \
         'force.bdss.notification_listener.factories'
+    UI_HOOK_FACTORIES = 'force.bdss.ui_hook.factories'
 
 
 def factory_id(producer, identifier):
-- 
GitLab