]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed primary stylename handling for CustomLayout #9902 15/115/2
authorJohn Ahlroos <john@vaadin.com>
Fri, 12 Oct 2012 07:19:10 +0000 (10:19 +0300)
committerJohn Ahlroos <john@vaadin.com>
Fri, 12 Oct 2012 07:21:09 +0000 (10:21 +0300)
Change-Id: I8ec0da24e73cc182b6d7df6409c348bb61e61d47

client/src/com/vaadin/client/ui/customlayout/VCustomLayout.java
uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.java [new file with mode: 0644]

index 7a512fac49c193a63ffd3754560decd81be40ee6..803b2665503fdb5a2f12d7482cf701c5b6b4b9a1 100644 (file)
@@ -21,6 +21,10 @@ import java.util.Iterator;
 
 import com.google.gwt.dom.client.ImageElement;
 import com.google.gwt.dom.client.NodeList;
+import com.google.gwt.dom.client.Style;
+import com.google.gwt.dom.client.Style.BorderStyle;
+import com.google.gwt.dom.client.Style.Position;
+import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
@@ -75,16 +79,22 @@ public class VCustomLayout extends ComplexPanel {
     public VCustomLayout() {
         setElement(DOM.createDiv());
         // Clear any unwanted styling
-        DOM.setStyleAttribute(getElement(), "border", "none");
-        DOM.setStyleAttribute(getElement(), "margin", "0");
-        DOM.setStyleAttribute(getElement(), "padding", "0");
+        Style style = getElement().getStyle();
+        style.setBorderStyle(BorderStyle.NONE);
+        style.setMargin(0, Unit.PX);
+        style.setPadding(0, Unit.PX);
 
         if (BrowserInfo.get().isIE()) {
-            DOM.setStyleAttribute(getElement(), "position", "relative");
+            style.setPosition(Position.RELATIVE);
         }
 
-        setStyleName(StyleConstants.UI_LAYOUT);
-        addStyleName(CLASSNAME);
+        setStyleName(CLASSNAME);
+    }
+
+    @Override
+    public void setStyleName(String style) {
+        super.setStyleName(style);
+        addStyleName(StyleConstants.UI_LAYOUT);
     }
 
     /**
diff --git a/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.html b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.html
new file mode 100644 (file)
index 0000000..0a5654b
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+    <td>open</td>
+    <td>/run/com.vaadin.tests.components.customlayout.CustomLayoutPrimaryStyleName?restartApplication</td>
+    <td></td>
+</tr>
+<tr>
+    <td>assertNotCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/</td>
+    <td>v-customlayout</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/</td>
+    <td>my-customlayout</td>
+</tr>
+<tr>
+    <td>click</td>
+    <td>vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0]</td>
+    <td></td>
+</tr>
+<tr>
+    <td>assertNotCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/</td>
+    <td>my-customlayout</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/</td>
+    <td>my-second-customlayout</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.java b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.java
new file mode 100644 (file)
index 0000000..f0dc711
--- /dev/null
@@ -0,0 +1,51 @@
+package com.vaadin.tests.components.customlayout;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.CustomLayout;
+import com.vaadin.ui.TextField;
+
+public class CustomLayoutPrimaryStyleName extends TestBase {
+
+    @Override
+    protected void setup() {
+        InputStream is = new ByteArrayInputStream(
+                "<div location='loc1'>".getBytes());
+        try {
+            final CustomLayout cl = new CustomLayout(is);
+
+            cl.addComponent(new TextField("Hello world"), "loc1");
+
+            cl.setPrimaryStyleName("my-customlayout");
+            addComponent(cl);
+
+            addComponent(new Button("Set primary stylename",
+                    new Button.ClickListener() {
+                        @Override
+                        public void buttonClick(ClickEvent event) {
+                            cl.setPrimaryStyleName("my-second-customlayout");
+                        }
+                    }));
+
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    protected String getDescription() {
+        return "CustomLayout should support primary stylenames both initially and dynamically";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 9902;
+    }
+
+}