Search in sources :

Example 1 with SelectionModel

use of com.manydesigns.elements.options.SelectionModel in project Portofino by ManyDesigns.

the class FormBuilder method build.

// **************************************************************************
// Building
// **************************************************************************
public Form build() {
    logger.debug("build");
    Form form = new Form(mode);
    if (groupedPropertyAccessors == null) {
        configReflectiveFields();
    }
    // remove unused (or partially used) selection providers
    List<PropertyAccessor> allPropertyAccessors = new ArrayList<PropertyAccessor>();
    for (ArrayList<PropertyAccessor> group : groupedPropertyAccessors) {
        allPropertyAccessors.addAll(group);
    }
    removeUnusedSelectionProviders(allPropertyAccessors);
    // create the form/fieldset/field sructure
    Map<String, Field> fieldMap = new HashMap<String, Field>();
    for (int i = 0; i < groupedPropertyAccessors.size(); i++) {
        buildFieldGroup(form, i, fieldMap);
    }
    // handle cascaded select fields
    for (Map.Entry<String[], SelectionProvider> current : selectionProviders.entrySet()) {
        String[] fieldNames = current.getKey();
        SelectionProvider selectionProvider = current.getValue();
        SelectionModel selectionModel = selectionProvider.createSelectionModel();
        SelectField previousField = null;
        for (int i = 0; i < fieldNames.length; i++) {
            SelectField selectField = (SelectField) fieldMap.get(fieldNames[i]);
            selectField.setSelectionModel(selectionModel);
            selectField.setSelectionModelIndex(i);
            if (previousField != null) {
                selectField.setPreviousSelectField(previousField);
                previousField.setNextSelectField(selectField);
            }
            previousField = selectField;
        }
    }
    return form;
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) SelectField(com.manydesigns.elements.fields.SelectField) Field(com.manydesigns.elements.fields.Field) SelectField(com.manydesigns.elements.fields.SelectField) SelectionModel(com.manydesigns.elements.options.SelectionModel) SelectionProvider(com.manydesigns.elements.options.SelectionProvider)

Example 2 with SelectionModel

use of com.manydesigns.elements.options.SelectionModel 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)

Example 3 with SelectionModel

use of com.manydesigns.elements.options.SelectionModel in project Portofino by ManyDesigns.

the class TableFormBuilder method setupSelectionProvidersForRow.

protected void setupSelectionProvidersForRow(TableForm tableForm, TableForm.Row row, Map.Entry<String[], SelectionProvider> current) {
    String[] fieldNames = current.getKey();
    SelectionProvider selectionProvider = current.getValue();
    SelectionModel selectionModel = selectionProvider.createSelectionModel();
    SelectField previousField = null;
    for (int i = 0; i < fieldNames.length; i++) {
        int fieldIndex = findFieldIndexByName(tableForm, fieldNames[i]);
        SelectField selectField = (SelectField) row.get(fieldIndex);
        selectField.setSelectionModel(selectionModel);
        selectField.setSelectionModelIndex(i);
        if (previousField != null) {
            selectField.setPreviousSelectField(previousField);
            previousField.setNextSelectField(selectField);
        }
        previousField = selectField;
    }
}
Also used : SelectField(com.manydesigns.elements.fields.SelectField) SelectionModel(com.manydesigns.elements.options.SelectionModel) SelectionProvider(com.manydesigns.elements.options.SelectionProvider)

Aggregations

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