forked from extnet/Ext.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractTabPanel.cs
More file actions
610 lines (553 loc) · 20.6 KB
/
AbstractTabPanel.cs
File metadata and controls
610 lines (553 loc) · 20.6 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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/********
* @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.Web.UI;
namespace Ext.Net
{
/// <summary>
///
/// </summary>
[Meta]
[Description("")]
public abstract partial class AbstractTabPanel : AbstractPanel, IItems, IAutoPostBack, INoneContentable
{
/// <summary>
///
/// </summary>
/// <returns></returns>
public override bool HasLayout()
{
return true;
}
/// <summary>
/// The tab to activate initially. Either an ID, index or the tab component itself.
/// </summary>
[Meta]
[DefaultValue(null)]
[Browsable(false)]
[Description("The numeric index of the tab that should be initially activated on render.")]
public virtual AbstractComponent ActiveTab
{
get
{
if (this.ActiveTabIndex > this.Items.Count - 1)
{
return this.Items[this.Items.Count - 1];
}
return this.Items[this.ActiveTabIndex];
}
set
{
this.ActiveTabIndex = this.Items.IndexOf(value);
}
}
/// <summary>
/// The tab to activate initially. Either an ID, index or the tab component itself.
/// </summary>
[Meta]
[DirectEventUpdate(MethodName = "SetActiveTab")]
[Category("6. AbstractTabPanel")]
[DefaultValue(-1)]
[NotifyParentProperty(true)]
[Description("The numeric index of the tab that should be initially activated on render.")]
public virtual int ActiveTabIndex
{
get
{
return this.State.Get<int>("ActiveTabIndex", (this.Items.Count == 0) ? -1 : 0);
}
set
{
this.State.Set("ActiveTabIndex", value);
this.CheckTabVisible();
}
}
/// <summary>
///
/// </summary>
[ConfigOption("activeTab")]
[DefaultValue(-1)]
protected internal int VisibleIndex
{
get
{
int i = this.ActiveTabIndex;
int correction = 0;
for (int ind = 0; ind < Math.Min(i, this.Items.Count); ind++)
{
if (!this.Items[ind].Visible || this.Items[ind].Hidden)
{
correction++;
}
}
return i - correction;
}
}
internal bool HasVisibleTab
{
get
{
foreach (AbstractComponent item in this.Items)
{
if (item.Visible == true)
{
return true;
}
}
return false;
}
}
private void CheckTabVisible()
{
TabPanel tp = (TabPanel)this;
if (tp.AutoPostBack && tp.DeferredRender)
{
for (int i = 0; i < tp.Items.Count; i++)
{
if (!tp.Items[i].HasLayout() || (tp.Items[i].HasLayout() && tp.ActiveTabIndex == i))
{
tp.Items[i].ContentContainer.Visible = (tp.ActiveTabIndex == i);
}
foreach (Control control in tp.Items[i].Controls)
{
control.Visible = tp.ActiveTabIndex == i;
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.CheckTabVisible();
}
/// <summary>
/// True by default to defer the rendering of child items to the browsers DOM until a tab is activated. False will render all contained items as soon as the layout is rendered. If there is a significant amount of content or a lot of heavy controls being rendered into panels that are not displayed by default, setting this to true might improve performance.
/// The deferredRender property is internally passed to the layout manager for TabPanels (Ext.layout.container.Card) as its Ext.layout.container.Card.deferredRender configuration value.
/// Note: leaving deferredRender as true means that the content within an unactivated tab will not be available
/// Defaults to: true
/// </summary>
[Meta]
[ConfigOption]
[Category("6. AbstractTabPanel")]
[DefaultValue(true)]
[NotifyParentProperty(true)]
[Description("True by default to defer the rendering of child items to the browsers DOM until a tab is activated.")]
public virtual bool DeferredRender
{
get
{
return this.State.Get<bool>("DeferredRender", true);
}
set
{
this.State.Set("DeferredRender", value);
}
}
/// <summary>
/// The minimum width for a tab in the tabBar.
/// </summary>
[Meta]
[ConfigOption]
[Category("6. AbstractTabPanel")]
[DefaultValue(0)]
[NotifyParentProperty(true)]
[Description("The minimum width for a tab in the tabBar.")]
public virtual int MinTabWidth
{
get
{
return this.State.Get<int>("MinTabWidth", 0);
}
set
{
this.State.Set("MinTabWidth", value);
}
}
/// <summary>
/// The maximum width for each tab.
/// </summary>
[Meta]
[ConfigOption]
[Category("6. AbstractTabPanel")]
[DefaultValue(int.MaxValue)]
[NotifyParentProperty(true)]
[Description("The maximum width for each tab.")]
public virtual int MaxTabWidth
{
get
{
return this.State.Get<int>("MaxTabWidth", int.MaxValue);
}
set
{
this.State.Set("MaxTabWidth", value);
}
}
/// <summary>
/// True to not show the full background on the TabBar. Defaults to: false
/// </summary>
[Meta]
[ConfigOption]
[Category("6. AbstractTabPanel")]
[DefaultValue(false)]
[NotifyParentProperty(true)]
[Description("True to not show the full background on the TabBar. Defaults to: false")]
public bool Plain
{
get
{
return this.State.Get<bool>("Plain", false);
}
set
{
this.State.Set("Plain", value);
}
}
/// <summary>
///
/// </summary>
/// <param name="item"></param>
protected override void BeforeItemAdd(AbstractComponent item)
{
base.BeforeItemAdd(item);
item.ContentContainer.Attributes.Add("class", "x-hidden");
}
/// <summary>
/// The alignment of the Tabs (defaults to 'Left'). Other option includes 'Right'. Note that tab scrolling is only supported for TabAlign='Left'. Note that when 'Right', the Tabs will be rendered in reverse order.
/// </summary>
[Meta]
[ConfigOption("tabAlign", JsonMode.ToLower)]
[Category("6. AbstractTabPanel")]
[DefaultValue(TabAlign.Left)]
[NotifyParentProperty(true)]
[Description("The alignment of the Tabs (defaults to 'Left'). Other option includes 'Right'. Note that tab scrolling is only supported for TabAlign='Left'. Note that when 'Right', the Tabs will be rendered in reverse order.")]
public virtual TabAlign TabAlign
{
get
{
return this.State.Get<TabAlign>("TabAlign", TabAlign.Left);
}
set
{
this.State.Set("TabAlign", value);
}
}
private ItemsCollection<AbstractComponent> tabBar;
/// <summary>
/// Optional items for the internal Ext.tab.Bar. If present, this is passed straight through to the TabBar's constructor.
/// </summary>
[Meta]
[ConfigOption("tabBarItems", typeof(ItemCollectionJsonConverter))]
[Category("6. AbstractTabPanel")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("Optional items for the internal Ext.tab.Bar. If present, this is passed straight through to the TabBar's constructor.")]
public virtual ItemsCollection<AbstractComponent> TabBar
{
get
{
if (this.tabBar == null)
{
this.tabBar = new ItemsCollection<AbstractComponent>();
this.tabBar.BeforeItemAdd += this.BeforeItemAdd;
this.tabBar.AfterItemAdd += this.AfterItemAdd;
this.tabBar.AfterItemRemove += this.AfterItemRemove;
this.tabBar.SingleItemMode = false;
}
return this.tabBar;
}
}
/// <summary>
/// The class added to each child item of this TabPanel. Defaults to: "x-tabpanel-child"
/// </summary>
[Meta]
[ConfigOption]
[Category("6. AbstractTabPanel")]
[DefaultValue("")]
[NotifyParentProperty(true)]
[Description("The class added to each child item of this TabPanel. Defaults to: \"x-tabpanel-child\"")]
public virtual string ItemCls
{
get
{
return this.State.Get<string>("ItemCls", "");
}
set
{
this.State.Set("ItemCls", value);
}
}
/// <summary>
/// True to instruct each Panel added to the TabContainer to not render its header element. This is to ensure that the title of the panel does not appear twice. Defaults to: true
/// </summary>
[Meta]
[ConfigOption]
[Category("6. AbstractTabPanel")]
[DefaultValue(true)]
[NotifyParentProperty(true)]
[Description("True to instruct each Panel added to the TabContainer to not render its header element. This is to ensure that the title of the panel does not appear twice. Defaults to: true")]
public virtual bool RemovePanelHeader
{
get
{
return this.State.Get<bool>("RemovePanelHeader", true);
}
set
{
this.State.Set("RemovePanelHeader", value);
}
}
/// <summary>
/// The position where the tab strip should be rendered. Can be top or bottom. Defaults to: "top"
/// </summary>
[Meta]
[ConfigOption(JsonMode.ToLower)]
[Category("6. AbstractTabPanel")]
[DefaultValue(TabPosition.Top)]
[NotifyParentProperty(true)]
[Description("The position where the tab strip should be rendered. Can be top or bottom. Defaults to: \"top\"")]
public virtual TabPosition TabPosition
{
get
{
return this.State.Get<TabPosition>("TabPosition", TabPosition.Top);
}
set
{
this.State.Set("TabPosition", value);
}
}
private MenuCollection defaultTabMenu;
/// <summary>
/// Default menu for all tabs
/// </summary>
[Meta]
[ConfigOption("defaultTabMenu", typeof(SingleItemCollectionJsonConverter))]
[Category("6. AbstractTabPanel")]
[NotifyParentProperty(true)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("Default menu for all tabs")]
public virtual MenuCollection DefaultTabMenu
{
get
{
if (this.defaultTabMenu == null)
{
this.defaultTabMenu = new MenuCollection();
this.defaultTabMenu.AfterItemAdd += this.AfterItemAdd;
this.defaultTabMenu.AfterItemRemove += this.AfterItemRemove;
}
return this.defaultTabMenu;
}
}
/// <summary>
/// Sets the specified tab as the active tab. This method fires the beforetabchange event which can return false to cancel the tab change.
/// </summary>
[Meta]
[Description("Sets the specified tab as the active tab. This method fires the beforetabchange event which can return false to cancel the tab change.")]
public virtual void SetActiveTab(int index)
{
int correction = 0;
for (int ind = 0; ind < Math.Min(index, this.Items.Count); ind++)
{
if (!this.Items[ind].Visible)
{
correction++;
}
}
this.Call("setActiveTab", index - correction);
}
/// <summary>
/// Sets the specified tab as the active tab. This method fires the beforetabchange event which can return false to cancel the tab change.
/// </summary>
[Meta]
[Description("Sets the specified tab as the active tab. This method fires the beforetabchange event which can return false to cancel the tab change.")]
public virtual void SetActiveTab(AbstractComponent item)
{
this.SetActiveTab(item.ConfigID);
}
/// <summary>
/// Sets the specified tab as the active tab. This method fires the beforetabchange event which can return false to cancel the tab change.
/// </summary>
/// <param name="id">The id.</param>
[Meta]
[Description("Sets the specified tab as the active tab. This method fires the beforetabchange event which can return false to cancel the tab change.")]
public virtual void SetActiveTab(string id)
{
this.Call("setActiveTab", id);
}
/// <summary>
/// Sets the last tab as the active tab
/// </summary>
[Meta]
public virtual void SetLastTabAsActive()
{
this.Call("setLastTabAsActive");
}
/// <summary>
/// Sets the previous tab as the active tab
/// </summary>
[Meta]
public virtual void SetPreviousTabAsActive()
{
this.Call("setPreviousTabAsActive");
}
/// <summary>
/// Sets the next tab as the active tab
/// </summary>
[Meta]
public virtual void SetNextTabAsActive()
{
this.Call("setNextTabAsActive");
}
/* IAutoPostBack
-----------------------------------------------------------------------------------------------*/
/// <summary>
/// Gets or sets a value indicating whether the control state automatically posts back to the server when tab changed.
/// </summary>
[Meta]
[Category("Behavior")]
[DefaultValue(false)]
[NotifyParentProperty(true)]
[Description("Gets or sets a value indicating whether the control state automatically posts back to the server when tab changed.")]
public virtual bool AutoPostBack
{
get
{
return this.State.Get<bool>("AutoPostBack", false);
}
set
{
this.State.Set("AutoPostBack", value);
}
}
/// <summary>
///
/// </summary>
[Meta]
[DefaultValue("beforetabchange")]
[Description("")]
public virtual string PostBackEvent
{
get
{
return this.State.Get<string>("PostBackEvent", "beforetabchange");
}
set
{
this.State.Set("PostBackEvent", value);
}
}
/// <summary>
/// Gets or sets a value indicating whether validation is performed when the control is set to validate when a postback occurs.
/// </summary>
[Meta]
[Category("Behavior")]
[DefaultValue(false)]
[NotifyParentProperty(true)]
[Description("Gets or sets a value indicating whether validation is performed when the control is set to validate when a postback occurs.")]
public virtual bool CausesValidation
{
get
{
return this.State.Get<bool>("CausesValidation", false);
}
set
{
this.State.Set("CausesValidation", value);
}
}
/// <summary>
/// Gets or Sets the Controls ValidationGroup
/// </summary>
[Meta]
[Category("Behavior")]
[DefaultValue("")]
[NotifyParentProperty(true)]
[Description("Gets or Sets the Controls ValidationGroup")]
public virtual string ValidationGroup
{
get
{
return this.State.Get<string>("ValidationGroup", "");
}
set
{
this.State.Set("ValidationGroup", value);
}
}
public void HideTab(string id)
{
if (id.Contains("."))
{
this.Call("closeTab", JRawValue.From(id), "hide");
}
else
{
this.Call("closeTab", id, "hide");
}
}
public void HideTab(AbstractContainer tab)
{
this.Call("closeTab", JRawValue.From(tab.ClientID), "hide");
}
public void HideTab(int index)
{
this.Call("closeTab", index, "hide");
}
public void CloseTab(string id, CloseAction action)
{
this.Call("closeTab", JRawValue.From(id), action.ToString().ToLowerInvariant());
}
public void CloseTab(AbstractContainer tab, CloseAction action)
{
this.Call("closeTab", JRawValue.From(tab.ClientID), action.ToString().ToLowerInvariant());
}
public void CloseTab(int index, CloseAction action)
{
this.Call("closeTab", index, action.ToString().ToLowerInvariant());
}
public void ShowTab(string id)
{
this.Call("addTab", id.Contains(".") ? JRawValue.From(id) : JRawValue.From("Ext.getCmp('" + id + "')"), false);
}
public void ShowTab(string id, int index)
{
this.Call("addTab", id.Contains(".") ? JRawValue.From(id) : JRawValue.From("Ext.getCmp('" + id + "')"), index, false);
}
public void ShowTab(string id, int index, bool activate)
{
this.Call("addTab", id.Contains(".") ? JRawValue.From(id) : JRawValue.From("Ext.getCmp('" + id + "')"), index, activate);
}
public void ShowTab(string id, bool activate)
{
this.Call("addTab", id.Contains(".") ? JRawValue.From(id) : JRawValue.From("Ext.getCmp('" + id + "')"), activate);
}
public void ShowTab(AbstractContainer tab)
{
this.Call("addTab", JRawValue.From(tab.ClientID), false);
}
public void ShowTab(AbstractContainer tab, int index)
{
this.Call("addTab", JRawValue.From(tab.ClientID), index, false);
}
public void ShowTab(AbstractContainer tab, int index, bool activate)
{
this.Call("addTab", JRawValue.From(tab.ClientID), index, activate);
}
public void ShowTab(AbstractContainer tab, bool activate)
{
this.Call("addTab", JRawValue.From(tab.ClientID), activate);
}
}
}