Search in sources :

Example 1 with SearchField

use of com.manydesigns.elements.fields.search.SearchField in project Portofino by ManyDesigns.

the class BooleanFieldHelper method tryToInstantiateSearchField.

public SearchField tryToInstantiateSearchField(ClassAccessor classAccessor, PropertyAccessor propertyAccessor, String prefix) {
    SearchField result;
    Class type = propertyAccessor.getType();
    if (type == Boolean.class || type == Boolean.TYPE) {
        result = new BooleanSearchField(propertyAccessor, prefix);
    } else {
        result = null;
    }
    return result;
}
Also used : SearchField(com.manydesigns.elements.fields.search.SearchField) BooleanSearchField(com.manydesigns.elements.fields.search.BooleanSearchField) BooleanSearchField(com.manydesigns.elements.fields.search.BooleanSearchField)

Example 2 with SearchField

use of com.manydesigns.elements.fields.search.SearchField in project Portofino by ManyDesigns.

the class SearchForm method toXhtml.

public void toXhtml(@NotNull XhtmlBuffer xb) {
    xb.openElement("div");
    xb.addAttribute("class", "searchform");
    for (SearchField current : this) {
        current.toXhtml(xb);
    }
    xb.closeElement("div");
}
Also used : SearchField(com.manydesigns.elements.fields.search.SearchField)

Example 3 with SearchField

use of com.manydesigns.elements.fields.search.SearchField in project Portofino by ManyDesigns.

the class SearchFormBuilder method build.

// **************************************************************************
// Building
// **************************************************************************
public SearchForm build() {
    logger.debug("build");
    SearchForm searchForm = new SearchForm();
    FieldsManager manager = FieldsManager.getManager();
    if (propertyAccessors == null) {
        configReflectiveFields();
    }
    Map<String, SearchField> fieldMap = new HashMap<String, SearchField>();
    for (PropertyAccessor propertyAccessor : propertyAccessors) {
        SearchField field = null;
        String fieldName = propertyAccessor.getName();
        for (Map.Entry<String[], SelectionProvider> current : selectionProviders.entrySet()) {
            String[] fieldNames = current.getKey();
            int index = ArrayUtils.indexOf(fieldNames, fieldName);
            if (index >= 0) {
                field = new SelectSearchField(propertyAccessor, current.getValue(), prefix);
                break;
            }
        }
        if (field == null) {
            field = manager.tryToInstantiateSearchField(classAccessor, propertyAccessor, prefix);
        }
        if (field == null) {
            logger.warn("Cannot instantiate field for property {}", propertyAccessor);
            continue;
        }
        fieldMap.put(fieldName, field);
        searchForm.add(field);
    }
    // handle cascaded select fields
    for (Map.Entry<String[], SelectionProvider> current : selectionProviders.entrySet()) {
        String[] fieldNames = current.getKey();
        SelectionProvider selectionProvider = current.getValue();
        SelectionModel selectionModel = selectionProvider.createSelectionModel();
        SelectSearchField previousField = null;
        for (int i = 0; i < fieldNames.length; i++) {
            SelectSearchField selectSearchField = (SelectSearchField) fieldMap.get(fieldNames[i]);
            if (selectSearchField == null) {
                previousField = null;
                continue;
            }
            selectSearchField.setSelectionModel(selectionModel);
            selectSearchField.setSelectionModelIndex(i);
            if (previousField != null) {
                selectSearchField.setPreviousSelectField(previousField);
                previousField.setNextSelectField(selectSearchField);
            }
            previousField = selectSearchField;
        }
    }
    return searchForm;
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) HashMap(java.util.HashMap) SelectSearchField(com.manydesigns.elements.fields.search.SelectSearchField) SearchField(com.manydesigns.elements.fields.search.SearchField) SelectSearchField(com.manydesigns.elements.fields.search.SelectSearchField) SelectionModel(com.manydesigns.elements.options.SelectionModel) SelectionProvider(com.manydesigns.elements.options.SelectionProvider) HashMap(java.util.HashMap) Map(java.util.Map) FieldsManager(com.manydesigns.elements.fields.helpers.FieldsManager)

Aggregations

SearchField (com.manydesigns.elements.fields.search.SearchField)3 FieldsManager (com.manydesigns.elements.fields.helpers.FieldsManager)1 BooleanSearchField (com.manydesigns.elements.fields.search.BooleanSearchField)1 SelectSearchField (com.manydesigns.elements.fields.search.SelectSearchField)1 SelectionModel (com.manydesigns.elements.options.SelectionModel)1 SelectionProvider (com.manydesigns.elements.options.SelectionProvider)1 PropertyAccessor (com.manydesigns.elements.reflection.PropertyAccessor)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1