Browse Source

Merged test updates from 6.4

svn changeset:15547/svn branch:6.5
tags/6.7.0.beta1
Artur Signell 13 years ago
parent
commit
cce8df71d5

+ 164
- 0
tests/src/com/vaadin/tests/components/AbstractComponentTestCase.java View File

@@ -0,0 +1,164 @@
package com.vaadin.tests.components;

import java.util.ArrayList;
import java.util.List;

import com.vaadin.terminal.UserError;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Field;
import com.vaadin.ui.Layout.SpacingHandler;

public abstract class AbstractComponentTestCase<T extends AbstractComponent>
extends TestBase {

private List<T> testComponents = new ArrayList<T>();

abstract protected Class<T> getTestClass();

abstract protected void initializeComponents();

private Log log = null;

@Override
protected void setup() {
((SpacingHandler) getLayout()).setSpacing(true);

// Create Components
initializeComponents();
}

@Override
protected Integer getTicketNumber() {
return null;
}

protected void addTestComponent(T c) {
testComponents.add(c);
addComponent(c);
}

protected List<T> getTestComponents() {
return testComponents;
}

public interface Command<T, VALUETYPE extends Object> {
public void execute(T c, VALUETYPE value, Object data);
}

/* COMMANDS */

protected Command<T, String> widthCommand = new Command<T, String>() {

public void execute(T t, String value, Object data) {
t.setWidth(value);
}
};
protected Command<T, String> heightCommand = new Command<T, String>() {

public void execute(T t, String value, Object data) {
t.setHeight(value);
}
};

protected Command<T, Boolean> enabledCommand = new Command<T, Boolean>() {

public void execute(T c, Boolean enabled, Object data) {
c.setEnabled(enabled);
}
};

protected Command<T, Boolean> immediateCommand = new Command<T, Boolean>() {

public void execute(T c, Boolean immediate, Object data) {
c.setImmediate(immediate);
}
};

protected Command<T, Boolean> requiredCommand = new Command<T, Boolean>() {

public void execute(T c, Boolean enabled, Object data) {
if (c instanceof Field) {
((Field) c).setRequired(enabled);
} else {
throw new IllegalArgumentException(c.getClass().getName()
+ " is not a field and cannot be set to required");
}
}
};

protected Command<T, Boolean> errorIndicatorCommand = new Command<T, Boolean>() {

public void execute(T c, Boolean enabled, Object data) {
if (enabled) {
c.setComponentError(new UserError("It failed!"));
} else {
c.setComponentError(null);

}
}
};

protected Command<T, Boolean> readonlyCommand = new Command<T, Boolean>() {

public void execute(T c, Boolean enabled, Object data) {
c.setReadOnly(enabled);
}
};

protected <VALUET> void doCommand(Command<T, VALUET> command, VALUET value) {
doCommand(command, value, null);
}

protected <VALUET> void doCommand(Command<T, VALUET> command, VALUET value,
Object data) {
for (T c : getTestComponents()) {
command.execute(c, value, data);
}
}

protected <VALUET> void doCommand(String commandName,
Command<T, VALUET> command, VALUET value) {
doCommand(command, value, null);
if (hasLog()) {
log(commandName + ": " + value);
}
}

protected <VALUET> void doCommand(String commandName,
Command<T, VALUET> command, VALUET value, Object data) {
doCommand(command, value, data);
if (hasLog()) {
log(commandName + ": " + value);
}
}

protected boolean hasLog() {
return log != null;
}

@Override
protected String getDescription() {
return "Generic test case for " + getTestClass().getSimpleName();
}

protected void clearLog() {
log.clear();
}

protected void enableLog() {
if (log == null) {
log = new Log(5).setNumberLogRows(true);
getLayout().addComponent(log, 1);
}

}

protected void log(String msg) {
if (log == null) {
throw new IllegalStateException(
"Use enableLog() before calling log()");
}
log.log(msg);
}
}

+ 13
- 102
tests/src/com/vaadin/tests/components/ComponentTestCase.java View File

@@ -7,8 +7,6 @@ import java.util.List;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.terminal.UserError;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
@@ -17,49 +15,37 @@ import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.Field;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Layout.SpacingHandler;
import com.vaadin.ui.NativeSelect;

