package net.sourceforge.fenixedu.presentationTier.renderers; import pt.ist.fenixWebFramework.renderers.components.HtmlComponent; import pt.ist.fenixWebFramework.renderers.components.HtmlText; import pt.ist.fenixWebFramework.renderers.layouts.Layout; import pt.ist.fenixWebFramework.renderers.utils.RenderKit; import pt.ist.fenixWebFramework.renderers.utils.RendererPropertyUtils; public class ConditionalObjectLinkRenderer extends ObjectLinkRenderer { /** * This render is used to create a link out of an object if a given boolean * property is true. You choose the link format and some properties can be * used to configure the link. You can also specify the link indirectly by * specifing a destination and then defining a destination with that name in * the place were ou use this renderer. * *

* The link body is configured through a sub rendering of the object with * the specified layout and schema. * *

* Example: Jane Doe * * @author pcma */ private String visibleIf; public String getVisibleIf() { return visibleIf; } public void setVisibleIf(String visibleIf) { this.visibleIf = visibleIf; } protected Layout getLayout(Object object, Class type) { final Layout layout = super.getLayout(object, type); return new Layout() { @Override public HtmlComponent createComponent(Object object, Class type) { Boolean visible = Boolean.FALSE; try { visible = (Boolean) RendererPropertyUtils.getProperty(getTargetObject(object), getVisibleIf(), false); } catch (ClassCastException e) { e.printStackTrace(); } if (visible) { return layout.createComponent(object, type); } else { String text = getText(); return (text != null) ? new HtmlText(text) : renderValue(object, RenderKit.getInstance().findSchema( getSubSchema()), getSubLayout()); } } }; } }