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.

CompositeConnector.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.client.ui.composite;
  17. import com.google.gwt.dom.client.EventTarget;
  18. import com.google.gwt.user.client.ui.Label;
  19. import com.google.gwt.user.client.ui.Widget;
  20. import com.vaadin.client.ComponentConnector;
  21. import com.vaadin.client.ConnectorHierarchyChangeEvent;
  22. import com.vaadin.client.HasComponentsConnector;
  23. import com.vaadin.client.ui.AbstractHasComponentsConnector;
  24. import com.vaadin.shared.AbstractComponentState;
  25. import com.vaadin.shared.MouseEventDetails;
  26. import com.vaadin.shared.ui.Connect;
  27. import com.vaadin.shared.ui.Connect.LoadStyle;
  28. import com.vaadin.ui.Composite;
  29. /**
  30. * Connector for the Composite component.
  31. *
  32. * @author Vaadin Ltd
  33. * @since 8.1
  34. */
  35. @Connect(value = Composite.class, loadStyle = LoadStyle.EAGER)
  36. public class CompositeConnector extends AbstractHasComponentsConnector {
  37. private ComponentConnector childConnector;
  38. @Override
  39. protected Widget createWidget() {
  40. throw new UnsupportedOperationException(
  41. "Composite has no widget of its own");
  42. }
  43. private boolean hasChildConnector() {
  44. return getChildConnector() != null;
  45. }
  46. private ComponentConnector getChildConnector() {
  47. // Must store the child connector to have it available when removing the
  48. // connector
  49. if (childConnector == null && !getChildren().isEmpty()) {
  50. childConnector = (ComponentConnector) getChildren().get(0);
  51. }
  52. return childConnector;
  53. }
  54. @Override
  55. public Widget getWidget() {
  56. if (!hasChildConnector()) {
  57. // This happens in doInit for instance when setConnectorId is called
  58. return new Label("This widget should not end up anywhere ever");
  59. } else {
  60. return getChildConnector().getWidget();
  61. }
  62. }
  63. @Override
  64. public HasComponentsConnector getParent() {
  65. return (HasComponentsConnector) super.getParent();
  66. }
  67. @Override
  68. public void updateCaption(ComponentConnector component) {
  69. // Parent might assume that the connector is always a child connector,
  70. // therefore passing "this" instead of the child connector. The child
  71. // caption will be returned as getState() returns the child's state.
  72. getParent().updateCaption(this);
  73. }
  74. @Override
  75. public AbstractComponentState getState() {
  76. if (!hasChildConnector()) {
  77. return new AbstractComponentState();
  78. } else {
  79. return getChildConnector().getState();
  80. }
  81. }
  82. @Override
  83. public void onConnectorHierarchyChange(
  84. ConnectorHierarchyChangeEvent event) {
  85. // Handled in getChildConnector
  86. }
  87. @Override
  88. protected void sendContextClickEvent(MouseEventDetails details, EventTarget eventTarget) {
  89. //Do nothing, because Composite is not an actual component, and the event
  90. //must be handled in inner components.
  91. }
  92. }