public abstract class ComponentTestCase<T extends AbstractComponent> extends
TestBase {
AbstractComponentTestCase<T> {

protected static final Object CAPTION = "caption";

private List<T> testComponents = new ArrayList<T>();
private HorizontalLayout actionLayout;

abstract protected Class<T> getTestClass();

abstract protected void initializeComponents();

private Log log = null;

@Override
protected final void setup() {
((SpacingHandler) getLayout()).setSpacing(true);

// Create action layout so it appears before the components
actionLayout = createActionLayout();
addComponent(actionLayout);

// Create Components
initializeComponents();
super.setup();

// Create actions and add to layout
populateActionLayout();
}

private void populateActionLayout() {
protected void populateActionLayout() {
for (Component c : createActions()) {
actionLayout.addComponent(c);
actionLayout.setComponentAlignment(c, Alignment.BOTTOM_LEFT);
addAction(c);
}

}

@Override
protected Integer getTicketNumber() {
return null;
private void addAction(Component c) {
actionLayout.addComponent(c);
actionLayout.setComponentAlignment(c, Alignment.BOTTOM_LEFT);
}

/**
@@ -104,69 +90,24 @@ public abstract class ComponentTestCase<T extends AbstractComponent> extends
return actionLayout;
}

protected void addTestComponent(T c) {
testComponents.add(c);
addComponent(c);
}

protected List<T> getTestComponents() {
return testComponents;
}

public interface Command<T, VALUETYPE extends Object> {
public void execute(T c, VALUETYPE value);

}

protected Component createErrorIndicatorAction(boolean initialState) {
return createCheckboxAction("Error indicators", initialState,
new Command<T, Boolean>() {
public void execute(T c, Boolean enabled) {
if (enabled) {
c.setComponentError(new UserError("It failed!"));
} else {
c.setComponentError(null);

}
}

});
return createBooleanAction("Error indicators", initialState,
errorIndicatorCommand);
}

protected Component createEnabledAction(boolean initialState) {
return createCheckboxAction("Enabled", initialState,
new Command<T, Boolean>() {
public void execute(T c, Boolean enabled) {
c.setEnabled(enabled);
}
});
return createBooleanAction("Enabled", initialState, enabledCommand);
}

protected Component createReadonlyAction(boolean initialState) {
return createCheckboxAction("Readonly", initialState,
new Command<T, Boolean>() {
public void execute(T c, Boolean enabled) {
c.setReadOnly(enabled);
}
});
return createBooleanAction("Readonly", initialState, readonlyCommand);
}

protected Component createRequiredAction(boolean initialState) {
return createCheckboxAction("Required", initialState,
new Command<T, Boolean>() {
public void execute(T c, Boolean enabled) {
if (c instanceof Field) {
((Field) c).setRequired(enabled);
} else {
throw new IllegalArgumentException(
c.getClass().getName()
+ " is not a field and cannot be set to required");
}
}
});
return createBooleanAction("Required", initialState, requiredCommand);
}

protected Component createCheckboxAction(String caption,
protected Component createBooleanAction(String caption,
boolean initialState, final Command<T, Boolean> command) {

CheckBox checkBox = new CheckBox(caption);
@@ -204,16 +145,6 @@ public abstract class ComponentTestCase<T extends AbstractComponent> extends
return button;
}

protected <VALUET> void doCommand(Command<T, VALUET> command, VALUET value) {
for (T c : getTestComponents()) {
if (c == null) {
continue;
}

command.execute(c, value);
}
}

protected <TYPE> Component createSelectAction(String caption,
LinkedHashMap<String, TYPE> options, String initialValue,
final Command<T, TYPE> command) {
@@ -255,24 +186,4 @@ public abstract class ComponentTestCase<T extends AbstractComponent> extends
return select;
}

@Override
protected String getDescription() {
return "Generic test case for " + getTestClass().getSimpleName();
}

protected void enableLog() {
if (log == null) {
log = new Log(5).setNumberLogRows(true);
getLayout().addComponent(log, 1);
}

}

protected void log(String msg) {
if (log == null) {
throw new IllegalStateException(
"Use enableLog() before calling log()");
}
log.log(msg);
}
}

+ 385
- 0
tests/src/com/vaadin/tests/components/MenuBasedComponentTestCase.java View File

@@ -0,0 +1,385 @@
package com.vaadin.tests.components;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.terminal.Resource;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.Field;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.MenuBar.MenuItem;
public abstract class MenuBasedComponentTestCase<T extends AbstractComponent>
extends AbstractComponentTestCase<T> {
private static final Resource SELECTED_ICON = new ThemeResource(
"../runo/icons/16/ok.png");
private MenuItem mainMenu;
private MenuBar menu;
private T component;
// Used to determine if a menuItem should be selected and the other
// unselected on click
private Set<MenuItem> parentOfSelectableMenuItem = new HashSet<MenuItem>();
protected static final String CATEGORY_STATE = "State";
protected static final String CATEGORY_SIZE = "Size";
protected static final String CATEGORY_SELECTION = "Selection";
protected static final String CATEGORY_CONTENT = "Contents";
protected static final String CATEGORY_LISTENERS = "Listeners";
@Override
protected final void setup() {
// Create menu here so it appears before the components
menu = new MenuBar();
mainMenu = menu.addItem("Settings", null);
addComponent(menu);
getLayout().setSizeFull();
enableLog();
super.setup();
// Create menu actions and trigger default actions
populateMenu();
// Clear initialization log messages
clearLog();
}
/**
* By default initializes just one instance of {@link #getTestClass()} using
* {@link #constructComponent()}.
*/
@Override
protected void initializeComponents() {
component = constructComponent();
addTestComponent(component);
}
public T getComponent() {
return component;
}
@Override
protected void addTestComponent(T c) {
super.addTestComponent(c);
getLayout().setExpandRatio(c, 1);
};
/**
* Construct the component that is to be tested. This method uses a no-arg
* constructor by default. Override to customize.
*
* @return Instance of the component that is to be tested.
* @throws IllegalAccessException
* @throws InstantiationException
*/
protected T constructComponent() {
try {
return getTestClass().newInstance();
} catch (Exception e) {
throw new RuntimeException("Failed to instantiate "
+ getTestClass(), e);
}
}
private void populateMenu() {
createDefaultActions();
createCustomActions();
}
private void createDefaultActions() {
createBooleanAction("Immediate", CATEGORY_STATE, true, immediateCommand);
createBooleanAction("Enabled", CATEGORY_STATE, true, enabledCommand);
createBooleanAction("Readonly", CATEGORY_STATE, false, readonlyCommand);
createBooleanAction("Error indicator", CATEGORY_STATE, false,
errorIndicatorCommand);
if (component instanceof Field) {
createBooleanAction("Required", CATEGORY_STATE, false,
requiredCommand);
}
createWidthSelect(CATEGORY_SIZE);
createHeightSelect(CATEGORY_SIZE);
if (component instanceof AbstractSelect) {
createNullSelectAllowedCheckbox(CATEGORY_SELECTION);
createItemsInContainerSelect(CATEGORY_CONTENT);
createColumnsInContainerSelect(CATEGORY_CONTENT);
}
}
@SuppressWarnings("unchecked")
protected void createItemsInContainerSelect(String category) {
LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
options.put("0", 0);
options.put("20", 20);
options.put("100", 100);
options.put("1000", 1000);
options.put("10000", 10000);
options.put("100000", 100000);
createSelectAction("Items in container", category, options, "20",
(Command) itemsInContainerCommand);
}
@SuppressWarnings("unchecked")
protected void createColumnsInContainerSelect(String category) {
LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
options.put("0", 0);
options.put("5", 5);
options.put("10", 10);
options.put("50", 50);
options.put("100", 100);
options.put("1000", 1000);
createSelectAction("Columns in container", category, options, "10",
(Command) columnsInContainerCommand);
}
private Container createContainer(int properties, int items) {
IndexedContainer c = new IndexedContainer();
for (int i = 1; i <= properties; i++) {
c.addContainerProperty("Column " + i, String.class, "");
}
for (int i = 1; i <= items; i++) {
Item item = c.addItem("Item " + i);
for (int j = 1; j <= properties; j++) {
item.getItemProperty("Column " + j).setValue(
"Item " + i + "," + j);
}
}
return c;
}
@SuppressWarnings("unchecked")
protected void createNullSelectAllowedCheckbox(String category) {
createBooleanAction("Null Selection Allowed", category, false,
(Command) nullSelectionAllowedCommand);
}
@SuppressWarnings("unchecked")
protected void createNullSelectItemId(String category) {
LinkedHashMap<String, Object> options = new LinkedHashMap<String, Object>();
options.put("- None -", null);
for (Object id : ((AbstractSelect) component).getContainerDataSource()
.getContainerPropertyIds()) {
options.put(id.toString(), id);
}
createSelectAction("Null Selection Item Id", category, options,
"- None -", (Command) nullSelectItemIdCommand);
}
protected void createWidthSelect(String category) {
LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
options.put("Undefined", null);
options.put("50%", "50%");
options.put("100%", "100%");
for (int w = 200; w < 1000; w += 100) {
options.put(w + "px", w + "px");
}
createSelectAction("Width", category, options, "Undefined",
widthCommand, null);
}
protected void createHeightSelect(String category) {
LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
options.put("Undefined", null);
options.put("50%", "50%");
options.put("100%", "100%");
for (int w = 200; w < 1000; w += 100) {
options.put(w + "px", w + "px");
}
createSelectAction("Height", category, options, "Undefined",
heightCommand, null);
}
protected void createBooleanAction(String caption, String category,
boolean initialState, final Command<T, Boolean> command) {
createBooleanAction(caption, category, initialState, command, null);
}
protected <DATATYPE> void createBooleanAction(String caption,
String category, boolean initialState,
final Command<T, Boolean> command, Object data) {
MenuItem categoryItem = getCategoryMenuItem(category);
MenuItem item = categoryItem.addItem(caption,
menuBooleanCommand(command, data));
setSelected(item, initialState);
doCommand(caption, command, initialState, data);
}
private MenuItem getCategoryMenuItem(String category) {
if (category == null) {
return getCategoryMenuItem("Misc");
}
if (mainMenu.getChildren() != null) {
for (MenuItem i : mainMenu.getChildren()) {
if (i.getText().equals(category)) {
return i;
}
}
}
return mainMenu.addItem(category, null);
}
/**
* Provide custom actions for the test case by creating them in this method.
*/
protected abstract void createCustomActions();
private MenuBar.Command menuBooleanCommand(
final com.vaadin.tests.components.ComponentTestCase.Command<T, Boolean> booleanCommand,
final Object data) {
return new MenuBar.Command() {
public void menuSelected(MenuItem selectedItem) {
boolean selected = !isSelected(selectedItem);
doCommand(getText(selectedItem), booleanCommand, selected, data);
setSelected(selectedItem, selected);
}
};
}
protected void setSelected(MenuItem item, boolean selected) {
if (selected) {
item.setIcon(SELECTED_ICON);
} else {
item.setIcon(null);
}
}
protected boolean isSelected(MenuItem item) {
return (item.getIcon() != null);
}
private <VALUETYPE> MenuBar.Command singleSelectMenuCommand(
final com.vaadin.tests.components.ComponentTestCase.Command<T, VALUETYPE> cmd,
final VALUETYPE object, final Object data) {
return new MenuBar.Command() {
public void menuSelected(MenuItem selectedItem) {
doCommand(getText(selectedItem), cmd, object, data);
if (parentOfSelectableMenuItem.contains(selectedItem
.getParent())) {
unselectChildren(selectedItem.getParent());
setSelected(selectedItem, true);
}
}
};
}
/**
* Unselect all child menu items
*
* @param parent
*/
protected void unselectChildren(MenuItem parent) {
List<MenuItem> children = parent.getChildren();
if (children == null) {
return;
}
for (MenuItem child : children) {
setSelected(child, false);
}
}
protected String getText(MenuItem item) {
if (!isCategory(item.getParent())) {
return item.getParent().getText();
} else {
return item.getText();
}
}
private boolean isCategory(MenuItem item) {
return item.getParent() == mainMenu;
}
protected <TYPE> void createSelectAction(
String caption,
String category,
LinkedHashMap<String, TYPE> options,
String initialValue,
com.vaadin.tests.components.ComponentTestCase.Command<T, TYPE> command) {
createSelectAction(caption, category, options, initialValue, command,
null);
}
protected <TYPE> void createSelectAction(
String caption,
String category,
LinkedHashMap<String, TYPE> options,
String initialValue,
com.vaadin.tests.components.ComponentTestCase.Command<T, TYPE> command,
Object data) {
MenuItem parentItem = getCategoryMenuItem(category);
MenuItem mainItem = parentItem.addItem(caption, null);
parentOfSelectableMenuItem.add(mainItem);
for (String option : options.keySet()) {
MenuBar.Command cmd = singleSelectMenuCommand(command,
options.get(option), data);
MenuItem item = mainItem.addItem(option, cmd);
if (option.equals(initialValue)) {
cmd.menuSelected(item);
}
}
}
/* COMMANDS */
protected Command<AbstractSelect, Boolean> nullSelectionAllowedCommand = new Command<AbstractSelect, Boolean>() {
public void execute(AbstractSelect c, Boolean value, Object data) {
(c).setNullSelectionAllowed(value);
}
};
protected Command<AbstractSelect, Object> nullSelectItemIdCommand = new Command<AbstractSelect, Object>() {
public void execute(AbstractSelect c, Object value, Object data) {
c.setNullSelectionItemId(value);
}
};
protected Command<AbstractSelect, Integer> itemsInContainerCommand = new Command<AbstractSelect, Integer>() {
public void execute(AbstractSelect t, Integer value, Object data) {
t.setContainerDataSource(createContainer(t.getContainerDataSource()
.getContainerPropertyIds().size(), value));
}
};
protected Command<AbstractSelect, Integer> columnsInContainerCommand = new Command<AbstractSelect, Integer>() {
public void execute(AbstractSelect t, Integer value, Object data) {
t.setContainerDataSource(createContainer(value, t
.getContainerDataSource().size()));
}
};
/* COMMANDS END */
}

+ 1
- 1
tests/src/com/vaadin/tests/components/combobox/Comboboxes.java View File

@@ -136,7 +136,7 @@ public class Comboboxes extends ComponentTestCase<ComboBox> {
return createSelectAction("Icon", options, "<None>",
new Command<ComboBox, String>() {

public void execute(ComboBox c, String value) {
public void execute(ComboBox c, String value, Object data) {
for (Object id : c.getItemIds()) {
if (value == null) {
c.setItemIcon(id, null);

+ 4
- 2
tests/src/com/vaadin/tests/components/datefield/InlineDateFields.java View File

@@ -77,7 +77,8 @@ public class InlineDateFields extends ComponentTestCase<InlineDateField> {
return createSelectAction("Resolution", options, "Year",
new Command<InlineDateField, Integer>() {
public void execute(InlineDateField c, Integer value) {
public void execute(InlineDateField c, Integer value,
Object data) {
c.setResolution(value);
}
@@ -92,7 +93,8 @@ public class InlineDateFields extends ComponentTestCase<InlineDateField> {
return createSelectAction("Locale", options, LOCALES[0].toString(),
new Command<InlineDateField, Locale>() {
public void execute(InlineDateField c, Locale value) {
public void execute(InlineDateField c, Locale value,
Object data) {
c.setCaption(c.getCaption().replaceAll(
c.getLocale().toString(), value.toString()));
c.setLocale(value);

+ 4
- 2
tests/src/com/vaadin/tests/components/datefield/PopupDateFields.java View File

@@ -77,7 +77,8 @@ public class PopupDateFields extends ComponentTestCase<PopupDateField> {
return createSelectAction("Resolution", options, "Year",
new Command<PopupDateField, Integer>() {
public void execute(PopupDateField c, Integer value) {
public void execute(PopupDateField c, Integer value,
Object data) {
c.setResolution(value);
}
@@ -93,7 +94,8 @@ public class PopupDateFields extends ComponentTestCase<PopupDateField> {
return createSelectAction("Input prompt", options, "<none>",
new Command<PopupDateField, String>() {
public void execute(PopupDateField c, String value) {
public void execute(PopupDateField c, String value,
Object data) {
c.setInputPrompt(value);
}

+ 4
- 2
tests/src/com/vaadin/tests/components/optiongroup/DisabledOptionGroupItems.java View File

@@ -52,7 +52,8 @@ public class DisabledOptionGroupItems extends ComponentTestCase<OptionGroup> {
return createButtonAction("Toggle selection mode",
new Command<OptionGroup, Boolean>() {

public void execute(OptionGroup og, Boolean value) {
public void execute(OptionGroup og, Boolean value,
Object data) {
if (og.isMultiSelect()) {
og.setMultiSelect(false);
og.setNullSelectionItemId(NULL_SELECTION_ID);
@@ -68,7 +69,8 @@ public class DisabledOptionGroupItems extends ComponentTestCase<OptionGroup> {
return createButtonAction("Invert disabled items",
new Command<OptionGroup, Boolean>() {

public void execute(OptionGroup c, Boolean value) {
public void execute(OptionGroup c, Boolean value,
Object data) {
for (Object itemId : c.getItemIds()) {
c.setItemEnabled(itemId, !c.isItemEnabled(itemId));
}

+ 3
- 2
tests/src/com/vaadin/tests/components/select/NativeSelects.java View File

@@ -105,10 +105,11 @@ public class NativeSelects extends ComponentTestCase<NativeSelect> {

@Override
protected void createCustomActions(List<Component> actions) {
actions.add(createCheckboxAction("Null selection allowed", false,
actions.add(createBooleanAction("Null selection allowed", false,
new Command<NativeSelect, Boolean>() {

public void execute(NativeSelect c, Boolean value) {
public void execute(NativeSelect c, Boolean value,
Object data) {
c.setNullSelectionAllowed(value);
}
}));

+ 204
- 229
tests/src/com/vaadin/tests/components/table/Tables.java View File

@@ -1,16 +1,14 @@
package com.vaadin.tests.components.table;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.tests.components.ComponentTestCase;
import com.vaadin.tests.components.MenuBasedComponentTestCase;
import com.vaadin.ui.AbstractSelect.MultiSelectMode;
import com.vaadin.ui.Component;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.ColumnResizeEvent;
import com.vaadin.ui.Table.ColumnResizeListener;
@@ -19,68 +17,163 @@ import com.vaadin.ui.Table.FooterClickListener;
import com.vaadin.ui.Table.HeaderClickEvent;
import com.vaadin.ui.Table.HeaderClickListener;
public class Tables extends ComponentTestCase<Table> implements
public class Tables extends MenuBasedComponentTestCase<Table> implements
ItemClickListener, HeaderClickListener, FooterClickListener,
ColumnResizeListener {
protected static final String CATEGORY_ROWS = "Rows";
private static final String CATEGORY_HEADER = "Header";
private static final String CATEGORY_FOOTER = "Footer";
private static final String CATEGORY_FEATURE_TOGGLES = "Features";
private static final String CATEGORY_VISIBLE_COLUMNS = "Visible columns";
/* COMMANDS */
private Command<Table, Boolean> visibleColumnCommand = new Command<Table, Boolean>() {
public void execute(Table c, Boolean visible, Object propertyId) {
List<Object> visibleColumns = new ArrayList<Object>(Arrays.asList(c
.getVisibleColumns()));
if (visible) {
// Table should really check this... Completely fails without
// the check (#
if (!visibleColumns.contains(propertyId)) {
visibleColumns.add(propertyId);
}
} else {
visibleColumns.remove(propertyId);
}
c.setVisibleColumns(visibleColumns.toArray());
}
};
protected Command<Table, Boolean> columnResizeListenerCommand = new Command<Table, Boolean>() {
public void execute(Table c, Boolean value, Object data) {
if (value) {
c.addListener((ColumnResizeListener) Tables.this);
} else {
c.removeListener((ColumnResizeListener) Tables.this);
}
}
};
protected Command<Table, Boolean> headerClickListenerCommand = new Command<Table, Boolean>() {
public void execute(Table c, Boolean value, Object data) {
if (value) {
c.addListener((HeaderClickListener) Tables.this);
} else {
c.removeListener((HeaderClickListener) Tables.this);
}
}
};
protected Command<Table, Boolean> footerClickListenerCommand = new Command<Table, Boolean>() {
public void execute(Table c, Boolean value, Object data) {
if (value) {
c.addListener((FooterClickListener) Tables.this);
} else {
c.removeListener((FooterClickListener) Tables.this);
}
}
};
protected Command<Table, Integer> rowHeaderModeCommand = new Command<Table, Integer>() {
public void execute(Table c, Integer value, Object data) {
if (value == Table.ROW_HEADER_MODE_PROPERTY) {
c.setItemCaptionPropertyId("Column 3");
}
c.setRowHeaderMode(value);
}
};
protected Command<Table, String> footerTextCommand = new Command<Table, String>() {
public void execute(Table c, String value, Object data) {
for (Object propertyId : c.getContainerPropertyIds()) {
if (value != null) {
c.setColumnFooter(propertyId,
value.replace("{id}", propertyId.toString()));
} else {
c.setColumnFooter(propertyId, null);
}
}
}
};
public class Alignments {
}
protected Command<Table, Alignments> columnAlignmentCommand = new Command<Table, Alignments>() {
public void execute(Table c, Alignments value, Object data) {
for (Object propertyId : c.getContainerPropertyIds()) {
// TODO
}
}
};
/* COMMANDS END */
@Override
protected Class<Table> getTestClass() {
return Table.class;
}
@Override
protected void initializeComponents() {
addTestComponent(createTable());
enableLog();
protected void createCustomActions() {
createPageLengthSelect(CATEGORY_SIZE);
}
createSelectionModeSelect(CATEGORY_SELECTION);
private Table createTable() {
Table t = new Table();
return t;
}
createItemClickListenerCheckbox(CATEGORY_LISTENERS);
createColumnResizeListenerCheckbox(CATEGORY_LISTENERS);
createHeaderClickListenerCheckbox(CATEGORY_LISTENERS);
createFooterClickListenerCheckbox(CATEGORY_LISTENERS);
private Container createContainer(int properties, int items) {
IndexedContainer c = new IndexedContainer();
for (int i = 1; i <= properties; i++) {
c.addContainerProperty("Column " + i, String.class, "");
}
for (int i = 1; i <= items; i++) {
Item item = c.addItem("Item " + i);
for (int j = 1; j <= properties; j++) {
item.getItemProperty("Column " + j).setValue(
"Item " + i + "," + j);
}
}
createRowHeaderModeSelect(CATEGORY_CONTENT);
createHeaderVisibilitySelect(CATEGORY_HEADER);
createHeaderTextCheckbox(CATEGORY_HEADER);
createFooterVisibilityCheckbox(CATEGORY_FOOTER);
createFooterTextSelect(CATEGORY_FOOTER);
createColumnReorderingAllowedCheckbox(CATEGORY_FEATURE_TOGGLES);
createColumnCollapsingAllowedCheckbox(CATEGORY_FEATURE_TOGGLES);
createVisibleColumnsMultiToggle(CATEGORY_VISIBLE_COLUMNS);
return c;
}
@Override
protected void createCustomActions(List<Component> actions) {
actions.add(createNullSelectCheckbox());
actions.add(createWidthSelect());
actions.add(createHeightSelect());
actions.add(createPageLengthSelect());
actions.add(createItemsInContainerSelect());
actions.add(createColumnsInContainerSelect());
actions.add(createSelectionModeSelect());
actions.add(createItemClickListenerCheckbox());
actions.add(createColumnResizeListenerCheckbox());
actions.add(createRowHeaderModeSelect());
actions.add(createHeaderVisibilitySelect());
actions.add(createHeaderClickListenerCheckbox());
actions.add(createHeaderTextCheckbox());
actions.add(createFooterVisibilityCheckbox());
actions.add(createFooterClickListenerCheckbox());
actions.add(createFooterTextCheckbox());
private void createColumnReorderingAllowedCheckbox(String category) {
createBooleanAction("Column reordering allowed", category, true,
new Command<Table, Boolean>() {
public void execute(Table c, Boolean value, Object data) {
c.setColumnReorderingAllowed(value);
}
});
}
private void createColumnCollapsingAllowedCheckbox(String category) {
createBooleanAction("Column collapsing allowed", category, true,
new Command<Table, Boolean>() {
public void execute(Table c, Boolean value, Object data) {
c.setColumnCollapsingAllowed(value);
}
});
}
private void createVisibleColumnsMultiToggle(String category) {
for (Object id : getComponent().getContainerPropertyIds()) {
createBooleanAction(id.toString() + " - visible", category, true,
visibleColumnCommand, id);
}
}
private Component createRowHeaderModeSelect() {
private void createRowHeaderModeSelect(String category) {
LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
options.put("Explicit", Table.ROW_HEADER_MODE_EXPLICIT);
options.put("Explicit defaults id",
@@ -92,50 +185,42 @@ public class Tables extends ComponentTestCase<Table> implements
options.put("Item", Table.ROW_HEADER_MODE_ITEM);
options.put("'Column 3' property", Table.ROW_HEADER_MODE_PROPERTY);
return super.createSelectAction("Row header mode", options, "Hidden",
new Command<Table, Integer>() {
public void execute(Table c, Integer value) {
if (value == Table.ROW_HEADER_MODE_PROPERTY) {
c.setItemCaptionPropertyId("Column 3");
}
c.setRowHeaderMode(value);
}
});
createSelectAction("Row header mode", category, options, "Hidden",
rowHeaderModeCommand);
}
private Component createFooterTextCheckbox() {
return super.createCheckboxAction("Texts in footer", false,
new Command<Table, Boolean>() {
public void execute(Table c, Boolean value) {
for (Object propertyId : c.getContainerPropertyIds()) {
if (value) {
c.setColumnFooter(propertyId, "Footer: "
+ propertyId);
} else {
c.setColumnFooter(propertyId, null);
}
}
private void createFooterTextSelect(String category) {
LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
options.put("None", null);
options.put("Footer X", "Footer {id}");
options.put("X", "{id}");
}
});
createSelectAction("Texts in footer", category, options, "None",
footerTextCommand);
}
private Component createHeaderTextCheckbox() {
return super.createCheckboxAction("Texts in header", false,
new Command<Table, Boolean>() {
private void createHeaderTextCheckbox(String category) {
LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
options.put("None", null);
options.put("Col: {id}", "Col: {id}");
options.put("Header {id} - every second", "Header {id}");
public void execute(Table c, Boolean value) {
createSelectAction("Texts in header", category, options, "None",
new Command<Table, String>() {
public void execute(Table c, String value, Object data) {
int nr = 0;
for (Object propertyId : c.getContainerPropertyIds()) {
if (value) {
c.setColumnHeader(propertyId, "Header: "
+ propertyId);
nr++;
if (value != null && value.equals("Header {id}")
&& nr % 2 == 0) {
c.setColumnHeader(propertyId, null);
} else if (value != null) {
c.setColumnHeader(
propertyId,
value.replace("{id}",
propertyId.toString()));
} else {
c.setColumnHeader(propertyId, null);
}
}
@@ -143,77 +228,47 @@ public class Tables extends ComponentTestCase<Table> implements
});
}
private Component createItemClickListenerCheckbox() {
return super.createCheckboxAction("Item click listener", false,
new Command<Table, Boolean>() {
private void createItemClickListenerCheckbox(String category) {
Command<Table, Boolean> itemClickListenerCommand = new Command<Table, Boolean>() {
public void execute(Table c, Boolean value) {
if (value) {
c.addListener((ItemClickListener) Tables.this);
} else {
c.removeListener((ItemClickListener) Tables.this);
}
public void execute(Table c, Boolean value, Object data) {
if (value) {
c.addListener((ItemClickListener) Tables.this);
} else {
c.removeListener((ItemClickListener) Tables.this);
}
}
});
}
};
createBooleanAction("Item click listener", category, false,
itemClickListenerCommand);
}
private Component createHeaderClickListenerCheckbox() {
return super.createCheckboxAction("Header click listener", false,
new Command<Table, Boolean>() {
private void createHeaderClickListenerCheckbox(String category) {
public void execute(Table c, Boolean value) {
if (value) {
c.addListener((HeaderClickListener) Tables.this);
} else {
c.removeListener((HeaderClickListener) Tables.this);
}
}
});
createBooleanAction("Header click listener", category, false,
headerClickListenerCommand);
}
private Component createFooterClickListenerCheckbox() {
return super.createCheckboxAction("Footer click listener", false,
new Command<Table, Boolean>() {
public void execute(Table c, Boolean value) {
if (value) {
c.addListener((FooterClickListener) Tables.this);
} else {
c.removeListener((FooterClickListener) Tables.this);
}
private void createFooterClickListenerCheckbox(String category) {
}
});
createBooleanAction("Footer click listener", category, false,
footerClickListenerCommand);
}
private Component createColumnResizeListenerCheckbox() {
return super.createCheckboxAction("Column resize listener", false,
new Command<Table, Boolean>() {
private void createColumnResizeListenerCheckbox(String category) {
public void execute(Table c, Boolean value) {
if (value) {
c.addListener((ColumnResizeListener) Tables.this);
} else {
c.removeListener((ColumnResizeListener) Tables.this);
}
}
});
createBooleanAction("Column resize listener", category, false,
columnResizeListenerCommand);
}
// TODO:
// Visible columns
// Column headers
// Column footers
// Column icons
// Column alignments
// Column width
// Column expand ratio
// Column collapse
// Column reordering allowed
// Column collapsing allowed
// setCurrentPageFirstItemIndex()
// setColumnHeaderMode(int)
// setRowHeaderMode(int)
@@ -224,27 +279,18 @@ public class Tables extends ComponentTestCase<Table> implements
// Cache rate
// CurrentPageFirstItemId
private Component createNullSelectCheckbox() {
return super.createCheckboxAction("NullSelection", false,
new Command<Table, Boolean>() {
public void execute(Table c, Boolean value) {
c.setNullSelectionAllowed(value);
}
});
}
private Component createFooterVisibilityCheckbox() {
return createCheckboxAction("Footer visible", true,
protected void createFooterVisibilityCheckbox(String category) {
createBooleanAction("Footer visible", category, true,
new Command<Table, Boolean>() {
public void execute(Table c, Boolean value) {
public void execute(Table c, Boolean value, Object data) {
c.setFooterVisible(value);
}
});
}
private Component createHeaderVisibilitySelect() {
protected void createHeaderVisibilitySelect(String category) {
LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
options.put("Explicit", Table.COLUMN_HEADER_MODE_EXPLICIT);
options.put("Explicit defaults id",
@@ -252,49 +298,17 @@ public class Tables extends ComponentTestCase<Table> implements
options.put("Id", Table.COLUMN_HEADER_MODE_ID);
options.put("Hidden", Table.COLUMN_HEADER_MODE_HIDDEN);
return createSelectAction("Header mode", options,
createSelectAction("Header mode", category, options,
"Explicit defaults id", new Command<Table, Integer>() {
public void execute(Table c, Integer value) {
public void execute(Table c, Integer value, Object data) {
c.setColumnHeaderMode(value);
}
});
}
protected Component createWidthSelect() {
LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
options.put("Undefined", null);
options.put("200px", "200px");
options.put("500px", "500px");
options.put("800px", "800px");
return super.createSelectAction("Width", options, "Undefined",
new Command<Table, String>() {
public void execute(Table t, String value) {
t.setWidth(value);
}
});
}
protected Component createHeightSelect() {
LinkedHashMap<String, String> options = new LinkedHashMap<String, String>();
options.put("Undefined", null);
options.put("200px", "200px");
options.put("500px", "500px");
options.put("800px", "800px");
return super.createSelectAction("Height", options, "Undefined",
new Command<Table, String>() {
public void execute(Table t, String value) {
t.setHeight(value);
}
});
}
protected Component createPageLengthSelect() {
protected void createPageLengthSelect(String category) {
LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
options.put("0", 0);
options.put("5", 5);
@@ -302,69 +316,30 @@ public class Tables extends ComponentTestCase<Table> implements
options.put("20", 20);
options.put("50", 50);
return super.createSelectAction("PageLength", options, "10",
createSelectAction("PageLength", category, options, "10",
new Command<Table, Integer>() {
public void execute(Table t, Integer value) {
public void execute(Table t, Integer value, Object data) {
t.setPageLength(value);
}
});
}
protected Component createItemsInContainerSelect() {
LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
options.put("0", 0);
options.put("20", 20);
options.put("100", 100);
options.put("1000", 1000);
options.put("10000", 10000);
options.put("100000", 100000);
return super.createSelectAction("Items in container", options, "20",
new Command<Table, Integer>() {
public void execute(Table t, Integer value) {
t.setContainerDataSource(createContainer(t
.getContainerDataSource()
.getContainerPropertyIds().size(), value));
}
});
}
protected Component createColumnsInContainerSelect() {
LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
options.put("0", 0);
options.put("5", 5);
options.put("10", 10);
options.put("50", 50);
options.put("100", 100);
options.put("1000", 1000);
return super.createSelectAction("Columns in container", options, "10",
new Command<Table, Integer>() {
public void execute(Table t, Integer value) {
t.setContainerDataSource(createContainer(value, t
.getContainerDataSource().size()));
}
});
}
private enum SelectMode {
NONE, SINGLE, MULTI_SIMPLE, MULTI;
}
protected Component createSelectionModeSelect() {
protected void createSelectionModeSelect(String category) {
LinkedHashMap<String, SelectMode> options = new LinkedHashMap<String, SelectMode>();
options.put("None", SelectMode.NONE);
options.put("Single", SelectMode.SINGLE);
options.put("Multi - simple", SelectMode.MULTI_SIMPLE);
options.put("Multi - ctrl/shift", SelectMode.MULTI);
return super.createSelectAction("Selection Mode", options,
createSelectAction("Selection Mode", category, options,
"Multi - ctrl/shift", new Command<Table, SelectMode>() {
public void execute(Table t, SelectMode value) {
public void execute(Table t, SelectMode value, Object data) {
switch (value) {
case NONE:
t.setSelectable(false);
@@ -404,7 +379,7 @@ public class Tables extends ComponentTestCase<Table> implements
}
public void itemClick(ItemClickEvent event) {
log("ItemClick on " + event.getPropertyId() + " using "
+ event.getButtonName());
log("ItemClick on " + event.getItemId() + "/" + event.getPropertyId()
+ " using " + event.getButtonName());
}
}

+ 1
- 1
tests/src/com/vaadin/tests/components/upload/TestUploadAndDisableOnSuccess.java View File

@@ -81,7 +81,7 @@ public class TestUploadAndDisableOnSuccess extends ComponentTestCase<Upload>
actions.add(createButtonAction("Toggle Enabled",
new Command<Upload, Boolean>() {
public void execute(Upload c, Boolean value) {
public void execute(Upload c, Boolean value, Object data) {
c.setEnabled(!c.isEnabled());
}
}));

Loading…
Cancel
Save