Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 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.TreeContextMenu");
13
dojo.provide("dojo.widget.TreeContextMenu");
12
dojo.require("dojo.event.*");
14
dojo.require("dojo.event.*");
13
dojo.require("dojo.io.*");
15
dojo.require("dojo.io.*");
14
dojo.require("dojo.widget.Menu2");
16
dojo.require("dojo.widget.Menu2");
15
dojo.widget.defineWidget("dojo.widget.TreeContextMenu", dojo.widget.PopupMenu2, function () {
17
dojo.widget.defineWidget("dojo.widget.TreeContextMenu", dojo.widget.PopupMenu2, function () {
16
	this.listenedTrees = [];
18
	this.listenedTrees = [];
17
}, {open:function (x, y, parentMenu, explodeSrc) {
19
}, {open:function (x, y, parentMenu, explodeSrc) {
18
	var result = dojo.widget.PopupMenu2.prototype.open.apply(this, arguments);
20
	var result = dojo.widget.PopupMenu2.prototype.open.apply(this, arguments);
19
	dojo.event.topic.publish(this.eventNames.open, {menu:this});
21
	dojo.event.topic.publish(this.eventNames.open, {menu:this});
20
	return result;
22
	return result;
21
}, listenTree:function (tree) {
23
}, listenTree:function (tree) {
22
	var nodes = tree.getDescendants();
24
	var nodes = tree.getDescendants();
23
	for (var i = 0; i < nodes.length; i++) {
25
	for (var i = 0; i < nodes.length; i++) {
24
		if (!nodes[i].isTreeNode) {
26
		if (!nodes[i].isTreeNode) {
25
			continue;
27
			continue;
26
		}
28
		}
27
		this.bindDomNode(nodes[i].labelNode);
29
		this.bindDomNode(nodes[i].labelNode);
28
	}
30
	}
29
	var _this = this;
31
	var _this = this;
30
	dojo.event.topic.subscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
32
	dojo.event.topic.subscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
31
	dojo.event.topic.subscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
33
	dojo.event.topic.subscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
32
	dojo.event.topic.subscribe(tree.eventNames.moveTo, this, "onMoveTo");
34
	dojo.event.topic.subscribe(tree.eventNames.moveTo, this, "onMoveTo");
33
	dojo.event.topic.subscribe(tree.eventNames.removeNode, this, "onRemoveNode");
35
	dojo.event.topic.subscribe(tree.eventNames.removeNode, this, "onRemoveNode");
34
	dojo.event.topic.subscribe(tree.eventNames.addChild, this, "onAddChild");
36
	dojo.event.topic.subscribe(tree.eventNames.addChild, this, "onAddChild");
35
	dojo.event.topic.subscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
37
	dojo.event.topic.subscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
36
	this.listenedTrees.push(tree);
38
	this.listenedTrees.push(tree);
37
}, unlistenTree:function (tree) {
39
}, unlistenTree:function (tree) {
38
	dojo.event.topic.unsubscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
40
	dojo.event.topic.unsubscribe(tree.eventNames.createDOMNode, this, "onCreateDOMNode");
39
	dojo.event.topic.unsubscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
41
	dojo.event.topic.unsubscribe(tree.eventNames.moveFrom, this, "onMoveFrom");
40
	dojo.event.topic.unsubscribe(tree.eventNames.moveTo, this, "onMoveTo");
42
	dojo.event.topic.unsubscribe(tree.eventNames.moveTo, this, "onMoveTo");
41
	dojo.event.topic.unsubscribe(tree.eventNames.removeNode, this, "onRemoveNode");
43
	dojo.event.topic.unsubscribe(tree.eventNames.removeNode, this, "onRemoveNode");
42
	dojo.event.topic.unsubscribe(tree.eventNames.addChild, this, "onAddChild");
44
	dojo.event.topic.unsubscribe(tree.eventNames.addChild, this, "onAddChild");
43
	dojo.event.topic.unsubscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
45
	dojo.event.topic.unsubscribe(tree.eventNames.treeDestroy, this, "onTreeDestroy");
44
	for (var i = 0; i < this.listenedTrees.length; i++) {
46
	for (var i = 0; i < this.listenedTrees.length; i++) {
45
		if (this.listenedTrees[i] === tree) {
47
		if (this.listenedTrees[i] === tree) {
46
			this.listenedTrees.splice(i, 1);
48
			this.listenedTrees.splice(i, 1);
47
			break;
49
			break;
48
		}
50
		}
49
	}
51
	}
50
}, onTreeDestroy:function (message) {
52
}, onTreeDestroy:function (message) {
51
	this.unlistenTree(message.source);
53
	this.unlistenTree(message.source);
52
}, bindTreeNode:function (node) {
54
}, bindTreeNode:function (node) {
53
	var _this = this;
55
	var _this = this;
54
	dojo.lang.forEach(node.getDescendants(), function (e) {
56
	dojo.lang.forEach(node.getDescendants(), function (e) {
55
		_this.bindDomNode(e.labelNode);
57
		_this.bindDomNode(e.labelNode);
56
	});
58
	});
57
}, unBindTreeNode:function (node) {
59
}, unBindTreeNode:function (node) {
58
	var _this = this;
60
	var _this = this;
59
	dojo.lang.forEach(node.getDescendants(), function (e) {
61
	dojo.lang.forEach(node.getDescendants(), function (e) {
60
		_this.unBindDomNode(e.labelNode);
62
		_this.unBindDomNode(e.labelNode);
61
	});
63
	});
62
}, onCreateDOMNode:function (message) {
64
}, onCreateDOMNode:function (message) {
63
	this.bindTreeNode(message.source);
65
	this.bindTreeNode(message.source);
64
}, onMoveFrom:function (message) {
66
}, onMoveFrom:function (message) {
65
	if (!dojo.lang.inArray(this.listenedTrees, message.newTree)) {
67
	if (!dojo.lang.inArray(this.listenedTrees, message.newTree)) {
66
		this.unBindTreeNode(message.child);
68
		this.unBindTreeNode(message.child);
67
	}
69
	}
68
}, onMoveTo:function (message) {
70
}, onMoveTo:function (message) {
69
	if (dojo.lang.inArray(this.listenedTrees, message.newTree)) {
71
	if (dojo.lang.inArray(this.listenedTrees, message.newTree)) {
70
		this.bindTreeNode(message.child);
72
		this.bindTreeNode(message.child);
71
	}
73
	}
72
}, onRemoveNode:function (message) {
74
}, onRemoveNode:function (message) {
73
	this.unBindTreeNode(message.child);
75
	this.unBindTreeNode(message.child);
74
}, onAddChild:function (message) {
76
}, onAddChild:function (message) {
75
	if (message.domNodeInitialized) {
77
	if (message.domNodeInitialized) {
76
		this.bindTreeNode(message.child);
78
		this.bindTreeNode(message.child);
77
	}
79
	}
78
}});
80
}});
79
dojo.widget.defineWidget("dojo.widget.TreeMenuItem", dojo.widget.MenuItem2, {treeActions:"", initialize:function (args, frag) {
81
dojo.widget.defineWidget("dojo.widget.TreeMenuItem", dojo.widget.MenuItem2, {treeActions:"", initialize:function (args, frag) {
80
	this.treeActions = this.treeActions.split(",");
82
	this.treeActions = this.treeActions.split(",");
81
	for (var i = 0; i < this.treeActions.length; i++) {
83
	for (var i = 0; i < this.treeActions.length; i++) {
82
		this.treeActions[i] = this.treeActions[i].toUpperCase();
84
		this.treeActions[i] = this.treeActions[i].toUpperCase();
83
	}
85
	}
84
}, getTreeNode:function () {
86
}, getTreeNode:function () {
85
	var menu = this;
87
	var menu = this;
86
	while (!(menu instanceof dojo.widget.TreeContextMenu)) {
88
	while (!(menu instanceof dojo.widget.TreeContextMenu)) {
87
		menu = menu.parent;
89
		menu = menu.parent;
88
	}
90
	}
89
	var source = menu.getTopOpenEvent().target;
91
	var source = menu.getTopOpenEvent().target;
90
	while (!source.getAttribute("treeNode") && source.tagName != "body") {
92
	while (!source.getAttribute("treeNode") && source.tagName != "body") {
91
		source = source.parentNode;
93
		source = source.parentNode;
92
	}
94
	}
93
	if (source.tagName == "body") {
95
	if (source.tagName == "body") {
94
		dojo.raise("treeNode not detected");
96
		dojo.raise("treeNode not detected");
95
	}
97
	}
96
	var treeNode = dojo.widget.manager.getWidgetById(source.getAttribute("treeNode"));
98
	var treeNode = dojo.widget.manager.getWidgetById(source.getAttribute("treeNode"));
97
	return treeNode;
99
	return treeNode;
98
}, menuOpen:function (message) {
100
}, menuOpen:function (message) {
99
	var treeNode = this.getTreeNode();
101
	var treeNode = this.getTreeNode();
100
	this.setDisabled(false);
102
	this.setDisabled(false);
101
	var _this = this;
103
	var _this = this;
102
	dojo.lang.forEach(_this.treeActions, function (action) {
104
	dojo.lang.forEach(_this.treeActions, function (action) {
103
		_this.setDisabled(treeNode.actionIsDisabled(action));
105
		_this.setDisabled(treeNode.actionIsDisabled(action));
104
	});
106
	});
105
}, toString:function () {
107
}, toString:function () {
106
	return "[" + this.widgetType + " node " + this.getTreeNode() + "]";
108
	return "[" + this.widgetType + " node " + this.getTreeNode() + "]";
107
}});
109
}});
108
 
110