X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=inline;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Futil%2FCmsLink.java;h=7c51e2ead877c08ad1287b3fdf0059a038aded05;hb=be23cc6f53178ac5108bc3f6cdca88d237ab1b7e;hp=865824c1a90b09890db356db0feaa0d9a78fd48f;hpb=77a5498dd5d10d2442127022efd6501a7dbddbae;p=lgpl%2Fargeo-commons.git
diff --git a/org.argeo.cms.ui/src/org/argeo/cms/util/CmsLink.java b/org.argeo.cms.ui/src/org/argeo/cms/util/CmsLink.java
index 865824c1a..7c51e2ead 100644
--- a/org.argeo.cms.ui/src/org/argeo/cms/util/CmsLink.java
+++ b/org.argeo.cms.ui/src/org/argeo/cms/util/CmsLink.java
@@ -5,13 +5,16 @@ import java.net.MalformedURLException;
import java.net.URL;
import javax.jcr.Node;
+import javax.jcr.RepositoryException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.cms.CmsException;
+import org.argeo.cms.auth.CurrentUser;
import org.argeo.cms.ui.CmsStyles;
import org.argeo.cms.ui.CmsUiProvider;
+import org.argeo.node.NodeUtils;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.service.ResourceManager;
import org.eclipse.swt.SWT;
@@ -26,7 +29,7 @@ import org.osgi.framework.BundleContext;
/** A link to an internal or external location. */
public class CmsLink implements CmsUiProvider {
private final static Log log = LogFactory.getLog(CmsLink.class);
- private BundleContext bundleContext ;
+ private BundleContext bundleContext;
private String label;
private String custom;
@@ -36,6 +39,9 @@ public class CmsLink implements CmsUiProvider {
private int verticalAlignment = SWT.CENTER;
+ private String loggedInLabel = null;
+ private String loggedInTarget = null;
+
// internal
// private Boolean isUrl = false;
private Integer imageWidth, imageHeight;
@@ -67,13 +73,17 @@ public class CmsLink implements CmsUiProvider {
/** @return {@link Composite} with a single {@link Label} child. */
@Override
public Control createUi(final Composite parent, Node context) {
+ if (image != null && (imageWidth == null || imageHeight == null)) {
+ throw new CmsException("Image is not properly configured."
+ + " Make sure bundleContext property is set and init() method has been called.");
+ }
+
Composite comp = new Composite(parent, SWT.BOTTOM);
comp.setLayout(CmsUtils.noSpaceGridLayout());
Label link = new Label(comp, SWT.NONE);
link.setData(RWT.MARKUP_ENABLED, Boolean.TRUE);
- GridData layoutData = new GridData(SWT.CENTER, verticalAlignment, true,
- true);
+ GridData layoutData = new GridData(SWT.CENTER, verticalAlignment, true, true);
if (image != null) {
layoutData.heightHint = imageHeight;
if (label == null)
@@ -91,39 +101,44 @@ public class CmsLink implements CmsUiProvider {
// label
StringBuilder labelText = new StringBuilder();
- if (target != null) {
- labelText
- .append("");
+ } else if (target != null) {
+ labelText.append("");
}
if (image != null) {
registerImageIfNeeded();
String imageLocation = RWT.getResourceManager().getLocation(image);
- labelText.append("
");
- // final Image img = loadImage(parent.getDisplay());
- // link.setImage(img);
- // link.addDisposeListener(new DListener(img));
}
- if (label != null) {
- // link.setText(label);
+ if (loggedInLabel != null && isLoggedIn()) {
+ labelText.append(' ').append(loggedInLabel);
+ } else if (label != null) {
labelText.append(' ').append(label);
}
- if (target != null)
+ if ((loggedInTarget != null && isLoggedIn()) || target != null)
labelText.append("");
link.setText(labelText.toString());
- // link.setCursor(link.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
- // CmsSession cmsSession = (CmsSession) parent.getDisplay().getData(
- // CmsSession.KEY);
if (mouseListener != null)
link.addMouseListener(mouseListener);
@@ -207,6 +222,14 @@ public class CmsLink implements CmsUiProvider {
this.image = image;
}
+ public void setLoggedInLabel(String loggedInLabel) {
+ this.loggedInLabel = loggedInLabel;
+ }
+
+ public void setLoggedInTarget(String loggedInTarget) {
+ this.loggedInTarget = loggedInTarget;
+ }
+
public void setMouseListener(MouseListener mouseListener) {
this.mouseListener = mouseListener;
}
@@ -219,8 +242,12 @@ public class CmsLink implements CmsUiProvider {
} else if ("center".equals(vAlign)) {
verticalAlignment = SWT.CENTER;
} else {
- throw new CmsException("Unsupported vertical allignment " + vAlign
- + " (must be: top, bottom or center)");
+ throw new CmsException("Unsupported vertical allignment " + vAlign + " (must be: top, bottom or center)");
}
}
+
+ protected boolean isLoggedIn() {
+ return !CurrentUser.isAnonymous();
+ }
+
}