1 29 30 package nextapp.echo2.webcontainer.syncpeer; 31 32 import org.w3c.dom.Document ; 33 import org.w3c.dom.DocumentFragment ; 34 import org.w3c.dom.Element ; 35 import org.w3c.dom.Node ; 36 37 import nextapp.echo2.app.Border; 38 import nextapp.echo2.app.Component; 39 import nextapp.echo2.app.Insets; 40 import nextapp.echo2.app.Panel; 41 import nextapp.echo2.app.update.ServerComponentUpdate; 42 import nextapp.echo2.webcontainer.ComponentSynchronizePeer; 43 import nextapp.echo2.webcontainer.ContainerInstance; 44 import nextapp.echo2.webcontainer.DomUpdateSupport; 45 import nextapp.echo2.webcontainer.RenderContext; 46 import nextapp.echo2.webcontainer.SynchronizePeerFactory; 47 import nextapp.echo2.webcontainer.propertyrender.BorderRender; 48 import nextapp.echo2.webcontainer.propertyrender.ColorRender; 49 import nextapp.echo2.webcontainer.propertyrender.FontRender; 50 import nextapp.echo2.webcontainer.propertyrender.InsetsRender; 51 import nextapp.echo2.webrender.output.CssStyle; 52 import nextapp.echo2.webrender.servermessage.DomUpdate; 53 54 61 public class CompositePeer 62 implements ComponentSynchronizePeer, DomUpdateSupport{ 63 64 67 public String getContainerId(Component child) { 68 return ContainerInstance.getElementId(child.getParent()); 69 } 70 71 76 public void renderAdd(RenderContext rc, ServerComponentUpdate update, String targetId, Component component) { 77 Element domAddElement = DomUpdate.renderElementAdd(rc.getServerMessage()); 78 DocumentFragment htmlFragment = rc.getServerMessage().getDocument().createDocumentFragment(); 79 renderHtml(rc, update, htmlFragment, component); 80 DomUpdate.renderElementAddContent(rc.getServerMessage(), domAddElement, targetId, htmlFragment); 81 } 82 83 88 public void renderDispose(RenderContext rc, ServerComponentUpdate update, Component component) { 89 } 91 92 97 public void renderHtml(RenderContext rc, ServerComponentUpdate update, Node parentNode, Component component) { 98 Document document = parentNode.getOwnerDocument(); 99 Element divElement = document.createElement("div"); 100 divElement.setAttribute("id", ContainerInstance.getElementId(component)); 101 parentNode.appendChild(divElement); 102 103 if (component.getVisibleComponentCount() == 0) { 104 return; 106 } 107 108 CssStyle cssStyle = new CssStyle(); 109 ColorRender.renderToStyle(cssStyle, component); 110 FontRender.renderToStyle(cssStyle, component); 111 if (component instanceof Panel) { 112 BorderRender.renderToStyle(cssStyle, (Border) component.getRenderProperty(Panel.PROPERTY_BORDER)); 113 InsetsRender.renderToStyle(cssStyle, "padding", (Insets) component.getRenderProperty(Panel.PROPERTY_INSETS)); 114 } 115 116 if (cssStyle.hasAttributes()) { 117 divElement.setAttribute("style", cssStyle.renderInline()); 118 } 119 120 Component child = component.getVisibleComponent(0); 121 ComponentSynchronizePeer syncPeer = SynchronizePeerFactory.getPeerForComponent(child.getClass()); 122 123 if (syncPeer instanceof DomUpdateSupport) { 124 ((DomUpdateSupport) syncPeer).renderHtml(rc, update, divElement, child); 125 } else { 126 syncPeer.renderAdd(rc, update, getContainerId(child), child); 127 } 128 } 129 130 134 public boolean renderUpdate(RenderContext rc, ServerComponentUpdate update, String targetId) { 135 String parentId = ContainerInstance.getElementId(update.getParent()); 136 DomUpdate.renderElementRemove(rc.getServerMessage(), parentId); 137 renderAdd(rc, update, targetId, update.getParent()); 138 return true; 139 } 140 141 } 142 | Popular Tags |