Make logging less verbose and better check disposed status of widgets
[lgpl/argeo-commons.git] / swt / org.argeo.cms.swt / src / org / argeo / cms / swt / CmsSwtUtils.java
index 5d964090b9abbd908ff1fc3f007c85afe11a76f8..d97bc4c35ad2bb89b81663e7d17d15899fd8ded0 100644 (file)
@@ -1,10 +1,7 @@
 package org.argeo.cms.swt;
 
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.StringTokenizer;
 
 import org.argeo.api.cms.ux.CmsIcon;
 import org.argeo.api.cms.ux.CmsStyle;
@@ -64,6 +61,8 @@ public class CmsSwtUtils {
        }
 
        public static CmsView getCmsView(Control parent) {
+               if (parent.isDisposed())
+                       return null;
                // find parent shell
                Shell topShell = parent.getShell();
                while (topShell.getParent() != null)
@@ -222,7 +221,7 @@ public class CmsSwtUtils {
 
        /** Style widget */
        public static <T extends Widget> T style(T widget, String style) {
-               if (style == null)
+               if (style == null || widget.isDisposed())
                        return widget;// does nothing
                EclipseUiSpecificUtils.setStyleData(widget, style);
                if (widget instanceof Control) {
@@ -294,20 +293,6 @@ public class CmsSwtUtils {
                        child.dispose();
        }
 
-       /** Clean reserved URL characters for use in HTTP links. */
-       public static String cleanPathForUrl(String path) {
-               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();
-       }
-
        /** Singleton. */
        private CmsSwtUtils() {
        }