Search in sources :

Example 1 with NewItemHandler

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

the class CmsFileHistoryPanel method setupVersionsToKeepComboBox.

/**
 * Sets up the combo box for the amount of versions to keep.<p>
 */
private void setupVersionsToKeepComboBox() {
    final List<Integer> items = new ArrayList<Integer>();
    // Add default values to ComboBox
    for (int i = 0; i < 10; i++) {
        m_numberVersionsToKeep.addItem(new Integer(i));
        items.add(new Integer(i));
    }
    for (int i = 10; i <= VERSIONS_MAX; i += 5) {
        m_numberVersionsToKeep.addItem(new Integer(i));
        items.add(new Integer(i));
    }
    m_numberVersionsToKeep.setPageLength(m_numberVersionsToKeep.size());
    m_numberVersionsToKeep.setNullSelectionAllowed(false);
    m_numberVersionsToKeep.setTextInputAllowed(true);
    // Alow user to enter other values
    m_numberVersionsToKeep.setNewItemsAllowed(true);
    m_numberVersionsToKeep.setNewItemHandler(new NewItemHandler() {

        private static final long serialVersionUID = -1962380117946789444L;

        public void addNewItem(String newItemCaption) {
            int num = CmsStringUtil.getIntValue(newItemCaption, -1, "user entered version number is not a number");
            if ((num > 1) && !items.contains(new Integer(num))) {
                m_numberVersionsToKeep.addItem(new Integer(num));
                m_numberVersionsToKeep.select(new Integer(num));
            }
        }
    });
    // Select the value which correspons to current history setting.
    int numberHistoryVersions = OpenCms.getSystemInfo().getHistoryVersions();
    if (numberHistoryVersions == CmsFileHistoryApp.NUMBER_VERSIONS_DISABLED) {
        numberHistoryVersions = 0;
    }
    if (numberHistoryVersions == CmsFileHistoryApp.NUMBER_VERSIONS_UNLIMITED) {
        numberHistoryVersions = VERSIONS_MAX;
    }
    m_numberVersionsToKeep.select(new Integer(numberHistoryVersions));
}
Also used : ArrayList(java.util.ArrayList) NewItemHandler(com.vaadin.v7.ui.AbstractSelect.NewItemHandler)

Example 2 with NewItemHandler

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

the class DateTimeField method initContent.

@Override
protected Component initContent() {
    HorizontalLayout layout = new HorizontalLayout();
    layout.setSpacing(true);
    layout.setWidth(100, Unit.PERCENTAGE);
    dateField = new PopupDateField();
    dateField.setId(this.getId() + "_" + "date");
    dateField.setWidth(100, Unit.PERCENTAGE);
    dateField.setDateFormat(DateFormatHelper.getDateFormatPattern());
    dateField.setLenient(true);
    dateField.setInputPrompt(inputPrompt);
    layout.addComponent(dateField);
    layout.setExpandRatio(dateField, 0.5f);
    if (!converterSet) {
        dateField.setConverter(converter);
        converterSet = true;
    }
    timeField = ComboBoxHelper.createComboBoxV7();
    timeField.setId(this.getId() + "_" + "time");
    timeField.addContainerProperty(CAPTION_PROPERTY_ID, String.class, null);
    timeField.setItemCaptionPropertyId(CAPTION_PROPERTY_ID);
    // fill
    for (int hours = 0; hours <= 23; hours++) {
        for (int minutes = 0; minutes <= 59; minutes += 15) {
            ensureTimeEntry(hours, minutes);
        }
    }
    timeField.setNewItemsAllowed(true);
    timeField.setNewItemHandler(new NewItemHandler() {

        @Override
        public void addNewItem(String newItemCaption) {
            Date date = DateHelper.parseTime(newItemCaption);
            timeField.setValue(ensureTimeEntry(date));
        }
    });
    timeField.setWidth(100, Unit.PERCENTAGE);
    layout.addComponent(timeField);
    layout.setExpandRatio(timeField, 0.5f);
    // value can't be set on readOnly fields
    dateField.setReadOnly(false);
    timeField.setReadOnly(false);
    // set field values based on internal value
    setInternalValue(super.getInternalValue());
    dateField.setReadOnly(isReadOnly());
    timeField.setReadOnly(isReadOnly());
    Property.ValueChangeListener validationValueChangeListener = new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            markAsDirty();
            fireValueChange(false);
        }
    };
    dateField.addValueChangeListener(validationValueChangeListener);
    timeField.addValueChangeListener(validationValueChangeListener);
    return layout;
}
Also used : PopupDateField(com.vaadin.v7.ui.PopupDateField) NewItemHandler(com.vaadin.v7.ui.AbstractSelect.NewItemHandler) Property(com.vaadin.v7.data.Property) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 3 with NewItemHandler

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

