summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Englund <marc@vaadin.com>2012-10-23 07:31:21 +0000
committerVaadin Code Review <review@vaadin.com>2012-10-23 07:31:21 +0000
commit7ec5bade7299a0989f7596ac346b8f0ec698d3cb (patch)
treecf4ca7b0676eb19297e9514ea1d2d63b758f926e
parent7a845fdf61f35540c4866a3a9a82015a1a279004 (diff)
parent9461faee8943987027e1622a5b15d4c3a4610bd7 (diff)
downloadvaadin-framework-7ec5bade7299a0989f7596ac346b8f0ec698d3cb.tar.gz
vaadin-framework-7ec5bade7299a0989f7596ac346b8f0ec698d3cb.zip
Merge "AbsoluteLayout now gets child component style names #9051"
-rw-r--r--client/src/com/vaadin/client/ui/absolutelayout/AbsoluteLayoutConnector.java21
-rw-r--r--client/src/com/vaadin/client/ui/absolutelayout/VAbsoluteLayout.java48
-rw-r--r--uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutWrapperStyles.html52
-rw-r--r--uitest/src/com/vaadin/tests/components/absolutelayout/AbsoluteLayoutWrapperStyles.java39
4 files changed, 158 insertions, 2 deletions
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<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);
}
}
}
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();
}
}
}
@@ -372,6 +372,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
*/
protected class AbsoluteWrapper extends SimplePanel {
@@ -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 @@
+<?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
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;
+ }
+
+}