All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.extjs.gxt.ui.client.widget.Composite Maven / Gradle / Ivy

There is a newer version: 2.3.1-gwt22
Show newest version
/*
 * Sencha GXT 2.3.0 - Sencha for GWT
 * Copyright(c) 2007-2013, Sencha, Inc.
 * [email protected]
 * 
 * http://www.sencha.com/products/gxt/license/
 */
 package com.extjs.gxt.ui.client.widget;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;

/**
 * A component that wraps another component, hiding the wrapped components
 * public API.
 * 
 * 

* {@link #initComponent(Component)} must be called to initialize the composite. * *

* If the wrapped components is a LayoutContainer instance, it's * layout will be executed as if the composite was a * LayoutContainer. * *

* Code snippet: * *

 * public void onModuleLoad() {
 *   class TestComposite extends Composite {
 *     public TestComposite() {
 *       LayoutContainer c = new LayoutContainer();
 *       c.setLayout(new RowLayout(Orientation.HORIZONTAL));
 * 
 *       ContentPanel cp1 = new ContentPanel();
 *       cp1.setHeading("Composite Test 1");
 *       c.add(cp1, new RowData(.5, 1));
 * 
 *       ContentPanel cp2 = new ContentPanel();
 *       cp2.setHeading("Composite Test 2");
 *       c.add(cp2, new RowData(.5, 1));
 * 
 *       initComponent(c);
 *     }
 *   }
 * 
 *   Viewport v = new Viewport();
 *   v.setLayout(new FitLayout());
 *   v.add(new TestComposite());
 *   RootPanel.get().add(v);
 * }
 * 
* *
*
Inherited Events:
*
BoxComponent Move
*
BoxComponent Resize
*
Component Enable
*
Component Disable
*
Component BeforeHide
*
Component Hide
*
Component BeforeShow
*
Component Show
*
Component Attach
*
Component Detach
*
Component BeforeRender
*
Component Render
*
Component BrowserEvent
*
Component BeforeStateRestore
*
Component StateRestore
*
Component BeforeStateSave
*
Component SaveState
*
*/ public class Composite extends BoxComponent { protected Component component; /** * Returns the wrapped component. * * @return the component */ public Component getComponent() { return component; } @Override public Element getElement() { // we need this because of lazy rendering return component.getElement(); } @Override public boolean isAttached() { if (component != null) { return component.isAttached(); } return false; } @Override public void onBrowserEvent(Event event) { // Fire any handler added to the composite itself. super.onBrowserEvent(event); // Delegate events to the widget. component.onBrowserEvent(event); } @Override public void setSize(int width, int height) { if (component instanceof BoxComponent) { ((BoxComponent) component).setSize(width, height); } } @Override public void setSize(String width, String height) { if (component instanceof BoxComponent) { ((BoxComponent) component).setSize(width, height); } } protected void initComponent(Component component) { component.removeFromParent(); this.component = component; component.setParent(this); } @Override protected void onAttach() { component.onAttach(); DOM.setEventListener(getElement(), this); onLoad(); } @Override protected void onDetach() { try { onUnload(); } finally { component.onDetach(); } onDetachHelper(); } @Override protected void onDisable() { super.onDisable(); component.disable(); } @Override protected void onEnable() { super.onEnable(); component.enable(); } @Override protected void onRender(Element target, int index) { component.render(target, index); setElement(component.getElement()); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy