Search in sources :

Example 6 with SelectionProvider

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

the class FormBuilder method buildField.

protected Field buildField(PropertyAccessor propertyAccessor) {
    Field 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 = buildSelectField(propertyAccessor, current.getValue(), prefix);
            break;
        }
    }
    return buildField(propertyAccessor, field, prefix);
}
Also used : Field(com.manydesigns.elements.fields.Field) SelectField(com.manydesigns.elements.fields.SelectField) SelectionProvider(com.manydesigns.elements.options.SelectionProvider)

Example 7 with SelectionProvider

use of com.manydesigns.elements.options.SelectionProvider 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 8 with SelectionProvider

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

Example 9 with SelectionProvider

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

the class TableFormBuilder method buildField.

protected Field buildField(PropertyAccessor propertyAccessor, String rowPrefix) {
    Field 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 = buildSelectField(propertyAccessor, null, rowPrefix);
            break;
        }
    }
    return buildField(propertyAccessor, field, rowPrefix);
}
Also used : Field(com.manydesigns.elements.fields.Field) SelectField(com.manydesigns.elements.fields.SelectField) SelectionProvider(com.manydesigns.elements.options.SelectionProvider)

Example 10 with SelectionProvider

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

the class AbstractCrudAction method configureTableFormSelectionProviders.

protected void configureTableFormSelectionProviders(TableFormBuilder tableFormBuilder) {
    // setup option providers
    if (selectionProviderSupport != null) {
        for (CrudSelectionProvider current : selectionProviderSupport.getCrudSelectionProviders()) {
            SelectionProvider selectionProvider = current.getSelectionProvider();
            if (selectionProvider == null) {
                continue;
            }
            String[] fieldNames = current.getFieldNames();
            tableFormBuilder.configSelectionProvider(selectionProvider, fieldNames);
        }
    }
}
Also used : SelectionProvider(com.manydesigns.elements.options.SelectionProvider)

Aggregations

SelectionProvider (com.manydesigns.elements.options.SelectionProvider)12 SelectField (com.manydesigns.elements.fields.SelectField)5 Field (com.manydesigns.elements.fields.Field)4 PropertyAccessor (com.manydesigns.elements.reflection.PropertyAccessor)4 SelectionModel (com.manydesigns.elements.options.SelectionModel)3 Operation (io.swagger.v3.oas.annotations.Operation)3 FieldsManager (com.manydesigns.elements.fields.helpers.FieldsManager)1 SearchField (com.manydesigns.elements.fields.search.SearchField)1 SelectSearchField (com.manydesigns.elements.fields.search.SelectSearchField)1 DisplayMode (com.manydesigns.elements.options.DisplayMode)1 SearchDisplayMode (com.manydesigns.elements.options.SearchDisplayMode)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1