org.zkoss.zk.ui.Desktop Maven / Gradle / Ivy
/* Desktop.java
Purpose:
Description:
History:
Fri Dec 9 16:27:21 2005, Created by tomyeh
Copyright (C) 2005 Potix Corporation. All Rights Reserved.
{{IS_RIGHT
This program is distributed under LGPL Version 2.1 in the hope that
it will be useful, but WITHOUT ANY WARRANTY.
}}IS_RIGHT
*/
package org.zkoss.zk.ui;
import java.util.Collection;
import java.util.Map;
import org.zkoss.util.media.Media;
import org.zkoss.zk.device.Device;
import org.zkoss.zk.ui.ext.Scope;
/**
* Represents a desktop.
* All pages that is created from the same URL is called a desktop.
*
* A desktop is created automatically when the first page is created
* during a request.
*
*
To access a {@link Page}, its desktop must be locked first.
* Once a desktop is locked to a request, all pages
* contained in this desktop are free to access.
*
* @author tomyeh
*/
public interface Desktop extends Scope {
/** Returns the device type that this desktop belongs to.
*
*
A device type identifies the type of a client. For example, "ajax"
* represents the Web browsers with Ajax support,
* while "mil" represents clients that supports
* Mobile Interactive markup Language (on Limited Connected Device,
* such as mobile phones).
*
*
A desktop can use the languages belonging to the same device type.
* See also {@link org.zkoss.zk.ui.metainfo.LanguageDefinition#getDeviceType}.
*
*
A component can be added to a desktop only if they belong to the same
* device type.
*
*
Default: depends on the extension of the resource path,
* "ajax" if the path or extension not available.
* If {@link Richlet} is used, its language definition's device type is
* assumed.
*/
public String getDeviceType();
/** Sets the device type that this desktop belongs to.
*
*
Note: you can change the device type only before any component
* is attached to a page of the desktop.
* In other words, you can set the device type only at the initialization
* stage.
*
*
If the device type is changed, any device allocated for this desktop
* ({@link #getDevice}) will be dropped and recreated at the next
* invocation to {@link #getDevice}.
*
* @exception UiException if any component is attached to a page of the desktop.
*/
public void setDeviceType(String deviceType);
/** Returns the device that is associated with this desktop.
*
Note: the device is shared by all desktops of the same device type.
*/
public Device getDevice();
/** Returns whether the desktop is still alive.
* It returns false once it is destroyed.
* @see org.zkoss.zk.ui.sys.DesktopCtrl#destroy
*/
public boolean isAlive();
/** Returns ID of this desktop.
* It is unique in the whole session.
*/
public String getId();
/** Returns the execution, or null if this desktop is not
* serving any execution (a.k.a., not locked).
*/
public Execution getExecution();
/** Returns the session of this desktop.
*/
public Session getSession();
/** Returns the Web application this desktop belongs to.
*/
public WebApp getWebApp();
/** Returns the page of the specified ID or UUID.
*
*
This is one of the only few method you could access
* before activating an execution.
*
* @param pageId the page's ID or UUID. ID has the higher priority.
* @exception ComponentNotFoundException if page not found
*/
public Page getPage(String pageId)
throws ComponentNotFoundException;
/** Returns the page of the specified ID or UUID, or null if no such page.
*
* @param pageId the page's ID or UUID. ID has the higher priority.
* @since 2.4.1
*/
public Page getPageIfAny(String pageId);
/** Returns a readonly collection of all {@link Page} in this desktop.
*/
public Collection getPages();
/** Returns the first page, or null if no page at all (happens when the desktop
* has been destroyed)
* @since 5.0.3
*/
public Page getFirstPage();
/** Returns whether a page exists.
*/
public boolean hasPage(String pageId);
/** Returns all custom attributes associated with this desktop.
*/
public Map getAttributes();
/** Returns the value of the specified custom attribute associated with the desktop.
*/
public Object getAttribute(String name);
/** Sets the value of the specified custom attribute associated with the desktop.
*/
public Object setAttribute(String name, Object value);
/** Removes the specified custom attribute associated with the desktop.
*/
public Object removeAttribute(String name);
/** Returns all components contained in this desktop.
*/
public Collection getComponents();
/** Returns the component of the specified UUID ({@link Component#getUuid}).
* @exception ComponentNotFoundException if component not found
*/
public Component getComponentByUuid(String uuid);
/** Returns the component of the specified UUID
* ({@link Component#getUuid}), or null if not found.
*/
public Component getComponentByUuidIfAny(String uuid);
/** Returns the URI for asynchronous update.
*
* You rarely need this method unless for implementing special
* components, such as file upload.
*
* @param pathInfo the path to append to the returned URI, or null
* to ignore
*/
public String getUpdateURI(String pathInfo);
/** Returns the path of the request that causes
* this desktop to be created, or "" if not available.
* In other words, it is the request path of the first page
* (see {@link Page#getRequestPath}).
*
*
For example, "/foo/index.zul" (a ZUML page is requested)
* or /test (a richlet).
*
* @see Page#getRequestPath
* @since 3.0.0
*/
public String getRequestPath();
/** Returns the query string that is contained in the request URL after the
* path ({@link #getRequestPath}), or null if the URL does not have a query
* string.
* @since 5.0.2
*/
public String getQueryString();
/** Returns the current directory (never null).
* It is empty if no current directory at all.
* Otherwise, it must end with '/'.
* In other words, you could use getCurrentDirectory() + relative_path.
*/
public String getCurrentDirectory();
/** Sets the current directory.
* @param dir the current directory. If null, an empty string is assumed
* (means no current directory at all).
*/
public void setCurrentDirectory(String dir);
/** Returns the current bookmark (never null).
* The returned might be the same as the last call to {@link #setBookmark},
* because user might use BACK, FORWARD or others to change the bookmark.
*/
public String getBookmark();
/** Sets a bookmark to this desktop. Then, when user press BACK, FORWARD
* or specify an URL with this bookmark, the onBookmarkChange event
* is sent to all pages of the desktop.
*
It is the same as setBookmark(name, false)
*/
public void setBookmark(String name);
/**
* Sets the bookmark to this desktop. with more control.
* @param name the name of the bookmark
* @param replace if true, the bookmark is replaced (in the history list)
* @since 3.6.4
* @see #setBookmark(String)
*/
public void setBookmark(String name, boolean replace);
/** Returns URI for a dynamic generated media associated with a component.
* ZK Update Engine will then invoke invoke
* {@link org.zkoss.zk.ui.ext.render.DynamicMedia#getMedia} to response.
*
*
Note: to use with this method, {@link org.zkoss.zk.ui.ext.render.DynamicMedia}
* must be implemented as part of the object returned by
* {@link org.zkoss.zk.ui.sys.ComponentCtrl#getExtraCtrl}.
*
*
Used mainly for component implementation.
*/
public String getDynamicMediaURI(Component comp, String pathInfo);
/** Returns URI for a media that is used to download to the client.
* The client will open a Save As dialog to save the specified file.
*
*
Note: once called, the media belongs to desktop and it is
* purged automatically. Thus, don't access it again after calling
* this method.
*/
public String getDownloadMediaURI(Media media, String pathInfo);
/** Enables or disables the server-push feature.
* Before using any server-push threads, you have to enable it
* for the particular desktop first by use of this method.
* Refer to {@link Executions#activate} for more details.
*
*
Default: false
*
*
This method uses the default class
* (defined by {@link Device#getServerPushClass})
* to instantiate the server-push controller.
*
* @param enable whether to enable or to disable the server-push
* feature.
* @see Executions#activate
* @see Device#getServerPushClass
* @see org.zkoss.zk.ui.sys.DesktopCtrl#enableServerPush(org.zkoss.zk.ui.sys.ServerPush)
* @since 3.0.0
*/
public boolean enableServerPush(boolean enable);
/** Returns whether the server-push feature is enabled for this
* desktop.
*
*
Default: false.
*
* @since 3.0.0
*/
public boolean isServerPushEnabled();
/** Adds a listener.
*
*
Note: if the listener is added twice, it will be invoked
* twice when a corresponding event occurs.
*
* @param listener the listener. It cannot be null.
* It must be an instance that implements
* {@link org.zkoss.zk.ui.util.DesktopCleanup},
* {@link org.zkoss.zk.ui.util.ExecutionInit},
* {@link org.zkoss.zk.ui.util.ExecutionCleanup},
* {@link org.zkoss.zk.ui.util.UiLifeCycle},
* {@link org.zkoss.zk.ui.util.EventInterceptor}
* and/or {@link org.zkoss.zk.au.AuService}.
* Note: {@link org.zkoss.zk.ui.util.DesktopInit},
* {@link org.zkoss.zk.ui.event.EventThreadInit},
* {@link org.zkoss.zk.ui.event.EventThreadCleanup},
* {@link org.zkoss.zk.ui.event.EventThreadSuspend} and
* {@link org.zkoss.zk.ui.event.EventThreadResume} are not supported.
* @exception IllegalArgumentException if not a valid listener.
* @since 3.0.6
*/
public void addListener(Object listener);
/** Removes a listener.
*
* @return whether the listener is removed successfully.
* {@link Object#equals} is used to check whether a listener is added.
* @since 3.0.6
*/
public boolean removeListener(Object listener);
/** Invalidates the desktop.
* All pages will be redrawn.
* @since 3.0.6
*/
public void invalidate();
}