Add text() utility to CMS utils.
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 23 Oct 2019 08:29:23 +0000 (10:29 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 23 Oct 2019 08:29:23 +0000 (10:29 +0200)
org.argeo.cms.ui/src/org/argeo/cms/util/CmsUtils.java

index 0c6eb53d4022dbbb496381db6e450006d4444f13..f4004e493123c75426e3a82b10289ef7491dc516 100644 (file)
@@ -25,10 +25,13 @@ import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.Widget;
 
 /** Static utilities for the CMS framework. */
@@ -127,6 +130,24 @@ public class CmsUtils implements CmsConstants {
                return widget;
        }
 
+       /**
+        * Apply markup and set text on {@link Label}, {@link Button}, {@link Text}.
+        * 
+        * @see #markup(Widget)
+        */
+       public static <T extends Widget> T text(T widget, String txt) {
+               markup(widget);
+               if (widget instanceof Label)
+                       ((Label) widget).setText(txt);
+               else if (widget instanceof Button)
+                       ((Button) widget).setText(txt);
+               else if (widget instanceof Text)
+                       ((Text) widget).setText(txt);
+               else
+                       throw new IllegalArgumentException("Unsupported widget type " + widget.getClass());
+               return widget;
+       }
+
        public static void setItemHeight(Table table, int height) {
                table.setData(CmsConstants.ITEM_HEIGHT, height);
        }