mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
- 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:
@@ -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;'> " +
|
||||
item.getDisplayLabel() + "</div>";
|
||||
|
||||
return html;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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("> ");
|
||||
htmlBuilder.append(item.getDisplayLabel());
|
||||
htmlBuilder.append("</div>");
|
||||
|
||||
return htmlBuilder.toString();
|
||||
}
|
||||
}
|
@@ -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><hr/></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>";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user