001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.webcontainer.syncpeer;
031:
032: import nextapp.echo2.app.Component;
033: import nextapp.echo2.app.Window;
034: import nextapp.echo2.app.update.ServerComponentUpdate;
035: import nextapp.echo2.webcontainer.PartialUpdateManager;
036: import nextapp.echo2.webcontainer.PartialUpdateParticipant;
037: import nextapp.echo2.webcontainer.RenderContext;
038: import nextapp.echo2.webcontainer.RootSynchronizePeer;
039: import nextapp.echo2.webcontainer.ComponentSynchronizePeer;
040: import nextapp.echo2.webcontainer.SynchronizePeerFactory;
041: import nextapp.echo2.webcontainer.WindowHtmlService;
042: import nextapp.echo2.webrender.servermessage.DomUpdate;
043: import nextapp.echo2.webrender.servermessage.WindowUpdate;
044:
045: /**
046: * Synchronization peer for <code>nextapp.echo2.app.Window</code> components.
047: * <p>
048: * This class should not be extended or used by classes outside of the
049: * Echo framework.
050: */
051: public class WindowPeer implements RootSynchronizePeer {
052:
053: private PartialUpdateManager partialUpdateManager;
054:
055: /**
056: * Default constructor.
057: */
058: public WindowPeer() {
059: super ();
060: partialUpdateManager = new PartialUpdateManager();
061: partialUpdateManager.add(Window.PROPERTY_TITLE,
062: new PartialUpdateParticipant() {
063:
064: /**
065: * @see nextapp.echo2.webcontainer.PartialUpdateParticipant#canRenderProperty(nextapp.echo2.webcontainer.RenderContext,
066: * nextapp.echo2.app.update.ServerComponentUpdate)
067: */
068: public boolean canRenderProperty(RenderContext rc,
069: ServerComponentUpdate update) {
070: return true;
071: }
072:
073: /**
074: * @see nextapp.echo2.webcontainer.PartialUpdateParticipant#renderProperty(
075: * nextapp.echo2.webcontainer.RenderContext, nextapp.echo2.app.update.ServerComponentUpdate)
076: */
077: public void renderProperty(RenderContext rc,
078: ServerComponentUpdate update) {
079: Window window = (Window) update.getParent();
080: String title = (String) window
081: .getRenderProperty(Window.PROPERTY_TITLE);
082: WindowUpdate.renderSetWindowTitle(rc
083: .getServerMessage(), title);
084: }
085: });
086: }
087:
088: /**
089: * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderAdd(nextapp.echo2.webcontainer.RenderContext,
090: * nextapp.echo2.app.update.ServerComponentUpdate, java.lang.String, nextapp.echo2.app.Component)
091: */
092: public void renderAdd(RenderContext rc,
093: ServerComponentUpdate update, String targetId,
094: Component component) {
095: throw new UnsupportedOperationException("Cannot add window.");
096: }
097:
098: /**
099: * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#getContainerId(nextapp.echo2.app.Component)
100: */
101: public String getContainerId(Component child) {
102: return WindowHtmlService.ROOT_ID;
103: }
104:
105: /**
106: * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderDispose(nextapp.echo2.webcontainer.RenderContext,
107: * nextapp.echo2.app.update.ServerComponentUpdate, nextapp.echo2.app.Component)
108: */
109: public void renderDispose(RenderContext rc,
110: ServerComponentUpdate update, Component component) {
111: // Do nothing.
112: }
113:
114: /**
115: * @see nextapp.echo2.webcontainer.RootSynchronizePeer#renderRefresh(nextapp.echo2.webcontainer.RenderContext,
116: * nextapp.echo2.app.update.ServerComponentUpdate, nextapp.echo2.app.Component)
117: */
118: public void renderRefresh(RenderContext rc,
119: ServerComponentUpdate update, Component component) {
120: Window window = (Window) component;
121:
122: String title = (String) window
123: .getRenderProperty(Window.PROPERTY_TITLE);
124: if (title != null) {
125: WindowUpdate.renderSetWindowTitle(rc.getServerMessage(),
126: title);
127: }
128:
129: DomUpdate.renderElementRemoveChildren(rc.getServerMessage(),
130: WindowHtmlService.ROOT_ID);
131: Component[] addedChildren = window.getVisibleComponents();
132: for (int i = 0; i < addedChildren.length; ++i) {
133: ComponentSynchronizePeer childSyncPeer = SynchronizePeerFactory
134: .getPeerForComponent(addedChildren[i].getClass());
135: childSyncPeer.renderAdd(rc, update,
136: WindowHtmlService.ROOT_ID, addedChildren[i]);
137: }
138: }
139:
140: /**
141: * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderUpdate(nextapp.echo2.webcontainer.RenderContext,
142: * nextapp.echo2.app.update.ServerComponentUpdate, java.lang.String)
143: */
144: public boolean renderUpdate(RenderContext rc,
145: ServerComponentUpdate update, String targetId) {
146: boolean fullRefresh;
147: if (update.hasAddedChildren() || update.hasRemovedChildren()
148: || update.hasUpdatedLayoutDataChildren()) {
149: fullRefresh = true;
150: } else if (update.hasUpdatedProperties()
151: && partialUpdateManager.canProcess(rc, update)) {
152: fullRefresh = false;
153: } else {
154: fullRefresh = true;
155: }
156:
157: if (fullRefresh) {
158: renderRefresh(rc, update, update.getParent());
159: } else {
160: partialUpdateManager.process(rc, update);
161: }
162:
163: return fullRefresh;
164: }
165: }
|