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.

GridColumnAutoWidthClientWidget.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.widgetset.client.grid;
  17. import java.util.ArrayList;
  18. import java.util.Arrays;
  19. import java.util.List;
  20. import com.vaadin.client.ui.grid.Grid;
  21. import com.vaadin.client.ui.grid.Grid.SelectionMode;
  22. import com.vaadin.client.ui.grid.GridColumn;
  23. import com.vaadin.client.ui.grid.datasources.ListDataSource;
  24. import com.vaadin.client.ui.grid.renderers.HtmlRenderer;
  25. public class GridColumnAutoWidthClientWidget extends
  26. PureGWTTestApplication<Grid<List<String>>> {
  27. private Grid<List<String>> grid;
  28. private class Col extends GridColumn<String, List<String>> {
  29. public Col(String header) {
  30. super(header, new HtmlRenderer());
  31. }
  32. @Override
  33. public String getValue(List<String> row) {
  34. int index = grid.getColumns().indexOf(this);
  35. return "<span>" + String.valueOf(row.get(index)) + "</span>";
  36. }
  37. }
  38. protected GridColumnAutoWidthClientWidget() {
  39. super(new Grid<List<String>>());
  40. grid = getTestedWidget();
  41. grid.setSelectionMode(SelectionMode.NONE);
  42. grid.setWidth("700px");
  43. List<List<String>> list = new ArrayList<List<String>>();
  44. list.add(Arrays.asList("equal length", "a very long cell content",
  45. "short", "fixed width narrow", "fixed width wide"));
  46. grid.setDataSource(new ListDataSource<List<String>>(list));
  47. addColumn("equal length");
  48. addColumn("short");
  49. addColumn("a very long header content");
  50. addColumn("fixed width narrow").setWidth(50);
  51. addColumn("fixed width wide").setWidth(200);
  52. addNorth(grid, 400);
  53. }
  54. private Col addColumn(String header) {
  55. Col column = (Col) grid.addColumn(new Col(header));
  56. grid.getHeaderRow(0).getCell(column)
  57. .setHtml("<span>" + header + "</span>");
  58. return column;
  59. }
  60. }