X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=core%2Forg.argeo.suite.ui%2Fsrc%2Forg%2Fargeo%2Fsuite%2Fui%2FSuiteUiUtils.java;h=048b94657459e58f378d5f99d597c95b8d5b6a97;hb=0fb6b00d68fe576d38af9073a431d6afda5f4489;hp=79edb6416e38ffd7644037b9bbae3b68fce58ea2;hpb=bf2b76df49da4a94e37d539ef15d676a9fa58359;p=gpl%2Fargeo-suite.git
diff --git a/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java b/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java
index 79edb64..048b946 100644
--- a/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java
+++ b/core/org.argeo.suite.ui/src/org/argeo/suite/ui/SuiteUiUtils.java
@@ -7,17 +7,23 @@ import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import org.argeo.cms.LocaleUtils;
import org.argeo.cms.Localized;
import org.argeo.cms.auth.CurrentUser;
import org.argeo.cms.ui.CmsEditable;
+import org.argeo.cms.ui.CmsTheme;
import org.argeo.cms.ui.CmsView;
import org.argeo.cms.ui.dialogs.LightweightDialog;
import org.argeo.cms.ui.util.CmsEvent;
+import org.argeo.cms.ui.util.CmsIcon;
+import org.argeo.cms.ui.util.CmsLink;
+import org.argeo.cms.ui.util.CmsStyle;
import org.argeo.cms.ui.util.CmsUiUtils;
import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.entity.EntityNames;
import org.argeo.entity.EntityType;
import org.argeo.jcr.Jcr;
+import org.argeo.jcr.JcrException;
import org.argeo.jcr.JcrUtils;
import org.argeo.suite.SuiteRole;
import org.eclipse.swt.SWT;
@@ -219,6 +225,11 @@ public class SuiteUiUtils {
}
public static Label addPicture(Composite parent, Node fileNode, Integer maxWidth) throws RepositoryException {
+ return addPicture(parent, fileNode, maxWidth, null);
+ }
+
+ public static Label addPicture(Composite parent, Node fileNode, Integer maxWidth, Node link)
+ throws RepositoryException {
Node content = fileNode.getNode(Node.JCR_CONTENT);
// TODO move it deeper in the middleware.
if (!content.isNodeType(EntityType.box.get())) {
@@ -258,63 +269,104 @@ public class SuiteUiUtils {
}
Label img = new Label(parent, SWT.NONE);
CmsUiUtils.markup(img);
- img.setText(CmsUiUtils.img(fileNode, width.toString(), height.toString()));
+ StringBuffer txt = new StringBuffer();
+ String target = toLink(link);
+ if (target != null)
+ txt.append("");
+ txt.append(CmsUiUtils.img(fileNode, width.toString(), height.toString()));
+ if (target != null)
+ txt.append("");
+ img.setText(txt.toString());
if (parent.getLayout() instanceof GridLayout) {
GridData gd = new GridData(SWT.CENTER, SWT.CENTER, false, false);
gd.widthHint = width.intValue();
gd.heightHint = height.intValue();
img.setLayoutData(gd);
}
- img.addMouseListener(new MouseListener() {
- private static final long serialVersionUID = -1362242049325206168L;
- @Override
- public void mouseUp(MouseEvent e) {
- }
+ if (target == null)
+ img.addMouseListener(new MouseListener() {
+ private static final long serialVersionUID = -1362242049325206168L;
- @Override
- public void mouseDown(MouseEvent e) {
- }
+ @Override
+ public void mouseUp(MouseEvent e) {
+ }
- @Override
- public void mouseDoubleClick(MouseEvent e) {
- LightweightDialog dialog = new LightweightDialog(img.getShell()) {
-
- @Override
- protected Control createDialogArea(Composite parent) {
- parent.setLayout(new GridLayout());
- ScrolledComposite scroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
- scroll.setLayoutData(CmsUiUtils.fillAll());
- scroll.setLayout(CmsUiUtils.noSpaceGridLayout());
- scroll.setExpandHorizontal(true);
- scroll.setExpandVertical(true);
- // scroll.setAlwaysShowScrollBars(true);
-
- Composite c = new Composite(scroll, SWT.NONE);
- scroll.setContent(c);
- c.setLayout(new GridLayout());
- c.setLayoutData(CmsUiUtils.fillAll());
- Label bigImg = new Label(c, SWT.NONE);
- CmsUiUtils.markup(bigImg);
- bigImg.setText(CmsUiUtils.img(fileNode, Jcr.get(content, EntityNames.SVG_WIDTH),
- Jcr.get(content, EntityNames.SVG_HEIGHT)));
- bigImg.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
- return bigImg;
- }
-
- @Override
- protected Point getInitialSize() {
- Point shellSize = img.getShell().getSize();
- return new Point(shellSize.x - 100, shellSize.y - 100);
- }
-
- };
- dialog.open();
- }
- });
+ @Override
+ public void mouseDown(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ LightweightDialog dialog = new LightweightDialog(img.getShell()) {
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ parent.setLayout(new GridLayout());
+ ScrolledComposite scroll = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
+ scroll.setLayoutData(CmsUiUtils.fillAll());
+ scroll.setLayout(CmsUiUtils.noSpaceGridLayout());
+ scroll.setExpandHorizontal(true);
+ scroll.setExpandVertical(true);
+ // scroll.setAlwaysShowScrollBars(true);
+
+ Composite c = new Composite(scroll, SWT.NONE);
+ scroll.setContent(c);
+ c.setLayout(new GridLayout());
+ c.setLayoutData(CmsUiUtils.fillAll());
+ Label bigImg = new Label(c, SWT.NONE);
+ CmsUiUtils.markup(bigImg);
+ bigImg.setText(CmsUiUtils.img(fileNode, Jcr.get(content, EntityNames.SVG_WIDTH),
+ Jcr.get(content, EntityNames.SVG_HEIGHT)));
+ bigImg.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
+ return bigImg;
+ }
+
+ @Override
+ protected Point getInitialSize() {
+ Point shellSize = img.getShell().getSize();
+ return new Point(shellSize.x - 100, shellSize.y - 100);
+ }
+
+ };
+ dialog.open();
+ }
+ });
return img;
}
+ public static String toLink(Node node) {
+ try {
+ return node != null ? "#" + CmsUiUtils.cleanPathForUrl(SuiteApp.nodeToState(node)) : null;
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot get link from " + node, e);
+ }
+ }
+
+ public static Control addLink(Composite parent, String label, Node node, CmsStyle style)
+ throws RepositoryException {
+ String target = toLink(node);
+ CmsLink link = new CmsLink(label, target, style);
+ return link.createUi(parent, node);
+ }
+
+ public static Control addExternalLink(Composite parent, String label, String url, String plainCssAnchorClass,
+ boolean newWindow) throws RepositoryException {
+ Label lbl = new Label(parent, SWT.NONE);
+ CmsUiUtils.markup(lbl);
+ StringBuilder txt = new StringBuilder();
+ txt.append("");
+ txt.append(label);
+ txt.append("");
+ lbl.setText(txt.toString());
+ return lbl;
+ }
+
public static boolean isCoworker(CmsView cmsView) {
boolean coworker = cmsView.doAs(() -> CurrentUser.isInRole(SuiteRole.coworker.dn()));
return coworker;
@@ -324,6 +376,27 @@ public class SuiteUiUtils {
return event.getTopic().equals(cmsEvent.topic());
}
+ public static Button createLayerButton(Composite parent, String layer, Localized msg, CmsIcon icon,
+ ClassLoader l10nClassLoader) {
+ CmsTheme theme = CmsTheme.getCmsTheme(parent);
+ Button button = new Button(parent, SWT.PUSH);
+ CmsUiUtils.style(button, SuiteStyle.leadPane);
+ if (icon != null)
+ button.setImage(icon.getBigIcon(theme));
+ button.setLayoutData(new GridData(SWT.CENTER, SWT.BOTTOM, true, false));
+ // button.setToolTipText(msg.lead());
+ if (msg != null) {
+ Label lbl = new Label(parent, SWT.CENTER);
+ CmsUiUtils.style(lbl, SuiteStyle.leadPane);
+ String txt = LocaleUtils.lead(msg, l10nClassLoader);
+// String txt = msg.lead();
+ lbl.setText(txt);
+ lbl.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false));
+ }
+ CmsUiUtils.sendEventOnSelect(button, SuiteEvent.switchLayer.topic(), SuiteEvent.LAYER, layer);
+ return button;
+ }
+
// public static String createAndConfigureEntity(Shell shell, Session referenceSession, String mainMixin,
// String... additionnalProps) {
//