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.

CustomRenderer.java 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.v7.tests.components.grid;
  17. import com.vaadin.annotations.Widgetset;
  18. import com.vaadin.server.VaadinRequest;
  19. import com.vaadin.tests.components.AbstractReindeerTestUI;
  20. import com.vaadin.tests.widgetset.TestingWidgetSet;
  21. import com.vaadin.tests.widgetset.client.SimpleTestBean;
  22. import com.vaadin.ui.Label;
  23. import com.vaadin.v7.data.Item;
  24. import com.vaadin.v7.data.Property;
  25. import com.vaadin.v7.data.util.IndexedContainer;
  26. import com.vaadin.v7.ui.Grid;
  27. import com.vaadin.v7.ui.Grid.SelectionMode;
  28. @Widgetset(TestingWidgetSet.NAME)
  29. public class CustomRenderer extends AbstractReindeerTestUI {
  30. private static final Object INT_ARRAY_PROPERTY = "int array";
  31. private static final Object VOID_PROPERTY = "void";
  32. private static final Object BEAN_PROPERTY = "pojo";
  33. static final Object ITEM_ID = "itemId1";
  34. static final String DEBUG_LABEL_ID = "debuglabel";
  35. static final String INIT_DEBUG_LABEL_CAPTION = "Debug label placeholder";
  36. @Override
  37. protected void setup(VaadinRequest request) {
  38. IndexedContainer container = new IndexedContainer();
  39. container.addContainerProperty(INT_ARRAY_PROPERTY, int[].class,
  40. new int[] {});
  41. container.addContainerProperty(VOID_PROPERTY, Void.class, null);
  42. container.addContainerProperty(BEAN_PROPERTY, SimpleTestBean.class,
  43. null);
  44. Item item = container.addItem(ITEM_ID);
  45. @SuppressWarnings("unchecked")
  46. Property<int[]> propertyIntArray = item
  47. .getItemProperty(INT_ARRAY_PROPERTY);
  48. propertyIntArray.setValue(new int[] { 1, 1, 2, 3, 5, 8, 13 });
  49. @SuppressWarnings("unchecked")
  50. Property<SimpleTestBean> propertyPojo = item
  51. .getItemProperty(BEAN_PROPERTY);
  52. SimpleTestBean bean = new SimpleTestBean();
  53. bean.setValue(42);
  54. propertyPojo.setValue(bean);
  55. Label debugLabel = new Label(INIT_DEBUG_LABEL_CAPTION);
  56. debugLabel.setId(DEBUG_LABEL_ID);
  57. Grid grid = new Grid(container);
  58. grid.getColumn(INT_ARRAY_PROPERTY).setRenderer(new IntArrayRenderer());
  59. grid.getColumn(VOID_PROPERTY)
  60. .setRenderer(new RowAwareRenderer(debugLabel));
  61. grid.getColumn(BEAN_PROPERTY).setRenderer(new BeanRenderer());
  62. grid.setSelectionMode(SelectionMode.NONE);
  63. addComponent(grid);
  64. addComponent(debugLabel);
  65. }
  66. @Override
  67. protected String getTestDescription() {
  68. return "Verifies that renderers operating on other data than "
  69. + "just Strings also work ";
  70. }
  71. @Override
  72. protected Integer getTicketNumber() {
  73. return Integer.valueOf(13334);
  74. }
  75. }