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.

TreeV8ContextClick.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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.tests.contextclick;
  17. import com.vaadin.data.TreeData;
  18. import com.vaadin.shared.Registration;
  19. import com.vaadin.ui.Button;
  20. import com.vaadin.ui.Button.ClickEvent;
  21. import com.vaadin.ui.HorizontalLayout;
  22. import com.vaadin.ui.Tree;
  23. import com.vaadin.ui.Tree.TreeContextClickEvent;
  24. import java.util.Collections;
  25. public class TreeV8ContextClick extends
  26. AbstractContextClickUI<Tree<String>, TreeContextClickEvent<String>> {
  27. @Override
  28. protected Tree<String> createTestComponent() {
  29. TreeData<String> treeData = new TreeData<>();
  30. for (int i = 0; i < 3; i++) {
  31. String grandDad = "Granddad " + i;
  32. treeData.addItems(null, grandDad);
  33. for (int j = 0; j < 4; j++) {
  34. String dad = "Dad " + i + "/" + j;
  35. treeData.addItems(grandDad, dad);
  36. for (int k = 0; k < 5; k++) {
  37. treeData.addItems(dad, "Son " + i + "/" + j + "/" + k);
  38. }
  39. }
  40. }
  41. Tree<String> tree = new Tree<>("Clane", treeData);
  42. tree.setWidth("100%");
  43. return tree;
  44. }
  45. @Override
  46. protected void handleContextClickEvent(
  47. TreeContextClickEvent<String> event) {
  48. String value = event.getItem();
  49. log("ContextClickEvent value: " + value);
  50. }
  51. @Override
  52. protected HorizontalLayout createContextClickControls() {
  53. HorizontalLayout controls = super.createContextClickControls();
  54. controls.addComponent(
  55. new Button("Remove all content", new Button.ClickListener() {
  56. @Override
  57. public void buttonClick(ClickEvent event) {
  58. testComponent.setItems(Collections.emptyList());
  59. testComponent.setHeight("200px");
  60. }
  61. }));
  62. return controls;
  63. }
  64. }