Example usage for com.vaadin.server Page getCurrent

List of usage examples for com.vaadin.server Page getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server Page getCurrent.

Prototype

public static Page getCurrent() 

Source Link

Document

Gets the Page to which the current uI belongs.

Usage

From source file:de.symeda.sormas.ui.login.LoginHelper.java

License:Open Source License

public static boolean logout() {
    try {/*from   w  w  w  . j a  v a2s.  co  m*/
        VaadinServletService.getCurrentServletRequest().logout();
    } catch (ServletException e) {
        return false;
    }

    VaadinSession.getCurrent().getSession().invalidate();
    Page.getCurrent().reload();

    return true;
}

From source file:de.symeda.sormas.ui.person.PersonController.java

License:Open Source License

private void savePerson(PersonDto personDto) {

    PersonDto existingPerson = FacadeProvider.getPersonFacade().getPersonByUuid(personDto.getUuid());
    List<CaseDataDto> personCases = FacadeProvider.getCaseFacade().getAllCasesOfPerson(personDto.getUuid(),
            UserProvider.getCurrent().getUserReference().getUuid());

    onPersonChanged(existingPerson, personDto);

    personFacade.savePerson(personDto);/*from  w  ww  .j  av  a 2 s.  c  o  m*/

    // Check whether the classification of any of this person's cases has changed
    CaseClassification newClassification = null;
    for (CaseDataDto personCase : personCases) {
        CaseDataDto updatedPersonCase = FacadeProvider.getCaseFacade().getCaseDataByUuid(personCase.getUuid());
        if (personCase.getCaseClassification() != updatedPersonCase.getCaseClassification()
                && updatedPersonCase.getClassificationUser() == null) {
            newClassification = updatedPersonCase.getCaseClassification();
            break;
        }
    }

    if (newClassification != null) {
        Notification notification = new Notification(
                String.format(I18nProperties.getString(Strings.messagePersonSavedClassificationChanged),
                        newClassification.toString()),
                Type.WARNING_MESSAGE);
        notification.setDelayMsec(-1);
        notification.show(Page.getCurrent());
    } else {
        Notification.show(I18nProperties.getString(Strings.messagePersonSaved), Type.WARNING_MESSAGE);
    }

    SormasUI.refreshView();
}

From source file:de.symeda.sormas.ui.person.PersonGrid.java

License:Open Source License

private void buildGrid() {
    setSizeFull();//from   ww  w  . ja v a2s.c o  m
    setSelectionMode(SelectionMode.SINGLE);
    setHeightMode(HeightMode.ROW);

    BeanItemContainer<PersonIndexDto> container = new BeanItemContainer<PersonIndexDto>(PersonIndexDto.class);
    GeneratedPropertyContainer generatedContainer = new GeneratedPropertyContainer(container);
    setContainerDataSource(generatedContainer);

    generatedContainer.addGeneratedProperty(CASE_LOC, new PropertyValueGenerator<String>() {
        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            PersonIndexDto person = (PersonIndexDto) itemId;
            if (person.getCaseDisease() != null) {
                return "<a href='" + Page.getCurrent().getLocation() + "/data/" + person.getCaseUuid()
                        + "' target='_blank'>" + person.getCaseDisease().toShortString() + " ("
                        + DateHelper.formatLocalShortDate(person.getCaseDiseaseStartDate()) + ")</a>";
            } else {
                return "";
            }
        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });

    setColumns(PersonIndexDto.FIRST_NAME, PersonIndexDto.LAST_NAME, PersonIndexDto.NICKNAME,
            PersonIndexDto.APPROXIMATE_AGE, PersonIndexDto.SEX, PersonIndexDto.PRESENT_CONDITION,
            PersonIndexDto.DISTRICT_NAME, PersonIndexDto.COMMUNITY_NAME, PersonIndexDto.CITY, CASE_LOC);

    for (Column column : getColumns()) {
        column.setHeaderCaption(I18nProperties.getPrefixCaption(PersonIndexDto.I18N_PREFIX,
                column.getPropertyId().toString(), column.getHeaderCaption()));
    }

    getColumn(PersonIndexDto.FIRST_NAME).setMinimumWidth(150);
    getColumn(PersonIndexDto.LAST_NAME).setMinimumWidth(150);
    getColumn(CASE_LOC).setRenderer(new HtmlRenderer());
    getColumn(CASE_LOC).setHeaderCaption(I18nProperties.getPrefixCaption(PersonIndexDto.I18N_PREFIX,
            associatedCase == null ? PersonIndexDto.LAST_DISEASE : PersonIndexDto.MATCHING_CASE));
}

