Explicitly specify server base for img.
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / ui / util / CmsUiUtils.java
index 303fb7deadb81d78905acca58645d3b6ca0e9a6c..428c910e54133dee353aa8d034ffc388fb8f30a5 100644 (file)
@@ -13,10 +13,10 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.argeo.api.NodeConstants;
 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.eclipse.ui.specific.EclipseUiSpecificUtils;
 import org.argeo.jcr.JcrUtils;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.service.ResourceManager;
@@ -89,7 +89,7 @@ public class CmsUiUtils implements CmsConstants {
                                buf.append(':').append(url.getPort());
                        return buf;
                } catch (MalformedURLException e) {
-                       throw new CmsException("Cannot extract server base URL from " + request.getRequestURL(), e);
+                       throw new IllegalArgumentException("Cannot extract server base URL from " + request.getRequestURL(), e);
                }
        }
 
@@ -100,7 +100,7 @@ public class CmsUiUtils implements CmsConstants {
                        buf.append(getDataPath(node));
                        return new URL(buf.toString()).toString();
                } catch (MalformedURLException e) {
-                       throw new CmsException("Cannot build data URL for " + node, e);
+                       throw new IllegalArgumentException("Cannot build data URL for " + node, e);
                }
        }
 
@@ -156,6 +156,9 @@ public class CmsUiUtils implements CmsConstants {
                return new GridData(horizontalAlignment, horizontalAlignment, false, true);
        }
 
+       /*
+        * ROW LAYOUT
+        */
        public static RowData rowData16px() {
                return new RowData(16, 16);
        }
@@ -164,7 +167,7 @@ public class CmsUiUtils implements CmsConstants {
         * FORM LAYOUT
         */
 
-       public static FormData coversAll() {
+       public static FormData coverAll() {
                FormData fdLabel = new FormData();
                fdLabel.top = new FormAttachment(0, 0);
                fdLabel.left = new FormAttachment(0, 0);
@@ -179,19 +182,23 @@ public class CmsUiUtils implements CmsConstants {
 
        /** Style widget */
        public static <T extends Widget> T style(T widget, String style) {
-               widget.setData(CmsConstants.STYLE, style);
+               if (style == null)
+                       return widget;// does nothing
+               EclipseUiSpecificUtils.setStyleData(widget, style);
+               if (widget instanceof Control) {
+                       CmsView.getCmsView((Control) widget).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);
+               EclipseUiSpecificUtils.setMarkupData(widget);
                return widget;
        }
 
@@ -231,6 +238,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);
        }
@@ -272,6 +280,15 @@ public class CmsUiUtils implements CmsConstants {
        }
 
        // IMAGES
+       public static String img(Node fileNode, String width, String height) {
+               return img(null, fileNode, width, height);
+       }
+
+       public static String img(String serverBase, Node fileNode, String width, String height) {
+               String src = (serverBase != null ? serverBase : "") + NodeUtils.getDataPath(fileNode);
+               return imgBuilder(src, width, height).append("/>").toString();
+       }
+
        public static String img(String src, String width, String height) {
                return imgBuilder(src, width, height).append("/>").toString();
        }