001    package org.gwtbootstrap3.client.ui.html;
002    
003    /*
004     * #%L
005     * GwtBootstrap3
006     * %%
007     * Copyright (C) 2013 GwtBootstrap3
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    
023    import org.gwtbootstrap3.client.ui.ListItem;
024    import org.gwtbootstrap3.client.ui.base.ComplexWidget;
025    import org.gwtbootstrap3.client.ui.base.helper.StyleHelper;
026    import org.gwtbootstrap3.client.ui.constants.Styles;
027    
028    import com.google.gwt.dom.client.Document;
029    
030    /**
031     * Widget representing an Unordered List
032     * <p/>
033     * ** Children must be of type ListItem
034     * <p/>
035     * <p/>
036     * <h3>UiBinder example</h3>
037     * <p/>
038     * <pre>
039     * {@code
040     * <b:UnorderedList>
041     *    ... [ListItems]
042     * </b:UnorderedList>
043     * }
044     * </pre>
045     *
046     * @author Joshua Godi
047     * @see org.gwtbootstrap3.client.ui.ListItem
048     */
049    public class UnorderedList extends ComplexWidget {
050    
051        /**
052         * Creates an empty list.
053         */
054        public UnorderedList() {
055            setElement(Document.get().createULElement());
056        }
057    
058        /**
059         * Creates a list and adds the given widgets.
060         *
061         * @param widgets widgets to be added
062         */
063        public UnorderedList(final ListItem... widgets) {
064            this();
065    
066            // Add all the list items to the widget
067            for (final ListItem li : widgets) {
068                add(li);
069            }
070        }
071    
072        /**
073         * Sets the UnorderedList to be unstyled
074         *
075         * @param unstyled boolean true/false to make unstyled
076         */
077        public void setUnstyled(final boolean unstyled) {
078            setStyleName(Styles.UNSTYLED, unstyled);
079        }
080    
081        /**
082         * Returns a boolean of whether or not the UnorderedList is unstyled
083         *
084         * @return true/false for unstyled or not
085         */
086        public boolean isUnstyled() {
087            return StyleHelper.containsStyle(Styles.UNSTYLED, getStyleName());
088        }
089    
090        /**
091         * Sets the UnorderedList to appear inline rather then stacked
092         *
093         * @param inline true/false for inline or not
094         */
095        public void setInline(final boolean inline) {
096            StyleHelper.toggleStyleName(this, inline, Styles.LIST_INLINE);
097        }
098    
099        /**
100         * Returns a boolean of whether or not the UnorderedList in inline
101         *
102         * @return true/false for inline or not
103         */
104        public boolean isInline() {
105            return StyleHelper.containsStyle(Styles.LIST_INLINE, getStyleName());
106        }
107    }