Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CustomFieldConnector.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.v7.client.ui.customfield;
  17. import java.util.Collections;
  18. import java.util.List;
  19. import com.google.gwt.event.shared.HandlerRegistration;
  20. import com.google.gwt.user.client.ui.Widget;
  21. import com.vaadin.client.ComponentConnector;
  22. import com.vaadin.client.ConnectorHierarchyChangeEvent;
  23. import com.vaadin.client.ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler;
  24. import com.vaadin.client.HasComponentsConnector;
  25. import com.vaadin.shared.ui.Connect;
  26. import com.vaadin.v7.client.ui.AbstractFieldConnector;
  27. import com.vaadin.v7.client.ui.VCustomComponent;
  28. import com.vaadin.v7.ui.CustomField;
  29. @Connect(value = CustomField.class)
  30. public class CustomFieldConnector extends AbstractFieldConnector
  31. implements HasComponentsConnector, ConnectorHierarchyChangeHandler {
  32. List<ComponentConnector> childComponents;
  33. /**
  34. * Default constructor
  35. */
  36. public CustomFieldConnector() {
  37. addConnectorHierarchyChangeHandler(this);
  38. }
  39. @Override
  40. public VCustomComponent getWidget() {
  41. return (VCustomComponent) super.getWidget();
  42. }
  43. @Override
  44. public void updateCaption(ComponentConnector connector) {
  45. // NOP, custom field does not render the caption of its content
  46. }
  47. @Override
  48. public void onConnectorHierarchyChange(
  49. ConnectorHierarchyChangeEvent event) {
  50. // We always have 1 child, unless the child is hidden
  51. getWidget().setWidget(getContentWidget());
  52. }
  53. /*
  54. * (non-Javadoc)
  55. *
  56. * @see com.vaadin.client.HasComponentsConnector#getChildren()
  57. */
  58. @Override
  59. public List<ComponentConnector> getChildComponents() {
  60. if (childComponents == null) {
  61. return Collections.emptyList();
  62. }
  63. return childComponents;
  64. }
  65. /*
  66. * (non-Javadoc)
  67. *
  68. * @see com.vaadin.client.HasComponentsConnector#setChildren
  69. * (java.util.Collection)
  70. */
  71. @Override
  72. public void setChildComponents(List<ComponentConnector> childComponents) {
  73. this.childComponents = childComponents;
  74. }
  75. @Override
  76. public HandlerRegistration addConnectorHierarchyChangeHandler(
  77. ConnectorHierarchyChangeHandler handler) {
  78. return ensureHandlerManager()
  79. .addHandler(ConnectorHierarchyChangeEvent.TYPE, handler);
  80. }
  81. /**
  82. * Returns the content (only/first child) of the container.
  83. *
  84. * @return child connector or null if none (e.g. invisible or not set on
  85. * server)
  86. */
  87. protected ComponentConnector getContent() {
  88. List<ComponentConnector> children = getChildComponents();
  89. if (children.isEmpty()) {
  90. return null;
  91. } else {
  92. return children.get(0);
  93. }
  94. }
  95. /**
  96. * Returns the widget (if any) of the content of the container.
  97. *
  98. * @return widget of the only/first connector of the container, null if no
  99. * content or if there is no widget for the connector
  100. */
  101. protected Widget getContentWidget() {
  102. ComponentConnector content = getContent();
  103. if (null != content) {
  104. return content.getWidget();
  105. } else {
  106. return null;
  107. }
  108. }
  109. }