Search in sources :

Example 16 with AbstractOrderedLayout

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);
    }
}
Also used : ReferenceDto(de.symeda.sormas.api.ReferenceDto) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Label(com.vaadin.ui.Label) ArrayList(java.util.ArrayList) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) BigDecimal(java.math.BigDecimal) HorizontalLayout(com.vaadin.ui.HorizontalLayout) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) LeafletMap(de.symeda.sormas.ui.map.LeafletMap) StatisticsCaseCountDto(de.symeda.sormas.api.statistics.StatisticsCaseCountDto) LeafletPolygon(de.symeda.sormas.ui.map.LeafletPolygon) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout) GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon)

Example 17 with AbstractOrderedLayout

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();
}
Also used : SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) FeatureType(de.symeda.sormas.api.feature.FeatureType) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) PaginationList(de.symeda.sormas.ui.utils.PaginationList) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) Date(java.util.Date) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DateFormatHelper(de.symeda.sormas.ui.utils.DateFormatHelper) VerticalLayout(com.vaadin.ui.VerticalLayout) SormasToSormasShareInfoDto(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoDto) LoggerFactory(org.slf4j.LoggerFactory) Alignment(com.vaadin.ui.Alignment) UI(com.vaadin.ui.UI) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) CssStyles(de.symeda.sormas.ui.utils.CssStyles) Label(com.vaadin.ui.Label) VaadinIcons(com.vaadin.icons.VaadinIcons) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) ValoTheme(com.vaadin.ui.themes.ValoTheme) Logger(org.slf4j.Logger) SormasToSormasShareInfoCriteria(de.symeda.sormas.api.sormastosormas.shareinfo.SormasToSormasShareInfoCriteria) DataHelper(de.symeda.sormas.api.utils.DataHelper) UserDto(de.symeda.sormas.api.user.UserDto) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) EventDto(de.symeda.sormas.api.event.EventDto) ShareRequestStatus(de.symeda.sormas.api.sormastosormas.sharerequest.ShareRequestStatus) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) Consumer(java.util.function.Consumer) List(java.util.List) Button(com.vaadin.ui.Button) Stream(java.util.stream.Stream) SampleDto(de.symeda.sormas.api.sample.SampleDto) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ContactDto(de.symeda.sormas.api.contact.ContactDto) Optional(java.util.Optional) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) UserDto(de.symeda.sormas.api.user.UserDto) Label(com.vaadin.ui.Label) SormasToSormasOriginInfoDto(de.symeda.sormas.api.sormastosormas.SormasToSormasOriginInfoDto) SormasToSormasShareTree(de.symeda.sormas.api.sormastosormas.SormasToSormasShareTree) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SormasServerDescriptor(de.symeda.sormas.api.sormastosormas.SormasServerDescriptor) UI(com.vaadin.ui.UI) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout)

Example 18 with AbstractOrderedLayout

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);
    }
}
Also used : VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) ComponentContainer(com.vaadin.ui.ComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) FormLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDFormLayout.FormLayoutTargetDetails) Component(com.vaadin.ui.Component) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout)

Example 19 with AbstractOrderedLayout

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);
    }
}
Also used : VerticalLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.v7.DDVerticalLayout.VerticalLayoutTargetDetails) VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) Component(com.vaadin.ui.Component) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout)

Example 20 with AbstractOrderedLayout

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);
    }
}
Also used : VerticalLayoutTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.v7.DDVerticalLayout.VerticalLayoutTargetDetails) VerticalDropLocation(com.vaadin.shared.ui.dd.VerticalDropLocation) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) ComponentContainer(com.vaadin.ui.ComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) SingleComponentContainer(com.vaadin.ui.SingleComponentContainer) Component(com.vaadin.ui.Component) AbstractOrderedLayout(com.vaadin.ui.AbstractOrderedLayout)

Aggregations

AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)34 List (java.util.List)9 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)8 HorizontalLayout (com.vaadin.ui.HorizontalLayout)8 Label (com.vaadin.ui.Label)7 Collectors (java.util.stream.Collectors)7 Component (com.vaadin.ui.Component)6 ComponentContainer (com.vaadin.ui.ComponentContainer)6 VerticalLayout (com.vaadin.ui.VerticalLayout)6 Map (java.util.Map)6 Entry (java.util.Map.Entry)6 DCharts (org.dussan.vaadin.dcharts.DCharts)6 XYseries (org.dussan.vaadin.dcharts.base.elements.XYseries)6 DataSeries (org.dussan.vaadin.dcharts.data.DataSeries)6 Series (org.dussan.vaadin.dcharts.options.Series)6 Service (org.springframework.stereotype.Service)6 DataContainer (com.hack23.cia.service.api.DataContainer)5 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)5 SimpleDateFormat (java.text.SimpleDateFormat)4 Locale (java.util.Locale)4