2
* Copyright (C) 2007-2008 Camptocamp
4
* This file is part of MapFish Client
6
* MapFish Client is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* MapFish Client is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with MapFish Client. If not, see <http://www.gnu.org/licenses/>.
21
* @requires OpenLayers/Control/SelectFeature.js
24
Ext.namespace('mapfish.widgets', 'mapfish.widgets.data');
27
* Class: mapfish.widgets.data.GridRowFeatureMediator
28
* A mediator for selecting feature on grid row selection and
33
* var mediator = mapfish.widgets.data.GridRowFeatureMediator({
35
* selectControl: selectFeatureControl
41
* Constructor: mapfish.widgets.data.GridRowFeatureMediator
42
* Create an instance of mapfish.widgets.data.GridRowFeatureMediator.
48
* {<mapfish.widgets.data.GridRowFeatureMediator>}
50
mapfish.widgets.data.GridRowFeatureMediator = function(config) {
51
Ext.apply(this, config);
53
OpenLayers.Console.error(
54
"no Ext.grid.GridPanel provided");
57
if (!this.selectControl ||
58
this.selectControl.CLASS_NAME != "OpenLayers.Control.SelectFeature") {
59
OpenLayers.Console.error(
60
"no OpenLayers.Control.SelectFeature provided");
63
this.selectModel = this.grid.getSelectionModel();
64
if (this.autoActivate) {
69
mapfish.widgets.data.GridRowFeatureMediator.prototype = {
71
* APIProperty: autoActivate
72
* {Boolean} The instance is activated at creation time, defaults
78
* APIProperty: selectControl
79
* {<OpenLayers.Control.SelectFeature>} The select feature control.
85
* {Ext.grid.GridPanel} The grid panel.
90
* Property: selectModel
91
* {Ext.grid.RowSelectionModel} The row selection model attached to
103
* APIMethod: activate
104
* Activate the mediator.
107
* {Boolean} - False if the mediator was already active, true
110
activate: function() {
112
this.featureEventsOn();
121
* APIMethod: deactivate
122
* Deactivate the mediator.
125
* {Boolean} - False if the mediator was already deactive, true
128
deactivate: function() {
130
this.featureEventsOff();
139
* Method: featureSelected
142
* o - {Object} An object with a feature property referencing
143
* the selected feature.
145
featureSelected: function(o) {
146
var r = this.grid.store.getById(o.feature.id);
149
this.selectModel.selectRecords([r]);
155
* Method: featureUnselected
158
* o - {Object} An object with a feature property referencing
159
* the selected feature.
161
featureUnselected: function(o) {
162
var r = this.grid.store.getById(o.feature.id);
165
this.selectModel.deselectRow(this.grid.store.indexOf(r));
171
* Method: rowSelected
174
* s - {Ext.grid.RowSelectModel} The row select model.
175
* i - {Number} The row index.
176
* r - {Ext.data.Record} The record.
178
rowSelected: function(s, i, r) {
179
var f = this.selectControl.layer.getFeatureById(r.id);
181
this.featureEventsOff();
182
this.selectControl.select(f);
183
this.featureEventsOn();
188
* Method: rowDeselected
191
* s - {Ext.grid.RowSelectModel} The row select model.
192
* i - {Number} The row index.
193
* r - {Ext.data.Record} The record.
195
rowDeselected: function(s, i, r) {
196
var f = this.selectControl.layer.getFeatureById(r.id);
198
this.featureEventsOff();
199
this.selectControl.unselect(f);
200
this.featureEventsOn();
205
* Method: rowEventsOff
206
* Turn off the row events.
208
rowEventsOff: function() {
209
this.selectModel.un("rowselect", this.rowSelected, this);
210
this.selectModel.un("rowdeselect", this.rowDeselected, this);
214
* Method: rowEventsOn
215
* Turn on the row events.
217
rowEventsOn: function() {
218
this.selectModel.on("rowselect", this.rowSelected, this);
219
this.selectModel.on("rowdeselect", this.rowDeselected, this);
223
* Method: featureEventsOff
224
* Turn off the feature events.
226
featureEventsOff: function() {
227
this.selectControl.layer.events.un({
228
featureselected: this.featureSelected,
229
featureunselected: this.featureUnselected,
235
* Method: featureEventsOn
236
* Turn on the feature events.
238
featureEventsOn: function() {
239
this.selectControl.layer.events.on({
240
featureselected: this.featureSelected,
241
featureunselected: this.featureUnselected,