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.TreeDndControllerV3");
14
dojo.require("dojo.dnd.TreeDragAndDropV3");
15
dojo.require("dojo.experimental");
16
dojo.experimental("Tree drag'n'drop' has lots of problems/bugs, it requires dojo drag'n'drop overhaul to work, probably in 0.5");
17
dojo.widget.defineWidget("dojo.widget.TreeDndControllerV3", [dojo.widget.HtmlWidget, dojo.widget.TreeCommon], function () {
18
	this.dragSources = {};
19
	this.dropTargets = {};
20
	this.listenedTrees = {};
21
}, {listenTreeEvents:["afterChangeTree", "beforeTreeDestroy", "afterAddChild"], listenNodeFilter:function (elem) {
22
	return elem instanceof dojo.widget.Widget;
23
}, initialize:function (args) {
24
	this.treeController = dojo.lang.isString(args.controller) ? dojo.widget.byId(args.controller) : args.controller;
25
	if (!this.treeController) {
26
		dojo.raise("treeController must be declared");
27
	}
28
}, onBeforeTreeDestroy:function (message) {
29
	this.unlistenTree(message.source);
30
}, onAfterAddChild:function (message) {
31
	this.listenNode(message.child);
32
}, onAfterChangeTree:function (message) {
33
	if (!message.oldTree) {
34
		return;
35
	}
36
	if (!message.newTree || !this.listenedTrees[message.newTree.widgetId]) {
37
		this.processDescendants(message.node, this.listenNodeFilter, this.unlistenNode);
38
	}
39
	if (!this.listenedTrees[message.oldTree.widgetId]) {
40
		this.processDescendants(message.node, this.listenNodeFilter, this.listenNode);
41
	}
42
}, listenNode:function (node) {
43
	if (!node.tree.DndMode) {
44
		return;
45
	}
46
	if (this.dragSources[node.widgetId] || this.dropTargets[node.widgetId]) {
47
		return;
48
	}
49
	var source = null;
50
	var target = null;
51
	if (!node.actionIsDisabled(node.actions.MOVE)) {
52
		var source = this.makeDragSource(node);
53
		this.dragSources[node.widgetId] = source;
54
	}
55
	var target = this.makeDropTarget(node);
56
	this.dropTargets[node.widgetId] = target;
57
}, makeDragSource:function (node) {
58
	return new dojo.dnd.TreeDragSourceV3(node.contentNode, this, node.tree.widgetId, node);
59
}, makeDropTarget:function (node) {
60
	return new dojo.dnd.TreeDropTargetV3(node.contentNode, this.treeController, node.tree.DndAcceptTypes, node);
61
}, unlistenNode:function (node) {
62
	if (this.dragSources[node.widgetId]) {
63
		dojo.dnd.dragManager.unregisterDragSource(this.dragSources[node.widgetId]);
64
		delete this.dragSources[node.widgetId];
65
	}
66
	if (this.dropTargets[node.widgetId]) {
67
		dojo.dnd.dragManager.unregisterDropTarget(this.dropTargets[node.widgetId]);
68
		delete this.dropTargets[node.widgetId];
69
	}
70
}});
71