]> source.dussan.org Git - vaadin-framework.git/commitdiff
Slots now get their childrens primary stylename in Vertical/Horizontal layouts #9576 43/143/4
authorJohn Ahlroos <john@vaadin.com>
Mon, 22 Oct 2012 11:15:32 +0000 (14:15 +0300)
committerJohn Ahlroos <john@vaadin.com>
Mon, 22 Oct 2012 13:00:39 +0000 (16:00 +0300)
Change-Id: I68f58868606b91353224a6eed83262b33e0af8ea

client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java
client/src/com/vaadin/client/ui/orderedlayout/VOrderedLayout.java
uitest/src/com/vaadin/tests/components/orderedlayout/OrderedLayoutSlotStyleNames.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/orderedlayout/OrderedLayoutSlotStyleNames.java [new file with mode: 0644]

index 7da2e17cbe08eabb7a9c94e423d94c6001d5031a..7a2166cde2c7b4e532e447d6afb6846c84041f7d 100644 (file)
@@ -83,8 +83,15 @@ public abstract class AbstractOrderedLayoutConnector extends
             slot.setRelativeWidth(child.isRelativeWidth());
             slot.setRelativeHeight(child.isRelativeHeight());
 
+            // Update slot style names
+            List<String> childStyles = child.getState().styles;
+            if (childStyles != null && !childStyles.isEmpty()) {
+                getWidget().setSlotStyleNames(child.getWidget(),
+                        childStyles.toArray(new String[childStyles
+                                .size()]));
+            }
+
             updateSlotListeners(child);
-            // updateAllSlotListeners();
 
             updateLayoutHeight();
         }
