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;
}
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;
}
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;
}
}
Aggregations