private List<DistrictComparisons> getSummaries(List<DistrictComparisons> list, User user) { List<DistrictComparisons> result = new ArrayList<DistrictComparisons>(); for (DistrictComparisons comparison : list) { if (comparison .getDistrict() .equals(user.getSubcounty().getCounty().getDistrict().getName())) { result.add(comparison); } } return result; }
@Override public void refresh(RefreshableEvent event) { if (event.getEventType() == RefreshableEvent.Type.DISTRICT_SUMMARIES) { ListStore<DistrictComparisonSummary> store1 = grid.getStore(); if (store1.getCount() > 0) { store1.removeAll(); } List<DistrictComparisons> summaries = getSummaries((List<DistrictComparisons>) event.getData(), parentView.loggedUser); for (DistrictComparisons d : summaries) { final String district = d.getDistrict(); final String subcounty = d.getSubcounty(); final String boreholes = d.getBoreholes(); final String shallowWells = d.getShallowWells(); final String publicTaps = d.getPublicTaps(); final String protectedSprings = d.getProtectedSprings(); int total = Integer.parseInt(boreholes) + Integer.parseInt(shallowWells) + Integer.parseInt(publicTaps) + Integer.parseInt(protectedSprings); DistrictComparisonSummary summary = new DistrictComparisonSummary( district, subcounty, boreholes, shallowWells, publicTaps, protectedSprings, String.valueOf(total)); store1.add(summary); } } }