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.eclipse.gemini.blueprint.context.BundleContextAware;
+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;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.osgi.framework.BundleContext;
-import org.springframework.beans.factory.InitializingBean;
/** A link to an internal or external location. */
-public class CmsLink implements CmsUiProvider, InitializingBean,
- BundleContextAware {
+public class CmsLink implements CmsUiProvider {
private final static Log log = LogFactory.getLog(CmsLink.class);
+ private BundleContext bundleContext;
private String label;
private String custom;
// private Boolean isUrl = false;
private Integer imageWidth, imageHeight;
- private BundleContext bundleContext;
-
public CmsLink() {
super();
}
this.label = label;
this.target = target;
this.custom = custom;
- afterPropertiesSet();
+ init();
}
- @Override
- public void afterPropertiesSet() {
- // if (target != null) {
- // if (target.startsWith("/")) {
- // isUrl = true;
- // } else {
- // try {
- // new URL(target);
- // isUrl = true;
- // } catch (MalformedURLException e1) {
- // isUrl = false;
- // }
- // }
- // }
-
+ public void init() {
if (image != null) {
ImageData image = loadImage();
imageWidth = image.width;
/** @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)
// label
StringBuilder labelText = new StringBuilder();
if (target != null) {
- labelText
- .append("<a style='color:inherit;text-decoration:inherit;' href=\"");
+ labelText.append("<a style='color:inherit;text-decoration:inherit;' href=\"");
// if (!isUrl)
// labelText.append('#');
labelText.append(target);
if (image != null) {
registerImageIfNeeded();
String imageLocation = RWT.getResourceManager().getLocation(image);
- labelText.append("<img width='").append(imageWidth)
- .append("' height='").append(imageHeight)
+ labelText.append("<img width='").append(imageWidth).append("' height='").append(imageHeight)
.append("' src=\"").append(imageLocation).append("\"/>");
// final Image img = loadImage(parent.getDisplay());
// pure URL
url = new URL(image);
} catch (MalformedURLException e1) {
- // in OSGi bundle
- if (bundleContext == null)
- throw new CmsException("No bundle context available");
url = bundleContext.getBundle().getResource(image);
}
return url;
}
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
public void setLabel(String label) {
this.label = label;
}
this.image = image;
}
- @Override
- public void setBundleContext(BundleContext bundleContext) {
- this.bundleContext = bundleContext;
- }
-
public void setMouseListener(MouseListener mouseListener) {
this.mouseListener = mouseListener;
}
} 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)");
}
}
-
- // private class MListener extends MouseAdapter {
- // private static final long serialVersionUID = 3634864186295639792L;
- //
- // @Override
- // public void mouseDown(MouseEvent e) {
- // if (e.button == 1) {
- // }
- // }
- // }
- //
- // private class DListener implements DisposeListener {
- // private static final long serialVersionUID = -3808587499269394812L;
- // private final Image img;
- //
- // public DListener(Image img) {
- // super();
- // this.img = img;
- // }
- //
- // @Override
- // public void widgetDisposed(DisposeEvent event) {
- // img.dispose();
- // }
- //
- // }
}