Search in sources :

Example 11 with ComboBox

use of com.vaadin.v7.ui.ComboBox in project opencms-core by alkacon.

the class CmsMessageBundleEditorOptions method initLanguageSwitch.

/**
 * Initializes the language switcher UI Component {@link #m_languageSwitch}, including {@link #m_languageSelect}.
 * @param locales the locales that can be selected.
 * @param current the currently selected locale.
 */
private void initLanguageSwitch(Collection<Locale> locales, Locale current) {
    FormLayout languages = new FormLayout();
    languages.setHeight("100%");
    languages.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    ComboBox languageSelect = new ComboBox();
    languageSelect.setCaption(m_messages.key(Messages.GUI_LANGUAGE_SWITCHER_LABEL_0));
    languageSelect.setNullSelectionAllowed(false);
    // set Locales
    for (Locale locale : locales) {
        languageSelect.addItem(locale);
        String caption = locale.getDisplayName(UI.getCurrent().getLocale());
        if (CmsLocaleManager.getDefaultLocale().equals(locale)) {
            caption += " (" + Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_DEFAULT_LOCALE_0) + ")";
        }
        languageSelect.setItemCaption(locale, caption);
    }
    languageSelect.setValue(current);
    languageSelect.setNewItemsAllowed(false);
    languageSelect.setTextInputAllowed(false);
    languageSelect.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            m_listener.handleLanguageChange((Locale) event.getProperty().getValue());
        }
    });
    if (locales.size() == 1) {
        languageSelect.setEnabled(false);
    }
    languages.addComponent(languageSelect);
    m_languageSwitch = languages;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) Locale(java.util.Locale) ValueChangeEvent(com.vaadin.v7.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener) ComboBox(com.vaadin.v7.ui.ComboBox)

Example 12 with ComboBox

use of com.vaadin.v7.ui.ComboBox 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 13 with ComboBox

use of com.vaadin.v7.ui.ComboBox in project opencms-core by alkacon.

the class CmsPrincipalSelectDialog method initTypeCombo.

/**
 * Init ComboBox for choosing type of principal.<p>
 * @param defaultType Default mode to open
 */
private void initTypeCombo(CmsPrincipalSelect.PrincipalType defaultType, boolean roleSelectionAllowed) {
    IndexedContainer container = new IndexedContainer();
    container.addContainerProperty("caption", String.class, "");
    Item item = container.addItem(CmsPrincipalSelect.PrincipalType.group);
    item.getItemProperty("caption").setValue(CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_GROUP_0));
    item = container.addItem(CmsPrincipalSelect.PrincipalType.user);
    item.getItemProperty("caption").setValue(CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_0));
    if (roleSelectionAllowed) {
        if ((m_type == null) || m_type.getPrincipalTypes().contains(CmsPrincipalSelect.PrincipalType.role)) {
            item = container.addItem(CmsPrincipalSelect.PrincipalType.role);
            String message = CmsVaadinUtils.getMessageText(Messages.GUI_USERMANAGEMENT_USER_ROLE_0);
            item.getItemProperty("caption").setValue(message);
        }
    }
    m_typeCombo.setContainerDataSource(container);
    m_typeCombo.select(defaultType);
    m_typeCombo.setEnabled((m_type == null) || (m_type.getPrincipalTypes().size() > 1));
    m_typeCombo.setItemCaptionPropertyId("caption");
    m_typeCombo.setNullSelectionAllowed(false);
    m_typeCombo.setNewItemsAllowed(false);
}
Also used : Item(com.vaadin.v7.data.Item) IndexedContainer(com.vaadin.v7.data.util.IndexedContainer)

Example 14 with ComboBox

use of com.vaadin.v7.ui.ComboBox in project SORMAS-Project by hzi-braunschweig.

the class CaseCreateForm method updatePOEs.

private void updatePOEs() {
    ComboBox comboBoxPOE = getField(CaseDataDto.POINT_OF_ENTRY);
    if (!comboBoxPOE.isReadOnly()) {
        DistrictReferenceDto districtDto;
        if (Boolean.TRUE.equals(differentPointOfEntryJurisdiction.getValue())) {
            districtDto = (DistrictReferenceDto) pointOfEntryDistrictCombo.getValue();
        } else if (Boolean.TRUE.equals(differentPlaceOfStayJurisdiction.getValue())) {
            districtDto = (DistrictReferenceDto) districtCombo.getValue();
        } else {
            districtDto = (DistrictReferenceDto) responsibleDistrictCombo.getValue();
        }
        List<PointOfEntryReferenceDto> POEs = districtDto == null ? Collections.emptyList() : FacadeProvider.getPointOfEntryFacade().getAllActiveByDistrict(districtDto.getUuid(), true);
        FieldHelper.updateItems(comboBoxPOE, POEs);
    }
}
Also used : ComboBox(com.vaadin.v7.ui.ComboBox) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)

Example 15 with ComboBox

use of com.vaadin.v7.ui.ComboBox 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)

Aggregations

ComboBox (com.vaadin.v7.ui.ComboBox)113 TextField (com.vaadin.v7.ui.TextField)43 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)31 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)28 Label (com.vaadin.ui.Label)24 Disease (de.symeda.sormas.api.Disease)24 TextArea (com.vaadin.v7.ui.TextArea)19 UserDto (de.symeda.sormas.api.user.UserDto)19 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)19 DateField (com.vaadin.v7.ui.DateField)18 List (java.util.List)18 CheckBox (com.vaadin.v7.ui.CheckBox)17 FacadeProvider (de.symeda.sormas.api.FacadeProvider)17 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)17 DateComparisonValidator (de.symeda.sormas.ui.utils.DateComparisonValidator)17 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)16 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)16 Field (com.vaadin.v7.ui.Field)15 FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)15 Captions (de.symeda.sormas.api.i18n.Captions)14