1. #1
    Ext User
    Join Date
    Apr 2008
    Posts
    376
    Vote Rating
    0
    zaccret is on a distinguished road

      0  

    Default Leaf name in a BaseTreeModel

    Leaf name in a BaseTreeModel


    When you build a tree with a BaseTreeModel, the manner to set
    leaf names is a little confusing. On each leaf, you have to
    Code:
    set("name","my folder name")
    We don't know which property have to be set (it's not very intuitive and it's not in the javadoc ;-)).
    Why don't we have get/setName(String) or get/setTest(String) ?
    Is there a good reason to that ?

    Code:
    public class MyBug implements EntryPoint {
        private Tree tree;
        private TreeViewer folders;
    
        /**
         * This is the entry point method.
         */
        public void onModuleLoad() {
            tree = new Tree();
    
            folders = new TreeViewer(tree);
            folders.setLabelProvider(new ModelLabelProvider());
            folders.setContentProvider(new ModelTreeContentProvider() {
                @Override
                public boolean hasChildren(Object element) {
                    return false;
                }
            });
    
            HashMap<String, Object> maMap = new HashMap<String, Object>();
            maMap.put("name", "My folder 1");
            final BaseTreeModel model = new BaseTreeModel();
            BaseTreeModel folder1 = new BaseTreeModel();
            folder1.set("name","Folder 1");
            model.add(folder1);
            folders.setInput(model);
            RootPanel.get().add(tree);
        }
    }

  2. #2
    Ext User
    Join Date
    Apr 2008
    Posts
    63
    Vote Rating
    0
    cdasher is on a distinguished road

      0  

    Default


    Although the demo and the demo model use name, you don't have to. Just extend BseTreeModel and add your own String to use for the label and then set the LabelProvider.

    You can see the getText method returns etSomeTextToDisplayAsTheLabel

    I have a getter/setter on my model class get/setIconStyle which holds a string for css background image like "icon-myObject" which you then style in your CSS like:

    .icon-myobject {
    background-image: url(mycustomIcon.png);
    }

    and add this image to root of webapp.

    then
    viewer.setLabelProvider(new LabelProvider() {
    public String getText(Object element) {
    if (element instanceof MyObject {
    return ((MyObject) element).getSomeTextToDisplayAsTheLabel();
    } else {
    return "unknown";
    }

    }

    public String getIconStyle(Object element) {
    if (element instanceof MyObject {
    return ((MyObject) element).getIconStyle();
    } else {
    return "some-other-css-style";
    }
    }
    });

    I hope this helps.

  3. #3
    Ext User
    Join Date
    Apr 2008
    Posts
    376
    Vote Rating
    0
    zaccret is on a distinguished road

      0  

    Default


    Yes. That will help. It feels more "OOP" ;-) Thank you.

  4. #4
    Ext User
    Join Date
    Apr 2008
    Posts
    376
    Vote Rating
    0
    zaccret is on a distinguished road

      0  

    Default


    Maybe for the basic tree we should have these 2 classes :
    Code:
    public class DefaultTreeLabelProvider extends LabelProvider<DefaultTreeModel> {
        @Override
        public String getText(DefaultTreeModel element) {
            return element.getName();
        }
    }
    
    public class DefaultTreeModel extends BaseTreeModel {
        private String name;
        
        public DefaultTreeModel(String name) {
            super();
            setName(name);
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    }
    then the code to build the tree becomes :

    Code:
    TreeViewer<SingleTreeSelectionModel> folders = new TreeViewer<SingleTreeSelectionModel>(tree);
    folders.setLabelProvider(new DefaultTreeLabelProvider());
    folders.setContentProvider(new ModelTreeContentProvider());
    
    final BaseTreeModel model = new BaseTreeModel();
    model.add(new DefaultTreeModel("Folder 1 name"));
    model.add(new DefaultTreeModel("Folder 2 name"));
    model.add(new DefaultTreeModel("Folder 3 name"));
    folders.setInput(model);
    What do you think about that ?

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi