forked from extnet/Ext.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractSelectionModel.cs
More file actions
465 lines (420 loc) · 17.2 KB
/
AbstractSelectionModel.cs
File metadata and controls
465 lines (420 loc) · 17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/********
* @version : 2.1.1 - Ext.NET Pro License
* @author : Ext.NET, Inc. http://www.ext.net/
* @date : 2012-12-10
* @copyright : Copyright (c) 2007-2012, Ext.NET, Inc. (http://www.ext.net/). All rights reserved.
* @license : See license.txt and http://www.ext.net/license/.
********/
using System;
using System.ComponentModel;
using System.Text;
using Ext.Net.Utilities;
namespace Ext.Net
{
/// <summary>
/// Tracks what records are currently selected in a databound component.
/// This is an abstract class and is not meant to be directly used. Databound UI widgets such as Grid and Tree should subclass Ext.selection.Model and provide a way to binding to the component.
/// The abstract methods onSelectChange and onLastFocusChanged should be implemented in these subclasses to update the UI widget.
/// </summary>
[Meta]
[Description("Tracks what records are currently selected in a databound component.")]
public abstract partial class AbstractSelectionModel : LazyObservable
{
/// <summary>
///
/// </summary>
[Category("0. About")]
[Description("")]
[DefaultValue("")]
[ConfigOption]
public virtual string SelType
{
get
{
return "";
}
}
/// <summary>
///
/// </summary>
[Description("")]
protected internal override bool IsIdRequired
{
get
{
return !this.IsGeneratedID || !(this.IsSelfRender || this.IsPageSelfRender || this.IsDynamic || this.IsMVC) || this.ForceIdRendering;
}
}
/// <summary>
/// Allow users to deselect a record in a DataView, List or Grid. Only applicable when the SelectionModel's mode is 'SINGLE'. Defaults to false.
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(false)]
[Description("Allow users to deselect a record in a DataView, List or Grid. Only applicable when the SelectionModel's mode is 'SINGLE'. Defaults to false.")]
public virtual bool AllowDeselect
{
get
{
return this.State.Get<bool>("AllowDeselect", false);
}
set
{
this.State.Set("AllowDeselect", value);
}
}
/// <summary>
/// Prune records when they are removed from the store from the selection.
/// </summary>
[Meta]
[ConfigOption]
[DefaultValue(true)]
[Description("Prune records when they are removed from the store from the selection.")]
public virtual bool PruneRemoved
{
get
{
return this.State.Get<bool>("PruneRemoved", true);
}
set
{
this.State.Set("PruneRemoved", value);
}
}
/// <summary>
/// Mode of selection. Valid values are:
///
/// SINGLE - Only allows selecting one item at a time. Use allowDeselect to allow deselecting that item. This is the default.
/// SIMPLE - Allows simple selection of multiple items one-by-one. Each click in grid will either select or deselect an item.
/// MULTI - Allows complex selection of multiple items using Ctrl and Shift keys.
/// </summary>
[Meta]
[DirectEventUpdate(MethodName="SetSelectionMode")]
[ConfigOption(JsonMode.ToLower)]
[DefaultValue(SelectionMode.Single)]
[NotifyParentProperty(true)]
[Description("Modes of selection. Valid values are SINGLE, SIMPLE, and MULTI. Defaults to 'SINGLE'")]
public virtual SelectionMode Mode
{
get
{
return this.State.Get<SelectionMode>("Mode", SelectionMode.Single);
}
set
{
this.State.Set("Mode", value);
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected override void PagePreLoad(object sender, EventArgs e)
{
if (this is IXPostBackDataHandler && !this.IsDynamic && (ExtNet.IsAjaxRequest || (this.Page != null && this.Page.IsPostBack)))
{
var ctrl = this as IXPostBackDataHandler;
if (ctrl != null && !ctrl.HasLoadPostData)
{
var result = ctrl.LoadPostData(this.ConfigID, this.Context.Request.Params);
if (result)
{
ctrl.RaisePostDataChangedEvent();
}
}
}
base.PagePreLoad(sender, e);
}
/* Public Methods
-----------------------------------------------------------------------------------------------*/
private JRawValue GetModelById(object[] ids)
{
StringBuilder sb = new StringBuilder();
sb.Append("[");
foreach (object id in ids)
{
sb.Append("{0}.store.getById({1})".FormatWith(this.ClientID, JSON.Serialize(id)));
sb.Append(",");
}
if (ids.Length > 0)
{
sb.Remove(sb.Length - 1, 1);
}
sb.Append("]");
return new JRawValue(sb.ToString());
}
private JRawValue GetModelById(object id)
{
return new JRawValue("{0}.store.getById({1})".FormatWith(this.ClientID, JSON.Serialize(id)));
}
/// <summary>
/// Deselects a record instance by record instance or index.
/// </summary>
/// <param name="index">Record index</param>
/// <param name="suppressEvent">Set to false to not fire a deselect event</param>
public void Deselect(int index, bool suppressEvent)
{
this.Call("deselect", index, suppressEvent);
}
/// <summary>
/// Deselects a record instance by record instance or index.
/// </summary>
/// <param name="index">Record index</param>
public void Deselect(int index)
{
this.Call("deselect", index);
}
/// <summary>
/// Deselects a record instance by record instance or index.
/// </summary>
/// <param name="id">Record id</param>
public void Deselect(object id)
{
this.Call("deselect", this.GetModelById(id));
}
/// <summary>
/// Deselects a record instance by record instance or index.
/// </summary>
/// <param name="record">Record id</param>
public void Deselect(ModelProxy record)
{
this.Call("deselect", record.ModelInstance);
}
/// <summary>
/// Deselects a record instance by record instance or index.
/// </summary>
/// <param name="id">Record id</param>
/// <param name="suppressEvent">Set to false to not fire a deselect event</param>
public void Deselect(object id, bool suppressEvent)
{
this.Call("deselect", this.GetModelById(id), suppressEvent);
}
/// <summary>
/// Deselects a record instance by record instance or index.
/// </summary>
/// <param name="ids">Record id</param>
public void Deselect(object[] ids)
{
this.Call("deselect", this.GetModelById(ids));
}
/// <summary>
/// Deselects a record instance by record instance or index.
/// </summary>
/// <param name="ids">Record id</param>
/// <param name="suppressEvent">Set to false to not fire a deselect event</param>
public void Deselect(object[] ids, bool suppressEvent)
{
this.Call("deselect", this.GetModelById(ids), suppressEvent);
}
/// <summary>
/// Deselects a record instance by record instance or index.
/// </summary>
/// <param name="record">Record id</param>
/// <param name="suppressEvent">Set to true to not fire a deselect event</param>
public void Deselect(ModelProxy record, bool suppressEvent)
{
this.Call("deselect", record.ModelInstance, suppressEvent);
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="index">Record index</param>
/// <param name="keepExisting"></param>
/// <param name="suppressEvent">Set to false to not fire a select event</param>
public void Select(int index, bool keepExisting, bool suppressEvent)
{
this.Call("select", index, keepExisting, suppressEvent);
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="index">Record index</param>
/// <param name="keepExisting"></param>
public void Select(int index, bool keepExisting)
{
this.Call("select", index, keepExisting);
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="index">Record index</param>
public void Select(int index)
{
this.Call("select", index);
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="record">record</param>
/// <param name="keepExisting"></param>
/// <param name="suppressEvent">Set to false to not fire a Select event</param>
public void Select(ModelProxy record, bool keepExisting, bool suppressEvent)
{
this.Call("select", record, keepExisting, suppressEvent);
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="record">An array of record indexes</param>
/// <param name="keepExisting"></param>
public void Select(ModelProxy record, bool keepExisting)
{
this.Call("select", record, keepExisting);
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="record">An array of record indexes</param>
public void Select(ModelProxy record)
{
this.Call("select", record);
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="id">Record id</param>
public void Select(object id)
{
this.Call("select", this.GetModelById(id));
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="id">Record id</param>
/// <param name="keepExisting"></param>
public void Select(object id, bool keepExisting)
{
this.Call("select", this.GetModelById(id), keepExisting);
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="id">Record id</param>
/// <param name="keepExisting"></param>
/// <param name="suppressEvent">Set to false to not fire a Select event</param>
public void Select(object id, bool keepExisting, bool suppressEvent)
{
this.Call("select", this.GetModelById(id), keepExisting, suppressEvent);
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="ids">Record id</param>
public void Select(object[] ids)
{
this.Call("select", this.GetModelById(ids));
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="ids">Record id</param>
/// <param name="keepExisting"></param>
public void Select(object[] ids, bool keepExisting)
{
this.Call("select", this.GetModelById(ids), keepExisting);
}
/// <summary>
/// Selects a record instance by record instance or index.
/// </summary>
/// <param name="ids">Record id</param>
/// <param name="keepExisting"></param>
/// <param name="suppressEvent">Set to false to not fire a Select event</param>
public void Select(object[] ids, bool keepExisting, bool suppressEvent)
{
this.Call("select", this.GetModelById(ids), keepExisting, suppressEvent);
}
/// <summary>
/// Selects a range of rows if the selection model is not locked. All rows in between startRow and endRow are also selected.
/// </summary>
/// <param name="startRowIndex">The record or index of the first row in the range</param>
/// <param name="endRowIndex">The record or index of the last row in the range</param>
/// <param name="keepExisting">(optional) True to retain existing selections</param>
public void SelectRange(int startRowIndex, int endRowIndex, bool keepExisting)
{
this.Call("selectRange", startRowIndex, endRowIndex, keepExisting);
}
/// <summary>
/// Selects a range of rows if the selection model is not locked. All rows in between startRow and endRow are also selected.
/// </summary>
/// <param name="startRowIndex">The record or index of the first row in the range</param>
/// <param name="endRowIndex">The record or index of the last row in the range</param>
public void SelectRange(int startRowIndex, int endRowIndex)
{
this.Call("selectRange", startRowIndex, endRowIndex);
}
/// <summary>
/// Selects a range of rows if the selection model is not locked. All rows in between startRow and endRow are also selected.
/// </summary>
/// <param name="startRowId">The record or index of the first row in the range</param>
/// <param name="endRowId">The record or index of the last row in the range</param>
/// <param name="keepExisting">(optional) True to retain existing selections</param>
public void SelectRange(object startRowId, object endRowId, bool keepExisting)
{
this.Call("selectRange", this.GetModelById(startRowId), this.GetModelById(endRowId), keepExisting);
}
/// <summary>
/// Selects a range of rows if the selection model is not locked. All rows in between startRow and endRow are also selected.
/// </summary>
/// <param name="startRowId">The record or index of the first row in the range</param>
/// <param name="endRowId">The record or index of the last row in the range</param>
public void SelectRange(object startRowId, object endRowId)
{
this.Call("selectRange", this.GetModelById(startRowId), this.GetModelById(endRowId));
}
/// <summary>
/// Locks the current selection and disables any changes from happening to the selection.
/// </summary>
/// <param name="locked">True to lock, false to unlock.</param>
public void SetLocked(bool locked)
{
this.Call("setLocked", locked);
}
/// <summary>
/// Sets the current selectionMode. SINGLE, MULTI or SIMPLE.
/// </summary>
/// <param name="mode">'SINGLE', 'MULTI' or 'SIMPLE'.</param>
public void SetSelectionMode(SelectionMode mode)
{
this.Call("setSelectionMode", mode.ToString().ToLowerInvariant());
}
/// <summary>
/// Selects all records in the view.
/// </summary>
/// <param name="suppressEvent">True to suppress any select events</param>
public void SelectAll(bool suppressEvent)
{
this.Call("selectAll", suppressEvent);
}
/// <summary>
/// Selects all records in the view.
/// </summary>
public void SelectAll()
{
this.Call("selectAll");
}
/// <summary>
/// Deselects all records in the view.
/// </summary>
public void DeselectAll()
{
this.Call("deselectAll");
}
/// <summary>
/// Deselects all records in the view.
/// </summary>
/// <param name="suppressEvent">True to suppress any deselect events</param>
public void DeselectAll(bool suppressEvent)
{
this.Call("deselectAll", suppressEvent);
}
/// <summary>
///
/// </summary>
public abstract void UpdateSelection();
/// <summary>
///
/// </summary>
public abstract void ClearSelection();
}
}