*/
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;
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;
};
};
+ 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;
/*
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);
}
}
}
@Override
public void add(Widget child) {
AbsoluteWrapper wrapper = new AbsoluteWrapper(child);
- wrapper.setStyleName(getStylePrimaryName() + "-wrapper");
+ wrapper.updateStyleNames();
super.add(wrapper, canvas);
}
for (Widget w : getChildren()) {
if (w instanceof AbsoluteWrapper) {
AbsoluteWrapper wrapper = (AbsoluteWrapper) w;
- wrapper.setStyleName(getStylePrimaryName() + "-wrapper");
+ wrapper.updateStyleNames();
}
}
}
}
}
+ /**
+ * 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
*/
private String zIndex;
private VCaption caption;
+ private String[] extraStyleNames;
/**
* Constructor
- 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);
+ }
+ }
+ }
}
}
--- /dev/null
+<?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>
--- /dev/null
+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;
+ }
+
+}