1 29 30 package nextapp.echo2.webcontainer.partialupdate; 31 32 import nextapp.echo2.app.Color; 33 import nextapp.echo2.app.update.ServerComponentUpdate; 34 import nextapp.echo2.webcontainer.ContainerInstance; 35 import nextapp.echo2.webcontainer.PartialUpdateParticipant; 36 import nextapp.echo2.webcontainer.RenderContext; 37 import nextapp.echo2.webcontainer.propertyrender.ColorRender; 38 import nextapp.echo2.webrender.servermessage.DomUpdate; 39 40 44 public class ColorUpdate 45 implements PartialUpdateParticipant { 46 47 public static final String CSS_BACKGROUND_COLOR = "backgroundColor"; 48 public static final String CSS_COLOR = "color"; 49 50 private String componentPropertyName; 51 private String cssAttributeName; 52 private String idSuffix; 53 54 63 public ColorUpdate(String componentPropertyName, String idSuffix, String cssAttributeName) { 64 super(); 65 this.componentPropertyName = componentPropertyName; 66 this.idSuffix = idSuffix; 67 this.cssAttributeName = cssAttributeName; 68 } 69 70 74 public boolean canRenderProperty(RenderContext rc, ServerComponentUpdate update) { 75 return true; 76 } 77 78 82 public void renderProperty(RenderContext rc, ServerComponentUpdate update) { 83 Color color = (Color) update.getParent().getRenderProperty(componentPropertyName); 84 String elementId = idSuffix == null ? ContainerInstance.getElementId(update.getParent()) 85 : ContainerInstance.getElementId(update.getParent()) + idSuffix; 86 if (color == null) { 87 DomUpdate.renderStyleUpdate(rc.getServerMessage(), elementId, cssAttributeName, ""); 88 } else { 89 DomUpdate.renderStyleUpdate(rc.getServerMessage(), elementId, cssAttributeName, 90 ColorRender.renderCssAttributeValue(color)); 91 } 92 } 93 } | Popular Tags |