From source file:de.symeda.sormas.ui.samples.PathogenTestController.java

License:Open Source License

private void showSaveNotification(CaseDataDto existingCaseDto, CaseDataDto newCaseDto) {
    if (existingCaseDto.getCaseClassification() != newCaseDto.getCaseClassification()
            && newCaseDto.getClassificationUser() == null) {
        Notification notification = new Notification(
                String.format(I18nProperties.getString(Strings.messagePathogenTestSaved),
                        newCaseDto.getCaseClassification().toString()),
                Type.WARNING_MESSAGE);
        notification.setDelayMsec(-1);/* w ww .  j a v a 2 s. c  om*/
        notification.show(Page.getCurrent());
    } else {
        Notification.show(I18nProperties.getString(Strings.messagePathogenTestSavedShort),
                Type.TRAY_NOTIFICATION);
    }
}

From source file:de.symeda.sormas.ui.samples.PathogenTestController.java

License:Open Source License

public void deleteAllSelectedItems(Collection<Object> selectedRows, Runnable callback) {
    if (selectedRows.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoPathogenTestsSelected),
                I18nProperties.getString(Strings.messageNoPathogenTestsSelected), Type.WARNING_MESSAGE, false)
                        .show(Page.getCurrent());
    } else {//  w w  w . j  a  v  a  2s. co  m
        VaadinUiUtil.showDeleteConfirmationWindow(String
                .format(I18nProperties.getString(Strings.confirmationDeletePathogenTests), selectedRows.size()),
                new Runnable() {
                    public void run() {
                        for (Object selectedRow : selectedRows) {
                            FacadeProvider.getPathogenTestFacade().deletePathogenTest(
                                    new PathogenTestReferenceDto(((PathogenTestDto) selectedRow).getUuid()),
                                    UserProvider.getCurrent().getUuid());
                        }
                        callback.run();
                        new Notification(I18nProperties.getString(Strings.headingPathogenTestsDeleted),
                                I18nProperties.getString(Strings.messagePathogenTestsDeleted),
                                Type.HUMANIZED_MESSAGE, false).show(Page.getCurrent());
                    }
                });
    }
}

From source file:de.symeda.sormas.ui.samples.SampleController.java

License:Open Source License

public void deleteAllSelectedItems(Collection<SampleIndexDto> selectedRows, Runnable callback) {
    if (selectedRows.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoSamplesSelected),
                I18nProperties.getString(Strings.messageNoSamplesSelected), Type.WARNING_MESSAGE, false)
                        .show(Page.getCurrent());
    } else {//from  www. j  av  a 2 s .  c o  m
        VaadinUiUtil.showDeleteConfirmationWindow(
                String.format(I18nProperties.getString(Strings.confirmationDeleteSamples), selectedRows.size()),
                new Runnable() {
                    public void run() {
                        for (Object selectedRow : selectedRows) {
                            FacadeProvider.getSampleFacade().deleteSample(
                                    new SampleReferenceDto(((SampleIndexDto) selectedRow).getUuid()),
                                    UserProvider.getCurrent().getUuid());
                        }
                        callback.run();
                        new Notification(I18nProperties.getString(Strings.headingSamplesDeleted),
                                I18nProperties.getString(Strings.messageSamplesDeleted), Type.HUMANIZED_MESSAGE,
                                false).show(Page.getCurrent());
                    }
                });
    }
}

From source file:de.symeda.sormas.ui.SormasErrorHandler.java

License:Open Source License

public static void handleError(ErrorEvent event) {
    final Throwable t = event.getThrowable();
    if (t instanceof SocketException) {
        // Most likely client browser closed socket
        logger.info(/*from   w  ww  .  jav a2s.  co  m*/
                "SocketException in CommunicationManager." + " Most likely client (browser) closed socket.");
        return;
    }

    ErrorMessage errorMessage = getErrorMessageForException(t);

    if (t != null) {
        // log the error or warning
        if (errorMessage instanceof SystemError) {
            logger.error(t.getMessage(), t);
        } else {
            logger.warn(t.getMessage(), t);
        }
    }

    // finds the original source of the error/exception
    AbstractComponent component = DefaultErrorHandler.findAbstractComponent(event);
    if (errorMessage != null && component != null) {
        // Shows the error in AbstractComponent
        if (errorMessage instanceof SystemError) {
            Notification.show(
                    I18nProperties.getString(Strings.errorOccurred,
                            I18nProperties.getString(Strings.errorOccurred)),
                    I18nProperties.getString(Strings.errorWasReported), Notification.Type.ERROR_MESSAGE);
        } else {

            // to prevent the original message from appearing, if necessary
            if (component instanceof AbstractField<?>) {
                ((AbstractField<?>) component).setCurrentBufferedSourceException(null);
            }

            Notification notification = new Notification(
                    I18nProperties.getString(Strings.errorProblemOccurred,
                            I18nProperties.getString(Strings.errorProblemOccurred)),
                    errorMessage.getFormattedHtmlMessage(), Notification.Type.WARNING_MESSAGE, true);
            notification.setDelayMsec(-1);
            notification.show(Page.getCurrent());
            component.setComponentError(errorMessage);
        }
    }
}

