001 002package org.opencms.ui.components; 003 004import org.opencms.ui.shared.components.CmsExternalLayoutState; 005 006import java.util.Collections; 007import java.util.Iterator; 008 009import com.vaadin.ui.AbstractComponent; 010import com.vaadin.ui.Component; 011import com.vaadin.ui.HasComponents; 012 013/** 014 * Single component container that can render the given component in any HTML 015 * element.<p> 016 * 017 * @author Risto Yrjänä / Vaadin Ltd. 018 */ 019public class CmsExternalLayout extends AbstractComponent implements HasComponents { 020 021 /** The serial version id. */ 022 private static final long serialVersionUID = 4970339558483506331L; 023 024 /** The child component. */ 025 private final Component m_childComponent; 026 027 /** 028 * Create a layout that renders the given component to an external HTML element that 029 * has the specified id 030 * 031 * @param divId 032 * id for the target element, cannot be null 033 * @param component 034 * component to be rendered, cannot be null 035 */ 036 public CmsExternalLayout(String divId, Component component) { 037 038 if ((divId == null) || (component == null)) { 039 throw new IllegalArgumentException("The div id or the child component cannot be null."); 040 } 041 042 getState().m_externalComponentId = divId; 043 m_childComponent = component; 044 m_childComponent.setParent(this); 045 } 046 047 /** 048 * @see com.vaadin.ui.AbstractComponent#getState() 049 */ 050 @Override 051 public CmsExternalLayoutState getState() { 052 053 return (CmsExternalLayoutState)super.getState(); 054 } 055 056 /** 057 * @see com.vaadin.ui.HasComponents#iterator() 058 */ 059 @Override 060 public Iterator<Component> iterator() { 061 062 return Collections.singleton(m_childComponent).iterator(); 063 } 064}