001 /*
002 * Copyright 2006 Mat Gessel <mat.gessel@gmail.com>
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * 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, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 */
016 package asquare.gwt.tk.client.ui;
017
018 import asquare.gwt.tk.client.util.GwtUtil;
019
020 import com.google.gwt.user.client.DOM;
021 import com.google.gwt.user.client.Element;
022 import com.google.gwt.user.client.ui.Widget;
023
024 /**
025 * A table-based panel which stacks cells vertically in rows and permits
026 * multiple widgets per cell. Empty cells are supported.
027 * {@link #add(Widget) add(Widget)},
028 * {@link #insert(Widget, int) insert(Widget, int)} and
029 * {@link #remove(Widget) remove(Widget)} behave the same as in
030 * {@link com.google.gwt.user.client.ui.VerticalPanel VerticalPanel}. That is,
031 * the table cell and the widget are treated as one. Other methods have options
032 * for cell addition, insertion and deletion.
033 * </p>
034 */
035 public class RowPanel extends ExposedCellPanel
036 {
037 /*
038 * (non-Javadoc)
039 * @see asquare.gwt.tk.client.ui.ExposedCellPanel#insertCellStructure(int)
040 */
041 protected void insertCellStructure(int cellIndex)
042 {
043 Element tr = DOM.createTR();
044 DOM.insertChild(getBody(), tr, cellIndex);
045 Element td = DOM.createTD();
046 DOM.appendChild(tr, td);
047 }
048
049 /*
050 * (non-Javadoc)
051 * @see asquare.gwt.tk.client.ui.ExposedCellPanel#removeCellStructure(int)
052 */
053 protected void removeCellStructure(int cellIndex)
054 {
055 Element tr = DOM.getChild(getBody(), cellIndex);
056 Element td = getCellElement(cellIndex);
057 DOM.removeChild(tr, td);
058 DOM.removeChild(getBody(), tr);
059 }
060
061 /*
062 * (non-Javadoc)
063 * @see asquare.gwt.tk.client.ui.ExposedCellPanel#getCellElement(int)
064 */
065 public Element getCellElement(int cellIndex)
066 {
067 GwtUtil.rangeCheck(0, getCellCount(), cellIndex, false);
068
069 Element tr = DOM.getChild(getBody(), cellIndex);
070 Element td = DOM.getFirstChild(tr);
071 return td;
072 }
073 }