KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.IOException JavaDoc;
33
34 import org.w3c.dom.Element JavaDoc;
35
36 import nextapp.echo2.app.Color;
37 import nextapp.echo2.app.Component;
38 import nextapp.echo2.app.Extent;
39 import nextapp.echo2.app.FillImage;
40 import nextapp.echo2.app.FillImageBorder;
41 import nextapp.echo2.app.Font;
42 import nextapp.echo2.app.ImageReference;
43 import nextapp.echo2.app.Insets;
44 import nextapp.echo2.app.ResourceImageReference;
45 import nextapp.echo2.app.WindowPane;
46 import nextapp.echo2.app.update.PropertyUpdate;
47 import nextapp.echo2.app.update.ServerComponentUpdate;
48 import nextapp.echo2.webcontainer.ActionProcessor;
49 import nextapp.echo2.webcontainer.ComponentSynchronizePeer;
50 import nextapp.echo2.webcontainer.ContainerInstance;
51 import nextapp.echo2.webcontainer.PartialUpdateManager;
52 import nextapp.echo2.webcontainer.PartialUpdateParticipant;
53 import nextapp.echo2.webcontainer.PropertyUpdateProcessor;
54 import nextapp.echo2.webcontainer.RenderContext;
55 import nextapp.echo2.webcontainer.SynchronizePeerFactory;
56 import nextapp.echo2.webcontainer.image.ImageRenderSupport;
57 import nextapp.echo2.webcontainer.image.ImageTools;
58 import nextapp.echo2.webcontainer.propertyrender.ColorRender;
59 import nextapp.echo2.webcontainer.propertyrender.ExtentRender;
60 import nextapp.echo2.webcontainer.propertyrender.FillImageRender;
61 import nextapp.echo2.webcontainer.propertyrender.FontRender;
62 import nextapp.echo2.webcontainer.propertyrender.InsetsRender;
63 import nextapp.echo2.webrender.Connection;
64 import nextapp.echo2.webrender.ContentType;
65 import nextapp.echo2.webrender.ServerMessage;
66 import nextapp.echo2.webrender.Service;
67 import nextapp.echo2.webrender.WebRenderServlet;
68 import nextapp.echo2.webrender.output.CssStyle;
69 import nextapp.echo2.webrender.servermessage.DomUpdate;
70 import nextapp.echo2.webrender.service.JavaScriptService;
71
72 /**
73  * Synchronization peer for <code>nextapp.echo2.app.WindowPane</code>
74  * components.
75  * <p>
76  * This class should not be extended or used by classes outside of the Echo
77  * framework.
78  */

