Search in sources :

Example 21 with ValueChangeEvent

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

the class ImmunizationCreationForm method addFields.

@SuppressWarnings("deprecation")
@Override
protected void addFields() {
    addField(ImmunizationDto.REPORT_DATE, DateField.class);
    TextField externalIdField = addField(ImmunizationDto.EXTERNAL_ID, TextField.class);
    style(externalIdField, ERROR_COLOR_PRIMARY);
    ComboBox diseaseField = addDiseaseField(ImmunizationDto.DISEASE, false, true);
    addField(ImmunizationDto.DISEASE_DETAILS, TextField.class);
    ComboBox meansOfImmunizationField = addField(ImmunizationDto.MEANS_OF_IMMUNIZATION, ComboBox.class);
    addField(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS, TextField.class);
    CheckBox overwriteImmunizationManagementStatus = addCustomField(OVERWRITE_IMMUNIZATION_MANAGEMENT_STATUS, Boolean.class, CheckBox.class);
    overwriteImmunizationManagementStatus.addStyleName(VSPACE_3);
    ComboBox managementStatusField = addCustomField(ImmunizationDto.IMMUNIZATION_MANAGEMENT_STATUS, ImmunizationManagementStatus.class, ComboBox.class);
    managementStatusField.setValue(ImmunizationManagementStatus.SCHEDULED);
    managementStatusField.setEnabled(false);
    managementStatusField.setNullSelectionAllowed(false);
    ComboBox immunizationStatusField = addCustomField(ImmunizationDto.IMMUNIZATION_STATUS, ImmunizationStatus.class, ComboBox.class);
    immunizationStatusField.setValue(ImmunizationStatus.PENDING);
    immunizationStatusField.setEnabled(false);
    Label jurisdictionHeadingLabel = new Label(I18nProperties.getString(Strings.headingResponsibleJurisdiction));
    jurisdictionHeadingLabel.addStyleName(H3);
    getContent().addComponent(jurisdictionHeadingLabel, RESPONSIBLE_JURISDICTION_HEADING_LOC);
    ComboBox responsibleRegion = addInfrastructureField(ImmunizationDto.RESPONSIBLE_REGION);
    responsibleRegion.setRequired(true);
    ComboBox responsibleDistrictCombo = addInfrastructureField(ImmunizationDto.RESPONSIBLE_DISTRICT);
    responsibleDistrictCombo.setRequired(true);
    ComboBox responsibleCommunityCombo = addInfrastructureField(ImmunizationDto.RESPONSIBLE_COMMUNITY);
    responsibleCommunityCombo.setNullSelectionAllowed(true);
    responsibleCommunityCombo.addStyleName(SOFT_REQUIRED);
    InfrastructureFieldsHelper.initInfrastructureFields(responsibleRegion, responsibleDistrictCombo, responsibleCommunityCombo);
    ComboBox 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);
    ComboBox facilityType = ComboBoxHelper.createComboBoxV7();
    facilityType.setId("type");
    facilityType.setCaption(I18nProperties.getCaption(Captions.facilityType));
    facilityType.setWidth(100, Unit.PERCENTAGE);
    getContent().addComponent(facilityType, ImmunizationDto.FACILITY_TYPE);
    ComboBox facilityCombo = addInfrastructureField(ImmunizationDto.HEALTH_FACILITY);
    facilityCombo.setImmediate(true);
    TextField facilityDetails = addField(ImmunizationDto.HEALTH_FACILITY_DETAILS, TextField.class);
    facilityDetails.setVisible(false);
    DateField startDate = addField(ImmunizationDto.START_DATE, DateField.class);
    DateField endDate = addDateField(ImmunizationDto.END_DATE, DateField.class, -1);
    DateComparisonValidator.addStartEndValidators(startDate, endDate);
    DateField validFrom = addDateField(ImmunizationDto.VALID_FROM, DateField.class, -1);
    DateField validUntil = addDateField(ImmunizationDto.VALID_UNTIL, DateField.class, -1);
    DateComparisonValidator.addStartEndValidators(validFrom, validUntil);
    Field numberOfDosesField = addField(ImmunizationDto.NUMBER_OF_DOSES);
    numberOfDosesField.addValidator(new NumberValidator(I18nProperties.getValidationError(Validations.vaccineDosesFormat), 1, 10, false));
    numberOfDosesField.setVisible(false);
    personCreateForm = new PersonCreateForm(false, true, false);
    personCreateForm.setWidth(100, Unit.PERCENTAGE);
    personCreateForm.setValue(new PersonDto());
    diseaseField.addValueChangeListener((ValueChangeListener) valueChangeEvent -> personCreateForm.updatePresentConditionEnum((Disease) valueChangeEvent.getProperty().getValue()));
    getContent().addComponent(personCreateForm, TravelEntryDto.PERSON);
    // Set initial visibilities & accesses
    initializeVisibilitiesAndAllowedVisibilities();
    setRequired(true, ImmunizationDto.REPORT_DATE, ImmunizationDto.MEANS_OF_IMMUNIZATION);
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(ImmunizationDto.DISEASE_DETAILS), ImmunizationDto.DISEASE, Collections.singletonList(Disease.OTHER), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), ImmunizationDto.DISEASE, Collections.singletonList(ImmunizationDto.DISEASE_DETAILS), Collections.singletonList(Disease.OTHER));
    FieldHelper.setVisibleWhen(getFieldGroup(), Collections.singletonList(ImmunizationDto.MEANS_OF_IMMUNIZATION_DETAILS), ImmunizationDto.MEANS_OF_IMMUNIZATION, Collections.singletonList(MeansOfImmunization.OTHER), true);
    overwriteImmunizationManagementStatus.addValueChangeListener(e -> {
        boolean selectedValue = (boolean) e.getProperty().getValue();
        if (!selectedValue) {
            managementStatusField.setValue(ImmunizationManagementStatus.SCHEDULED);
        }
        managementStatusField.setEnabled(selectedValue);
    });
    meansOfImmunizationField.addValueChangeListener(e -> {
        MeansOfImmunization meansOfImmunization = (MeansOfImmunization) e.getProperty().getValue();
        if (MeansOfImmunization.RECOVERY.equals(meansOfImmunization) || MeansOfImmunization.OTHER.equals(meansOfImmunization)) {
            managementStatusField.setValue(ImmunizationManagementStatus.COMPLETED);
        } else {
            managementStatusField.setValue(ImmunizationManagementStatus.SCHEDULED);
        }
        boolean isVaccinationVisible = MeansOfImmunization.VACCINATION.equals(meansOfImmunization) || MeansOfImmunization.VACCINATION_RECOVERY.equals(meansOfImmunization);
        numberOfDosesField.setVisible(isVaccinationVisible);
        if (!isVaccinationVisible) {
            numberOfDosesField.setValue(null);
        }
    });
    managementStatusField.addValueChangeListener(e -> {
        ImmunizationManagementStatus managementStatusValue = (ImmunizationManagementStatus) e.getProperty().getValue();
        switch(managementStatusValue) {
            case SCHEDULED:
            case ONGOING:
                immunizationStatusField.setValue(ImmunizationStatus.PENDING);
                break;
            case COMPLETED:
                immunizationStatusField.setValue(ImmunizationStatus.ACQUIRED);
                break;
            case CANCELED:
                immunizationStatusField.setValue(ImmunizationStatus.NOT_ACQUIRED);
                break;
            default:
                break;
        }
    });
    responsibleDistrictCombo.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        if (districtDto != null && facilityType.getValue() != null) {
            FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(districtDto, (FacilityType) facilityType.getValue(), true, false));
        }
    });
    responsibleCommunityCombo.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
        if (facilityType.getValue() != null) {
            FieldHelper.updateItems(facilityCombo, communityDto != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(communityDto, (FacilityType) facilityType.getValue(), true, false) : responsibleDistrictCombo.getValue() != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) responsibleDistrictCombo.getValue(), (FacilityType) facilityType.getValue(), true, false) : null);
        }
    });
    facilityTypeGroup.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        FieldHelper.updateEnumData(facilityType, FacilityType.getAccommodationTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
    });
    facilityType.addValueChangeListener(e -> {
        FieldHelper.removeItems(facilityCombo);
        if (facilityType.getValue() != null && responsibleDistrictCombo.getValue() != null) {
            if (responsibleCommunityCombo.getValue() != null) {
                FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType((CommunityReferenceDto) responsibleCommunityCombo.getValue(), (FacilityType) facilityType.getValue(), true, false));
            } else {
                FieldHelper.updateItems(facilityCombo, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) responsibleDistrictCombo.getValue(), (FacilityType) facilityType.getValue(), true, false));
            }
        }
    });
    facilityCombo.addValueChangeListener(e -> {
        updateFacilityFields(facilityCombo, facilityDetails);
        this.getValue().setFacilityType((FacilityType) facilityType.getValue());
    });
    addValueChangeListener(e -> {
        if (disease != null) {
            setVisible(false, ImmunizationDto.DISEASE, ImmunizationDto.DISEASE_DETAILS);
            setReadOnly(false, ImmunizationDto.DISEASE, ImmunizationDto.DISEASE_DETAILS);
        } else {
            setRequired(true, ImmunizationDto.DISEASE);
        }
        if (personDto != null) {
            personCreateForm.setVisible(false);
            personCreateForm.setReadOnly(false);
        } else {
            personCreateForm.enablePersonFields(true);
        }
    });
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) H3(de.symeda.sormas.ui.utils.CssStyles.H3) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) CheckBox(com.vaadin.v7.ui.CheckBox) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) PersonDto(de.symeda.sormas.api.person.PersonDto) Label(com.vaadin.ui.Label) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) VSPACE_3(de.symeda.sormas.ui.utils.CssStyles.VSPACE_3) ERROR_COLOR_PRIMARY(de.symeda.sormas.ui.utils.CssStyles.ERROR_COLOR_PRIMARY) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) DateField(com.vaadin.v7.ui.DateField) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) CssStyles.style(de.symeda.sormas.ui.utils.CssStyles.style) Validations(de.symeda.sormas.api.i18n.Validations) PersonCreateForm(de.symeda.sormas.ui.person.PersonCreateForm) ComboBox(com.vaadin.v7.ui.ComboBox) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) 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) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) Disease(de.symeda.sormas.api.Disease) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TravelEntryDto(de.symeda.sormas.api.travelentry.TravelEntryDto) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) TextField(com.vaadin.v7.ui.TextField) ImmunizationStatus(de.symeda.sormas.api.immunization.ImmunizationStatus) ImmunizationDto(de.symeda.sormas.api.immunization.ImmunizationDto) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) NumberValidator(de.symeda.sormas.ui.utils.NumberValidator) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ComboBox(com.vaadin.v7.ui.ComboBox) PersonDto(de.symeda.sormas.api.person.PersonDto) Label(com.vaadin.ui.Label) MeansOfImmunization(de.symeda.sormas.api.immunization.MeansOfImmunization) PersonCreateForm(de.symeda.sormas.ui.person.PersonCreateForm) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ImmunizationManagementStatus(de.symeda.sormas.api.immunization.ImmunizationManagementStatus) DateField(com.vaadin.v7.ui.DateField) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) NumberValidator(de.symeda.sormas.ui.utils.NumberValidator) CheckBox(com.vaadin.v7.ui.CheckBox) TextField(com.vaadin.v7.ui.TextField) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) DateField(com.vaadin.v7.ui.DateField) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 22 with ValueChangeEvent

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

