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 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2000-2014 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.data.Item;
  18. import com.vaadin.shared.ui.grid.GridConstants.Section;
  19. import com.vaadin.tests.util.PersonContainer;
  20. import com.vaadin.ui.Grid;
  21. import com.vaadin.ui.Grid.GridContextClickEvent;
  22. public class GridContextClick extends
  23. AbstractContextClickUI<Grid, GridContextClickEvent> {
  24. @Override
  25. protected Grid createTestComponent() {
  26. Grid grid = new Grid(PersonContainer.createWithTestData());
  27. grid.setFooterVisible(true);
  28. grid.appendFooterRow();
  29. grid.setColumnOrder("address", "email", "firstName", "lastName",
  30. "phoneNumber", "address.streetAddress", "address.postalCode",
  31. "address.city");
  32. grid.setSizeFull();
  33. return grid;
  34. }
  35. @Override
  36. protected void handleContextClickEvent(GridContextClickEvent event) {
  37. String value = "";
  38. Object propertyId = event.getPropertyId();
  39. if (event.getItemId() != null) {
  40. Item item = event.getComponent().getContainerDataSource()
  41. .getItem(event.getItemId());
  42. value += item.getItemProperty("firstName").getValue();
  43. value += " " + item.getItemProperty("lastName").getValue();
  44. } else if (event.getSection() == Section.HEADER) {
  45. value = event.getComponent().getHeaderRow(event.getRowIndex())
  46. .getCell(propertyId).getText();
  47. } else if (event.getSection() == Section.FOOTER) {
  48. value = event.getComponent().getFooterRow(event.getRowIndex())
  49. .getCell(propertyId).getText();
  50. }
  51. log("ContextClickEvent value: " + value + ", propertyId: " + propertyId
  52. + ", section: " + event.getSection());
  53. }
  54. }