79 public class WindowPanePeer implements ActionProcessor, ImageRenderSupport,
80         PropertyUpdateProcessor, ComponentSynchronizePeer {
81
82     /**
83      * A boolean property which may be assigned to <code>WindowPane</code>s
84      * in order to enable the proprietary Internet Explorer transparent PNG
85      * alpha renderer for rendering the <code>border</code> property of the
86      * window pane.
87      */

88     public static final String JavaDoc PROPERTY_IE_ALPHA_RENDER_BORDER
89             = "nextapp.echo2.webcontainer.syncpeer.WindowPanePeer.ieAlphaRenderBorder";
90     
91     private static final String JavaDoc IMAGE_ID_TITLE_BACKGROUND = "titleBackground";
92     private static final String JavaDoc IMAGE_ID_CLOSE_ICON = "close";
93     private static final String JavaDoc IMAGE_ID_ICON = "icon";
94     private static final String JavaDoc IMAGE_ID_BACKGROUND = "background";
95     private static final String JavaDoc IMAGE_ID_BORDER_TOP_LEFT = "borderTopLeft";
96     private static final String JavaDoc IMAGE_ID_BORDER_TOP = "borderTop";
97     private static final String JavaDoc IMAGE_ID_BORDER_TOP_RIGHT = "borderTopRight";
98     private static final String JavaDoc IMAGE_ID_BORDER_LEFT = "borderLeft";
99     private static final String JavaDoc IMAGE_ID_BORDER_RIGHT = "borderRight";
100     private static final String JavaDoc IMAGE_ID_BORDER_BOTTOM_LEFT = "borderBottomLeft";
101     private static final String JavaDoc IMAGE_ID_BORDER_BOTTOM = "borderBottom";
102     private static final String JavaDoc IMAGE_ID_BORDER_BOTTOM_RIGHT = "borderBottomRight";
103
104     private static final ImageReference DEFAULT_CLOSE_ICON = new ResourceImageReference(
105             "/nextapp/echo2/webcontainer/resource/image/DefaultCloseButton.gif");
106
107     private static final String JavaDoc[] FILL_IMAGE_NAMES = {"tl", "t", "tr", "l", "r", "bl", "b", "br"};
108     private static final String JavaDoc[] FILL_IMAGE_IDS = {
109             IMAGE_ID_BORDER_TOP_LEFT, IMAGE_ID_BORDER_TOP, IMAGE_ID_BORDER_TOP_RIGHT, IMAGE_ID_BORDER_LEFT,
110             IMAGE_ID_BORDER_RIGHT, IMAGE_ID_BORDER_BOTTOM_LEFT, IMAGE_ID_BORDER_BOTTOM, IMAGE_ID_BORDER_BOTTOM_RIGHT };
111     
112     private static final String JavaDoc BLANK_HTML_STRING = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "
113             + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
114             + "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title><body></body></html>";
115     
116     private static final Service BLANK_HTML_SERVICE = new Service() {
117
118         /**
119          * @see nextapp.echo2.webrender.Service#getId()
120          */

121         public String JavaDoc getId() {
122             return "Echo.WindowPane.IFrame";
123         }
124     
125         /**
126          * @see nextapp.echo2.webrender.Service#getVersion()
127          */

128         public int getVersion() {
129             return 0;
130         }
131     
132         /**
133          * @see nextapp.echo2.webrender.Service#service(nextapp.echo2.webrender.Connection)
134          */

135         public void service(Connection conn) throws IOException JavaDoc {
136             conn.setContentType(ContentType.TEXT_HTML);
137             conn.getWriter().write(BLANK_HTML_STRING);
138         }
139     };
140     
141     /**
142      * Service to provide supporting JavaScript library.
143      */

144     public static final Service WINDOW_PANE_SERVICE = JavaScriptService.forResource("Echo.WindowPane",
145             "/nextapp/echo2/webcontainer/resource/js/WindowPane.js");
146
147     static {
148         WebRenderServlet.getServiceRegistry().add(WINDOW_PANE_SERVICE);
149         WebRenderServlet.getServiceRegistry().add(BLANK_HTML_SERVICE);
150     }
151
152     private static void renderPixelProperty(WindowPane windowPane, String JavaDoc propertyName, Element JavaDoc element, String JavaDoc attributeName) {
153         String JavaDoc pixelValue;
154         Extent extent = (Extent) windowPane.getRenderProperty(propertyName);
155         if (extent != null) {
156             pixelValue = ExtentRender.renderCssAttributePixelValue(extent);
157             if (pixelValue != null) {
158                 element.setAttribute(attributeName, pixelValue);
159             }
160         }
161     }
162
163     private PartialUpdateParticipant placeHolder = new PartialUpdateParticipant() {
164
165         public boolean canRenderProperty(RenderContext rc, ServerComponentUpdate update) {
166             return true;
167         }
168
169         public void renderProperty(RenderContext rc, ServerComponentUpdate update) {
170             // Do nothing.
171
}
172     };
173     
174     private PartialUpdateManager partialUpdateManager;
175
176     /**
177      * Default constructor.
178      */

179     public WindowPanePeer() {
180         super();
181         partialUpdateManager = new PartialUpdateManager();
182         partialUpdateManager.add(WindowPane.PROPERTY_POSITION_X, placeHolder);
183         partialUpdateManager.add(WindowPane.PROPERTY_POSITION_Y, placeHolder);
184         partialUpdateManager.add(WindowPane.PROPERTY_WIDTH, placeHolder);
185         partialUpdateManager.add(WindowPane.PROPERTY_HEIGHT, placeHolder);
186         partialUpdateManager.add(WindowPane.PROPERTY_TITLE, placeHolder);
187     }
188     
189     /**
190      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#getContainerId(nextapp.echo2.app.Component)
191      */

192     public String JavaDoc getContainerId(Component child) {
193         return ContainerInstance.getElementId(child.getParent()) + "_content";
194     }
195     
196     /**
197      * @see nextapp.echo2.webcontainer.image.ImageRenderSupport#getImage(nextapp.echo2.app.Component,
198      * java.lang.String)
199      */

200     public ImageReference getImage(Component component, String JavaDoc imageId) {
201         if (IMAGE_ID_TITLE_BACKGROUND.equals(imageId)) {
202             FillImage backgroundImage = (FillImage) component.getRenderProperty(WindowPane.PROPERTY_TITLE_BACKGROUND_IMAGE);
203             return backgroundImage == null ? null : backgroundImage.getImage();
204         } else if (IMAGE_ID_BACKGROUND.equals(imageId)) {
205             FillImage backgroundImage = (FillImage) component.getRenderProperty(WindowPane.PROPERTY_BACKGROUND_IMAGE);
206             return backgroundImage == null ? null : backgroundImage.getImage();
207         } else if (IMAGE_ID_ICON.equals(imageId)) {
208             return (ImageReference) component.getRenderProperty(WindowPane.PROPERTY_ICON);
209         } else if (IMAGE_ID_CLOSE_ICON.equals(imageId)) {
210             return (ImageReference) component.getRenderProperty(WindowPane.PROPERTY_CLOSE_ICON, DEFAULT_CLOSE_ICON);
211         } else if (IMAGE_ID_BORDER_TOP_LEFT.equals(imageId)) {
212             FillImageBorder fillImageBorder = ((FillImageBorder) component.getRenderProperty(WindowPane.PROPERTY_BORDER));
213             FillImage fillImage = fillImageBorder == null ? null : fillImageBorder.getFillImage(FillImageBorder.TOP_LEFT);
214             return fillImage == null ? null : fillImage.getImage();
215         } else if (IMAGE_ID_BORDER_TOP.equals(imageId)) {
216             FillImageBorder fillImageBorder = ((FillImageBorder) component.getRenderProperty(WindowPane.PROPERTY_BORDER));
217             FillImage fillImage = fillImageBorder == null ? null : fillImageBorder.getFillImage(FillImageBorder.TOP);
218             return fillImage == null ? null : fillImage.getImage();
219         } else if (IMAGE_ID_BORDER_TOP_RIGHT.equals(imageId)) {
220             FillImageBorder fillImageBorder = ((FillImageBorder) component.getRenderProperty(WindowPane.PROPERTY_BORDER));
221             FillImage fillImage = fillImageBorder == null ? null : fillImageBorder.getFillImage(FillImageBorder.TOP_RIGHT);
222             return fillImage == null ? null : fillImage.getImage();
223         } else if (IMAGE_ID_BORDER_LEFT.equals(imageId)) {
224             FillImageBorder fillImageBorder = ((FillImageBorder) component.getRenderProperty(WindowPane.PROPERTY_BORDER));
225             FillImage fillImage = fillImageBorder == null ? null : fillImageBorder.getFillImage(FillImageBorder.LEFT);
226             return fillImage == null ? null : fillImage.getImage();
227         } else if (IMAGE_ID_BORDER_RIGHT.equals(imageId)) {
228             FillImageBorder fillImageBorder = ((FillImageBorder) component.getRenderProperty(WindowPane.PROPERTY_BORDER));
229             FillImage fillImage = fillImageBorder == null ? null : fillImageBorder.getFillImage(FillImageBorder.RIGHT);
230             return fillImage == null ? null : fillImage.getImage();
231         } else if (IMAGE_ID_BORDER_BOTTOM_LEFT.equals(imageId)) {
232             FillImageBorder fillImageBorder = ((FillImageBorder) component.getRenderProperty(WindowPane.PROPERTY_BORDER));
233             FillImage fillImage = fillImageBorder == null ? null : fillImageBorder.getFillImage(FillImageBorder.BOTTOM_LEFT);
234             return fillImage == null ? null : fillImage.getImage();
235         } else if (IMAGE_ID_BORDER_BOTTOM.equals(imageId)) {
236             FillImageBorder fillImageBorder = ((FillImageBorder) component.getRenderProperty(WindowPane.PROPERTY_BORDER));
237             FillImage fillImage = fillImageBorder == null ? null : fillImageBorder.getFillImage(FillImageBorder.BOTTOM);
238             return fillImage == null ? null : fillImage.getImage();
239         } else if (IMAGE_ID_BORDER_BOTTOM_RIGHT.equals(imageId)) {
240             FillImageBorder fillImageBorder = ((FillImageBorder) component.getRenderProperty(WindowPane.PROPERTY_BORDER));
241             FillImage fillImage = fillImageBorder == null ? null : fillImageBorder.getFillImage(FillImageBorder.BOTTOM_RIGHT);
242             return fillImage == null ? null : fillImage.getImage();
243         } else {
244             return null;
245         }
246     }
247
248     /**
249      * @see nextapp.echo2.webcontainer.ActionProcessor#processAction(nextapp.echo2.webcontainer.ContainerInstance,
250      * nextapp.echo2.app.Component, org.w3c.dom.Element)
251      */

252     public void processAction(ContainerInstance ci, Component component, Element JavaDoc actionElement) {
253         WindowPane windowPane = (WindowPane) component;
254         boolean closable = ((Boolean JavaDoc) windowPane.getRenderProperty(WindowPane.PROPERTY_CLOSABLE, Boolean.TRUE)).booleanValue();
255         if (closable) {
256             ci.getUpdateManager().getClientUpdateManager().setComponentAction(component, WindowPane.INPUT_CLOSE, null);
257         }
258     }
259
260     /**
261      * @see nextapp.echo2.webcontainer.PropertyUpdateProcessor#processPropertyUpdate(
262      * nextapp.echo2.webcontainer.ContainerInstance,
263      * nextapp.echo2.app.Component, org.w3c.dom.Element)
264      */

265     public void processPropertyUpdate(ContainerInstance ci, Component component, Element JavaDoc propertyElement) {
266         String JavaDoc propertyName = propertyElement.getAttribute(PropertyUpdateProcessor.PROPERTY_NAME);
267         WindowPane windowPane = (WindowPane) component;
268         boolean movable = ((Boolean JavaDoc) windowPane.getRenderProperty(WindowPane.PROPERTY_MOVABLE, Boolean.TRUE)).booleanValue();
269         boolean resizable = ((Boolean JavaDoc) windowPane.getRenderProperty(WindowPane.PROPERTY_RESIZABLE, Boolean.TRUE)).booleanValue();
270         if (WindowPane.PROPERTY_POSITION_X.equals(propertyName)) {
271             if (movable) {
272                 ci.getUpdateManager().getClientUpdateManager().setComponentProperty(component, WindowPane.PROPERTY_POSITION_X,
273                         ExtentRender.toExtent(propertyElement.getAttribute(PropertyUpdateProcessor.PROPERTY_VALUE)));
274             }
275         } else if (WindowPane.PROPERTY_POSITION_Y.equals(propertyName)) {
276             if (movable) {
277                 ci.getUpdateManager().getClientUpdateManager().setComponentProperty(component, WindowPane.PROPERTY_POSITION_Y,
278                         ExtentRender.toExtent(propertyElement.getAttribute(PropertyUpdateProcessor.PROPERTY_VALUE)));
279             }
280         } else if (WindowPane.PROPERTY_WIDTH.equals(propertyName)) {
281             if (resizable) {
282                 ci.getUpdateManager().getClientUpdateManager().setComponentProperty(component, WindowPane.PROPERTY_WIDTH,
283                         ExtentRender.toExtent(propertyElement.getAttribute(PropertyUpdateProcessor.PROPERTY_VALUE)));
284             }
285         } else if (WindowPane.PROPERTY_HEIGHT.equals(propertyName)) {
286             if (resizable) {
287                 ci.getUpdateManager().getClientUpdateManager().setComponentProperty(component, WindowPane.PROPERTY_HEIGHT,
288                         ExtentRender.toExtent(propertyElement.getAttribute(PropertyUpdateProcessor.PROPERTY_VALUE)));
289             }
290         } else if (WindowPane.Z_INDEX_CHANGED_PROPERTY.equals(propertyName)) {
291             ci.getUpdateManager().getClientUpdateManager().setComponentProperty(component, WindowPane.Z_INDEX_CHANGED_PROPERTY,
292                     new Integer JavaDoc(propertyElement.getAttribute(PropertyUpdateProcessor.PROPERTY_VALUE)));
293         }
294     }
295
296
297     /**
298      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderAdd(nextapp.echo2.webcontainer.RenderContext,
299      * nextapp.echo2.app.update.ServerComponentUpdate, java.lang.String,
300      * nextapp.echo2.app.Component)
301      */

302     public void renderAdd(RenderContext rc, ServerComponentUpdate update,
303             String JavaDoc targetId, Component component) {
304         ServerMessage serverMessage = rc.getServerMessage();
305         serverMessage.addLibrary(WINDOW_PANE_SERVICE.getId());
306         WindowPane windowPane = (WindowPane) component;
307         renderInitDirective(rc, windowPane, targetId);
308         Component[] children = windowPane.getVisibleComponents();
309         if (children.length != 0) {
310             ComponentSynchronizePeer syncPeer = SynchronizePeerFactory.getPeerForComponent(children[0].getClass());
311             syncPeer.renderAdd(rc, update, getContainerId(children[0]), children[0]);
312         }
313     }
314
315     /**
316      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderDispose(nextapp.echo2.webcontainer.RenderContext,
317      * nextapp.echo2.app.update.ServerComponentUpdate,
318      * nextapp.echo2.app.Component)
319      */

320     public void renderDispose(RenderContext rc, ServerComponentUpdate update,
321             Component component) {
322         ServerMessage serverMessage = rc.getServerMessage();
323         serverMessage.addLibrary(WINDOW_PANE_SERVICE.getId());
324         renderDisposeDirective(rc, (WindowPane) component);
325     }
326
327     /**
328      * Renders a directive to the outgoing <code>ServerMessage</code> to
329      * dispose the state of a <code>WindowPane</code>, performing tasks such as
330      * unregistering event listeners on the client.
331      *
332      * @param rc the relevant <code>RenderContext</code>
333      * @param windowPane the <code>WindowPane</code>
334      */

335     private void renderDisposeDirective(RenderContext rc, WindowPane windowPane) {
336         String JavaDoc elementId = ContainerInstance.getElementId(windowPane);
337         ServerMessage serverMessage = rc.getServerMessage();
338         Element JavaDoc initElement = serverMessage.appendPartDirective(ServerMessage.GROUP_ID_PREREMOVE,
339                 "EchoWindowPane.MessageProcessor", "dispose");
340         initElement.setAttribute("eid", elementId);
341     }
342
343     /**
344      * Renders a directive to the outgoing <code>ServerMessage</code> to
345      * render and intialize the state of a <code>WindowPane</code>.
346      *
347      * @param rc the relevant <code>RenderContext</code>
348      * @param windowPane the <code>WindowPane</code>
349      * @param targetId the id of the container element
350      */

351     private void renderInitDirective(RenderContext rc, WindowPane windowPane, String JavaDoc targetId) {
352         String JavaDoc elementId = ContainerInstance.getElementId(windowPane);
353         ServerMessage serverMessage = rc.getServerMessage();
354         Element JavaDoc partElement = serverMessage.addPart(ServerMessage.GROUP_ID_UPDATE, "EchoWindowPane.MessageProcessor");
355         Element JavaDoc initElement = serverMessage.getDocument().createElement("init");
356         initElement.setAttribute("container-eid", targetId);
357         initElement.setAttribute("eid", elementId);
358
359         if (!windowPane.isRenderEnabled()) {
360             initElement.setAttribute("enabled", "false");
361         }
362         if (windowPane.getZIndex() != 0) {
363             initElement.setAttribute("z-index", Integer.toString(windowPane.getZIndex()));
364         }
365         
366         // Content Appearance
367
Insets insets = (Insets) windowPane.getRenderProperty(WindowPane.PROPERTY_INSETS);
368         if (insets != null) {
369             initElement.setAttribute("insets", InsetsRender.renderCssAttributeValue(insets));
370         }
371         Color background = (Color) windowPane.getRenderProperty(WindowPane.PROPERTY_BACKGROUND);
372         if (background != null) {
373             initElement.setAttribute("background", ColorRender.renderCssAttributeValue(background));
374         }
375         FillImage backgroundImage = (FillImage) windowPane.getRenderProperty(WindowPane.PROPERTY_BACKGROUND_IMAGE);
376         if (backgroundImage != null) {
377             CssStyle backgroundImageCssStyle = new CssStyle();
378             FillImageRender.renderToStyle(backgroundImageCssStyle, rc, this, windowPane, IMAGE_ID_BACKGROUND,
379                     backgroundImage, 0);
380             initElement.setAttribute("background-image", backgroundImageCssStyle.renderInline());
381         }
382         Color foreground = (Color) windowPane.getRenderProperty(WindowPane.PROPERTY_FOREGROUND);
383         if (foreground != null) {
384             initElement.setAttribute("foreground", ColorRender.renderCssAttributeValue(foreground));
385         }
386         Font font = (Font) windowPane.getRenderProperty(WindowPane.PROPERTY_FONT);
387         if (font != null) {
388             CssStyle fontCssStyle = new CssStyle();
389             FontRender.renderToStyle(fontCssStyle, font);
390             initElement.setAttribute("font", fontCssStyle.renderInline());
391         }
392
393         // Positioning
394
renderPixelProperty(windowPane, WindowPane.PROPERTY_POSITION_X, initElement, "position-x");
395         renderPixelProperty(windowPane, WindowPane.PROPERTY_POSITION_Y, initElement, "position-y");
396         renderPixelProperty(windowPane, WindowPane.PROPERTY_WIDTH, initElement, "width");
397         renderPixelProperty(windowPane, WindowPane.PROPERTY_HEIGHT, initElement, "height");
398         renderPixelProperty(windowPane, WindowPane.PROPERTY_MINIMUM_WIDTH, initElement, "minimum-width");
399         renderPixelProperty(windowPane, WindowPane.PROPERTY_MINIMUM_HEIGHT, initElement, "minimum-height");
400         renderPixelProperty(windowPane, WindowPane.PROPERTY_MAXIMUM_WIDTH, initElement, "maximum-width");
401         renderPixelProperty(windowPane, WindowPane.PROPERTY_MAXIMUM_HEIGHT, initElement, "maximum-height");
402         
403         int fillImageRenderFlags = ((Boolean JavaDoc) windowPane.getRenderProperty(PROPERTY_IE_ALPHA_RENDER_BORDER,
404                 Boolean.FALSE)).booleanValue() ? FillImageRender.FLAG_ENABLE_IE_PNG_ALPHA_FILTER : 0;
405     
406         // Title-related
407
if (windowPane.getRenderProperty(WindowPane.PROPERTY_ICON) != null) {
408             initElement.setAttribute("icon", ImageTools.getUri(rc, this, windowPane, IMAGE_ID_ICON));
409             Insets iconInsets = (Insets) windowPane.getRenderProperty(WindowPane.PROPERTY_ICON_INSETS);
410             if (iconInsets != null) {
411                 initElement.setAttribute("icon-insets", InsetsRender.renderCssAttributeValue(iconInsets));
412             }
413         }
414         String JavaDoc title = (String JavaDoc) windowPane.getRenderProperty(WindowPane.PROPERTY_TITLE);
415         if (title != null) {
416             initElement.setAttribute("title", title);
417             Insets titleInsets = (Insets) windowPane.getRenderProperty(WindowPane.PROPERTY_TITLE_INSETS);
418             Color titleForeground = (Color) windowPane.getRenderProperty(WindowPane.PROPERTY_TITLE_FOREGROUND);
419             if (titleForeground != null) {
420                 initElement.setAttribute("title-foreground", ColorRender.renderCssAttributeValue(titleForeground));
421             }
422             if (titleInsets != null) {
423                 initElement.setAttribute("title-insets", InsetsRender.renderCssAttributeValue(titleInsets));
424             }
425             Font titleFont = (Font) windowPane.getRenderProperty(WindowPane.PROPERTY_TITLE_FONT);
426             if (titleFont != null) {
427                 CssStyle fontCssStyle = new CssStyle();
428                 FontRender.renderToStyle(fontCssStyle, titleFont);
429                 initElement.setAttribute("title-font", fontCssStyle.renderInline());
430             }
431         }
432         Insets titleBarInsets = (Insets) windowPane.getRenderProperty(WindowPane.PROPERTY_TITLE_BAR_INSETS);
433         if (titleBarInsets != null) {
434             initElement.setAttribute("title-bar-insets", InsetsRender.renderCssAttributeValue(titleBarInsets));
435         }
436         renderPixelProperty(windowPane, WindowPane.PROPERTY_TITLE_HEIGHT, initElement, "title-height");
437         Color titleBackground = (Color) windowPane.getRenderProperty(WindowPane.PROPERTY_TITLE_BACKGROUND);
438         if (titleBackground != null) {
439             initElement.setAttribute("title-background", ColorRender.renderCssAttributeValue(titleBackground));
440         }
441         FillImage titleBackgroundImage = (FillImage) windowPane.getRenderProperty(WindowPane.PROPERTY_TITLE_BACKGROUND_IMAGE);
442         if (titleBackgroundImage != null) {
443             CssStyle titleBackgroundImageCssStyle = new CssStyle();
444             FillImageRender.renderToStyle(titleBackgroundImageCssStyle, rc, this, windowPane, IMAGE_ID_TITLE_BACKGROUND,
445                     titleBackgroundImage, fillImageRenderFlags);
446             initElement.setAttribute("title-background-image", titleBackgroundImageCssStyle.renderInline());
447         }
448         
449         // Move/Close/Resize
450
Boolean JavaDoc resizableBoolean = (Boolean JavaDoc) windowPane.getRenderProperty(WindowPane.PROPERTY_RESIZABLE);
451         boolean resizable = resizableBoolean == null ? true : resizableBoolean.booleanValue();
452         initElement.setAttribute("resizable", resizable ? "true" : "false");
453         Boolean JavaDoc closableBoolean = (Boolean JavaDoc) windowPane.getRenderProperty(WindowPane.PROPERTY_CLOSABLE);
454         boolean closable = closableBoolean == null ? true : closableBoolean.booleanValue();
455         initElement.setAttribute("closable", closable ? "true" : "false");
456         if (closable) {
457             if (getImage(windowPane, IMAGE_ID_CLOSE_ICON) != null) {
458                 initElement.setAttribute("close-icon", ImageTools.getUri(rc, this, windowPane, IMAGE_ID_CLOSE_ICON));
459                 Insets closeIconInsets = (Insets) windowPane.getRenderProperty(WindowPane.PROPERTY_CLOSE_ICON_INSETS);
460                 if (closeIconInsets != null) {
461                     initElement.setAttribute("close-icon-insets", InsetsRender.renderCssAttributeValue(closeIconInsets));
462                 }
463             }
464         }
465         Boolean JavaDoc movableBoolean = (Boolean JavaDoc) windowPane.getRenderProperty(WindowPane.PROPERTY_MOVABLE);
466         boolean movable = movableBoolean == null ? true : movableBoolean.booleanValue();
467         initElement.setAttribute("movable", movable ? "true" : "false");
468
469         // Border
470
FillImageBorder border = (FillImageBorder) windowPane.getRenderProperty(WindowPane.PROPERTY_BORDER);
471         if (border != null && border.getBorderInsets() != null && border.getContentInsets() != null) {
472             Element JavaDoc borderElement = serverMessage.getDocument().createElement("border");
473             if (border.getColor() != null) {
474                 borderElement.setAttribute("color", ColorRender.renderCssAttributeValue(border.getColor()));
475             }
476             borderElement.setAttribute("border-insets", InsetsRender.renderCssAttributeValue(border.getBorderInsets()));
477             borderElement.setAttribute("content-insets", InsetsRender.renderCssAttributeValue(border.getContentInsets()));
478             for (int i = 0; i < 8; ++i) {
479                 FillImage fillImage = border.getFillImage(i);
480                 if (fillImage != null) {
481                     Element JavaDoc imageElement = serverMessage.getDocument().createElement("image");
482                     imageElement.setAttribute("name", FILL_IMAGE_NAMES[i]);
483                     CssStyle fillImageCssStyle = new CssStyle();
484                     FillImageRender.renderToStyle(fillImageCssStyle, rc, this, windowPane, FILL_IMAGE_IDS[i], fillImage,
485                             fillImageRenderFlags);
486                     imageElement.setAttribute("value", fillImageCssStyle.renderInline());
487                     borderElement.appendChild(imageElement);
488                 }
489             }
490             initElement.appendChild(borderElement);
491         }
492         
493         partElement.appendChild(initElement);
494     }
495     
496     private void renderSetContent(RenderContext rc, ServerComponentUpdate update) {
497         //TODO. implement
498
}
499     
500     /**
501      * @see nextapp.echo2.webcontainer.ComponentSynchronizePeer#renderUpdate(nextapp.echo2.webcontainer.RenderContext,
502      * nextapp.echo2.app.update.ServerComponentUpdate, java.lang.String)
503      */

504     public boolean renderUpdate(RenderContext rc, ServerComponentUpdate update,
505             String JavaDoc targetId) {
506         boolean fullReplace = false;
507         if (update.hasUpdatedLayoutDataChildren()) {
508             fullReplace = true;
509         } else if (update.hasUpdatedProperties()) {
510             if (partialUpdateManager.canProcess(rc, update)) {
511                 renderUpdateDirective(rc, update);
512             } else {
513                 fullReplace = true;
514             }
515         }
516
517         if (update.hasAddedChildren() || update.hasRemovedChildren() || update.hasUpdatedLayoutDataChildren()) {
518             //TODO. temporary, renderSetContent needs impl
519
fullReplace = true;
520         }
521         
522         if (fullReplace) {
523             // Perform full update.
524
renderDisposeDirective(rc, (WindowPane) update.getParent());
525             DomUpdate.renderElementRemove(rc.getServerMessage(), ContainerInstance.getElementId(update.getParent()));
526             renderAdd(rc, update, targetId, update.getParent());
527         } else {
528             partialUpdateManager.process(rc, update);
529             if (update.hasAddedChildren() || update.hasRemovedChildren()) {
530                 renderSetContent(rc, update);
531             }
532         }
533         
534         return fullReplace;
535     }
536     
537     private void renderUpdateDirective(RenderContext rc, ServerComponentUpdate update) {
538         WindowPane windowPane = (WindowPane) update.getParent();
539
540         Element JavaDoc updateElement = rc.getServerMessage().appendPartDirective(ServerMessage.GROUP_ID_PREREMOVE,
541                 "EchoWindowPane.MessageProcessor", "update");
542         String JavaDoc elementId = ContainerInstance.getElementId(windowPane);
543         updateElement.setAttribute("eid", elementId);
544
545         PropertyUpdate positionX = update.getUpdatedProperty(WindowPane.PROPERTY_POSITION_X);
546         if (positionX != null) {
547             renderPixelProperty(windowPane, WindowPane.PROPERTY_POSITION_X, updateElement, "position-x");
548         }
549
550         PropertyUpdate positionY = update.getUpdatedProperty(WindowPane.PROPERTY_POSITION_Y);
551         if (positionY != null) {
552             renderPixelProperty(windowPane, WindowPane.PROPERTY_POSITION_Y, updateElement, "position-y");
553         }
554         
555         PropertyUpdate width = update.getUpdatedProperty(WindowPane.PROPERTY_WIDTH);
556         if (width != null) {
557             renderPixelProperty(windowPane, WindowPane.PROPERTY_WIDTH, updateElement, "width");
558         }
559
560         PropertyUpdate height = update.getUpdatedProperty(WindowPane.PROPERTY_HEIGHT);
561         if (height != null) {
562             renderPixelProperty(windowPane, WindowPane.PROPERTY_HEIGHT, updateElement, "height");
563         }
564         
565         if (update.getUpdatedProperty(WindowPane.PROPERTY_TITLE) != null) {
566             updateElement.setAttribute("title", (String JavaDoc) windowPane.getRenderProperty(WindowPane.PROPERTY_TITLE, " "));
567         }
568     }
569 }
570
Popular Tags