1 |
3032
|
perry
|
/*
|
2 |
|
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3 |
|
|
$Id$
|
4 |
|
|
*/
|
5 |
|
|
|
6 |
|
|
/**
|
7 |
|
|
* Base Tool object that all Tools extend.
|
8 |
|
|
* @constructor
|
9 |
|
|
* @author Mike Adair mike.adairATccrs.nrcan.gc.ca
|
10 |
|
|
* @param toolNode The tool node from the Config XML file.
|
11 |
|
|
* @param model The widget object which created this tool.
|
12 |
|
|
*/
|
13 |
|
|
function ToolBase(toolNode, model) {
|
14 |
|
|
this.model = model;
|
15 |
|
|
this.toolNode = toolNode;
|
16 |
|
|
|
17 |
|
|
//set the ID for this tool
|
18 |
|
|
var id = toolNode.selectSingleNode("@id");
|
19 |
|
|
if (id) {
|
20 |
|
|
this.id = id.firstChild.nodeValue;
|
21 |
|
|
} else {
|
22 |
|
|
this.id = "MbTool_" + mbIds.getId();
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
/**
|
26 |
|
|
* Initialize the targetModel property to point to the object. This happens
|
27 |
|
|
* as an init listener to ensure that the referenced model has been created.
|
28 |
|
|
* @param toolRef Pointer to this object.
|
29 |
|
|
*/
|
30 |
|
|
this.initTargetModel = function(toolRef) {
|
31 |
|
|
/** The model this tool will update. */
|
32 |
|
|
var targetModel = toolRef.toolNode.selectSingleNode("mb:targetModel");
|
33 |
|
|
if (targetModel) {
|
34 |
|
|
var targetModelName = targetModel.firstChild.nodeValue;
|
35 |
|
|
toolRef.targetModel = eval("config.objects."+targetModelName);
|
36 |
|
|
if (!toolRef.targetModel) alert("error finding targetModel:"+targetModelName+" for tool:"+toolRef.id);
|
37 |
|
|
} else {
|
38 |
|
|
toolRef.targetModel = toolRef.model;
|
39 |
|
|
}
|
40 |
|
|
}
|
41 |
|
|
this.model.addListener( "init", this.initTargetModel, this );
|
42 |
|
|
|
43 |
|
|
/**
|
44 |
|
|
* Initialize the mouseHandler property to point to the object. This happens
|
45 |
|
|
* as an init listener to ensure that the referenced model has been created.
|
46 |
|
|
* @param toolRef Pointer to this object.
|
47 |
|
|
*/
|
48 |
|
|
this.initMouseHandler = function(toolRef) {
|
49 |
|
|
/** Mouse handler which this tool will register listeners with. */
|
50 |
|
|
var mouseHandler = toolRef.toolNode.selectSingleNode("mb:mouseHandler");
|
51 |
|
|
if (mouseHandler) {
|
52 |
|
|
toolRef.mouseHandler = eval("config.objects." + mouseHandler.firstChild.nodeValue);
|
53 |
|
|
if (!toolRef.mouseHandler) {
|
54 |
|
|
alert("error finding mouseHandler:"+mouseHandler.firstChild.nodeValue+" for tool:"+toolRef.id);
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
}
|
58 |
|
|
this.model.addListener( "init", this.initMouseHandler, this );
|
59 |
|
|
|
60 |
|
|
//tools enabled by default; can set to false in config for initial loading
|
61 |
|
|
this.enabled = true;
|
62 |
|
|
var enabled = toolNode.selectSingleNode("mb:enabled");
|
63 |
|
|
if (enabled) this.enabled = eval(enabled.firstChild.nodeValue);
|
64 |
|
|
}
|