Search in sources :

Example 1 with DeleteListener

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.DeleteListener in project SORMAS-Project by hzi-braunschweig.

the class PreviousHospitalizationsField method editEntry.

@Override
protected void editEntry(PreviousHospitalizationDto entry, boolean create, Consumer<PreviousHospitalizationDto> commitCallback) {
    if (create && entry.getUuid() == null) {
        entry.setUuid(DataHelper.createUuid());
    }
    PreviousHospitalizationEditForm editForm = new PreviousHospitalizationEditForm(create, fieldVisibilityCheckers, fieldAccessCheckers);
    editForm.setValue(entry);
    final CommitDiscardWrapperComponent<PreviousHospitalizationEditForm> editView = new CommitDiscardWrapperComponent<PreviousHospitalizationEditForm>(editForm, UserProvider.getCurrent().hasUserRight(UserRight.CASE_EDIT), editForm.getFieldGroup());
    editView.getCommitButton().setCaption(I18nProperties.getString(Strings.done));
    Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView, I18nProperties.getCaption(PreviousHospitalizationDto.I18N_PREFIX));
    editView.addCommitListener(new CommitListener() {

        @Override
        public void onCommit() {
            if (!editForm.getFieldGroup().isModified()) {
                commitCallback.accept(editForm.getValue());
            }
        }
    });
    if (!isEmpty(entry)) {
        editView.addDeleteListener(new DeleteListener() {

            @Override
            public void onDelete() {
                popupWindow.close();
                PreviousHospitalizationsField.this.removeEntry(entry);
            }
        }, I18nProperties.getCaption(PreviousHospitalizationDto.I18N_PREFIX));
    }
}
Also used : Window(com.vaadin.ui.Window) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) DeleteListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.DeleteListener) CommitListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)

Example 2 with DeleteListener

use of de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.DeleteListener in project SORMAS-Project by hzi-braunschweig.

the class TherapyController method openPrescriptionEditForm.

public void openPrescriptionEditForm(PrescriptionReferenceDto prescriptionReference, Runnable callback, boolean readOnly) {
    PrescriptionDto prescription = FacadeProvider.getPrescriptionFacade().getPrescriptionByUuid(prescriptionReference.getUuid());
    PrescriptionForm form = new PrescriptionForm(false, readOnly, prescription.isPseudonymized());
    form.setValue(prescription);
    final CommitDiscardWrapperComponent<PrescriptionForm> view = new CommitDiscardWrapperComponent<>(form, UserProvider.getCurrent().hasUserRight(UserRight.PRESCRIPTION_EDIT), form.getFieldGroup());
    Window popupWindow = VaadinUiUtil.showModalPopupWindow(view, I18nProperties.getString(readOnly ? Strings.entityPrescription : Strings.headingEditPrescription));
    view.addCommitListener(new CommitListener() {

        @Override
        public void onCommit() {
            if (!form.getFieldGroup().isModified()) {
                PrescriptionDto dto = form.getValue();
                FacadeProvider.getPrescriptionFacade().savePrescription(dto);
                popupWindow.close();
                Notification.show(I18nProperties.getString(Strings.messagePrescriptionSaved), Type.TRAY_NOTIFICATION);
                if (callback != null) {
                    callback.run();
                }
            }
        }
    });
    view.addDiscardListener(() -> popupWindow.close());
    if (UserProvider.getCurrent().hasUserRight(UserRight.PRESCRIPTION_DELETE)) {
        view.addDeleteListener(new DeleteListener() {

            @Override
            public void onDelete() {
                FacadeProvider.getPrescriptionFacade().deletePrescription(prescription.getUuid());
                popupWindow.close();
                if (callback != null) {
                    callback.run();
                }
            }
        }, I18nProperties.getString(Strings.entityPrescription));
    }
}
Also used : Window(com.vaadin.ui.Window) PrescriptionDto(de.symeda.sormas.api.therapy.PrescriptionDto) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent) DeleteListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.DeleteListener) CommitListener(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)

Aggregations

Window (com.vaadin.ui.Window)2 CommitDiscardWrapperComponent (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)2 CommitListener (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.CommitListener)2 DeleteListener (de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent.DeleteListener)2 PrescriptionDto (de.symeda.sormas.api.therapy.PrescriptionDto)1