[6010] | 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 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
[6020] | 23 | using System.Linq;
|
---|
[6010] | 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.Common.Resources;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Analysis.Views {
|
---|
| 28 | public partial class DataTableVisualPropertiesDialog : Form {
|
---|
[6020] | 29 | protected bool SuppressEvents { get; set; }
|
---|
[6010] | 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();
|
---|
[6016] | 36 | upButton.Text = string.Empty;
|
---|
| 37 | upButton.Image = VSImageLibrary.ArrowUp;
|
---|
| 38 | downButton.Text = string.Empty;
|
---|
| 39 | downButton.Image = VSImageLibrary.ArrowDown;
|
---|
[6010] | 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();
|
---|
[6012] | 49 | dataTableVisualPropertiesControl.Content = Content.VisualProperties;
|
---|
[6010] | 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) {
|
---|
[6020] | 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 | }
|
---|
[6010] | 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 | }
|
---|
[6011] | 81 | Content.VisualProperties = originalDataTableVPs;
|
---|
[6010] | 82 | Close();
|
---|
| 83 | }
|
---|
[6016] | 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];
|
---|
[6020] | 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);
|
---|
[6016] | 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];
|
---|
[6020] | 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);
|
---|
[6016] | 121 | UpdateAllSeriesPositions();
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | #region Helpers
|
---|
| 126 | private void UpdateAllSeriesPositions() {
|
---|
[6020] | 127 | Dictionary<string, DataRow> rows = Content.Rows.ToDictionary(x => x.Name);
|
---|
[6016] | 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
|
---|
[6010] | 135 | }
|
---|
| 136 | }
|
---|