Search in sources :

Example 11 with ValueChangeListener

use of com.vaadin.v7.data.Property.ValueChangeListener in project opencms-core by alkacon.

the class CmsSourceEditor method initUI.

/**
 * @see org.opencms.ui.editors.I_CmsEditor#initUI(org.opencms.ui.apps.I_CmsAppUIContext, org.opencms.file.CmsResource, java.lang.String, java.util.Map)
 */
public void initUI(I_CmsAppUIContext context, CmsResource resource, String backLink, Map<String, String> params) {
    CmsMessages messages = Messages.get().getBundle(UI.getCurrent().getLocale());
    context.showInfoArea(false);
    context.setAppTitle(messages.key(Messages.GUI_SOURCE_EDITOR_TITLE_0));
    CmsAppWorkplaceUi.setWindowTitle(CmsVaadinUtils.getMessageText(org.opencms.ui.apps.Messages.GUI_CONTENT_EDITOR_TITLE_2, resource.getName(), CmsResource.getParentFolder(A_CmsUI.getCmsObject().getSitePath(resource))));
    m_backLink = backLink;
    m_codeMirror = new CmsCodeMirror();
    m_codeMirror.setSizeFull();
    context.setAppContent(m_codeMirror);
    context.enableDefaultToolbarButtons(false);
    m_saveAndExit = CmsToolBar.createButton(FontOpenCms.SAVE_EXIT, messages.key(Messages.GUI_BUTTON_SAVE_AND_EXIT_0), true);
    m_saveAndExit.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            saveAndExit();
        }
    });
    m_saveAndExit.setEnabled(false);
    context.addToolbarButton(m_saveAndExit);
    m_save = CmsToolBar.createButton(FontOpenCms.SAVE, messages.key(Messages.GUI_BUTTON_SAVE_0), true);
    m_save.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            save();
        }
    });
    m_save.setEnabled(false);
    context.addToolbarButton(m_save);
    Button undo = CmsToolBar.createButton(FontOpenCms.UNDO, messages.key(Messages.GUI_BUTTON_UNDO_0), true);
    context.addToolbarButton(undo);
    Button redo = CmsToolBar.createButton(FontOpenCms.REDO, messages.key(Messages.GUI_BUTTON_REDO_0), true);
    context.addToolbarButton(redo);
    m_codeMirror.registerUndoRedo(undo, redo);
    Button search = CmsToolBar.createButton(FontOpenCms.SEARCH, messages.key(Messages.GUI_BUTTON_SEARCH_0), true);
    context.addToolbarButton(search);
    Button replace = CmsToolBar.createButton(FontOpenCms.SEARCH_REPLACE, messages.key(Messages.GUI_BUTTON_REPLACE_0), true);
    context.addToolbarButton(replace);
    m_codeMirror.registerSearchReplace(search, replace);
    EditorSettings settings;
    try {
        settings = OpenCms.getWorkplaceAppManager().getAppSettings(A_CmsUI.getCmsObject(), EditorSettings.class);
    } catch (Exception e) {
        settings = new EditorSettings();
    }
    final Button toggleHighlight = CmsToolBar.createButton(FontOpenCms.HIGHLIGHT, messages.key(Messages.GUI_BUTTON_TOGGLE_HIGHLIGHTING_0));
    toggleHighlight.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setHighlighting(!pressed);
        }
    });
    if (settings.m_highlighting) {
        m_codeMirror.setHighlighting(true);
        toggleHighlight.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setHighlighting(false);
    }
    context.addToolbarButtonRight(toggleHighlight);
    final Button toggleLineWrap = CmsToolBar.createButton(FontOpenCms.WRAP_LINES, messages.key(Messages.GUI_BUTTON_TOGGLE_LINE_WRAPPING_0));
    toggleLineWrap.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setLineWrapping(!pressed);
        }
    });
    if (settings.m_lineWrapping) {
        m_codeMirror.setLineWrapping(true);
        toggleLineWrap.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setLineWrapping(false);
    }
    context.addToolbarButtonRight(toggleLineWrap);
    final Button toggleBrackets = CmsToolBar.createButton(FontOpenCms.BRACKETS, messages.key(Messages.GUI_BUTTON_TOBBLE_BRACKET_AUTOCLOSE_0));
    toggleBrackets.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setCloseBrackets(!pressed);
        }
    });
    if (settings.m_closeBrackets) {
        m_codeMirror.setCloseBrackets(true);
        toggleBrackets.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setCloseBrackets(false);
    }
    context.addToolbarButtonRight(toggleBrackets);
    final Button toggleTabs = CmsToolBar.createButton(FontOpenCms.INVISIBLE_CHARS, messages.key(Messages.GUI_BUTTON_TOGGLE_TAB_VISIBILITY_0));
    toggleTabs.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            Button b = event.getButton();
            boolean pressed = b.getStyleName().contains(OpenCmsTheme.BUTTON_PRESSED);
            if (pressed) {
                b.removeStyleName(OpenCmsTheme.BUTTON_PRESSED);
            } else {
                b.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
            }
            m_codeMirror.setTabsVisible(!pressed);
        }
    });
    if (settings.m_tabsVisible) {
        m_codeMirror.setTabsVisible(true);
        toggleTabs.addStyleName(OpenCmsTheme.BUTTON_PRESSED);
    } else {
        m_codeMirror.setTabsVisible(false);
    }
    context.addToolbarButtonRight(toggleTabs);
    ComboBox modeSelect = new ComboBox();
    modeSelect.setWidth("115px");
    modeSelect.addStyleName(OpenCmsTheme.TOOLBAR_FIELD);
    modeSelect.addStyleName(OpenCmsTheme.REQUIRED_BUTTON);
    modeSelect.setNullSelectionAllowed(false);
    modeSelect.setImmediate(true);
    modeSelect.setNewItemsAllowed(false);
    for (CodeMirrorLanguage lang : CodeMirrorLanguage.values()) {
        modeSelect.addItem(lang);
        modeSelect.setItemCaption(lang, lang.name());
    }
    CodeMirrorLanguage lang = getHighlightMode(resource);
    modeSelect.setValue(lang);
    m_codeMirror.setLanguage(lang);
    modeSelect.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            m_codeMirror.setLanguage((CodeMirrorLanguage) event.getProperty().getValue());
        }
    });
    context.addToolbarButtonRight(modeSelect);
    ComboBox fontSizeSelect = new ComboBox();
    fontSizeSelect.setWidth("75px");
    fontSizeSelect.addStyleName(OpenCmsTheme.TOOLBAR_FIELD);
    fontSizeSelect.addStyleName(OpenCmsTheme.REQUIRED_BUTTON);
    fontSizeSelect.setNullSelectionAllowed(false);
    fontSizeSelect.setImmediate(true);
    fontSizeSelect.setNewItemsAllowed(false);
    for (int i = 0; i < FONT_SIZES.length; i++) {
        fontSizeSelect.addItem(FONT_SIZES[i]);
    }
    fontSizeSelect.setValue(settings.m_fontSize);
    fontSizeSelect.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            m_codeMirror.setFontSize((String) event.getProperty().getValue());
        }
    });
    context.addToolbarButtonRight(fontSizeSelect);
    m_codeMirror.setFontSize(settings.m_fontSize);
    m_exit = CmsToolBar.createButton(FontOpenCms.EXIT, messages.key(Messages.GUI_BUTTON_CANCEL_0), true);
    m_exit.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {
            exit();
        }
    });
    context.addToolbarButtonRight(m_exit);
    try {
        m_file = LockedFile.lockResource(A_CmsUI.getCmsObject(), resource);
        String content = new String(m_file.getFile().getContents(), m_file.getEncoding());
        m_codeMirror.setValue(content);
    } catch (Exception e) {
        CmsErrorDialog.showErrorDialog(e);
    }
    m_codeMirror.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            onChange((String) event.getProperty().getValue());
        }
    });
}
Also used : CodeMirrorLanguage(org.opencms.ui.components.codemirror.CmsCodeMirror.CodeMirrorLanguage) ComboBox(com.vaadin.v7.ui.ComboBox) ClickEvent(com.vaadin.ui.Button.ClickEvent) CmsCodeMirror(org.opencms.ui.components.codemirror.CmsCodeMirror) JSONException(org.opencms.json.JSONException) ValueChangeEvent(com.vaadin.v7.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener) Button(com.vaadin.ui.Button) CmsMessages(org.opencms.i18n.CmsMessages) ClickListener(com.vaadin.ui.Button.ClickListener)

