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.

BasicCrudGridEditorRow.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.fieldgroup;
  17. import java.text.DateFormat;
  18. import java.util.Locale;
  19. import com.vaadin.data.Item;
  20. import com.vaadin.data.util.BeanItem;
  21. import com.vaadin.event.SelectionEvent;
  22. import com.vaadin.event.SelectionEvent.SelectionListener;
  23. import com.vaadin.legacy.data.validator.LegacyIntegerRangeValidator;
  24. import com.vaadin.server.VaadinRequest;
  25. import com.vaadin.ui.Grid;
  26. import com.vaadin.ui.renderers.DateRenderer;
  27. public class BasicCrudGridEditorRow extends AbstractBasicCrud {
  28. private Grid grid;
  29. @Override
  30. protected void setup(VaadinRequest request) {
  31. super.setup(request);
  32. formType.setVisible(false);
  33. grid = new Grid();
  34. grid.setContainerDataSource(container);
  35. grid.setColumnOrder((Object[]) columns);
  36. grid.removeColumn("salary");
  37. grid.addSelectionListener(new SelectionListener() {
  38. @Override
  39. public void select(SelectionEvent event) {
  40. Item item = grid.getContainerDataSource()
  41. .getItem(grid.getSelectedRow());
  42. form.edit((BeanItem<ComplexPerson>) item);
  43. }
  44. });
  45. grid.setEditorEnabled(true);
  46. grid.setSizeFull();
  47. grid.getColumn("age").getEditorField().addValidator(
  48. new LegacyIntegerRangeValidator("Must be between 0 and 100", 0,
  49. 100));
  50. grid.getColumn("birthDate").setRenderer(new DateRenderer(
  51. DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US)));
  52. addComponent(grid);
  53. getLayout().setExpandRatio(grid, 1);
  54. }
  55. @Override
  56. protected void deselectAll() {
  57. grid.select(null);
  58. }
  59. }