Example usage for com.vaadin.ui Slider getMin

List of usage examples for com.vaadin.ui Slider getMin

Introduction

In this page you can find the example usage for com.vaadin.ui Slider getMin.

Prototype

public double getMin() 

Source Link

Document

Gets the minimum slider value.

Usage

From source file:org.metawidget.vaadin.ui.widgetbuilder.VaadinWidgetBuilder.java

License:LGPL

public Component buildWidget(String elementName, Map<String, String> attributes, VaadinMetawidget metawidget) {

    // Hidden/* www  .ja v a  2s  .  c  o  m*/

    if (TRUE.equals(attributes.get(HIDDEN))) {
        return new Stub();
    }

    // Action

    if (ACTION.equals(elementName)) {
        return new Button();
    }

    // Lookup the Class

    Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, String.class);

    // Support mandatory Booleans (can be rendered as a checkbox, even
    // though they have a Lookup)

    if (Boolean.class.equals(clazz) && TRUE.equals(attributes.get(REQUIRED))) {
        return new CheckBox();
    }

    // Lookups

    String lookup = attributes.get(LOOKUP);

    if (lookup != null && !"".equals(lookup)) {
        return createSelectComponent(attributes, lookup, metawidget);
    }

    if (clazz != null) {

        // Primitives

        if (clazz.isPrimitive()) {
            // booleans

            if (boolean.class.equals(clazz)) {
                return new CheckBox();
            }

            // chars

            if (char.class.equals(clazz)) {
                TextField textField = new TextField();
                textField.setMaxLength(1);

                return textField;
            }

            // Ranged

            String minimumValue = attributes.get(MINIMUM_VALUE);
            String maximumValue = attributes.get(MAXIMUM_VALUE);

            if (minimumValue != null && !"".equals(minimumValue) && maximumValue != null
                    && !"".equals(maximumValue)) {
                Slider slider = new Slider();
                slider.setMin(Double.parseDouble(minimumValue));
                try {
                    // Use big 'D' Double for Vaadin 6/7 compatibility
                    slider.setValue(Double.valueOf(slider.getMin()));
                } catch (ValueOutOfBoundsException e) {
                    throw WidgetBuilderException.newException(e);
                }
                slider.setMax(Double.parseDouble(maximumValue));

                return slider;
            }

            // Not-ranged

            return createTextField(attributes);
        }

        // Strings

        if (String.class.equals(clazz)) {
            if (TRUE.equals(attributes.get(MASKED))) {
                return new PasswordField();
            }

            if (TRUE.equals(attributes.get(LARGE))) {
                return new TextArea();
            }

            return createTextField(attributes);
        }

        // Characters

        if (Character.class.isAssignableFrom(clazz)) {
            TextField textField = new TextField();
            textField.setMaxLength(1);

            return textField;
        }

        // Dates

        if (Date.class.equals(clazz)) {
            return new PopupDateField();
        }

        // Numbers
        //
        // Note: we use a text field, not a JSpinner or JSlider, because
        // BeansBinding gets upset at doing 'setValue( null )' if the Integer
        // is null. We can still use JSpinner/JSliders for primitives, though.

        if (Number.class.isAssignableFrom(clazz)) {
            return createTextField(attributes);
        }

        // Collections

        if (Collection.class.isAssignableFrom(clazz)) {
            return new Stub();
        }
    }

    // Not simple, but don't expand

    if (TRUE.equals(attributes.get(DONT_EXPAND))) {
        return createTextField(attributes);
    }

    return null;
}