Search in sources :

Example 1 with GetActivityForms

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);
                }
            }
        });
    }
}
Also used : AttributeGroupDTO(org.activityinfo.legacy.shared.model.AttributeGroupDTO) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) Filter(org.activityinfo.legacy.shared.command.Filter) GetActivityForms(org.activityinfo.legacy.shared.command.GetActivityForms) ActivityFormResults(org.activityinfo.legacy.shared.command.result.ActivityFormResults)

Aggregations

Filter (org.activityinfo.legacy.shared.command.Filter)1 GetActivityForms (org.activityinfo.legacy.shared.command.GetActivityForms)1 ActivityFormResults (org.activityinfo.legacy.shared.command.result.ActivityFormResults)1 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)1 AttributeGroupDTO (org.activityinfo.legacy.shared.model.AttributeGroupDTO)1