private Command<T, Integer> removeComponentByIndexCommand = new Command<T, Integer>() {\r
\r
public void execute(T c, Integer value, Object data) {\r
- Iterator<Component> iter = c.getComponentIterator();\r
- for (int i = 0; i < value; i++) {\r
- iter.next();\r
- }\r
- c.removeComponent(iter.next());\r
+ Component child = getComponentAtIndex(c, value);\r
+ c.removeComponent(child);\r
\r
}\r
};\r
}\r
};\r
\r
+ private Command<T, Integer> setComponentHeight = new Command<T, Integer>() {\r
+\r
+ public void execute(T c, Integer value, Object data) {\r
+ Component child = getComponentAtIndex(c, value);\r
+ child.setHeight((String) data);\r
+\r
+ }\r
+ };\r
+\r
+ private Command<T, Integer> setComponentWidth = new Command<T, Integer>() {\r
+\r
+ public void execute(T c, Integer value, Object data) {\r
+ Component child = getComponentAtIndex(c, value);\r
+ child.setWidth((String) data);\r
+\r
+ }\r
+ };\r
+\r
protected static class ComponentSize {\r
private String width, height;\r
\r
\r
createAddComponentActions(CATEGORY_COMPONENT_CONTAINER_FEATURES);\r
createRemoveComponentActions(CATEGORY_COMPONENT_CONTAINER_FEATURES);\r
+ createChangeComponentSizeActions(CATEGORY_COMPONENT_CONTAINER_FEATURES);\r
createComponentAttachListener(CATEGORY_LISTENERS);\r
createComponentDetachListener(CATEGORY_LISTENERS);\r
}\r
\r
+ protected Component getComponentAtIndex(T container, int value) {\r
+ Iterator<Component> iter = container.getComponentIterator();\r
+ for (int i = 0; i < value; i++) {\r
+ iter.next();\r
+ }\r
+\r
+ return iter.next();\r
+ }\r
+\r
protected Table createTable() {\r
Table t = new Table();\r
t.addContainerProperty("property 1", String.class, "");\r
createCategory(byIndexCategory, subCategory);\r
createClickAction("Remove all components", subCategory,\r
removeAllComponentsCommand, null);\r
- for (int i = 0; i < 10; i++) {\r
+ for (int i = 0; i < 20; i++) {\r
createClickAction("Remove component " + i, byIndexCategory,\r
removeComponentByIndexCommand, Integer.valueOf(i));\r
}\r
\r
}\r
\r
+ private void createChangeComponentSizeActions(String category) {\r
+ String widthCategory = "Change component width";\r
+ createCategory(widthCategory, category);\r
+ String heightCategory = "Change component height";\r
+ createCategory(heightCategory, category);\r
+\r
+ String[] options = new String[] { "100px", "200px", "50%", "100%" };\r
+ for (int i = 0; i < 20; i++) {\r
+ String componentWidthCategory = "Component " + i + " width";\r
+ String componentHeightCategory = "Component " + i + " height";\r
+ createCategory(componentWidthCategory, widthCategory);\r
+ createCategory(componentHeightCategory, heightCategory);\r
+\r
+ createClickAction("auto", componentHeightCategory,\r
+ setComponentHeight, Integer.valueOf(i), null);\r
+ createClickAction("auto", componentWidthCategory,\r
+ setComponentWidth, Integer.valueOf(i), null);\r
+ for (String option : options) {\r
+ createClickAction(option, componentHeightCategory,\r
+ setComponentHeight, Integer.valueOf(i), option);\r
+ createClickAction(option, componentWidthCategory,\r
+ setComponentWidth, Integer.valueOf(i), option);\r
+ }\r
+\r
+ }\r
+\r
+ }\r
+\r
public void componentDetachedFromContainer(ComponentDetachEvent event) {\r
log(event.getClass().getSimpleName() + ": "\r
+ event.getDetachedComponent().getClass().getSimpleName()\r
import java.util.LinkedHashMap;\r
\r
import com.vaadin.ui.AbstractLayout;\r
+import com.vaadin.ui.Alignment;\r
+import com.vaadin.ui.Component;\r
+import com.vaadin.ui.Layout.AlignmentHandler;\r
import com.vaadin.ui.Layout.MarginInfo;\r
+import com.vaadin.ui.Layout.SpacingHandler;\r
\r
public abstract class AbstractLayoutTest<T extends AbstractLayout> extends\r
AbstractComponentContainerTest<T> {\r
\r
- private static final String CATEGORY_LAYOUT_FEATURES = "Layout features";\r
+ protected static final String CATEGORY_LAYOUT_FEATURES = "Layout features";\r
private Command<T, MarginInfo> marginCommand = new Command<T, MarginInfo>() {\r
\r
public void execute(T c, MarginInfo value, Object data) {\r
}\r
};\r
\r
+ protected Command<T, Boolean> spacingCommand = new Command<T, Boolean>() {\r
+ public void execute(T c, Boolean value, Object data) {\r
+ ((SpacingHandler) c).setSpacing(value);\r
+ }\r
+ };\r
+\r
+ private Command<T, Integer> setComponentAlignment = new Command<T, Integer>() {\r
+\r
+ public void execute(T c, Integer value, Object alignment) {\r
+ Component child = getComponentAtIndex(c, value);\r
+ ((AlignmentHandler) c).setComponentAlignment(child,\r
+ (Alignment) alignment);\r
+ }\r
+ };\r
+\r
@Override\r
protected void createActions() {\r
super.createActions();\r
createMarginsSelect(CATEGORY_LAYOUT_FEATURES);\r
+ if (SpacingHandler.class.isAssignableFrom(getTestClass())) {\r
+ createSpacingSelect(CATEGORY_LAYOUT_FEATURES);\r
+ }\r
+ if (AlignmentHandler.class.isAssignableFrom(getTestClass())) {\r
+ createChangeComponentAlignmentAction(CATEGORY_LAYOUT_FEATURES);\r
+ }\r
+\r
}\r
\r
private void createMarginsSelect(String category) {\r
\r
createSelectAction("Margins", category, options, "off", marginCommand);\r
}\r
+\r
+ private void createSpacingSelect(String category) {\r
+ createBooleanAction("Spacing", category, false, spacingCommand);\r
+ }\r
+\r
+ private void createChangeComponentAlignmentAction(String category) {\r
+ String alignmentCategory = "Component alignment";\r
+ createCategory(alignmentCategory, category);\r
+\r
+ LinkedHashMap<String, Alignment> options = new LinkedHashMap<String, Alignment>();\r
+ options.put("Top left", Alignment.TOP_LEFT);\r
+ options.put("Top center", Alignment.TOP_CENTER);\r
+ options.put("Top right", Alignment.TOP_RIGHT);\r
+\r
+ options.put("Middle left", Alignment.MIDDLE_LEFT);\r
+ options.put("Middle center", Alignment.MIDDLE_CENTER);\r
+ options.put("Middle right", Alignment.MIDDLE_RIGHT);\r
+\r
+ options.put("Bottom left", Alignment.BOTTOM_LEFT);\r
+ options.put("Bottom center", Alignment.BOTTOM_CENTER);\r
+ options.put("Bottom right", Alignment.BOTTOM_RIGHT);\r
+\r
+ for (int i = 0; i < 20; i++) {\r
+ String componentAlignmentCategory = "Component " + i + " alignment";\r
+ createCategory(componentAlignmentCategory, alignmentCategory);\r
+\r
+ for (String option : options.keySet()) {\r
+ createClickAction(option, componentAlignmentCategory,\r
+ setComponentAlignment, Integer.valueOf(i),\r
+ options.get(option));\r
+ }\r
+\r
+ }\r
+\r
+ }\r
}\r
--- /dev/null
+package com.vaadin.tests.components;\r
+\r
+import java.util.LinkedHashMap;\r
+\r
+import com.vaadin.event.LayoutEvents.LayoutClickEvent;\r
+import com.vaadin.event.LayoutEvents.LayoutClickListener;\r
+import com.vaadin.ui.AbstractOrderedLayout;\r
+import com.vaadin.ui.Component;\r
+\r
+public abstract class AbstractOrderedLayoutTest<T extends AbstractOrderedLayout>\r
+ extends AbstractLayoutTest<T> implements LayoutClickListener {\r
+\r
+ private Command<T, Boolean> layoutClickListenerCommand = new Command<T, Boolean>() {\r
+\r
+ public void execute(T c, Boolean value, Object data) {\r
+ if (value) {\r
+ c.addListener((LayoutClickListener) AbstractOrderedLayoutTest.this);\r
+ } else {\r
+\r
+ }\r
+\r
+ }\r
+ };\r
+\r
+ private Command<T, Integer> setComponentExpandRatio = new Command<T, Integer>() {\r
+\r
+ public void execute(T c, Integer value, Object ratio) {\r
+ Component child = getComponentAtIndex(c, value);\r
+ c.setExpandRatio(child, (Float) ratio);\r
+ }\r
+ };\r
+\r
+ @Override\r
+ protected void createActions() {\r
+ super.createActions();\r
+\r
+ createLayoutClickListenerAction(CATEGORY_LISTENERS);\r
+ createChangeComponentExpandRatioAction(CATEGORY_LAYOUT_FEATURES);\r
+ // Set a root style so we can see the component. Can be overridden by\r
+ // setting the style name in the UI\r
+ for (T c : getTestComponents()) {\r
+ c.setStyleName("background-lightblue");\r
+ }\r
+ }\r
+\r
+ private void createLayoutClickListenerAction(String category) {\r
+ createBooleanAction("Layout click listener", category, false,\r
+ layoutClickListenerCommand);\r
+ }\r
+\r
+ private void createChangeComponentExpandRatioAction(String category) {\r
+ String expandRatioCategory = "Component expand ratio";\r
+ createCategory(expandRatioCategory, category);\r
+\r
+ LinkedHashMap<String, Float> options = new LinkedHashMap<String, Float>();\r
+ options.put("0", 0f);\r
+ options.put("0.5", 0.5f);\r
+ for (float f = 1; f <= 5; f++) {\r
+ options.put(String.valueOf(f), f);\r
+ }\r
+\r
+ for (int i = 0; i < 20; i++) {\r
+ String componentExpandRatioCategory = "Component " + i\r
+ + " expand ratio";\r
+ createCategory(componentExpandRatioCategory, expandRatioCategory);\r
+\r
+ for (String option : options.keySet()) {\r
+ createClickAction(option, componentExpandRatioCategory,\r
+ setComponentExpandRatio, Integer.valueOf(i),\r
+ options.get(option));\r
+ }\r
+\r
+ }\r
+\r
+ }\r
+\r
+ public void layoutClick(LayoutClickEvent event) {\r
+ log(event.getClass().getSimpleName() + ": button="\r
+ + event.getButtonName() + ", childComponent="\r
+ + event.getChildComponent().getClass().getSimpleName()\r
+ + ", relativeX=" + event.getRelativeX() + ", relativeY="\r
+ + event.getRelativeY());\r
+\r
+ }\r
+}\r
--- /dev/null
+package com.vaadin.tests.components.orderedlayout;\r
+\r
+import com.vaadin.tests.components.AbstractOrderedLayoutTest;\r
+import com.vaadin.ui.HorizontalLayout;\r
+\r
+public class HorizontalLayoutTest extends\r
+ AbstractOrderedLayoutTest<HorizontalLayout> {\r
+\r
+ @Override\r
+ protected Class<HorizontalLayout> getTestClass() {\r
+ return HorizontalLayout.class;\r
+ }\r
+\r
+}
\ No newline at end of file
--- /dev/null
+package com.vaadin.tests.components.orderedlayout;\r
+\r
+import com.vaadin.tests.components.AbstractOrderedLayoutTest;\r
+import com.vaadin.ui.VerticalLayout;\r
+\r
+public class VerticalLayoutTest extends\r
+ AbstractOrderedLayoutTest<VerticalLayout> {\r
+\r
+ @Override\r
+ protected Class<VerticalLayout> getTestClass() {\r
+ return VerticalLayout.class;\r
+ }\r
+\r
+}\r