KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > webcontainer > syncpeer > WindowPeer


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.webcontainer.syncpeer;
31
32 import nextapp.echo2.app.Component;
33 import nextapp.echo2.app.Window;
34 import nextapp.echo2.app.update.ServerComponentUpdate;
35 import nextapp.echo2.webcontainer.PartialUpdateManager;
36 import nextapp.echo2.webcontainer.PartialUpdateParticipant;
37 import nextapp.echo2.webcontainer.RenderContext;
38 import nextapp.echo2.webcontainer.RootSynchronizePeer;
39 import nextapp.echo2.webcontainer.ComponentSynchronizePeer;
40 import nextapp.echo2.webcontainer.SynchronizePeerFactory;
41 import nextapp.echo2.webcontainer.WindowHtmlService;
42 import nextapp.echo2.webrender.servermessage.DomUpdate;
43 import nextapp.echo2.webrender.servermessage.WindowUpdate;
44
45 /**
46  * Synchronization peer for <code>nextapp.echo2.app.Window</code> components.
47  * <p>
48  * This class should not be extended or used by classes outside of the
49  * Echo framework.
50  */

51 public class WindowPeer
52 implements RootSynchronizePeer {
53
54     private PartialUpdateManager partialUpdateManager;
55
56     /**
57      * Default constructor.
58      */

59     public WindowPeer() {
60         super();
61         partialUpdateManager = new PartialUpdateManager();
62         partialUpdateManager.add(Window.PROPERTY_TITLE, new PartialUpdateParticipant() {
63             
64             /**
65              * @see nextapp.echo2.webcontainer.PartialUpdateParticipant#canRenderProperty(nextapp.echo2.webcontainer.RenderContext,
66              * nextapp.echo2.app.update.ServerComponentUpdate)
67              */

68             public boolean canRenderProperty(RenderContext rc, ServerComponentUpdate update) {
69                 return true;
70             }
71
72             /**
73              * @see nextapp.echo2.webcontainer.PartialUpdateParticipant#renderProperty(
74              * nextapp.echo2.webcontainer.RenderContext, nextapp.echo2.app.update.ServerComponentUpdate)
75              */

76             public void renderProperty(RenderContext rc, ServerComponentUpdate update) {
77                 Window window = (Window) update.getParent();
78                 String JavaDoc title = (String JavaDoc) window.getRenderProperty(Window.PROPERTY_TITLE);
79                 WindowUpdate.renderSetWindowTitle(rc.getServerMessage(), title);
80             }
81         });
82     }
83        
84     /**
85      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderAdd(nextapp.echo2.webcontainer.RenderContext,
86      * nextapp.echo2.app.update.ServerComponentUpdate, java.lang.String, nextapp.echo2.app.Component)
87      */

88     public void renderAdd(RenderContext rc, ServerComponentUpdate update,
89             String JavaDoc targetId, Component component) {
90         throw new UnsupportedOperationException JavaDoc("Cannot add window.");
91     }
92
93     /**
94      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#getContainerId(nextapp.echo2.app.Component)
95      */

96     public String JavaDoc getContainerId(Component child) {
97         return WindowHtmlService.ROOT_ID;
98     }
99     
100     /**
101      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderDispose(nextapp.echo2.webcontainer.RenderContext,
102      * nextapp.echo2.app.update.ServerComponentUpdate, nextapp.echo2.app.Component)
103      */

104     public void renderDispose(RenderContext rc, ServerComponentUpdate update, Component component) {
105         // Do nothing.
106
}
107     
108     /**
109      * @see nextapp.echo2.webcontainer.RootSynchronizePeer#renderRefresh(nextapp.echo2.webcontainer.RenderContext,
110      * nextapp.echo2.app.update.ServerComponentUpdate, nextapp.echo2.app.Component)
111      */

112     public void renderRefresh(RenderContext rc, ServerComponentUpdate update, Component component) {
113         Window window = (Window) component;
114         
115         String JavaDoc title = (String JavaDoc) window.getRenderProperty(Window.PROPERTY_TITLE);
116         if (title != null) {
117             WindowUpdate.renderSetWindowTitle(rc.getServerMessage(), title);
118         }
119         
120         DomUpdate.renderElementRemoveChildren(rc.getServerMessage(), WindowHtmlService.ROOT_ID);
121         Component[] addedChildren = window.getVisibleComponents();
122         for (int i = 0; i < addedChildren.length; ++i) {
123             ComponentSynchronizePeer childSyncPeer = SynchronizePeerFactory.getPeerForComponent(addedChildren[i].getClass());
124             childSyncPeer.renderAdd(rc, update, WindowHtmlService.ROOT_ID, addedChildren[i]);
125         }
126     }
127
128     /**
129      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderUpdate(nextapp.echo2.webcontainer.RenderContext,
130      * nextapp.echo2.app.update.ServerComponentUpdate, java.lang.String)
131      */

132     public boolean renderUpdate(RenderContext rc, ServerComponentUpdate update, String JavaDoc targetId) {
133         boolean fullRefresh;
134         if (update.hasAddedChildren() || update.hasRemovedChildren() || update.hasUpdatedLayoutDataChildren()) {
135             fullRefresh = true;
136         } else if (update.hasUpdatedProperties() && partialUpdateManager.canProcess(rc, update)) {
137             fullRefresh = false;
138         } else {
139             fullRefresh = true;
140         }
141         
142         if (fullRefresh) {
143             renderRefresh(rc, update, update.getParent());
144         } else {
145             partialUpdateManager.process(rc, update);
146         }
147         
148         return fullRefresh;
149     }
150 }
151
Popular Tags