1. #1
    Ext GWT Premium Member
    Join Date
    Mar 2009
    Posts
    226
    Vote Rating
    3
    The_Jackal is on a distinguished road

      0  

    Default Show empty TreePanel branch nodes using the branch icon (not leaf icon)

    Show empty TreePanel branch nodes using the branch icon (not leaf icon)


    The default TreePanel changes the branch node icon to a leaf node icon if not children exist. This doesn't really make sense to me - in the GXT examples a folder of music gets a music icon if there is no music in it. It's still a folder - just an empty one!

    The code below is a ModelIconProvider that fixes this, with the caveat that you must add a property to each leaf model. See the javadoc for an example:

    BranchIconProv.jpg

    Code:
    import com.extjs.gxt.ui.client.data.ModelData;
    import com.extjs.gxt.ui.client.data.ModelIconProvider;
    import com.extjs.gxt.ui.client.widget.treepanel.TreePanel;
    import com.extjs.gxt.ui.client.widget.treepanel.TreeStyle;
    import com.google.gwt.user.client.ui.AbstractImagePrototype;
    
    /**
     * Enables TreePanel to have branch nodes with no children preserving the (open and closed) branch node icon.
     * Default TreePanel changes the branch node to a leaf node if no children exist.
     * 
     * <p>Usage:
     * <pre>
     * TreePanel treePanel = new TreePanel<ModelData>(store));
     * treePanel.setIconProvider(new BranchPreservingIconProvider<ModelData>(treePanel));
     * 
     * ...
     * //Each leaf node model must set the {@link BranchPreservingIconProvider#IS_LEAF} property
     * BaseTreeModel treeItem = new BaseTreeModel();
     * treeItem.set(BranchPreservingIconProvider.IS_LEAF, Boolean.TRUE);
     * </pre>
     * </p>
     *
     * @param <M> ModelData type
     * @author Carl Pritchett
     */
    public class BranchPreservingIconProvider<M extends ModelData> implements ModelIconProvider<M>
    {
        public static final String IS_LEAF = "isLeaf";
        
        private TreePanel<M> treePanel;
        
        public BranchPreservingIconProvider(TreePanel<M> treePanel)
        {
            this.treePanel = treePanel;
        }
        
        public AbstractImagePrototype getIcon(M model)
        {
            TreeStyle ts = treePanel.getStyle();
            AbstractImagePrototype style = ts.getLeafIcon();
            
            if (!Boolean.TRUE.equals(model.get(IS_LEAF)))
            {
                if (treePanel.isExpanded(model))
                {
                    style = ts.getNodeOpenIcon();
                }
                else
                {
                    style = ts.getNodeCloseIcon();
                }
            }
            
            return style;
        }
    }
    Last edited by The_Jackal; 11 Aug 2010 at 7:28 PM. Reason: Code fix

Similar Threads

  1. show custom icon in TreePanel leaf nodes
    By shirin_iir in forum Ext GWT: Discussion
    Replies: 1
    Last Post: 24 May 2010, 6:23 PM
  2. [CLOSED] [2.0-Branch r1749] icon in button misplaced (only FF)
    By takayser in forum Ext GWT: Bugs (2.x)
    Replies: 1
    Last Post: 19 Oct 2009, 2:38 AM
  3. Change Tree Branch/Folder Icon
    By Lloyd K in forum Ext 2.x: Help & Discussion
    Replies: 9
    Last Post: 1 Oct 2009, 2:55 AM
  4. How to hide the folder icon in non-leaf nodes in a TreePanel
    By rvillane in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 3 Oct 2008, 9:43 AM

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar