001package gwt.material.design.client.ui;
002
003/*
004 * #%L
005 * GwtMaterial
006 * %%
007 * Copyright (C) 2015 GwtMaterialDesign
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 * 
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 * 
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import gwt.material.design.client.base.HasColors;
024import gwt.material.design.client.base.HasGrid;
025import gwt.material.design.client.base.HasId;
026import gwt.material.design.client.base.HasPlaceholder;
027import gwt.material.design.client.base.MaterialWidget;
028import gwt.material.design.client.base.mixin.ToggleStyleMixin;
029import gwt.material.design.client.ui.html.Label;
030import gwt.material.design.client.ui.html.Option;
031
032import java.util.LinkedList;
033import java.util.List;
034
035import com.google.gwt.dom.client.Document;
036import com.google.gwt.dom.client.Element;
037import com.google.gwt.dom.client.OptionElement;
038import com.google.gwt.dom.client.SelectElement;
039import com.google.gwt.event.logical.shared.HasValueChangeHandlers;
040import com.google.gwt.event.logical.shared.ValueChangeEvent;
041import com.google.gwt.event.logical.shared.ValueChangeHandler;
042import com.google.gwt.event.shared.HandlerRegistration;
043import com.google.gwt.i18n.client.HasDirection.Direction;
044import com.google.gwt.user.client.ui.FormPanel;
045import com.google.gwt.user.client.ui.ListBox;
046
047//@formatter:off
048
049/**
050 * <p>Material ListBox is another dropdown component that will set / get the value depends on the selected index
051 * <h3>UiBinder Usage:</h3>
052 *
053 * <pre>
054 * {@code
055 *    <m:MaterialListBox ui:field="lstBox" />
056 * }
057 * </pre>
058 * <h3>Java Usage:</h3>
059 *
060 * <pre>
061 * {@code
062 *     // functions
063 *    lstBox.setSelectedIndex(2);
064 *    lstBox.getSelectedIndex();
065 *    lstBox.addValueChangeHandler(handler);
066 * }
067 * </pre>
068 * </p>
069 *
070 * @author kevzlou7979
071 * @author Ben Dol
072 * @see <a href="http://gwt-material-demo.herokuapp.com/#forms">Material ListBox</a>
073 */
074//@formatter:on
075public class MaterialListBox extends MaterialListValueBox<String> implements HasId, HasGrid, HasColors, HasPlaceholder {
076
077    public MaterialListBox() {
078        super();
079    }
080
081    public void add(Option option) {
082        getSelectElement().add(OptionElement.as(option.getElement()), null);
083        values.add(option.getValue());
084    }
085}