Example 12 with ValueChangeListener

use of com.vaadin.v7.data.Property.ValueChangeListener in project SORMAS-Project by hzi-braunschweig.

the class CaseCreateForm method addFields.

@Override
protected void addFields() {
    NullableOptionGroup ogCaseOrigin = addField(CaseDataDto.CASE_ORIGIN, NullableOptionGroup.class);
    ogCaseOrigin.setRequired(true);
    TextField epidField = addField(CaseDataDto.EPID_NUMBER, TextField.class);
    epidField.setInvalidCommitted(true);
    style(epidField, ERROR_COLOR_PRIMARY);
    if (!FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled()) {
        TextField externalIdField = addField(CaseDataDto.EXTERNAL_ID, TextField.class);
        style(externalIdField, ERROR_COLOR_PRIMARY);
    } else {
        CheckBox dontShareCheckbox = addField(CaseDataDto.DONT_SHARE_WITH_REPORTING_TOOL, CheckBox.class);
        CaseFormHelper.addDontShareWithReportingTool(getContent(), () -> dontShareCheckbox, DONT_SHARE_WARNING_LOC);
    }
    addField(CaseDataDto.REPORT_DATE, DateField.class);
    ComboBox diseaseField = addDiseaseField(CaseDataDto.DISEASE, false, true);
    diseaseVariantField = addField(CaseDataDto.DISEASE_VARIANT, ComboBox.class);
    diseaseVariantDetailsField = addField(CaseDataDto.DISEASE_VARIANT_DETAILS, TextField.class);
    diseaseVariantDetailsField.setVisible(false);
    diseaseVariantField.setNullSelectionAllowed(true);
    diseaseVariantField.setVisible(false);
    addField(CaseDataDto.DISEASE_DETAILS, TextField.class);
    NullableOptionGroup plagueType = addField(CaseDataDto.PLAGUE_TYPE, NullableOptionGroup.class);
    addField(CaseDataDto.DENGUE_FEVER_TYPE, NullableOptionGroup.class);
    addField(CaseDataDto.RABIES_TYPE, NullableOptionGroup.class);
    personCreateForm = new PersonCreateForm(showHomeAddressForm, true, true, showPersonSearchButton);
    personCreateForm.setWidth(100, Unit.PERCENTAGE);
    getContent().addComponent(personCreateForm, CaseDataDto.PERSON);
    differentPlaceOfStayJurisdiction = addCustomField(DIFFERENT_PLACE_OF_STAY_JURISDICTION, Boolean.class, CheckBox.class);
    differentPlaceOfStayJurisdiction.addStyleName(VSPACE_3);
    Label placeOfStayHeadingLabel = new Label(I18nProperties.getCaption(Captions.casePlaceOfStay));
    placeOfStayHeadingLabel.addStyleName(H3);
    getContent().addComponent(placeOfStayHeadingLabel, PLACE_OF_STAY_HEADING_LOC);
    ComboBox region = addInfrastructureField(CaseDataDto.REGION);
    districtCombo = addInfrastructureField(CaseDataDto.DISTRICT);
    communityCombo = addInfrastructureField(CaseDataDto.COMMUNITY);
    communityCombo.setNullSelectionAllowed(true);
    // jurisdictionfields
    Label jurisdictionHeadingLabel = new Label(I18nProperties.getString(Strings.headingCaseResponsibleJurisidction));
    jurisdictionHeadingLabel.addStyleName(H3);
    getContent().addComponent(jurisdictionHeadingLabel, RESPONSIBLE_JURISDICTION_HEADING_LOC);
    ComboBox responsibleRegion = addInfrastructureField(CaseDataDto.RESPONSIBLE_REGION);
    responsibleRegion.setRequired(true);
    responsibleDistrictCombo = addInfrastructureField(CaseDataDto.RESPONSIBLE_DISTRICT);
    responsibleDistrictCombo.setRequired(true);
    responsibleCommunityCombo = addInfrastructureField(CaseDataDto.RESPONSIBLE_COMMUNITY);
    responsibleCommunityCombo.setNullSelectionAllowed(true);
    responsibleCommunityCombo.addStyleName(SOFT_REQUIRED);
    InfrastructureFieldsHelper.initInfrastructureFields(responsibleRegion, responsibleDistrictCombo, responsibleCommunityCombo);
    differentPointOfEntryJurisdiction = addCustomField(DIFFERENT_POINT_OF_ENTRY_JURISDICTION, Boolean.class, CheckBox.class);
    differentPointOfEntryJurisdiction.addStyleName(VSPACE_3);
    ComboBox pointOfEntryRegionCombo = addCustomField(POINT_OF_ENTRY_REGION, RegionReferenceDto.class, ComboBox.class);
    pointOfEntryDistrictCombo = addCustomField(POINT_OF_ENTRY_DISTRICT, DistrictReferenceDto.class, ComboBox.class);
    InfrastructureFieldsHelper.initInfrastructureFields(pointOfEntryRegionCombo, pointOfEntryDistrictCombo, null);
    pointOfEntryDistrictCombo.addValueChangeListener(e -> updatePOEs());
    FieldHelper.setVisibleWhen(differentPlaceOfStayJurisdiction, Arrays.asList(region, districtCombo, communityCombo), Collections.singletonList(Boolean.TRUE), true);
    FieldHelper.setVisibleWhen(differentPointOfEntryJurisdiction, Arrays.asList(pointOfEntryRegionCombo, pointOfEntryDistrictCombo), Collections.singletonList(Boolean.TRUE), true);
    FieldHelper.setRequiredWhen(differentPlaceOfStayJurisdiction, Arrays.asList(region, districtCombo), Collections.singletonList(Boolean.TRUE), false, null);
    ogCaseOrigin.addValueChangeListener(e -> {
        boolean pointOfEntryRegionDistrictVisible = CaseOrigin.POINT_OF_ENTRY.equals(ogCaseOrigin.getValue()) && Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue());
        pointOfEntryRegionCombo.setVisible(pointOfEntryRegionDistrictVisible);
        pointOfEntryDistrictCombo.setVisible(pointOfEntryRegionDistrictVisible);
    });
    facilityOrHome = addCustomField(FACILITY_OR_HOME_LOC, TypeOfPlace.class, NullableOptionGroup.class, I18nProperties.getCaption(Captions.casePlaceOfStay));
    facilityOrHome.removeAllItems();
    for (TypeOfPlace place : TypeOfPlace.FOR_CASES) {
        facilityOrHome.addItem(place);
        facilityOrHome.setItemCaption(place, I18nProperties.getEnumCaption(place));
    }
    facilityOrHome.setItemCaptionMode(ItemCaptionMode.EXPLICIT);
    facilityOrHome.setId("facilityOrHome");
    facilityOrHome.setWidth(100, Unit.PERCENTAGE);
    CssStyles.style(facilityOrHome, ValoTheme.OPTIONGROUP_HORIZONTAL);
    facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
    facilityTypeGroup.setId("typeGroup");
    facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
    facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
    facilityTypeGroup.addItems(FacilityTypeGroup.getAccomodationGroups());
    getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
    facilityType = ComboBoxHelper.createComboBoxV7();
    facilityType.setId("type");
    facilityType.setCaption(I18nProperties.getCaption(Captions.facilityType));
    facilityType.setWidth(100, Unit.PERCENTAGE);
    getContent().addComponent(facilityType, CaseDataDto.FACILITY_TYPE);
    facilityCombo = addInfrastructureField(CaseDataDto.HEALTH_FACILITY);
    facilityCombo.setImmediate(true);
    TextField facilityDetails = addField(CaseDataDto.HEALTH_FACILITY_DETAILS, TextField.class);
    facilityDetails.setVisible(false);
    ComboBox cbPointOfEntry = addInfrastructureField(CaseDataDto.POINT_OF_ENTRY);
    cbPointOfEntry.setImmediate(true);
    TextField tfPointOfEntryDetails = addField(CaseDataDto.POINT_OF_ENTRY_DETAILS, TextField.class);
    tfPointOfEntryDetails.setVisible(false);
    if (convertedTravelEntry != null) {
        differentPointOfEntryJurisdiction.setValue(true);
        RegionReferenceDto regionReferenceDto = convertedTravelEntry.getPointOfEntryRegion() != null ? convertedTravelEntry.getPointOfEntryRegion() : convertedTravelEntry.getResponsibleRegion();
        pointOfEntryRegionCombo.setValue(regionReferenceDto);
        DistrictReferenceDto districtReferenceDto = convertedTravelEntry.getPointOfEntryDistrict() != null ? convertedTravelEntry.getPointOfEntryDistrict() : convertedTravelEntry.getResponsibleDistrict();
        pointOfEntryDistrictCombo.setValue(districtReferenceDto);
        differentPointOfEntryJurisdiction.setReadOnly(true);
        pointOfEntryRegionCombo.setReadOnly(true);
        pointOfEntryDistrictCombo.setReadOnly(true);
        updatePOEs();
        cbPointOfEntry.setReadOnly(true);
        tfPointOfEntryDetails.setReadOnly(true);
        ogCaseOrigin.setReadOnly(true);
    }
    region.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(districtCombo, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
    });
    districtCombo.addValueChangeListener(e -> {
        FieldHelper.removeItems(communityCombo);
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(communityCombo, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
        updateFacility();
        if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
            updatePOEs();
        }
    });
    communityCombo.addValueChangeListener(e -> {
        updateFacility();
    });
    facilityOrHome.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        if (TypeOfPlace.FACILITY.equals(facilityOrHome.getValue()) || ((facilityOrHome.getValue() instanceof java.util.Set) && TypeOfPlace.FACILITY.equals(facilityOrHome.getNullableValue()))) {
            if (facilityTypeGroup.getValue() == null) {
                facilityTypeGroup.setValue(FacilityTypeGroup.MEDICAL_FACILITY);
            }
            if (facilityType.getValue() == null && FacilityTypeGroup.MEDICAL_FACILITY.equals(facilityTypeGroup.getValue())) {
                facilityType.setValue(FacilityType.HOSPITAL);
            }
            if (facilityType.getValue() != null) {
                updateFacility();
            }
            if (CaseOrigin.IN_COUNTRY.equals(ogCaseOrigin.getValue())) {
                facilityCombo.setRequired(true);
            }
            updateFacilityFields(facilityCombo, facilityDetails);
        } else if (TypeOfPlace.HOME.equals(facilityOrHome.getValue()) || ((facilityOrHome.getValue() instanceof java.util.Set) && TypeOfPlace.HOME.equals(facilityOrHome.getNullableValue()))) {
            setNoneFacility();
        } else {
            facilityCombo.removeAllItems();
            facilityCombo.setValue(null);
            updateFacilityFields(facilityCombo, facilityDetails);
        }
    });
    facilityTypeGroup.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        FieldHelper.updateEnumData(facilityType, FacilityType.getAccommodationTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
    });
    facilityType.addValueChangeListener(e -> updateFacility());
    region.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    JurisdictionLevel userJurisdictionLevel = UserRole.getJurisdictionLevel(UserProvider.getCurrent().getUserRoles());
    if (userJurisdictionLevel == JurisdictionLevel.HEALTH_FACILITY) {
        region.setReadOnly(true);
        responsibleRegion.setReadOnly(true);
        districtCombo.setReadOnly(true);
        responsibleDistrictCombo.setReadOnly(true);
        communityCombo.setReadOnly(true);
        responsibleCommunityCombo.setReadOnly(true);
        differentPlaceOfStayJurisdiction.setVisible(false);
        differentPlaceOfStayJurisdiction.setEnabled(false);
        facilityOrHome.setImmediate(true);
        // [FACILITY]
        facilityOrHome.setValue(Sets.newHashSet(TypeOfPlace.FACILITY));
        facilityOrHome.setReadOnly(true);
        facilityTypeGroup.setValue(FacilityTypeGroup.MEDICAL_FACILITY);
        facilityTypeGroup.setReadOnly(true);
        facilityType.setValue(FacilityType.HOSPITAL);
        facilityType.setReadOnly(true);
        facilityCombo.setValue(UserProvider.getCurrent().getUser().getHealthFacility());
        facilityCombo.setReadOnly(true);
    }
    if (!UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
        ogCaseOrigin.addValueChangeListener(ev -> {
            if (ev.getProperty().getValue() == CaseOrigin.IN_COUNTRY) {
                setVisible(false, CaseDataDto.POINT_OF_ENTRY, CaseDataDto.POINT_OF_ENTRY_DETAILS);
                differentPointOfEntryJurisdiction.setVisible(false);
                setRequired(true, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE, CaseDataDto.HEALTH_FACILITY);
                setRequired(false, CaseDataDto.POINT_OF_ENTRY);
                updateFacilityFields(facilityCombo, facilityDetails);
            } else {
                setVisible(true, CaseDataDto.POINT_OF_ENTRY);
                differentPointOfEntryJurisdiction.setVisible(true);
                setRequired(true, CaseDataDto.POINT_OF_ENTRY);
                if (userJurisdictionLevel != JurisdictionLevel.HEALTH_FACILITY) {
                    facilityOrHome.clear();
                    setRequired(false, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE, CaseDataDto.HEALTH_FACILITY);
                }
                updatePointOfEntryFields(cbPointOfEntry, tfPointOfEntryDetails);
            }
        });
    }
    // jurisdiction field valuechangelisteners
    responsibleDistrictCombo.addValueChangeListener(e -> {
        Boolean differentPlaceOfStay = differentPlaceOfStayJurisdiction.getValue();
        if (!Boolean.TRUE.equals(differentPlaceOfStay)) {
            updateFacility();
            if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
                updatePOEs();
            }
        }
    });
    responsibleCommunityCombo.addValueChangeListener((e) -> {
        Boolean differentPlaceOfStay = differentPlaceOfStayJurisdiction.getValue();
        if (differentPlaceOfStay == null || Boolean.FALSE.equals(differentPlaceOfStay)) {
            updateFacility();
        }
    });
    differentPlaceOfStayJurisdiction.addValueChangeListener(e -> {
        updateFacility();
        if (!Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
            updatePOEs();
        }
    });
    // Set initial visibilities & accesses
    initializeVisibilitiesAndAllowedVisibilities();
    setRequired(true, CaseDataDto.REPORT_DATE, CaseDataDto.DISEASE, FACILITY_OR_HOME_LOC, FACILITY_TYPE_GROUP_LOC, CaseDataDto.FACILITY_TYPE);
    FieldHelper.addSoftRequiredStyle(plagueType, communityCombo, facilityDetails);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.DISEASE_DETAILS), CaseDataDto.DISEASE, Arrays.asList(Disease.OTHER), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.DISEASE, Arrays.asList(CaseDataDto.DISEASE_DETAILS), Arrays.asList(Disease.OTHER));
    FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.CASE_ORIGIN, Arrays.asList(CaseDataDto.HEALTH_FACILITY), Arrays.asList(CaseOrigin.IN_COUNTRY));
    FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.CASE_ORIGIN, Arrays.asList(CaseDataDto.POINT_OF_ENTRY), Arrays.asList(CaseOrigin.POINT_OF_ENTRY));
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.PLAGUE_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.PLAGUE), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.DENGUE_FEVER_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.DENGUE), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.RABIES_TYPE), CaseDataDto.DISEASE, Arrays.asList(Disease.RABIES), true);
    FieldHelper.setVisibleWhen(facilityOrHome, Arrays.asList(facilityTypeGroup, facilityType, facilityCombo), Collections.singletonList(TypeOfPlace.FACILITY), false);
    FieldHelper.setRequiredWhen(facilityOrHome, Arrays.asList(facilityTypeGroup, facilityType, facilityCombo), Collections.singletonList(TypeOfPlace.FACILITY), false, null);
    facilityCombo.addValueChangeListener(e -> {
        updateFacilityFields(facilityCombo, facilityDetails);
        this.getValue().setFacilityType((FacilityType) facilityType.getValue());
    });
    cbPointOfEntry.addValueChangeListener(e -> {
        updatePointOfEntryFields(cbPointOfEntry, tfPointOfEntryDetails);
    });
    addValueChangeListener(e -> {
        if (UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
            setVisible(false, CaseDataDto.CASE_ORIGIN, CaseDataDto.DISEASE, CaseDataDto.COMMUNITY, CaseDataDto.HEALTH_FACILITY);
            setVisible(true, CaseDataDto.POINT_OF_ENTRY);
        }
    });
    diseaseField.addValueChangeListener((ValueChangeListener) valueChangeEvent -> {
        updateDiseaseVariant((Disease) valueChangeEvent.getProperty().getValue());
        personCreateForm.updatePresentConditionEnum((Disease) valueChangeEvent.getProperty().getValue());
    });
    diseaseVariantField.addValueChangeListener(e -> {
        DiseaseVariant diseaseVariant = (DiseaseVariant) e.getProperty().getValue();
        diseaseVariantDetailsField.setVisible(diseaseVariant != null && diseaseVariant.matchPropertyValue(DiseaseVariant.HAS_DETAILS, true));
    });
    if (diseaseField.getValue() != null) {
        Disease disease = (Disease) diseaseField.getValue();
        updateDiseaseVariant(disease);
        personCreateForm.updatePresentConditionEnum(disease);
    }
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) H3(de.symeda.sormas.ui.utils.CssStyles.H3) Arrays(java.util.Arrays) Date(java.util.Date) CheckBox(com.vaadin.v7.ui.CheckBox) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) LayoutUtil.locs(de.symeda.sormas.ui.utils.LayoutUtil.locs) PersonDto(de.symeda.sormas.api.person.PersonDto) CssStyles(de.symeda.sormas.ui.utils.CssStyles) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) UserRole(de.symeda.sormas.api.user.UserRole) UserProvider(de.symeda.sormas.ui.UserProvider) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) ComboBox(com.vaadin.v7.ui.ComboBox) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Sets(com.google.common.collect.Sets) TypeOfPlace(de.symeda.sormas.api.event.TypeOfPlace) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) List(java.util.List) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) FacadeProvider(de.symeda.sormas.api.FacadeProvider) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) Converter(com.vaadin.v7.data.util.converter.Converter) CustomizableEnumType(de.symeda.sormas.api.customizableenum.CustomizableEnumType) CollectionUtils(org.apache.commons.collections.CollectionUtils) Label(com.vaadin.ui.Label) ERROR_COLOR_PRIMARY(de.symeda.sormas.ui.utils.CssStyles.ERROR_COLOR_PRIMARY) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) CssStyles.style(de.symeda.sormas.ui.utils.CssStyles.style) PersonCreateForm(de.symeda.sormas.ui.person.PersonCreateForm) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) SOFT_REQUIRED(de.symeda.sormas.ui.utils.CssStyles.SOFT_REQUIRED) Captions(de.symeda.sormas.api.i18n.Captions) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ItemCaptionMode(com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) Disease(de.symeda.sormas.api.Disease) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) LayoutUtil.fluidColumn(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumn) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) Disease(de.symeda.sormas.api.Disease) DiseaseVariant(de.symeda.sormas.api.disease.DiseaseVariant) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) TypeOfPlace(de.symeda.sormas.api.event.TypeOfPlace) PersonCreateForm(de.symeda.sormas.ui.person.PersonCreateForm) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) CheckBox(com.vaadin.v7.ui.CheckBox) TextField(com.vaadin.v7.ui.TextField) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup)

