X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.app.ui%2Fsrc%2Forg%2Fargeo%2Fapp%2Fui%2FSuiteUiUtils.java;h=9d9395bb051950dbba4b6fde3f908b20a2ce420a;hb=f1b87af2e0de38f1f49ab8fe68f9988018914811;hp=d1869717e28f1352792defe0ea988c36e10783d5;hpb=8873dfad689dff038387f739f358dde5e93d42f4;p=gpl%2Fargeo-suite.git diff --git a/org.argeo.app.ui/src/org/argeo/app/ui/SuiteUiUtils.java b/org.argeo.app.ui/src/org/argeo/app/ui/SuiteUiUtils.java index d186971..9d9395b 100644 --- a/org.argeo.app.ui/src/org/argeo/app/ui/SuiteUiUtils.java +++ b/org.argeo.app.ui/src/org/argeo/app/ui/SuiteUiUtils.java @@ -1,26 +1,31 @@ package org.argeo.app.ui; -import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Objects; -import javax.imageio.ImageIO; import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; -import org.argeo.api.cms.CmsEditable; +import org.apache.commons.io.IOUtils; +import org.argeo.api.acr.Content; import org.argeo.api.cms.CmsEvent; -import org.argeo.api.cms.CmsStyle; -import org.argeo.api.cms.CmsTheme; -import org.argeo.api.cms.CmsView; +import org.argeo.api.cms.ux.CmsEditable; +import org.argeo.api.cms.ux.CmsIcon; +import org.argeo.api.cms.ux.CmsStyle; +import org.argeo.api.cms.ux.CmsView; import org.argeo.app.api.EntityNames; import org.argeo.app.api.EntityType; import org.argeo.app.api.SuiteRole; import org.argeo.cms.LocaleUtils; import org.argeo.cms.Localized; import org.argeo.cms.auth.CurrentUser; -import org.argeo.cms.swt.CmsIcon; +import org.argeo.cms.jcr.acr.JcrContent; +import org.argeo.cms.swt.CmsSwtTheme; import org.argeo.cms.swt.CmsSwtUtils; import org.argeo.cms.swt.dialogs.LightweightDialog; import org.argeo.cms.ui.util.CmsLink; @@ -41,7 +46,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; -import org.osgi.service.event.Event; /** UI utilities related to the APAF project. */ public class SuiteUiUtils { @@ -237,22 +241,20 @@ public class SuiteUiUtils { boolean test = false; if (test) { try (InputStream in = JcrUtils.getFileAsStream(fileNode); - // OutputStream out = Files.newOutputStream(Paths.get("/home/mbaudier/tmp/" + - // fileNode.getName())) - ) { - BufferedImage img = ImageIO.read(in); - System.out.println(fileNode.getName() + ": width=" + img.getWidth() + ", height=" + img.getHeight()); -// IOUtils.copy(in, out); + OutputStream out = Files.newOutputStream(Paths.get("/home/mbaudier/tmp/" + fileNode.getName()));) { +// BufferedImage img = ImageIO.read(in); +// System.out.println(fileNode.getName() + ": width=" + img.getWidth() + ", height=" + img.getHeight()); + IOUtils.copy(in, out); } catch (IOException e) { throw new RuntimeException(e); } - try (InputStream in = JcrUtils.getFileAsStream(fileNode);) { - ImageData imageData = new ImageData(in); - System.out.println(fileNode.getName() + ": width=" + imageData.width + ", height=" + imageData.height); - } catch (IOException e) { - throw new RuntimeException(e); - } +// try (InputStream in = JcrUtils.getFileAsStream(fileNode);) { +// ImageData imageData = new ImageData(in); +// System.out.println(fileNode.getName() + ": width=" + imageData.width + ", height=" + imageData.height); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } } // TODO move it deeper in the middleware. if (!content.isNodeType(EntityType.box.get())) { @@ -358,8 +360,13 @@ public class SuiteUiUtils { return img; } + public static String toLink(Content node) { + return node != null ? "#" + CmsSwtUtils.cleanPathForUrl(SuiteApp.nodeToState(node)) : null; + } + public static String toLink(Node node) { - return node != null ? "#" + CmsUiUtils.cleanPathForUrl(SuiteApp.nodeToState(node)) : null; + return node != null ? "#" + CmsSwtUtils.cleanPathForUrl(SuiteApp.nodeToState(JcrContent.nodeToContent(node))) + : null; } public static Control addLink(Composite parent, String label, Node node, CmsStyle style) @@ -386,22 +393,23 @@ public class SuiteUiUtils { return lbl; } - public static boolean isCoworker(CmsView cmsView) { - boolean coworker = cmsView.doAs(() -> CurrentUser.isInRole(SuiteRole.coworker.dn())); - return coworker; - } +// public static boolean isCoworker(CmsView cmsView) { +// boolean coworker = cmsView.doAs(() -> CurrentUser.isInRole(SuiteRole.coworker.dn())); +// return coworker; +// } - public static boolean isTopic(Event event, CmsEvent cmsEvent) { - return event.getTopic().equals(cmsEvent.topic()); + public static boolean isTopic(String topic, CmsEvent cmsEvent) { + Objects.requireNonNull(topic); + return topic.equals(cmsEvent.topic()); } public static Button createLayerButton(Composite parent, String layer, Localized msg, CmsIcon icon, ClassLoader l10nClassLoader) { - CmsTheme theme = CmsSwtUtils.getCmsTheme(parent); + CmsSwtTheme theme = CmsSwtUtils.getCmsTheme(parent); Button button = new Button(parent, SWT.PUSH); CmsSwtUtils.style(button, SuiteStyle.leadPane); if (icon != null) - button.setImage(icon.getBigIcon(theme)); + button.setImage(theme.getBigIcon(icon)); button.setLayoutData(new GridData(SWT.CENTER, SWT.BOTTOM, true, false)); // button.setToolTipText(msg.lead()); if (msg != null) {