diff options
author | John Ahlroos <john@vaadin.com> | 2012-10-22 14:15:32 +0300 |
---|---|---|
committer | John Ahlroos <john@vaadin.com> | 2012-10-22 16:00:39 +0300 |
commit | 6838d421c03f6ce3cb595d450520ed2523a4236c (patch) | |
tree | ebc2e7fb0c52f28f9badf310d998a211688edaec /client | |
parent | ce0640100a3892a1e36d25df1b85de73b6e2d1d0 (diff) | |
download | vaadin-framework-6838d421c03f6ce3cb595d450520ed2523a4236c.tar.gz vaadin-framework-6838d421c03f6ce3cb595d450520ed2523a4236c.zip |
Slots now get their childrens primary stylename in Vertical/Horizontal layouts #9576
Change-Id: I68f58868606b91353224a6eed83262b33e0af8ea
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java | 9 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/orderedlayout/VOrderedLayout.java | 45 |
2 files changed, 48 insertions, 6 deletions
diff --git a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index 7da2e17cbe..7a2166cde2 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -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(); } diff --git a/client/src/com/vaadin/client/ui/orderedlayout/VOrderedLayout.java b/client/src/com/vaadin/client/ui/orderedlayout/VOrderedLayout.java index e9cdc42b86..91d6852f52 100644 --- a/client/src/com/vaadin/client/ui/orderedlayout/VOrderedLayout.java +++ b/client/src/com/vaadin/client/ui/orderedlayout/VOrderedLayout.java @@ -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"); } /** @@ -190,6 +192,22 @@ public class VOrderedLayout extends FlowPanel { } /** + * 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 * * @param alignment @@ -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); + } } |