aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/main/java
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-09-12 22:29:25 +0300
committerVaadin Code Review <review@vaadin.com>2016-09-13 08:36:23 +0000
commit29cdc9873442b8051066810e866bcc2b3f010a59 (patch)
tree068614020e234826e1ee68abdbe40ea70c9fa324 /uitest/src/main/java
parent8b91ebd61bf72d4f1fb2925cea073de297da94fa (diff)
downloadvaadin-framework-29cdc9873442b8051066810e866bcc2b3f010a59.tar.gz
vaadin-framework-29cdc9873442b8051066810e866bcc2b3f010a59.zip
Add context event support to new Grid
Change-Id: I21c5bb95feb3dbab1b543943adc0584aa8eec87b
Diffstat (limited to 'uitest/src/main/java')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/contextclick/GridContextClick.java75
-rw-r--r--uitest/src/main/java/com/vaadin/tests/util/PersonContainer.java20
2 files changed, 63 insertions, 32 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/contextclick/GridContextClick.java b/uitest/src/main/java/com/vaadin/tests/contextclick/GridContextClick.java
index 22c0331059..e5d33ab17a 100644
--- a/uitest/src/main/java/com/vaadin/tests/contextclick/GridContextClick.java
+++ b/uitest/src/main/java/com/vaadin/tests/contextclick/GridContextClick.java
@@ -15,27 +15,44 @@
*/
package com.vaadin.tests.contextclick;
+import java.util.Collections;
+
+import com.vaadin.shared.ui.grid.GridConstants.Section;
+import com.vaadin.tests.util.Person;
import com.vaadin.tests.util.PersonContainer;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.GridContextClickEvent;
import com.vaadin.ui.HorizontalLayout;
-import com.vaadin.v7.data.Item;
-import com.vaadin.v7.shared.ui.grid.GridConstants.Section;
-import com.vaadin.v7.ui.Grid;
-import com.vaadin.v7.ui.Grid.GridContextClickEvent;
-public class GridContextClick
- extends AbstractContextClickUI<Grid, GridContextClickEvent> {
+public class GridContextClick extends
+ AbstractContextClickUI<Grid<Person>, GridContextClickEvent<Person>> {
@Override
- protected Grid createTestComponent() {
- Grid grid = new Grid(PersonContainer.createWithTestData());
- grid.setFooterVisible(true);
- grid.appendFooterRow();
+ protected Grid<Person> createTestComponent() {
+ Grid<Person> grid = new Grid<>();
+ grid.setItems(PersonContainer.createTestData());
+ grid.addColumn("Address",
+ person -> String.valueOf(person.getAddress()));
+ grid.addColumn("Email", person -> String.valueOf(person.getEmail()));
+ grid.addColumn("First Name",
+ person -> String.valueOf(person.getFirstName()));
+ grid.addColumn("Last Name",
+ person -> String.valueOf(person.getLastName()));
+ grid.addColumn("Phone Number",
+ person -> String.valueOf(person.getPhoneNumber()));
+ grid.addColumn("Street Address", person -> String
+ .valueOf(person.getAddress().getStreetAddress()));
+ grid.addColumn("City",
+ person -> String.valueOf(person.getAddress().getCity()));
+
+ // grid.setFooterVisible(true);
+ // grid.appendFooterRow();
- grid.setColumnOrder("address", "email", "firstName", "lastName",
- "phoneNumber", "address.streetAddress", "address.postalCode",
- "address.city");
+ // grid.setColumnOrder("address", "email", "firstName", "lastName",
+ // "phoneNumber", "address.streetAddress", "address.postalCode",
+ // "address.city");
grid.setWidth("100%");
grid.setHeight("400px");
@@ -44,23 +61,27 @@ public class GridContextClick
}
@Override
- protected void handleContextClickEvent(GridContextClickEvent event) {
+ protected void handleContextClickEvent(
+ GridContextClickEvent<Person> event) {
String value = "";
- Object propertyId = event.getPropertyId();
- if (event.getItemId() != null) {
- Item item = event.getComponent().getContainerDataSource()
- .getItem(event.getItemId());
- value += item.getItemProperty("firstName").getValue();
- value += " " + item.getItemProperty("lastName").getValue();
+ Person person = event.getItem();
+ if (event.getItem() != null) {
+ value = person.getFirstName() + " " + person.getLastName();
} else if (event.getSection() == Section.HEADER) {
- value = event.getComponent().getHeaderRow(event.getRowIndex())
- .getCell(propertyId).getText();
+ value = event.getColumn().getCaption();
} else if (event.getSection() == Section.FOOTER) {
- value = event.getComponent().getFooterRow(event.getRowIndex())
- .getCell(propertyId).getText();
+ value = event.getColumn().getCaption();
+ }
+
+ if (event.getColumn() != null) {
+ log("ContextClickEvent value: " + value + ", column: "
+ + event.getColumn().getCaption() + ", section: "
+ + event.getSection());
+ } else {
+ log("ContextClickEvent value: " + value + ", section: "
+ + event.getSection());
+
}
- log("ContextClickEvent value: " + value + ", propertyId: " + propertyId
- + ", section: " + event.getSection());
}
@Override
@@ -71,7 +92,7 @@ public class GridContextClick
@Override
public void buttonClick(ClickEvent event) {
- testComponent.getContainerDataSource().removeAllItems();
+ testComponent.setItems(Collections.emptyList());
}
}));
return controls;
diff --git a/uitest/src/main/java/com/vaadin/tests/util/PersonContainer.java b/uitest/src/main/java/com/vaadin/tests/util/PersonContainer.java
index cb7c3c28a5..caedc9f299 100644
--- a/uitest/src/main/java/com/vaadin/tests/util/PersonContainer.java
+++ b/uitest/src/main/java/com/vaadin/tests/util/PersonContainer.java
@@ -1,6 +1,8 @@
package com.vaadin.tests.util;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Random;
import com.vaadin.v7.data.util.BeanItemContainer;
@@ -36,9 +38,18 @@ public class PersonContainer extends BeanItemContainer<Person>
}
public static PersonContainer createWithTestData(int size) {
- PersonContainer c = null;
+ PersonContainer c = new PersonContainer();
+ c.addAll(createTestData(size));
+ return c;
+ }
+
+ public static Collection<Person> createTestData() {
+ return createTestData(100);
+ }
+
+ public static Collection<Person> createTestData(int size) {
Random r = new Random(0);
- c = new PersonContainer();
+ ArrayList<Person> testData = new ArrayList<>();
for (int i = 0; i < size; i++) {
Person p = new Person();
p.setFirstName(TestDataGenerator.getFirstName(r));
@@ -51,10 +62,9 @@ public class PersonContainer extends BeanItemContainer<Person>
p.getAddress().setPostalCode(TestDataGenerator.getPostalCode(r));
p.getAddress()
.setStreetAddress(TestDataGenerator.getStreetAddress(r));
- c.addItem(p);
+ testData.add(p);
}
-
- return c;
+ return testData;
}
}