Package com.vaadin.ui

Examples of com.vaadin.ui.NativeSelect


            LinkedHashMap<String, TYPE> options, String initialValue,
            final Command<T, TYPE> command) {
        final String CAPTION = "caption";
        final String VALUE = "value";

        final NativeSelect select = new NativeSelect(caption);
        select.addContainerProperty(CAPTION, String.class, "");
        select.addContainerProperty(VALUE, Object.class, "");
        select.setItemCaptionPropertyId(CAPTION);
        select.setNullSelectionAllowed(false);
        select.addListener(new Property.ValueChangeListener() {

            @Override
            public void valueChange(ValueChangeEvent event) {
                Object itemId = event.getProperty().getValue();
                Item item = select.getItem(itemId);
                @SuppressWarnings("unchecked")
                TYPE value = (TYPE) item.getItemProperty(VALUE).getValue();
                doCommand(command, value);

            }
        });

        for (String itemCaption : options.keySet()) {
            Object itemId = new Object();
            Item i = select.addItem(itemId);
            i.getItemProperty(CAPTION).setValue(itemCaption);
            i.getItemProperty(VALUE).setValue(options.get(itemCaption));
            if (itemCaption.equals(initialValue)) {
                select.setValue(itemId);
            }

        }

        select.setId("selectaction-" + caption);

        select.setImmediate(true);

        return select;
    }
View Full Code Here


                return;
            }
            @SuppressWarnings("unused")
            final Layout.AlignmentHandler ah = (AlignmentHandler) testedLayout;

            final NativeSelect vAlign = new NativeSelect();
            final NativeSelect hAlign = new NativeSelect();
            controls.addComponent(new Label("component alignment"));
            controls.addComponent(hAlign);
            controls.addComponent(vAlign);
            hAlign.setNullSelectionAllowed(false);
            vAlign.setNullSelectionAllowed(false);

            vAlign.addItem(new Integer(Bits.ALIGNMENT_TOP));
            vAlign.setItemCaption(new Integer(Bits.ALIGNMENT_TOP), "top");
            vAlign.addItem(new Integer(Bits.ALIGNMENT_VERTICAL_CENTER));
            vAlign.setItemCaption(new Integer(Bits.ALIGNMENT_VERTICAL_CENTER),
                    "center");
            vAlign.addItem(new Integer(Bits.ALIGNMENT_BOTTOM));
            vAlign.setItemCaption(new Integer(Bits.ALIGNMENT_BOTTOM), "bottom");

            hAlign.addItem(new Integer(Bits.ALIGNMENT_LEFT));
            hAlign.setItemCaption(new Integer(Bits.ALIGNMENT_LEFT), "left");
            hAlign.addItem(new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER));
            hAlign.setItemCaption(
                    new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER), "center");
            hAlign.addItem(new Integer(Bits.ALIGNMENT_RIGHT));
            hAlign.setItemCaption(new Integer(Bits.ALIGNMENT_RIGHT), "right");

            Property.ValueChangeListener alignmentChangeListener = new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    Integer h = ((Integer) hAlign.getValue()).intValue();
                    int v = ((Integer) vAlign.getValue()).intValue();

                    updateAlignments(new Alignment(h + v));
                }

            };

            hAlign.setValue(new Integer(Bits.ALIGNMENT_LEFT));
            vAlign.addListener(alignmentChangeListener);
            hAlign.addListener(alignmentChangeListener);
            vAlign.setValue(new Integer(Bits.ALIGNMENT_TOP));

            controls.addComponent(new Label("layout alignment"));
            final NativeSelect lAlign = new NativeSelect();
            controls.addComponent(lAlign);
            lAlign.setNullSelectionAllowed(false);
            lAlign.addItem(new Integer(Bits.ALIGNMENT_LEFT));
            lAlign.setItemCaption(new Integer(Bits.ALIGNMENT_LEFT), "left");
            lAlign.addItem(new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER));
            lAlign.setItemCaption(
                    new Integer(Bits.ALIGNMENT_HORIZONTAL_CENTER), "center");
            lAlign.addItem(new Integer(Bits.ALIGNMENT_RIGHT));
            lAlign.setItemCaption(new Integer(Bits.ALIGNMENT_RIGHT), "right");

            lAlign.addListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(ValueChangeEvent event) {
                    testPanelLayout.setComponentAlignment(
                            testedLayout,
                            new Alignment(((Integer) lAlign.getValue())
                                    .intValue() + Bits.ALIGNMENT_TOP));
                }
            });
        }
