View Javadoc

1   /*
2    * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.gwtwidgets.client.temp;
17  
18  import com.google.gwt.user.client.ui.FlexTable;
19  import com.google.gwt.user.client.ui.Widget;
20  
21  /***
22   * Fix for removeRow(0 bug.
23   * See http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/78104bd661bebedd
24   * for a full explaination.
25   * 
26   * @author Iancu Mihai (iancu.mihai@gmail.com) 
27   */
28  class TFlexTable extends FlexTable
29  {
30      public void removeRow (int row)
31      {
32          int total = this.getRowCount();
33          int rowsBellow = total - row - 1;
34          Widget[][] toMove = new Widget[rowsBellow][];
35          //store old widgets
36          for (int i = row + 1; i < total; i++) {
37              int rCols = this.getCellCount(i);
38              Widget[] wRow = new Widget[rCols];
39              for (int j = 0; j < rCols; j++) {
40                  Widget w = this.getWidget(i, j);
41                  if (w != null) this.remove(w);
42                  wRow[j] = w;
43              }
44              toMove[i - row - 1] = wRow;
45          }
46          super.removeRow(row);
47          //restore old widgets
48          for (int i = row; i < total - 1; i++) {
49              int rCols = this.getCellCount(i);
50              Widget[] wRow = toMove[i - row];
51              for (int j = 0; j < rCols; j++) {
52                  Widget w = wRow[j];
53                  if (w != null) this.setWidget(i, j, w);
54              }
55          }
56      }
57  }