- Added MimeTypeSelector component

- Changed edit doc props page to use it
- Changed checkbox generator to only apply boolean converter
- Moved handling of multiple boolean values from the multi value converter to the boolean converter

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2666 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gavin Cornwell
2006-04-19 13:13:34 +00:00
parent f584f83e4c
commit 819bf188d8
13 changed files with 308 additions and 39 deletions

View File

@@ -1,13 +1,12 @@
package org.alfresco.web.bean.generator; package org.alfresco.web.bean.generator;
import javax.faces.component.UIComponent; import javax.faces.component.UIComponent;
import javax.faces.component.UISelectBoolean;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import org.alfresco.service.cmr.dictionary.PropertyDefinition; import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.web.app.servlet.FacesHelper; import org.alfresco.web.app.servlet.FacesHelper;
import org.alfresco.web.ui.common.ComponentConstants; import org.alfresco.web.ui.common.ComponentConstants;
import org.alfresco.web.ui.repo.RepoConstants; import org.alfresco.web.ui.common.converter.BooleanLabelConverter;
import org.alfresco.web.ui.repo.component.property.PropertySheetItem; import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
import org.alfresco.web.ui.repo.component.property.UIPropertySheet; import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
@@ -20,7 +19,7 @@ public class CheckboxGenerator extends BaseComponentGenerator
{ {
public UIComponent generate(FacesContext context, String id) public UIComponent generate(FacesContext context, String id)
{ {
UIComponent component = (UISelectBoolean)context.getApplication(). UIComponent component = context.getApplication().
createComponent(ComponentConstants.JAVAX_FACES_SELECT_BOOLEAN); createComponent(ComponentConstants.JAVAX_FACES_SELECT_BOOLEAN);
component.setRendererType(ComponentConstants.JAVAX_FACES_CHECKBOX); component.setRendererType(ComponentConstants.JAVAX_FACES_CHECKBOX);
FacesHelper.setupComponentId(context, component, id); FacesHelper.setupComponentId(context, component, id);
@@ -42,23 +41,11 @@ public class CheckboxGenerator extends BaseComponentGenerator
{ {
if (propertySheet.inEditMode() == false) if (propertySheet.inEditMode() == false)
{ {
if (propertyDef != null && propertyDef.isMultiValued()) // if there isn't a custom converter add the boolean
{ // converter as a default
// if there isn't a custom converter and the property is createAndSetConverter(context, BooleanLabelConverter.CONVERTER_ID,
// multi-valued add the multi value converter as a default
createAndSetConverter(context,
RepoConstants.ALFRESCO_FACES_MULTIVALUE_CONVERTER,
component); component);
} }
else
{
// if there isn't a custom converter and the property is
// not multi-valued add the boolean converter as a default
createAndSetConverter(context,
RepoConstants.ALFRESCO_FACES_BOOLEAN_CONVERTER,
component);
}
}
} }
} }

View File

@@ -0,0 +1,56 @@
package org.alfresco.web.bean.generator;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.web.app.servlet.FacesHelper;
import org.alfresco.web.ui.repo.component.UIMimeTypeSelector;
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
import org.alfresco.web.ui.repo.converter.MimeTypeConverter;
/**
* Generates a MIME type selector component.
*
* @author gavinc
*/
public class MimeTypeSelectorGenerator extends BaseComponentGenerator
{
public UIComponent generate(FacesContext context, String id)
{
UIComponent component = context.getApplication().
createComponent(UIMimeTypeSelector.COMPONENT_TYPE);
FacesHelper.setupComponentId(context, component, id);
return component;
}
@Override
protected void setupConverter(FacesContext context,
UIPropertySheet propertySheet, PropertySheetItem property,
PropertyDefinition propertyDef, UIComponent component)
{
if (property.getConverter() != null)
{
// create and add the custom converter
createAndSetConverter(context, property.getConverter(), component);
}
else
{
// if there isn't a custom converter add the mime type
// converter as a default
createAndSetConverter(context, MimeTypeConverter.CONVERTER_ID,
component);
}
}
@Override
protected void setupMandatoryValidation(FacesContext context,
UIPropertySheet propertySheet, PropertySheetItem item,
UIComponent component, boolean realTimeChecking)
{
// a mime type selector will always have one value or another
// so there is no need to create a mandatory validation rule.
}
}

View File

@@ -30,6 +30,7 @@ public final class ComponentConstants
public static final String JAVAX_FACES_SELECT_BOOLEAN = "javax.faces.SelectBoolean"; public static final String JAVAX_FACES_SELECT_BOOLEAN = "javax.faces.SelectBoolean";
public static final String JAVAX_FACES_GRAPHIC = "javax.faces.Graphic"; public static final String JAVAX_FACES_GRAPHIC = "javax.faces.Graphic";
public static final String JAVAX_FACES_PARAMETER = "javax.faces.Parameter"; public static final String JAVAX_FACES_PARAMETER = "javax.faces.Parameter";
public static final String JAVAX_FACES_MENU = "javax.faces.Menu";
/** /**
* Private constructor * Private constructor

View File

@@ -16,6 +16,7 @@
*/ */
package org.alfresco.web.ui.common.converter; package org.alfresco.web.ui.common.converter;
import java.util.Collection;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javax.faces.component.UIComponent; import javax.faces.component.UIComponent;
@@ -63,6 +64,29 @@ public class BooleanLabelConverter implements Converter
{ {
result = ((Boolean)value).booleanValue() ? bundle.getString(MSG_YES) : bundle.getString(MSG_NO); result = ((Boolean)value).booleanValue() ? bundle.getString(MSG_YES) : bundle.getString(MSG_NO);
} }
else if (value instanceof Collection)
{
StringBuilder buffer = new StringBuilder();
for (Object obj : (Collection)value)
{
if (buffer.length() != 0)
{
buffer.append(", ");
}
if (obj instanceof Boolean)
{
buffer.append(((Boolean)obj).booleanValue() ?
bundle.getString(MSG_YES) : bundle.getString(MSG_NO));
}
else
{
buffer.append(obj.toString());
}
}
result = buffer.toString();
}
return result; return result;
} }

