Changeset 4795

Show
Ignore:
Timestamp:
06/09/08 07:20:38 (6 months ago)
Author:
risto.yrjana@…
Message:

Fix for #1783 and refactoring for java 1.5

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

Legend:

Unmodified
Added
Removed
  • incubator/widgets/menubar/src/com/itmill/toolkit/ui/MenuBar.java

    r4658 r4795  
    1818public class MenuBar extends AbstractComponent { 
    1919 
    20     private List menuItems = new ArrayList(); // Items of the top-level menu 
    21     private static int numberOfItems = 0; // Number of items in this menu 
     20    // Items of the top-level menu 
     21    private List<MenuItem> menuItems = new ArrayList<MenuItem>(); 
     22 
     23    // Number of items in this menu 
     24    private static int numberOfItems = 0; 
    2225 
    2326    /** Tag is the UIDL element name for client-server communications. */ 
     
    2932    public void paintContent(PaintTarget target) throws PaintException { 
    3033 
    31         Stack iteratorStack = new Stack(); // Stack for list iterators 
    32  
    33          
     34        // Superclass writes any common attributes in the paint target. 
     35        super.paintContent(target); 
     36 
     37        // Stack for list iterators 
     38        Stack<Iterator<MenuItem>> iteratorStack = new Stack<Iterator<MenuItem>>(); 
     39 
    3440        target.startTag("items"); 
    3541 
    36         Iterator itr = menuItems.iterator(); 
     42        Iterator<MenuItem> itr = menuItems.iterator(); 
    3743 
    3844        // This generates the tree from the contents of the menu 
     
    5258                target.addAttribute("command", false); 
    5359            } 
    54              
    5560 
    5661            Resource icon = item.getIcon(); 
     
    6166            if (item.hasChildren()) { 
    6267                iteratorStack.push(itr); // For later use 
    63                 itr = item.getChildren().iterator(); // Go through the children 
     68 
     69                // Go through the children 
     70                itr = item.getChildren().iterator(); 
    6471            } else { 
    6572                target.endTag("item"); // Item had no children, end description 
     
    6774 
    6875            if (!itr.hasNext() && !iteratorStack.empty()) { // The end submenu 
    69                 itr = (Iterator) iteratorStack.pop();  
     76                itr = (Iterator<MenuItem>) iteratorStack.pop(); 
    7077                target.endTag("item"); 
    7178            } 
     
    7885    /** Deserialize changes received from client. */ 
    7986    public void changeVariables(Object source, Map variables) { 
    80         Stack items = new Stack(); 
     87        Stack<MenuItem> items = new Stack<MenuItem>(); 
    8188        boolean found = false; 
    8289 
     
    8491 
    8592            Integer clickedId = (Integer) variables.get("clickedId"); 
    86             Iterator itr = this.getItems().iterator(); 
     93            Iterator<MenuItem> itr = this.getItems().iterator(); 
    8794            while (itr.hasNext()) { 
    88                 items.push(itr.next()); 
     95                items.push((MenuItem) itr.next()); 
    8996            } 
    9097 
     
    137144     *                The menu items to be added 
    138145     */ 
    139     public void addItems(java.util.List items) { 
     146    public void addItems(java.util.List<MenuItem> items) { 
    140147        if (items != null) { 
    141             Iterator itr = items.iterator(); 
     148            Iterator<MenuItem> itr = items.iterator(); 
    142149 
    143150            while (itr.hasNext()) { 
     
    153160     * @return a list containing the MenuItem objects in the menubar 
    154161     */ 
    155     public java.util.List getItems() { 
     162    public java.util.List<MenuItem> getItems() { 
    156163        return menuItems; 
    157164    } 
     
    207214        private MenuCommand itsCommand; 
    208215        private String itsText; 
    209         private List itsChildren; 
     216        private List<MenuItem> itsChildren; 
    210217        private Resource itsIcon; 
    211218        private MenuItem itsParent; 
     
    245252         *                A list of MenuItems to be added to the item 
    246253         */ 
    247         public MenuItem(java.lang.String text, java.util.List children) { 
     254        public MenuItem(java.lang.String text, java.util.List<MenuItem> children) { 
    248255            itsId = ++numberOfItems; 
    249256            itsText = text; 
     
    270277 
    271278                if (itsChildren == null) { 
    272                     itsChildren = new ArrayList(); 
     279                    itsChildren = new ArrayList<MenuItem>(); 
    273280                } 
    274281 
    275                 //The only place where the parent is set 
     282                // The only place where the parent is set 
    276283                item.setParent(this); 
    277284                itsChildren.add(item); 
     
    286293         *                A list of menu items to be added. 
    287294         */ 
    288         public void addItems(java.util.List items) { 
     295        public void addItems(java.util.List<MenuItem> items) { 
    289296            if (items != null) { 
    290297 
    291                 Iterator itr = items.iterator(); 
     298                Iterator<MenuItem> itr = items.iterator(); 
    292299                while (itr.hasNext()) { 
    293300                    addItem((MenuItem) itr.next()); 
     
    330337         * @return List of children items, or null if there are none 
    331338         */ 
    332         public java.util.List getChildren() { 
     339        public java.util.List<MenuItem> getChildren() { 
    333340            return itsChildren; 
    334341        } 
  • incubator/widgets/menubar/src/com/itmill/toolkit/ui/gwt/client/ui/IMenuBar.java

    r4662 r4795  
    1717 
    1818    /** Component identifier in UIDL communications. */ 
    19     String uidlId; 
     19    protected String uidlId; 
    2020 
    2121    /** Reference to the server connection object. */ 
    22     ApplicationConnection client; 
     22    protected ApplicationConnection client; 
    2323 
    2424    /** A host reference for the Command objects */ 
    25     final IMenuBar hostReference = this; 
     25    protected final IMenuBar hostReference = this; 
    2626 
    2727    /** 
     
    6666        // Get tree received from server and actualize it in the GWT-MenuBar 
    6767        UIDL items = uidl.getChildUIDL(0); 
    68         Iterator itr = items.getChildIterator(); 
    69         Stack iteratorStack = new Stack(); 
     68        Iterator<UIDL> itr = items.getChildIterator(); 
     69        Stack<Iterator<UIDL>> iteratorStack = new Stack<Iterator<UIDL>>(); 
     70        Stack<MenuBar> menuStack = new Stack<MenuBar>(); 
    7071        MenuBar currentMenu = this; 
    71         MenuBar parentMenu = null; 
    7272 
    7373        // Construct an empty command to be used when the item has no command 
     
    115115 
    116116            if (item.getChildCount() > 0) { 
    117                 parentMenu = currentMenu; 
     117                menuStack.push(currentMenu); 
    118118                iteratorStack.push(itr); 
    119119                itr = item.getChildIterator(); 
     
    123123 
    124124            if (!itr.hasNext() && !iteratorStack.empty()) { 
    125                 itr = (Iterator) iteratorStack.pop(); 
    126                 currentMenu = parentMenu; 
     125                itr = (Iterator<UIDL>) iteratorStack.pop(); 
     126                currentMenu = menuStack.pop(); 
    127127            } 
    128128        }// while