X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Futil%2FCmsUiUtils.java;h=303fb7deadb81d78905acca58645d3b6ca0e9a6c;hb=d289fa62f9dadd0a5bd49ab5e3d499e87152525d;hp=167d7341f441748bf1e4bd99d4126572de794f84;hpb=dffc0df8766937ad0863d389883cba2ebac835d6;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsUiUtils.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsUiUtils.java index 167d7341f..303fb7dea 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsUiUtils.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsUiUtils.java @@ -4,6 +4,8 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.util.HashMap; +import java.util.Map; import javax.jcr.Node; import javax.jcr.RepositoryException; @@ -14,13 +16,17 @@ import org.argeo.api.NodeUtils; import org.argeo.cms.CmsException; import org.argeo.cms.ui.CmsConstants; import org.argeo.cms.ui.CmsView; +import org.argeo.eclipse.ui.Selected; import org.argeo.jcr.JcrUtils; import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.service.ResourceManager; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.RowData; @@ -37,6 +43,31 @@ import org.eclipse.swt.widgets.Widget; public class CmsUiUtils implements CmsConstants { // private final static Log log = LogFactory.getLog(CmsUiUtils.class); + /* + * CMS VIEW + */ + + /** Sends an event via {@link CmsView#sendEvent(String, Map)}. */ + public static void sendEventOnSelect(Control control, String topic, Map properties) { + SelectionListener listener = (Selected) (e) -> { + CmsView.getCmsView(control.getParent()).sendEvent(topic, properties); + }; + if (control instanceof Button) { + ((Button) control).addSelectionListener(listener); + } else + throw new UnsupportedOperationException("Control type " + control.getClass() + " is not supported."); + } + + /** + * Convenience method to sends an event via + * {@link CmsView#sendEvent(String, Map)}. + */ + public static void sendEventOnSelect(Control control, String topic, String key, Object value) { + Map properties = new HashMap<>(); + properties.put(key, value); + sendEventOnSelect(control, topic, properties); + } + /** * The CMS view related to this display, or null if none is available from this * call. @@ -86,6 +117,9 @@ public class CmsUiUtils implements CmsConstants { @Deprecated public static RowData ROW_DATA_16px = new RowData(16, 16); + /* + * GRID LAYOUT + */ public static GridLayout noSpaceGridLayout() { return noSpaceGridLayout(new GridLayout()); } @@ -102,9 +136,6 @@ public class CmsUiUtils implements CmsConstants { return layout; } - // - // GRID DATA - // public static GridData fillAll() { return new GridData(SWT.FILL, SWT.FILL, true, true); } @@ -129,6 +160,23 @@ public class CmsUiUtils implements CmsConstants { return new RowData(16, 16); } + /* + * FORM LAYOUT + */ + + public static FormData coversAll() { + FormData fdLabel = new FormData(); + fdLabel.top = new FormAttachment(0, 0); + fdLabel.left = new FormAttachment(0, 0); + fdLabel.right = new FormAttachment(100, 0); + fdLabel.bottom = new FormAttachment(100, 0); + return fdLabel; + } + + /* + * STYLING + */ + /** Style widget */ public static T style(T widget, String style) { widget.setData(CmsConstants.STYLE, style);