Search in sources :

Example 31 with Filter

use of org.activityinfo.shared.command.Filter 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);
        // retrieve all attributegroups for the current filter
        service.execute(new GetAttributeGroupsDimension(value), new AsyncCallback<AttributeGroupResult>() {

            @Override
            public void onFailure(Throwable caught) {
                GWT.log("Failed to load attributes", caught);
            }

            @Override
            public void onSuccess(final AttributeGroupResult attributeGroupResult) {
                // if the result is indeed different from the last time, (re)draw the widgets
                if (prevResult == null || !prevResult.equals(attributeGroupResult)) {
                    prevResult = attributeGroupResult;
                    Log.debug("AttributeGroupFilterWidgets drawing widgets for result: " + attributeGroupResult);
                    service.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            GWT.log("Failed to load schema", caught);
                        }

                        @Override
                        public void onSuccess(final SchemaDTO schema) {
                            // clean up old widgets
                            for (AttributeGroupFilterWidget widget : widgets) {
                                panel.remove(widget);
                            }
                            duplicates.clear();
                            // decorate resultlist from schema
                            List<AttributeGroupDTO> pivotData = attributeGroupResult.getData();
                            groups = new ArrayList<AttributeGroupDTO>();
                            if (CollectionUtil.isNotEmpty(pivotData)) {
                                for (AttributeGroupDTO pivotGroup : pivotData) {
                                    AttributeGroupDTO schemaGroup = schema.getAttributeGroupById(pivotGroup.getId());
                                    if (schemaGroup != null) {
                                        groups.add(schemaGroup);
                                    }
                                }
                            }
                            // create new widgets, one for each attributegroup.
                            // remember the old selection
                            List<Integer> selection = getSelectedIds();
                            widgets = new ArrayList<AttributeGroupFilterWidget>();
                            for (AttributeGroupDTO group : groups) {
                                // create
                                AttributeGroupFilterWidget widget = new AttributeGroupFilterWidget(group);
                                // set old selection
                                widget.setSelection(selection);
                                // what to do when value changes
                                if (valueChangeHandler != null) {
                                    widget.addValueChangeHandler(valueChangeHandler);
                                }
                                // already been added
                                if (isNoDuplicate(widget)) {
                                    widgets.add(widget);
                                    panel.add(widget);
                                } else {
                                    // otherwise add to collection of duplicates
                                    duplicates.put(group.getName().toLowerCase(), widget);
                                }
                            }
                            if (drawCallback != null) {
                                drawCallback.onSuccess(null);
                            }
                        }
                    });
                }
            }
        });
    }
}
Also used : AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) AttributeGroupResult(org.activityinfo.shared.command.result.AttributeGroupResult) Filter(org.activityinfo.shared.command.Filter) GetAttributeGroupsDimension(org.activityinfo.shared.command.GetAttributeGroupsDimension) GetSchema(org.activityinfo.shared.command.GetSchema)

Example 32 with Filter

use of org.activityinfo.shared.command.Filter in project activityinfo by bedatadriven.

the class FilterWidget method setValue.

@Override
public final void setValue(Filter value, boolean fireEvents) {
    if (value == null) {
        value = new Filter();
    }
    this.value = value;
    if (fireEvents) {
        ValueChangeEvent.fire(this, this.value);
    }
    updateView();
}
Also used : Filter(org.activityinfo.shared.command.Filter)

Example 33 with Filter

use of org.activityinfo.shared.command.Filter in project activityinfo by bedatadriven.

the class PartnerFilterPanel method applyFilter.

protected void applyFilter() {
    value = new Filter();
    if (isRendered()) {
        List<Integer> selectedIds = getSelectedIds();
        if (selectedIds.size() > 0) {
            value.addRestriction(DimensionType.Partner, getSelectedIds());
        }
    }
    ValueChangeEvent.fire(this, value);
    filterToolBar.setApplyFilterEnabled(false);
    filterToolBar.setRemoveFilterEnabled(true);
}
Also used : Filter(org.activityinfo.shared.command.Filter)

Example 34 with Filter

use of org.activityinfo.shared.command.Filter in project activityinfo by bedatadriven.

the class PartnerFilterPanel method applyBaseFilter.

@Override
public void applyBaseFilter(Filter rawFilter) {
    // we need to remove any partner filter from this base filter
    // so the user has the full selection
    final Filter filter = new Filter(rawFilter);
    filter.clearRestrictions(DimensionType.Partner);
    if (baseFilter == null || !baseFilter.equals(filter)) {
        service.execute(new GetPartnersDimension(filter), new AsyncCallback<PartnerResult>() {

            @Override
            public void onFailure(Throwable caught) {
            }

            @Override
            public void onSuccess(PartnerResult result) {
                List<Integer> ids = getSelectedIds();
                store.removeAll();
                store.add(result.getData());
                applyInternalValue();
                for (PartnerDTO partner : store.getModels()) {
                    if (ids.contains(partner.getId())) {
                        listView.setChecked(partner, true);
                    }
                }
                baseFilter = filter;
            }
        });
    }
}
Also used : PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) Filter(org.activityinfo.shared.command.Filter) ArrayList(java.util.ArrayList) List(java.util.List) PartnerResult(org.activityinfo.shared.command.result.PartnerResult) GetPartnersDimension(org.activityinfo.shared.command.GetPartnersDimension)

Example 35 with Filter

use of org.activityinfo.shared.command.Filter in project activityinfo by bedatadriven.

the class AttributeFilterPanel method clearFilter.

protected void clearFilter() {
    value = new Filter();
    widgets.clearFilter();
    filterToolBar.setRemoveFilterEnabled(false);
}
Also used : Filter(org.activityinfo.shared.command.Filter)

Aggregations

Filter (org.activityinfo.shared.command.Filter)59 GetSites (org.activityinfo.shared.command.GetSites)8 Test (org.junit.Test)8 GetSchema (org.activityinfo.shared.command.GetSchema)5 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)5 DimensionType (org.activityinfo.shared.report.model.DimensionType)5 ArrayList (java.util.ArrayList)4 SiteDTO (org.activityinfo.shared.dto.SiteDTO)4 DateRange (org.activityinfo.shared.report.model.DateRange)4 StringWriter (java.io.StringWriter)3 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)3 SiteResult (org.activityinfo.shared.command.result.SiteResult)3 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)3 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)3 Margins (com.extjs.gxt.ui.client.util.Margins)2 BorderLayoutData (com.extjs.gxt.ui.client.widget.layout.BorderLayoutData)2 JsonElement (com.google.gson.JsonElement)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 List (java.util.List)2