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