View File

@@ -26,9 +26,6 @@ import javax.faces.context.FacesContext;
import javax.faces.convert.Converter; import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException; import javax.faces.convert.ConverterException;
import org.alfresco.web.app.Application;
import org.alfresco.web.ui.repo.RepoConstants;
/** /**
* Converter class to convert a List of multiple values into a comma * Converter class to convert a List of multiple values into a comma
* separated list. * separated list.
@@ -76,17 +73,8 @@ public class MultiValueConverter implements Converter
buffer.append(", "); buffer.append(", ");
} }
if (obj instanceof Boolean)
{
Converter boolLabel = context.getApplication().createConverter(
RepoConstants.ALFRESCO_FACES_BOOLEAN_CONVERTER);
buffer.append(boolLabel.getAsString(context, component, obj));
}
else
{
buffer.append(obj.toString()); buffer.append(obj.toString());
} }
}
result = buffer.toString(); result = buffer.toString();
} }

View File

@@ -0,0 +1,75 @@
package org.alfresco.web.ui.repo.component;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.faces.component.UISelectItems;
import javax.faces.component.UISelectOne;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.data.IDataContainer;
import org.alfresco.web.data.QuickSort;
/**
* Component that holds a list of MIME types configured in the repository.
*
* @author gavinc
*/
public class UIMimeTypeSelector extends UISelectOne
{
public static final String COMPONENT_TYPE = "org.alfresco.faces.MimeTypeSelector";
public static final String COMPONENT_FAMILY = "javax.faces.SelectOne";
@Override
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException
{
// if the component does not have any children yet create the
// list of MIME types the user can choose from as a child
// SelectItems component.
if (getChildren().size() == 0)
{
UISelectItems items = (UISelectItems)context.getApplication().
createComponent("javax.faces.SelectItems");
items.setValue(createList());
// add the child component
getChildren().add(items);
}
// do the default processing
super.encodeBegin(context);
}
/**
* Creates the list of SelectItem components to represent the list
* of MIME types the user can select from
*
* @return List of SelectItem components
*/
protected List<SelectItem> createList()
{
List<SelectItem> items = new ArrayList<SelectItem>(80);
ServiceRegistry registry = Repository.getServiceRegistry(FacesContext.getCurrentInstance());
MimetypeService mimetypeService = registry.getMimetypeService();
// get the mime type display names
Map<String, String> mimeTypes = mimetypeService.getDisplaysByMimetype();
for (String mimeType : mimeTypes.keySet())
{
items.add(new SelectItem(mimeType, mimeTypes.get(mimeType)));
}
// make sure the list is sorted by the values
QuickSort sorter = new QuickSort(items, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
return items;
}
}

View File

@@ -198,7 +198,14 @@ public class UIProperty extends PropertySheetItem
*/ */
private void generateControl(FacesContext context, UIPropertySheet propSheet, String propName) private void generateControl(FacesContext context, UIPropertySheet propSheet, String propName)
{ {
UIComponent control = FacesHelper.getComponentGenerator(context, RepoConstants.GENERATOR_TEXT_FIELD). String componentGeneratorName = this.getComponentGenerator();
if (componentGeneratorName == null)
{
componentGeneratorName = RepoConstants.GENERATOR_TEXT_FIELD;
}
UIComponent control = FacesHelper.getComponentGenerator(context, componentGeneratorName).
generateAndAdd(context, propSheet, this); generateAndAdd(context, propSheet, this);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())

View File

@@ -97,7 +97,7 @@ public class UIPropertySheet extends UIPanel implements NamingContainer
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException public void encodeBegin(FacesContext context) throws IOException
{ {
int howManyKids = getChildren().size(); int howManyChildren = getChildren().size();
Boolean externalConfig = (Boolean)getAttributes().get("externalConfig"); Boolean externalConfig = (Boolean)getAttributes().get("externalConfig");
// generate a variable name to use if necessary // generate a variable name to use if necessary
@@ -109,7 +109,7 @@ public class UIPropertySheet extends UIPanel implements NamingContainer
// force retrieval of node info // force retrieval of node info
Node node = getNode(); Node node = getNode();
if (howManyKids == 0) if (howManyChildren == 0)
{ {
if (externalConfig != null && externalConfig.booleanValue()) if (externalConfig != null && externalConfig.booleanValue())
{ {

View File

@@ -0,0 +1,71 @@
package org.alfresco.web.ui.repo.tag;
import javax.faces.component.UIComponent;
import org.alfresco.web.ui.common.ComponentConstants;
import org.alfresco.web.ui.common.tag.HtmlComponentTag;
import org.alfresco.web.ui.repo.component.UIMimeTypeSelector;
/**
* Tag class for the MIME type selector component
*
* @author gavinc
*/
public class MimeTypeSelectorTag extends HtmlComponentTag
{
/** The value */
private String value;
/** Whether the component is disabled */
private String disabled;
@Override
public String getComponentType()
{
return UIMimeTypeSelector.COMPONENT_TYPE;
}
@Override
public String getRendererType()
{
return ComponentConstants.JAVAX_FACES_MENU;
}
@Override
protected void setProperties(UIComponent component)
{
super.setProperties(component);
setStringBindingProperty(component, "value", this.value);
setBooleanProperty(component, "disabled", this.disabled);
}
@Override
public void release()
{
super.release();
this.value = null;
this.disabled = null;
}
/**
* Set the value
*
* @param value the value
*/
public void setValue(String value)
{
this.value = value;
}
/**
* Sets whether the component should be rendered in a disabled state
*
* @param disabled true to render the component in a disabled state
*/
public void setDisabled(String disabled)
{
this.disabled = disabled;
}
}

View File

@@ -1447,6 +1447,15 @@
<managed-bean-scope>request</managed-bean-scope> <managed-bean-scope>request</managed-bean-scope>
</managed-bean> </managed-bean>
<managed-bean>
<description>
Bean that generates a mime type selector component
</description>
<managed-bean-name>MimeTypeSelectorGenerator</managed-bean-name>
<managed-bean-class>org.alfresco.web.bean.generator.MimeTypeSelectorGenerator</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean> <managed-bean>
<description> <description>
Bean that generates an image picker component Bean that generates an image picker component

View File

@@ -54,6 +54,11 @@
<component-class>org.alfresco.web.ui.repo.component.UICategorySelector</component-class> <component-class>org.alfresco.web.ui.repo.component.UICategorySelector</component-class>
</component> </component>
<component>
<component-type>org.alfresco.faces.MimeTypeSelector</component-type>
<component-class>org.alfresco.web.ui.repo.component.UIMimeTypeSelector</component-class>
</component>
<component> <component>
<component-type>org.alfresco.faces.SimpleSearch</component-type> <component-type>org.alfresco.faces.SimpleSearch</component-type>
<component-class>org.alfresco.web.ui.repo.component.UISimpleSearch</component-class> <component-class>org.alfresco.web.ui.repo.component.UISimpleSearch</component-class>

View File

@@ -713,6 +713,12 @@
<required>false</required> <required>false</required>
<rtexprvalue>true</rtexprvalue> <rtexprvalue>true</rtexprvalue>
</attribute> </attribute>
<attribute>
<name>disabled</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag> </tag>
<tag> <tag>
@@ -785,6 +791,48 @@
<required>false</required> <required>false</required>
<rtexprvalue>true</rtexprvalue> <rtexprvalue>true</rtexprvalue>
</attribute> </attribute>
<attribute>
<name>disabled</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>mimeTypeSelector</name>
<tag-class>org.alfresco.web.ui.repo.tag.MimeTypeSelectorTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>id</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>binding</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>rendered</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>disabled</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag> </tag>
<tag> <tag>

View File

@@ -123,9 +123,7 @@
<tr> <tr>
<td><nobr><h:outputText value="#{msg.content_type}" />:</nobr></td> <td><nobr><h:outputText value="#{msg.content_type}" />:</nobr></td>
<td> <td>
<h:selectOneMenu value="#{EditDocPropsDialog.properties.mimetype}"> <r:mimeTypeSelector value="#{EditDocPropsDialog.properties.mimetype}" />&nbsp;*
<f:selectItems value="#{EditDocPropsDialog.contentTypes}" />
</h:selectOneMenu>&nbsp;*
</td> </td>
</tr> </tr>
<tr> <tr>
@@ -175,7 +173,7 @@
</tr> </tr>
<tr> <tr>
<td align="center"> <td align="center">
<h:commandButton value="#{msg.cancel}" action="cancel" styleClass="wizardButton" /> <h:commandButton id="cancel-button" value="#{msg.cancel}" action="cancel" styleClass="wizardButton" />
</td> </td>
</tr> </tr>
</table> </table>