~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/Data/ICSharpCode.Data.Core/DatabaseObjects/DatabaseObjectsCollection.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
#region Usings
 
5
 
 
6
using System;
 
7
using System.Collections.Generic;
 
8
using System.Linq;
 
9
using System.Text;
 
10
using System.Collections.ObjectModel;
 
11
using ICSharpCode.Data.Core.Interfaces;
 
12
 
 
13
#endregion
 
14
 
 
15
namespace ICSharpCode.Data.Core.DatabaseObjects
 
16
{
 
17
    public class DatabaseObjectsCollection<T> : ObservableCollection<T>, IDatabaseObjectsCollection where T : IDatabaseObjectBase
 
18
    {
 
19
        #region Fields
 
20
 
 
21
        protected IDatabaseObjectBase _parent = null;
 
22
 
 
23
        #endregion
 
24
 
 
25
        #region Properties
 
26
 
 
27
        public List<IDatabaseObjectBase> NonGenericItems
 
28
        {
 
29
            get
 
30
            { 
 
31
                List<IDatabaseObjectBase> items = new List<IDatabaseObjectBase>();
 
32
                items.AddRange(this.Cast<IDatabaseObjectBase>());
 
33
                return items;
 
34
            }
 
35
        }
 
36
 
 
37
        public int SelectedItemsCount
 
38
        {
 
39
            get 
 
40
            {
 
41
                int selectedItemsCount = 0;
 
42
 
 
43
                foreach (T item in this)
 
44
                {
 
45
                    if (item.IsSelected)
 
46
                        selectedItemsCount++;
 
47
                }
 
48
 
 
49
                return selectedItemsCount;
 
50
            }
 
51
        }
 
52
 
 
53
        #endregion
 
54
 
 
55
        #region Methods
 
56
 
 
57
        public new void Add(T item)
 
58
        {
 
59
            item.Parent = _parent;
 
60
            base.Add(item);
 
61
        }
 
62
 
 
63
        #endregion
 
64
 
 
65
        #region Constructor
 
66
 
 
67
        public DatabaseObjectsCollection(IDatabaseObjectBase parent)
 
68
        {
 
69
            _parent = parent;
 
70
        }
 
71
 
 
72
        public DatabaseObjectsCollection()
 
73
        { }
 
74
 
 
75
        #endregion
 
76
    }
 
77
 
 
78
    public static class DatabaseObjectsCollection
 
79
    {
 
80
        #region Extension methods
 
81
 
 
82
        public static DatabaseObjectsCollection<T> ToDatabaseObjectsCollection<T>(this IEnumerable<T> source) where T : IDatabaseObjectBase
 
83
        {
 
84
            DatabaseObjectsCollection<T> dest = new DatabaseObjectsCollection<T>(null);
 
85
 
 
86
            foreach (T item in source)
 
87
                dest.Add(item);
 
88
 
 
89
            return dest;
 
90
        }
 
91
 
 
92
        public static DatabaseObjectsCollection<T> ToDatabaseObjectsCollection<T>(this IEnumerable<T> source, IDatabaseObjectBase parent) where T : IDatabaseObjectBase
 
93
        {
 
94
            DatabaseObjectsCollection<T> dest = new DatabaseObjectsCollection<T>(parent);
 
95
 
 
96
            foreach (T item in source)
 
97
                dest.Add(item);
 
98
 
 
99
            return dest;
 
100
        }
 
101
 
 
102
        #endregion
 
103
    }
 
104
}