Improve single sourcing.
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 14 Oct 2020 08:18:30 +0000 (10:18 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 14 Oct 2020 08:18:30 +0000 (10:18 +0200)
org.argeo.cms.ui/src/org/argeo/cms/ui/CmsConstants.java
org.argeo.cms.ui/src/org/argeo/cms/ui/CmsView.java
org.argeo.cms.ui/src/org/argeo/cms/ui/util/CmsUiUtils.java
org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/EclipseUiConstants.java [new file with mode: 0644]

index 53e2aee6c8d137ae6e70c649650491b0263e744a..15716850842fc6d63e7705ac50760b4b1415cc0a 100644 (file)
@@ -1,17 +1,21 @@
 package org.argeo.cms.ui;
 
-import org.eclipse.rap.rwt.RWT;
+import org.argeo.eclipse.ui.specific.EclipseUiConstants;
 import org.eclipse.swt.graphics.Point;
 
 /** Commons constants */
 public interface CmsConstants {
        // DATAKEYS
-       public final static String STYLE = RWT.CUSTOM_VARIANT;
-       public final static String MARKUP = RWT.MARKUP_ENABLED;
-       public final static String ITEM_HEIGHT = RWT.CUSTOM_ITEM_HEIGHT;
+       public final static String STYLE = EclipseUiConstants.CSS_CLASS;
+       public final static String MARKUP = EclipseUiConstants.MARKUP_SUPPORT;
+       @Deprecated
+       /* RWT.CUSTOM_ITEM_HEIGHT */
+       public final static String ITEM_HEIGHT = "org.eclipse.rap.rwt.customItemHeight";
 
        // EVENT DETAILS
-       public final static int HYPERLINK = RWT.HYPERLINK;
+       @Deprecated
+       /* RWT.HYPERLINK */
+       public final static int HYPERLINK = 1 << 26;
 
        // STANDARD RESOURCES
        public final static String LOADING_IMAGE = "icons/loading.gif";
index 9f5e4f7973f9e35f29b37dca5199ca9b88814e2d..b403a2088d33fbfcb703c49c1bdf11762eca4b6d 100644 (file)
@@ -51,6 +51,10 @@ public interface CmsView {
                properties.put(param, value);
                sendEvent(topic, properties);
        }
+       
+       default void applyStyles(Object widget) {
+               
+       }
 
        static CmsView getCmsView(Composite parent) {
                // find parent shell
index 915b033365d8adab08ab6ab538e088fd946ca183..4e5572dbde6f19cf9bb9e84f683b45bd9100ac73 100644 (file)
@@ -181,18 +181,20 @@ public class CmsUiUtils implements CmsConstants {
                if (style == null)
                        return widget;// does nothing
                widget.setData(CmsConstants.STYLE, style);
+               if (widget instanceof Control)
+                       CmsView.getCmsView(((Control) widget).getParent()).applyStyles(widget);
                return widget;
        }
 
        /** Style widget */
        public static <T extends Widget> T style(T widget, CmsStyle style) {
-               widget.setData(CmsConstants.STYLE, style.toStyleClass());
-               return widget;
+               return style(widget, style.toStyleClass());
        }
 
        /** Enable markups on widget */
        public static <T extends Widget> T markup(T widget) {
-               widget.setData(CmsConstants.MARKUP, true);
+               if (CmsConstants.MARKUP != null)
+                       widget.setData(CmsConstants.MARKUP, true);
                return widget;
        }
 
@@ -232,6 +234,7 @@ public class CmsUiUtils implements CmsConstants {
                return text(new Text(parent, SWT.NONE), txt);
        }
 
+       @Deprecated
        public static void setItemHeight(Table table, int height) {
                table.setData(CmsConstants.ITEM_HEIGHT, height);
        }
diff --git a/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/EclipseUiConstants.java b/org.argeo.eclipse.ui.rap/src/org/argeo/eclipse/ui/specific/EclipseUiConstants.java
new file mode 100644 (file)
index 0000000..76ad973
--- /dev/null
@@ -0,0 +1,9 @@
+package org.argeo.eclipse.ui.specific;
+
+import org.eclipse.rap.rwt.RWT;
+
+/** Constants which are specific to RWT.*/
+public interface EclipseUiConstants {
+       final static String CSS_CLASS = RWT.CUSTOM_VARIANT;
+       final static String MARKUP_SUPPORT = RWT.MARKUP_ENABLED;
+}