X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Futil%2FCmsLink.java;h=a395bd23095eb3296336d12b7af22533e3c8ce5a;hb=3200c28bdc2f274178a62a372dbd2f2cd12855ed;hp=bd5052c5b9a79f1bf1b548e23a31fc7a0db09ffe;hpb=e01612eb49c5e0d32095b86c623cd35bf0995f99;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 bd5052c5b..a395bd230 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 @@ -10,8 +10,8 @@ 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.CmsStyles; -import org.argeo.cms.CmsUiProvider; +import org.argeo.cms.ui.CmsStyles; +import org.argeo.cms.ui.CmsUiProvider; import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.service.ResourceManager; import org.eclipse.swt.SWT; @@ -22,13 +22,11 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; /** A link to an internal or external location. */ public class CmsLink implements CmsUiProvider { private final static Log log = LogFactory.getLog(CmsLink.class); - private BundleContext bc = FrameworkUtil.getBundle(getClass()) - .getBundleContext(); + private BundleContext bundleContext; private String label; private String custom; @@ -69,13 +67,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) @@ -94,8 +96,7 @@ public class CmsLink implements CmsUiProvider { // label StringBuilder labelText = new StringBuilder(); if (target != null) { - labelText - .append(""); // final Image img = loadImage(parent.getDisplay()); @@ -174,7 +174,7 @@ public class CmsLink implements CmsUiProvider { // pure URL url = new URL(image); } catch (MalformedURLException e1) { - url = bc.getBundle().getResource(image); + url = bundleContext.getBundle().getResource(image); } if (url == null) @@ -183,6 +183,10 @@ public class CmsLink implements CmsUiProvider { return url; } + public void setBundleContext(BundleContext bundleContext) { + this.bundleContext = bundleContext; + } + public void setLabel(String label) { this.label = label; } @@ -217,8 +221,7 @@ 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)"); } } }