- Year field in date picker is now configurable

- Text field length is configurable
- Text area controls can now be used and configured

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3443 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-08-01 14:54:59 +00:00
parent b78a266d20
commit d3fb5dd9fd
8 changed files with 223 additions and 17 deletions

View File

@@ -1,5 +1,7 @@
package org.alfresco.web.bean.generator;
import java.util.Date;
import javax.faces.component.UIComponent;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
@@ -21,8 +23,43 @@ import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
*/
public class DatePickerGenerator extends BaseComponentGenerator
{
private int yearCount = 30;
private int startYear = new Date().getYear() + 1900 + 2;
private static final String MSG_DATE = "date_pattern";
/**
* @return Returns the year to start counting back from
*/
public int getStartYear()
{
return startYear;
}
/**
* @param startYear Sets the year to start counting back from
*/
public void setStartYear(int startYear)
{
this.startYear = startYear;
}
/**
* @return Returns the number of years to show
*/
public int getYearCount()
{
return yearCount;
}
/**
* @param yearCount Sets the number of years to show
*/
public void setYearCount(int yearCount)
{
this.yearCount = yearCount;
}
@SuppressWarnings("unchecked")
public UIComponent generate(FacesContext context, String id)
{
@@ -30,7 +67,8 @@ public class DatePickerGenerator extends BaseComponentGenerator
createComponent(ComponentConstants.JAVAX_FACES_INPUT);
component.setRendererType(RepoConstants.ALFRESCO_FACES_DATE_PICKER_RENDERER);
FacesHelper.setupComponentId(context, component, id);
component.getAttributes().put("yearCount", new Integer(30));
component.getAttributes().put("startYear", this.startYear);
component.getAttributes().put("yearCount", this.yearCount);
component.getAttributes().put("style", "margin-right: 7px;");
return component;

View File

@@ -0,0 +1,64 @@
package org.alfresco.web.bean.generator;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.alfresco.web.app.servlet.FacesHelper;
import org.alfresco.web.ui.common.ComponentConstants;
/**
* Generates a text field component.
*
* @author gavinc
*/
public class TextAreaGenerator extends TextFieldGenerator
{
private int rows = 3;
private int columns = 32;
/**
* @return Returns the number of columns
*/
public int getColumns()
{
return columns;
}
/**
* @param columns Sets the number of columns
*/
public void setColumns(int columns)
{
this.columns = columns;
}
/**
* @return Returns the number of rows
*/
public int getRows()
{
return rows;
}
/**
* @param rows Sets the number of rows
*/
public void setRows(int rows)
{
this.rows = rows;
}
@SuppressWarnings("unchecked")
public UIComponent generate(FacesContext context, String id)
{
UIComponent component = context.getApplication().
createComponent(ComponentConstants.JAVAX_FACES_INPUT);
component.setRendererType(ComponentConstants.JAVAX_FACES_TEXTAREA);
FacesHelper.setupComponentId(context, component, id);
component.getAttributes().put("rows", this.rows);
component.getAttributes().put("cols", this.columns);
return component;
}
}

View File

@@ -26,6 +26,41 @@ import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
*/
public class TextFieldGenerator extends BaseComponentGenerator
{
private int size = 35;
private int maxLength = 1024;
/**
* @return Returns the default size for a text field
*/
public int getSize()
{
return size;
}
/**
* @param size Sets the size of a text field
*/
public void setSize(int size)
{
this.size = size;
}
/**
* @return Returns the max length for the text field
*/
public int getMaxLength()
{
return maxLength;
}
/**
* @param maxLength Sets the max length of the text field
*/
public void setMaxLength(int maxLength)
{
this.maxLength = maxLength;
}
@SuppressWarnings("unchecked")
public UIComponent generate(FacesContext context, String id)
{
@@ -33,8 +68,9 @@ public class TextFieldGenerator extends BaseComponentGenerator
createComponent(ComponentConstants.JAVAX_FACES_INPUT);
component.setRendererType(ComponentConstants.JAVAX_FACES_TEXT);
FacesHelper.setupComponentId(context, component, id);
component.getAttributes().put("size", "35");
component.getAttributes().put("maxlength", "1024");
component.getAttributes().put("size", this.size);
component.getAttributes().put("maxlength", this.maxLength);
return component;
}

View File

@@ -23,6 +23,7 @@ public final class ComponentConstants
{
public static final String JAVAX_FACES_INPUT = "javax.faces.Input";
public static final String JAVAX_FACES_TEXT = "javax.faces.Text";
public static final String JAVAX_FACES_TEXTAREA = "javax.faces.Textarea";
public static final String JAVAX_FACES_OUTPUT = "javax.faces.Output";
public static final String JAVAX_FACES_GRID = "javax.faces.Grid";
public static final String JAVAX_FACES_PANEL = "javax.faces.Panel";

View File

@@ -43,6 +43,7 @@ public final class RepoConstants
public static final String GENERATOR_LABEL = "LabelGenerator";
public static final String GENERATOR_TEXT_FIELD = "TextFieldGenerator";
public static final String GENERATOR_TEXT_AREA = "TextAreaGenerator";
public static final String GENERATOR_CHECKBOX = "CheckboxGenerator";
public static final String GENERATOR_DATE_PICKER = "DatePickerGenerator";
public static final String GENERATOR_DATETIME_PICKER = "DateTimePickerGenerator";

View File

@@ -78,6 +78,7 @@ public class UISearchCustomProperties extends SelfRenderingComponent implements
/**
* @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
*/
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException
{
if (isRendered() == false)
@@ -133,6 +134,7 @@ public class UISearchCustomProperties extends SelfRenderingComponent implements
*
* @param context FacesContext
*/
@SuppressWarnings("unchecked")
private void createComponentsFromConfig(FacesContext context)
{
DictionaryService dd = Repository.getServiceRegistry(context).getDictionaryService();
@@ -236,6 +238,7 @@ public class UISearchCustomProperties extends SelfRenderingComponent implements
*
* @return UIComponent
*/
@SuppressWarnings("unchecked")
private UIComponent generateControl(FacesContext context, PropertyDefinition propDef, String displayLabel, String beanBinding)
{
UIComponent control = null;
@@ -265,6 +268,22 @@ public class UISearchCustomProperties extends SelfRenderingComponent implements
{
Boolean showTime = Boolean.valueOf(typeName.equals(DataTypeDefinition.DATETIME));
// create value bindings for the start year and year count attributes
ValueBinding startYearBind = null;
ValueBinding yearCountBind = null;
if (showTime)
{
startYearBind = facesApp.createValueBinding("#{DateTimePickerGenerator.startYear}");
yearCountBind = facesApp.createValueBinding("#{DateTimePickerGenerator.yearCount}");
}
else
{
startYearBind = facesApp.createValueBinding("#{DatePickerGenerator.startYear}");
yearCountBind = facesApp.createValueBinding("#{DatePickerGenerator.yearCount}");
}
// Need to output component for From and To date selectors and labels
// also neeed checkbox for enable/disable state - requires an outer wrapper component
control = (UIPanel)facesApp.createComponent(ComponentConstants.JAVAX_FACES_PANEL);
@@ -298,7 +317,8 @@ public class UISearchCustomProperties extends SelfRenderingComponent implements
UIInput inputFromDate = (UIInput)facesApp.createComponent(ComponentConstants.JAVAX_FACES_INPUT);
inputFromDate.setId(context.getViewRoot().createUniqueId());
inputFromDate.setRendererType(RepoConstants.ALFRESCO_FACES_DATE_PICKER_RENDERER);
inputFromDate.getAttributes().put("yearCount", new Integer(30));
inputFromDate.setValueBinding("startYear", startYearBind);
inputFromDate.setValueBinding("yearCount", yearCountBind);
inputFromDate.getAttributes().put("showTime", showTime);
ValueBinding vbFromDate = facesApp.createValueBinding(
"#{" + beanBinding + "[\"" + PREFIX_DATE_FROM + propDef.getName().toString() + "\"]}");
@@ -316,7 +336,8 @@ public class UISearchCustomProperties extends SelfRenderingComponent implements
UIInput inputToDate = (UIInput)facesApp.createComponent(ComponentConstants.JAVAX_FACES_INPUT);
inputToDate.setId(context.getViewRoot().createUniqueId());
inputToDate.setRendererType(RepoConstants.ALFRESCO_FACES_DATE_PICKER_RENDERER);
inputToDate.getAttributes().put("yearCount", new Integer(30));
inputToDate.setValueBinding("startYear", startYearBind);
inputToDate.setValueBinding("yearCount", yearCountBind);
inputToDate.getAttributes().put("showTime", showTime);
ValueBinding vbToDate = facesApp.createValueBinding(
"#{" + beanBinding + "[\"" + PREFIX_DATE_TO + propDef.getName().toString() + "\"]}");
@@ -333,8 +354,8 @@ public class UISearchCustomProperties extends SelfRenderingComponent implements
// any other type is represented as an input text field
control = (UIInput)facesApp.createComponent(ComponentConstants.JAVAX_FACES_INPUT);
control.setRendererType(ComponentConstants.JAVAX_FACES_TEXT);
control.getAttributes().put("size", "28");
control.getAttributes().put("maxlength", "1024");
control.setValueBinding("size", facesApp.createValueBinding("#{TextFieldGenerator.size}"));
control.setValueBinding("maxlength", facesApp.createValueBinding("#{TextFieldGenerator.maxLength}"));
control.setValueBinding(VALUE, vb);
}