Changeset 3588a2fad in vaadin


Ignore:
Timestamp:
02/10/12 09:35:43 (2 years ago)
Author:
Henri Sara <hesara@…>
Branches:
716046af83ec05a44314a792648863646398d3b9, 7.0, 7.1, 7.2
Children:
eba294b5
Parents:
81540696
git-author:
Henri Sara <hesara@…> (02/10/12 09:35:43)
git-committer:
Henri Sara <hesara@…> (02/10/12 09:35:43)
Message:

Defer nested components to paint them as top-level changes (#8304).

Refactoring and changes to paint nested component contents after the
component in which they are nested. The client side can create
uninitialized components immediately but defer configuring them.

Location:
src/com/vaadin
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/com/vaadin/terminal/PaintTarget.java

    r81540696 r3588a2fad  
    3636    public void addSection(String sectionTagName, String sectionData) 
    3737            throws PaintException; 
     38 
     39    /** 
     40     * Result of starting to paint a Paintable ( 
     41     * {@link PaintTarget#startPaintable(Paintable, String)}). 
     42     *  
     43     * @since 7.0 
     44     */ 
     45    public enum PaintStatus { 
     46        /** 
     47         * Painting started, addVariable() and addAttribute() etc. methods may 
     48         * be called. 
     49         */ 
     50        PAINTING, 
     51        /** 
     52         * Paintable is cached on the client side and unmodified - only an 
     53         * indication of that should be painted. 
     54         */ 
     55        CACHED, 
     56        /** 
     57         * A previously unpainted or painted {@link Paintable} has been queued 
     58         * be created/update later in a separate change in the same set of 
     59         * changes. 
     60         */ 
     61        DEFER 
     62    }; 
    3863 
    3964    /** 
     
    5378     * <p> 
    5479     * Each paintable being painted should be closed by a matching 
    55      * {@link #endPaintable(Paintable)}. 
     80     * {@link #endPaintable(Paintable)} regardless of the {@link PaintStatus} 
     81     * returned. 
    5682     * </p> 
    5783     *  
     
    6086     * @param tag 
    6187     *            the name of the start tag. 
    62      * @return <code>true</code> if paintable found in cache, <code>false</code> 
    63      *         otherwise. 
     88     * @return {@link PaintStatus} - ready to paint, already cached on the 
     89     *         client or defer painting to another change 
    6490     * @throws PaintException 
    6591     *             if the paint operation failed. 
     
    6793     * @since 7.0 (previously using startTag(Paintable, String)) 
    6894     */ 
    69     public boolean startPaintable(Paintable paintable, String tag) 
     95    public PaintStatus startPaintable(Paintable paintable, String tag) 
    7096            throws PaintException; 
    7197 
  • src/com/vaadin/terminal/gwt/client/ApplicationConnection.java

    r947e59a1 r3588a2fad  
    18661866    public VPaintableWidget getPaintable(UIDL uidl) { 
    18671867        final String pid = uidl.getId(); 
     1868        // the actual content UIDL may be deferred, but it always contains 
     1869        // enough information to create a paintable instance 
    18681870        if (!paintableMap.hasPaintable(pid)) { 
    18691871            // Create and register a new paintable if no old was found 
  • src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java

    r2bb7aae1 r3588a2fad  
    107107 
    108108    protected static boolean isRealUpdate(UIDL uidl) { 
    109         return !isCachedUpdate(uidl) && !uidl.getBooleanAttribute("invisible"); 
     109        return !isCachedUpdate(uidl) && !uidl.getBooleanAttribute("invisible") 
     110                && !uidl.hasAttribute("deferred"); 
    110111    } 
    111112 
  • src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java

    r6e7f9728 r3588a2fad  
    1616        getWidgetForPaintable().client = client; 
    1717 
    18         // Only non-cached UIDL:s can introduce changes 
    19         if (isCachedUpdate(uidl)) { 
    20             return; 
     18        if (isRealUpdate(uidl)) { 
     19            /** 
     20             * Margin and spacing detection depends on classNames and must be 
     21             * set before setting size. Here just update the details from UIDL 
     22             * and from overridden setStyleName run actual margin detections. 
     23             */ 
     24            updateMarginAndSpacingInfo(uidl); 
    2125        } 
    22  
    23         /** 
    24          * Margin and spacind detection depends on classNames and must be set 
    25          * before setting size. Here just update the details from UIDL and from 
    26          * overridden setStyleName run actual margin detections. 
    27          */ 
    28         updateMarginAndSpacingInfo(uidl); 
    2926 
    3027        /* 
     
    3431        super.updateFromUIDL(uidl, client); 
    3532 
    36         handleDynamicDimensions(uidl); 
     33        if (isRealUpdate(uidl)) { 
     34            handleDynamicDimensions(uidl); 
     35        } 
    3736    } 
    3837 
     
    5958 
    6059    void updateMarginAndSpacingInfo(UIDL uidl) { 
    61         if (!uidl.hasAttribute("invisible")) { 
    62             int bitMask = uidl.getIntAttribute("margins"); 
    63             if (getWidgetForPaintable().activeMarginsInfo.getBitMask() != bitMask) { 
    64                 getWidgetForPaintable().activeMarginsInfo = new VMarginInfo( 
    65                         bitMask); 
    66                 getWidgetForPaintable().marginsNeedsRecalculation = true; 
    67             } 
    68             boolean spacing = uidl.getBooleanAttribute("spacing"); 
    69             if (spacing != getWidgetForPaintable().spacingEnabled) { 
    70                 getWidgetForPaintable().marginsNeedsRecalculation = true; 
    71                 getWidgetForPaintable().spacingEnabled = spacing; 
    72             } 
     60        int bitMask = uidl.getIntAttribute("margins"); 
     61        if (getWidgetForPaintable().activeMarginsInfo.getBitMask() != bitMask) { 
     62            getWidgetForPaintable().activeMarginsInfo = new VMarginInfo(bitMask); 
     63            getWidgetForPaintable().marginsNeedsRecalculation = true; 
     64        } 
     65        boolean spacing = uidl.getBooleanAttribute("spacing"); 
     66        if (spacing != getWidgetForPaintable().spacingEnabled) { 
     67            getWidgetForPaintable().marginsNeedsRecalculation = true; 
     68            getWidgetForPaintable().spacingEnabled = spacing; 
    7369        } 
    7470    } 
  • src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java

    r81540696 r3588a2fad  
    857857                if (paintTarget.needsToBePainted(p)) { 
    858858                    paintTarget.startTag("change"); 
    859                     paintTarget.addAttribute("format", "uidl"); 
    860859                    final String pid = getPaintableId(p); 
    861860                    paintTarget.addAttribute("pid", pid); 
    862861 
    863                     // TODO this should paint subcomponents as references and 
    864                     // defer painting their contents to another top-level change 
     862                    // paints subcomponents as references (via 
     863                    // JsonPaintTarget.startPaintable()) and defers painting 
     864                    // their contents to another top-level change (via 
     865                    // queuePaintable()) 
    865866                    p.paint(paintTarget); 
    866867 
  • src/com/vaadin/terminal/gwt/server/JsonPaintTarget.java

    r81540696 r3588a2fad  
    1212import java.io.Serializable; 
    1313import java.io.StringWriter; 
     14import java.util.ArrayList; 
    1415import java.util.Collection; 
    1516import java.util.HashMap; 
     
    9192    private Collection<Paintable> identifiersCreatedDueRefPaint; 
    9293 
     94    private Collection<Paintable> deferredPaintables; 
     95 
    9396    private final Collection<Class<? extends Paintable>> usedPaintableTypes = new LinkedList<Class<? extends Paintable>>(); 
    9497 
     
    120123        openPaintables = new Stack<Paintable>(); 
    121124        openPaintableTags = new Stack<String>(); 
     125 
     126        deferredPaintables = new ArrayList<Paintable>(); 
    122127 
    123128        cacheEnabled = cachingRequired; 
     
    678683     * (non-Javadoc) 
    679684     *  
    680      * @see com.vaadin.terminal.PaintTarget#startTag(com.vaadin.terminal 
     685     * @see com.vaadin.terminal.PaintTarget#startPaintable(com.vaadin.terminal 
    681686     * .Paintable, java.lang.String) 
    682687     */ 
    683     public boolean startPaintable(Paintable paintable, String tagName) 
     688    public PaintStatus startPaintable(Paintable paintable, String tagName) 
    684689            throws PaintException { 
    685690        startTag(tagName, true); 
    686691        final boolean isPreviouslyPainted = manager.hasPaintableId(paintable) 
    687692                && (identifiersCreatedDueRefPaint == null || !identifiersCreatedDueRefPaint 
    688                         .contains(paintable)); 
     693                        .contains(paintable)) 
     694                && !deferredPaintables.contains(paintable); 
    689695        final String id = manager.getPaintableId(paintable); 
    690696        paintable.addListener(manager); 
    691697        addAttribute("id", id); 
    692698 
    693         // TODO if to queue if already painting a paintable 
    694         // if (openPaintables.isEmpty()) { 
     699        // queue for painting later if already painting a paintable 
     700        boolean topLevelPaintableTag = openPaintables.isEmpty(); 
     701 
    695702        openPaintables.push(paintable); 
    696703        openPaintableTags.push(tagName); 
    697704 
    698         paintedComponents.add(paintable); 
    699         // } else { 
    700         // // notify manager: add to paint queue instead of painting now 
    701         // manager.queuePaintable(paintable); 
    702         // // TODO return suitable value to defer painting and close tag if a 
    703         // // paintable tag is already open 
    704         // } 
    705  
    706         if (paintable instanceof CustomLayout) { 
    707             customLayoutArgumentsOpen = true; 
    708         } 
    709  
    710         return cacheEnabled && isPreviouslyPainted; 
     705        if (cacheEnabled && isPreviouslyPainted) { 
     706            // cached (unmodified) paintable, paint the it now 
     707            paintedComponents.add(paintable); 
     708            deferredPaintables.remove(paintable); 
     709            return PaintStatus.CACHED; 
     710        } else if (!topLevelPaintableTag) { 
     711            // notify manager: add to paint queue instead of painting now 
     712            manager.queuePaintable(paintable); 
     713            deferredPaintables.add(paintable); 
     714            return PaintStatus.DEFER; 
     715        } else { 
     716            // not a nested paintable, paint the it now 
     717            paintedComponents.add(paintable); 
     718            deferredPaintables.remove(paintable); 
     719 
     720            if (paintable instanceof CustomLayout) { 
     721                customLayoutArgumentsOpen = true; 
     722            } 
     723            return PaintStatus.PAINTING; 
     724        } 
    711725    } 
    712726 
  • src/com/vaadin/ui/AbstractComponent.java

    r81540696 r3588a2fad  
    2828import com.vaadin.terminal.PaintException; 
    2929import com.vaadin.terminal.PaintTarget; 
     30import com.vaadin.terminal.PaintTarget.PaintStatus; 
    3031import com.vaadin.terminal.Resource; 
    3132import com.vaadin.terminal.Terminal; 
     
    754755    public void paint(PaintTarget target) throws PaintException { 
    755756        final String tag = target.getTag(this); 
    756         if (!target.startPaintable(this, tag) 
    757                 || repaintRequestListenersNotified) { 
    758  
     757        final PaintStatus status = target.startPaintable(this, tag); 
     758        if (PaintStatus.DEFER == status) { 
     759            // nothing to do but flag as deferred and close the paintable tag 
     760            // paint() will be called again later to paint the contents 
     761            target.addAttribute("deferred", true); 
     762        } else if (PaintStatus.CACHED == status 
     763                && !repaintRequestListenersNotified) { 
     764            // Contents have not changed, only cached presentation can be used 
     765            target.addAttribute("cached", true); 
     766        } else { 
    759767            // Paint the contents of the component 
    760768 
     
    810818                target.addAttribute("invisible", true); 
    811819            } 
    812         } else { 
    813  
    814             // Contents have not changed, only cached presentation can be used 
    815             target.addAttribute("cached", true); 
    816820        } 
    817821        target.endPaintable(this); 
Note: See TracChangeset for help on using the changeset viewer.