diff options
author | Artur <artur@vaadin.com> | 2017-04-18 10:57:11 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-04-18 10:57:11 +0300 |
commit | 9a0f1c136168fbc7b63570b88da7a9cba9de389c (patch) | |
tree | 1f08ad9d488a00fabdb639f7ffe9d7a02978aad3 /client | |
parent | b480c7166ac56801cda11b73a6ad4694d467b98b (diff) | |
download | vaadin-framework-9a0f1c136168fbc7b63570b88da7a9cba9de389c.tar.gz vaadin-framework-9a0f1c136168fbc7b63570b88da7a9cba9de389c.zip |
Composite component (#8952)
A composite is included in the server side hierarchy and in the connector
hierarchy on the client side but does not have its own widget or DOM.
To ensure that captions etc are renderer correctly for the root contents,
the client side connector returns both the widget and state for the content
connector.
Server side API related to width and height are automatically forwarded to
the root component to enable easy use of the composite inside different
layout configurations.
Other server side API inherited from AbstractComponent is unwanted, should be
optional and therefore throw an exception by default.
Resolves #2458
Diffstat (limited to 'client')
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/composite/CompositeConnector.java | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/composite/CompositeConnector.java b/client/src/main/java/com/vaadin/client/ui/composite/CompositeConnector.java new file mode 100644 index 0000000000..ad5e019b6b --- /dev/null +++ b/client/src/main/java/com/vaadin/client/ui/composite/CompositeConnector.java @@ -0,0 +1,90 @@ +/* + * Copyright 2000-2016 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.client.ui.composite; + +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.client.ComponentConnector; +import com.vaadin.client.ConnectorHierarchyChangeEvent; +import com.vaadin.client.HasComponentsConnector; +import com.vaadin.client.ui.AbstractHasComponentsConnector; +import com.vaadin.shared.AbstractComponentState; +import com.vaadin.shared.ui.Connect; +import com.vaadin.shared.ui.Connect.LoadStyle; +import com.vaadin.ui.Composite; + +@Connect(value = Composite.class, loadStyle = LoadStyle.EAGER) +public class CompositeConnector extends AbstractHasComponentsConnector { + + private ComponentConnector childConnector; + + @Override + protected Widget createWidget() { + throw new UnsupportedOperationException( + "Composite has no widget of its own"); + } + + private boolean hasChildConnector() { + return getChildConnector() != null; + } + + private ComponentConnector getChildConnector() { + // Must store the child connector to have it available when removing the + // connector + if (childConnector == null && !getChildren().isEmpty()) { + childConnector = (ComponentConnector) getChildren().get(0); + } + return childConnector; + } + + @Override + public Widget getWidget() { + if (!hasChildConnector()) { + // This happens in doInit for instance when setConnectorId is called + return new Label("This widget should not end up anywhere ever"); + } else { + return getChildConnector().getWidget(); + } + } + + @Override + public HasComponentsConnector getParent() { + return (HasComponentsConnector) super.getParent(); + } + + @Override + public void updateCaption(ComponentConnector component) { + // Parent might assume that the connector is always a child connector, + // therefore passing "this" instead of the child connector. The child + // caption will be returned as getState() returns the child's state. + getParent().updateCaption(this); + } + + @Override + public AbstractComponentState getState() { + if (!hasChildConnector()) { + return new AbstractComponentState(); + } else { + return getChildConnector().getState(); + } + } + + @Override + public void onConnectorHierarchyChange( + ConnectorHierarchyChangeEvent event) { + // Handled in getChildConnector + } +} |