View Full Code Here

        final DateField df = new DateField(null, calendar.getTime());
        df.setResolution(Resolution.SECOND);
        df.setImmediate(true);
        hl.addComponent(df);

        NativeSelect resolution = new NativeSelect(null,
                Arrays.asList(Resolution.values()));
        resolution.setImmediate(true);
        resolution.setValue(df.getResolution());
        hl.addComponent(resolution);
        resolution.addValueChangeListener(new ValueChangeListener() {

            @Override
            public void valueChange(ValueChangeEvent event) {
                df.setResolution((Resolution) event.getProperty().getValue());
            }
View Full Code Here

        return l;
    }

    private Component createLayoutSelect() {
        layoutSelect = new NativeSelect("Layout");
        layoutSelect.addContainerProperty(CAPTION, String.class, "");
        layoutSelect.addContainerProperty(CLASS, Class.class, "");
        layoutSelect.addContainerProperty(WIDTH, String.class, "");
        layoutSelect.setItemCaptionPropertyId(CAPTION);
        layoutSelect.setNullSelectionAllowed(false);
View Full Code Here

        listing.addContainerProperty("Time", String.class, "0:00");
        listing.addContainerProperty("Artist", String.class, "");
        listing.addContainerProperty("Album", String.class, "");
        listing.addContainerProperty("Genre", String.class, "");
        listing.addContainerProperty("Rating", NativeSelect.class,
                new NativeSelect());

        // Lets populate the table with random data
        String[] tracks = new String[] { "Red Flag", "Millstone",
                "Not The Sun", "Breath", "Here We Are", "Deep Heaven",
                "Her Voice Resides", "Natural Tan", "End It All", "Kings",
                "Daylight Slaving", "Mad Man", "Resolve", "Teargas",
                "African Air", "Passing Bird" };
        String[] times = new String[] { "4:12", "6:03", "5:43", "4:32", "3:42",
                "4:45", "2:56", "9:34", "2:10", "3:44", "5:49", "6:30", "5:18",
                "7:42", "3:13", "2:52" };
        String[] artists = new String[] { "Billy Talent", "Brand New",
                "Breaking Benjamin", "Becoming The Archetype",
                "Bullet For My Valentine", "Chasing Victory", "Chimaira",
                "Danko Jones", "Deadlock", "Deftones", "From Autumn To Ashes",
                "Haste The Day", "Four Year Strong", "In Flames", "Kemopetrol",
                "John Legend" };
        String[] albums = new String[] { "Once Again", "The Caitiff Choir",
                "The Devil And God", "Light Grenades", "Dicthonomy",
                "Back In Black", "Dreamer", "Come Clarity", "Year Zero",
                "Frames", "Fortress", "Phobia", "The Poison", "Manifesto",
                "White Pony", "The Big Dirty" };
        String[] genres = new String[] { "Rock", "Metal", "Hardcore", "Indie",
                "Pop", "Alternative", "Blues", "Jazz", "Hip Hop",
                "Electronica", "Punk", "Hard Rock", "Dance", "R'n'B", "Gospel",
                "Country" };
        for (int i = 0; i < 1000; i++) {
            NativeSelect s = new NativeSelect();
            s.addItem("1 star");
            s.addItem("2 stars");
            s.addItem("3 stars");
            s.addItem("4 stars");
            s.addItem("5 stars");
            s.select(i % 5 + " stars");
            final int index = i % 16;
            listing.addItem(new Object[] { tracks[index], times[index],
                    artists[index], albums[index], genres[index], s }, i);
        }
View Full Code Here

                    final Window chooser = new Window("Choose component",
                            layout);
                    layout.setSizeUndefined();
                    chooser.setModal(true);

                    NativeSelect select = new NativeSelect(
                            "Choose component to edit");

                    select.setNullSelectionAllowed(false);

                    IndexedContainer container = new IndexedContainer();
                    container.addContainerProperty("caption", String.class, "");
                    Iterator<Component> componentIterator = l
                            .getComponentIterator();
                    while (componentIterator.hasNext()) {
                        AbstractComponent next = (AbstractComponent) componentIterator
                                .next();
                        Item item = container.addItem(next);

                        String caption = next.getClass().getSimpleName();

                        caption += "; cap: " + next.getCaption() + "; debugid"
                                + getId();

                        if (next instanceof Property) {
                            caption += " value:"
                                    + ((Property<?>) next).getValue();
                        }

                        item.getItemProperty("caption").setValue(caption);
                    }
                    select.setContainerDataSource(container);
                    select.setItemCaptionPropertyId("caption");
                    select.setImmediate(true);

                    select.addListener(new ValueChangeListener() {
                        @Override
                        public void valueChange(ValueChangeEvent event) {
                            editcomponent((Component) event.getProperty()
                                    .getValue());
                            getMainWindow().removeWindow(chooser);
                        }

                    });

                    layout.addComponent(select);

                    getMainWindow().addWindow(chooser);

                }
            });

            addComponent(componentChooser);

            Button addComp = new Button("add component");
            addComp.addListener(new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    VerticalLayout layout = new VerticalLayout();
                    layout.setMargin(true);
                    final Window chooser = new Window(
                            "Choose component type to add", layout);
                    layout.setSizeUndefined();
                    chooser.setModal(true);

                    NativeSelect select = new NativeSelect(
                            "Choose component to edit");

                    select.setNullSelectionAllowed(false);

                    IndexedContainer container = new IndexedContainer();

                    URL resource = AbstractComponent.class.getResource(".");
                    File directory = new File(resource.getFile());
                    if (directory.exists()) {
                        // Get the list of the files contained in the
                        // package
                        final String[] files = directory.list();
                        for (int j = 0; j < files.length; j++) {
                            // we are only interested in .class files
                            if (files[j].endsWith(".class")) {
                                // removes the .class extension
                                String p = resource.toString()
                                        + files[j].substring(0,
                                                files[j].length() - 6);
                                p = p.replaceAll(".*classes/", "");
                                p = p.replaceAll("/", ".");
                                Class<?> c;
                                try {
                                    c = Class.forName(p);
                                    if (AbstractComponent.class
                                            .isAssignableFrom(c)
                                            && !p.toLowerCase().contains(
                                                    "layout")
                                            && !p.toLowerCase().contains(
                                                    "abstract")) {
                                        container.addItem(c);
                                    }
                                } catch (ClassNotFoundException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                    select.setContainerDataSource(container);
                    select.setImmediate(true);

                    select.addListener(new ValueChangeListener() {
                        @Override
                        public void valueChange(ValueChangeEvent event) {
                            Class<?> c = (Class<?>) event.getProperty()
                                    .getValue();

View Full Code Here

        layout.addComponent(new Label("Layout"));

        ArrayList<String> sizes = new ArrayList<String>();
        sizes.addAll(Arrays.asList("100px", "30em", "100%"));

        final NativeSelect width = new NativeSelect(null, sizes);
        width.setImmediate(true);
        width.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (width.getValue() != null) {
                    l.setWidth(width.getValue().toString());
                } else {
                    l.setWidth(null);
                }
            }
        });
        layout.addComponent(width);
        layout.addComponent(new Label("&times;", ContentMode.HTML));
        final NativeSelect height = new NativeSelect(null, sizes);
        height.setImmediate(true);
        height.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (height.getValue() != null) {
                    l.setHeight(height.getValue().toString());
                } else {
                    l.setHeight(null);
                }
            }
        });
        layout.addComponent(height);

        final CheckBox margin = new CheckBox("Margin", false);
        margin.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                l.setMargin(margin.getValue().booleanValue());
            }
        });
        margin.setImmediate(true);
        layout.addComponent(margin);
        layout.addComponent(margin);

        final CheckBox spacing = new CheckBox("Spacing", false);
        spacing.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                l.setSpacing(spacing.getValue().booleanValue());
            }
        });
        spacing.setImmediate(true);
        layout.addComponent(spacing);

        // Cell controls
        HorizontalLayout cell = new HorizontalLayout();
        cell.addStyleName("fieldset");
        cell.setSpacing(true);
        controls.addComponent(cell);
        cell.addComponent(new Label("Cell"));

        ArrayList<Alignment> alignments = new ArrayList<Alignment>();
        alignments.addAll(Arrays.asList(Alignment.TOP_LEFT,
                Alignment.MIDDLE_LEFT, Alignment.BOTTOM_LEFT,
                Alignment.TOP_CENTER, Alignment.MIDDLE_CENTER,
                Alignment.BOTTOM_CENTER, Alignment.TOP_RIGHT,
                Alignment.MIDDLE_RIGHT, Alignment.BOTTOM_RIGHT));

        align = new NativeSelect(null, alignments);
        for (Alignment a : alignments) {
            align.setItemCaption(a,
                    a.getVerticalAlignment() + "-" + a.getHorizontalAlignment());
        }
        align.setImmediate(true);
        align.setEnabled(false);
        align.setNullSelectionAllowed(false);
        align.select(Alignment.TOP_LEFT);
        align.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (target == null) {
                    return;
                }
                l.setComponentAlignment(target, ((Alignment) align.getValue()));
            }
        });
        cell.addComponent(align);

        expand = new CheckBox("Expand");
        expand.setImmediate(true);
        expand.setEnabled(false);
        expand.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (target != null) {
                    l.setExpandRatio(target, expand.getValue() ? 1 : 0);
                }
            }
        });
        cell.addComponent(expand);

        // Component controls
        HorizontalLayout component = new HorizontalLayout();
        component.addStyleName("fieldset");
        component.setSpacing(true);
        root.addComponent(component);
        component.addComponent(new Label("Component"));

        sizes = new ArrayList<String>();
        sizes.addAll(Arrays.asList("50px", "200px", "10em", "50%", "100%"));

        componentWidth = new NativeSelect(null, sizes);
        componentWidth.setImmediate(true);
        componentWidth.setEnabled(false);
        componentWidth.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (target == null) {
                    return;
                }
                if (componentWidth.getValue() != null) {
                    target.setWidth(componentWidth.getValue().toString());
                } else {
                    target.setWidth(null);
                }
            }
        });
        component.addComponent(componentWidth);
        component.addComponent(new Label("&times;", ContentMode.HTML));

        componentHeight = new NativeSelect(null, sizes);
        componentHeight.setImmediate(true);
        componentHeight.setEnabled(false);
        componentHeight.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (componentHeight.getValue() != null) {
                    target.setHeight(componentHeight.getValue().toString());
                } else {
                    target.setHeight(null);
                }
            }
        });
        component.addComponent(componentHeight);

        componentCaption = new NativeSelect("Caption", Arrays.asList("Short",
                "Slightly Longer Caption"));
        componentCaption.setImmediate(true);
        componentCaption.setEnabled(false);
        componentCaption.addListener(new ValueChangeListener() {
            @Override
            public void valueChange(ValueChangeEvent event) {
                if (componentCaption.getValue() != null) {
                    target.setCaption(componentCaption.getValue().toString());
                } else {
                    target.setCaption(null);
                }
            }
        });
        component.addComponent(componentCaption);

        componentIcon = new NativeSelect("Icon", Arrays.asList(
                "../runo/icons/16/folder.png", "../runo/icons/32/document.png"));
        componentIcon.setImmediate(true);
        componentIcon.setEnabled(false);
        componentIcon.addListener(new ValueChangeListener() {
            @Override
View Full Code Here

        label = new Label(
                "<em>Hint</em>. Use debug dialog to measure rendering times TODO: extend with size settings (to both layout and content).",
                ContentMode.HTML);
        getLayout().addComponent(label);

        ns = new NativeSelect("Select component to test");
        ns.addItem(CssLayout.class);
        ns.addItem(GridLayout.class);
        ns.addItem(VerticalLayout.class);
        ns.setNullSelectionAllowed(false);
        ns.setValue(CssLayout.class);

        ns2 = new NativeSelect("Select component to render inside layout.");
        ns2.addItem(Label.class);
        ns2.addItem(Button.class);
        ns2.setNullSelectionAllowed(false);
        ns2.setValue(Label.class);
View Full Code Here

        hl.setSpacing(true);
        hl.setMargin(new MarginInfo(true, false, false, false));
        l.addComponent(hl);

        AbstractSelect cb = new ComboBox();
        AbstractSelect nat = new NativeSelect();
        AbstractSelect list = new ListSelect();
        AbstractSelect twincol = new TwinColSelect();

        for (int i = 0; i < 50; i++) {
            cb.addItem("Item " + i);
            nat.addItem("Item " + i);
            list.addItem("Item " + i);
            twincol.addItem("Item " + i);
        }

        hl.addComponent(cb);
View Full Code Here

    @Override
    protected void setup() {
        tf = new TextArea("Text", "Hello world");
        tf.setRows(10);
        addComponent(tf);
        type = new NativeSelect();
        type.setNullSelectionAllowed(false);
        type.addContainerProperty(CAPTION, String.class, "");
        type.setItemCaptionPropertyId(CAPTION);
        type.addItem(Notification.TYPE_HUMANIZED_MESSAGE)
                .getItemProperty(CAPTION).setValue("Humanized");
View Full Code Here

TOP

Related Classes of com.vaadin.ui.NativeSelect

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.