~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/admin/.svn/text-base/FileTypeFilter.ascx.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
6
 
 | This program is free software; you can redistribute it and/or
7
 
 | modify it under the terms of version 2 of the GNU General Public License as
8
 
 | published by the Free Software Foundation.
9
 
 |
10
 
 | This program is distributed in the hope that it will be useful,
11
 
 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 | GNU General Public License for more details.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com
20
 
 |
21
 
 | Author: Mike Lasky (mlasky@novell.com)
22
 
 |***************************************************************************/
23
 
 
24
 
namespace Novell.iFolderWeb.Admin
25
 
{
26
 
        using System;
27
 
        using System.Collections;
28
 
        using System.Data;
29
 
        using System.Drawing;
30
 
        using System.Resources;
31
 
        using System.Web;
32
 
        using System.Web.UI;
33
 
        using System.Web.UI.WebControls;
34
 
        using System.Web.UI.HtmlControls;
35
 
 
36
 
        /// <summary>
37
 
        ///             Summary description for FileTypeFilter.
38
 
        /// </summary>
39
 
        public class FileTypeFilter : System.Web.UI.UserControl
40
 
        {
41
 
                #region Class Members
42
 
 
43
 
                /// <summary>
44
 
                /// Resource Manager
45
 
                /// </summary>
46
 
                private ResourceManager rm;
47
 
 
48
 
 
49
 
                /// <summary>
50
 
                /// File type filter control.
51
 
                /// </summary>
52
 
                protected Label Title;
53
 
 
54
 
 
55
 
                /// <summary>
56
 
                /// Non system file type policy controls.
57
 
                /// </summary>
58
 
                protected DataGrid FileTypeList;
59
 
 
60
 
                /// <summary>
61
 
                /// Table footer control.
62
 
                /// </summary>
63
 
                protected ListFooter FileTypeListFooter;
64
 
 
65
 
 
66
 
                /// <summary>
67
 
                /// Button control.
68
 
                /// </summary>
69
 
                protected Button DeleteButton;
70
 
 
71
 
                /// <summary>
72
 
                /// Button control.
73
 
                /// </summary>
74
 
                protected Button AddButton;
75
 
 
76
 
                /// <summary>
77
 
                /// Button control.
78
 
                /// </summary>
79
 
                protected Button AllowButton;
80
 
 
81
 
                /// <summary>
82
 
                /// Button control.
83
 
                /// </summary>
84
 
                protected Button DenyButton;
85
 
 
86
 
 
87
 
                /// <summary>
88
 
                /// Control that allows a new file type to be added.
89
 
                /// </summary>
90
 
                protected TextBox NewFileTypeName;
91
 
 
92
 
 
93
 
                /// <summary>
94
 
                /// Controls that selects file type entries.
95
 
                /// </summary>
96
 
                protected CheckBox AllFilesCheckBox;
97
 
 
98
 
 
99
 
                /// <summary>
100
 
                /// Event that notifies consumer that the filter list has changed.
101
 
                /// </summary>
102
 
                public event EventHandler ListChanged = null;
103
 
 
104
 
                #endregion
105
 
 
106
 
                #region Properties
107
 
 
108
 
                /// <summary>
109
 
                /// Gets or sets the current file offset.
110
 
                /// </summary>
111
 
                private int CurrentFileOffset
112
 
                {
113
 
                        get { return ( int )ViewState[ "CurrentFileOffset" ]; }
114
 
                        set { ViewState[ "CurrentFileOffset" ] = value; }
115
 
                }
116
 
 
117
 
                /// <summary>
118
 
                /// Gets or sets the file type data source value.
119
 
                /// </summary>
120
 
                private Hashtable FileTypeSource
121
 
                {
122
 
                        get { return ViewState[ "FileTypeSource" ] as Hashtable; }
123
 
                        set { ViewState[ "FileTypeSource" ] = value; }
124
 
                }
125
 
 
126
 
                /// <summary>
127
 
                /// Returns true if any FileType source entries are checked.
128
 
                /// </summary>
129
 
                private bool HasCheckedEntries
130
 
                {
131
 
                        get
132
 
                        {
133
 
                                bool isChecked = false;
134
 
                                foreach( FileTypeInfo fti in FileTypeSource.Values )
135
 
                                {
136
 
                                        if ( fti.IsChecked )
137
 
                                        {
138
 
                                                isChecked = true;
139
 
                                                break;
140
 
                                        }
141
 
                                }
142
 
 
143
 
                                return isChecked;
144
 
                        }
145
 
                }
146
 
 
147
 
                /// <summary>
148
 
                /// Returns true if any FileType source entries are disallowed.
149
 
                /// </summary>
150
 
                private bool HasDisallowedEntries
151
 
                {
152
 
                        get
153
 
                        {
154
 
                                bool isDisallowed = false;
155
 
                                foreach( FileTypeInfo fti in FileTypeSource.Values )
156
 
                                {
157
 
                                        if ( fti.IsChecked && !fti.IsAllowed )
158
 
                                        {
159
 
                                                isDisallowed = true;
160
 
                                                break;
161
 
                                        }
162
 
                                }
163
 
 
164
 
                                return isDisallowed;
165
 
                        }
166
 
                }
167
 
 
168
 
                /// <summary>
169
 
                /// Returns true if any FileType source entries are allowed.
170
 
                /// </summary>
171
 
                private bool HasAllowedEntries
172
 
                {
173
 
                        get
174
 
                        {
175
 
                                bool isAllowed = false;
176
 
                                foreach( FileTypeInfo fti in FileTypeSource.Values )
177
 
                                {
178
 
                                        if ( fti.IsChecked && fti.IsAllowed )
179
 
                                        {
180
 
                                                isAllowed = true;
181
 
                                                break;
182
 
                                        }
183
 
                                }
184
 
 
185
 
                                return isAllowed;
186
 
                        }
187
 
                }
188
 
 
189
 
                /// <summary>
190
 
                /// Gets or sets the total number of files contained in
191
 
                /// the exclude list.
192
 
                /// </summary>
193
 
                private int TotalFiles
194
 
                {
195
 
                        get { return ( int )ViewState[ "TotalFiles" ]; }
196
 
                        set { ViewState[ "TotalFiles" ] = value; }
197
 
                }
198
 
 
199
 
                #endregion
200
 
 
201
 
                #region Private Methods
202
 
        
203
 
                /// <summary>
204
 
                /// Creates the file type list view for the web control.
205
 
                /// </summary>
206
 
                private DataView CreateFileTypeListView()
207
 
                {
208
 
                        DataTable dt = new DataTable();
209
 
                        DataRow dr;
210
 
 
211
 
                        dt.Columns.Add( new DataColumn( "VisibleField", typeof( bool ) ) );
212
 
                        dt.Columns.Add( new DataColumn( "FileRegExField", typeof( string ) ) );
213
 
                        dt.Columns.Add( new DataColumn( "AllowedField", typeof( string ) ) );
214
 
                        dt.Columns.Add( new DataColumn( "FileNameField", typeof( string ) ) );
215
 
                        dt.Columns.Add( new DataColumn( "EnabledField", typeof( bool ) ) );
216
 
 
217
 
                        // Fill the data table from the saved selected member list.
218
 
                        Hashtable ht = FileTypeSource;
219
 
                        FileTypeInfo[] ftInfoList = new FileTypeInfo[ ht.Count ];
220
 
                        TotalFiles = ht.Count;
221
 
 
222
 
                        // Copy the Values to the array so that they can be sorted.
223
 
                        ht.Values.CopyTo( ftInfoList, 0 );
224
 
                        Array.Sort( ftInfoList );
225
 
 
226
 
                        for ( int i = 0; i < ftInfoList.Length; ++i )
227
 
                        {
228
 
                                // Don't add until at the right display offset.
229
 
                                if ( i >= CurrentFileOffset )
230
 
                                {
231
 
                                        // Don't add more than one page worth of data.
232
 
                                        if ( i < ( CurrentFileOffset + FileTypeList.PageSize ) )
233
 
                                        {
234
 
                                                dr = dt.NewRow();
235
 
                                                dr[ 0 ] = true;
236
 
                                                dr[ 1 ] = ftInfoList[ i ].RegExFileName;
237
 
                                                dr[ 2 ] = GetString( ftInfoList[ i ].IsAllowed ? "ALLOW" : "DENY" );
238
 
                                                dr[ 3 ] = ftInfoList[ i ].FriendlyFileName;
239
 
                                                dr[ 4 ] = ftInfoList[ i ].IsEnabled;
240
 
 
241
 
                                                dt.Rows.Add( dr );
242
 
                                        }
243
 
                                        else
244
 
                                        {
245
 
                                                break;
246
 
                                        }
247
 
                                }
248
 
                        }
249
 
 
250
 
                        // If the page size is not full, finish it with empty entries.
251
 
                        for ( int i = dt.Rows.Count; i < FileTypeList.PageSize; ++i )
252
 
                        {
253
 
                                dr = dt.NewRow();
254
 
                                dr[ 0 ] = false;
255
 
                                dr[ 1 ] = String.Empty;
256
 
                                dr[ 2 ] = String.Empty;
257
 
                                dr[ 3 ] = String.Empty;
258
 
                                dr[ 4 ] = false;
259
 
 
260
 
                                dt.Rows.Add( dr );
261
 
                        }
262
 
 
263
 
                        // Build the data view from the table.
264
 
                        return new DataView( dt );
265
 
                }
266
 
 
267
 
                /// <summary>
268
 
                /// Creates a stateful list of file type filters.
269
 
                /// </summary>
270
 
                /// <param name="policy">User policy object</param>
271
 
                /// <returns>A hashtable containing the file type filters.</returns>
272
 
                private Hashtable CreateFileTypeSource( UserPolicy policy )
273
 
                {
274
 
                        // Keep the state in a hashtable.
275
 
                        Hashtable ht = new Hashtable();
276
 
                        foreach( string s in policy.FileTypesExcludesEffective )
277
 
                        {
278
 
                                ht[ s ] = new FileTypeInfo( 
279
 
                                        s, 
280
 
                                        Utils.ConvertFromRegEx( s ), 
281
 
                                        IsAllowed( policy.FileTypesIncludes, s ), 
282
 
                                        true );
283
 
                        }
284
 
                        foreach( string s in policy.FileTypesIncludes )
285
 
                        {
286
 
                                ht[ s ] = new FileTypeInfo( 
287
 
                                        s, 
288
 
                                        Utils.ConvertFromRegEx( s ), 
289
 
                                        true, 
290
 
                                        true );
291
 
                        }
292
 
 
293
 
                        return ht;
294
 
                }
295
 
 
296
 
                /// <summary>
297
 
                /// Creates a stateful list of file type filters.
298
 
                /// </summary>
299
 
                /// <param name="policy">iFolder policy object</param>
300
 
                /// <returns>A hashtable containing the file type filters.</returns>
301
 
                private Hashtable CreateFileTypeSource( iFolderPolicy policy )
302
 
                {
303
 
                        // Keep the state in a hashtable.
304
 
                        Hashtable ht = new Hashtable();
305
 
                        foreach( string s in policy.FileTypesExcludesEffective )
306
 
                        {
307
 
                                ht[ s ] = new FileTypeInfo( 
308
 
                                        s, 
309
 
                                        Utils.ConvertFromRegEx( s ), 
310
 
                                        IsAllowed( policy.FileTypesIncludesEffective, s ), 
311
 
                                        false );
312
 
                        }
313
 
 
314
 
                        foreach( string s in policy.FileTypesExcludes )
315
 
                        {
316
 
                                ht[ s ] = new FileTypeInfo( 
317
 
                                        s, 
318
 
                                        Utils.ConvertFromRegEx( s ), 
319
 
                                        false, 
320
 
                                        true );
321
 
                        }
322
 
 
323
 
                        return ht;
324
 
                }
325
 
 
326
 
                /// <summary>
327
 
                /// Creates a stateful list of file type filters.
328
 
                /// </summary>
329
 
                /// <param name="policy">System policy object</param>
330
 
                /// <returns>A hashtable containing the file type filters.</returns>
331
 
                private Hashtable CreateFileTypeSource( SystemPolicy policy )
332
 
                {
333
 
                        // Keep the state in a hashtable.
334
 
                        Hashtable ht = new Hashtable();
335
 
                        foreach( string s in policy.FileTypesExcludes )
336
 
                        {
337
 
                                ht[ s ] = new FileTypeInfo( s, Utils.ConvertFromRegEx( s ), false, true );
338
 
                        }
339
 
 
340
 
                        return ht;
341
 
                }
342
 
 
343
 
                /// <summary>
344
 
                /// Checks if the specified file name is already in the list.
345
 
                /// </summary>
346
 
                /// <param name="fileName"></param>
347
 
                /// <returns>True if the specified file name is already in the list.</returns>
348
 
                private bool FileTypeExists( string fileName )
349
 
                {
350
 
                        bool exists = false;
351
 
 
352
 
                        Hashtable ht = FileTypeSource;
353
 
                        foreach( FileTypeInfo fti in ht.Values )
354
 
                        {
355
 
                                if ( String.Compare( fti.FriendlyFileName, fileName, true ) == 0 )
356
 
                                {
357
 
                                        exists = true;
358
 
                                        break;
359
 
                                }
360
 
                        }
361
 
 
362
 
                        return exists;
363
 
                }
364
 
 
365
 
                /// <summary>
366
 
                /// Gets whether the specified file type is allowed.
367
 
                /// </summary>
368
 
                /// <param name="effectivePolicy">Effective user policy</param>
369
 
                /// <param name="fileType">Name of file type.</param>
370
 
                /// <returns></returns>
371
 
                private bool IsAllowed( string[] effectivePolicy, string fileType )
372
 
                {
373
 
                        return ( Array.IndexOf( effectivePolicy, fileType ) != -1 ) ? true : false;
374
 
                }
375
 
 
376
 
                /// <summary>
377
 
                /// Event handler for when this page is loaded.
378
 
                /// </summary>
379
 
                /// <param name="sender"></param>
380
 
                /// <param name="e"></param>
381
 
                private void Page_Load(object sender, System.EventArgs e)
382
 
                {
383
 
                        // localization
384
 
                        rm = Application[ "RM" ] as ResourceManager;
385
 
 
386
 
                        if ( !IsPostBack )
387
 
                        {
388
 
                                // Initialize the localized fields.
389
 
                                DeleteButton.Text = GetString( "DELETE" );
390
 
                                AddButton.Text = GetString( "ADD" );
391
 
                                DenyButton.Text = GetString( "DENY" );
392
 
                                AllowButton.Text = GetString( "ALLOW" );
393
 
 
394
 
                                Title.Text = GetString( "EXCLUDEDFILES" );
395
 
 
396
 
                                // Initialize the state variables.
397
 
                                CurrentFileOffset = 0;
398
 
                                TotalFiles = 0;
399
 
 
400
 
                                // Set the javascript function that will handle key presses.
401
 
                                NewFileTypeName.Attributes[ "OnKeyPress" ] = "return SubmitKeyDown(event, '" + AddButton.ClientID + "');";
402
 
                        }
403
 
                }
404
 
 
405
 
                /// <summary>
406
 
                /// Sets the page button state of the file type list.
407
 
                /// </summary>
408
 
                private void SetPageButtonState()
409
 
                {
410
 
                        FileTypeListFooter.SetPageButtonState( 
411
 
                                FileTypeList, 
412
 
                                CurrentFileOffset, 
413
 
                                TotalFiles, 
414
 
                                GetString( "FILES" ),
415
 
                                GetString( "FILE" ) );
416
 
                }
417
 
 
418
 
                /// <summary>
419
 
                /// Displays an error message on the parent page.
420
 
                /// </summary>
421
 
                /// <param name="errMsg"></param>
422
 
                private void ShowError( string errMsg )
423
 
                {
424
 
                        TopNavigation nav = Page.FindControl( "TopNav" ) as TopNavigation;
425
 
                        if ( nav != null )
426
 
                        {
427
 
                                nav.ShowError( errMsg );
428
 
                        }
429
 
                }
430
 
 
431
 
                #endregion
432
 
 
433
 
                #region Protected Methods
434
 
 
435
 
                /// <summary>
436
 
                /// Get a Localized String
437
 
                /// </summary>
438
 
                /// <param name="key">Key to the localized string.</param>
439
 
                /// <returns>Localized string.</returns>
440
 
                protected string GetString( string key )
441
 
                {
442
 
                        return rm.GetString( key );
443
 
                }
444
 
 
445
 
                /// <summary>
446
 
                /// Returns whether the entry has been checked.
447
 
                /// </summary>
448
 
                /// <param name="entry"></param>
449
 
                /// <returns></returns>
450
 
                protected bool IsEntryChecked( Object entry )
451
 
                {
452
 
                        FileTypeInfo fti = FileTypeSource[ entry ] as FileTypeInfo;
453
 
                        return ( fti != null ) ? fti.IsChecked : false;
454
 
                }
455
 
 
456
 
                /// <summary>
457
 
                /// Event handler that gets called when the all files checkbox is checked.
458
 
                /// </summary>
459
 
                /// <param name="sender"></param>
460
 
                /// <param name="e"></param>
461
 
                protected void OnAllFilesChecked( Object sender, EventArgs e )
462
 
                {
463
 
                        CheckBox allCheckBox = sender as CheckBox;
464
 
 
465
 
                        foreach( DataGridItem item in FileTypeList.Items )
466
 
                        {
467
 
                                string fileName = item.Cells[ 0 ].Text;
468
 
                                if ( fileName != "&nbsp;" )
469
 
                                {
470
 
                                        FileTypeInfo fti = FileTypeSource[ fileName ] as FileTypeInfo;
471
 
                                        if ( fti != null )
472
 
                                        {
473
 
                                                CheckBox checkBox = item.Cells[ 1 ].FindControl( "FileTypeCheckBox" ) as CheckBox;
474
 
                                                if ( ( checkBox != null ) && checkBox.Enabled )
475
 
                                                {
476
 
                                                        fti.IsChecked = checkBox.Checked = allCheckBox.Checked;
477
 
                                                }
478
 
                                        }
479
 
                                }
480
 
                        }
481
 
 
482
 
                        // See if there are any checked members.
483
 
                        bool hasEntries = allCheckBox.Checked ? true : HasCheckedEntries;
484
 
                        if ( DeleteButton.Visible )
485
 
                        {
486
 
                                DeleteButton.Enabled = hasEntries;
487
 
                        }
488
 
                        else
489
 
                        {
490
 
                                AllowButton.Enabled = HasDisallowedEntries && hasEntries;
491
 
                                DenyButton.Enabled = HasAllowedEntries && hasEntries;
492
 
                        }
493
 
                }
494
 
 
495
 
                /// <summary>
496
 
                /// Event handler that gets called when the delete button is clicked.
497
 
                /// </summary>
498
 
                /// <param name="sender"></param>
499
 
                /// <param name="e"></param>
500
 
                protected void OnDeleteFileType( Object sender, EventArgs e )
501
 
                {
502
 
                        // Get all of the values from the hashtable.
503
 
                        Hashtable ht = FileTypeSource;
504
 
                        FileTypeInfo[] ftInfoList = new FileTypeInfo[ ht.Count ];
505
 
                        ht.Values.CopyTo( ftInfoList, 0 );
506
 
 
507
 
                        foreach( FileTypeInfo fti in ftInfoList )
508
 
                        {
509
 
                                if ( fti.IsChecked )
510
 
                                {
511
 
                                        ht.Remove( fti.RegExFileName );
512
 
                                }
513
 
                        }
514
 
 
515
 
                        // Reset the all files check box.
516
 
                        AllFilesCheckBox.Checked = false;
517
 
                        DeleteButton.Enabled = false;
518
 
 
519
 
                        // If there are no entries in the current view, set the current page back one page.
520
 
                        if ( CurrentFileOffset >= ht.Count )
521
 
                        {
522
 
                                CurrentFileOffset -= FileTypeList.PageSize;
523
 
                                if ( CurrentFileOffset < 0 )
524
 
                                {
525
 
                                        CurrentFileOffset = 0;
526
 
                                }
527
 
                        }
528
 
 
529
 
                        // Refresh the policy view.
530
 
                        FileTypeList.DataSource = CreateFileTypeListView();
531
 
                        FileTypeList.DataBind();
532
 
                        SetPageButtonState();
533
 
 
534
 
                        // Indicate an event that the list has changed.
535
 
                        if ( ListChanged != null )
536
 
                        {
537
 
                                ListChanged( this, e );
538
 
                        }
539
 
                }
540
 
 
541
 
                /// <summary>
542
 
                /// Event handler that gets called when the allow file type button is clicked.
543
 
                /// </summary>
544
 
                /// <param name="sender"></param>
545
 
                /// <param name="e"></param>
546
 
                protected void OnAllowFileType( Object sender, EventArgs e )
547
 
                {
548
 
                        // Get all of the values from the hashtable.
549
 
                        foreach( FileTypeInfo fti in FileTypeSource.Values )
550
 
                        {
551
 
                                if ( fti.IsChecked )
552
 
                                {
553
 
                                        fti.IsAllowed = true;
554
 
                                        fti.IsChecked = false;
555
 
                                }
556
 
                        }
557
 
 
558
 
                        // Reset the all files check box.
559
 
                        AllFilesCheckBox.Checked = false;
560
 
                        AllowButton.Enabled = false;
561
 
 
562
 
                        // Refresh the policy view.
563
 
                        FileTypeList.DataSource = CreateFileTypeListView();
564
 
                        FileTypeList.DataBind();
565
 
 
566
 
                        // Indicate an event that the list has changed.
567
 
                        if ( ListChanged != null )
568
 
                        {
569
 
                                ListChanged( this, e );
570
 
                        }
571
 
                }
572
 
 
573
 
                /// <summary>
574
 
                /// Event handler that gets called when the deny file type button is clicked.
575
 
                /// </summary>
576
 
                /// <param name="sender"></param>
577
 
                /// <param name="e"></param>
578
 
                protected void OnDenyFileType( Object sender, EventArgs e )
579
 
                {
580
 
                        // Get all of the values from the hashtable.
581
 
                        foreach( FileTypeInfo fti in FileTypeSource.Values )
582
 
                        {
583
 
                                if ( fti.IsChecked )
584
 
                                {
585
 
                                        fti.IsAllowed = fti.IsChecked = false;
586
 
                                }
587
 
                        }
588
 
 
589
 
                        // Reset the all files check box.
590
 
                        AllFilesCheckBox.Checked = false;
591
 
                        DenyButton.Enabled = false;
592
 
 
593
 
                        // Refresh the policy view.
594
 
                        FileTypeList.DataSource = CreateFileTypeListView();
595
 
                        FileTypeList.DataBind();
596
 
 
597
 
                        // Indicate an event that the list has changed.
598
 
                        if ( ListChanged != null )
599
 
                        {
600
 
                                ListChanged( this, e );
601
 
                        }
602
 
                }
603
 
 
604
 
                /// <summary>
605
 
                /// Event handler that gets called when the add button is clicked.
606
 
                /// </summary>
607
 
                /// <param name="sender"></param>
608
 
                /// <param name="e"></param>
609
 
                protected void OnFileTypeAddClick( Object sender, EventArgs e )
610
 
                {
611
 
                        string fileName = NewFileTypeName.Text;
612
 
                        if ( ( fileName != null ) && ( fileName != String.Empty ) )
613
 
                        {
614
 
                                // Make sure that this entry is not already in the list.
615
 
                                if ( !FileTypeExists( fileName ) )
616
 
                                {
617
 
                                        Hashtable ht = FileTypeSource;
618
 
                                        ht[ fileName ] = new FileTypeInfo( Utils.ConvertToRegEx( fileName ), fileName, false, true );
619
 
 
620
 
                                        // A new file was added to the list. Update the page buttons.
621
 
                                        ++TotalFiles;
622
 
 
623
 
                                        // Clear out the old entry.
624
 
                                        NewFileTypeName.Text = String.Empty;
625
 
 
626
 
                                        // Indicate an event that the list has changed.
627
 
                                        if ( ListChanged != null )
628
 
                                        {
629
 
                                                ListChanged( this, e );
630
 
                                        }
631
 
 
632
 
                                        // Refresh the policy view.
633
 
                                        FileTypeList.DataSource = CreateFileTypeListView();
634
 
                                        FileTypeList.DataBind();
635
 
                                        SetPageButtonState();
636
 
                                }
637
 
                                else
638
 
                                {
639
 
                                        ShowError( GetString( "FILETYPEALREADYEXISTS" ) );
640
 
                                }
641
 
                        }
642
 
                        else
643
 
                        {
644
 
                                AddButton.Enabled = false;
645
 
                        }
646
 
                }
647
 
 
648
 
                /// <summary>
649
 
                /// Event handler that gets called when the file type checkbox is changed.
650
 
                /// </summary>
651
 
                /// <param name="sender"></param>
652
 
                /// <param name="e"></param>
653
 
                protected void OnFileTypeCheckChanged( Object sender, EventArgs e )
654
 
                {
655
 
                        CheckBox checkBox = sender as CheckBox;
656
 
                        DataGridItem item = checkBox.Parent.Parent as DataGridItem;
657
 
                        string fileName = item.Cells[ 0 ].Text;
658
 
                        if ( fileName != "&nbsp;" )
659
 
                        {
660
 
                                FileTypeInfo fti = FileTypeSource[ fileName ] as FileTypeInfo;
661
 
                                if ( fti != null )
662
 
                                {
663
 
                                        fti.IsChecked = checkBox.Checked;
664
 
 
665
 
                                        bool hasEntries = checkBox.Checked ? true : HasCheckedEntries;
666
 
                                        if ( DeleteButton.Visible )
667
 
                                        {
668
 
                                                DeleteButton.Enabled = hasEntries;
669
 
                                        }
670
 
                                        else
671
 
                                        {
672
 
                                                AllowButton.Enabled = HasDisallowedEntries && hasEntries;
673
 
                                                DenyButton.Enabled = HasAllowedEntries && hasEntries;
674
 
                                        }
675
 
                                }
676
 
                        }
677
 
                }
678
 
 
679
 
                /// <summary>
680
 
                /// Event handler for the PageFirstButton.
681
 
                /// </summary>
682
 
                /// <param name="source"></param>
683
 
                /// <param name="e"></param>
684
 
                protected void PageFirstButton_Click( object source, ImageClickEventArgs e )
685
 
                {
686
 
                        // Set to get the first files.
687
 
                        CurrentFileOffset = 0;
688
 
 
689
 
                        // Rebind the data source with the new data.
690
 
                        FileTypeList.DataSource = CreateFileTypeListView();
691
 
                        FileTypeList.DataBind();
692
 
 
693
 
                        // Set the button state.
694
 
                        SetPageButtonState();
695
 
                
696
 
                        // Reset the all files checkbox.
697
 
                        AllFilesCheckBox.Checked = false;
698
 
                }
699
 
 
700
 
                /// <summary>
701
 
                /// Event that first when the PageNextButton is clicked.
702
 
                /// </summary>
703
 
                /// <param name="source"></param>
704
 
                /// <param name="e"></param>
705
 
                protected void PageNextButton_Click( object source, ImageClickEventArgs e)
706
 
                {
707
 
                        CurrentFileOffset += FileTypeList.PageSize;
708
 
 
709
 
                        // Rebind the data source with the new data.
710
 
                        FileTypeList.DataSource = CreateFileTypeListView();
711
 
                        FileTypeList.DataBind();
712
 
 
713
 
                        // Set the button state.
714
 
                        SetPageButtonState();
715
 
 
716
 
                        // Reset the all files checkbox.
717
 
                        AllFilesCheckBox.Checked = false;
718
 
                }
719
 
 
720
 
                /// <summary>
721
 
                /// Event that first when the PageLastButton is clicked.
722
 
                /// </summary>
723
 
                /// <param name="source"></param>
724
 
                /// <param name="e"></param>
725
 
                protected void PageLastButton_Click( object source, ImageClickEventArgs e)
726
 
                {
727
 
                        CurrentFileOffset =  ( ( TotalFiles - 1 ) / FileTypeList.PageSize ) * FileTypeList.PageSize;
728
 
 
729
 
                        // Rebind the data source with the new data.
730
 
                        FileTypeList.DataSource = CreateFileTypeListView();
731
 
                        FileTypeList.DataBind();
732
 
 
733
 
                        // Set the button state.
734
 
                        SetPageButtonState();
735
 
 
736
 
                        // Reset the all files checkbox.
737
 
                        AllFilesCheckBox.Checked = false;
738
 
                }
739
 
 
740
 
                /// <summary>
741
 
                /// Event that first when the PagePreviousButton is clicked.
742
 
                /// </summary>
743
 
                /// <param name="source"></param>
744
 
                /// <param name="e"></param>
745
 
                protected void PagePreviousButton_Click( object source, ImageClickEventArgs e)
746
 
                {
747
 
                        CurrentFileOffset -= FileTypeList.PageSize;
748
 
                        if ( CurrentFileOffset < 0 )
749
 
                        {
750
 
                                CurrentFileOffset = 0;
751
 
                        }
752
 
 
753
 
                        // Rebind the data source with the new data.
754
 
                        FileTypeList.DataSource = CreateFileTypeListView();
755
 
                        FileTypeList.DataBind();
756
 
 
757
 
                        // Set the button state.
758
 
                        SetPageButtonState();
759
 
 
760
 
                        // Reset the all files checkbox.
761
 
                        AllFilesCheckBox.Checked = false;
762
 
                }
763
 
 
764
 
                #endregion
765
 
 
766
 
                #region Public Methods
767
 
 
768
 
                /// <summary>
769
 
                /// Gets the file type policy for the current user.
770
 
                /// </summary>
771
 
                /// <param name="policy">User policy.</param>
772
 
                public void GetFileTypePolicy( UserPolicy policy )
773
 
                {
774
 
                        // Show the proper control buttons.
775
 
                        AllowButton.Visible = DenyButton.Visible = true;
776
 
 
777
 
                        NewFileTypeName.Visible = AddButton.Visible = true;
778
 
                        // Create a list from the file type policy.
779
 
                        FileTypeSource = CreateFileTypeSource( policy );
780
 
 
781
 
                        // Build the data view from the table.
782
 
                        FileTypeList.DataSource = CreateFileTypeListView();
783
 
                        FileTypeList.DataBind();
784
 
                        SetPageButtonState();
785
 
                }
786
 
 
787
 
                /// <summary>
788
 
                /// Gets the file type policy for the current ifolder.
789
 
                /// </summary>
790
 
                /// <param name="policy">iFolder policy.</param>
791
 
                public void GetFileTypePolicy( iFolderPolicy policy )
792
 
                {
793
 
                        // Enable the add/delete controls.
794
 
                        NewFileTypeName.Visible = AddButton.Visible = DeleteButton.Visible = true;
795
 
 
796
 
                        // Create a list from the file type policy.
797
 
                        FileTypeSource = CreateFileTypeSource( policy );
798
 
 
799
 
                        // Build the data view from the table.
800
 
                        FileTypeList.DataSource = CreateFileTypeListView();
801
 
                        FileTypeList.DataBind();
802
 
                        SetPageButtonState();
803
 
                }
804
 
 
805
 
                /// <summary>
806
 
                /// Gets the file type policy for the system.
807
 
                /// </summary>
808
 
                /// <param name="policy">System policy.</param>
809
 
                public void GetFileTypePolicy( SystemPolicy policy )
810
 
                {
811
 
                        // Enable the add/delete controls.
812
 
                        NewFileTypeName.Visible = AddButton.Visible = DeleteButton.Visible = true;
813
 
 
814
 
                        // Create a list from the file type policy.
815
 
                        FileTypeSource = CreateFileTypeSource( policy );
816
 
 
817
 
                        // Build the data view from the table.
818
 
                        FileTypeList.DataSource = CreateFileTypeListView();
819
 
                        FileTypeList.DataBind();
820
 
                        SetPageButtonState();
821
 
                }
822
 
 
823
 
                /// <summary>
824
 
                /// Sets the file type policy for this user.
825
 
                /// </summary>
826
 
                /// <param name="policy">User policy that the new file type filter will be set.</param>
827
 
                public void SetFileTypePolicy( UserPolicy policy )
828
 
                {
829
 
                        // Build a list of checked file types.
830
 
                        ArrayList filterListAllow = new ArrayList();
831
 
                        ArrayList filterListDeny = new ArrayList();
832
 
                        foreach( FileTypeInfo fti in FileTypeSource.Values )
833
 
                        {
834
 
                                if ( fti.IsAllowed )
835
 
                                {
836
 
                                        filterListAllow.Add( fti.RegExFileName );
837
 
                                }
838
 
                                else
839
 
                                {
840
 
                                        filterListDeny.Add( fti.RegExFileName );        
841
 
                                }
842
 
                        }
843
 
 
844
 
                        // Set the user current user policy.
845
 
                        policy.FileTypesIncludes = filterListAllow.ToArray( typeof( string ) ) as string[];
846
 
                        policy.FileTypesExcludes = filterListDeny.ToArray( typeof( string ) ) as string[];
847
 
                }
848
 
 
849
 
                /// <summary>
850
 
                /// Sets the file type policy for this ifolder.
851
 
                /// </summary>
852
 
                /// <param name="policy">iFolder policy that the new file type filter will be set.</param>
853
 
                public void SetFileTypePolicy( iFolderPolicy policy )
854
 
                {
855
 
                        // Build a list of checked file types.
856
 
                        ArrayList filterList = new ArrayList();
857
 
                        foreach( FileTypeInfo fti in FileTypeSource.Values )
858
 
                        {
859
 
                                if ( fti.IsEnabled && !fti.IsAllowed )
860
 
                                {
861
 
                                        filterList.Add( fti.RegExFileName );
862
 
                                }
863
 
                        }
864
 
 
865
 
                        // Set the current ifolder policy.
866
 
                        policy.FileTypesExcludes = filterList.ToArray( typeof( string ) ) as string[];
867
 
                }
868
 
 
869
 
                /// <summary>
870
 
                /// Sets the file type policy for the system.
871
 
                /// </summary>
872
 
                /// <param name="policy">System policy that the new file type filter will be set.</param>
873
 
                public void SetFileTypePolicy( SystemPolicy policy )
874
 
                {
875
 
                        // Build a list of checked file types.
876
 
                        ArrayList filterList = new ArrayList();
877
 
                        foreach( FileTypeInfo fti in FileTypeSource.Values )
878
 
                        {
879
 
                                filterList.Add( fti.RegExFileName );
880
 
                        }
881
 
 
882
 
                        // Set the user current system policy.
883
 
                        policy.FileTypesExcludes = filterList.ToArray( typeof( string ) ) as string[];
884
 
                }
885
 
 
886
 
                #endregion
887
 
 
888
 
                #region Web Form Designer generated code
889
 
 
890
 
                /// <summary>
891
 
                /// OnInit
892
 
                /// </summary>
893
 
                /// <param name="e"></param>
894
 
                override protected void OnInit(EventArgs e)
895
 
                {
896
 
                        //
897
 
                        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
898
 
                        //
899
 
                        InitializeComponent();
900
 
                        base.OnInit(e);
901
 
                }
902
 
                
903
 
                /// <summary>
904
 
                ///             Required method for Designer support - do not modify
905
 
                ///             the contents of this method with the code editor.
906
 
                /// </summary>
907
 
                private void InitializeComponent()
908
 
                {
909
 
                        FileTypeListFooter.PageFirstClick += new ImageClickEventHandler( PageFirstButton_Click );
910
 
                        FileTypeListFooter.PagePreviousClick += new ImageClickEventHandler( PagePreviousButton_Click );
911
 
                        FileTypeListFooter.PageNextClick += new ImageClickEventHandler( PageNextButton_Click );
912
 
                        FileTypeListFooter.PageLastClick += new ImageClickEventHandler( PageLastButton_Click );
913
 
                        
914
 
                        this.Load += new System.EventHandler(this.Page_Load);
915
 
                }
916
 
                #endregion
917
 
 
918
 
                #region FileTypeInfo Class
919
 
 
920
 
                /// <summary>
921
 
                /// Class used to hold File Type filter information.
922
 
                /// </summary>
923
 
                [ Serializable() ]
924
 
                        private class FileTypeInfo : IComparable
925
 
                {
926
 
                        #region Class Members
927
 
 
928
 
                        /// <summary>
929
 
                        /// The regular expression version of the file name.
930
 
                        /// </summary>
931
 
                        public string RegExFileName;
932
 
 
933
 
                        /// <summary>
934
 
                        /// The friendly version of the file name.
935
 
                        /// </summary>
936
 
                        public string FriendlyFileName;
937
 
 
938
 
                        /// <summary>
939
 
                        /// If the file name is enabled as a filter.
940
 
                        /// </summary>
941
 
                        public bool IsAllowed;
942
 
 
943
 
                        /// <summary>
944
 
                        /// True if entry is a system level policy that can be
945
 
                        /// enabled/disabled or deleted.
946
 
                        /// </summary>
947
 
                        public bool IsEnabled;
948
 
 
949
 
                        /// <summary>
950
 
                        /// True if entry has been checked in the list.
951
 
                        /// </summary>
952
 
                        public bool IsChecked = false;
953
 
 
954
 
                        #endregion
955
 
 
956
 
                        #region Constructor
957
 
 
958
 
                        /// <summary>
959
 
                        /// Constructor
960
 
                        /// </summary>
961
 
                        /// <param name="regExFileName"></param>
962
 
                        /// <param name="friendlyFileName"></param>
963
 
                        /// <param name="allowed"></param>
964
 
                        /// <param name="enabled"></param>
965
 
                        public FileTypeInfo( 
966
 
                                string regExFileName, 
967
 
                                string friendlyFileName, 
968
 
                                bool allowed, 
969
 
                                bool enabled )
970
 
                        {
971
 
                                RegExFileName = regExFileName;
972
 
                                FriendlyFileName = friendlyFileName;
973
 
                                IsAllowed = allowed;
974
 
                                IsEnabled = enabled;
975
 
                        }
976
 
 
977
 
                        #endregion
978
 
 
979
 
                        #region IComparable Members
980
 
 
981
 
                        /// <summary>
982
 
                        /// Compares the current instance with another object of the same type.
983
 
                        /// </summary>
984
 
                        /// <param name="obj"></param>
985
 
                        /// <returns></returns>
986
 
                        public int CompareTo( object obj )
987
 
                        {
988
 
                                return String.Compare( FriendlyFileName, ( obj as FileTypeInfo ).FriendlyFileName, false );
989
 
                        }
990
 
 
991
 
                        #endregion
992
 
                }
993
 
 
994
 
                #endregion
995
 
        }
996
 
}