]> source.dussan.org Git - vaadin-framework.git/commitdiff
AbsoluteLayout now gets child component style names #9051 46/146/1
authorJohn Ahlroos <john@vaadin.com>
Mon, 22 Oct 2012 12:57:15 +0000 (15:57 +0300)
committerJohn Ahlroos <john@vaadin.com>
Tue, 23 Oct 2012 05:50:27 +0000 (08:50 +0300)
Change-Id: I236ec48d05b49ee468afa09cc6d88501813811b7

client/src/com/vaadin/client/ui/absolutelayout/AbsoluteLayoutConnector.java
client/src/com/vaadin/client/ui/absolutelayout/VAbsoluteLayout.java
uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutWrapperStyles.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutWrapperStyles.java [new file with mode: 0644]

index 0877b563a0c8f3e6ebf0d909878dfb6b1725d1a1..e4b2440ef7e5893573d570f65dfdcdd50aa089eb 100644 (file)
@@ -15,6 +15,8 @@
  */
 package com.vaadin.client.ui.absolutelayout;
 
+import java.util.List;
+
 import com.google.gwt.user.client.Element;
 import com.vaadin.client.ComponentConnector;
 import com.vaadin.client.ConnectorHierarchyChangeEvent;
@@ -23,6 +25,7 @@ import com.vaadin.client.Util;
 import com.vaadin.client.VCaption;
 import com.vaadin.client.communication.RpcProxy;
 import com.vaadin.client.communication.StateChangeEvent;
+import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
 import com.vaadin.client.ui.AbstractComponentContainerConnector;
 import com.vaadin.client.ui.LayoutClickEventHandler;
 import com.vaadin.shared.ui.Connect;
@@ -53,6 +56,22 @@ public class AbsoluteLayoutConnector extends
         };
     };
 
+    private StateChangeHandler childStateChangeHandler = new StateChangeHandler() {
+        @Override
+        public void onStateChanged(StateChangeEvent stateChangeEvent) {
+            ComponentConnector child = (ComponentConnector) stateChangeEvent
+                    .getConnector();
+            List<String> childStyles = child.getState().styles;
+            if (childStyles == null) {
+                getWidget().setWidgetWrapperStyleNames(child.getWidget(),
+                        (String[]) null);
+            } else {
+                getWidget().setWidgetWrapperStyleNames(child.getWidget(),
+                        childStyles.toArray(new String[childStyles.size()]));
+            }
+        }
+    };
+
     private AbsoluteLayoutServerRpc rpc;
 
     /*
@@ -160,11 +179,13 @@ public class AbsoluteLayoutConnector extends
         for (ComponentConnector child : getChildComponents()) {
             if (!getWidget().contains(child.getWidget())) {
                 getWidget().add(child.getWidget());
+                child.addStateChangeHandler(childStateChangeHandler);
             }
         }
         for (ComponentConnector oldChild : event.getOldChildren()) {
             if (oldChild.getParent() != this) {
                 getWidget().remove(oldChild.getWidget());
+                oldChild.removeStateChangeHandler(childStateChangeHandler);
             }
         }
     }
index 6c58933dd301a1cbaa8b3fb7d4425d577746493c..04acb06c400aae98cb0d2eb28bc953d251e72f03 100644 (file)
@@ -62,7 +62,7 @@ public class VAbsoluteLayout extends ComplexPanel {
     @Override
     public void add(Widget child) {
         AbsoluteWrapper wrapper = new AbsoluteWrapper(child);
-        wrapper.setStyleName(getStylePrimaryName() + "-wrapper");
+        wrapper.updateStyleNames();
         super.add(wrapper, canvas);
     }
 
@@ -292,7 +292,7 @@ public class VAbsoluteLayout extends ComplexPanel {
         for (Widget w : getChildren()) {
             if (w instanceof AbsoluteWrapper) {
                 AbsoluteWrapper wrapper = (AbsoluteWrapper) w;
-                wrapper.setStyleName(getStylePrimaryName() + "-wrapper");
+                wrapper.updateStyleNames();
             }
         }
     }
@@ -371,6 +371,24 @@ public class VAbsoluteLayout extends ComplexPanel {
         }
     }
 
+    /**
+     * Sets style names for the wrapper wrapping the widget in the layout. The
+     * style names will be prefixed with v-absolutelayout-wrapper.
+     * 
+     * @param widget
+     *            The widget which wrapper we want to add the stylenames to
+     * @param stylenames
+     *            The style names that should be added to the wrapper
+     */
+    public void setWidgetWrapperStyleNames(Widget widget, String... stylenames) {
+        AbsoluteWrapper wrapper = getChildWrapper(widget);
+        if (wrapper == null) {
+            throw new IllegalArgumentException(
+                    "No wrapper for widget found, has the widget been added to the layout?");
+        }
+        wrapper.setWrapperStyleNames(stylenames);
+    }
+
     /**
      * Internal wrapper for wrapping widgets in the Absolute layout
      */
