Login Register

Tree - problem accessing newly created items

Hi,

Here's the use case. A sub-tree (with children) needs to be added to a node in an existing tree (parent tree). So what is the best way to do this? Should we create a store and add the sub-tree item by item to the parent tree. This works, but here's the catch.

Lets say a sub-tree node, A has children, B,C,D. So A is added to the parent tree using the following:

tree.model.newItem (A, parent);

.

Now we want to add the children B, C, D to A. Naturally, I need to acess A. What is the recommended methodology? Use a query? Here it is:

tree.model.store.fetch ( { query : id : A.id}, onComplete: handleItems, onError:displayError} );

This does not work. The error is that there is no such id!!!

Some questions:
If this methodology is acceptable, what should I use to get an item that was added to the tree? Why can't we say
tree.model.getItem (A.id) and get back the item? Perhaps I am missing something, but I don't see this method.
If this is not the appropriate methodology, what is?
Finally - a suggestion. Please add examples of recommended methodologies for CRUD (Create, Replace, Update, Delete) operations on the tree. This would fit well into your API site.

Thanks,

John

Okay - I see how it might

Okay - I see how it might be done. The tree.model.newItem(...) returns the newly created item. And this can be used as the new parent. However, it would still be great if there were more examples of how to use the tree APIs.

Thanks,

John

Since you guys are back to

Since you guys are back to your normal, non-responsive selves, here is more grist for the mill. Here is what the dictionary says about documentation.

Documentation: manuals, listings, diagrams, and other hard- or soft-copy written and graphic materials that describe the use, operation, maintenance, or design of software or hardware:

Note the strange insistence on describing the "use operation, maintenance or design. of software". Now lets look at enterprise grade software, like Java 1.5 documentation:

ArrayList
Constructor Summary
ArrayList()
Constructs an empty list with an initial capacity of ten.
ArrayList(Collection<? extends E> c)
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
ArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity.

And here's the addAll method's documentation:

addAll

public boolean addAll(Collection<? extends E> c)

Appends all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collection's Iterator. The behavior of this operation is undefined if the specified Collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified Collection is this list, and this list is nonempty.)

Specified by:
addAll in interface Collection
Specified by:
addAll in interface List
Overrides:
addAll in class AbstractCollection

Parameters:
c - the elements to be inserted into this list.
Returns:
true if this list changed as a result of the call.
Throws:
NullPointerException - if the specified collection is null.
See Also:

Note that it cleverly documents the return value and it's type. One idly wonders why?

Here's what dijit.Tree.model has to say: (followed from the dijit.Tree API).

dojo.require("dijit.Tree");
defined in dijit/Tree.js
Alternate interface from store to access data (and changes to data) in the tree.

So the user has to dig through to dijit.Tree.TreeStoreModel, which has this entry:

dijit.tree.TreeStoreModel
dojo.require("dijit.Tree");
defined in dijit/Tree.js
passed the arguments listed above (store, etc)
Usage
var foo=new dijit.tree.TreeStoreModel(args: Object); (view source)

parameter type description
args Object

Examples
Example 1

{id:’ROOT’}

So then we hunt down newItem:

dijit.tree.TreeStoreModel.newItem
dojo.require("dijit.Tree");
defined in dijit/Tree.js
Creates a new item. See dojo.data.api.Write for details on args. Used in drag & drop when item from external source dropped onto tree.
Usage
var foo=dijit.tree.TreeStoreModel.newItem(args: Object?, parent); (hide source)

var pInfo = {parent: parent, attribute: this.childrenAttrs[0]};
return this.store.newItem(args, pInfo);

parameter type description
args Object Optional.
parent

And we see that it returns an item. Finally.....! But the question still remains? How do CRUD operations occur on a tree? Where are the examples?

Now I am sure that someone with a priori knowledge will say....oh look here's all you have to do and point immediately to some forum entry or some piece of code, etc. However, it is not enough that folks familiar with the byzantine pathways of their own weird thought processes understand how to navigate through their domain. If they want others to participate in their world it must be sane, clear, user-friendly and intuitive.

Why can't there be simple a usage example to create a node and add children to the tree programmatically.

var argData={items: [ ], identifier: 'id', label: 'name'};
var treeStore = new dojo.data.ItemFileWriteStore({data:argData}); 

var parentNode = treeStore.newItem({id: '1', name:'Project', type: 'component'});
treeStore.newItem({id: '2', name:'Requirements', 
                                  type: 'component'}, parentNode);
treeStore.newItem({id: '3', name:'Architecture Design', 
		                   type: 'component'},  parentNode );

var myModel = new dijit.tree.ForestStoreModel({
                                store: treeStore,
                                query: {type:'component'},
                                rootId: "project",
                                rootLabel: "Project",
                                childrenAttr: "children" });

var tree=new dijit.Tree({id:'tree1', model: myModel,
                                        onClick:testTreeEventHandlerAddItem, 
                                         childrenAttr:'children'});
tree.startup();

And why can't this be available at the API site or even in your tests for all to see and benefit from?

Note that in the world of enterprise software there exists an odd construct called a programming model. It has something to do with how your objects are built and wired together. It is canonical in that objects of certain types are constructed and hooked-up in certain definite ways. It is consistent, it has cohesion and an inner logic. It is the hallmark of a best of breed software distributions. Please look at Spring, or Tomcat or Jetty or any of the best of breed offerings. They contain clear examples of a mature, evolved programming model s (among other things).

Dojo, on the other hand ........
Your objects are not consistent: AccordionPane does not behave like a ContentPane, even though it has the typology of a
content pane. Try putting a Tree into an AccordionPane programmatically. It's interesting. There's a bug coming your way on this.

You change the domain model of your objects and do not provide examples for differences: A dijit.Tree is constructed and
wired-up differently from a TabContainer. A Border container has to be constructed differently than an ExpandoPane. (The
startup () call must come immediately after the BorderContainer is constructed and before any children are added to it.
Where is the documentation on this idiosyncracy?) However, an AccordionPane must have it's startup() call only after
all it's children have been added. TabContainers must change to the new wiring methodology of 1.1 or they
will not render at all. An ExpandoPane in Tab 2 of a TabContainer will collapse all the way and will not open, whereas in Tab 1 it
behaves as specified.

And there's more - these are only some of the highlights!

Your objects, when programmatically constructed behave differently than when they are built in-line. The "theory" that they should be the same is not born out by experience and you guys will not test this proposition. In fact, users like myself, are your programmatic test group, whose input you continually deprecate, trivialize or simply ignore.

Can you guys relate to this?

John