From source file:de.symeda.sormas.ui.statistics.DatabaseExportView.java

License:Open Source License

public void showExportErrorNotification() {
    new Notification(I18nProperties.getString(Strings.headingDatabaseExportFailed),
            I18nProperties.getString(Strings.messageDatabaseExportFailed), Type.ERROR_MESSAGE, false)
                    .show(Page.getCurrent());
}

From source file:de.symeda.sormas.ui.statistics.StatisticsView.java

License:Open Source License

private void addGenerateButton(VerticalLayout statisticsLayout) {
    Button generateButton = new Button(I18nProperties.getCaption(Captions.actionGenerate));
    CssStyles.style(generateButton, ValoTheme.BUTTON_PRIMARY);
    generateButton.addClickListener(e -> {
        // Check whether there is any invalid empty filter or grouping data
        Notification errorNotification = null;
        for (StatisticsFilterComponent filterComponent : filterComponents) {
            if (filterComponent.getSelectedAttribute() != StatisticsCaseAttribute.REGION_DISTRICT
                    && (filterComponent.getSelectedAttribute() == null
                            || filterComponent.getSelectedAttribute().getSubAttributes().length > 0
                                    && filterComponent.getSelectedSubAttribute() == null)) {
                errorNotification = new Notification(
                        I18nProperties.getString(Strings.messageSpecifyFilterAttributes), Type.WARNING_MESSAGE);
                break;
            }//w w  w.j a v  a2  s  . com
        }

        if (errorNotification == null && visualizationComponent.getRowsAttribute() != null
                && visualizationComponent.getRowsAttribute().getSubAttributes().length > 0
                && visualizationComponent.getRowsSubAttribute() == null) {
            errorNotification = new Notification(I18nProperties.getString(Strings.messageSpecifyRowAttribute),
                    Type.WARNING_MESSAGE);
        } else if (errorNotification == null && visualizationComponent.getColumnsAttribute() != null
                && visualizationComponent.getColumnsAttribute().getSubAttributes().length > 0
                && visualizationComponent.getColumnsSubAttribute() == null) {
            errorNotification = new Notification(
                    I18nProperties.getString(Strings.messageSpecifyColumnAttribute), Type.WARNING_MESSAGE);
        }

        if (errorNotification != null) {
            errorNotification.setDelayMsec(-1);
            errorNotification.show(Page.getCurrent());
        } else {
            resultsLayout.removeAllComponents();
            switch (visualizationComponent.getVisualizationType()) {
            case TABLE:
                generateTable();
                break;
            case MAP:
                generateMap();
                break;
            default:
                generateChart();
                break;
            }
        }
    });

    statisticsLayout.addComponent(generateButton);
}

From source file:de.symeda.sormas.ui.task.TaskController.java

License:Open Source License

public void deleteAllSelectedItems(Collection<TaskIndexDto> selectedRows, Runnable callback) {
    if (selectedRows.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoTasksSelected),
                I18nProperties.getString(Strings.messageNoTasksSelected), Type.WARNING_MESSAGE, false)
                        .show(Page.getCurrent());
    } else {/*from w  ww  . j a  v  a  2s  .c o  m*/
        VaadinUiUtil.showDeleteConfirmationWindow(
                String.format(I18nProperties.getString(Strings.confirmationDeleteTasks), selectedRows.size()),
                new Runnable() {
                    public void run() {
                        for (TaskIndexDto selectedRow : selectedRows) {
                            FacadeProvider.getTaskFacade().deleteTask(
                                    FacadeProvider.getTaskFacade().getByUuid(selectedRow.getUuid()),
                                    UserProvider.getCurrent().getUuid());
                        }
                        callback.run();
                        new Notification(I18nProperties.getString(Strings.headingTasksDeleted),
                                I18nProperties.getString(Strings.messageTasksDeleted), Type.HUMANIZED_MESSAGE,
                                false).show(Page.getCurrent());
                    }
                });
    }
}