Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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
 
11
dojo.provide("dojo.widget.TreeSelector");
12
dojo.require("dojo.widget.HtmlWidget");
13
dojo.widget.defineWidget("dojo.widget.TreeSelector", dojo.widget.HtmlWidget, function () {
14
	this.eventNames = {};
15
	this.listenedTrees = [];
16
}, {widgetType:"TreeSelector", selectedNode:null, dieWithTree:false, eventNamesDefault:{select:"select", destroy:"destroy", deselect:"deselect", dblselect:"dblselect"}, initialize:function () {
17
	for (name in this.eventNamesDefault) {
18
		if (dojo.lang.isUndefined(this.eventNames[name])) {
19
			this.eventNames[name] = this.widgetId + "/" + this.eventNamesDefault[name];
20
		}
21
	}
22
}, destroy:function () {
23
	dojo.event.topic.publish(this.eventNames.destroy, {source:this});
24
	return dojo.widget.HtmlWidget.prototype.destroy.apply(this, arguments);
25
}, listenTree:function (tree) {
26
	dojo.event.topic.subscribe(tree.eventNames.titleClick, this, "select");
27
	dojo.event.topic.subscribe(tree.eventNames.iconClick, this, "select");
28
	dojo.event.topic.subscribe(tree.eventNames.collapse, this, "onCollapse");
29
	dojo.event.topic.subscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
30
	dojo.event.topic.subscribe(tree.eventNames.removeNode, this, "onRemoveNode");
31
	dojo.event.topic.subscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
32
	this.listenedTrees.push(tree);
33
}, unlistenTree:function (tree) {
34
	dojo.event.topic.unsubscribe(tree.eventNames.titleClick, this, "select");
35
	dojo.event.topic.unsubscribe(tree.eventNames.iconClick, this, "select");
36
	dojo.event.topic.unsubscribe(tree.eventNames.collapse, this, "onCollapse");
37
	dojo.event.topic.unsubscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
38
	dojo.event.topic.unsubscribe(tree.eventNames.removeNode, this, "onRemoveNode");
39
	dojo.event.topic.unsubscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
40
	for (var i = 0; i < this.listenedTrees.length; i++) {
41
		if (this.listenedTrees[i] === tree) {
42
			this.listenedTrees.splice(i, 1);
43
			break;
44
		}
45
	}
46
}, onTreeDestroy:function (message) {
47
	this.unlistenTree(message.source);
48
	if (this.dieWithTree) {
49
		this.destroy();
50
	}
51
}, onCollapse:function (message) {
52
	if (!this.selectedNode) {
53
		return;
54
	}
55
	var node = message.source;
56
	var parent = this.selectedNode.parent;
57
	while (parent !== node && parent.isTreeNode) {
58
		parent = parent.parent;
59
	}
60
	if (parent.isTreeNode) {
61
		this.deselect();
62
	}
63
}, select:function (message) {
64
	var node = message.source;
65
	var e = message.event;
66
	if (this.selectedNode === node) {
67
		if (e.ctrlKey || e.shiftKey || e.metaKey) {
68
			this.deselect();
69
			return;
70
		}
71
		dojo.event.topic.publish(this.eventNames.dblselect, {node:node});
72
		return;
73
	}
74
	if (this.selectedNode) {
75
		this.deselect();
76
	}
77
	this.doSelect(node);
78
	dojo.event.topic.publish(this.eventNames.select, {node:node});
79
}, onMoveFrom:function (message) {
80
	if (message.child !== this.selectedNode) {
81
		return;
82
	}
83
	if (!dojo.lang.inArray(this.listenedTrees, message.newTree)) {
84
		this.deselect();
85
	}
86
}, onRemoveNode:function (message) {
87
	if (message.child !== this.selectedNode) {
88
		return;
89
	}
90
	this.deselect();
91
}, doSelect:function (node) {
92
	node.markSelected();
93
	this.selectedNode = node;
94
}, deselect:function () {
95
	var node = this.selectedNode;
96
	this.selectedNode = null;
97
	node.unMarkSelected();
98
	dojo.event.topic.publish(this.eventNames.deselect, {node:node});
99
}});
100