Example 13 with ValueChangeListener

use of com.vaadin.v7.data.Property.ValueChangeListener in project SORMAS-Project by hzi-braunschweig.

the class LocationEditForm method addFields.

@SuppressWarnings("deprecation")
@Override
protected void addFields() {
    addressType = addField(LocationDto.ADDRESS_TYPE, ComboBox.class);
    addressType.setVisible(false);
    final PersonAddressType[] personAddressTypeValues = PersonAddressType.getValues(FacadeProvider.getConfigFacade().getCountryCode());
    if (!isConfiguredServer("ch")) {
        addressType.removeAllItems();
        addressType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
        addressType.addItems(personAddressTypeValues);
    }
    TextField addressTypeDetails = addField(LocationDto.ADDRESS_TYPE_DETAILS, TextField.class);
    addressTypeDetails.setVisible(false);
    FieldHelper.setVisibleWhen(getFieldGroup(), LocationDto.ADDRESS_TYPE_DETAILS, addressType, Arrays.stream(personAddressTypeValues).filter(pat -> !pat.equals(PersonAddressType.HOME)).collect(Collectors.toList()), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), addressType, Arrays.asList(LocationDto.ADDRESS_TYPE_DETAILS), Arrays.asList(PersonAddressType.OTHER_ADDRESS));
    facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
    ;
    facilityTypeGroup.setId("typeGroup");
    facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
    facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
    facilityTypeGroup.addItems(FacilityTypeGroup.values());
    getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
    facilityType = addField(LocationDto.FACILITY_TYPE);
    facility = addInfrastructureField(LocationDto.FACILITY);
    facility.setImmediate(true);
    facilityDetails = addField(LocationDto.FACILITY_DETAILS, TextField.class);
    facilityDetails.setVisible(false);
    addressType.addValueChangeListener(e -> {
        FacilityTypeGroup oldGroup = (FacilityTypeGroup) facilityTypeGroup.getValue();
        FacilityType oldType = (FacilityType) facilityType.getValue();
        FacilityReferenceDto oldFacility = (FacilityReferenceDto) facility.getValue();
        String oldDetails = facilityDetails.getValue();
        if (PersonAddressType.HOME.equals(addressType.getValue())) {
            facilityTypeGroup.removeAllItems();
            facilityTypeGroup.addItems(FacilityTypeGroup.getAccomodationGroups());
            setOldFacilityValuesIfPossible(oldGroup, oldType, oldFacility, oldDetails);
        } else {
            facilityTypeGroup.removeAllItems();
            facilityTypeGroup.addItems(FacilityTypeGroup.values());
            setOldFacilityValuesIfPossible(oldGroup, oldType, oldFacility, oldDetails);
        }
    });
    TextField streetField = addField(LocationDto.STREET, TextField.class);
    TextField houseNumberField = addField(LocationDto.HOUSE_NUMBER, TextField.class);
    TextField additionalInformationField = addField(LocationDto.ADDITIONAL_INFORMATION, TextField.class);
    addField(LocationDto.DETAILS, TextField.class);
    TextField cityField = addField(LocationDto.CITY, TextField.class);
    TextField postalCodeField = addField(LocationDto.POSTAL_CODE, TextField.class);
    ComboBox areaType = addField(LocationDto.AREA_TYPE, ComboBox.class);
    areaType.setDescription(I18nProperties.getDescription(getPropertyI18nPrefix() + "." + LocationDto.AREA_TYPE));
    contactPersonFirstName = addField(LocationDto.CONTACT_PERSON_FIRST_NAME, TextField.class);
    contactPersonLastName = addField(LocationDto.CONTACT_PERSON_LAST_NAME, TextField.class);
    contactPersonPhone = addField(LocationDto.CONTACT_PERSON_PHONE, TextField.class);
    contactPersonPhone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, contactPersonPhone.getCaption())));
    contactPersonEmail = addField(LocationDto.CONTACT_PERSON_EMAIL, TextField.class);
    contactPersonEmail.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, contactPersonEmail.getCaption())));
    final AccessibleTextField tfLatitude = addField(LocationDto.LATITUDE, AccessibleTextField.class);
    final AccessibleTextField tfLongitude = addField(LocationDto.LONGITUDE, AccessibleTextField.class);
    final AccessibleTextField tfAccuracy = addField(LocationDto.LAT_LON_ACCURACY, AccessibleTextField.class);
    final StringToAngularLocationConverter stringToAngularLocationConverter = new StringToAngularLocationConverter();
    tfLatitude.setConverter(stringToAngularLocationConverter);
    tfLongitude.setConverter(stringToAngularLocationConverter);
    tfAccuracy.setConverter(stringToAngularLocationConverter);
    continent = addInfrastructureField(LocationDto.CONTINENT);
    subcontinent = addInfrastructureField(LocationDto.SUB_CONTINENT);
    country = addInfrastructureField(LocationDto.COUNTRY);
    ComboBox region = addInfrastructureField(LocationDto.REGION);
    ComboBox district = addInfrastructureField(LocationDto.DISTRICT);
    ComboBox community = addInfrastructureField(LocationDto.COMMUNITY);
    continent.setVisible(false);
    subcontinent.setVisible(false);
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    if (!isEditableAllowed(LocationDto.COMMUNITY)) {
        setEnabled(false, LocationDto.COUNTRY, LocationDto.REGION, LocationDto.DISTRICT);
    }
    ValueChangeListener continentValueListener = e -> {
        if (continent.isVisible()) {
            ContinentReferenceDto continentReferenceDto = (ContinentReferenceDto) e.getProperty().getValue();
            if (subcontinent.getValue() == null) {
                FieldHelper.updateItems(country, continentReferenceDto != null ? FacadeProvider.getCountryFacade().getAllActiveByContinent(continentReferenceDto.getUuid()) : FacadeProvider.getCountryFacade().getAllActiveAsReference());
                country.setValue(null);
            }
            subcontinent.setValue(null);
            FieldHelper.updateItems(subcontinent, continentReferenceDto != null ? FacadeProvider.getSubcontinentFacade().getAllActiveByContinent(continentReferenceDto.getUuid()) : FacadeProvider.getSubcontinentFacade().getAllActiveAsReference());
        }
    };
    ValueChangeListener subContinentValueListener = e -> {
        if (subcontinent.isVisible()) {
            SubcontinentReferenceDto subcontinentReferenceDto = (SubcontinentReferenceDto) e.getProperty().getValue();
            if (subcontinentReferenceDto != null) {
                continent.removeValueChangeListener(continentValueListener);
                continent.setValue(FacadeProvider.getContinentFacade().getBySubcontinent(subcontinentReferenceDto));
                continent.addValueChangeListener(continentValueListener);
            }
            country.setValue(null);
            ContinentReferenceDto continentValue = (ContinentReferenceDto) continent.getValue();
            FieldHelper.updateItems(country, subcontinentReferenceDto != null ? FacadeProvider.getCountryFacade().getAllActiveBySubcontinent(subcontinentReferenceDto.getUuid()) : continentValue == null ? FacadeProvider.getCountryFacade().getAllActiveAsReference() : FacadeProvider.getCountryFacade().getAllActiveByContinent(continentValue.getUuid()));
        }
    };
    continent.addValueChangeListener(continentValueListener);
    subcontinent.addValueChangeListener(subContinentValueListener);
    skipCountryValueChange = false;
    country.addValueChangeListener(e -> {
        if (!skipCountryValueChange) {
            CountryReferenceDto countryDto = (CountryReferenceDto) e.getProperty().getValue();
            if (countryDto != null) {
                final ContinentReferenceDto countryContinent = FacadeProvider.getContinentFacade().getByCountry(countryDto);
                final SubcontinentReferenceDto countrySubcontinent = FacadeProvider.getSubcontinentFacade().getByCountry(countryDto);
                if (countryContinent != null) {
                    continent.removeValueChangeListener(continentValueListener);
                    if (continent.isVisible()) {
                        skipCountryValueChange = true;
                        FieldHelper.updateItems(country, FacadeProvider.getCountryFacade().getAllActiveByContinent(countryContinent.getUuid()));
                        skipCountryValueChange = false;
                    }
                    continent.setValue(countryContinent);
                    continent.addValueChangeListener(continentValueListener);
                }
                if (countrySubcontinent != null) {
                    subcontinent.removeValueChangeListener(subContinentValueListener);
                    if (subcontinent.isVisible()) {
                        skipCountryValueChange = true;
                        if (countryContinent != null) {
                            FieldHelper.updateItems(subcontinent, FacadeProvider.getSubcontinentFacade().getAllActiveByContinent(countryContinent.getUuid()));
                        }
                        FieldHelper.updateItems(country, FacadeProvider.getCountryFacade().getAllActiveBySubcontinent(countrySubcontinent.getUuid()));
                        skipCountryValueChange = false;
                    }
                    subcontinent.setValue(countrySubcontinent);
                    subcontinent.addValueChangeListener(subContinentValueListener);
                }
            }
        }
    });
    region.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(district, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
    });
    district.addValueChangeListener(e -> {
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(community, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
        if (districtDto == null) {
            FieldHelper.removeItems(facility);
            // Add a visual indictator reminding the user to select a district
            facility.setComponentError(new ErrorMessage() {

                @Override
                public ErrorLevel getErrorLevel() {
                    return ErrorLevel.INFO;
                }

                @Override
                public String getFormattedHtmlMessage() {
                    return I18nProperties.getString(Strings.infoFacilityNeedsDistrict);
                }
            });
        } else if (facilityType.getValue() != null) {
            facility.setComponentError(null);
            facility.markAsDirty();
            FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(districtDto, (FacilityType) facilityType.getValue(), true, false));
        }
    });
    community.addValueChangeListener(e -> {
        CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
        if (facilityType.getValue() != null) {
            FieldHelper.updateItems(facility, communityDto != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(communityDto, (FacilityType) facilityType.getValue(), true, true) : district.getValue() != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) district.getValue(), (FacilityType) facilityType.getValue(), true, false) : null);
        }
    });
    skipFacilityTypeUpdate = false;
    facilityTypeGroup.addValueChangeListener(e -> {
        if (!skipFacilityTypeUpdate) {
            FieldHelper.removeItems(facility);
            FieldHelper.updateEnumData(facilityType, FacilityType.getTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
            facilityType.setRequired(facilityTypeGroup.getValue() != null);
        }
    });
    facilityType.addValueChangeListener(e -> {
        FieldHelper.removeItems(facility);
        facility.setComponentError(null);
        facility.markAsDirty();
        if (facilityType.getValue() != null && facilityTypeGroup.getValue() == null) {
            facilityTypeGroup.setValue(((FacilityType) facilityType.getValue()).getFacilityTypeGroup());
        }
        if (facilityType.getValue() != null && district.getValue() != null) {
            if (community.getValue() != null) {
                FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType((CommunityReferenceDto) community.getValue(), (FacilityType) facilityType.getValue(), true, false));
            } else {
                FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) district.getValue(), (FacilityType) facilityType.getValue(), true, false));
            }
        } else if (facilityType.getValue() != null && district.getValue() == null) {
            // Add a visual indictator reminding the user to select a district
            facility.setComponentError(new ErrorMessage() {

                @Override
                public ErrorLevel getErrorLevel() {
                    return ErrorLevel.INFO;
                }

                @Override
                public String getFormattedHtmlMessage() {
                    return I18nProperties.getString(Strings.infoFacilityNeedsDistrict);
                }
            });
        }
        // Only show contactperson-details if at least a faciltytype has been set
        if (facilityType.getValue() != null) {
            setFacilityContactPersonFieldsVisible(true, true);
        } else {
            setFacilityContactPersonFieldsVisible(false, true);
        }
    });
    facility.addValueChangeListener(e -> {
        if (facility.getValue() != null) {
            boolean visibleAndRequired = areFacilityDetailsRequired();
            facilityDetails.setVisible(visibleAndRequired);
            facilityDetails.setRequired(visibleAndRequired);
            if (!visibleAndRequired) {
                facilityDetails.clear();
            } else {
                String facilityDetailsValue = getValue() != null ? getValue().getFacilityDetails() : null;
                facilityDetails.setValue(facilityDetailsValue);
            }
        } else {
            facilityDetails.setVisible(false);
            facilityDetails.setRequired(false);
            facilityDetails.clear();
        }
        // value because of this field dependencies to other fields and the way updateEnumValues works
        if (facility.isAttached() && !disableFacilityAddressCheck) {
            if (facility.getValue() != null) {
                FacilityDto facilityDto = FacadeProvider.getFacilityFacade().getByUuid(((FacilityReferenceDto) getField(LocationDto.FACILITY).getValue()).getUuid());
                // Only if the facility's address is set
                if (StringUtils.isNotEmpty(facilityDto.getCity()) || StringUtils.isNotEmpty(facilityDto.getPostalCode()) || StringUtils.isNotEmpty(facilityDto.getStreet()) || StringUtils.isNotEmpty(facilityDto.getHouseNumber()) || StringUtils.isNotEmpty(facilityDto.getAdditionalInformation()) || facilityDto.getAreaType() != null || facilityDto.getLatitude() != null || facilityDto.getLongitude() != null || (StringUtils.isNotEmpty(facilityDto.getContactPersonFirstName()) && StringUtils.isNotEmpty(facilityDto.getContactPersonLastName()))) {
                    // Show a confirmation popup if the location's address is already set and different from the facility one
                    if ((StringUtils.isNotEmpty(cityField.getValue()) && !cityField.getValue().equals(facilityDto.getCity())) || (StringUtils.isNotEmpty(postalCodeField.getValue()) && !postalCodeField.getValue().equals(facilityDto.getPostalCode())) || (StringUtils.isNotEmpty(streetField.getValue()) && !streetField.getValue().equals(facilityDto.getStreet())) || (StringUtils.isNotEmpty(houseNumberField.getValue()) && !houseNumberField.getValue().equals(facilityDto.getHouseNumber())) || (StringUtils.isNotEmpty(additionalInformationField.getValue()) && !additionalInformationField.getValue().equals(facilityDto.getAdditionalInformation())) || (areaType.getValue() != null && areaType.getValue() != facilityDto.getAreaType()) || (StringUtils.isNotEmpty(contactPersonFirstName.getValue()) && StringUtils.isNotEmpty(contactPersonLastName.getValue())) || (tfLatitude.getConvertedValue() != null && Double.compare((Double) tfLatitude.getConvertedValue(), facilityDto.getLatitude()) != 0) || (tfLongitude.getConvertedValue() != null && Double.compare((Double) tfLongitude.getConvertedValue(), facilityDto.getLongitude()) != 0)) {
                        VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingLocation), new Label(I18nProperties.getString(Strings.confirmationLocationFacilityAddressOverride)), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), 640, confirmationEvent -> {
                            if (confirmationEvent) {
                                overrideLocationDetailsWithFacilityOnes(facilityDto);
                            }
                        });
                    } else {
                        overrideLocationDetailsWithFacilityOnes(facilityDto);
                    }
                }
            }
        }
    });
    final List<ContinentReferenceDto> continents = FacadeProvider.getContinentFacade().getAllActiveAsReference();
    if (continents.isEmpty()) {
        continent.setVisible(false);
        continent.clear();
    } else {
        continent.addItems(continents);
    }
    final List<SubcontinentReferenceDto> subcontinents = FacadeProvider.getSubcontinentFacade().getAllActiveAsReference();
    if (subcontinents.isEmpty()) {
        subcontinent.setVisible(false);
        subcontinent.clear();
    } else {
        subcontinent.addItems(subcontinents);
    }
    country.addItems(FacadeProvider.getCountryFacade().getAllActiveAsReference());
    updateRegionCombo(region, country);
    country.addValueChangeListener(e -> {
        updateRegionCombo(region, country);
        region.setValue(null);
    });
    Stream.of(LocationDto.LATITUDE, LocationDto.LONGITUDE).<Field<?>>map(this::getField).forEach(f -> f.addValueChangeListener(e -> this.updateLeafletMapContent()));
    // Set initial visiblity of facility-contactperson-details (should only be visible if at least a facilityType has been selected)
    setFacilityContactPersonFieldsVisible(facilityType.getValue() != null, true);
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) Arrays(java.util.Arrays) AbstractField(com.vaadin.v7.ui.AbstractField) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) Alignment(com.vaadin.ui.Alignment) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) LeafletMarker(de.symeda.sormas.ui.map.LeafletMarker) StringUtils(org.apache.commons.lang3.StringUtils) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) CssStyles(de.symeda.sormas.ui.utils.CssStyles) GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon) VaadinIcons(com.vaadin.icons.VaadinIcons) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) LeafletMap(de.symeda.sormas.ui.map.LeafletMap) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) LayoutUtil.divs(de.symeda.sormas.ui.utils.LayoutUtil.divs) PopupView(com.vaadin.ui.PopupView) ComboBox(com.vaadin.v7.ui.ComboBox) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) List(java.util.List) PersonAddressType(de.symeda.sormas.api.person.PersonAddressType) Stream(java.util.stream.Stream) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) SubcontinentReferenceDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) FacadeProvider(de.symeda.sormas.api.FacadeProvider) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) ContinentCriteria(de.symeda.sormas.api.infrastructure.continent.ContinentCriteria) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) Converter(com.vaadin.v7.data.util.converter.Converter) CustomLayout(com.vaadin.ui.CustomLayout) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Label(com.vaadin.ui.Label) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) LocationDto(de.symeda.sormas.api.location.LocationDto) ContentMode(com.vaadin.shared.ui.ContentMode) Validations(de.symeda.sormas.api.i18n.Validations) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ErrorMessage(com.vaadin.server.ErrorMessage) Captions(de.symeda.sormas.api.i18n.Captions) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Button(com.vaadin.ui.Button) MarkerIcon(de.symeda.sormas.ui.map.MarkerIcon) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SubcontinentCriteria(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentCriteria) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) StringToAngularLocationConverter(de.symeda.sormas.ui.utils.StringToAngularLocationConverter) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) Component(com.vaadin.ui.Component) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) Label(com.vaadin.ui.Label) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) StringToAngularLocationConverter(de.symeda.sormas.ui.utils.StringToAngularLocationConverter) TextField(com.vaadin.v7.ui.TextField) SubcontinentReferenceDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto) ComboBox(com.vaadin.v7.ui.ComboBox) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) PersonAddressType(de.symeda.sormas.api.person.PersonAddressType) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) ErrorMessage(com.vaadin.server.ErrorMessage) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 14 with ValueChangeListener

