use of org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint in project acs-community-packaging by Alfresco.
the class TextFieldGenerator method createComponent.
@Override
@SuppressWarnings("unchecked")
protected UIComponent createComponent(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item) {
UIComponent component = null;
if (propertySheet.inEditMode()) {
// if the field has the list of values constraint
// and it is editable a SelectOne component is
// required otherwise create the standard edit component
ListOfValuesConstraint constraint = getListOfValuesConstraint(context, propertySheet, item);
PropertyDefinition propDef = this.getPropertyDefinition(context, propertySheet.getNode(), item.getName());
if (constraint != null && item.isReadOnly() == false && propDef != null && propDef.isProtected() == false) {
component = context.getApplication().createComponent(UISelectOne.COMPONENT_TYPE);
FacesHelper.setupComponentId(context, component, item.getName());
// create the list of choices
UISelectItems itemsComponent = (UISelectItems) context.getApplication().createComponent("javax.faces.SelectItems");
List<String> values = constraint.getAllowedValues();
List<SelectItem> items = new ArrayList<SelectItem>(values.size());
for (String value : values) {
Object obj = null;
// we need to setup the list with objects of the correct type
if (propDef.getDataType().getName().equals(DataTypeDefinition.INT)) {
obj = Integer.valueOf(value);
} else if (propDef.getDataType().getName().equals(DataTypeDefinition.LONG)) {
obj = Long.valueOf(value);
} else if (propDef.getDataType().getName().equals(DataTypeDefinition.DOUBLE)) {
obj = Double.valueOf(value);
} else if (propDef.getDataType().getName().equals(DataTypeDefinition.FLOAT)) {
obj = Float.valueOf(value);
} else {
obj = value;
}
// retrieve the display label
String label = constraint.getDisplayLabel(value, dataDictionary.getDictionaryService());
if (label == null) {
label = value;
}
items.add(new SelectItem(obj, label));
}
itemsComponent.setValue(items);
// add the items as a child component
component.getChildren().add(itemsComponent);
} else {
// use the standard component in edit mode
component = generate(context, item.getName());
}
} else {
// create an output text component in view mode
component = createOutputTextComponent(context, item.getName());
}
return component;
}
use of org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint in project alfresco-remote-api by Alfresco.
the class WorkflowRestImpl method getFormModelElements.
/**
* @param type the type to get the elements for
* @param paging Paging
* @return collection with all valid form-model elements for the given type.
*/
public CollectionWithPagingInfo<FormModelElement> getFormModelElements(TypeDefinition type, Paging paging) {
Map<QName, PropertyDefinition> taskProperties = type.getProperties();
Set<QName> typesToExclude = getTypesToExclude(type);
List<FormModelElement> page = new ArrayList<FormModelElement>();
for (Entry<QName, PropertyDefinition> entry : taskProperties.entrySet()) {
String name = entry.getKey().toPrefixString(namespaceService).replace(':', '_');
// Only add properties which are not part of an excluded type
if (!typesToExclude.contains(entry.getValue().getContainerClass().getName()) && excludeModelTypes.contains(name) == false) {
FormModelElement element = new FormModelElement();
element.setName(name);
element.setQualifiedName(entry.getKey().toString());
element.setTitle(entry.getValue().getTitle(dictionaryService));
element.setRequired(entry.getValue().isMandatory());
element.setDataType(entry.getValue().getDataType().getName().toPrefixString(namespaceService));
element.setDefaultValue(entry.getValue().getDefaultValue());
if (entry.getValue().getConstraints() != null) {
for (ConstraintDefinition constraintDef : entry.getValue().getConstraints()) {
Constraint constraint = constraintDef.getConstraint();
if (constraint != null && constraint instanceof ListOfValuesConstraint) {
ListOfValuesConstraint valuesConstraint = (ListOfValuesConstraint) constraint;
if (valuesConstraint.getAllowedValues() != null && valuesConstraint.getAllowedValues().size() > 0) {
element.setAllowedValues(valuesConstraint.getAllowedValues());
}
}
}
}
page.add(element);
}
}
Map<QName, AssociationDefinition> taskAssociations = type.getAssociations();
for (Entry<QName, AssociationDefinition> entry : taskAssociations.entrySet()) {
// Only add associations which are not part of an excluded type
if (!typesToExclude.contains(entry.getValue().getSourceClass().getName())) {
FormModelElement element = new FormModelElement();
element.setName(entry.getKey().toPrefixString(namespaceService).replace(':', '_'));
element.setQualifiedName(entry.getKey().toString());
element.setTitle(entry.getValue().getTitle(dictionaryService));
element.setRequired(entry.getValue().isTargetMandatory());
element.setDataType(entry.getValue().getTargetClass().getName().toPrefixString(namespaceService));
page.add(element);
}
}
return CollectionWithPagingInfo.asPaged(paging, page, false, page.size());
}
Aggregations