You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridContextClick.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.contextclick;
  17. import com.vaadin.tests.util.PersonContainer;
  18. import com.vaadin.ui.Button;
  19. import com.vaadin.ui.Button.ClickEvent;
  20. import com.vaadin.ui.HorizontalLayout;
  21. import com.vaadin.v7.data.Item;
  22. import com.vaadin.v7.shared.ui.grid.GridConstants.Section;
  23. import com.vaadin.v7.ui.Grid;
  24. import com.vaadin.v7.ui.Grid.GridContextClickEvent;
  25. public class GridContextClick
  26. extends AbstractContextClickUI<Grid, GridContextClickEvent> {
  27. @Override
  28. protected Grid createTestComponent() {
  29. Grid grid = new Grid(PersonContainer.createWithTestData());
  30. grid.setFooterVisible(true);
  31. grid.appendFooterRow();
  32. grid.setColumnOrder("address", "email", "firstName", "lastName",
  33. "phoneNumber", "address.streetAddress", "address.postalCode",
  34. "address.city");
  35. grid.setWidth("100%");
  36. grid.setHeight("400px");
  37. return grid;
  38. }
  39. @Override
  40. protected void handleContextClickEvent(GridContextClickEvent event) {
  41. String value = "";
  42. Object propertyId = event.getPropertyId();
  43. if (event.getItemId() != null) {
  44. Item item = event.getComponent().getContainerDataSource()
  45. .getItem(event.getItemId());
  46. value += item.getItemProperty("firstName").getValue();
  47. value += " " + item.getItemProperty("lastName").getValue();
  48. } else if (event.getSection() == Section.HEADER) {
  49. value = event.getComponent().getHeaderRow(event.getRowIndex())
  50. .getCell(propertyId).getText();
  51. } else if (event.getSection() == Section.FOOTER) {
  52. value = event.getComponent().getFooterRow(event.getRowIndex())
  53. .getCell(propertyId).getText();
  54. }
  55. log("ContextClickEvent value: " + value + ", propertyId: " + propertyId
  56. + ", section: " + event.getSection());
  57. }
  58. @Override
  59. protected HorizontalLayout createContextClickControls() {
  60. HorizontalLayout controls = super.createContextClickControls();
  61. controls.addComponent(
  62. new Button("Remove all content", new Button.ClickListener() {
  63. @Override
  64. public void buttonClick(ClickEvent event) {
  65. testComponent.getContainerDataSource().removeAllItems();
  66. }
  67. }));
  68. return controls;
  69. }
  70. }