use of org.activityinfo.legacy.shared.command.GetActivityForms in project activityinfo by bedatadriven.
the class AttributeGroupFilterWidgets method draw.
public void draw(final Filter filter) {
final Filter value = new Filter(filter);
value.clearRestrictions(DIMENSION_TYPE);
// prevents executing the same command needlessly
if (prevFilter == null || !prevFilter.equals(filter)) {
prevFilter = filter;
Log.debug("AttributeGroupFilterWidgets called for filter " + filter);
service.execute(new GetActivityForms(filter), new AsyncCallback<ActivityFormResults>() {
@Override
public void onFailure(Throwable caught) {
GWT.log("Failed to load schema", caught);
}
@Override
public void onSuccess(final ActivityFormResults forms) {
// clean up old widgets
for (AttributeGroupFilterWidget widget : widgets) {
panel.remove(widget);
}
// create new widgets, one for each attributegroup.
// remember the old selection
Set<Integer> selection = getSelectedIds();
widgets = new ArrayList<AttributeGroupFilterWidget>();
Set<String> attributesByName = Sets.newHashSet();
for (ActivityFormDTO form : forms.getData()) {
for (AttributeGroupDTO group : form.getAttributeGroups()) {
String key = group.getName().toLowerCase();
if (!attributesByName.contains(key)) {
AttributeGroupFilterWidget widget = new AttributeGroupFilterWidget(group);
widget.setSelection(selection);
if (valueChangeHandler != null) {
widget.addValueChangeHandler(valueChangeHandler);
}
panel.add(widget);
widgets.add(widget);
attributesByName.add(key);
}
}
}
if (drawCallback != null) {
drawCallback.onSuccess(null);
}
}
});
}
}
Aggregations