]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added user interface identifier support for AbstractComponent and CustomComponent.
authorJani Laakso <jani.laakso@itmill.com>
Fri, 11 May 2007 14:38:07 +0000 (14:38 +0000)
committerJani Laakso <jani.laakso@itmill.com>
Fri, 11 May 2007 14:38:07 +0000 (14:38 +0000)
API change needs refactoring as currently Identifiable is plain class (not interface as requested by Joonas).

svn changeset:1421/svn branch:trunk

src/com/itmill/toolkit/terminal/web/AjaxApplicationManager.java
src/com/itmill/toolkit/ui/AbstractComponent.java
src/com/itmill/toolkit/ui/CustomComponent.java

index 2727b63042b0a532fadbec99067d788e3d4b0dc3..bacda812367a5f27524feb5cfaa6df68c5877c8c 100644 (file)
@@ -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;
        }
index 6c453d0a571de82030f23fbae97f3ce80f394033..91d6465d47246649613e311b43a5c4f20e272edc 100644 (file)
@@ -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
index 3aebcfeb6bd12b84ea031aded73bedee27323243..ddbbfcc07a1a482534d8479d1301286d176af097 100644 (file)
@@ -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.