X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Futil%2FCmsUiUtils.java;h=c305fa0db6b684159ebc42cf2271e726c0f8bdd2;hb=0fff629f700e9a9c742b6fe3874d408bee20ed10;hp=33377b6ca365f1db0c3e57c258d733071d7fec67;hpb=ed889869ecd572e9699260306c346b64f4439e3b;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 33377b6ca..c305fa0db 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 @@ -4,8 +4,11 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; +import java.util.StringTokenizer; import javax.jcr.Node; import javax.jcr.RepositoryException; @@ -13,10 +16,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 +92,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 +103,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); } } @@ -113,6 +116,25 @@ public class CmsUiUtils implements CmsConstants { return NodeUtils.getDataPath(cn, node); } + /** Clean reserved URL characters for use in HTTP links. */ + public static String getDataPathForUrl(Node node) throws RepositoryException { + return cleanPathForUrl(getDataPath(node)); + } + + /** Clean reserved URL characters for use in HTTP links. */ + public static String cleanPathForUrl(String path) throws RepositoryException { + StringTokenizer st = new StringTokenizer(path, "/"); + StringBuilder sb = new StringBuilder(); + while (st.hasMoreElements()) { + sb.append('/'); + String encoded = URLEncoder.encode(st.nextToken(), StandardCharsets.UTF_8); + encoded = encoded.replace("+", "%20"); + sb.append(encoded); + + } + return sb.toString(); + } + /** @deprecated Use rowData16px() instead. GridData should not be reused. */ @Deprecated public static RowData ROW_DATA_16px = new RowData(16, 16); @@ -136,15 +158,6 @@ public class CmsUiUtils implements CmsConstants { return layout; } - public static GridLayout standardSpaceGridLayout(GridLayout layout) { - layout.horizontalSpacing = 16; - layout.verticalSpacing = 16; - layout.marginWidth = 16; - layout.marginHeight = 16; - return layout; - } - - public static GridData fillAll() { return new GridData(SWT.FILL, SWT.FILL, true, true); } @@ -165,6 +178,9 @@ public class CmsUiUtils implements CmsConstants { return new GridData(horizontalAlignment, horizontalAlignment, false, true); } + /* + * ROW LAYOUT + */ public static RowData rowData16px() { return new RowData(16, 16); } @@ -173,7 +189,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); @@ -188,19 +204,29 @@ public class CmsUiUtils implements CmsConstants { /** Style widget */ public static 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 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 markup(T widget) { - widget.setData(CmsConstants.MARKUP, true); + EclipseUiSpecificUtils.setMarkupData(widget); + return widget; + } + + /** Disable markup validation. */ + public static T disableMarkupValidation(T widget) { + EclipseUiSpecificUtils.setMarkupValidationDisabledData(widget); return widget; } @@ -240,12 +266,15 @@ 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); } /** Dispose all children of a Composite */ public static void clear(Composite composite) { + if (composite.isDisposed()) + return; for (Control child : composite.getChildren()) child.dispose(); } @@ -281,6 +310,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(); } @@ -337,4 +375,5 @@ public class CmsUiUtils implements CmsConstants { /** Singleton. */ private CmsUiUtils() { } + }