Search in sources :

Example 26 with ValueChangeListener

use of com.vaadin.v7.data.Property.ValueChangeListener 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)

Example 27 with ValueChangeListener

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

the class CmsLogicalCheckboxGroup method remove.

/**
 * Removes a check box from the group.<p>
 *
 * @param checkBox the check box
 */
public void remove(CheckBox checkBox) {
    m_checkboxes.remove(checkBox);
    if (m_selected == checkBox) {
        m_selected = null;
    }
    ValueChangeListener listener = m_listeners.get(checkBox);
    if (listener != null) {
        checkBox.removeValueChangeListener(m_listeners.get(checkBox));
    }
}
Also used : ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener)

Example 28 with ValueChangeListener

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

the class CmsLogicalCheckboxGroup method add.

/**
 * Adds a check box to the group.<p>
 *
 * @param checkBox the check box to add
 */
public void add(final CheckBox checkBox) {
    checkBox.setValue(Boolean.FALSE);
    m_checkboxes.add(checkBox);
    ValueChangeListener listener = new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("synthetic-access")
        public void valueChange(ValueChangeEvent event) {
            if (m_runningEvent) {
                return;
            } else {
                try {
                    m_runningEvent = true;
                    if (((Boolean) event.getProperty().getValue()).booleanValue()) {
                        if ((m_selected != null) && (m_selected != checkBox)) {
                            m_selected.setValue(Boolean.FALSE);
                        }
                        setActiveCheckBox(checkBox);
                    } else {
                        setActiveCheckBox(null);
                        m_selected = null;
                    }
                // TODO Auto-generated method stub
                } finally {
                    m_runningEvent = false;
                }
            }
        }
    };
    checkBox.addValueChangeListener(listener);
    m_listeners.put(checkBox, listener);
}
Also used : ValueChangeEvent(com.vaadin.v7.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener)

Example 29 with ValueChangeListener

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

the class CmsSiteSelectDialog method initForm.

/**
 * Initializes the form component.<p>
 *
 * @return the form component
 */
private FormLayout initForm() {
    FormLayout form = new FormLayout();
    form.setWidth("100%");
    m_siteComboBox = prepareSiteSelector(org.opencms.workplace.Messages.GUI_LABEL_SITE_0);
    m_siteComboBox.setValue(new CmsExtendedSiteSelector.SiteSelectorOption(A_CmsUI.getCmsObject().getRequestContext().getSiteRoot(), null, null));
    form.addComponent(m_siteComboBox);
    ValueChangeListener changeListener = new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {
            submit();
        }
    };
    m_siteComboBox.addValueChangeListener(evt -> submit());
    return form;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) ValueChangeEvent(com.vaadin.v7.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener) CmsExtendedSiteSelector(org.opencms.ui.components.CmsExtendedSiteSelector)

Example 30 with ValueChangeListener

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

the class CmsDataViewPanel method updateFilters.

/**
 * Changes the displayed filters to a new set.<p>
 *
 * @param newFilters the new filters
 */
public void updateFilters(List<CmsDataViewFilter> newFilters) {
    if (newFilters.isEmpty()) {
        m_filterContainer.setVisible(false);
    }
    if (m_filters.equals(newFilters)) {
        return;
    }
    m_filterContainer.removeAllComponents();
    m_filters = newFilters;
    m_filterMap.clear();
    for (CmsDataViewFilter filter : newFilters) {
        m_filterMap.put(filter.getId(), filter);
        final CmsDataViewFilter finalFilter = filter;
        ComboBox select = new ComboBox(filter.getNiceName());
        select.setWidth("175px");
        select.setNullSelectionAllowed(false);
        select.setPageLength(0);
        Map<String, String> options = filter.getOptions();
        for (Map.Entry<String, String> entry : options.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            select.addItem(key);
            select.setItemCaption(key, value);
        }
        select.setValue(filter.getValue());
        if (filter.getHelpText() != null) {
            select.setDescription(filter.getHelpText());
        }
        select.addValueChangeListener(new ValueChangeListener() {

            private static final long serialVersionUID = 1L;

            public void valueChange(ValueChangeEvent event) {
                String newValue = (String) (event.getProperty().getValue());
                updateFilter(finalFilter.getId(), newValue);
            }
        });
        m_filterContainer.addComponent(select);
    }
}
Also used : ValueChangeEvent(com.vaadin.v7.data.Property.ValueChangeEvent) ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener) ComboBox(com.vaadin.v7.ui.ComboBox) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CmsDataViewFilter(org.opencms.widgets.dataview.CmsDataViewFilter)

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