Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/View/DataSetView.cs @ 11692

Last change on this file since 11692 was 9615, checked in by mkommend, 11 years ago

#1734: Updated copyright information in all DataImporter classes.

File size: 5.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30
31namespace HeuristicLab.DataImporter.Data.View {
32  public partial class DataSetView : UserControl {
33    private DataSetView() {
34      InitializeComponent();
35      columnGroupViews = new List<ColumnGroupView>();
36      this.AutoScroll = true;
37      this.Scroll += new ScrollEventHandler(DataSetView_Scroll);
38      this.state = new DataSetState(0, ColumnGroupState.None);
39    }
40
41    public DataSetView(Model.DataSet dataSet)
42      : this() {
43      this.DataSet = dataSet;
44      this.DataSet.Changed += this.DataSetChanged;
45      this.Refresh();
46    }
47
48    public DataSetView(Model.DataSet dataSet, CommandChain commandChain)
49      : this(dataSet) {
50      this.CommandChain = commandChain;
51    }
52
53    private List<ColumnGroupView> columnGroupViews;
54
55    private CommandChain commandChain;
56    public CommandChain CommandChain {
57      get { return this.commandChain; }
58      set {
59        this.commandChain = value;
60        foreach (ColumnGroupView view in this.columnGroupViews)
61          view.CommandChain = value;
62      }
63    }
64
65    private int columnGroupMaxWidth;
66    public int ColumnGroupMaxWidth {
67      get { return columnGroupMaxWidth; }
68      set {
69        columnGroupMaxWidth = value;
70        foreach (ColumnGroupView view in columnGroupViews)
71          view.MaxWidth = value;
72      }
73    }
74
75    private Model.DataSet dataSet;
76    public Model.DataSet DataSet {
77      get { return (Model.DataSet)this.dataSet; }
78      private set { this.dataSet = value; }
79    }
80
81    private DataSetState state;
82    public DataSetState State {
83      get { return this.state; }
84      protected set {
85        this.state = value;
86        FireStateChanged();
87      }
88    }
89
90    private bool allowReorderColumns;
91    public bool AllowReorderColumns {
92      set {
93        allowReorderColumns = value;
94        foreach (ColumnGroupView view in this.columnGroupViews) {
95          view.AllowReorderColumns = value;
96        }
97      }
98      get { return allowReorderColumns; }
99    }
100
101    public override void Refresh() {
102      base.Refresh();
103
104      //clean up - caution: view.dispose removes disposed view from controls collection
105      this.SuspendLayout();
106      this.Controls.Clear();
107      foreach (ColumnGroupView view in this.columnGroupViews.Reverse<ColumnGroupView>())
108        view.Dispose();
109      this.columnGroupViews.Clear();
110
111      ColumnGroupView ctrl;
112      //necessary because otherwise columnGroupsViews are in reverse order
113      for (int i = 0; i < this.DataSet.ColumnGroups.Count(); i++) {
114        ctrl = new ColumnGroupView(this.DataSet.ColumnGroups.ElementAt(i), this.commandChain);
115        ctrl.Activated += new ColumnGroupActivatedEventHandler(ColumnGroupActivated);
116        ctrl.StateChanged += new EventHandler(ColumnGroupStateChanged);
117        ctrl.MaxWidth = this.columnGroupMaxWidth;
118        if (this.DataSet.ColumnGroups.ElementAt(i).Active) {
119          ctrl.ColumnGroupActive = true;
120          ctrl.FireActivated(false);
121        }
122        ctrl.Dock = DockStyle.Top | DockStyle.Bottom;
123        this.columnGroupViews.Add(ctrl);
124      }
125      this.Controls.AddRange(this.columnGroupViews.Reverse<ColumnGroupView>().ToArray());
126      this.Invalidate();
127      this.ResumeLayout();
128    }
129
130    public void DataSetChanged(object sender, EventArgs e) {
131      this.Refresh();
132      this.UpdateStateInformation();
133    }
134
135    public void ColumnGroupActivated(object sender, bool addToActiveColumnGroups) {
136      if (!addToActiveColumnGroups) {
137        foreach (ColumnGroupView view in this.columnGroupViews)
138          view.ColumnGroupActive = view == sender;
139      }
140      UpdateStateInformation();
141    }
142
143    public void ColumnGroupStateChanged(object sender, EventArgs e) {
144      UpdateStateInformation();
145    }
146
147    private void UpdateStateInformation() {
148      DataSetState state = new DataSetState(0, ColumnGroupState.None);
149      foreach (ColumnGroupView view in this.columnGroupViews.Where(cg => cg.ColumnGroupActive))
150        state.AddColumnGroupState(view.State);
151      if (state.ActiveColumnGroups == 1)
152        state.SelectedColumns = DataSet.ActiveColumnGroups.ElementAt(0).SelectedColumns.Count();
153      if (!this.state.Equals(state))
154        this.State = state;
155    }
156
157    public event EventHandler StateChanged;
158    protected void FireStateChanged() {
159      OnStateChanged();
160    }
161
162    protected virtual void OnStateChanged() {
163      if (StateChanged != null) {
164        StateChanged(this, new EventArgs());
165      }
166    }
167
168    #region GUI interaction with scroll bars
169    private Point scrollposition;
170    private void DataSetView_Scroll(object sender, ScrollEventArgs e) {
171      scrollposition.X = this.DisplayRectangle.X;
172      scrollposition.Y = this.DisplayRectangle.Y;
173    }
174
175    protected override Point ScrollToControl(Control activeControl) {
176      return scrollposition;
177    }
178    #endregion
179  }
180}
Note: See TracBrowser for help on using the repository browser.