the class CmsFileExplorer method createSiteSelect.

/**
 * Creates the site selector combo box.<p>
 *
 * @param cms the current cms context
 *
 * @return the combo box
 */
private ComboBox createSiteSelect(CmsObject cms) {
    final List<CmsExtendedSiteSelector.SiteSelectorOption> sites = CmsExtendedSiteSelector.getExplorerSiteSelectorOptions(cms, true);
    final BeanItemContainer<CmsExtendedSiteSelector.SiteSelectorOption> container = new BeanItemContainer<>(CmsExtendedSiteSelector.SiteSelectorOption.class);
    for (CmsExtendedSiteSelector.SiteSelectorOption option : sites) {
        container.addItem(option);
    }
    ComboBox combo = new ComboBox(null, container);
    combo.setTextInputAllowed(true);
    combo.setNullSelectionAllowed(false);
    combo.setWidth("200px");
    combo.setInputPrompt(Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_EXPLORER_CLICK_TO_EDIT_0));
    combo.setItemCaptionPropertyId("label");
    combo.select(new CmsExtendedSiteSelector.SiteSelectorOption(cms.getRequestContext().getSiteRoot(), null, null));
    combo.setFilteringMode(FilteringMode.CONTAINS);
    combo.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        /**
         * Flag used to temporarily disable the standard listener behavior, used when we change the combo box's value programatically.
         */
        private boolean m_disabled;

        public void valueChange(ValueChangeEvent event) {
            if (m_disabled) {
                return;
            }
            CmsExtendedSiteSelector.SiteSelectorOption option = (CmsExtendedSiteSelector.SiteSelectorOption) (event.getProperty().getValue());
            if (container.containsId(option)) {
                changeSite(option.getSite(), option.getPath());
                m_appContext.updateOnChange();
                container.removeAllContainerFilters();
                if (option.getPath() != null) {
                    try {
                        m_disabled = true;
                        combo.select(new CmsExtendedSiteSelector.SiteSelectorOption(option.getSite(), null, null));
                    } finally {
                        m_disabled = false;
                    }
                }
            }
        }
    });
    if (Page.getCurrent().getBrowserWindowHeight() > 650) {
        combo.setPageLength(20);
    }
    return combo;
}
Also used : ValueChangeEvent(com.vaadin.v7.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener) CmsExtendedSiteSelector(org.opencms.ui.components.CmsExtendedSiteSelector) ComboBox(com.vaadin.v7.ui.ComboBox) BeanItemContainer(com.vaadin.v7.data.util.BeanItemContainer)

