~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Collections/Collections.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
using System.Collections.ObjectModel;
 
7
using System.Globalization;
 
8
using System.Linq;
 
9
 
 
10
using ICSharpCode.Reports.Core.Exporter;
 
11
using ICSharpCode.Reports.Core.Interfaces;
 
12
 
 
13
namespace ICSharpCode.Reports.Core{
 
14
        
 
15
        public class CollectionChangedEventArgs<T> : EventArgs
 
16
        {
 
17
                T item;
 
18
                
 
19
                public T Item {
 
20
                        get {
 
21
                                return item;
 
22
                        }
 
23
                }
 
24
                
 
25
                public CollectionChangedEventArgs(T item)
 
26
                {
 
27
                        this.item = item;
 
28
                }
 
29
        }
 
30
        ///<summary>
 
31
        /// Comparer to Sort the <see cref="ReportItemCollection"></see>
 
32
        /// by System.Drawing.Location.Y, so we have <see cref="BaseReportItem"></see> in the Order we use them
 
33
        /// (Line by Line)
 
34
        /// </summary>
 
35
        internal class LocationSorter : IComparer<BaseReportItem>  {
 
36
                public int Compare(BaseReportItem lhs, BaseReportItem rhs){
 
37
                        if (lhs == null){
 
38
                                if (rhs == null){
 
39
                                        return 0;
 
40
                                }
 
41
                                return -1;
 
42
                        }
 
43
                        if (rhs == null){
 
44
                                return 1;
 
45
                        }
 
46
                        
 
47
                        if (lhs.Location.Y == rhs.Location.Y){
 
48
                                return lhs.Location.X - rhs.Location.X;
 
49
                        }
 
50
                        return lhs.Location.Y - rhs.Location.Y;
 
51
                }
 
52
        }
 
53
        
 
54
 
 
55
        ///<summary>
 
56
        ///  A collection that holds <see cref='IItemRenderer'/> objects.
 
57
        ///</summary>
 
58
        public class ReportItemCollection : Collection<BaseReportItem>
 
59
        {
 
60
                
 
61
                // Trick to get the inner list as List<T> (InnerList always has that type because we only use
 
62
                // the parameterless constructor on Collection<T>)
 
63
                
 
64
                private List<BaseReportItem> InnerList {
 
65
                        get { return (List<BaseReportItem>)base.Items; }
 
66
                }
 
67
                
 
68
                private void Sort(IComparer<BaseReportItem> comparer)
 
69
                {
 
70
                        InnerList.Sort(comparer);
 
71
                }
 
72
                
 
73
                public void ForEach (Action <BaseReportItem> action)
 
74
                {
 
75
                        this.InnerList.ForEach (action);
 
76
                }
 
77
                
 
78
                
 
79
                public void AddRange(IEnumerable<BaseReportItem> items)
 
80
                {
 
81
                        foreach (BaseReportItem item in items) Add(item);
 
82
                }
 
83
                
 
84
                
 
85
                public void SortByLocation () {
 
86
                        if (this.Count > 1) {
 
87
                                this.Sort(new LocationSorter());
 
88
                        }
 
89
                }
 
90
                
 
91
                
 
92
                public bool Exist (string itemName)
 
93
                {
 
94
                        if (String.IsNullOrEmpty(itemName)) {
 
95
                                throw new ArgumentNullException("itemName");
 
96
                        }
 
97
                        
 
98
                        if (InnerFind(itemName) == null) {
 
99
                                return false;
 
100
                        }
 
101
                        else {
 
102
                                return true;
 
103
                        }       
 
104
                }
 
105
                
 
106
        
 
107
                private BaseReportItem InnerFind (string name)
 
108
                {
 
109
                        return this.FirstOrDefault(x => 0 == String.Compare(x.Name, name,true,CultureInfo.InvariantCulture));
 
110
                }
 
111
                
 
112
                
 
113
                public BaseReportItem Find (string itemName)
 
114
                {
 
115
                        if (String.IsNullOrEmpty(itemName)) {
 
116
                                throw new ArgumentNullException("itemName");
 
117
                        }
 
118
                        return this.InnerFind (itemName);
 
119
                }
 
120
                
 
121
                
 
122
                public BaseReportItem FindHighestElement()
 
123
                {
 
124
                        if (this.InnerList.Count == 0) {
 
125
                                return null;
 
126
                        }
 
127
                        BaseReportItem heighest = this.InnerList[0];
 
128
                        foreach (BaseReportItem item in this.InnerList)
 
129
                        {
 
130
                                if (item.Size.Height > heighest.Size.Height) {
 
131
                                        heighest = item;
 
132
                                }
 
133
                        }
 
134
                        return heighest;
 
135
                }
 
136
                
 
137
                
 
138
                protected override void InsertItem(int index, BaseReportItem item)
 
139
                {
 
140
                        base.InsertItem(index, item);
 
141
                }
 
142
                
 
143
                
 
144
                protected override void RemoveItem(int index)
 
145
                {
 
146
                        base.RemoveItem(index);
 
147
                }
 
148
        
 
149
                #region Grouphandling
 
150
 
 
151
        public  Collection<GroupHeader> FindGroupHeader()
 
152
        {
 
153
            return new Collection<GroupHeader>(this.Items.OfType<GroupHeader>().ToList());
 
154
        }
 
155
 
 
156
 
 
157
        public  Collection<GroupFooter> FindGroupFooter()
 
158
        {
 
159
            return new Collection<GroupFooter>(this.Items.OfType<GroupFooter>().ToList());
 
160
        }
 
161
 
 
162
      
 
163
                private Collection<BaseDataItem> CreateGroupedList ()
 
164
                {
 
165
                        Collection<BaseDataItem> inheritedReportItems = null;
 
166
                        foreach (BaseReportItem element in this) {
 
167
                                ISimpleContainer container = element as ISimpleContainer;
 
168
                                if (container == null) {
 
169
                                        inheritedReportItems = new Collection<BaseDataItem>(this.OfType<BaseDataItem>().ToList());
 
170
                                        break;
 
171
                                } else {
 
172
                                        inheritedReportItems = new Collection<BaseDataItem>(container.Items.OfType<BaseDataItem>().ToList());
 
173
                                        break;
 
174
                                }
 
175
                        }
 
176
                        return inheritedReportItems;
 
177
                }
 
178
                
 
179
                
 
180
                public ReportItemCollection ExtractGroupedColumns ()
 
181
                {
 
182
                        Collection<BaseDataItem> inheritedReportItems = CreateGroupedList();
 
183
                        ReportItemCollection r = new ReportItemCollection();
 
184
                        r.AddRange(inheritedReportItems);
 
185
                        return r;
 
186
                }
 
187
                
 
188
                #endregion
 
189
        }
 
190
 
 
191
        /// <summary>
 
192
        /// This class holds all the available Sections of an Report
 
193
        /// </summary>
 
194
        [Serializable()]
 
195
        public sealed class ReportSectionCollection: Collection<BaseSection>
 
196
        {
 
197
        }
 
198
        
 
199
        
 
200
        
 
201
        [Serializable()]
 
202
        public class AvailableFieldsCollection: Collection<AbstractColumn>{
 
203
                
 
204
                public AvailableFieldsCollection(){
 
205
                }
 
206
                
 
207
                public AbstractColumn Find (string columnName)
 
208
                {
 
209
                        if (String.IsNullOrEmpty(columnName)) {
 
210
                                throw new ArgumentNullException("columnName");
 
211
                        }
 
212
                        
 
213
                         return this.FirstOrDefault(x => 0 == String.Compare(x.ColumnName,columnName,true,CultureInfo.InvariantCulture));
 
214
                }
 
215
        }
 
216
        
 
217
        
 
218
        
 
219
        
 
220
        [Serializable()]
 
221
        public class SortColumnCollection: ColumnCollection
 
222
        {
 
223
                public SortColumnCollection()
 
224
                {
 
225
                }
 
226
                
 
227
                public new AbstractColumn Find (string columnName)
 
228
                {
 
229
                        if (String.IsNullOrEmpty(columnName)) {
 
230
                                throw new ArgumentNullException("columnName");
 
231
                        }
 
232
                        
 
233
                        return this.FirstOrDefault(x => 0 == String.Compare(x.ColumnName,columnName,true,CultureInfo.InvariantCulture));
 
234
                }
 
235
        
 
236
                
 
237
                public void AddRange (IEnumerable<SortColumn> items)
 
238
                {
 
239
                        foreach (SortColumn item in items){
 
240
                                this.Add(item);
 
241
                        }
 
242
                }
 
243
                
 
244
                
 
245
                /// <summary>
 
246
                /// The Culture is used for direct String Comparison
 
247
                /// </summary>
 
248
                
 
249
                public new static CultureInfo Culture
 
250
                {
 
251
                        get { return CultureInfo.CurrentCulture;}
 
252
                }
 
253
        }
 
254
        
 
255
        
 
256
        [Serializable()]
 
257
        public class GroupColumnCollection: SortColumnCollection
 
258
        {
 
259
                public GroupColumnCollection()
 
260
                {
 
261
                }
 
262
                
 
263
                public new AbstractColumn Find (string columnName)
 
264
                {
 
265
                        if (String.IsNullOrEmpty(columnName)) {
 
266
                                throw new ArgumentNullException("columnName");
 
267
                        }
 
268
                        
 
269
                        return this.FirstOrDefault(x => 0 == String.Compare(x.ColumnName,columnName,true,CultureInfo.InvariantCulture));
 
270
                }
 
271
        }
 
272
        
 
273
        
 
274
        
 
275
        [Serializable()]
 
276
        public class ColumnCollection: Collection<AbstractColumn>{
 
277
                
 
278
                public ColumnCollection()
 
279
                {
 
280
                }
 
281
                
 
282
                public AbstractColumn Find (string columnName)
 
283
                {
 
284
                        if (String.IsNullOrEmpty(columnName)) {
 
285
                                throw new ArgumentNullException("columnName");
 
286
                        }
 
287
                        
 
288
                        return this.FirstOrDefault(x => 0 == String.Compare(x.ColumnName,columnName,true,CultureInfo.InvariantCulture));
 
289
                }
 
290
        
 
291
                
 
292
                public void AddRange (IEnumerable<AbstractColumn> items)
 
293
                {
 
294
                        foreach (AbstractColumn item in items){
 
295
                                this.Add(item);
 
296
                        }
 
297
                }
 
298
                
 
299
                
 
300
                /// <summary>
 
301
                /// The Culture is used for direct String Comparison
 
302
                /// </summary>
 
303
                
 
304
                public static CultureInfo Culture
 
305
                {
 
306
                        get { return CultureInfo.CurrentCulture;}
 
307
                }
 
308
        }
 
309
        
 
310
 
 
311
        public class SqlParameterCollection : Collection<SqlParameter>
 
312
        {
 
313
                public SqlParameterCollection()
 
314
                {
 
315
                }
 
316
                
 
317
                public SqlParameter Find (string parameterName)
 
318
                {
 
319
                        if (String.IsNullOrEmpty(parameterName)) {
 
320
                                throw new ArgumentNullException("parameterName");
 
321
                        }
 
322
                        return this.FirstOrDefault(x => 0 == String.Compare(x.ParameterName,parameterName,true,CultureInfo.InvariantCulture));
 
323
                }
 
324
                
 
325
                
 
326
                public void AddRange (IEnumerable<SqlParameter> items)
 
327
                {
 
328
                        foreach (SqlParameter item in items){
 
329
                                this.Add(item);
 
330
                        }
 
331
                }
 
332
                
 
333
                public static CultureInfo Culture
 
334
                {
 
335
                        get { return System.Globalization.CultureInfo.CurrentCulture; }
 
336
                }
 
337
                
 
338
        }
 
339
        
 
340
        public class ParameterCollection: Collection<BasicParameter>{
 
341
                
 
342
                public ParameterCollection()
 
343
                {                       
 
344
                }
 
345
                
 
346
                
 
347
                public BasicParameter Find (string parameterName)
 
348
                {
 
349
                        if (String.IsNullOrEmpty(parameterName)) {
 
350
                                throw new ArgumentNullException("parameterName");
 
351
                        }
 
352
                        return this.FirstOrDefault(x => 0 == String.Compare(x.ParameterName,parameterName,true,CultureInfo.InvariantCulture));
 
353
                }
 
354
                
 
355
                
 
356
                public  System.Collections.Hashtable CreateHash ()
 
357
                {
 
358
                        System.Collections.Hashtable ht = new System.Collections.Hashtable();
 
359
                        foreach(BasicParameter bt in this){
 
360
                                        ht.Add(bt.ParameterName,bt.ParameterValue);
 
361
                        }
 
362
                        return ht;
 
363
                }
 
364
                
 
365
                public static CultureInfo Culture
 
366
                {
 
367
                        get { return System.Globalization.CultureInfo.CurrentCulture; }
 
368
                }
 
369
                
 
370
                
 
371
                public void AddRange (IEnumerable<BasicParameter> items)
 
372
                {
 
373
                        foreach (BasicParameter item in items){
 
374
                                this.Add(item);
 
375
                        }
 
376
                }
 
377
        }
 
378
        
 
379
        #region ExporterCollection
 
380
        
 
381
        public class ExporterCollection : Collection<BaseExportColumn>
 
382
        {
 
383
                
 
384
                public void AddRange (IEnumerable <BaseExportColumn> items){
 
385
                        foreach (var item in items) {
 
386
                                this.Add (item);
 
387
                        }
 
388
                }
 
389
        }
 
390
        
 
391
        
 
392
        public class PagesCollection  :Collection<ExporterPage>
 
393
        {
 
394
                
 
395
        }
 
396
        
 
397
        
 
398
        #endregion
 
399
        
 
400
        public class  CurrentItemsCollection:Collection<CurrentItem>
 
401
        {
 
402
                public CurrentItem Find (string columnName)
 
403
                {
 
404
                        if (String.IsNullOrEmpty(columnName)) {
 
405
                                throw new ArgumentNullException("columnName");
 
406
                        }
 
407
                        
 
408
                        return this.FirstOrDefault(x => 0 == String.Compare(x.ColumnName,columnName,true,CultureInfo.InvariantCulture));
 
409
                }
 
410
        }
 
411
}