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.

TreeHorizontalResize.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package com.vaadin.tests.components.tree;
  2. import java.util.Iterator;
  3. import com.vaadin.server.ThemeResource;
  4. import com.vaadin.tests.components.TestBase;
  5. import com.vaadin.ui.Panel;
  6. import com.vaadin.ui.VerticalLayout;
  7. import com.vaadin.v7.data.Item;
  8. import com.vaadin.v7.data.util.HierarchicalContainer;
  9. import com.vaadin.v7.ui.Tree;
  10. public class TreeHorizontalResize extends TestBase {
  11. // copied from Sampler to eliminate dependency
  12. public static final Object hw_PROPERTY_NAME = "name";
  13. public static final Object hw_PROPERTY_ICON = "icon";
  14. private static final String[][] hardware = { //
  15. { "Desktops", "Dell OptiPlex GX240", "Dell OptiPlex GX260",
  16. "Dell OptiPlex GX280" },
  17. { "Monitors", "Benq T190HD", "Benq T220HD", "Benq T240HD" },
  18. { "Laptops", "IBM ThinkPad T40", "IBM ThinkPad T43",
  19. "IBM ThinkPad T60" } };
  20. @Override
  21. protected void setup() {
  22. VerticalLayout treeLayout = new VerticalLayout();
  23. treeLayout.setMargin(true);
  24. treeLayout.setSizeUndefined();
  25. Panel treePanel = new Panel(treeLayout);
  26. treePanel.setHeight("500px");
  27. treePanel.setWidth(null);
  28. addComponent(treePanel);
  29. Tree tree = new Tree();
  30. tree.setContainerDataSource(getHardwareContainer());
  31. tree.setItemCaptionPropertyId(hw_PROPERTY_NAME);
  32. for (Iterator<?> it = tree.rootItemIds().iterator(); it.hasNext();) {
  33. tree.expandItemsRecursively(it.next());
  34. }
  35. treeLayout.addComponent(tree);
  36. }
  37. @Override
  38. protected String getDescription() {
  39. return "The Tree should be properly resized horizontally when collapsing/expanding nodes. The height is fixed to 500px.";
  40. }
  41. @Override
  42. protected Integer getTicketNumber() {
  43. return 6230;
  44. }
  45. public static HierarchicalContainer getHardwareContainer() {
  46. Item item = null;
  47. int itemId = 0; // Increasing numbering for itemId:s
  48. // Create new container
  49. HierarchicalContainer hwContainer = new HierarchicalContainer();
  50. // Create containerproperty for name
  51. hwContainer.addContainerProperty(hw_PROPERTY_NAME, String.class, null);
  52. // Create containerproperty for icon
  53. hwContainer.addContainerProperty(hw_PROPERTY_ICON, ThemeResource.class,
  54. new ThemeResource("../runo/icons/16/document.png"));
  55. for (int i = 0; i < hardware.length; i++) {
  56. // Add new item
  57. item = hwContainer.addItem(itemId);
  58. // Add name property for item
  59. item.getItemProperty(hw_PROPERTY_NAME).setValue(hardware[i][0]);
  60. // Allow children
  61. hwContainer.setChildrenAllowed(itemId, true);
  62. itemId++;
  63. for (int j = 1; j < hardware[i].length; j++) {
  64. if (j == 1) {
  65. item.getItemProperty(hw_PROPERTY_ICON).setValue(
  66. new ThemeResource("../runo/icons/16/folder.png"));
  67. }
  68. // Add child items
  69. item = hwContainer.addItem(itemId);
  70. item.getItemProperty(hw_PROPERTY_NAME).setValue(hardware[i][j]);
  71. hwContainer.setParent(itemId, itemId - j);
  72. hwContainer.setChildrenAllowed(itemId, false);
  73. itemId++;
  74. }
  75. }
  76. return hwContainer;
  77. }
  78. }