component.java

来自「非常接近C/S操作方式的Java Ajax框架-ZK 用ZK框架使你的B/S应」· Java 代码 · 共 616 行 · 第 1/2 页

JAVA
616
字号
/* Component.java{{IS_NOTE	Purpose:			Description:			History:		Mon May 30 21:03:47     2005, Created by tomyeh}}IS_NOTECopyright (C) 2005 Potix Corporation. All Rights Reserved.{{IS_RIGHT	This program is distributed under GPL Version 2.0 in the hope that	it will be useful, but WITHOUT ANY WARRANTY.}}IS_RIGHT*/package org.zkoss.zk.ui;import java.util.List;import java.util.Map;import java.util.Iterator;import java.io.Writer;import java.io.IOException;import org.zkoss.zk.ui.event.EventListener;import org.zkoss.zk.ui.util.Namespace;import org.zkoss.zk.au.AuResponse;/** * A UI component. * * <p>There are two kind of lifecycles: one is page creations and the other * is asynchronous updates. * * <h3>The Page Creation</h3> * <p>The page creation occurs when a page is about to render at the first * time. The detailed phases can be found in the devloper's guide. * * <h3>The Asynchronous Update</h3> * <p>The asynchronous update occurs when users does something on the browser, * such as changing the content of input, clicking buttons and so on. * Such behaviors are packed as requests, queue in the browser, and then * send to the server at the proper time. The detailed phases * can be found in the developer's guide. * * <h3>No Synchronization Required</h3> * <p>To simplify the development of components and applications, * invocations of methods of components and event listener are all serialized. * In other words, application and component developers need not worry * synchronization and other thread issues (unless you are developing * background thread to handle long operations). * * <p>It also implies a limitation that you cannot access components * belonging to other desktops when processing an event. * * @author tomyeh */public interface Component extends java.io.Serializable, Cloneable {	/** Returns the owner of the ID space that this component belongs to.	 * It is either a component, a page or null.	 * If it has an ancestor that implements {@link IdSpace}, it is returned.	 * Otherwise, the page it belongs to is returned	 *	 * <p>Each ID space defines an independent set of IDs. No component	 * in the same ID space could have the same ID.	 * To get any component in the same ID space, you could use	 * {@link #getFellow}.	 * See {@link IdSpace} for more details.	 *	 * <p>The ID space relevant methods include {@link #getFellow},	 * {@link #getAttribute} and {@link #getVariable}.	 */	public IdSpace getSpaceOwner();	/** Returns the ID. If it is a root component (i.e., without parent),	 * its ID must be unquie among root components of the same page.	 *	 * <p>If a component belongs to an ID space (see {@link IdSpace}),	 * the ID must also be unique in the ID space it belongs.	 * any its parent and ancestor implements {@link IdSpace}.	 *	 * <p>A page itself is also an ID space, so you could retrieve	 * compnents in a page by use of {@link Page#getFellow}, unless	 * the component is a descendant of another component that implements	 * {@link IdSpace}. In this case, you have to retrieve the parent	 * first (by use of {@link Page#getFellow} and then use {@link #getFellow}	 * against the owner of the ID space.	 *	 * <p>In BSH and EL, a component with explicit ID can be accessed	 * directly by the ID. In other word, a variable named by the ID is	 * created automatically.	 *	 * @see Page	 */	public String getId();	/** Sets the ID. The scope of uniqunes depends on whether this component	 * is a root component. Refer to {@link #getId} for more details.	 *	 * <p>When a component is constructed, an ID is generated automatically.	 * Thus, calling this method only you need to identify a component.	 *	 * @see Page	 */	public void setId(String id);	/** Returns the desktop of this component,	 * or null if this component doesn't belong to any desktop.	 *	 * <p>When a component is created in an event listener, it	 * is assigned to the current desktop automatically.	 * If a component is created not in any event listener, it doesn't	 * belong to any desktop and this method returns null.	 * Once a component is attached to a desktop (thru {@link #setPage}	 * or {@link #setParent}), it belongs to the desktop.	 *	 * <p>Notice: there is no way to detach a component from a desktop,	 * once it is attached as described above.	 * In other words, you cannot move a component (or page) from	 * one desktop to another.	 *	 * <p>In summary, there are only two ways to handle components.	 * <ol>	 * <li>Handle them all in event listeners and don't access any components	 * from other desktops. This is simplest and clearest.</li>	 * <li>Creates components in another thread (other than event listener)	 * and attach them to a page (and then desktop) upon an event is received.</li>	 * </ol>	 */	public Desktop getDesktop();	/** Returns the page that this component belongs to, or null if	 * it doesn't belong to any page.	 *	 * <p>When a component is created (aka., constructed), it doesn't	 * belong to any page. And, if a component doesn't belong to	 * any page, they won't be displayed at the client.	 *	 * <p>When changing parent ({@link #setParent}), the child component's	 * page will become the same as parent's. In other words, a component	 * is added to a page automatically if it becomes a child of	 * another component (who belongs to a page).	 * 	 * <p>For root components, you have to invoke {@link #setPage}	 * explicityly.	 *	 * @see #setParent	 * @see #setPage	 */	public Page getPage();	/** Sets what page this component belongs to.	 *	 * <p>For child components, the page they belong is maintained	 * automatically. You need to invoke this method only for root 	 * components.	 */	public void setPage(Page page);	/** Returns UUID (universal unique ID) which is unquie in the whole	 * desktop. The UUID is generated automatically and immutable, unless	 * {@link org.zkoss.zk.ui.ext.RawId} is also implemented.	 *	 * <p>It is mainly used for communication between client and server	 * and you rarely need to access it.	 *	 * <p>If {@link org.zkoss.zk.ui.ext.RawId} is implemented as part of	 * a component, UUID is the same as {@link #getId} if {@link #setId}	 * is ever called. It is designed to migrate HTML pages to ZK, such	 * that the element ID could remain the same.	 */	public String getUuid();	/** Returns a component of the specified ID in the same ID space.	 * Components in the same ID space are called fellows.	 *	 * <p>Unlike {@link #getFellowIfAny}, it throws an exception if not found.	 *	 * @exception ComponentNotFoundException is thrown if fellow not found	 */	public Component getFellow(String id);	/** Returns a component of the specified ID in the same ID space, or null	 * if not found.	 * <p>Unlike {@link #getFellow}, it returns null if not found.	 */	public Component getFellowIfAny(String id);	/** Used with {@link #getAttribute} and relevants to denote	 * custom attributes private to a component is searched.	 * <p>It is also known as the component attributes.	 * <p>It is the same as {@link Component#getAttributes}.	 */	public static final int COMPONENT_SCOPE = 0;	/** Used with {@link #getAttribute} and relevants to denote	 * custom attributes shared by the same ID space.	 * <p>It is also known as the ID space attributes.	 */	public static final int SPACE_SCOPE = 1;	/** Used with {@link #getAttribute} and relevants to denote	 * custom attributes shared by the same page.	 * <p>It is also known as the page attributes.	 * <p>It is the same as {@link Page#getAttributes}.	 */	public static final int PAGE_SCOPE = 2;	/** Used with {@link #getAttribute} and relevants to denote	 * custom attributes shared by the same desktop.	 * <p>It is also known as the desktop attributes.	 * <p>It is the same as {@link Desktop#getAttributes}.	 */	public static final int DESKTOP_SCOPE = 3;	/** Used with {@link #getAttribute} and relevants to denote	 * custom attributes shared by the same session.	 * <p>It is also known as the session attributes.	 * <p>It is the same as {@link Session#getAttributes}.	 */	public static final int SESSION_SCOPE = 4;	/** Used with {@link #getAttribute} and relevants to denote	 * custom attributes shared by the whole application.	 * <p>It is also known as the application attributes.	 * <p>It is the same as {@link WebApp#getAttributes}.	 */	public static final int APPLICATION_SCOPE = 5;	/** Used with {@link #getAttribute} and relevants to denote	 * custom attributes shared by the same request.	 * <p>It is also known as the request attributes.	 * <p>It is the same as {@link Execution#getAttributes}.	 */	public static final int REQUEST_SCOPE = 6;	/** Returns all custom attributes of the specified scope.	 * You could reference them thru componentScope, spaceScope, pageScope,	 * requestScope and desktopScope in BSH and EL.	 *	 * <p>If scope is {@link #COMPONENT_SCOPE}, it means custom attributes private	 * to this component.	 * <p>If scope is {@link #SPACE_SCOPE}, it means custom attributes shared	 * by components from the same ID space as this one's.	 * <p>If scope is {@link #PAGE_SCOPE}, it means custom attributes shared	 * by components from the same page as this one's.	 * <p>If scope is {@link #DESKTOP_SCOPE}, it means custom attributes shared	 * by components from the same desktopas this one's.	 *	 * @param scope {@link #COMPONENT_SCOPE}, {@link #SPACE_SCOPE},	 * {@link #PAGE_SCOPE}, {@link #DESKTOP_SCOPE}, {@link #SESSION_SCOPE},	 * {@link #REQUEST_SCOPE} or {@link #APPLICATION_SCOPE}, 	 */	public Map getAttributes(int scope);	/** Returns the value of the specified custom attribute in the specified scope.	 * <p>If scope is {@link #COMPONENT_SCOPE}, it means attributes private	 * to this component.	 * <p>If scope is {@link #SPACE_SCOPE}, it means custom attributes shared	 * by components from the same ID space as this one's.	 * <p>If scope is {@link #PAGE_SCOPE}, it means custom attributes shared	 * by components from the same page as this one's.	 * <p>If scope is {@link #DESKTOP_SCOPE}, it means custom attributes shared	 * by components from the same desktopas this one's.	 *	 * @param scope {@link #COMPONENT_SCOPE}, {@link #SPACE_SCOPE},	 * {@link #PAGE_SCOPE}, {@link #DESKTOP_SCOPE}, {@link #SESSION_SCOPE},	 * {@link #REQUEST_SCOPE} or {@link #APPLICATION_SCOPE}, 	 */	public Object getAttribute(String name, int scope);	/** Sets the value of the specified custom attribute in the specified scope.	 * <p>If scope is {@link #COMPONENT_SCOPE}, it means custom attributes private	 * to this component.	 * <p>If scope is {@link #SPACE_SCOPE}, it means custom attributes shared	 * by components from the same ID space as this one's.	 * <p>If scope is {@link #PAGE_SCOPE}, it means custom attributes shared	 * by components from the same page as this one's.	 * <p>If scope is {@link #DESKTOP_SCOPE}, it means custom attributes shared	 * by components from the same desktopas this one's.	 *	 * @param scope {@link #COMPONENT_SCOPE}, {@link #SPACE_SCOPE},	 * {@link #PAGE_SCOPE}, {@link #DESKTOP_SCOPE}, {@link #SESSION_SCOPE},	 * {@link #REQUEST_SCOPE} or {@link #APPLICATION_SCOPE}, 	 */	public Object setAttribute(String name, Object value, int scope);	/** Removes the specified custom attribute in the specified scope.	 * <p>If scope is {@link #COMPONENT_SCOPE}, it means attributes private	 * to this component.	 * <p>If scope is {@link #SPACE_SCOPE}, it means custom attributes shared	 * by components from the same ID space as this one's.	 * <p>If scope is {@link #PAGE_SCOPE}, it means custom attributes shared	 * by components from the same page as this one's.	 * <p>If scope is {@link #DESKTOP_SCOPE}, it means custom attributes shared	 * by components from the same desktopas this one's.	 *	 * @param scope {@link #COMPONENT_SCOPE}, {@link #SPACE_SCOPE},	 * {@link #PAGE_SCOPE}, {@link #DESKTOP_SCOPE}, {@link #SESSION_SCOPE},	 * {@link #REQUEST_SCOPE} or {@link #APPLICATION_SCOPE}, 	 */	public Object removeAttribute(String name, int scope);	/** Returns all custom attributes associated with this component, i.e.,	 * {@link #COMPONENT_SCOPE}.	 */	public Map getAttributes();	/** Returns the custom attribute associated with this component, i.e.,	 * {@link #COMPONENT_SCOPE}.	 */	public Object getAttribute(String name);	/** Sets the custom attribute associated with this component, i.e.,	 * {@link #COMPONENT_SCOPE}.	 */	public Object setAttribute(String name, Object value);	/** Removes the custom attribute associated with this component, i.e.,	 * {@link #COMPONENT_SCOPE}.	 */	public Object removeAttribute(String name);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?