001
002package org.opencms.ui.client;
003
004import org.opencms.ui.shared.components.CmsExternalLayoutState;
005
006import com.google.gwt.dom.client.Document;
007import com.google.gwt.dom.client.Element;
008import com.google.gwt.user.client.ui.SimplePanel;
009import com.vaadin.client.ComponentConnector;
010import com.vaadin.client.ConnectorHierarchyChangeEvent;
011import com.vaadin.client.ui.AbstractHasComponentsConnector;
012import com.vaadin.shared.ui.Connect;
013
014/**
015 * Connector between {@link org.opencms.ui.components.CmsExternalLayout} and {@link CmsExternalLayout}.<p>
016 *
017 * @author Risto Yrjänä / Vaadin Ltd.
018 */
019@Connect(org.opencms.ui.components.CmsExternalLayout.class)
020public class CmsExternalLayoutConnector extends AbstractHasComponentsConnector {
021
022    /** The serial version id. */
023    private static final long serialVersionUID = 7508554962069048058L;
024
025    /**
026     * @see com.vaadin.client.ui.AbstractComponentConnector#getState()
027     */
028    @Override
029    public CmsExternalLayoutState getState() {
030
031        return (CmsExternalLayoutState)super.getState();
032    }
033
034    /**
035     * @see com.vaadin.client.ui.AbstractComponentConnector#getWidget()
036     */
037    @Override
038    public CmsExternalLayout getWidget() {
039
040        return (CmsExternalLayout)super.getWidget();
041    }
042
043    /**
044     * @see com.vaadin.client.ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler#onConnectorHierarchyChange(com.vaadin.client.ConnectorHierarchyChangeEvent)
045     */
046    @Override
047    public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) {
048
049        ComponentConnector child = getChildComponents().get(0);
050
051        Element targetElement = Document.get().getElementById(getState().m_externalComponentId);
052        if (targetElement == null) {
053            targetElement = getWidget().getElement();
054        }
055        getWidget().setRenderTargetElement(targetElement);
056
057        getWidget().setWidget(child.getWidget());
058    }
059
060    /**
061     * @see com.vaadin.client.HasComponentsConnector#updateCaption(com.vaadin.client.ComponentConnector)
062     */
063    @Override
064    public void updateCaption(ComponentConnector connector) {
065        // Captions not supported
066    }
067
068    /**
069     * @see com.vaadin.client.ui.AbstractComponentConnector#createWidget()
070     */
071    @Override
072    protected SimplePanel createWidget() {
073
074        return new CmsExternalLayout();
075    }
076
077}