@@ -383,6 +401,7 @@ public class VAbsoluteLayout extends ComplexPanel {
         private String zIndex;
 
         private VCaption caption;
+        private String[] extraStyleNames;
 
         /**
          * Constructor
@@ -486,5 +505,30 @@ public class VAbsoluteLayout extends ComplexPanel {
                         - caption.getHeight());
             }
         }
+
+        /**
+         * Sets the style names of the wrapper. Will be prefixed with the
+         * v-absolutelayout-wrapper prefix
+         * 
+         * @param stylenames
+         *            The wrapper style names
+         */
+        public void setWrapperStyleNames(String... stylenames) {
+            extraStyleNames = stylenames;
+            updateStyleNames();
+        }
+
+        /**
+         * Updates the style names using the primary style name as prefix
+         */
+        protected void updateStyleNames() {
+            setStyleName(VAbsoluteLayout.this.getStylePrimaryName()
+                    + "-wrapper");
+            if(extraStyleNames != null){
+                for (String stylename : extraStyleNames) {
+                    addStyleDependentName(stylename);
+                }
+            }
+        }
     }
 }
diff --git a/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutWrapperStyles.html b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutWrapperStyles.html
new file mode 100644 (file)
index 0000000..1b92e3c
--- /dev/null
@@ -0,0 +1,52 @@
+<?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.absolutelayout.AbsoluteLayoutWrapperStyles?restartApplication</td>
+    <td></td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[0]</td>
+    <td>v-absolutelayout-wrapper</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[0]</td>
+    <td>v-absolutelayout-wrapper-my-label</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[0]</td>
+    <td>v-absolutelayout-wrapper-my-second-label</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[1]</td>
+    <td>v-absolutelayout-wrapper</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[1]</td>
+    <td>v-absolutelayout-wrapper-my-button</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[1]</td>
+    <td>v-absolutelayout-wrapper-my-second-button</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutWrapperStyles.java b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutWrapperStyles.java
new file mode 100644 (file)
index 0000000..11d9f9c
--- /dev/null
@@ -0,0 +1,39 @@
+package com.vaadin.tests.components.absolutelayout;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.AbsoluteLayout;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+
+public class AbsoluteLayoutWrapperStyles extends TestBase {
+
+    @Override
+    protected void setup() {
+        AbsoluteLayout layout = new AbsoluteLayout();
+        layout.setWidth("500px");
+        layout.setHeight("500px");
+
+        Label lbl = new Label("Label");
+        lbl.setStyleName("my-label");
+        lbl.addStyleName("my-second-label");
+        layout.addComponent(lbl);
+
+        Button btn = new Button("Button");
+        btn.setStyleName("my-button");
+        btn.addStyleName("my-second-button");
+        layout.addComponent(btn, "top:50px;");
+
+        addComponent(layout);
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Absolutelayout wrapper should get child stylenames";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 9051;
+    }
+
+}