Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.widget.TreeSelector");
14
dojo.require("dojo.widget.HtmlWidget");
15
dojo.widget.defineWidget("dojo.widget.TreeSelector", dojo.widget.HtmlWidget, function () {
16
	this.eventNames = {};
17
	this.listenedTrees = [];
18
}, {widgetType:"TreeSelector", selectedNode:null, dieWithTree:false, eventNamesDefault:{select:"select", destroy:"destroy", deselect:"deselect", dblselect:"dblselect"}, initialize:function () {
1422 alexandre_ 19
	for (var name in this.eventNamesDefault) {
1318 alexandre_ 20
		if (dojo.lang.isUndefined(this.eventNames[name])) {
21
			this.eventNames[name] = this.widgetId + "/" + this.eventNamesDefault[name];
22
		}
23
	}
24
}, destroy:function () {
25
	dojo.event.topic.publish(this.eventNames.destroy, {source:this});
26
	return dojo.widget.HtmlWidget.prototype.destroy.apply(this, arguments);
27
}, listenTree:function (tree) {
28
	dojo.event.topic.subscribe(tree.eventNames.titleClick, this, "select");
29
	dojo.event.topic.subscribe(tree.eventNames.iconClick, this, "select");
30
	dojo.event.topic.subscribe(tree.eventNames.collapse, this, "onCollapse");
31
	dojo.event.topic.subscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
32
	dojo.event.topic.subscribe(tree.eventNames.removeNode, this, "onRemoveNode");
33
	dojo.event.topic.subscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
34
	this.listenedTrees.push(tree);
35
}, unlistenTree:function (tree) {
36
	dojo.event.topic.unsubscribe(tree.eventNames.titleClick, this, "select");
37
	dojo.event.topic.unsubscribe(tree.eventNames.iconClick, this, "select");
38
	dojo.event.topic.unsubscribe(tree.eventNames.collapse, this, "onCollapse");
39
	dojo.event.topic.unsubscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
40
	dojo.event.topic.unsubscribe(tree.eventNames.removeNode, this, "onRemoveNode");
41
	dojo.event.topic.unsubscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
42
	for (var i = 0; i < this.listenedTrees.length; i++) {
43
		if (this.listenedTrees[i] === tree) {
44
			this.listenedTrees.splice(i, 1);
45
			break;
46
		}
47
	}
48
}, onTreeDestroy:function (message) {
49
	this.unlistenTree(message.source);
50
	if (this.dieWithTree) {
51
		this.destroy();
52
	}
53
}, onCollapse:function (message) {
54
	if (!this.selectedNode) {
55
		return;
56
	}
57
	var node = message.source;
58
	var parent = this.selectedNode.parent;
59
	while (parent !== node && parent.isTreeNode) {
60
		parent = parent.parent;
61
	}
62
	if (parent.isTreeNode) {
63
		this.deselect();
64
	}
65
}, select:function (message) {
66
	var node = message.source;
67
	var e = message.event;
68
	if (this.selectedNode === node) {
69
		if (e.ctrlKey || e.shiftKey || e.metaKey) {
70
			this.deselect();
71
			return;
72
		}
73
		dojo.event.topic.publish(this.eventNames.dblselect, {node:node});
74
		return;
75
	}
76
	if (this.selectedNode) {
77
		this.deselect();
78
	}
79
	this.doSelect(node);
80
	dojo.event.topic.publish(this.eventNames.select, {node:node});
81
}, onMoveFrom:function (message) {
82
	if (message.child !== this.selectedNode) {
83
		return;
84
	}
85
	if (!dojo.lang.inArray(this.listenedTrees, message.newTree)) {
86
		this.deselect();
87
	}
88
}, onRemoveNode:function (message) {
89
	if (message.child !== this.selectedNode) {
90
		return;
91
	}
92
	this.deselect();
93
}, doSelect:function (node) {
94
	node.markSelected();
95
	this.selectedNode = node;
96
}, deselect:function () {
97
	var node = this.selectedNode;
98
	this.selectedNode = null;
99
	node.unMarkSelected();
100
	dojo.event.topic.publish(this.eventNames.deselect, {node:node});
101
}});
102