Changeset 5231

Show
Ignore:
Timestamp:
08/21/08 08:26:41 (3 months ago)
Author:
risto.yrjana@…
Message:

Simplified server API and added client support for description

Location:
incubator/widgets/popuppanel/src/com/itmill/toolkit/ui
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • incubator/widgets/popuppanel/src/com/itmill/toolkit/ui/PopupPanel.java

    r4957 r5231  
    11package com.itmill.toolkit.ui; 
    22 
     3import java.util.ArrayList; 
    34import java.util.Iterator; 
    4 import java.util.LinkedList; 
    5 import java.util.List; 
    65import java.util.Map; 
    76 
     
    1110public class PopupPanel extends AbstractComponentContainer { 
    1211 
    13     java.lang.String smallView; 
    14     Component largeView; 
    15     Component currentPopupComponent; 
    1612    Content itsContent; 
    1713    boolean popupVisible; 
    18  
    19     // To make this behave more like a container 
    20     List componentList = new LinkedList(); 
    21  
    22     /* **Constructors** */ 
    23  
    24     /** 
    25      * A simple way to create a PopupPanel. 
     14    ArrayList componentList; 
     15 
     16    /* Constructors */ 
     17 
     18    /** 
     19     * A simple way to create a PopupPanel. Note that the minimal representation 
     20     * may not be dynamically updated, to achieve this create your own Content 
     21     * object. 
    2622     *  
    2723     * @param small 
    28      *                the minimal textual representation as HTML 
     24     *            the minimal textual representation as HTML 
    2925     * @param large 
    30      *                the full, Component-type representation 
     26     *            the full, Component-type representation 
    3127     */ 
    3228    public PopupPanel(final java.lang.String small, final Component large) { 
    33         super(); 
    34         PopupPanel.Content content = new PopupPanel.Content() { 
     29        this(new PopupPanel.Content() { 
    3530            public java.lang.String getMinimizedValueAsHTML() { 
    3631                return small; 
     
    4035                return large; 
    4136            } 
    42         }; 
    43  
    44         itsContent = content; 
    45         popupVisible = false; 
     37        }); 
    4638 
    4739    } 
     
    5244     *  
    5345     * @param content 
    54      *                the PopupPanel.Content that contains the information for 
    55      *                this 
     46     *            the PopupPanel.Content that contains the information for this 
    5647     */ 
    5748    public PopupPanel(final PopupPanel.Content content) { 
     
    5950        itsContent = content; 
    6051        popupVisible = false; 
    61     } 
    62  
    63     /* These methods should be preferred */ 
     52        componentList = new ArrayList(1); 
     53    } 
    6454 
    6555    /** 
     
    6858     *  
    6959     * @param newContent 
    70      *                PopupPanel.Content object containing new information for 
    71      *                the PopupPanel 
     60     *            PopupPanel.Content object containing new information for the 
     61     *            PopupPanel 
    7262     *  
    7363     */ 
    7464    public void setContent(PopupPanel.Content newContent) { 
    75         if (newContent != null) { 
    76             addComponent(newContent.getPopupComponent()); 
    77             itsContent = newContent; 
    78  
    79         } else { 
    80             removeAllComponents(); 
    81         } 
    82  
     65        itsContent = newContent; 
    8366        requestRepaint(); 
    84     } 
    85  
    86     /** 
    87      * Returns the smaller, minimized representation of the data. Returns null 
    88      * if the object has no content. 
    89      *  
    90      * @return minimal representation as HTML or null 
    91      */ 
    92     public java.lang.String getSmallView() { 
    93         if (itsContent != null) { 
    94             return itsContent.getMinimizedValueAsHTML(); 
    95         } 
    96         return null; 
    97     } 
    98  
    99     /** 
    100      * Returns the larger, full representation of the data. Returns null if the 
    101      * object has no internal content 
    102      *  
    103      * @return full representation as a Component or null 
    104      */ 
    105     public Component getLargeView() { 
    106         if (itsContent != null) { 
    107             if (currentPopupComponent == null) { 
    108                 addComponent(itsContent.getPopupComponent()); 
    109             } 
    110             return currentPopupComponent; 
    111         } 
    112         return null; 
    11367    } 
    11468 
     
    13488    /* 
    13589     * Methods inherited from AbstractComponentContainer. These are unnecessary 
    136      * (but mandatory). Some of them are not supported in this implementation. 
    137      */ 
    138  
    139     /** 
    140      * @see com.itmill.toolkit.ui.AbstractComponentContainer#attach() 
    141      */ 
    142     public void attach() { 
    143         super.attach(); 
    144         getLargeView().attach(); 
    145     } 
    146  
    147     /** 
    148      * @see com.itmill.toolkit.ui.AbstractComponentContainer#detach() 
    149      */ 
    150     public void detach() { 
    151         super.detach(); 
    152         getLargeView().detach(); 
    153     } 
    154  
    155     /** 
    156      * Returns an iterator for compatibility. The underlying List contains one 
    157      * element. 
    158      *  
    159      * @return an iterator with one Component element that == getLargeView() 
     90     * (but mandatory). They are not supported in this implementation. 
     91     */ 
     92 
     93    /** 
     94     * Not supported in this implementation. Will return an empty iterator. 
     95     *  
    16096     * @see com.itmill.toolkit.ui.ComponentContainer#getComponentIterator() 
    16197     */ 
    16298    public Iterator getComponentIterator() { 
    16399        return componentList.iterator(); 
    164     } 
    165  
    166     /** 
    167      * Clears both aspects of the PopupPanel. This is also true if the object is 
    168      * a dynamic PopupPanel. The object is guaranteed to be empty after this 
    169      * call. 
     100 
     101    } 
     102 
     103    /** 
     104     * Not supported in this implementation. 
    170105     *  
    171106     * @see com.itmill.toolkit.ui.AbstractComponentContainer#removeAllComponents() 
     107     * @throws UnsupportedOperationException 
    172108     */ 
    173109    public void removeAllComponents() { 
    174         if (currentPopupComponent != null) { 
    175             removeComponent(currentPopupComponent); 
    176         } 
    177  
    178         itsContent = null; 
    179         requestRepaint(); 
     110        throw new UnsupportedOperationException(); 
    180111    } 
    181112 
     
    184115     * UnsupportedOperationException. 
    185116     *  
    186      *  
    187      * @param source 
    188      *                contains the (single) component that is used as the 
    189      *                popup-view 
    190      * @throws UnsupportedOperationException 
    191117     * @see com.itmill.toolkit.ui.AbstractComponentContainer#moveComponentsFrom(com.itmill.toolkit.ui.ComponentContainer) 
     118     * @throws UnsupportedOperationException 
    192119     */ 
    193120    public void moveComponentsFrom(ComponentContainer source) 
    194121            throws UnsupportedOperationException { 
    195122 
    196         throw new UnsupportedOperationException( 
    197                 "moveComponentsFrom not supported"); 
    198     } 
    199  
    200     /** 
    201      * This adds a new Component as the full representation and removes the old 
    202      * one. It's effectively a replacement method. Users should remember that 
    203      * the only supported way of changing the contents of this object is through 
    204      * the PopupPanel.Content interface. 
    205      *  
    206      *  
    207      * @param c 
    208      *                the component to be added 
    209      * @throws RuntimeException 
     123        throw new UnsupportedOperationException(); 
     124    } 
     125 
     126    /** 
     127     * Not supported in this implementation. 
     128     *  
    210129     * @see com.itmill.toolkit.ui.AbstractComponentContainer#addComponent(com.itmill.toolkit.ui.Component) 
    211      */ 
    212     public void addComponent(Component c) throws RuntimeException { 
    213         if (c != null) { 
    214             if (currentPopupComponent != null) { 
    215                 removeComponent(currentPopupComponent); 
    216             } 
    217  
    218             if (c instanceof AbstractComponent) 
    219                 ((AbstractComponent) c).setImmediate(true); 
    220  
    221             currentPopupComponent = c; 
    222  
    223             componentList.add(c); 
    224             super.addComponent(c); 
    225         } 
     130     * @throws UnsupportedOperationException 
     131     */ 
     132    public void addComponent(Component c) throws UnsupportedOperationException { 
     133        throw new UnsupportedOperationException(); 
     134 
    226135    } 
    227136 
     
    230139     * UnsupportedOperationException. 
    231140     *  
    232      * @param oldComponent 
    233      *                the existing component 
    234      * @param newComponent 
    235      *                the new component 
    236      * @throws UnsupportedOperationException 
    237141     * @see com.itmill.toolkit.ui.ComponentContainer#replaceComponent(com.itmill.toolkit.ui.Component, 
    238142     *      com.itmill.toolkit.ui.Component) 
     143     * @throws UnsupportedOperationException 
    239144     */ 
    240145    public void replaceComponent(Component oldComponent, Component newComponent) 
    241146            throws UnsupportedOperationException { 
    242147 
    243         throw new UnsupportedOperationException( 
    244                 "Method replaceComponent not supported"); 
    245     } 
    246  
    247     /** 
    248      * Remove the larger view. Users should remember that the only supported way 
    249      * of changing the contents of this object is through the PopupPanel.Content 
    250      * interface. 
    251      *  
    252      * @param c 
    253      *                the component to be removed, in this case must be c == 
    254      *                getLargeView() 
     148        throw new UnsupportedOperationException(); 
     149    } 
     150 
     151    /** 
     152     * Not supported in this implementation 
    255153     *  
    256154     * @see com.itmill.toolkit.ui.AbstractComponentContainer#removeComponent(com.itmill.toolkit.ui.Component) 
    257155     */ 
    258     public void removeComponent(Component c) throws RuntimeException { 
    259         if (currentPopupComponent != null) { 
    260             super.removeComponent(c); 
    261             componentList.remove(c); 
    262             currentPopupComponent = null; 
    263         } 
     156    public void removeComponent(Component c) 
     157            throws UnsupportedOperationException { 
     158        throw new UnsupportedOperationException(); 
     159 
    264160    } 
    265161 
     
    284180        super.paintContent(target); 
    285181 
    286         target.addAttribute("html", getSmallView()); 
     182        target.addAttribute("html", itsContent.getMinimizedValueAsHTML()); 
    287183        target.addAttribute("popupVisible", popupVisible); 
    288184 
    289         Component componentToShow = getLargeView(); 
    290  
    291185        if (popupVisible) { 
     186            Component c = itsContent.getPopupComponent(); 
     187 
    292188            target.startTag("popupComponent"); 
    293             componentToShow.paint(target); 
     189            c.paint(target); 
    294190            target.endTag("popupComponent"); 
    295         } else { 
    296             removeComponent(componentToShow); 
    297191        } 
    298192 
     
    307201    public void changeVariables(Object source, Map variables) { 
    308202        if (variables.containsKey("popupVisibility")) { 
    309             Boolean tmp = (Boolean) variables.get("popupVisibility"); 
    310             popupVisible = tmp.booleanValue(); 
     203            popupVisible = ((Boolean) variables.get("popupVisibility")) 
     204                    .booleanValue(); 
     205 
     206            if (popupVisible) { 
     207                componentList.add(itsContent.getPopupComponent()); 
     208            } else { 
     209                componentList.clear(); 
     210            } 
    311211            requestRepaint(); 
    312212        } 
  • incubator/widgets/popuppanel/src/com/itmill/toolkit/ui/gwt/client/ui/IPopupPanel.java

    r5227 r5231  
    1010import com.google.gwt.user.client.ui.ClickListener; 
    1111import com.google.gwt.user.client.ui.HTML; 
     12import com.google.gwt.user.client.ui.HasFocus; 
    1213import com.google.gwt.user.client.ui.Label; 
    1314import com.google.gwt.user.client.ui.PopupListener; 
     
    8788        hostPopupVisible = uidl.getBooleanAttribute("popupVisible"); 
    8889        this.setHTML(uidl.getStringAttribute("html")); 
     90 
     91        if (uidl.hasAttribute("description")) { 
     92            this.setTitle(uidl.getStringAttribute("description")); 
     93        } 
    8994 
    9095        // Render the popup if visible and show it. The component inside can 
     
    132137                int left = hostHorizontalCenter - offsetWidth / 2; 
    133138                int top = hostVerticalCenter - offsetHeight / 2; 
     139 
    134140                popup.setPopupPosition(left, top); 
    135141 
     
    163169 
    164170    public static native void nativeBlur(Element e) /*-{  
    165                                        if(e.focus) { 
    166                                        e.focus(); 
    167                                        e.blur(); 
    168                                      } 
    169                                      }-*/; 
     171                                                         if(e.focus) { 
     172                                                         e.focus(); 
     173                                                         e.blur(); 
     174                                                       } 
     175                                                       }-*/; 
    170176 
    171177    private class CustomPopup extends ToolkitOverlay implements Container { 
     
    216222        public void hide() { 
    217223            // Notify children with focus 
     224            if ((popupComponentWidget instanceof HasFocus)) { 
     225                ((HasFocus) popupComponentWidget).setFocus(false); 
     226            } 
     227 
    218228            for (Iterator iterator = activeChildren.iterator(); iterator 
    219229                    .hasNext();) {