- Improved flexibility of separator generators

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3656 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-09-01 20:47:27 +00:00
parent 78196e1005
commit 02408541cd
5 changed files with 205 additions and 70 deletions

View File

@@ -1,23 +0,0 @@
package org.alfresco.web.bean.generator;
import javax.faces.component.UIComponent;
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
/**
* Generates a component to represent a separator that gets rendered
* as a header.
*
* @author gavinc
*/
public class HeaderSeparatorGenerator extends SeparatorGenerator
{
@Override
protected String getHtml(UIComponent component, PropertySheetItem item)
{
String html = "<div class='wizardSectionHeading mainSubTitle' style='margin-top: 6px; margin-bottom: 6px;'>&nbsp;" +
item.getDisplayLabel() + "</div>";
return html;
}
}

View File

@@ -0,0 +1,79 @@
package org.alfresco.web.bean.generator;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
/**
* Generates a component to represent a separator.
* <p>The HTML to be used for the separator is configured via the
* <code>setHtml</code> method.
*
* @author gavinc
*/
public class HtmlSeparatorGenerator extends BaseComponentGenerator
{
protected String html = "<b>default</b>";
/**
* Returns the HTML configured to be used for this separator
*
* @return The HTML to display
*/
public String getHtml()
{
return html;
}
/**
* Sets the HTML to display for the separator
*
* @param html The HTML
*/
public void setHtml(String html)
{
this.html = html;
}
@SuppressWarnings("unchecked")
public UIComponent generate(FacesContext context, String id)
{
UIComponent component = this.createOutputTextComponent(context, id);
component.getAttributes().put("escape", Boolean.FALSE);
return component;
}
@Override
@SuppressWarnings("unchecked")
protected UIComponent createComponent(FacesContext context, UIPropertySheet propertySheet,
PropertySheetItem item)
{
UIComponent component = this.generate(context, item.getName());
// set the HTML to use
component.getAttributes().put("value", getResolvedHtml(component, item));
return component;
}
/**
* Returns the resolved HTML to use for the separator.
* <p>In the default case we just return the HTML set
* via setHtml however subclasses may choose to generate
* the resulting HTML using a combination of the HTML set
* via setHtml and the given PropertySheetItem.
*
* @param component The JSF component representing the separator
* @param item The separator item
* @return The resolved HTML
*/
protected String getResolvedHtml(UIComponent component, PropertySheetItem item)
{
// In the default case we just return the HTML set via setHtml
return this.html;
}
}

View File

@@ -0,0 +1,85 @@
package org.alfresco.web.bean.generator;
import javax.faces.component.UIComponent;
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
/**
* Generates a component to represent a separator that uses the
* property sheet display label configuration. The CSS class used
* for the HTML representing the label can also be configured via
* the <code>setStyleClass</code> method.
*
* @author gavinc
*/
public class LabelSeparatorGenerator extends HtmlSeparatorGenerator
{
protected String style = "margin-top: 6px; margin-bottom: 6px;";
protected String styleClass;
/**
* Returns the CSS class configured to be used for this separator
*
* @return The CSS class
*/
public String getStyleClass()
{
return styleClass;
}
/**
* Sets the CSS class to use for the separator
*
* @param styleClass The CSS class
*/
public void setStyleClass(String styleClass)
{
this.styleClass = styleClass;
}
/**
* Returns the CSS style configured to be used for this separator
*
* @return The CSS style
*/
public String getStyle()
{
return style;
}
/**
* Sets the CSS style to use for the separator
*
* @param style The CSS style
*/
public void setStyle(String style)
{
this.style = style;
}
@Override
protected String getResolvedHtml(UIComponent component, PropertySheetItem item)
{
StringBuilder htmlBuilder = new StringBuilder("<div");
if (this.styleClass != null && this.styleClass.length() > 0)
{
htmlBuilder.append(" class=\"");
htmlBuilder.append(this.styleClass);
htmlBuilder.append("\"");
}
if (this.style != null && this.style.length() > 0)
{
htmlBuilder.append(" style=\"");
htmlBuilder.append(this.style);
htmlBuilder.append("\"");
}
// add the display label and close the div
htmlBuilder.append(">&nbsp;");
htmlBuilder.append(item.getDisplayLabel());
htmlBuilder.append("</div>");
return htmlBuilder.toString();
}
}

View File

@@ -1,49 +1,16 @@
package org.alfresco.web.bean.generator;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
/**
* Generates a component to represent a separator.
* Generates a component to represent a separator using the HTML <code>&lt;hr/&gt;</code> element.
*
* @author gavinc
*/
public class SeparatorGenerator extends BaseComponentGenerator
public class SeparatorGenerator extends HtmlSeparatorGenerator
{
@SuppressWarnings("unchecked")
public UIComponent generate(FacesContext context, String id)
public SeparatorGenerator()
{
UIComponent component = this.createOutputTextComponent(context, id);
component.getAttributes().put("escape", Boolean.FALSE);
// For the standard separator just show a <hr/> element
return component;
}
@Override
@SuppressWarnings("unchecked")
protected UIComponent createComponent(FacesContext context, UIPropertySheet propertySheet,
PropertySheetItem item)
{
UIComponent component = this.generate(context, item.getName());
// set the HTML to use
component.getAttributes().put("value", getHtml(component, item));
return component;
}
/**
* Returns the HTML to display for the separator
*
* @param component The JSF component representing the separator
* @param item The separator item
* @return The HTML
*/
protected String getHtml(UIComponent component, PropertySheetItem item)
{
return "<div style='margin-top: 6px; margin-bottom: 6px;'><hr/></div>";
this.html = "<div style='margin-top: 6px; margin-bottom: 6px;'><hr/></div>";
}
}

View File

@@ -2154,18 +2154,45 @@
<managed-bean-name>SeparatorGenerator</managed-bean-name>
<managed-bean-class>org.alfresco.web.bean.generator.SeparatorGenerator</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<description>
Bean that generates a header separator component
</description>
<managed-bean-name>HeaderSeparatorGenerator</managed-bean-name>
<managed-bean-class>org.alfresco.web.bean.generator.HeaderSeparatorGenerator</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<description>
Bean that generates a label separator component
</description>
<managed-bean-name>LabelSeparatorGenerator</managed-bean-name>
<managed-bean-class>org.alfresco.web.bean.generator.LabelSeparatorGenerator</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<description>
Bean that generates a label separator component rendered as a heading
</description>
<managed-bean-name>HeaderSeparatorGenerator</managed-bean-name>
<managed-bean-class>org.alfresco.web.bean.generator.LabelSeparatorGenerator</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>styleClass</property-name>
<value>wizardSectionHeading mainSubTitle</value>
</managed-property>
</managed-bean>
<!--
<managed-bean>
<description>
Bean that generates a HTML separator component
</description>
<managed-bean-name>MyCustomSeparatorGenerator</managed-bean-name>
<managed-bean-class>org.alfresco.web.bean.generator.HtmlSeparatorGenerator</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>html</property-name>
<value><![CDATA[This is <i>my</i> custom header]]></value>
</managed-property>
</managed-bean>
-->
<!-- ==================== AJAX BEANS ==================== -->
<managed-bean>