Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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