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.

CloseModalSubWindow.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.components.window;
  17. import com.vaadin.server.VaadinRequest;
  18. import com.vaadin.tests.components.AbstractTestUIWithLog;
  19. import com.vaadin.ui.Button;
  20. import com.vaadin.ui.Button.ClickEvent;
  21. import com.vaadin.ui.Button.ClickListener;
  22. import com.vaadin.ui.HorizontalLayout;
  23. import com.vaadin.ui.UI;
  24. import com.vaadin.ui.Window;
  25. import com.vaadin.v7.data.Item;
  26. import com.vaadin.v7.ui.TreeTable;
  27. @SuppressWarnings("serial")
  28. public class CloseModalSubWindow extends AbstractTestUIWithLog {
  29. public static final String SUB_WINDOW = "sub-win";
  30. public static final String TREE_TABLE = "treetable";
  31. public static final String DELETE_BUTTON = "del-btn";
  32. public static final String CONFIRM_BUTTON = "confirm-btn";
  33. private ConfirmWindow win;
  34. private TreeTable table;
  35. @Override
  36. protected String getTestDescription() {
  37. return "Lists a dozen items in a TreeTable with a Delete Button in each row. "
  38. + "Delete button will open an sub-window allowing user to either confirm delete operation or cancel. "
  39. + "Confirming should close the sub-window at the same time as the item is removed from the TreeTable.";
  40. }
  41. @Override
  42. protected Integer getTicketNumber() {
  43. return 13188;
  44. }
  45. @SuppressWarnings("unchecked")
  46. @Override
  47. protected void setup(VaadinRequest request) {
  48. table = new TreeTable();
  49. table.setId(TREE_TABLE);
  50. table.addContainerProperty("column", String.class, null);
  51. table.addContainerProperty("delete", Button.class, null);
  52. for (int i = 0; i < 10; i++) {
  53. Item item = table.addItem(i);
  54. item.getItemProperty("column").setValue("" + i);
  55. Button b = new Button("Delete", deleteClickListener);
  56. b.setId(DELETE_BUTTON + i);
  57. b.setData(i);
  58. item.getItemProperty("delete").setValue(b);
  59. }
  60. table.setSortEnabled(false);
  61. table.setColumnReorderingAllowed(false);
  62. table.setEditable(true);
  63. table.setPageLength(0);
  64. addComponent(table);
  65. }
  66. private void deleteItem(Object itemId) {
  67. table.removeItem(itemId);
  68. }
  69. private ClickListener deleteClickListener = new ClickListener() {
  70. @Override
  71. public void buttonClick(ClickEvent event) {
  72. win = new ConfirmWindow(event.getButton().getData());
  73. log("Modal sub-window opened");
  74. }
  75. };
  76. private ClickListener confirmClickListener = new ClickListener() {
  77. @Override
  78. public void buttonClick(ClickEvent event) {
  79. deleteItem(event.getButton().getData());
  80. win.close();
  81. log("Modal sub-window closed");
  82. }
  83. };
  84. private ClickListener cancelClickListener = new ClickListener() {
  85. @Override
  86. public void buttonClick(ClickEvent event) {
  87. win.close();
  88. log("Modal sub-window closed");
  89. }
  90. };
  91. /** Modal confirmation sub-window. */
  92. class ConfirmWindow extends Window {
  93. public ConfirmWindow(Object itemId) {
  94. setModal(true);
  95. setWidth("300px");
  96. setHeight("200px");
  97. setId(SUB_WINDOW);
  98. Button ok = new Button("Confirm Delete", confirmClickListener);
  99. ok.setId(CONFIRM_BUTTON);
  100. ok.setData(itemId);
  101. Button cancel = new Button("Cancel", cancelClickListener);
  102. HorizontalLayout l = new HorizontalLayout();
  103. l.addComponent(ok);
  104. l.addComponent(cancel);
  105. setContent(l);
  106. UI.getCurrent().addWindow(this);
  107. }
  108. }
  109. }