Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive.Azure/HeuristicLab.Analysis.Views/3.3/DataTableVisualPropertiesDialog.cs @ 7260

Last change on this file since 7260 was 6342, checked in by abeham, 14 years ago

#1465, #1469, #1470, #1494, #1496, #1497, #1539, #1487

  • merged to trunk
File size: 5.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Collections.Generic;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Common.Resources;
26
27namespace HeuristicLab.Analysis.Views {
28  public partial class DataTableVisualPropertiesDialog : Form {
29    protected bool SuppressEvents { get; set; }
30    protected DataTable Content { get; private set; }
31    private DataTableVisualProperties originalDataTableVPs;
32    private Dictionary<string, DataRowVisualProperties> originalDataRowVPs;
33
34    public DataTableVisualPropertiesDialog(DataTable dataTable) {
35      InitializeComponent();
36      upButton.Text = string.Empty;
37      upButton.Image = VSImageLibrary.ArrowUp;
38      downButton.Text = string.Empty;
39      downButton.Image = VSImageLibrary.ArrowDown;
40      Content = dataTable;
41      originalDataTableVPs = (DataTableVisualProperties)Content.VisualProperties.Clone();
42      originalDataRowVPs = new Dictionary<string, DataRowVisualProperties>();
43      foreach (DataRow row in Content.Rows)
44        originalDataRowVPs.Add(row.Name, (DataRowVisualProperties)row.VisualProperties.Clone());
45      seriesListView.Items.Clear();
46      seriesListView.SmallImageList = new ImageList();
47      seriesListView.SmallImageList.Images.Add(VSImageLibrary.Graph);
48      FillSeriesListView();
49      dataTableVisualPropertiesControl.Content = Content.VisualProperties;
50    }
51
52    private void FillSeriesListView() {
53      seriesListView.SelectedIndices.Clear();
54      foreach (DataRow row in Content.Rows) {
55        seriesListView.Items.Add(new ListViewItem(row.Name, 0));
56      }
57      seriesListView.SelectedIndices.Add(0);
58    }
59
60    private void seriesListView_SelectedIndexChanged(object sender, System.EventArgs e) {
61      if (!SuppressEvents) {
62        if (seriesListView.SelectedItems.Count != 1) {
63          dataRowVisualPropertiesControl.Content = null;
64        } else {
65          string rowName = seriesListView.SelectedItems[0].Text;
66          dataRowVisualPropertiesControl.Content = Content.Rows[rowName].VisualProperties;
67        }
68      }
69    }
70
71    private void okButton_Click(object sender, System.EventArgs e) {
72      DialogResult = DialogResult.OK;
73      Close();
74    }
75
76    private void cancelButton_Click(object sender, System.EventArgs e) {
77      DialogResult = DialogResult.Cancel;
78      foreach (DataRow row in Content.Rows) {
79        row.VisualProperties = originalDataRowVPs[row.Name];
80      }
81      Content.VisualProperties = originalDataTableVPs;
82      Close();
83    }
84
85    private void upButton_Click(object sender, System.EventArgs e) {
86      if (seriesListView.SelectedIndices.Count == 1 && seriesListView.SelectedIndices[0] > 0) {
87        int index = seriesListView.SelectedIndices[0];
88        SuppressEvents = true;
89        try {
90          seriesListView.BeginUpdate();
91          ListViewItem selectedSeriesItem = seriesListView.Items[index];
92          seriesListView.Items.RemoveAt(index);
93          ListViewItem temp = seriesListView.Items[index - 1];
94          seriesListView.Items.RemoveAt(index - 1);
95          seriesListView.Items.Insert(index - 1, selectedSeriesItem);
96          seriesListView.Items.Insert(index, temp);
97          seriesListView.SelectedIndices.Clear();
98          seriesListView.EndUpdate();
99        } finally { SuppressEvents = false; }
100        seriesListView.SelectedIndices.Add(index - 1);
101        UpdateAllSeriesPositions();
102      }
103    }
104
105    private void downButton_Click(object sender, System.EventArgs e) {
106      if (seriesListView.SelectedIndices.Count == 1 && seriesListView.SelectedIndices[0] < seriesListView.Items.Count - 1) {
107        int index = seriesListView.SelectedIndices[0];
108        SuppressEvents = true;
109        try {
110          seriesListView.BeginUpdate();
111          ListViewItem temp = seriesListView.Items[index + 1];
112          seriesListView.Items.RemoveAt(index + 1);
113          ListViewItem selectedSeriesItem = seriesListView.Items[index];
114          seriesListView.Items.RemoveAt(index);
115          seriesListView.Items.Insert(index, temp);
116          seriesListView.Items.Insert(index + 1, selectedSeriesItem);
117          seriesListView.SelectedIndices.Clear();
118          seriesListView.EndUpdate();
119        } finally { SuppressEvents = false; }
120        seriesListView.SelectedIndices.Add(index + 1);
121        UpdateAllSeriesPositions();
122      }
123    }
124
125    #region Helpers
126    private void UpdateAllSeriesPositions() {
127      Dictionary<string, DataRow> rows = Content.Rows.ToDictionary(x => x.Name);
128      Content.Rows.Clear();
129      for (int i = 0; i < seriesListView.Items.Count; i++) {
130        ListViewItem item = seriesListView.Items[i];
131        Content.Rows.Add(rows[item.Text]);
132      }
133    }
134    #endregion
135  }
136}
Note: See TracBrowser for help on using the repository browser.