From: John Ahlroos Date: Mon, 22 Oct 2012 12:57:15 +0000 (+0300) Subject: AbsoluteLayout now gets child component style names #9051 X-Git-Tag: 7.0.0.beta6~17^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F46%2F146%2F1;p=vaadin-framework.git AbsoluteLayout now gets child component style names #9051 Change-Id: I236ec48d05b49ee468afa09cc6d88501813811b7 --- diff --git a/client/src/com/vaadin/client/ui/absolutelayout/AbsoluteLayoutConnector.java b/client/src/com/vaadin/client/ui/absolutelayout/AbsoluteLayoutConnector.java index 0877b563a0..e4b2440ef7 100644 --- a/client/src/com/vaadin/client/ui/absolutelayout/AbsoluteLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/absolutelayout/AbsoluteLayoutConnector.java @@ -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 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); } } } diff --git a/client/src/com/vaadin/client/ui/absolutelayout/VAbsoluteLayout.java b/client/src/com/vaadin/client/ui/absolutelayout/VAbsoluteLayout.java index 6c58933dd3..04acb06c40 100644 --- a/client/src/com/vaadin/client/ui/absolutelayout/VAbsoluteLayout.java +++ b/client/src/com/vaadin/client/ui/absolutelayout/VAbsoluteLayout.java @@ -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 index 0000000000..1b92e3cdc5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutWrapperStyles.html @@ -0,0 +1,52 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.absolutelayout.AbsoluteLayoutWrapperStyles?restartApplication
assertCSSClassvaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[0]v-absolutelayout-wrapper
assertCSSClassvaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[0]v-absolutelayout-wrapper-my-label
assertCSSClassvaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[0]v-absolutelayout-wrapper-my-second-label
assertCSSClassvaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[1]v-absolutelayout-wrapper
assertCSSClassvaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[1]v-absolutelayout-wrapper-my-button
assertCSSClassvaadin=runcomvaadintestscomponentsabsolutelayoutAbsoluteLayoutWrapperStyles::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VAbsoluteLayout[0]/VAbsoluteLayout$AbsoluteWrapper[1]v-absolutelayout-wrapper-my-second-button
+ + 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 index 0000000000..11d9f9c850 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutWrapperStyles.java @@ -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; + } + +}