Use clean URL data path for images.
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / ui / util / CmsUiUtils.java
index 8b10ef123a3bb9a62122496bfb848e94bf3ee790..75cff0fff6dd541ff047df25de8be948657c6b53 100644 (file)
@@ -20,6 +20,7 @@ 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.JcrException;
 import org.argeo.jcr.JcrUtils;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.service.ResourceManager;
@@ -33,6 +34,7 @@ import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
@@ -150,6 +152,7 @@ public class CmsUiUtils implements CmsConstants {
                return noSpaceGridLayout(new GridLayout(columns, false));
        }
 
+       /** @return the same layout, with spaces removed. */
        public static GridLayout noSpaceGridLayout(GridLayout layout) {
                layout.horizontalSpacing = 0;
                layout.verticalSpacing = 0;
@@ -181,6 +184,19 @@ public class CmsUiUtils implements CmsConstants {
        /*
         * ROW LAYOUT
         */
+       /** @return the same layout, with margins removed. */
+       public static RowLayout noMarginsRowLayout(RowLayout rowLayout) {
+               rowLayout.marginTop = 0;
+               rowLayout.marginBottom = 0;
+               rowLayout.marginLeft = 0;
+               rowLayout.marginRight = 0;
+               return rowLayout;
+       }
+
+       public static RowLayout noMarginsRowLayout(int type) {
+               return noMarginsRowLayout(new RowLayout(type));
+       }
+
        public static RowData rowData16px() {
                return new RowData(16, 16);
        }
@@ -224,6 +240,12 @@ public class CmsUiUtils implements CmsConstants {
                return widget;
        }
 
+       /** Disable markup validation. */
+       public static <T extends Widget> T disableMarkupValidation(T widget) {
+               EclipseUiSpecificUtils.setMarkupValidationDisabledData(widget);
+               return widget;
+       }
+
        /**
         * Apply markup and set text on {@link Label}, {@link Button}, {@link Text}.
         * 
@@ -309,7 +331,13 @@ public class CmsUiUtils implements CmsConstants {
        }
 
        public static String img(String serverBase, Node fileNode, String width, String height) {
-               String src = (serverBase != null ? serverBase : "") + NodeUtils.getDataPath(fileNode);
+//             String src = (serverBase != null ? serverBase : "") + NodeUtils.getDataPath(fileNode);
+               String src;
+               try {
+                       src = (serverBase != null ? serverBase : "") + getDataPathForUrl(fileNode);
+               } catch (RepositoryException e) {
+                       throw new JcrException("Cannot get URL data path for " + fileNode, e);
+               }
                return imgBuilder(src, width, height).append("/>").toString();
        }