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.

VForm.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright 2000-2018 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.v7.client.ui;
  17. import com.google.gwt.dom.client.Element;
  18. import com.google.gwt.event.dom.client.KeyDownEvent;
  19. import com.google.gwt.event.dom.client.KeyDownHandler;
  20. import com.google.gwt.event.shared.HandlerRegistration;
  21. import com.google.gwt.user.client.DOM;
  22. import com.google.gwt.user.client.Event;
  23. import com.google.gwt.user.client.ui.ComplexPanel;
  24. import com.google.gwt.user.client.ui.Widget;
  25. import com.vaadin.client.ApplicationConnection;
  26. import com.vaadin.client.VErrorMessage;
  27. import com.vaadin.client.ui.Icon;
  28. import com.vaadin.client.ui.ShortcutActionHandler;
  29. public class VForm extends ComplexPanel implements KeyDownHandler {
  30. public static final String CLASSNAME = "v-form";
  31. /** For internal use only. May be removed or replaced in the future. */
  32. public String id;
  33. /** For internal use only. May be removed or replaced in the future. */
  34. public Widget lo;
  35. /** For internal use only. May be removed or replaced in the future. */
  36. public Element legend = DOM.createLegend();
  37. /** For internal use only. May be removed or replaced in the future. */
  38. public Element caption = DOM.createSpan();
  39. /** For internal use only. May be removed or replaced in the future. */
  40. public Element desc = DOM.createDiv();
  41. /** For internal use only. May be removed or replaced in the future. */
  42. public Icon icon;
  43. /** For internal use only. May be removed or replaced in the future. */
  44. public VErrorMessage errorMessage = new VErrorMessage();
  45. /** For internal use only. May be removed or replaced in the future. */
  46. public Element fieldContainer = DOM.createDiv();
  47. /** For internal use only. May be removed or replaced in the future. */
  48. public Element footerContainer = DOM.createDiv();
  49. /** For internal use only. May be removed or replaced in the future. */
  50. public Element fieldSet = DOM.createFieldSet();
  51. /** For internal use only. May be removed or replaced in the future. */
  52. public Widget footer;
  53. /** For internal use only. May be removed or replaced in the future. */
  54. public ApplicationConnection client;
  55. /** For internal use only. May be removed or replaced in the future. */
  56. public ShortcutActionHandler shortcutHandler;
  57. /** For internal use only. May be removed or replaced in the future. */
  58. public HandlerRegistration keyDownRegistration;
  59. public VForm() {
  60. setElement(DOM.createDiv());
  61. getElement().appendChild(fieldSet);
  62. setStyleName(CLASSNAME);
  63. fieldSet.appendChild(legend);
  64. legend.appendChild(caption);
  65. // Adding description for initial padding
  66. // measurements, removed later if no
  67. // description is set
  68. fieldSet.appendChild(desc);
  69. fieldSet.appendChild(fieldContainer);
  70. errorMessage.setVisible(false);
  71. fieldSet.appendChild(errorMessage.getElement());
  72. fieldSet.appendChild(footerContainer);
  73. errorMessage.setOwner(this);
  74. }
  75. @Override
  76. public void setStyleName(String style) {
  77. super.setStyleName(style);
  78. updateStyleNames();
  79. }
  80. @Override
  81. public void setStylePrimaryName(String style) {
  82. super.setStylePrimaryName(style);
  83. updateStyleNames();
  84. }
  85. protected void updateStyleNames() {
  86. fieldContainer.setClassName(getStylePrimaryName() + "-content");
  87. errorMessage.setStyleName(getStylePrimaryName() + "-errormessage");
  88. desc.setClassName(getStylePrimaryName() + "-description");
  89. footerContainer.setClassName(getStylePrimaryName() + "-footer");
  90. }
  91. @Override
  92. public void onKeyDown(KeyDownEvent event) {
  93. shortcutHandler.handleKeyboardEvent(Event.as(event.getNativeEvent()));
  94. }
  95. public void setFooterWidget(Widget footerWidget) {
  96. if (footer != null) {
  97. remove(footer);
  98. }
  99. if (footerWidget != null) {
  100. super.add(footerWidget, footerContainer);
  101. }
  102. footer = footerWidget;
  103. }
  104. public void setLayoutWidget(Widget newLayoutWidget) {
  105. if (lo != null) {
  106. remove(lo);
  107. }
  108. if (newLayoutWidget != null) {
  109. super.add(newLayoutWidget, fieldContainer);
  110. }
  111. lo = newLayoutWidget;
  112. }
  113. }