index e9cdc42b86113818367b24ef0eb0c3f957d98cea..91d6852f52bbff5d3681f8dfc09554d255eed007 100644 (file)
@@ -149,6 +149,8 @@ public class VOrderedLayout extends FlowPanel {
      */
     public static final class Slot extends SimplePanel {
 
+        public static final String SLOT_CLASSNAME = "v-slot";
+
         private Element spacer;
         private Element captionWrap;
         private Element caption;
@@ -177,8 +179,8 @@ public class VOrderedLayout extends FlowPanel {
          */
         private Slot(Widget widget, VOrderedLayout layout) {
             this.layout = layout;
+            setStyleName(SLOT_CLASSNAME);
             setWidget(widget);
-            setStylePrimaryName("v-slot");
         }
 
         /**
@@ -189,6 +191,22 @@ public class VOrderedLayout extends FlowPanel {
             return alignment;
         }
 
+        /**
+         * Sets the style names for the slot containing the widget
+         * 
+         * @param stylenames
+         *            The style names for the slot
+         */
+        protected void setStyleNames(String... stylenames) {
+            setStyleName(SLOT_CLASSNAME);
+            for (String stylename : stylenames) {
+                addStyleDependentName(stylename);
+            }
+
+            // Ensure alignment style names are correct
+            setAlignment(alignment);
+        }
+
         /**
          * Sets how the widget is aligned inside the slot
          * 
@@ -198,20 +216,21 @@ public class VOrderedLayout extends FlowPanel {
         public void setAlignment(AlignmentInfo alignment) {
             this.alignment = alignment;
 
-            if (alignment.isHorizontalCenter()) {
+            if (alignment != null && alignment.isHorizontalCenter()) {
                 addStyleName(ALIGN_CLASS_PREFIX + "center");
                 removeStyleName(ALIGN_CLASS_PREFIX + "right");
-            } else if (alignment.isRight()) {
+            } else if (alignment != null && alignment.isRight()) {
                 addStyleName(ALIGN_CLASS_PREFIX + "right");
                 removeStyleName(ALIGN_CLASS_PREFIX + "center");
             } else {
                 removeStyleName(ALIGN_CLASS_PREFIX + "right");
                 removeStyleName(ALIGN_CLASS_PREFIX + "center");
             }
-            if (alignment.isVerticalCenter()) {
+
+            if (alignment != null && alignment.isVerticalCenter()) {
                 addStyleName(ALIGN_CLASS_PREFIX + "middle");
                 removeStyleName(ALIGN_CLASS_PREFIX + "bottom");
-            } else if (alignment.isBottom()) {
+            } else if (alignment != null && alignment.isBottom()) {
                 addStyleName(ALIGN_CLASS_PREFIX + "bottom");
                 removeStyleName(ALIGN_CLASS_PREFIX + "middle");
             } else {
@@ -970,4 +989,20 @@ public class VOrderedLayout extends FlowPanel {
         super.setHeight(height);
         definedHeight = (height != null && !"".equals(height));
     }
+
+    /**
+     * Sets the slots style names. The style names will be prefixed with the
+     * v-slot prefix.
+     * 
+     * @param stylenames
+     *            The style names of the slot.
+     */
+    public void setSlotStyleNames(Widget widget, String... stylenames) {
+        Slot slot = getSlot(widget);
+        if (slot == null) {
+            throw new IllegalArgumentException(
+                    "A slot for the widget could not be found. Has the widget been added to the layout?");
+        }
+        slot.setStyleNames(stylenames);
+    }
 }
diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/OrderedLayoutSlotStyleNames.html b/uitest/src/com/vaadin/tests/components/orderedlayout/OrderedLayoutSlotStyleNames.html
new file mode 100644 (file)
index 0000000..adfc8fb
--- /dev/null
@@ -0,0 +1,82 @@
+<?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.orderedlayout.OrderedLayoutSlotStyleNames?restartApplication</td>
+    <td></td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]</td>
+    <td>v-slot</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]</td>
+    <td>v-slot-my-label</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[0]</td>
+    <td>v-slot-my-second-label</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]</td>
+    <td>v-slot</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]</td>
+    <td>v-slot-my-button</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VVerticalLayout[0]/VOrderedLayout$Slot[1]</td>
+    <td>v-slot-my-second-button</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]</td>
+    <td>v-slot</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]</td>
+    <td>v-slot-my-label</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VHorizontalLayout[0]/VOrderedLayout$Slot[0]</td>
+    <td>v-slot-my-second-label</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VHorizontalLayout[0]/VOrderedLayout$Slot[1]</td>
+    <td>v-slot</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VHorizontalLayout[0]/VOrderedLayout$Slot[1]</td>
+    <td>v-slot-my-button</td>
+</tr>
+<tr>
+    <td>assertCSSClass</td>
+    <td>vaadin=runcomvaadintestscomponentsorderedlayoutOrderedLayoutSlotStyleNames::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VHorizontalLayout[0]/VOrderedLayout$Slot[1]</td>
+    <td>v-slot-my-second-button</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/orderedlayout/OrderedLayoutSlotStyleNames.java b/uitest/src/com/vaadin/tests/components/orderedlayout/OrderedLayoutSlotStyleNames.java
new file mode 100644 (file)
index 0000000..3bfc5bb
--- /dev/null
@@ -0,0 +1,53 @@
+package com.vaadin.tests.components.orderedlayout;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.VerticalLayout;
+
+public class OrderedLayoutSlotStyleNames extends TestBase {
+
+    @Override
+    protected void setup() {
+        VerticalLayout vl = new VerticalLayout();
+
+        Label lbl = new Label("A label");
+        lbl.setStyleName("my-label");
+        lbl.addStyleName("my-second-label");
+        vl.addComponent(lbl);
+
+        Button btn = new Button("A Button");
+        btn.setStyleName("my-button");
+        btn.addStyleName("my-second-button");
+        vl.addComponent(btn);
+
+        addComponent(vl);
+
+
+        HorizontalLayout hl = new HorizontalLayout();
+
+        lbl = new Label("A label");
+        lbl.setStyleName("my-label");
+        lbl.addStyleName("my-second-label");
+        hl.addComponent(lbl);
+
+        btn = new Button("A Button");
+        btn.setStyleName("my-button");
+        btn.addStyleName("my-second-button");
+        hl.addComponent(btn);
+
+        addComponent(hl);
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Vertical/HorizontalLayout slots should get child dependant name";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 9051;
+    }
+
+}