1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 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;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Data;
|
---|
26 | using System.Drawing;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.MainForm;
|
---|
31 | using HeuristicLab.Data.Views;
|
---|
32 | using HeuristicLab.Collections;
|
---|
33 | using HeuristicLab.Core;
|
---|
34 |
|
---|
35 | namespace HeuristicLab.Optimization.Views {
|
---|
36 | [View("RunCollection Tabular View")]
|
---|
37 | [Content(typeof(RunCollection), false)]
|
---|
38 | public partial class RunCollectionTabularView : StringConvertibleMatrixView {
|
---|
39 | public RunCollectionTabularView() {
|
---|
40 | InitializeComponent();
|
---|
41 | Caption = "Run Collection";
|
---|
42 | this.dataGridView.RowHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(dataGridView_RowHeaderMouseDoubleClick);
|
---|
43 | base.ReadOnly = true;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public RunCollectionTabularView(RunCollection content)
|
---|
47 | : this() {
|
---|
48 | Content = content;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public override bool ReadOnly {
|
---|
52 | get { return base.ReadOnly; }
|
---|
53 | set { /*not needed because results are always readonly */}
|
---|
54 | }
|
---|
55 |
|
---|
56 | public new RunCollection Content {
|
---|
57 | get { return (RunCollection)base.Content; }
|
---|
58 | set { base.Content = value; }
|
---|
59 | }
|
---|
60 |
|
---|
61 | private void dataGridView_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) {
|
---|
62 | if (e.RowIndex > 0) {
|
---|
63 | IContentView view = MainFormManager.CreateDefaultView(Content.ElementAt(e.RowIndex));
|
---|
64 | if (view != null) {
|
---|
65 | view.ReadOnly = this.ReadOnly;
|
---|
66 | view.Locked = this.Locked;
|
---|
67 | view.Show();
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | protected override int[] Sort(IEnumerable<KeyValuePair<int, SortOrder>> sortedColumns) {
|
---|
74 | int[] newSortedIndex = Enumerable.Range(0, Content.Count).ToArray();
|
---|
75 | RunCollectionRowComparer rowComparer = new RunCollectionRowComparer();
|
---|
76 | if (sortedColumns.Count() != 0) {
|
---|
77 | rowComparer.SortedIndizes = sortedColumns;
|
---|
78 | rowComparer.Matrix = Content;
|
---|
79 | Array.Sort(newSortedIndex, rowComparer);
|
---|
80 | }
|
---|
81 | return newSortedIndex;
|
---|
82 | }
|
---|
83 |
|
---|
84 | public class RunCollectionRowComparer : IComparer<int> {
|
---|
85 | public RunCollectionRowComparer() {
|
---|
86 | }
|
---|
87 |
|
---|
88 | private List<KeyValuePair<int, SortOrder>> sortedIndizes;
|
---|
89 | public IEnumerable<KeyValuePair<int, SortOrder>> SortedIndizes {
|
---|
90 | get { return this.sortedIndizes; }
|
---|
91 | set { sortedIndizes = new List<KeyValuePair<int, SortOrder>>(value); }
|
---|
92 | }
|
---|
93 | private RunCollection matrix;
|
---|
94 | public RunCollection Matrix {
|
---|
95 | get { return this.matrix; }
|
---|
96 | set { this.matrix = value; }
|
---|
97 | }
|
---|
98 |
|
---|
99 | public int Compare(int x, int y) {
|
---|
100 | int result = 0;
|
---|
101 | IItem value1, value2;
|
---|
102 | IComparable comparable1, comparable2;
|
---|
103 |
|
---|
104 | if (matrix == null)
|
---|
105 | throw new InvalidOperationException("Could not sort IStringConvertibleMatrix if the matrix member is null.");
|
---|
106 | if (sortedIndizes == null)
|
---|
107 | return 0;
|
---|
108 |
|
---|
109 | foreach (KeyValuePair<int, SortOrder> pair in sortedIndizes.Where(p => p.Value != SortOrder.None)) {
|
---|
110 | value1 = matrix.GetValue(x, pair.Key);
|
---|
111 | value2 = matrix.GetValue(y, pair.Key);
|
---|
112 | comparable1 = value1 as IComparable;
|
---|
113 | comparable2 = value2 as IComparable;
|
---|
114 | if (comparable1 != null)
|
---|
115 | result = comparable1.CompareTo(comparable2);
|
---|
116 | else {
|
---|
117 | string string1 = value1 != null ? value1.ToString() : string.Empty;
|
---|
118 | string string2 = value2 != null ? value2.ToString() : string.Empty;
|
---|
119 | result = string1.CompareTo(string2);
|
---|
120 | }
|
---|
121 | if (pair.Value == SortOrder.Descending)
|
---|
122 | result *= -1;
|
---|
123 | if (result != 0)
|
---|
124 | return result;
|
---|
125 | }
|
---|
126 | return result;
|
---|
127 | }
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|