use of com.vaadin.v7.data.Property.ValueChangeListener in project SORMAS-Project by hzi-braunschweig.

the class SymptomsForm method addSoftRequiredStyleWhenSymptomaticAndCooperative.

/**
 * Sets the fields defined by the ids contained in sourceValues to required when the person is symptomatic
 * and - if a visit is processed - cooperative. When this method is called from within a case, it needs to
 * be called with visitStatusField set to null in order to ignore the visit status requirement.
 */
@SuppressWarnings("rawtypes")
private void addSoftRequiredStyleWhenSymptomaticAndCooperative(FieldGroup fieldGroup, Object targetPropertyId, List<String> sourcePropertyIds, List<Object> sourceValues, NullableOptionGroup visitStatusField) {
    for (Object sourcePropertyId : sourcePropertyIds) {
        Field sourceField = fieldGroup.getField(sourcePropertyId);
        if (sourceField instanceof AbstractField<?>) {
            ((AbstractField) sourceField).setImmediate(true);
        }
    }
    // Initialize
    final Field targetField = fieldGroup.getField(targetPropertyId);
    if (!targetField.isVisible()) {
        return;
    }
    if (visitStatusField != null) {
        if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues) && visitStatusField.getNullableValue() == VisitStatus.COOPERATIVE) {
            FieldHelper.addSoftRequiredStyle(targetField);
        } else {
            FieldHelper.removeSoftRequiredStyle(targetField);
        }
    } else {
        if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)) {
            FieldHelper.addSoftRequiredStyle(targetField);
        } else {
            FieldHelper.removeSoftRequiredStyle(targetField);
        }
    }
    // Add listeners
    for (Object sourcePropertyId : sourcePropertyIds) {
        Field sourceField = fieldGroup.getField(sourcePropertyId);
        sourceField.addValueChangeListener(event -> {
            if (visitStatusField != null) {
                if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues) && visitStatusField.getValue() == VisitStatus.COOPERATIVE) {
                    FieldHelper.addSoftRequiredStyle(targetField);
                } else {
                    FieldHelper.removeSoftRequiredStyle(targetField);
                }
            } else {
                if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)) {
                    FieldHelper.addSoftRequiredStyle(targetField);
                } else {
                    FieldHelper.removeSoftRequiredStyle(targetField);
                }
            }
        });
    }
    if (visitStatusField != null) {
        visitStatusField.addValueChangeListener(new ValueChangeListener() {

            @Override
            public void valueChange(com.vaadin.v7.data.Property.ValueChangeEvent event) {
                if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues) && visitStatusField.getValue() == VisitStatus.COOPERATIVE) {
                    FieldHelper.addSoftRequiredStyle(targetField);
                } else {
                    FieldHelper.removeSoftRequiredStyle(targetField);
                }
            }
        });
    }
}
Also used : AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) AbstractField(com.vaadin.v7.ui.AbstractField)

