Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#5940 closed defect (fixed)

Tree: model interface between store and tree

Reported by: bill Owned by: bill
Priority: high Milestone: 1.1
Component: Dijit Version: 1.0
Keywords: Cc:
Blocked By: Blocking:


Add middle "model" layer to Tree so that it's easier to connect Tree to stores with various formats for specifying children (including where the child points to the parent rather than vice-versa). QueryReadStore is one example of why this is important, since it doesn't support references.

Interface will look like:

// summary
//		Contract for any data provider object for the tree.  Tree 
//		passes in values to the constructor to specify the callbacks.
//		"item" is typically a but it's just a black box so
//		it could be anything.
//		This (like is just documentation, and not meant to be used.

destroy: function(){
	// summary: destroys this object, releasing connections to the store

// =======================================================================
// Methods for traversing hierarchy

getRoot: function(onItem){
	// summary:
	//		Calls onItem with the root item for the tree, possibly a fabricated item.
	//		Throws exception on error.

mayHaveChildren: function(/**/ item){
	// summary
	//		Tells if an item has or may have children.  Implementing logic here
	//		avoids showing +/- expando icon for nodes that we know don't have children.
	//		(For efficiency reasons we may not want to check if an element actually
	//		has children until user clicks the expando node)

getChildren: function(/**/ parentItem, /*function(items)*/ onComplete){
	// summary
	// 		Calls onComplete() with array of child items of given parent item, all loaded.
	//		Throws exception on error.

// =======================================================================
// Inspecting items

getIdentity: function(/* item */ item){
	// summary: returns identity for an item

getLabel: function(/**/ item){
	// summary: get the label for an item

// =======================================================================
// Write interface

newItem: function(/* Object? */ args, /*Object?*/ parentInfo){
	// summary
	//		Creates a new item.   See for details on args.

pasteItem: function(/*Item*/ childItem, /*Item*/ oldParentItem, /*Item*/ newParentItem, /*Boolean*/ bCopy){
	// summary
	//		Move or copy an item from one parent item to another.
	//		Used in drag & drop.
	//		If oldParentItem is specified and bCopy is false, childItem is removed from oldParentItem.
	//		If newParentItem is specified, childItem is attached to newParentItem.

// =======================================================================
// Callbacks

onChange: function(/**/ item){
	// summary
	//		Callback whenever an item has changed, so that Tree
	//		can update the label, icon, etc.   Note that changes
	//		to an item's children or parent(s) will trigger an
	//		onChildrenChange() so you can ignore those changes here.

onChildrenChange: function(/**/ parent, /*[]*/ newChildrenList){
	// summary
	//		Callback to do notifications about new, updated, or deleted items.

Related to work on #5879, #4544, #4977, #5560, #5536

Change History (4)

comment:1 Changed 13 years ago by bill

Resolution: fixed
Status: newclosed

(In [12603]) Refactor Tree again. Decided needed a layer between the store and the Tree in order to support non-standard stores that don't have children attributes with _references, like QueryReadStore?. Fixes #5940. !strict

comment:2 Changed 13 years ago by bill

(In [12627]) Make DnD test work. Refs #5940.

comment:3 Changed 13 years ago by bill

(In [12689]) Update i18n demo to use new Tree API; refs #5940.

comment:4 Changed 12 years ago by bill

(In [16335]) Model.js was in the wrong directory. Doesn't really matter, since this file is never used (except for documentation purposes), but might as well put it in the right place. Refs #5940 !strict

Note: See TracTickets for help on using tickets.