Example 23 with ValueChangeEvent

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

the class CmsGitToolOptionsPanel method configureConfigurationSelector.

/**
 * Configures the configuration selector.
 */
private void configureConfigurationSelector() {
    if (m_checkinBean.getConfigurations().size() < 2) {
        // Do not show the configuration selection at all.
        removeComponent(m_configurationSelectionPanel);
    } else {
        for (CmsGitConfiguration configuration : m_checkinBean.getConfigurations()) {
            m_configurationSelector.addItem(configuration);
            m_configurationSelector.setItemCaption(configuration, configuration.getName());
        }
        m_configurationSelector.setNullSelectionAllowed(false);
        m_configurationSelector.setNewItemsAllowed(false);
        m_configurationSelector.setWidth("350px");
        m_configurationSelector.select(m_checkinBean.getCurrentConfiguration());
        // There is really a choice between configurations
        m_configurationSelector.addValueChangeListener(new ValueChangeListener() {

            private static final long serialVersionUID = 1L;

            @SuppressWarnings("synthetic-access")
            public void valueChange(ValueChangeEvent event) {
                updateForNewConfiguration((CmsGitConfiguration) event.getProperty().getValue());
                restoreFieldsFromUserInfo();
            }
        });
    }
}
Also used : ValueChangeEvent(com.vaadin.v7.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener)

