Search in sources :

Example 11 with SelectionProvider

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

the class AbstractCrudAction method getAllSelectionProviders.

// **************************************************************************
// Configuration
// **************************************************************************
@GET
@Path(":allSelectionProviders")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "The list of selection providers configured on this crud action.")
public CrudSelectionProviderEdit[] getAllSelectionProviders() {
    Map<List<String>, Collection<String>> availableSelectionProviders = selectionProviderSupport.getAvailableSelectionProviderNames();
    CrudSelectionProviderEdit[] selectionProviderEdits = new CrudSelectionProviderEdit[availableSelectionProviders.size()];
    int i = 0;
    for (Map.Entry<List<String>, Collection<String>> entry : availableSelectionProviders.entrySet()) {
        CrudSelectionProviderEdit selectionProviderEdit = new CrudSelectionProviderEdit();
        selectionProviderEdits[i] = selectionProviderEdit;
        String[] fieldNames = entry.getKey().toArray(new String[0]);
        selectionProviderEdit.fieldNames = fieldNames;
        selectionProviderEdit.availableSelectionProviders = entry.getValue();
        selectionProviderEdit.displayModeName = DisplayMode.DROPDOWN.name();
        selectionProviderEdit.searchDisplayModeName = SearchDisplayMode.DROPDOWN.name();
        for (CrudSelectionProvider cp : selectionProviderSupport.getCrudSelectionProviders()) {
            if (Arrays.equals(cp.fieldNames, fieldNames)) {
                SelectionProvider selectionProvider = cp.getSelectionProvider();
                if (selectionProvider != null) {
                    selectionProviderEdit.selectionProviderName = selectionProvider.getName();
                    DisplayMode displayMode = selectionProvider.getDisplayMode();
                    if (displayMode != null) {
                        selectionProviderEdit.displayModeName = displayMode.name();
                    }
                    SearchDisplayMode searchDisplayMode = selectionProvider.getSearchDisplayMode();
                    if (searchDisplayMode != null) {
                        selectionProviderEdit.searchDisplayModeName = searchDisplayMode.name();
                    }
                }
            }
        }
        i++;
    }
    return selectionProviderEdits;
}
Also used : SearchDisplayMode(com.manydesigns.elements.options.SearchDisplayMode) DisplayMode(com.manydesigns.elements.options.DisplayMode) SearchDisplayMode(com.manydesigns.elements.options.SearchDisplayMode) SelectionProvider(com.manydesigns.elements.options.SelectionProvider) Operation(io.swagger.v3.oas.annotations.Operation)

Example 12 with SelectionProvider

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

the class AbstractCrudAction method selectionProviders.

@GET
@Path(":selectionProvider")
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("unchecked")
@Operation(summary = "The list of selection providers supported by this resource")
public List selectionProviders() {
    List<Map<?, ?>> result = new ArrayList<>();
    // setup option providers
    for (CrudSelectionProvider current : selectionProviderSupport.getCrudSelectionProviders()) {
        SelectionProvider selectionProvider = current.getSelectionProvider();
        if (selectionProvider == null) {
            continue;
        }
        String[] fieldNames = current.getFieldNames();
        Map description = new HashMap();
        description.put("name", selectionProvider.getName());
        description.put("fieldNames", Arrays.asList(fieldNames));
        description.put("displayMode", selectionProvider.getDisplayMode());
        description.put("searchDisplayMode", selectionProvider.getSearchDisplayMode());
        result.add(description);
    }
    return result;
}
Also used : SelectionProvider(com.manydesigns.elements.options.SelectionProvider) Operation(io.swagger.v3.oas.annotations.Operation)

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