1 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 51 public class WindowPeer 52 implements RootSynchronizePeer { 53 54 private PartialUpdateManager partialUpdateManager; 55 56 59 public WindowPeer() { 60 super(); 61 partialUpdateManager = new PartialUpdateManager(); 62 partialUpdateManager.add(Window.PROPERTY_TITLE, new PartialUpdateParticipant() { 63 64 68 public boolean canRenderProperty(RenderContext rc, ServerComponentUpdate update) { 69 return true; 70 } 71 72 76 public void renderProperty(RenderContext rc, ServerComponentUpdate update) { 77 Window window = (Window) update.getParent(); 78 String title = (String ) window.getRenderProperty(Window.PROPERTY_TITLE); 79 WindowUpdate.renderSetWindowTitle(rc.getServerMessage(), title); 80 } 81 }); 82 } 83 84 88 public void renderAdd(RenderContext rc, ServerComponentUpdate update, 89 String targetId, Component component) { 90 throw new UnsupportedOperationException ("Cannot add window."); 91 } 92 93 96 public String getContainerId(Component child) { 97 return WindowHtmlService.ROOT_ID; 98 } 99 100 104 public void renderDispose(RenderContext rc, ServerComponentUpdate update, Component component) { 105 } 107 108 112 public void renderRefresh(RenderContext rc, ServerComponentUpdate update, Component component) { 113 Window window = (Window) component; 114 115 String title = (String ) 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 132 public boolean renderUpdate(RenderContext rc, ServerComponentUpdate update, String 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 |