X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2FCmsView.java;h=8011dce59a9af024ef40ecb025c30cde7e80be31;hb=fea7cd546f9c04c00f961918919dd6307c32cc8e;hp=6d70935d7e4a0ffd9d8205cac0404dc97fdbf2ff;hpb=d66d81530f1da58e2e2c5d25e0a5dc30ad32b848;p=lgpl%2Fargeo-commons.git 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 6d70935d7..8011dce59 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 @@ -1,10 +1,20 @@ package org.argeo.cms.ui; +import java.security.PrivilegedAction; +import java.util.HashMap; +import java.util.Map; + import javax.security.auth.login.LoginContext; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + /** Provides interaction with the CMS system. */ public interface CmsView { - String KEY = "org.argeo.cms.ui.view"; + final static String CMS_VIEW_UID_PROPERTY = "argeo.cms.view.uid"; + // String KEY = "org.argeo.cms.ui.view"; + + String getUid(); UxContext getUxContext(); @@ -24,4 +34,52 @@ public interface CmsView { CmsImageManager getImageManager(); boolean isAnonymous(); + + /** + * Send an event to this topic. Does noothing by default., but if implemented it + * MUST set the {@link #CMS_VIEW_UID_PROPERTY} in the properties. + */ + default void sendEvent(String topic, Map properties) { + + } + + /** + * Convenience methods for when {@link #sendEvent(String, Map)} only requires + * one single parameter. + */ + default void sendEvent(String topic, String param, Object value) { + Map properties = new HashMap<>(); + properties.put(param, value); + sendEvent(topic, properties); + } + + default void applyStyles(Object widget) { + + } + + default T doAs(PrivilegedAction action) { + throw new UnsupportedOperationException(); + } + + static CmsView getCmsView(Control parent) { + // find parent shell + Shell topShell = parent.getShell(); + while (topShell.getParent() != null) + topShell = (Shell) topShell.getParent(); + return (CmsView) topShell.getData(CmsView.class.getName()); + } + + static void registerCmsView(Shell shell, CmsView view) { + // find parent shell + Shell topShell = shell; + while (topShell.getParent() != null) + topShell = (Shell) topShell.getParent(); + // check if already set + if (topShell.getData(CmsView.class.getName()) != null) { + CmsView registeredView = (CmsView) topShell.getData(CmsView.class.getName()); + throw new IllegalArgumentException("Cms view " + registeredView + " already registered in this shell"); + } + shell.setData(CmsView.class.getName(), view); + } + }