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.CmsStyle;
-import org.argeo.api.cms.CmsTheme;
-import org.argeo.api.cms.CmsView;
+import org.argeo.api.cms.ux.CmsIcon;
+import org.argeo.api.cms.ux.CmsStyle;
+import org.argeo.api.cms.ux.CmsTheme;
+import org.argeo.api.cms.ux.CmsView;
import org.argeo.eclipse.ui.specific.EclipseUiSpecificUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
/** SWT utilities. */
public class CmsSwtUtils {
+ /*
+ * THEME AND VIEW
+ */
- /** Singleton. */
- private CmsSwtUtils() {
- }
-
- public static CmsTheme getCmsTheme(Composite parent) {
- CmsTheme theme = (CmsTheme) parent.getData(CmsTheme.class.getName());
+ public static CmsSwtTheme getCmsTheme(Composite parent) {
+ CmsSwtTheme theme = (CmsSwtTheme) parent.getData(CmsTheme.class.getName());
if (theme == null) {
// find parent shell
Shell topShell = parent.getShell();
while (topShell.getParent() != null)
topShell = (Shell) topShell.getParent();
- theme = (CmsTheme) topShell.getData(CmsTheme.class.getName());
+ theme = (CmsSwtTheme) topShell.getData(CmsTheme.class.getName());
parent.setData(CmsTheme.class.getName(), theme);
}
return theme;
shell.setData(CmsView.class.getName(), view);
}
+ /*
+ * EVENTS
+ */
+
/** Sends an event via {@link CmsView#sendEvent(String, Map)}. */
public static void sendEventOnSelect(Control control, String topic, Map<String, Object> properties) {
SelectionListener listener = (Selected) (e) -> {
sendEventOnSelect(control, topic, properties);
}
+ /*
+ * ICONS
+ */
+ /** Get a small icon from this theme. */
+ public static Image getSmallIcon(CmsTheme theme, CmsIcon icon) {
+ return ((CmsSwtTheme) theme).getSmallIcon(icon);
+ }
+
+ /** Get a big icon from this theme. */
+ public static Image getBigIcon(CmsTheme theme, CmsIcon icon) {
+ return ((CmsSwtTheme) theme).getBigIcon(icon);
+ }
+
/*
* LAYOUT INDEPENDENT
*/
for (Control child : composite.getChildren())
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() {
+ }
+
}