Search in sources :

Example 1 with FieldsManager

use of com.manydesigns.elements.fields.helpers.FieldsManager in project Portofino by ManyDesigns.

the class FormBuilderTest method testRegistry.

public void testRegistry() {
    FieldsManager fieldsManager = FieldsManager.getManager();
    assertEquals(15, fieldsManager.getHelperList().size());
    Form form = formBuilder1.build();
    assertEquals(1, form.size());
    FieldSet fieldSet = form.get(0);
    assertEquals(16, fieldSet.size());
    Field field = (Field) fieldSet.get(0);
    assertEquals("A private int", field.getLabel());
    assertTrue(field.isRequired());
    assertEquals(NumericField.class, field.getClass());
    field = (Field) fieldSet.get(1);
    assertEquals("a boolean1", field.getLabel());
    assertTrue(field.isRequired());
    assertEquals(BooleanField.class, field.getClass());
    field = (Field) fieldSet.get(2);
    assertEquals("a boolean2", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(BooleanField.class, field.getClass());
    field = (Field) fieldSet.get(3);
    assertEquals("date", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(DateField.class, field.getClass());
    field = (Field) fieldSet.get(4);
    assertEquals("decimal", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(NumericField.class, field.getClass());
    field = (Field) fieldSet.get(5);
    assertEquals("an int", field.getLabel());
    assertTrue(field.isRequired());
    assertEquals(NumericField.class, field.getClass());
    field = (Field) fieldSet.get(6);
    assertEquals("an integer", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(NumericField.class, field.getClass());
    field = (Field) fieldSet.get(7);
    assertEquals("cap", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(CAPField.class, field.getClass());
    field = (Field) fieldSet.get(8);
    assertEquals("codice fiscale", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(CodiceFiscaleField.class, field.getClass());
    field = (Field) fieldSet.get(9);
    assertEquals("email", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(EmailField.class, field.getClass());
    field = (Field) fieldSet.get(10);
    assertEquals("partita iva", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(PartitaIvaField.class, field.getClass());
    field = (Field) fieldSet.get(11);
    assertEquals("password", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(PasswordField.class, field.getClass());
    field = (Field) fieldSet.get(12);
    assertEquals("phone", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(PhoneField.class, field.getClass());
    field = (Field) fieldSet.get(13);
    assertEquals("select", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(SelectField.class, field.getClass());
    field = (Field) fieldSet.get(14);
    assertEquals("text", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(TextField.class, field.getClass());
    field = (Field) fieldSet.get(15);
    assertEquals("a blob", field.getLabel());
    assertFalse(field.isRequired());
    assertEquals(FileBlobField.class, field.getClass());
}
Also used : FieldsManager(com.manydesigns.elements.fields.helpers.FieldsManager)

Example 2 with FieldsManager

use of com.manydesigns.elements.fields.helpers.FieldsManager 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

FieldsManager (com.manydesigns.elements.fields.helpers.FieldsManager)2 SearchField (com.manydesigns.elements.fields.search.SearchField)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