[6010] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7270] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6010] | 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 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
[7270] | 23 | using System.ComponentModel;
|
---|
[6020] | 24 | using System.Linq;
|
---|
[6010] | 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Common.Resources;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Analysis.Views {
|
---|
| 29 | public partial class DataTableVisualPropertiesDialog : Form {
|
---|
[6020] | 30 | protected bool SuppressEvents { get; set; }
|
---|
[6010] | 31 | protected DataTable Content { get; private set; }
|
---|
| 32 | private DataTableVisualProperties originalDataTableVPs;
|
---|
| 33 | private Dictionary<string, DataRowVisualProperties> originalDataRowVPs;
|
---|
| 34 |
|
---|
[7270] | 35 | private HashSet<string> modifiedDisplayNames;
|
---|
| 36 | public IEnumerable<string> RowsWithModifiedDisplayNames { get { return modifiedDisplayNames.AsEnumerable(); } }
|
---|
| 37 |
|
---|
[6010] | 38 | public DataTableVisualPropertiesDialog(DataTable dataTable) {
|
---|
| 39 | InitializeComponent();
|
---|
[7270] | 40 | #region Prepare controls
|
---|
[6016] | 41 | upButton.Text = string.Empty;
|
---|
| 42 | upButton.Image = VSImageLibrary.ArrowUp;
|
---|
| 43 | downButton.Text = string.Empty;
|
---|
| 44 | downButton.Image = VSImageLibrary.ArrowDown;
|
---|
[7270] | 45 | seriesListView.Items.Clear();
|
---|
| 46 | seriesListView.SmallImageList = new ImageList();
|
---|
| 47 | seriesListView.SmallImageList.Images.Add(VSImageLibrary.Graph);
|
---|
| 48 | #endregion
|
---|
| 49 |
|
---|
[6010] | 50 | Content = dataTable;
|
---|
| 51 | originalDataTableVPs = (DataTableVisualProperties)Content.VisualProperties.Clone();
|
---|
| 52 | originalDataRowVPs = new Dictionary<string, DataRowVisualProperties>();
|
---|
| 53 | foreach (DataRow row in Content.Rows)
|
---|
| 54 | originalDataRowVPs.Add(row.Name, (DataRowVisualProperties)row.VisualProperties.Clone());
|
---|
[7270] | 55 |
|
---|
| 56 | dataTableVisualPropertiesControl.Content = Content.VisualProperties;
|
---|
| 57 |
|
---|
| 58 | modifiedDisplayNames = new HashSet<string>();
|
---|
[6010] | 59 | FillSeriesListView();
|
---|
[7270] | 60 | RegisterContentEvents();
|
---|
[6010] | 61 | }
|
---|
| 62 |
|
---|
[7270] | 63 | private void RegisterContentEvents() {
|
---|
[6010] | 64 | foreach (DataRow row in Content.Rows) {
|
---|
[7270] | 65 | row.VisualProperties.PropertyChanged += new PropertyChangedEventHandler(Row_VisualProperties_PropertyChanged);
|
---|
[6010] | 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[7270] | 69 | private void DeregisterContentEvents() {
|
---|
| 70 | foreach (DataRow row in Content.Rows) {
|
---|
| 71 | row.VisualProperties.PropertyChanged -= new PropertyChangedEventHandler(Row_VisualProperties_PropertyChanged);
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | protected override void OnClosing(CancelEventArgs e) {
|
---|
| 76 | DeregisterContentEvents();
|
---|
| 77 | Application.DoEvents();
|
---|
| 78 | base.OnClosing(e);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | private void Row_VisualProperties_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
| 82 | foreach (DataRow row in Content.Rows) {
|
---|
| 83 | if (e.PropertyName == "DisplayName" && row.VisualProperties == sender) {
|
---|
| 84 | modifiedDisplayNames.Add(row.Name);
|
---|
| 85 | break;
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[6010] | 90 | private void seriesListView_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
[6020] | 91 | if (!SuppressEvents) {
|
---|
| 92 | if (seriesListView.SelectedItems.Count != 1) {
|
---|
| 93 | dataRowVisualPropertiesControl.Content = null;
|
---|
| 94 | } else {
|
---|
| 95 | string rowName = seriesListView.SelectedItems[0].Text;
|
---|
| 96 | dataRowVisualPropertiesControl.Content = Content.Rows[rowName].VisualProperties;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
[6010] | 99 | }
|
---|
| 100 |
|
---|
| 101 | private void okButton_Click(object sender, System.EventArgs e) {
|
---|
| 102 | DialogResult = DialogResult.OK;
|
---|
| 103 | Close();
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | private void cancelButton_Click(object sender, System.EventArgs e) {
|
---|
| 107 | DialogResult = DialogResult.Cancel;
|
---|
| 108 | foreach (DataRow row in Content.Rows) {
|
---|
| 109 | row.VisualProperties = originalDataRowVPs[row.Name];
|
---|
| 110 | }
|
---|
[7270] | 111 | modifiedDisplayNames.Clear();
|
---|
[6011] | 112 | Content.VisualProperties = originalDataTableVPs;
|
---|
[6010] | 113 | Close();
|
---|
| 114 | }
|
---|
[6016] | 115 |
|
---|
| 116 | private void upButton_Click(object sender, System.EventArgs e) {
|
---|
| 117 | if (seriesListView.SelectedIndices.Count == 1 && seriesListView.SelectedIndices[0] > 0) {
|
---|
| 118 | int index = seriesListView.SelectedIndices[0];
|
---|
[6020] | 119 | SuppressEvents = true;
|
---|
| 120 | try {
|
---|
| 121 | seriesListView.BeginUpdate();
|
---|
| 122 | ListViewItem selectedSeriesItem = seriesListView.Items[index];
|
---|
| 123 | seriesListView.Items.RemoveAt(index);
|
---|
| 124 | ListViewItem temp = seriesListView.Items[index - 1];
|
---|
| 125 | seriesListView.Items.RemoveAt(index - 1);
|
---|
| 126 | seriesListView.Items.Insert(index - 1, selectedSeriesItem);
|
---|
| 127 | seriesListView.Items.Insert(index, temp);
|
---|
| 128 | seriesListView.SelectedIndices.Clear();
|
---|
| 129 | seriesListView.EndUpdate();
|
---|
| 130 | } finally { SuppressEvents = false; }
|
---|
| 131 | seriesListView.SelectedIndices.Add(index - 1);
|
---|
[6016] | 132 | UpdateAllSeriesPositions();
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | private void downButton_Click(object sender, System.EventArgs e) {
|
---|
| 137 | if (seriesListView.SelectedIndices.Count == 1 && seriesListView.SelectedIndices[0] < seriesListView.Items.Count - 1) {
|
---|
| 138 | int index = seriesListView.SelectedIndices[0];
|
---|
[6020] | 139 | SuppressEvents = true;
|
---|
| 140 | try {
|
---|
| 141 | seriesListView.BeginUpdate();
|
---|
| 142 | ListViewItem temp = seriesListView.Items[index + 1];
|
---|
| 143 | seriesListView.Items.RemoveAt(index + 1);
|
---|
| 144 | ListViewItem selectedSeriesItem = seriesListView.Items[index];
|
---|
| 145 | seriesListView.Items.RemoveAt(index);
|
---|
| 146 | seriesListView.Items.Insert(index, temp);
|
---|
| 147 | seriesListView.Items.Insert(index + 1, selectedSeriesItem);
|
---|
| 148 | seriesListView.SelectedIndices.Clear();
|
---|
| 149 | seriesListView.EndUpdate();
|
---|
| 150 | } finally { SuppressEvents = false; }
|
---|
| 151 | seriesListView.SelectedIndices.Add(index + 1);
|
---|
[6016] | 152 | UpdateAllSeriesPositions();
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | #region Helpers
|
---|
[7270] | 157 | private void FillSeriesListView() {
|
---|
| 158 | seriesListView.SelectedIndices.Clear();
|
---|
| 159 | foreach (DataRow row in Content.Rows) {
|
---|
| 160 | seriesListView.Items.Add(new ListViewItem(row.Name, 0));
|
---|
| 161 | }
|
---|
| 162 | seriesListView.SelectedIndices.Add(0);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[6016] | 165 | private void UpdateAllSeriesPositions() {
|
---|
[6020] | 166 | Dictionary<string, DataRow> rows = Content.Rows.ToDictionary(x => x.Name);
|
---|
[6016] | 167 | Content.Rows.Clear();
|
---|
| 168 | for (int i = 0; i < seriesListView.Items.Count; i++) {
|
---|
| 169 | ListViewItem item = seriesListView.Items[i];
|
---|
| 170 | Content.Rows.Add(rows[item.Text]);
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
| 173 | #endregion
|
---|
[6010] | 174 | }
|
---|
| 175 | }
|
---|