001/*
002 *  Copyright 2012 GWT-Bootstrap
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package com.github.gwtbootstrap.client.ui.incubator;
017
018import com.github.gwtbootstrap.client.ui.base.ComplexWidget;
019import com.github.gwtbootstrap.client.ui.constants.Constants;
020import com.google.gwt.user.client.ui.Widget;
021
022//@formatter:off
023/**
024 * Wrapper for an HTML Table.
025 *
026 * <p>Table Usage:</p>
027 * <pre>
028 * {@code
029 * <b:Table>
030 *     <b:TableHeader>Name</b:TableHeader>
031 *     <b:TableHeader>Surname</b:TableHeader>
032 *     <tr>
033 *         <td>John</td>
034 *         <td>Smith</td>
035 *     </tr>
036 * </b:Table>
037 * }
038 * </pre>
039 *
040 * @since 2.0.4.0
041 * 
042 * @author Dominik Mayer
043 * 
044 * @see <a href="http://twitter.github.com/bootstrap/base-css.html#tables">Bootstrap documentation</a>
045 */
046//@formatter:on
047public class Table extends ComplexWidget {
048
049        private Header header = new Header();
050
051        public Table() {
052                super("table");
053                super.add(header);
054                setStylePrimaryName(Constants.TABLE);
055        }
056
057        /**
058         * Prints the rows in two different colors. Does not work in IE7 - IE8.
059         * 
060         * @param striped
061         */
062        public void setStriped(boolean striped) {
063                setStyleDependentName(Constants.STRIPED, striped);
064        }
065
066    public void setBordered(boolean bordered) {
067        setStyleDependentName(Constants.BORDERED, bordered);
068    }
069
070    public void setCondensed(boolean condensed) {
071        setStyleDependentName(Constants.CONDENSED, condensed);
072    }
073
074    public void setHover(boolean hover) {
075        setStyleDependentName(Constants.HOVER, hover);
076    }
077
078        @Override
079        public void add(Widget w) {
080                if (w instanceof TableHeader)
081                        header.add(w);
082                else
083                        super.add(w);
084        }
085
086        private class Header extends ComplexWidget {
087
088                public Header() {
089                        super("thead");
090                }
091        }
092}