1
|
/*
|
2
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
3
|
$Id: ToolBase.js 3881 2008-02-27 15:41:07Z gjvoosten $
|
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 = getNodeValue(id);
|
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 = getNodeValue(targetModel);
|
35
|
//toolRef.targetModel = eval("config.objects."+targetModelName);
|
36
|
toolRef.targetModel = window.config.objects[targetModelName];
|
37
|
if (!toolRef.targetModel) alert(mbGetMessage("noTargetModelTool", targetModelName, toolRef.id));
|
38
|
} else {
|
39
|
toolRef.targetModel = toolRef.model;
|
40
|
}
|
41
|
}
|
42
|
this.model.addListener( "init", this.initTargetModel, this );
|
43
|
|
44
|
/**
|
45
|
* Initialize the mouseHandler property to point to the object. This happens
|
46
|
* as an init listener to ensure that the referenced model has been created.
|
47
|
* @param toolRef Pointer to this object.
|
48
|
*/
|
49
|
this.initMouseHandler = function(toolRef) {
|
50
|
/** Mouse handler which this tool will register listeners with. */
|
51
|
var mouseHandler = toolRef.toolNode.selectSingleNode("mb:mouseHandler");
|
52
|
if (mouseHandler) {
|
53
|
toolRef.mouseHandler = window.config.objects[getNodeValue(mouseHandler)];
|
54
|
if (!toolRef.mouseHandler) {
|
55
|
alert(mbGetMessage("noMouseHandlerTool", getNodeValue(mouseHandler), toolRef.id));
|
56
|
}
|
57
|
}
|
58
|
}
|
59
|
this.model.addListener( "init", this.initMouseHandler, this );
|
60
|
|
61
|
/**
|
62
|
* Convenient access to Mapbuilder.getProperty
|
63
|
* @param property property to get
|
64
|
* @param default value to use if property is not set
|
65
|
* @return the value for the property
|
66
|
*/
|
67
|
this.getProperty = function(property, defaultValue) {
|
68
|
return Mapbuilder.getProperty(toolNode, property, defaultValue);
|
69
|
}
|
70
|
|
71
|
//tools enabled by default; can set to false in config for initial loading
|
72
|
this.enabled = Mapbuilder.parseBoolean(this.getProperty("mb:enabled", true));
|
73
|
}
|