Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    PickListItem with split Tree Requirements

    SmartClient Version: SNAPSHOT_v9.1d_2013-09-15/PowerEdition Deployment (built 2013-09-15)

    Chrome Version 30.0/ FF Version 24.x

    I'm attempting to use a PickListItem where the first child of the tree root has a fixed set of code defined nodes, but the second child of the root needs to fetch it's children from a DataSource. Something like your PickTree SmartGWT showcase example of two pick trees, Advertising and Category, but I only have room for one top level pick tree and so I'm trying to combine them into the first level of the pick tree.

    Code:
    pPickTreeItem = new PickTreeItem();
    pPickTreeItem.setTitle("Choose");
    TreeNode myC1     = new TreeNode("Choice1");
    TreeNode myC2    = new TreeNode("Choice2");
    TreeNode bltIn         = new TreeNode("Built In:", myC1, myC2);
    final TreeNode favP   = new TreeNode("Favs:"); 
    final TreeNode baseP  = new TreeNode("root", bltIn, favP);
    
    final Tree treeP = new Tree();
    treeP.setRoot(baseP);		
    pPickTreeItem.setValueTree(treeP);		
    pPickTreeItem.setDefaultValue("Favs:");
    			
    pPickTreeItem.addChangeHandler(new com.smartgwt.client.widgets.form.fields.events.ChangeHandler ()
    Not fully shown here is that I have a ChangeHandler on pPickTreeItem in which I attempt to fetch the children of the favP leg, modify the treeP tree by adding the fetched data nodes as:

    Code:
    TreeNode node = new TreeNode(record.getAttibuteAsString("Name"));
    node.setParentID( favP.getName() );
    
    treeP.setRoot(baseP);  // baseP has been changed thru favP above
    pPickTreeItem.setValueTree(treeP)
    pPickTreeItem.redraw();
    But this doesn't work and the tree selections of the fetch data done in the ChangeHandler never appear in pPickListItem.

    Do you have an alternative suggestion, or see where I have gone wrong?

    #2
    You should provide a DataSource to do the fetches and provide the initial set of nodes via setInitialData().

    Comment


      #3
      Originally posted by Isomorphic View Post
      You should provide a DataSource to do the fetches and provide the initial set of nodes via setInitialData().
      setInitialData can only be called on a TreeGrid, but PickListItem only accepts a setValueTree on a Tree Object. PickListItem does not have an setInitialData method.

      So I'm not sure how exactly the setInitialData is supposed to be applied?

      Comment


        #4
        Ping?

        This answer doesn't make sense to me.

        Comment


          #5
          Sorry for the confusion - the API we were thinking of is not available on PickTreeItem directly.
          We're looking at the easiest way to do this / whether we want to expose an additional API to handle this case. We'll be following up with a concrete answer.

          Comment


            #6
            You can seed a ResultTree with initialData using the standard "setData()" method [implemented at the Tree] level.
            Folders with no explicitly specified children supplied in this way will automatically issue server requests to pick up their children.
            Here's an example of attaching such a tree to a PickTreeItem. (This uses the "supplyCategory" dataSource as an example)

            Regards
            Isomorphic Software

            Code:
            import com.google.gwt.core.client.EntryPoint;
            import com.smartgwt.client.data.DataSource;
            import com.smartgwt.client.widgets.form.DynamicForm;
            import com.smartgwt.client.widgets.form.fields.PickTreeItem;
            import com.smartgwt.client.widgets.tree.ResultTree;
            import com.smartgwt.client.widgets.tree.TreeNode;
            
            public class PickTreeItemSeed implements EntryPoint{
            
            	@Override
            	public void onModuleLoad() {
            		ResultTree categoryTree = new ResultTree();
            		categoryTree.setDataSource(DataSource.get("supplyCategory"));
            	
            		TreeNode[] initialData = new TreeNode[] {
            				// top level node
            				new TreeNode() {{
            					setAttribute("parentID",  "root");
            					setAttribute("categoryName", "Canteen and Washroom Products");
            					setIsFolder(true);
            				}},
            				// Children of the first node:
            				new TreeNode() {{
            					setAttribute("parentID",  "Canteen and Washroom Products");
            					setAttribute("categoryName", "Canteen");
            					setIsFolder(true);
            				}},
            				new TreeNode() {{
            					setAttribute("parentID",  "Canteen and Washroom Products");
            					setAttribute("categoryName", "Washroom");
            					setIsFolder(true);
            				}},
            				
            				// Additional top level nodes
            				new TreeNode() {{
            					setAttribute("parentID",  "root");
            					setAttribute("categoryName", "Computer Consumables");
            					setIsFolder(true);
            				}},
            				new TreeNode() {{
            					setAttribute("parentID",  "root");
            					setAttribute("categoryName", "Computer Hardware/software");
            					setIsFolder(true);
            				}},
            				new TreeNode() {{
            					setAttribute("parentID",  "root");
            					setAttribute("categoryName", "First Aid");
            					setIsFolder(true);
            				}},
            				new TreeNode() {{
            					setAttribute("parentID",  "root");
            					setAttribute("categoryName", "Office Filing and Storage");
            					setIsFolder(true);
            				}},
            				new TreeNode() {{
            					setAttribute("parentID",  "root");
            					setAttribute("categoryName", "Office Furniture");
            					setIsFolder(true);
            				}},
            				new TreeNode() {{
            					setAttribute("parentID",  "root");
            					setAttribute("categoryName", "Office Machines and Electronics");
            					setIsFolder(true);
            				}},
            				new TreeNode() {{
            					setAttribute("parentID",  "root");
            					setAttribute("categoryName", "Office Paper Products");
            					setIsFolder(true);
            				}}
            		};
            		categoryTree.setData(initialData);
            		
            		PickTreeItem categoryItem= new PickTreeItem();
            		categoryItem.setName("category");
            		categoryItem.setValueTree(categoryTree);
            		categoryItem.setValueField("categoryName");
            
            		DynamicForm testForm = new DynamicForm();
            		testForm.setItems(categoryItem);
            		
            		testForm.draw();
            
            	}
            
            }

            Comment


              #7
              Thanks.

              This is working for me. We were moving towards a similar solution but this fills in the features.

              Comment

              Working...
              X