X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Futil%2FCmsUiUtils.java;h=c96e77b62649ce74b76f1e0e7c7a0f80b580af1a;hb=1e077d22f485d504491e65579258925b53bf1a3c;hp=39df49ebfba4f60689fc59eda53eaf95aedfe317;hpb=b6976ad6a8bdff4ab9dc9176b20e51bfdfa5a74d;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 39df49ebf..c96e77b62 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 @@ -133,21 +133,39 @@ public class CmsUiUtils implements CmsConstants { /** * Apply markup and set text on {@link Label}, {@link Button}, {@link Text}. * + * @param widget the widget to style and to use in order to display text + * @param txt the object to display via its toString() method. + * This argument should not be null, but if it is null and + * assertions are disabled "" is displayed instead; if + * assertions are enabled the call will fail. + * * @see #markup(Widget) */ - public static T text(T widget, String txt) { + public static T text(T widget, Object txt) { + assert txt != null; + String str = txt != null ? txt.toString() : ""; markup(widget); if (widget instanceof Label) - ((Label) widget).setText(txt); + ((Label) widget).setText(str); else if (widget instanceof Button) - ((Button) widget).setText(txt); + ((Button) widget).setText(str); else if (widget instanceof Text) - ((Text) widget).setText(txt); + ((Text) widget).setText(str); else throw new IllegalArgumentException("Unsupported widget type " + widget.getClass()); return widget; } + /** A {@link Label} with markup activated. */ + public static Label lbl(Composite parent, Object txt) { + return text(new Label(parent, SWT.NONE), txt); + } + + /** A read-only {@link Text} whose content can be copy/pasted. */ + public static Text txt(Composite parent, Object txt) { + return text(new Text(parent, SWT.NONE), txt); + } + public static void setItemHeight(Table table, int height) { table.setData(CmsConstants.ITEM_HEIGHT, height); }