the class CmsWorkplaceServerWidget method setUpWorkplaceComboBox.

/**
 * Sets the combo box for workplace.<p>
 *
 * @param allSites alls available sites
 * @param combo combo box to fill
 * @param nullselect if true, nothing is selected
 * @param defaultValue if set, this value gets chosen
 * @param sslMode CmsSSLMode
 * @return BeanItemContainer
 */
private static BeanItemContainer<CmsSite> setUpWorkplaceComboBox(List<CmsSite> allSites, final ComboBox combo, boolean nullselect, String defaultValue, CmsSSLMode sslMode) {
    final List<CmsSite> modSites = new ArrayList<CmsSite>();
    CmsSite siteWithDefaultURL = null;
    String defaultURL = defaultValue;
    for (CmsSite site : allSites) {
        CmsSite si = new CmsSite("dummy", site.getUrl());
        si.setSSLMode(site.getSSLMode());
        modSites.add(si);
        if (defaultValue != null) {
            if (defaultURL.equals(si.getUrl())) {
                // SSL sensitive ('http'!='https')
                siteWithDefaultURL = si;
            }
        }
    }
    if (defaultValue != null) {
        if (siteWithDefaultURL == null) {
            siteWithDefaultURL = new CmsSite("dummy", defaultURL);
            siteWithDefaultURL.setSSLMode(sslMode);
            modSites.add(0, siteWithDefaultURL);
        }
    }
    final BeanItemContainer<CmsSite> objects = new BeanItemContainer<CmsSite>(CmsSite.class, modSites);
    combo.setContainerDataSource(objects);
    combo.setNullSelectionAllowed(nullselect);
    combo.setItemCaptionPropertyId("url");
    combo.setValue(siteWithDefaultURL);
    combo.setNewItemsAllowed(true);
    combo.setImmediate(true);
    combo.setNewItemHandler(new NewItemHandler() {

        private static final long serialVersionUID = -4760590374697520609L;

        public void addNewItem(String newItemCaption) {
            CmsSite newItem = new CmsSite("dummy", newItemCaption);
            newItem.setSSLMode(newItemCaption.contains("https:") ? CmsSSLMode.MANUAL : CmsSSLMode.NO);
            objects.addBean(newItem);
            combo.select(newItem);
        }
    });
    return objects;
}
Also used : ArrayList(java.util.ArrayList) BeanItemContainer(com.vaadin.v7.data.util.BeanItemContainer) CmsSite(org.opencms.site.CmsSite) NewItemHandler(com.vaadin.v7.ui.AbstractSelect.NewItemHandler)

Aggregations

NewItemHandler (com.vaadin.v7.ui.AbstractSelect.NewItemHandler)3 ArrayList (java.util.ArrayList)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Property (com.vaadin.v7.data.Property)1 BeanItemContainer (com.vaadin.v7.data.util.BeanItemContainer)1 PopupDateField (com.vaadin.v7.ui.PopupDateField)1 Date (java.util.Date)1 LocalDate (org.joda.time.LocalDate)1 CmsSite (org.opencms.site.CmsSite)1