From e0a9791b34d3ae703716801513efb7b75b97b789 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Mon, 1 Feb 2021 17:15:25 +0100 Subject: [PATCH] Store UI context data in CMS View. --- .../org/argeo/cms/web/CmsWebEntryPoint.java | 21 +++++++++++++++++++ .../src/org/argeo/cms/ui/CmsView.java | 10 ++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/org.argeo.cms.ui.rap/src/org/argeo/cms/web/CmsWebEntryPoint.java b/org.argeo.cms.ui.rap/src/org/argeo/cms/web/CmsWebEntryPoint.java index 1ad09d102..288069bd9 100644 --- a/org.argeo.cms.ui.rap/src/org/argeo/cms/web/CmsWebEntryPoint.java +++ b/org.argeo.cms.ui.rap/src/org/argeo/cms/web/CmsWebEntryPoint.java @@ -117,6 +117,9 @@ public class CmsWebEntryPoint implements EntryPoint, CmsView, BrowserNavigationL ui = cmsWebApp.getCmsApp().initUi(parent); ui.setData(CmsApp.UI_NAME_PROPERTY, uiName); ui.setLayoutData(CmsUiUtils.fillAll()); + // we need ui to be set before refresh so that CmsView can store UI context data + // in it. + cmsWebApp.getCmsApp().refreshUi(ui, null); } catch (Exception e) { throw new IllegalStateException("Cannot create entrypoint contents", e); } @@ -260,6 +263,24 @@ public class CmsWebEntryPoint implements EntryPoint, CmsView, BrowserNavigationL return cmsSession; } + @Override + public Object getData(String key) { + if (ui != null) { + return ui.getData(key); + } else { + throw new IllegalStateException("UI is not initialized"); + } + } + + @Override + public void setData(String key, Object value) { + if (ui != null) { + ui.setData(key, value); + } else { + throw new IllegalStateException("UI is not initialized"); + } + } + /* * EntryPoint IMPLEMENTATION */ diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/CmsView.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/CmsView.java index e18d4b433..44e2837ec 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/CmsView.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/CmsView.java @@ -37,7 +37,7 @@ public interface CmsView { boolean isAnonymous(); /** - * Send an event to this topic. Does noothing by default., but if implemented it + * Send an event to this topic. Does nothing by default., but if implemented it * MUST set the {@link #CMS_VIEW_UID_PROPERTY} in the properties. */ default void sendEvent(String topic, Map properties) { @@ -81,6 +81,14 @@ public interface CmsView { throw new UnsupportedOperationException(); } + default Object getData(String key) { + throw new UnsupportedOperationException(); + } + + default void setData(String key, Object value) { + throw new UnsupportedOperationException(); + } + static CmsView getCmsView(Control parent) { // find parent shell Shell topShell = parent.getShell(); -- 2.30.2