use of org.alfresco.service.cmr.dictionary.DataTypeDefinition in project acs-community-packaging by Alfresco.
the class UISearchCustomProperties method generateControl.
/**
* Generates an appropriate control for the given property
*
* @param context JSF context
* @param propDef The definition of the property to create the control for
* @param displayLabel Display label for the component
* @param beanBinding Combined name of the value bound bean and variable used for value binding expression
*
* @return UIComponent
*/
@SuppressWarnings("unchecked")
private UIComponent generateControl(FacesContext context, PropertyDefinition propDef, String displayLabel, String beanBinding) {
UIComponent control = null;
DataTypeDefinition dataTypeDef = propDef.getDataType();
QName typeName = dataTypeDef.getName();
javax.faces.application.Application facesApp = context.getApplication();
// create default value binding to a Map of values with a defined name
ValueBinding vb = facesApp.createValueBinding("#{" + beanBinding + "[\"" + propDef.getName().toString() + "\"]}");
// generate the appropriate input field
if (typeName.equals(DataTypeDefinition.BOOLEAN)) {
control = (UISelectBoolean) facesApp.createComponent(ComponentConstants.JAVAX_FACES_SELECT_BOOLEAN);
control.setRendererType(ComponentConstants.JAVAX_FACES_CHECKBOX);
control.setValueBinding(VALUE, vb);
} else if (typeName.equals(DataTypeDefinition.CATEGORY)) {
control = (UICategorySelector) facesApp.createComponent(RepoConstants.ALFRESCO_FACES_TAG_SELECTOR);
control.setValueBinding(VALUE, vb);
} else if (typeName.equals(DataTypeDefinition.DATETIME) || typeName.equals(DataTypeDefinition.DATE)) {
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);
control.setRendererType(ComponentConstants.JAVAX_FACES_GRID);
control.getAttributes().put("columns", Integer.valueOf(2));
// enabled state checkbox
UIInput checkbox = (UIInput) facesApp.createComponent(ComponentConstants.JAVAX_FACES_SELECT_BOOLEAN);
checkbox.setRendererType(ComponentConstants.JAVAX_FACES_CHECKBOX);
checkbox.setId(context.getViewRoot().createUniqueId());
ValueBinding vbCheckbox = facesApp.createValueBinding("#{" + beanBinding + "[\"" + propDef.getName().toString() + "\"]}");
checkbox.setValueBinding(VALUE, vbCheckbox);
control.getChildren().add(checkbox);
// main display label
UIOutput label = (UIOutput) context.getApplication().createComponent(ComponentConstants.JAVAX_FACES_OUTPUT);
label.setId(context.getViewRoot().createUniqueId());
label.setRendererType(ComponentConstants.JAVAX_FACES_TEXT);
label.setValue(displayLabel + ":");
control.getChildren().add(label);
// from date label
UIOutput labelFromDate = (UIOutput) context.getApplication().createComponent(ComponentConstants.JAVAX_FACES_OUTPUT);
labelFromDate.setId(context.getViewRoot().createUniqueId());
labelFromDate.setRendererType(ComponentConstants.JAVAX_FACES_TEXT);
labelFromDate.setValue(Application.getMessage(context, MSG_FROM));
control.getChildren().add(labelFromDate);
// from date control
UIInput inputFromDate = (UIInput) facesApp.createComponent(ComponentConstants.JAVAX_FACES_INPUT);
inputFromDate.setId(context.getViewRoot().createUniqueId());
inputFromDate.setRendererType(RepoConstants.ALFRESCO_FACES_DATE_PICKER_RENDERER);
inputFromDate.setValueBinding("startYear", startYearBind);
inputFromDate.setValueBinding("yearCount", yearCountBind);
inputFromDate.getAttributes().put("initialiseIfNull", Boolean.TRUE);
inputFromDate.getAttributes().put("showTime", showTime);
ValueBinding vbFromDate = facesApp.createValueBinding("#{" + beanBinding + "[\"" + PREFIX_DATE_FROM + propDef.getName().toString() + "\"]}");
inputFromDate.setValueBinding(VALUE, vbFromDate);
control.getChildren().add(inputFromDate);
// to date label
UIOutput labelToDate = (UIOutput) context.getApplication().createComponent(ComponentConstants.JAVAX_FACES_OUTPUT);
labelToDate.setId(context.getViewRoot().createUniqueId());
labelToDate.setRendererType(ComponentConstants.JAVAX_FACES_TEXT);
labelToDate.setValue(Application.getMessage(context, MSG_TO));
control.getChildren().add(labelToDate);
// to date control
UIInput inputToDate = (UIInput) facesApp.createComponent(ComponentConstants.JAVAX_FACES_INPUT);
inputToDate.setId(context.getViewRoot().createUniqueId());
inputToDate.setRendererType(RepoConstants.ALFRESCO_FACES_DATE_PICKER_RENDERER);
inputToDate.setValueBinding("startYear", startYearBind);
inputToDate.setValueBinding("yearCount", yearCountBind);
inputToDate.getAttributes().put("initialiseIfNull", Boolean.TRUE);
inputToDate.getAttributes().put("showTime", showTime);
ValueBinding vbToDate = facesApp.createValueBinding("#{" + beanBinding + "[\"" + PREFIX_DATE_TO + propDef.getName().toString() + "\"]}");
inputToDate.setValueBinding(VALUE, vbToDate);
control.getChildren().add(inputToDate);
} else if (typeName.equals(DataTypeDefinition.NODE_REF)) {
control = (UISpaceSelector) facesApp.createComponent(RepoConstants.ALFRESCO_FACES_SPACE_SELECTOR);
control.setValueBinding(VALUE, vb);
} else {
ListOfValuesConstraint constraint = getListOfValuesConstraint(propDef);
if (constraint != null && propDef != null && propDef.isProtected() == false) {
control = (UISelectOne) facesApp.createComponent(UISelectOne.COMPONENT_TYPE);
UISelectItems itemsComponent = (UISelectItems) facesApp.createComponent(ComponentConstants.JAVAX_FACES_SELECT_ITEMS);
List<SelectItem> items = new ArrayList<SelectItem>();
List<String> values = constraint.getAllowedValues();
for (String value : values) {
items.add(new SelectItem(value, value));
}
itemsComponent.setValue(items);
// add the items as a child component
control.getChildren().add(itemsComponent);
ValueBinding vbItemList = facesApp.createValueBinding("#{" + beanBinding + "[\"" + PREFIX_LOV_ITEM + propDef.getName().toString() + "\"]}");
control.setValueBinding(VALUE, vbItemList);
} else {
// 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.setValueBinding("size", facesApp.createValueBinding("#{TextFieldGenerator.size}"));
control.setValueBinding("maxlength", facesApp.createValueBinding("#{TextFieldGenerator.maxLength}"));
control.setValueBinding(VALUE, vb);
}
}
// set up the common aspects of the control
control.setId(context.getViewRoot().createUniqueId());
return control;
}
use of org.alfresco.service.cmr.dictionary.DataTypeDefinition in project acs-community-packaging by Alfresco.
the class AdvancedSearchDialog method getCustomPropertyLookup.
/**
* Helper map to lookup custom property QName strings against a DataTypeDefinition
*
* @return custom property lookup Map
*/
private Map<String, DataTypeDefinition> getCustomPropertyLookup() {
if ((properties.getCustomPropertyLookup() == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
properties.setCustomPropertyLookup(new HashMap<String, DataTypeDefinition>(7, 1.0f));
List<CustomProperty> customProps = getSearchConfig().getCustomProperties();
if (customProps != null) {
DictionaryService dd = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getDictionaryService();
for (CustomProperty customProp : customProps) {
PropertyDefinition propDef = null;
QName propQName = Repository.resolveToQName(customProp.Property);
if (customProp.Type != null) {
QName type = Repository.resolveToQName(customProp.Type);
TypeDefinition typeDef = dd.getType(type);
propDef = typeDef.getProperties().get(propQName);
} else if (customProp.Aspect != null) {
QName aspect = Repository.resolveToQName(customProp.Aspect);
AspectDefinition aspectDef = dd.getAspect(aspect);
propDef = aspectDef.getProperties().get(propQName);
}
if (propQName != null && propDef != null) {
properties.getCustomPropertyLookup().put(propQName.toString(), propDef.getDataType());
}
}
}
}
return properties.getCustomPropertyLookup();
}
use of org.alfresco.service.cmr.dictionary.DataTypeDefinition in project acs-community-packaging by Alfresco.
the class BaseComponentGenerator method isEnabledInEditMode.
public boolean isEnabledInEditMode(FacesContext context, UIComponent control, PropertyDefinition propDef) {
// get type info for the property
DataTypeDefinition dataTypeDef = propDef.getDataType();
QName typeName = dataTypeDef.getName();
if (typeName.equals(DataTypeDefinition.NODE_REF) || typeName.equals(DataTypeDefinition.PATH) || typeName.equals(DataTypeDefinition.CONTENT) || typeName.equals(DataTypeDefinition.QNAME) || typeName.equals(DataTypeDefinition.CHILD_ASSOC_REF) || typeName.equals(DataTypeDefinition.ASSOC_REF)) {
return false;
} else {
return true;
}
}
use of org.alfresco.service.cmr.dictionary.DataTypeDefinition in project records-management by Alfresco.
the class RecordsManagementTypeFormFilterUnitTest method mockPropertyDefintionMap.
/**
* Helper method to createa a mock property definition map
*/
private Map<QName, PropertyDefinition> mockPropertyDefintionMap(int size) {
Map<QName, PropertyDefinition> properties = new HashMap<QName, PropertyDefinition>(size);
for (int i = 0; i < size; i++) {
QName name = generateQName(RM_URI);
PropertyDefinition propDef = mock(PropertyDefinition.class);
when(propDef.getName()).thenReturn(name);
DataTypeDefinition mockDataTypeDefinition = mock(DataTypeDefinition.class);
when(mockDataTypeDefinition.getName()).thenReturn(DataTypeDefinition.TEXT);
when(propDef.getDataType()).thenReturn(mockDataTypeDefinition);
properties.put(name, propDef);
}
return properties;
}
use of org.alfresco.service.cmr.dictionary.DataTypeDefinition in project SearchServices by Alfresco.
the class AlfrescoSolrDataModel method getAlfrescoPropertyFromSchemaField.
public String getAlfrescoPropertyFromSchemaField(String schemaField) {
int index = schemaField.lastIndexOf("@{");
if (index == -1) {
return schemaField;
}
String alfrescoQueryField = schemaField.substring(index + 1);
QName qName = QName.createQName(alfrescoQueryField);
alfrescoQueryField = qName.toPrefixString(namespaceDAO);
PropertyDefinition propertyDefinition = getPropertyDefinition(qName);
if ((propertyDefinition == null)) {
return alfrescoQueryField;
}
if (!propertyDefinition.isIndexed() && !propertyDefinition.isStoredInIndex()) {
return alfrescoQueryField;
}
DataTypeDefinition dataTypeDefinition = propertyDefinition.getDataType();
if (dataTypeDefinition.getName().equals(DataTypeDefinition.CONTENT)) {
if (schemaField.contains("__size@")) {
return alfrescoQueryField + ".size";
} else if (schemaField.contains("__locale@")) {
return alfrescoQueryField + ".locale";
} else if (schemaField.contains("__mimetype@")) {
return alfrescoQueryField + ".mimetype";
} else if (schemaField.contains("__encoding@")) {
return alfrescoQueryField + ".encoding";
} else if (schemaField.contains("__docid@")) {
return alfrescoQueryField + ".docid";
} else if (schemaField.contains("__tr_ex@")) {
return alfrescoQueryField + ".tr_ex";
} else if (schemaField.contains("__tr_time@")) {
return alfrescoQueryField + ".tr_time";
} else if (schemaField.contains("__tr_status@")) {
return alfrescoQueryField + ".tr_status";
} else {
return alfrescoQueryField;
}
} else {
return alfrescoQueryField;
}
}
Aggregations