From 0366b0e937a2104c5f6c770e363c637ac28ce1c1 Mon Sep 17 00:00:00 2001 From: Jani Laakso Date: Fri, 11 May 2007 14:38:07 +0000 Subject: [PATCH] Added user interface identifier support for AbstractComponent and CustomComponent. API change needs refactoring as currently Identifiable is plain class (not interface as requested by Joonas). svn changeset:1421/svn branch:trunk --- .../terminal/web/AjaxApplicationManager.java | 124 ++++++++++-------- .../itmill/toolkit/ui/AbstractComponent.java | 4 +- .../itmill/toolkit/ui/CustomComponent.java | 3 +- 3 files changed, 76 insertions(+), 55 deletions(-) diff --git a/src/com/itmill/toolkit/terminal/web/AjaxApplicationManager.java b/src/com/itmill/toolkit/terminal/web/AjaxApplicationManager.java index 2727b63042..bacda81236 100644 --- a/src/com/itmill/toolkit/terminal/web/AjaxApplicationManager.java +++ b/src/com/itmill/toolkit/terminal/web/AjaxApplicationManager.java @@ -54,6 +54,7 @@ import com.itmill.toolkit.Application; import com.itmill.toolkit.Application.WindowAttachEvent; import com.itmill.toolkit.Application.WindowDetachEvent; import com.itmill.toolkit.terminal.DownloadStream; +import com.itmill.toolkit.terminal.Identifiable; import com.itmill.toolkit.terminal.Paintable; import com.itmill.toolkit.terminal.URIHandler; import com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent; @@ -141,8 +142,8 @@ public class AjaxApplicationManager implements * if the writing failed due to input/output error. */ public void handleUidlRequest(HttpServletRequest request, - HttpServletResponse response, ThemeSource themeSource) - throws IOException { + HttpServletResponse response, ThemeSource themeSource) + throws IOException { // repaint requested or sesssion has timed out and new one is created boolean repaintAll = (request.getParameter(GET_PARAM_REPAINT_ALL) != null) @@ -306,55 +307,63 @@ public class AjaxApplicationManager implements } } - // add meta instruction for client to set focus if it is set - Paintable f = (Paintable) application.consumeFocus(); - // .. or initializion (first uidl-request) - boolean init = application.ajaxInit(); - if(init || f != null) { - paintTarget.startTag("meta"); - if(init) - paintTarget.addAttribute("appInit", true); - if(f != null) { - paintTarget.startTag("focus"); - paintTarget.addAttribute("pid", getPaintableId(f)); - paintTarget.endTag("focus"); - } - paintTarget.endTag("meta"); - } - - // Precache custom layouts - // TODO Does not support theme-get param or different themes in different windows -> Allways preload layouts with the theme specified by the applications - String themeName = application.getTheme() != null ? application.getTheme() : ApplicationServlet.DEFAULT_THEME; - // TODO We should only precache the layouts that are not cached already - for (Iterator i=paintTarget.preCachedResources.iterator(); i.hasNext();) { - String resource = (String) i.next(); - InputStream is = null; - try { - is = themeSource.getResource(themeName + "/" + resource); - } catch (ThemeSource.ThemeException e) { - Log.info(e.getMessage()); - } - if (is != null) { - paintTarget.startTag("precache"); - paintTarget.addAttribute("resource", 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) { - Log.info("Resource transfer failed: " + request.getRequestURI() - + ". (" + e.getMessage() + ")"); - } - paintTarget.addCharacterData(layout.toString()); - paintTarget.endTag("precache"); - } - } - + // add meta instruction for client to set focus if it is set + Paintable f = (Paintable) application.consumeFocus(); + // .. or initializion (first uidl-request) + boolean init = application.ajaxInit(); + if (init || f != null) { + paintTarget.startTag("meta"); + if (init) + paintTarget.addAttribute("appInit", true); + if (f != null) { + paintTarget.startTag("focus"); + paintTarget.addAttribute("pid", getPaintableId(f)); + paintTarget.endTag("focus"); + } + paintTarget.endTag("meta"); + } + + // Precache custom layouts + // TODO Does not support theme-get param or different themes + // in different windows -> Allways preload layouts with the + // theme specified by the applications + String themeName = application.getTheme() != null ? application + .getTheme() + : ApplicationServlet.DEFAULT_THEME; + // TODO We should only precache the layouts that are not + // cached already + for (Iterator i = paintTarget.preCachedResources.iterator(); i + .hasNext();) { + String resource = (String) i.next(); + InputStream is = null; + try { + is = themeSource.getResource(themeName + "/" + + resource); + } catch (ThemeSource.ThemeException e) { + Log.info(e.getMessage()); + } + if (is != null) { + paintTarget.startTag("precache"); + paintTarget.addAttribute("resource", 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) { + Log.info("Resource transfer failed: " + + request.getRequestURI() + ". (" + + e.getMessage() + ")"); + } + paintTarget.addCharacterData(layout.toString()); + paintTarget.endTag("precache"); + } + } + paintTarget.close(); out.flush(); } else { @@ -584,9 +593,18 @@ public class AjaxApplicationManager implements String id = (String) paintableIdMap.get(paintable); if (id == null) { - id = "PID" + Integer.toString(idSequence++); - paintableIdMap.put(paintable, id); + String UIID = null; + // try to get PID using unique user interface identity (UUID) + if (paintable instanceof Identifiable) + UIID = ((Identifiable) paintable).getUIID(); + if (UIID != null) + id = "PID" + UIID; + else { + // UUID not set, get PID using growing sequence number + id = "PID" + Integer.toString(idSequence++); + } } + paintableIdMap.put(paintable, id); return id; } diff --git a/src/com/itmill/toolkit/ui/AbstractComponent.java b/src/com/itmill/toolkit/ui/AbstractComponent.java index 6c453d0a57..91d6465d47 100644 --- a/src/com/itmill/toolkit/ui/AbstractComponent.java +++ b/src/com/itmill/toolkit/ui/AbstractComponent.java @@ -52,7 +52,8 @@ import java.lang.reflect.Method; * @VERSION@ * @since 3.0 */ -public abstract class AbstractComponent implements Component, MethodEventSource { +public abstract class AbstractComponent extends Identifiable implements + Component, MethodEventSource { /* Private members ************************************************* */ @@ -919,4 +920,5 @@ public abstract class AbstractComponent implements Component, MethodEventSource public Object getData() { return this.applicationData; } + } \ No newline at end of file diff --git a/src/com/itmill/toolkit/ui/CustomComponent.java b/src/com/itmill/toolkit/ui/CustomComponent.java index 3aebcfeb6b..ddbbfcc07a 100644 --- a/src/com/itmill/toolkit/ui/CustomComponent.java +++ b/src/com/itmill/toolkit/ui/CustomComponent.java @@ -36,6 +36,7 @@ import java.util.Map; import java.util.Set; import com.itmill.toolkit.Application; +import com.itmill.toolkit.terminal.Identifiable; import com.itmill.toolkit.terminal.PaintException; import com.itmill.toolkit.terminal.PaintTarget; import com.itmill.toolkit.terminal.Resource; @@ -55,7 +56,7 @@ import com.itmill.toolkit.terminal.VariableOwner; * @VERSION@ * @since 3.0 */ -public class CustomComponent implements Component { +public class CustomComponent extends Identifiable implements Component { /** * The root component implementing the custom component. -- 2.39.5