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.partialupdate;
031:
032: import nextapp.echo2.app.Color;
033: import nextapp.echo2.app.update.ServerComponentUpdate;
034: import nextapp.echo2.webcontainer.ContainerInstance;
035: import nextapp.echo2.webcontainer.PartialUpdateParticipant;
036: import nextapp.echo2.webcontainer.RenderContext;
037: import nextapp.echo2.webcontainer.propertyrender.ColorRender;
038: import nextapp.echo2.webrender.servermessage.DomUpdate;
039:
040: /**
041: * A <code>PartialUpdateParticipant</code> to update a CSS property
042: * representing a color, e.g., 'color' or 'background-color'.
043: */
044: public class ColorUpdate implements PartialUpdateParticipant {
045:
046: public static final String CSS_BACKGROUND_COLOR = "backgroundColor";
047: public static final String CSS_COLOR = "color";
048:
049: private String componentPropertyName;
050: private String cssAttributeName;
051: private String idSuffix;
052:
053: /**
054: * Creates a new <code>ColorUpdate</code>.
055: *
056: * @param componentPropertyName the name of the property of the component
057: * @param idSuffix the suffix to append to the root client-side identifier
058: * of the component (should be null in typical case of no suffix)
059: * @param cssAttributeName the name of the CSS attribute to update (see
060: * CSS constants provided in this class)
061: */
062: public ColorUpdate(String componentPropertyName, String idSuffix,
063: String cssAttributeName) {
064: super ();
065: this .componentPropertyName = componentPropertyName;
066: this .idSuffix = idSuffix;
067: this .cssAttributeName = cssAttributeName;
068: }
069:
070: /**
071: * @see nextapp.echo2.webcontainer.PartialUpdateParticipant#canRenderProperty(nextapp.echo2.webcontainer.RenderContext,
072: * nextapp.echo2.app.update.ServerComponentUpdate)
073: */
074: public boolean canRenderProperty(RenderContext rc,
075: ServerComponentUpdate update) {
076: return true;
077: }
078:
079: /**
080: * @see nextapp.echo2.webcontainer.PartialUpdateParticipant#renderProperty(
081: * nextapp.echo2.webcontainer.RenderContext, nextapp.echo2.app.update.ServerComponentUpdate)
082: */
083: public void renderProperty(RenderContext rc,
084: ServerComponentUpdate update) {
085: Color color = (Color) update.getParent().getRenderProperty(
086: componentPropertyName);
087: String elementId = idSuffix == null ? ContainerInstance
088: .getElementId(update.getParent()) : ContainerInstance
089: .getElementId(update.getParent())
090: + idSuffix;
091: if (color == null) {
092: DomUpdate.renderStyleUpdate(rc.getServerMessage(),
093: elementId, cssAttributeName, "");
094: } else {
095: DomUpdate.renderStyleUpdate(rc.getServerMessage(),
096: elementId, cssAttributeName, ColorRender
097: .renderCssAttributeValue(color));
098: }
099: }
100: }
|