use of com.vaadin.ui.AbstractOrderedLayout in project SORMAS-Project by hzi-braunschweig.
the class StatisticsView method generateMap.
public void generateMap() {
List<StatisticsCaseCountDto> resultData = generateStatistics();
if (resultData.isEmpty()) {
resultsLayout.addComponent(emptyResultLabel);
return;
}
if (showCaseIncidence && caseIncidencePossible && populationReferenceYear != null && populationReferenceYear != Calendar.getInstance().get(Calendar.YEAR)) {
referenceYearLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml() + " " + String.format(I18nProperties.getString(Strings.infoPopulationReferenceYear), populationReferenceYear), ContentMode.HTML);
resultsLayout.addComponent(referenceYearLabel);
CssStyles.style(referenceYearLabel, CssStyles.VSPACE_TOP_4);
}
if (showCaseIncidence && (!caseIncidencePossible || hasMissingPopulationData)) {
if (!caseIncidencePossible) {
if (hasMissingPopulationData) {
caseIncidenceNotPossibleLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml() + " " + String.format(I18nProperties.getString(Strings.infoCaseIncidenceNotPossible), missingPopulationDataNames), ContentMode.HTML);
} else {
caseIncidenceNotPossibleLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml() + " " + I18nProperties.getString(Strings.infoCaseIncidenceIncompatible), ContentMode.HTML);
}
} else {
caseIncidenceNotPossibleLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml() + " " + String.format(I18nProperties.getString(Strings.infoCaseIncidenceMissingPopulationData), missingPopulationDataNames), ContentMode.HTML);
}
resultsLayout.addComponent(caseIncidenceNotPossibleLabel);
caseIncidenceNotPossibleLabel.setWidth(100, Unit.PERCENTAGE);
CssStyles.style(caseIncidenceNotPossibleLabel, CssStyles.VSPACE_TOP_4);
}
HorizontalLayout mapLayout = new HorizontalLayout();
mapLayout.setSpacing(true);
mapLayout.setMargin(false);
mapLayout.setWidth(100, Unit.PERCENTAGE);
mapLayout.setHeightUndefined();
LeafletMap map = new LeafletMap();
map.setTileLayerOpacity(0.5f);
map.setWidth(100, Unit.PERCENTAGE);
map.setHeight(580, Unit.PIXELS);
map.setZoom(FacadeProvider.getConfigFacade().getMapZoom());
GeoLatLon mapCenter = FacadeProvider.getGeoShapeProvider().getCenterOfAllRegions();
if (mapCenter != null) {
map.setCenter(mapCenter);
} else {
GeoLatLon countryCenter = FacadeProvider.getConfigFacade().getCountryCenter();
map.setCenter(countryCenter);
}
if (cbHideOtherCountries.getValue()) {
LeafletMapUtil.addOtherCountriesOverlay(map);
}
List<RegionReferenceDto> regions = FacadeProvider.getRegionFacade().getAllActiveByServerCountry();
List<LeafletPolygon> outlinePolygones = new ArrayList<>();
// draw outlines of all regions
for (RegionReferenceDto region : regions) {
GeoLatLon[][] regionShape = FacadeProvider.getGeoShapeProvider().getRegionShape(region);
if (regionShape == null) {
continue;
}
// fillOpacity is used, so we can still hover the region
Arrays.stream(regionShape).forEach(regionShapePart -> {
LeafletPolygon polygon = new LeafletPolygon();
polygon.setCaption(region.getCaption());
polygon.setOptions("{\"weight\": 1, \"color\": '#888', \"fillOpacity\": 0.02}");
polygon.setLatLons(regionShapePart);
outlinePolygones.add(polygon);
});
}
map.addPolygonGroup("outlines", outlinePolygones);
if (!showCaseIncidence || !caseIncidencePossible) {
resultData.sort(Comparator.comparingInt(StatisticsCaseCountDto::getCaseCount));
} else {
resultData.sort((a, b) -> {
BigDecimal incidenceA = a.getIncidence(incidenceDivisor);
BigDecimal incidenceB = b.getIncidence(incidenceDivisor);
return DataHelper.compare(incidenceA, incidenceB);
});
}
BigDecimal valuesLowerQuartile, valuesMedian, valuesUpperQuartile;
if (!showCaseIncidence || !caseIncidencePossible) {
valuesLowerQuartile = resultData.size() > 0 ? new BigDecimal(resultData.get((int) (resultData.size() * 0.25)).getCaseCount()) : BigDecimal.ZERO;
valuesMedian = resultData.size() > 0 ? new BigDecimal(resultData.get((int) (resultData.size() * 0.5)).getCaseCount()) : BigDecimal.ZERO;
valuesUpperQuartile = resultData.size() > 0 ? new BigDecimal(resultData.get((int) (resultData.size() * 0.75)).getCaseCount()) : BigDecimal.ZERO;
} else {
valuesLowerQuartile = resultData.size() > 0 ? resultData.get((int) (resultData.size() * 0.25)).getIncidence(incidenceDivisor) : BigDecimal.ZERO;
if (valuesLowerQuartile == null) {
valuesLowerQuartile = BigDecimal.ZERO;
}
valuesMedian = resultData.size() > 0 ? resultData.get((int) (resultData.size() * 0.5)).getIncidence(incidenceDivisor) : BigDecimal.ZERO;
if (valuesMedian == null) {
valuesMedian = BigDecimal.ZERO;
}
valuesUpperQuartile = resultData.size() > 0 ? resultData.get((int) (resultData.size() * 0.75)).getIncidence(incidenceDivisor) : BigDecimal.ZERO;
if (valuesUpperQuartile == null) {
valuesUpperQuartile = BigDecimal.ZERO;
}
}
List<LeafletPolygon> resultPolygons = new ArrayList<LeafletPolygon>();
boolean hasNullValue = false;
// Draw relevant district fills
for (StatisticsCaseCountDto resultRow : resultData) {
ReferenceDto regionOrDistrict = (ReferenceDto) resultRow.getRowKey();
String shapeUuid = regionOrDistrict.getUuid();
BigDecimal regionOrDistrictValue;
if (!showCaseIncidence || !caseIncidencePossible) {
regionOrDistrictValue = new BigDecimal(resultRow.getCaseCount());
} else {
regionOrDistrictValue = resultRow.getIncidence(incidenceDivisor);
}
hasNullValue |= regionOrDistrictValue == null;
GeoLatLon[][] shape;
switch(visualizationComponent.getVisualizationMapType()) {
case REGIONS:
shape = FacadeProvider.getGeoShapeProvider().getRegionShape(new RegionReferenceDto(shapeUuid, null, null));
break;
case DISTRICTS:
shape = FacadeProvider.getGeoShapeProvider().getDistrictShape(new DistrictReferenceDto(shapeUuid, null, null));
break;
default:
throw new IllegalArgumentException(visualizationComponent.getVisualizationMapType().toString());
}
if (shape == null) {
continue;
}
for (int part = 0; part < shape.length; part++) {
GeoLatLon[] shapePart = shape[part];
String fillColor;
String fillOpacity = "0.8";
if (regionOrDistrictValue == null) {
fillColor = "#888";
} else if (regionOrDistrictValue.compareTo(BigDecimal.ZERO) == 0) {
fillColor = "#000";
fillOpacity = "0";
} else if (regionOrDistrictValue.compareTo(valuesLowerQuartile) < 0) {
fillColor = "#FEDD6C";
} else if (regionOrDistrictValue.compareTo(valuesMedian) < 0) {
fillColor = "#FDBF44";
} else if (regionOrDistrictValue.compareTo(valuesUpperQuartile) < 0) {
fillColor = "#F47B20";
} else {
fillColor = "#ED1B24";
}
LeafletPolygon polygon = new LeafletPolygon();
if (regionOrDistrictValue == null) {
polygon.setCaption(regionOrDistrict.getCaption() + "<br>" + I18nProperties.getCaption(Captions.notAvailableShort));
} else {
polygon.setCaption(regionOrDistrict.getCaption() + "<br>" + regionOrDistrictValue);
}
// fillOpacity is used, so we can still hover the region
polygon.setOptions("{\"stroke\": true, \"color\": '#000000', \"weight\": 1, \"fillColor\": '" + fillColor + "', \"fillOpacity\": " + fillOpacity + "}");
polygon.setLatLons(shapePart);
resultPolygons.add(polygon);
}
}
// sort polygon array, so that polygons which are completely contained by another appear on top
List<Integer[]> indexesToSwap = new ArrayList<>();
for (int poly1index = 0; poly1index < resultPolygons.size(); poly1index++) {
LeafletPolygon poly1 = resultPolygons.get(poly1index);
for (int poly2index = poly1index; poly2index < resultPolygons.size(); poly2index++) {
LeafletPolygon poly2 = resultPolygons.get(poly2index);
if (poly1index == poly2index) {
continue;
}
// if the max/min values of poly1 are completely inside those of poly2, switch both
if (poly1.getMaxLatLon()[0] < poly2.getMaxLatLon()[0] && poly1.getMinLatLon()[0] > poly2.getMinLatLon()[0] && poly1.getMaxLatLon()[1] < poly2.getMaxLatLon()[1] && poly1.getMinLatLon()[1] > poly2.getMinLatLon()[1]) {
// make sure not to change the list we are currently iterating over
indexesToSwap.add(new Integer[] { poly1index, poly2index });
}
}
}
for (Integer[] swaps : indexesToSwap) {
Collections.swap(resultPolygons, swaps[0], swaps[1]);
}
map.addPolygonGroup("results", resultPolygons);
mapLayout.addComponent(map);
mapLayout.setExpandRatio(map, 1);
if (showCaseIncidence && caseIncidencePossible) {
valuesLowerQuartile = valuesLowerQuartile.setScale(2, RoundingMode.HALF_UP);
valuesMedian = valuesMedian.setScale(2, RoundingMode.HALF_UP);
valuesUpperQuartile = valuesUpperQuartile.setScale(2, RoundingMode.HALF_UP);
}
AbstractOrderedLayout regionLegend = DashboardMapComponent.buildRegionLegend(true, showCaseIncidence && caseIncidencePossible ? CaseMeasure.CASE_INCIDENCE : CaseMeasure.CASE_COUNT, hasNullValue, valuesLowerQuartile, valuesMedian, valuesUpperQuartile, incidenceDivisor);
Label legendHeader = new Label(I18nProperties.getCaption(Captions.dashboardMapKey));
CssStyles.style(legendHeader, CssStyles.H4, CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_NONE);
regionLegend.addComponent(legendHeader, 0);
mapLayout.addComponent(regionLegend);
mapLayout.setExpandRatio(regionLegend, 0);
resultsLayout.addComponent(mapLayout);
resultsLayout.setExpandRatio(mapLayout, 1);
if (showCaseIncidence && hasMissingPopulationData && caseIncidencePossible) {
resultsLayout.addComponent(caseIncidenceNotPossibleLabel);
}
}
use of com.vaadin.ui.AbstractOrderedLayout in project SORMAS-Project by hzi-braunschweig.
the class SormasToSormasListComponent method reloadList.
public void reloadList() {
UI currentUI = UI.getCurrent();
UserDto currentUser = FacadeProvider.getUserFacade().getCurrentUser();
sormasToSormasList.showPlaceholder(I18nProperties.getString(Strings.sormasToSormasLoadingShares));
Thread loadSharesThread = new Thread(() -> {
try {
I18nProperties.setUserLanguage(currentUser.getLanguage());
FacadeProvider.getI18nFacade().setUserLanguage(currentUser.getLanguage());
currentUI.setPollInterval(300);
List<SormasToSormasShareTree> shareInfos = loadShares.load();
String currentServerOrgId = FacadeProvider.getSormasToSormasFacade().getOrganizationId();
List<SormasToSormasShareInfoDto> shareInfoList = getShareInfoList(shareInfos);
SormasToSormasShareInfoDto ownerShare = getOwnerShare(shareInfos);
SormasToSormasOriginInfoDto rootOrigin = findRootOriginInfo(shareInfos);
List<String> directShareUuids = getDirectShares(shareInfos).stream().map(s -> s.getShare().getUuid()).collect(Collectors.toList());
String ownerOrganizationId = getOwnerOrganizationId(ownerShare, rootOrigin, currentServerOrgId);
boolean isOwnedByCurrentOrg = currentServerOrgId.equals(ownerOrganizationId);
boolean isOwnedByOrigin = originInfo != null && originInfo.getOrganizationId().equals(ownerOrganizationId);
boolean isOwnedByRootOrg = rootOrigin != null && rootOrigin.getOrganizationId().equals(ownerOrganizationId);
currentUI.access(() -> {
try {
// render origin
if (originInfo != null) {
HorizontalLayout originLayout = buildSormasOriginInfo(originInfo, isOwnedByOrigin);
originLayout.addStyleName(CssStyles.VSPACE_3);
addComponent(originLayout, getComponentIndex(sormasToSormasList));
}
// render the owner of the entity
if (!isOwnedByCurrentOrg && !isOwnedByOrigin) {
AbstractOrderedLayout ownerLayout = null;
if (isOwnedByRootOrg) {
ownerLayout = buildSormasOriginInfo(rootOrigin, true);
} else if (ownerShare != null && !ownerShare.getTargetDescriptor().getId().equals(currentServerOrgId)) {
ownerLayout = buildOwnerShareLayout(ownerShare);
}
if (ownerLayout != null) {
ownerLayout.addStyleName(CssStyles.VSPACE_3);
addComponent(ownerLayout, getComponentIndex(sormasToSormasList));
}
}
// show shares to other systems then owner and current one
List<SormasToSormasShareListEntryData> listData = shareInfoList.stream().filter(s -> {
String shareOrganizationId = s.getTargetDescriptor().getId();
if (ownerShare != null && shareOrganizationId.equals(ownerShare.getTargetDescriptor().getId())) {
return false;
}
if (originInfo != null && shareOrganizationId.equals(originInfo.getOrganizationId()) && // show return share
!(s.getRequestStatus() == ShareRequestStatus.PENDING && directShareUuids.contains(s.getUuid()))) {
return false;
}
if (isOwnedByRootOrg && shareOrganizationId.equals(rootOrigin.getOrganizationId())) {
return false;
}
return !shareOrganizationId.equals(currentServerOrgId);
}).map(s -> {
SormasToSormasShareListEntryData entryData = new SormasToSormasShareListEntryData();
entryData.shareUuid = s.getUuid();
entryData.target = s.getTargetDescriptor().getName();
entryData.sender = s.getSender().getShortCaption();
entryData.status = s.getRequestStatus();
entryData.creationDate = s.getCreationDate();
entryData.comment = s.getComment();
entryData.ownershipHandedOver = s.isOwnershipHandedOver();
entryData.responseComment = s.getResponseComment();
entryData.isDirectShare = directShareUuids.contains(s.getUuid());
return entryData;
}).collect(Collectors.toList());
// add the creator of the entity as a share
if (!isOwnedByRootOrg && rootOrigin != null && originInfo != null && !rootOrigin.getOrganizationId().equals(currentServerOrgId) && !rootOrigin.getOrganizationId().equals(originInfo.getOrganizationId())) {
SormasServerDescriptor serverDescriptor = FacadeProvider.getSormasToSormasFacade().getSormasServerDescriptorById(rootOrigin.getOrganizationId());
SormasToSormasShareListEntryData entryData = new SormasToSormasShareListEntryData();
entryData.shareUuid = null;
entryData.target = serverDescriptor.getName();
entryData.sender = rootOrigin.getSenderName();
entryData.status = ShareRequestStatus.ACCEPTED;
entryData.creationDate = rootOrigin.getCreationDate();
entryData.comment = rootOrigin.getComment();
entryData.ownershipHandedOver = rootOrigin.isOwnershipHandedOver();
listData.add(entryData);
}
if (shareInfoList.size() > 0) {
if (listData.size() > 0) {
Label shareListLabel = new Label(I18nProperties.getCaption(Captions.sormasToSormasSharedWith));
shareListLabel.addStyleNames(CssStyles.LABEL_BOLD, CssStyles.VSPACE_4);
addComponent(shareListLabel, getComponentIndex(sormasToSormasList));
sormasToSormasList.setData(listData);
} else {
sormasToSormasList.setVisible(false);
}
} else {
sormasToSormasList.showPlaceholder(null);
}
} catch (Exception e) {
logger.error("Failed to load shares", e);
sormasToSormasList.showPlaceholder(I18nProperties.getString(Strings.errorSormasToSormasLoadShares));
} finally {
currentUI.setPollInterval(-1);
}
});
} catch (Exception e) {
logger.error(e.getMessage(), e);
currentUI.setPollInterval(-1);
currentUI.access(() -> {
sormasToSormasList.showPlaceholder(I18nProperties.getString(Strings.errorSormasToSormasLoadShares));
});
}
});
loadSharesThread.start();
}
use of com.vaadin.ui.AbstractOrderedLayout in project cuba by cuba-platform.
the class DefaultFormLayoutDropHandler method handleDropFromLayout.
/*
* (non-Javadoc)
*
* @see
* com.haulmont.cuba.web.widgets.addons.dragdroplayouts.drophandlers.AbstractDefaultLayoutDropHandler
* #handleDropFromLayout(com.vaadin.event.dd.DragAndDropEvent)
*/
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
FormLayoutTargetDetails details = (FormLayoutTargetDetails) event.getTargetDetails();
AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
Component source = event.getTransferable().getSourceComponent();
int idx = details.getOverIndex();
Component comp = transferable.getComponent();
// Check that we are not dragging an outer layout into an inner
// layout
Component parent = layout.getParent();
while (parent != null) {
if (parent == comp) {
return;
}
parent = parent.getParent();
}
// Detach from old source
if (source instanceof ComponentContainer) {
((ComponentContainer) source).removeComponent(comp);
} else if (source instanceof SingleComponentContainer) {
((SingleComponentContainer) source).setContent(null);
}
// Increase index if component is dropped after or above a
// previous
// component
VerticalDropLocation loc = (details).getDropLocation();
if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) {
idx++;
}
// Add component
if (idx >= 0) {
layout.addComponent(comp, idx);
} else {
layout.addComponent(comp);
}
// Add component alignment if given
if (dropAlignment != null) {
layout.setComponentAlignment(comp, dropAlignment);
}
}
use of com.vaadin.ui.AbstractOrderedLayout in project cuba by cuba-platform.
the class DefaultVerticalLayoutDropHandler method handleHTML5Drop.
@Override
protected void handleHTML5Drop(DragAndDropEvent event) {
VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event.getTargetDetails();
AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
int idx = (details).getOverIndex();
// Increase index if component is dropped after or above a
// previous
// component
VerticalDropLocation loc = (details).getDropLocation();
if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) {
idx++;
}
Component comp = resolveComponentFromHTML5Drop(event);
// Add component
if (idx >= 0) {
layout.addComponent(comp, idx);
} else {
layout.addComponent(comp);
}
// Add component alignment if given
if (dropAlignment != null) {
layout.setComponentAlignment(comp, dropAlignment);
}
}
use of com.vaadin.ui.AbstractOrderedLayout in project cuba by cuba-platform.
the class DefaultVerticalLayoutDropHandler method handleDropFromLayout.
/**
* Handle a drop from another layout
*
* @param event
* The drag and drop event
*/
@Override
protected void handleDropFromLayout(DragAndDropEvent event) {
LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
VerticalLayoutTargetDetails details = (VerticalLayoutTargetDetails) event.getTargetDetails();
AbstractOrderedLayout layout = (AbstractOrderedLayout) details.getTarget();
Component source = event.getTransferable().getSourceComponent();
int idx = (details).getOverIndex();
Component comp = transferable.getComponent();
// Check that we are not dragging an outer layout into an inner
// layout
Component parent = layout.getParent();
while (parent != null) {
if (parent == comp) {
return;
}
parent = parent.getParent();
}
// Detach from old source
if (source instanceof ComponentContainer) {
((ComponentContainer) source).removeComponent(comp);
} else if (source instanceof SingleComponentContainer) {
((SingleComponentContainer) source).setContent(null);
}
// Increase index if component is dropped after or above a
// previous
// component
VerticalDropLocation loc = (details).getDropLocation();
if (loc == VerticalDropLocation.MIDDLE || loc == VerticalDropLocation.BOTTOM) {
idx++;
}
// Add component
if (idx >= 0) {
layout.addComponent(comp, idx);
} else {
layout.addComponent(comp);
}
// Add component alignment if given
if (dropAlignment != null) {
layout.setComponentAlignment(comp, dropAlignment);
}
}
Aggregations