litesoft
@ 948
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
/* * Copyright 2007 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.google.gwt.gen2.table.client; import com.google.gwt.user.client.*; import com.google.gwt.user.client.ui.*; import java.util.*; /** * Abstract base class for all panels, which are widgets that can contain other * widgets. * * @deprecated as of Jan 26 2009, No longer needed as events have graduated to gwt. */ @Deprecated public abstract class Gen2TablePanel extends Gen2TableWidget implements HasWidgets { /** * Adds a child widget. * <p/> * <p> * <b>How to Override this Method</b> * </p> * <p> * There are several important things that must take place in the correct * order to properly add or insert a Widget to a Gen2TablePanel. Not all of these steps * will be relevant to every Gen2TablePanel, but all of the steps must be considered. * <ol> * <li><b>Validate:</b> Perform any sanity checks to ensure the Gen2TablePanel can * accept a new Widget. Examples: checking for a valid index on insertion; * checking that the Gen2TablePanel is not full if there is a max capacity.</li> * <li><b>Adjust for Reinsertion:</b> Some Panels need to handle the case * where the Widget is already a child of this Gen2TablePanel. Example: when performing * a reinsert, the index might need to be adjusted to account for the Widget's * removal. See {@link Gen2TableComplexPanel#adjustIndex(Widget, int)}.</li> * <li><b>Detach Child:</b> Remove the Widget from its existing parent, if * any. Most Panels will simply call {@link Widget#removeFromParent()} on the * Widget.</li> * <li><b>Logical Attach:</b> Any state variables of the Gen2TablePanel should be * updated to reflect the addition of the new Widget. Example: the Widget is * added to the Gen2TablePanel's {@link com.google.gwt.user.client.ui.WidgetCollection} * at the appropriate index.</li> * <li><b>Physical Attach:</b> The Widget's Element must be physically * attached to the Gen2TablePanel's Element, either directly or indirectly.</li> * <li><b>Adopt:</b> Call {@link #adopt(Widget)} to finalize the add as the * very last step.</li> * </ol> * </p> * * @param child the widget to be added * * @throws UnsupportedOperationException if this method is not supported (most * often this means that a specific overload must be called) * @see HasWidgets#add(Widget) */ @Override public void add( Widget child ) { throw new UnsupportedOperationException( "This panel does not support no-arg add()" ); } @Override public void clear() { Iterator<Widget> it = iterator(); while ( it.hasNext() ) { it.next(); it.remove(); } } /** * Removes a child widget. * <p/> * <p> * <b>How to Override this Method</b> * </p> * <p> * There are several important things that must take place in the correct * order to properly remove a Widget from a Gen2TablePanel. Not all of these steps will * be relevant to every Gen2TablePanel, but all of the steps must be considered. * <ol> * <li><b>Validate:</b> Make sure this Gen2TablePanel is actually the parent of the * child Widget; return <code>false</code> if it is not.</li> * <li><b>Orphan:</b> Call {@link #orphan(Widget)} first while the child * Widget is still attached.</li> * <li><b>Physical Detach:</b> Adjust the DOM to account for the removal of * the child Widget. The Widget's Element must be physically removed from the * DOM.</li> * <li><b>Logical Detach:</b> Update the Gen2TablePanel's state variables to reflect * the removal of the child Widget. Example: the Widget is removed from the * Gen2TablePanel's {@link com.google.gwt.user.client.ui.WidgetCollection}.</li> * </ol> * </p> * * @param child the widget to be removed * * @return <code>true</code> if the child was present */ @Override public abstract boolean remove( Widget child ); /** * Finalize the attachment of a Widget to this Gen2TablePanel. This method is the * <b>last</b> step in adding or inserting a Widget into a Gen2TablePanel, and should * be called after physical attachment in the DOM is complete. This Gen2TablePanel * becomes the parent of the child Widget, and the child will now fire its * {@link Widget#onAttach()} event if this Gen2TablePanel is currently attached. * * @param child the widget to be adopted * * @see #add(Widget) */ protected final void adopt( Widget child ) { assert (child.getParent() == null); WidgetAdaptorImpl.setParent( child, this ); } /** * This method was formerly part of the process of adding a Widget to a Gen2TablePanel * but has been deprecated in favor of {@link #adopt(Widget)}. * * @deprecated Use {@link #adopt(Widget)}. */ @Deprecated protected void adopt( Widget w, Element container ) { // Remove the widget from its current parent, if any. w.removeFromParent(); // Attach it at the DOM and GWT levels. if ( container != null ) { DOM.appendChild( container, w.getElement() ); } WidgetAdaptorImpl.setParent( w, this ); } /** * This method was formerly part of the process of removing a Widget from a * Gen2TablePanel but has been deprecated in favor of {@link #orphan(Widget)}. * * @deprecated Use {@link #orphan(Widget)}. */ @Deprecated protected void disown( Widget w ) { // Only disown it if it's actually contained in this panel. if ( w.getParent() != this ) { throw new IllegalArgumentException( "w is not a child of this panel" ); } // setParent() must be called before removeChild() to ensure that the // element is still attached when onDetach()/onUnload() are called. Element elem = w.getElement(); WidgetAdaptorImpl.setParent( w, null ); DOM.removeChild( DOM.getParent( elem ), elem ); } @Override protected void doAttachChildren() { // Ensure that all child widgets are attached. for ( Iterator<Widget> it = iterator(); it.hasNext(); ) { Widget child = it.next(); WidgetAdaptorImpl.onAttach( child ); } } @Override protected void doDetachChildren() { // Ensure that all child widgets are detached. for ( Iterator<Widget> it = iterator(); it.hasNext(); ) { Widget child = it.next(); WidgetAdaptorImpl.onDetach( child ); } } /** * A Gen2TablePanel's onLoad method will be called after all of its children are * attached. * * @see Widget#onLoad() */ @Override protected void onLoad() { } /** * A Gen2TablePanel's onUnload method will be called before its children become * detached themselves. * * @see Widget#onLoad() */ @Override protected void onUnload() { } /** * This method must be called as part of the remove method of any Gen2TablePanel. It * ensures that the Widget's parent is cleared. This method should be called * after verifying that the child Widget is an existing child of the Gen2TablePanel, * but before physically removing the child Widget from the DOM. The child * will now fire its {@link Widget#onDetach()} event if this Gen2TablePanel is * currently attached. * * @param child the widget to be disowned * * @see #add(Widget) */ protected final void orphan( Widget child ) { assert (child.getParent() == this); WidgetAdaptorImpl.setParent( child, null ); } } |