Example 15 with ValueChangeListener

use of com.vaadin.v7.data.Property.ValueChangeListener in project SORMAS-Project by hzi-braunschweig.

the class MultiSelect method initContent.

@Override
protected Component initContent() {
    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setMargin(new MarginInfo(false, false, true, false));
    selectComponent.setWidth("100%");
    selectComponent.addValueChangeListener((ValueChangeListener) event -> {
        T item = (T) selectComponent.getValue();
        if (item == null) {
            return;
        }
        String caption = selectComponent.getItemCaption(item);
        selectedItemsWithCaption.put(item, caption);
        setValue(new HashSet<>(selectedItemsWithCaption.keySet()));
        selectComponent.setValue(null);
        listSelectedItems();
    });
    verticalLayout.addComponent(selectComponent);
    if (isReadOnly()) {
        selectComponent.setVisible(false);
        selectComponent.setReadOnly(true);
    }
    labelLayout.setMargin(false);
    verticalLayout.addComponent(labelLayout);
    initFromCurrentValue();
    listSelectedItems();
    return verticalLayout;
}
Also used : ValoTheme(com.vaadin.ui.themes.ValoTheme) VerticalLayout(com.vaadin.ui.VerticalLayout) Set(java.util.Set) HashMap(java.util.HashMap) Converter(com.vaadin.v7.data.util.converter.Converter) MarginInfo(com.vaadin.shared.ui.MarginInfo) Select(com.vaadin.v7.ui.Select) HashSet(java.util.HashSet) Button(com.vaadin.ui.Button) HorizontalLayout(com.vaadin.ui.HorizontalLayout) Map(java.util.Map) Label(com.vaadin.ui.Label) CustomField(com.vaadin.v7.ui.CustomField) VaadinIcons(com.vaadin.icons.VaadinIcons) Component(com.vaadin.ui.Component) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) MarginInfo(com.vaadin.shared.ui.MarginInfo) VerticalLayout(com.vaadin.ui.VerticalLayout) HashSet(java.util.HashSet)

Aggregations

ValueChangeListener (com.vaadin.v7.data.Property.ValueChangeListener)21 ValueChangeEvent (com.vaadin.v7.data.Property.ValueChangeEvent)20 ComboBox (com.vaadin.v7.ui.ComboBox)17 TextField (com.vaadin.v7.ui.TextField)11 Label (com.vaadin.ui.Label)10 DateField (com.vaadin.v7.ui.DateField)8 FacadeProvider (de.symeda.sormas.api.FacadeProvider)8 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)8 FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)8 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)8 FieldHelper (de.symeda.sormas.ui.utils.FieldHelper)8 List (java.util.List)8 Converter (com.vaadin.v7.data.util.converter.Converter)7 Captions (de.symeda.sormas.api.i18n.Captions)7 Strings (de.symeda.sormas.api.i18n.Strings)7 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)7 CheckBox (com.vaadin.v7.ui.CheckBox)6 Field (com.vaadin.v7.ui.Field)6 Disease (de.symeda.sormas.api.Disease)6 FacilityDto (de.symeda.sormas.api.infrastructure.facility.FacilityDto)6