Example 24 with ValueChangeEvent

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

the class CmsMessageBundleEditorOptions method initModeSwitch.

/**
 * Initializes the mode switcher.
 * @param current the current edit mode
 */
private void initModeSwitch(final EditMode current) {
    FormLayout modes = new FormLayout();
    modes.setHeight("100%");
    modes.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
    m_modeSelect = new ComboBox();
    m_modeSelect.setCaption(m_messages.key(Messages.GUI_VIEW_SWITCHER_LABEL_0));
    // add Modes
    m_modeSelect.addItem(CmsMessageBundleEditorTypes.EditMode.DEFAULT);
    m_modeSelect.setItemCaption(CmsMessageBundleEditorTypes.EditMode.DEFAULT, m_messages.key(Messages.GUI_VIEW_SWITCHER_EDITMODE_DEFAULT_0));
    m_modeSelect.addItem(CmsMessageBundleEditorTypes.EditMode.MASTER);
    m_modeSelect.setItemCaption(CmsMessageBundleEditorTypes.EditMode.MASTER, m_messages.key(Messages.GUI_VIEW_SWITCHER_EDITMODE_MASTER_0));
    // set current mode as selected
    m_modeSelect.setValue(current);
    m_modeSelect.setNewItemsAllowed(false);
    m_modeSelect.setTextInputAllowed(false);
    m_modeSelect.setNullSelectionAllowed(false);
    m_modeSelect.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            m_listener.handleModeChange((EditMode) event.getProperty().getValue());
        }
    });
    modes.addComponent(m_modeSelect);
    m_modeSwitch = modes;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) ValueChangeEvent(com.vaadin.v7.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener) ComboBox(com.vaadin.v7.ui.ComboBox) EditMode(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditMode)

