Author: [email protected]
Date: Fri May 15 08:59:08 2009
New Revision: 5388
Added:
trunk/user/test/com/google/gwt/user/client/ui/AbstractCellPanelTest.java
(contents, props changed)
Modified:
trunk/user/src/com/google/gwt/user/client/ui/CellPanel.java
trunk/user/test/com/google/gwt/user/client/ui/HorizontalPanelTest.java
trunk/user/test/com/google/gwt/user/client/ui/VerticalPanelTest.java
Log:
CellPanel now checks that a widget is its child before trying to set the
height or width of its containing TD element.
Patch by: david.nouls, jlabanca
Review by: jgw
Modified: trunk/user/src/com/google/gwt/user/client/ui/CellPanel.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/CellPanel.java (original)
+++ trunk/user/src/com/google/gwt/user/client/ui/CellPanel.java Fri May 15
08:59:08 2009
@@ -65,8 +65,10 @@
* @param height the cell's height, in CSS units
*/
public void setCellHeight(Widget w, String height) {
- Element td = DOM.getParent(w.getElement());
- DOM.setElementProperty(td, "height", height);
+ Element td = getWidgetTd(w);
+ if (td != null) {
+ td.setPropertyString("height", height);
+ }
}
/**
@@ -106,8 +108,10 @@
* @param width the cell's width, in CSS units
*/
public void setCellWidth(Widget w, String width) {
- Element td = DOM.getParent(w.getElement());
- DOM.setElementProperty(td, "width", width);
+ Element td = getWidgetTd(w);
+ if (td != null) {
+ td.setPropertyString("width", width);
+ }
}
/**
Added:
trunk/user/test/com/google/gwt/user/client/ui/AbstractCellPanelTest.java
==============================================================================
--- (empty file)
+++
trunk/user/test/com/google/gwt/user/client/ui/AbstractCellPanelTest.java
Fri May 15 08:59:08 2009
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2009 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.user.client.ui;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Base tests for {...@link CellPanel}.
+ */
+public abstract class AbstractCellPanelTest extends GWTTestCase {
+
+ @Override
+ public String getModuleName() {
+ return "com.google.gwt.user.DebugTest";
+ }
+
+ public void testGetWidgetTd() {
+ CellPanel panel = createCellPanel();
+ Widget w = panel.getWidget(0);
+ assertEquals(w.getElement().getParentElement(), panel.getWidgetTd(w));
+ }
+
+ public void testSetCellAlignment() {
+ CellPanel panel = createCellPanel();
+ Widget w = panel.getWidget(0);
+ Element td = panel.getWidgetTd(w);
+
+ // setCellVerticalAlignment
+ panel.setCellVerticalAlignment(w, HasVerticalAlignment.ALIGN_BOTTOM);
+ assertEquals("bottom", td.getStyle().getProperty("verticalAlign"));
+
+ // setCellHorizontalAlignment
+ panel.setCellHorizontalAlignment(w,
HasHorizontalAlignment.ALIGN_RIGHT);
+ assertEquals("right", td.getPropertyString("align"));
+ }
+
+ public void testSetCellAlignmentForNonChildWidget() {
+ CellPanel panel = createCellPanel();
+ Widget w = new Label("Not a chid");
+
+ // setCellVerticalAlignment should not throw an error
+ panel.setCellVerticalAlignment(w, HasVerticalAlignment.ALIGN_BOTTOM);
+
+ // setCellHorizontalAlignment should not throw an error
+ panel.setCellHorizontalAlignment(w,
HasHorizontalAlignment.ALIGN_RIGHT);
+ }
+
+ public void testSetCellSize() {
+ CellPanel panel = createCellPanel();
+ Widget w = panel.getWidget(0);
+ Element td = panel.getWidgetTd(w);
+
+ // setCellHeight
+ panel.setCellHeight(w, "100px");
+ assertEquals(100, td.getPropertyInt("height"));
+
+ // setCellWidth
+ panel.setCellWidth(w, "200px");
+ assertEquals(200, td.getPropertyInt("width"));
+ }
+
+ public void testSetCellSizeForNonChildWidget() {
+ CellPanel panel = createCellPanel();
+ Widget w = new Label("Not a chid");
+
+ // setCellHeight should not throw an error
+ panel.setCellHeight(w, "100px");
+
+ // setCellWidth should not throw an error
+ panel.setCellWidth(w, "200px");
+ }
+
+ /**
+ * Create a populated {...@link CellPanel}.
+ *
+ * @return the {...@link CellPanel}
+ */
+ protected abstract CellPanel createCellPanel();
+}
Modified:
trunk/user/test/com/google/gwt/user/client/ui/HorizontalPanelTest.java
==============================================================================
--- trunk/user/test/com/google/gwt/user/client/ui/HorizontalPanelTest.java
(original)
+++ trunk/user/test/com/google/gwt/user/client/ui/HorizontalPanelTest.java
Fri May 15 08:59:08 2009
@@ -15,7 +15,6 @@
*/
package com.google.gwt.user.client.ui;
-import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.DOM;
import java.util.Iterator;
@@ -23,12 +22,7 @@
/**
* A test for {...@link HorizontalPanel}.
*/
-public class HorizontalPanelTest extends GWTTestCase {
-
- @Override
- public String getModuleName() {
- return "com.google.gwt.user.DebugTest";
- }
+public class HorizontalPanelTest extends AbstractCellPanelTest {
public void testAttachDetachOrder() {
HasWidgetsTester.testAll(new HorizontalPanel());
@@ -87,5 +81,14 @@
assertEquals(2, p.getWidgetCount());
assertEquals(0, p.getWidgetIndex(tb));
assertEquals(1, p.getWidgetIndex(l));
+ }
+
+ @Override
+ protected CellPanel createCellPanel() {
+ HorizontalPanel p = new HorizontalPanel();
+ p.add(new Label("a"));
+ p.add(new Label("b"));
+ p.add(new Label("c"));
+ return p;
}
}
Modified:
trunk/user/test/com/google/gwt/user/client/ui/VerticalPanelTest.java
==============================================================================
--- trunk/user/test/com/google/gwt/user/client/ui/VerticalPanelTest.java
(original)
+++ trunk/user/test/com/google/gwt/user/client/ui/VerticalPanelTest.java
Fri May 15 08:59:08 2009
@@ -15,7 +15,6 @@
*/
package com.google.gwt.user.client.ui;
-import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.DOM;
import java.util.Iterator;
@@ -23,12 +22,7 @@
/**
* A test for {...@link VerticalPanel}.
*/
-public class VerticalPanelTest extends GWTTestCase {
-
- @Override
- public String getModuleName() {
- return "com.google.gwt.user.DebugTest";
- }
+public class VerticalPanelTest extends AbstractCellPanelTest {
public void testAttachDetachOrder() {
HasWidgetsTester.testAll(new VerticalPanel());
@@ -87,5 +81,14 @@
assertEquals(2, p.getWidgetCount());
assertEquals(0, p.getWidgetIndex(tb));
assertEquals(1, p.getWidgetIndex(l));
+ }
+
+ @Override
+ protected CellPanel createCellPanel() {
+ VerticalPanel p = new VerticalPanel();
+ p.add(new Label("a"));
+ p.add(new Label("b"));
+ p.add(new Label("c"));
+ return p;
}
}
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---