summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2007-11-30 09:34:16 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2007-11-30 09:34:16 +0000
commit2bd6e48d83b0134d04dcd8338b57985915af20bb (patch)
treecb726007634626df873cd899e24086ec6186da05 /src
parent20310afe28dd07dd0c8fb5b9064ba35debcfa170 (diff)
downloadvaadin-framework-2bd6e48d83b0134d04dcd8338b57985915af20bb.tar.gz
vaadin-framework-2bd6e48d83b0134d04dcd8338b57985915af20bb.zip
added clearing idPaintable & vs maps back, but only for components in this window. Also removed some old obsolete code.
svn changeset:3055/svn branch:trunk
Diffstat (limited to 'src')
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java325
1 files changed, 161 insertions, 164 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java b/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java
index 30ee4e66f4..6ecdb543f2 100644
--- a/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java
+++ b/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java
@@ -247,204 +247,201 @@ public class CommunicationManager implements Paintable.RepaintRequestListener,
try {
- // Is this a download request from application
- DownloadStream download = null;
-
// The rest of the process is synchronized with the application
// in order to guarantee that no parallel variable handling is
// made
synchronized (application) {
- // Change all variables based on request parameters
- handleVariables(request, application);
-
- // If this is not a download request
- if (download == null) {
-
- // Finds the window within the application
- Window window = null;
- if (application.isRunning()) {
- window = getApplicationWindow(request, application);
- }
-
- // Removes application if it has stopped
- if (!application.isRunning()) {
- endApplication(request, response, application);
- return;
- }
-
+ // Finds the window within the application
+ Window window = null;
+ if (application.isRunning()) {
+ window = getApplicationWindow(request, application);
// Returns if no window found
if (window == null) {
return;
}
+ } else {
+ return;
+ }
- // Sets the response type
- response.setContentType("application/json; charset=UTF-8");
- // some dirt to prevent cross site scripting
- outWriter.print(")/*{");
+ // If repaint is requested, clean all ids in this root window
+ if (repaintAll) {
+ for (Iterator it = idPaintableMap.keySet().iterator(); it
+ .hasNext();) {
+ Component c = (Component) idPaintableMap.get(it.next());
+ if (isChildOf(window, c)) {
+ it.remove();
+ paintableIdMap.remove(c);
+ }
+ }
+ }
- outWriter.print("\"changes\":[");
+ // Change all variables based on request parameters
+ handleVariables(request, application);
- paintTarget = new JsonPaintTarget(this, outWriter,
- !repaintAll);
+ // Removes application if it has stopped during variable changes
+ if (!application.isRunning()) {
+ endApplication(request, response, application);
+ return;
+ }
- // Paints components
- Set paintables;
- if (repaintAll) {
- paintables = new LinkedHashSet();
- paintables.add(window);
+ // Sets the response type
+ response.setContentType("application/json; charset=UTF-8");
+ // some dirt to prevent cross site scripting
+ outWriter.print(")/*{");
- // Reset sent locales
- locales = null;
- requireLocale(application.getLocale().toString());
+ outWriter.print("\"changes\":[");
- } else {
- paintables = getDirtyComponents(window);
- }
- if (paintables != null) {
-
- // Creates "working copy" of the current state.
- List currentPaintables = new ArrayList(paintables);
-
- // Sorts the Paintable list so that parents
- // are always painted before children
- Collections.sort(currentPaintables, new Comparator() {
- public int compare(Object o1, Object o2) {
- Component c1 = (Component) o1;
- Component c2 = (Component) o2;
- if (isChildOf(c1, c2)) {
- return -1;
- }
- if (isChildOf(c2, c1)) {
- return 1;
- }
- return 0;
+ paintTarget = new JsonPaintTarget(this, outWriter, !repaintAll);
+
+ // Paints components
+ Set paintables;
+ if (repaintAll) {
+ paintables = new LinkedHashSet();
+ paintables.add(window);
+
+ // Reset sent locales
+ locales = null;
+ requireLocale(application.getLocale().toString());
+
+ } else {
+ paintables = getDirtyComponents(window);
+ }
+ if (paintables != null) {
+
+ // Creates "working copy" of the current state.
+ List currentPaintables = new ArrayList(paintables);
+
+ // Sorts the Paintable list so that parents
+ // are always painted before children
+ Collections.sort(currentPaintables, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ Component c1 = (Component) o1;
+ Component c2 = (Component) o2;
+ if (isChildOf(c1, c2)) {
+ return -1;
}
- });
-
- for (Iterator i = currentPaintables.iterator(); i
- .hasNext();) {
- Paintable p = (Paintable) i.next();
-
- // TODO CLEAN
- if (p instanceof Window) {
- Window w = (Window) p;
- if (w.getTerminal() == null) {
- w.setTerminal(application.getMainWindow()
- .getTerminal());
- }
+ if (isChildOf(c2, c1)) {
+ return 1;
}
- /*
- * This does not seem to happen in tk5, but remember
- * this case: else if (p instanceof Component) { if
- * (((Component) p).getParent() == null ||
- * ((Component) p).getApplication() == null) { //
- * Component requested repaint, but is no // longer
- * attached: skip paintablePainted(p); continue; } }
- */
-
- // TODO we may still get changes that have been
- // rendered already (changes with only cached flag)
- paintTarget.startTag("change");
- paintTarget.addAttribute("format", "uidl");
- String pid = getPaintableId(p);
- paintTarget.addAttribute("pid", pid);
-
- // Track paints to identify empty paints
- paintTarget.setTrackPaints(true);
- p.paint(paintTarget);
-
- // If no paints add attribute empty
- if (paintTarget.getNumberOfPaints() <= 0) {
- paintTarget.addAttribute("visible", false);
+ return 0;
+ }
+ });
+
+ for (Iterator i = currentPaintables.iterator(); i.hasNext();) {
+ Paintable p = (Paintable) i.next();
+
+ // TODO CLEAN
+ if (p instanceof Window) {
+ Window w = (Window) p;
+ if (w.getTerminal() == null) {
+ w.setTerminal(application.getMainWindow()
+ .getTerminal());
}
- paintTarget.endTag("change");
- paintablePainted(p);
}
+ /*
+ * This does not seem to happen in tk5, but remember
+ * this case: else if (p instanceof Component) { if
+ * (((Component) p).getParent() == null || ((Component)
+ * p).getApplication() == null) { // Component requested
+ * repaint, but is no // longer attached: skip
+ * paintablePainted(p); continue; } }
+ */
+
+ // TODO we may still get changes that have been
+ // rendered already (changes with only cached flag)
+ paintTarget.startTag("change");
+ paintTarget.addAttribute("format", "uidl");
+ String pid = getPaintableId(p);
+ paintTarget.addAttribute("pid", pid);
+
+ // Track paints to identify empty paints
+ paintTarget.setTrackPaints(true);
+ p.paint(paintTarget);
+
+ // If no paints add attribute empty
+ if (paintTarget.getNumberOfPaints() <= 0) {
+ paintTarget.addAttribute("visible", false);
+ }
+ paintTarget.endTag("change");
+ paintablePainted(p);
}
+ }
- paintTarget.close();
- outWriter.print("]"); // close changes
+ paintTarget.close();
+ outWriter.print("]"); // close changes
- outWriter.print(", \"meta\" : {");
- boolean metaOpen = false;
+ outWriter.print(", \"meta\" : {");
+ boolean metaOpen = false;
- // add meta instruction for client to set focus if it is set
- Paintable f = (Paintable) application.consumeFocus();
- if (f != null) {
- if (metaOpen) {
- outWriter.write(",");
- }
- outWriter.write("\"focus\":\"" + getPaintableId(f)
- + "\"");
+ // add meta instruction for client to set focus if it is set
+ Paintable f = (Paintable) application.consumeFocus();
+ if (f != null) {
+ if (metaOpen) {
+ outWriter.write(",");
}
+ outWriter.write("\"focus\":\"" + getPaintableId(f) + "\"");
+ }
- outWriter.print("}, \"resources\" : {");
+ outWriter.print("}, \"resources\" : {");
- // Precache custom layouts
- String themeName = window.getTheme();
- if (request.getParameter("theme") != null) {
- themeName = request.getParameter("theme");
- }
- if (themeName == null) {
- themeName = "default";
+ // Precache custom layouts
+ String themeName = window.getTheme();
+ if (request.getParameter("theme") != null) {
+ themeName = request.getParameter("theme");
+ }
+ if (themeName == null) {
+ themeName = "default";
+ }
+
+ // TODO We should only precache the layouts that are not
+ // cached already
+ int resourceIndex = 0;
+ for (Iterator i = paintTarget.getPreCachedResources()
+ .iterator(); i.hasNext();) {
+ String resource = (String) i.next();
+ InputStream is = null;
+ try {
+ is = applicationServlet
+ .getServletContext()
+ .getResourceAsStream(
+ "/"
+ + ApplicationServlet.THEME_DIRECTORY_PATH
+ + themeName + "/" + resource);
+ } catch (Exception e) {
+ e.printStackTrace();
}
+ if (is != null) {
+
+ outWriter.print((resourceIndex++ > 0 ? ", " : "")
+ + "\"" + resource + "\" : ");
+ StringBuffer layout = new StringBuffer();
- // TODO We should only precache the layouts that are not
- // cached already
- int resourceIndex = 0;
- for (Iterator i = paintTarget.getPreCachedResources()
- .iterator(); i.hasNext();) {
- String resource = (String) i.next();
- InputStream is = null;
try {
- is = applicationServlet
- .getServletContext()
- .getResourceAsStream(
- "/"
- + ApplicationServlet.THEME_DIRECTORY_PATH
- + themeName + "/"
- + resource);
- } catch (Exception e) {
- e.printStackTrace();
- }
- if (is != null) {
-
- outWriter.print((resourceIndex++ > 0 ? ", " : "")
- + "\"" + resource + "\" : ");
- StringBuffer layout = new StringBuffer();
-
- try {
- InputStreamReader r = new InputStreamReader(is);
- char[] buffer = new char[20000];
- int charsRead = 0;
- while ((charsRead = r.read(buffer)) > 0) {
- layout.append(buffer, 0, charsRead);
- }
- r.close();
- } catch (java.io.IOException e) {
- System.err
- .println("Resource transfer failed: "
- + request.getRequestURI()
- + ". (" + e.getMessage() + ")");
+ InputStreamReader r = new InputStreamReader(is);
+ char[] buffer = new char[20000];
+ int charsRead = 0;
+ while ((charsRead = r.read(buffer)) > 0) {
+ layout.append(buffer, 0, charsRead);
}
- outWriter.print("\""
- + JsonPaintTarget.escapeJSON(layout
- .toString()) + "\"");
+ r.close();
+ } catch (java.io.IOException e) {
+ System.err.println("Resource transfer failed: "
+ + request.getRequestURI() + ". ("
+ + e.getMessage() + ")");
}
+ outWriter.print("\""
+ + JsonPaintTarget.escapeJSON(layout.toString())
+ + "\"");
}
- outWriter.print("}");
+ }
+ outWriter.print("}");
- printLocaleDeclarations(outWriter);
+ printLocaleDeclarations(outWriter);
- outWriter.flush();
- outWriter.close();
- out.flush();
- } else {
-
- // For download request, transfer the downloaded data
- handleDownload(download, request, response);
- }
+ outWriter.flush();
+ outWriter.close();
+ out.flush();
}
out.flush();