X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2FCmsView.java;h=f8ab3a6821cf09860bdb052e6b118c377d3053ed;hb=94ec9b5a0282c8119ee9831688124bc96f3a62b8;hp=0e7e7268042a64650a9979acb5e03dba53dd5553;hpb=d289fa62f9dadd0a5bd49ab5e3d499e87152525d;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 0e7e72680..f8ab3a682 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,13 @@ 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.Composite; +import org.argeo.cms.auth.CmsSession; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** Provides interaction with the CMS system. */ @@ -34,14 +37,68 @@ 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) { } - static CmsView getCmsView(Composite parent) { + /** + * 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(); + } + + default Void runAs(Runnable runnable) { + return doAs(new PrivilegedAction() { + + @Override + public Void run() { + if (runnable != null) + runnable.run(); + return null; + } + }); + } + + default void stateChanged(String state, String title) { + } + + default CmsSession getCmsSession() { + throw new UnsupportedOperationException(); + } + + default Object getData(String key) { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings("unchecked") + default T getUiContext(Class clss) { + return (T) getData(clss.getName()); + } + + default void setUiContext(Class clss, T instance) { + setData(clss.getName(), instance); + } + + default void setData(String key, Object value) { + throw new UnsupportedOperationException(); + } + + static CmsView getCmsView(Control parent) { // find parent shell Shell topShell = parent.getShell(); while (topShell.getParent() != null)