for (Component child : this) {
Element childElement = designContext.createElement(child);
design.appendChild(childElement);
- child.writeDesign(childElement, designContext);
+
// handle position
ComponentPosition position = getPosition(child);
writePositionAttribute(childElement, ATTR_TOP, position
.getBottomUnits().getSymbol(), position.getBottomValue());
writePositionAttribute(childElement, ATTR_LEFT, position
.getLeftUnits().getSymbol(), position.getLeftValue());
+
// handle z-index
if (position.getZIndex() >= 0) {
childElement
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import org.jsoup.nodes.Element;
import org.junit.Test;
+import com.vaadin.ui.AbsoluteLayout;
+import com.vaadin.ui.Accordion;
import com.vaadin.ui.Button;
+import com.vaadin.ui.ComponentContainer;
+import com.vaadin.ui.CssLayout;
+import com.vaadin.ui.CustomLayout;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.HorizontalSplitPanel;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.SingleComponentContainer;
+import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.VerticalSplitPanel;
+import com.vaadin.ui.Window;
import com.vaadin.ui.declarative.Design;
import com.vaadin.ui.declarative.DesignContext;
assertEquals("Found the wrong component by local id.", ctx
.getComponentByLocalId("bar").getClass(), TextField.class);
}
+
+ @Test
+ public void testWriteLocalId() {
+ DesignContext ctx = new DesignContext();
+
+ Button b = new Button();
+ ctx.setComponentLocalId(b, "button-id");
+
+ assertEquals("button-id", ctx.createElement(b).attr("_id"));
+ }
+
+ @Test
+ public void testWriteChildLocalIds() throws Exception {
+ DesignContext ctx = new DesignContext();
+
+ ComponentContainer[] ctrs = { new AbsoluteLayout(), new CssLayout(),
+ new GridLayout(1, 1), new CustomLayout(),
+ new HorizontalLayout(), new VerticalLayout(), new Accordion(),
+ new HorizontalSplitPanel(), new TabSheet(),
+ new VerticalSplitPanel() };
+
+ Button b = new Button();
+ ctx.setComponentLocalId(b, "button-id");
+
+ for (ComponentContainer ctr : ctrs) {
+ ctr.addComponent(b);
+ Element e = ctx.createElement(ctr);
+ assertEquals("Unexpected child local id for "
+ + ctr.getClass().getSimpleName(), "button-id", e
+ .getElementsByTag("v-button").first().attr("_id"));
+ }
+
+ SingleComponentContainer[] sctrs = { new Window(), new Panel() };
+
+ for (SingleComponentContainer ctr : sctrs) {
+ ctr.setContent(b);
+ Element e = ctx.createElement(ctr);
+ assertEquals("Unexpected child local id for "
+ + ctr.getClass().getSimpleName(), "button-id", e
+ .getElementsByTag("v-button").first().attr("_id"));
+ }
+ }
}