private SelectItem selectSearch;
private List<SearchWidget> searchWidgets = new ArrayList<SearchWidget>();
public CombinedSearchPanel(final MapWidget mapWidget) {
super(mapWidget);
VLayout layout = new VLayout(10);
layout.setWidth100();
layout.setHeight100();
// -- operator type --
operatorForm = new DynamicForm();
operatorForm.setWidth100();
operatorForm.setAlign(Alignment.LEFT);
type = new RadioGroupItem();
type.setTitle(messages.combinedSearchWidgetType());
type.setValueMap(messages.combinedSearchWidgetOr(), messages.combinedSearchWidgetAnd());
type.setValue(messages.combinedSearchWidgetAnd());
type.setVertical(false);
operatorForm.setFields(type);
layout.addMember(operatorForm);
// -- criteria grid --
VLayout wrapper = new VLayout(10);
searchItems = new ListGrid();
searchItems.setWidth100();
searchItems.setHeight(1);
searchItems.setShowAllRecords(true);
searchItems.setBodyOverflow(Overflow.VISIBLE);
searchItems.setOverflow(Overflow.VISIBLE);
searchItems.setLeaveScrollbarGap(false);
searchItems.setShowHeader(false);
searchItems.setShowRecordComponents(true);
searchItems.setShowRecordComponentsByCell(true);
ListGridField nameField = new ListGridField(SearchListRecord.NAME_FIELD);
nameField.setType(ListGridFieldType.TEXT);
ListGridField removeField = new ListGridField(SearchListRecord.REMOVE_FIELD);
removeField.setType(ListGridFieldType.IMAGE);
removeField.setShowHover(true);
removeField.setWidth(24);
removeField.setHoverCustomizer(new HoverCustomizer() {
public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
return messages.combinedSearchWidgetRemove();
}
});
removeField.setWidth(20);
removeField.addRecordClickHandler(new RecordClickHandler() {
public void onRecordClick(RecordClickEvent event) {
searchItems.removeData(event.getRecord());
}
});
searchItems.setFields(nameField, removeField);
updateDisplay();
HLayout addBar = new HLayout(0);
addBar.setAlign(Alignment.LEFT);
addBar.setHeight(20);
Img addImg = new Img(ADD_IMAGE, 16, 16);
addImg.setTooltip(messages.combinedSearchWidgetAdd());
DynamicForm searchForm = new DynamicForm();
selectSearch = new SelectItem();
selectSearch.setTitle(addImg.getInnerHTML());
selectSearch.setWidth(200);
selectSearch.setTooltip(messages.combinedSearchWidgetSelectSearch());
selectSearch.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
if (event.getValue() != null) {
final SearchWidget sw = getSearchWidget((String) event.getValue());
sw.showForSave(new SaveRequestHandler() {
public void onSaveRequested(SaveRequestEvent event) {
searchItems.addData(new SearchListRecord(sw.getName(), event.getCriterion()));
updateDisplay();
}
});
}
event.cancel();
}
});
searchForm.setFields(selectSearch);
addBar.addMember(searchForm);
wrapper.setOverflow(Overflow.AUTO);
wrapper.addMember(searchItems);
wrapper.addMember(addBar);
layout.addMember(wrapper);
addChild(layout);
}