Example 25 with ValueChangeEvent

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

the class CmsLocaleComparePanel method initialize.

/**
 * Initializes the locale comparison view.<p>
 *
 * @param id the structure id of the currrent sitemap root entry
 * @param initialComparisonLocale if not null, the initially selected ccomparison locale
 *
 * @throws CmsException if something goes wrong
 */
public void initialize(CmsUUID id, Locale initialComparisonLocale) throws CmsException {
    removeAllComponents();
    CmsObject cms = A_CmsUI.getCmsObject();
    CmsResource res = cms.readResource(id);
    m_currentRoot = res;
    CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(res.getRootPath());
    Locale rootLocale = OpenCms.getLocaleManager().getDefaultLocale(cms, res);
    m_rootLocale = rootLocale;
    Locale mainLocale = site.getMainTranslationLocale(null);
    List<Locale> secondaryLocales = site.getSecondaryTranslationLocales();
    List<Locale> possibleLocaleSelections = getMainLocaleSelectOptions(cms, res, mainLocale, secondaryLocales);
    m_rootLocaleSelector = new ComboBox();
    m_rootLocaleSelector.addStyleName("o-sitemap-localeselect");
    m_rootLocaleSelector.setNullSelectionAllowed(false);
    for (Locale selectableLocale : possibleLocaleSelections) {
        m_rootLocaleSelector.addItem(selectableLocale);
        m_rootLocaleSelector.setItemIcon(selectableLocale, FontOpenCms.SPACE);
        m_rootLocaleSelector.setItemCaption(selectableLocale, selectableLocale.getDisplayName(A_CmsUI.get().getLocale()));
    }
    m_rootLocaleSelector.setItemIcon(mainLocale, MAIN_LOCALE_ICON);
    m_rootLocaleSelector.setValue(m_rootLocale);
    m_rootLocaleSelector.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("synthetic-access")
        public void valueChange(ValueChangeEvent event) {
            if (!m_handlingLocaleChange) {
                m_handlingLocaleChange = true;
                try {
                    Locale newLocale = (Locale) (event.getProperty().getValue());
                    switchToLocale(newLocale);
                } catch (Exception e) {
                    LOG.error(e.getLocalizedMessage(), e);
                    CmsErrorDialog.showErrorDialog(e);
                } finally {
                    m_handlingLocaleChange = false;
                }
            }
        }
    });
    m_comparisonLocaleSelector = new ComboBox();
    m_comparisonLocaleSelector.addStyleName("o-sitemap-localeselect");
    m_comparisonLocaleSelector.setNullSelectionAllowed(false);
    List<Locale> comparisonLocales = getComparisonLocales();
    Locale selectedComparisonLocale = null;
    for (Locale comparisonLocale : comparisonLocales) {
        m_comparisonLocaleSelector.addItem(comparisonLocale);
        m_comparisonLocaleSelector.setItemIcon(comparisonLocale, FontOpenCms.SPACE);
        m_comparisonLocaleSelector.setItemCaption(comparisonLocale, comparisonLocale.getDisplayName(A_CmsUI.get().getLocale()));
        if ((selectedComparisonLocale == null) && !comparisonLocale.equals(m_rootLocale)) {
            selectedComparisonLocale = comparisonLocale;
        }
        if ((initialComparisonLocale != null) && comparisonLocale.equals(initialComparisonLocale) && !comparisonLocale.equals(m_rootLocale)) {
            // if an initial comparison locale is given, it should have priority over the first comparison locale
            selectedComparisonLocale = comparisonLocale;
        }
    }
    m_comparisonLocale = selectedComparisonLocale;
    m_comparisonLocaleSelector.setValue(selectedComparisonLocale);
    m_comparisonLocaleSelector.setItemIcon(mainLocale, MAIN_LOCALE_ICON);
    m_comparisonLocaleSelector.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("synthetic-access")
        public void valueChange(ValueChangeEvent event) {
            if (!m_handlingLocaleChange) {
                m_handlingLocaleChange = true;
                try {
                    Locale locale = (Locale) (event.getProperty().getValue());
                    if (m_rootLocale.equals(locale)) {
                        Locale oldComparisonLocale = m_comparisonLocale;
                        if (getLocaleGroup().getResourcesByLocale().keySet().contains(oldComparisonLocale)) {
                            m_comparisonLocale = locale;
                            switchToLocale(oldComparisonLocale);
                            updateLocaleWidgets();
                        } else {
                            Notification.show(CmsVaadinUtils.getMessageText(Messages.GUI_LOCALECOMPARE_CANNOT_SWITCH_COMPARISON_LOCALE_0));
                            m_comparisonLocaleSelector.setValue(oldComparisonLocale);
                        }
                    } else {
                        m_comparisonLocale = locale;
                        updateLocaleWidgets();
                        initTree(m_currentRoot);
                    }
                } catch (Exception e) {
                    LOG.error(e.getLocalizedMessage(), e);
                    CmsErrorDialog.showErrorDialog(e);
                } finally {
                    m_handlingLocaleChange = false;
                }
            }
        }
    });
    CssLayout localeSelectors = new CssLayout();
    localeSelectors.addStyleName(OpenCmsTheme.SITEMAP_LOCALE_BAR);
    m_rootLocaleSelector.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_LOCALECOMPARE_MAIN_LOCALE_0));
    m_comparisonLocaleSelector.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_LOCALECOMPARE_COMPARISON_LOCALE_0));
    localeSelectors.setWidth("100%");
    localeSelectors.addComponent(m_rootLocaleSelector);
    localeSelectors.addComponent(m_comparisonLocaleSelector);
    // localeSelectors.setComponentAlignment(wrapper2, Alignment.MIDDLE_RIGHT);
    setSpacing(true);
    addComponent(localeSelectors);
    addComponent(m_treeContainer);
    m_treeContainer.setWidth("100%");
    initTree(res);
}
Also used : Locale(java.util.Locale) CssLayout(com.vaadin.ui.CssLayout) ValueChangeEvent(com.vaadin.v7.data.Property.ValueChangeEvent) CmsObject(org.opencms.file.CmsObject) ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener) CmsResource(org.opencms.file.CmsResource) ComboBox(com.vaadin.v7.ui.ComboBox) CmsSite(org.opencms.site.CmsSite) CmsException(org.opencms.main.CmsException)

Aggregations

ValueChangeEvent (com.vaadin.v7.data.Property.ValueChangeEvent)20 ValueChangeListener (com.vaadin.v7.data.Property.ValueChangeListener)20 ComboBox (com.vaadin.v7.ui.ComboBox)17 TextField (com.vaadin.v7.ui.TextField)11 Label (com.vaadin.ui.Label)10 CheckBox (com.vaadin.v7.ui.CheckBox)10 DateField (com.vaadin.v7.ui.DateField)9 Disease (de.symeda.sormas.api.Disease)9 FacadeProvider (de.symeda.sormas.api.FacadeProvider)9 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)9 FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)9 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)9 H3 (de.symeda.sormas.ui.utils.CssStyles.H3)9 VSPACE_3 (de.symeda.sormas.ui.utils.CssStyles.VSPACE_3)9 FieldHelper (de.symeda.sormas.ui.utils.FieldHelper)9 Captions (de.symeda.sormas.api.i18n.Captions)8 Strings (de.symeda.sormas.api.i18n.Strings)8 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)8 Converter (com.vaadin.v7.data.util.converter.Converter)7 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)7