[3884] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9456] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3884] | 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
|
---|
[5829] | 21 |
|
---|
[3884] | 22 | using System;
|
---|
[5829] | 23 | using System.Collections.Generic;
|
---|
[9999] | 24 | using System.ComponentModel;
|
---|
[6612] | 25 | using System.Drawing;
|
---|
| 26 | using System.Linq;
|
---|
[3884] | 27 | using System.Windows.Forms;
|
---|
[6692] | 28 | using HeuristicLab.Core;
|
---|
[6652] | 29 | using HeuristicLab.Core.Views;
|
---|
[3884] | 30 | using HeuristicLab.MainForm;
|
---|
[6652] | 31 | using HeuristicLab.Optimization;
|
---|
[5829] | 32 | using HeuristicLab.Optimization.Views;
|
---|
[9999] | 33 | using HeuristicLab.PluginInfrastructure;
|
---|
[3884] | 34 |
|
---|
| 35 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
[9999] | 36 |
|
---|
[5834] | 37 | [View("DataAnalysisSolution View")]
|
---|
[6652] | 38 | [Content(typeof(DataAnalysisSolution), false)]
|
---|
| 39 | public partial class DataAnalysisSolutionView : NamedItemCollectionView<IResult> {
|
---|
[3884] | 40 | public DataAnalysisSolutionView() {
|
---|
| 41 | InitializeComponent();
|
---|
[6652] | 42 | viewHost.ViewsLabelVisible = false;
|
---|
[3884] | 43 | }
|
---|
| 44 |
|
---|
[5829] | 45 | public new DataAnalysisSolution Content {
|
---|
| 46 | get { return (DataAnalysisSolution)base.Content; }
|
---|
[3884] | 47 | set { base.Content = value; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[6666] | 50 | protected override void SetEnabledStateOfControls() {
|
---|
| 51 | base.SetEnabledStateOfControls();
|
---|
| 52 | addButton.Enabled = false;
|
---|
| 53 | removeButton.Enabled = false;
|
---|
[9999] | 54 | if (Content == null) {
|
---|
| 55 | exportButton.Enabled = false;
|
---|
| 56 | } else {
|
---|
| 57 | exportButton.Enabled = !Locked;
|
---|
| 58 | }
|
---|
[6666] | 59 | }
|
---|
| 60 |
|
---|
| 61 | protected override void RegisterContentEvents() {
|
---|
| 62 | base.RegisterContentEvents();
|
---|
| 63 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
| 64 | }
|
---|
| 65 | protected override void DeregisterContentEvents() {
|
---|
| 66 | base.DeregisterContentEvents();
|
---|
| 67 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
| 68 | }
|
---|
| 69 | private void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
| 70 | OnContentChanged();
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[3884] | 73 | protected override void OnContentChanged() {
|
---|
[5829] | 74 | string selectedName = null;
|
---|
| 75 | if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null && itemsListView.SelectedItems[0].Tag is Type))
|
---|
| 76 | selectedName = itemsListView.SelectedItems[0].Text;
|
---|
| 77 |
|
---|
[3884] | 78 | base.OnContentChanged();
|
---|
[6642] | 79 | AddEvaluationViewTypes();
|
---|
[5829] | 80 |
|
---|
| 81 | //recover selection
|
---|
| 82 | if (selectedName != null) {
|
---|
| 83 | foreach (ListViewItem item in itemsListView.Items) {
|
---|
| 84 | if (item.Tag != null && item.Tag is Type && item.Text == selectedName)
|
---|
| 85 | item.Selected = true;
|
---|
| 86 | }
|
---|
[3884] | 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[6652] | 90 | protected override IResult CreateItem() {
|
---|
| 91 | return null;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[6642] | 94 | protected virtual void AddEvaluationViewTypes() {
|
---|
[6666] | 95 | if (Content != null && !Content.ProblemData.IsEmpty) {
|
---|
[6642] | 96 | var viewTypes = MainFormManager.GetViewTypes(Content.GetType(), true)
|
---|
| 97 | .Where(t => typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(t));
|
---|
| 98 | foreach (var viewType in viewTypes)
|
---|
| 99 | AddViewListViewItem(viewType, ((IDataAnalysisSolutionEvaluationView)Activator.CreateInstance(viewType)).ViewImage);
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[5829] | 103 | protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
|
---|
[6652] | 104 | if (itemsListView.SelectedItems.Count != 1) return;
|
---|
| 105 |
|
---|
| 106 | IResult result = itemsListView.SelectedItems[0].Tag as IResult;
|
---|
| 107 | Type viewType = itemsListView.SelectedItems[0].Tag as Type;
|
---|
| 108 | if (result != null) {
|
---|
| 109 | IContentView view = MainFormManager.MainForm.ShowContent(result, typeof(ResultView));
|
---|
| 110 | if (view != null) {
|
---|
| 111 | view.ReadOnly = ReadOnly;
|
---|
| 112 | view.Locked = Locked;
|
---|
| 113 | }
|
---|
| 114 | } else if (viewType != null) {
|
---|
[5829] | 115 | MainFormManager.MainForm.ShowContent(Content, viewType);
|
---|
[6652] | 116 | }
|
---|
[3884] | 117 | }
|
---|
[3915] | 118 |
|
---|
[5829] | 119 | protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 120 | if (itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
|
---|
| 121 | detailsGroupBox.Enabled = true;
|
---|
| 122 | Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
|
---|
| 123 | viewHost.ViewType = viewType;
|
---|
| 124 | viewHost.Content = Content;
|
---|
| 125 | } else
|
---|
| 126 | base.itemsListView_SelectedIndexChanged(sender, e);
|
---|
[3884] | 127 | }
|
---|
[3915] | 128 |
|
---|
[9999] | 129 |
|
---|
| 130 | private void exportButton_Click(object sender, EventArgs e) {
|
---|
| 131 | var exporters = ApplicationManager.Manager.GetInstances<IDataAnalysisSolutionExporter>()
|
---|
| 132 | .Where(exporter => exporter.Supports(Content)).ToArray();
|
---|
| 133 | exportFileDialog.Filter = exporters.Skip(1)
|
---|
| 134 | .Aggregate(exporters.First().FileTypeFilter, (s, exporter) => s + "|" + exporter.FileTypeFilter);
|
---|
| 135 | var result = exportFileDialog.ShowDialog();
|
---|
| 136 | if (result == DialogResult.OK) {
|
---|
| 137 |
|
---|
| 138 | var name = exportFileDialog.FileName;
|
---|
| 139 | var selectedExporter = exporters.Single(exporter => exporter.FileTypeFilter == exportFileDialog.Filter);
|
---|
| 140 |
|
---|
| 141 | using (BackgroundWorker bg = new BackgroundWorker()) {
|
---|
| 142 | MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Exportion solution to " + name + ".");
|
---|
| 143 | bg.DoWork += (_, __) => selectedExporter.Export(Content, name);
|
---|
| 144 | bg.RunWorkerCompleted += (_, __) => MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
|
---|
| 145 | bg.RunWorkerAsync();
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 |
|
---|
[6612] | 150 | protected void AddViewListViewItem(Type viewType, Image image) {
|
---|
[5829] | 151 | ListViewItem listViewItem = new ListViewItem();
|
---|
| 152 | listViewItem.Text = ViewAttribute.GetViewName(viewType);
|
---|
[6612] | 153 | itemsListView.SmallImageList.Images.Add(image);
|
---|
[5829] | 154 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
| 155 | listViewItem.Tag = viewType;
|
---|
| 156 | itemsListView.Items.Add(listViewItem);
|
---|
| 157 |
|
---|
| 158 | AdjustListViewColumnSizes();
|
---|
[3915] | 159 | }
|
---|
[5829] | 160 |
|
---|
| 161 | protected void RemoveViewListViewItem(Type viewType) {
|
---|
[6612] | 162 | List<ListViewItem> itemsToRemove = itemsListView.Items.Cast<ListViewItem>().Where(item => item.Tag as Type == viewType).ToList();
|
---|
[5829] | 163 |
|
---|
| 164 | foreach (ListViewItem item in itemsToRemove)
|
---|
| 165 | itemsListView.Items.Remove(item);
|
---|
[3884] | 166 | }
|
---|
[6653] | 167 |
|
---|
[8125] | 168 | protected override void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 169 | if (showDetailsCheckBox.Checked && itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
|
---|
| 170 | Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
|
---|
| 171 | viewHost.ViewType = viewType;
|
---|
| 172 | viewHost.Content = Content;
|
---|
| 173 | splitContainer.Panel2Collapsed = false;
|
---|
| 174 | detailsGroupBox.Enabled = true;
|
---|
| 175 | } else base.showDetailsCheckBox_CheckedChanged(sender, e);
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[8798] | 178 | protected override void RebuildImageList() {
|
---|
| 179 | itemsListView.SmallImageList.Images.Clear();
|
---|
| 180 | foreach (ListViewItem listViewItem in itemsListView.Items) {
|
---|
| 181 | IResult result = listViewItem.Tag as IResult;
|
---|
| 182 | Type viewType = listViewItem.Tag as Type;
|
---|
| 183 | if (result != null) itemsListView.SmallImageList.Images.Add(result.ItemImage);
|
---|
| 184 | else if (viewType != null && typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(viewType))
|
---|
| 185 | itemsListView.SmallImageList.Images.Add(((IDataAnalysisSolutionEvaluationView)Activator.CreateInstance(viewType)).ViewImage);
|
---|
| 186 | else itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Nothing);
|
---|
| 187 |
|
---|
| 188 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 |
|
---|
[6653] | 192 | #region drag and drop
|
---|
| 193 | protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
|
---|
| 194 | validDragOperation = false;
|
---|
[6692] | 195 | if (ReadOnly) return;
|
---|
| 196 |
|
---|
| 197 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
| 198 | if (dropData is DataAnalysisProblemData) validDragOperation = true;
|
---|
| 199 | else if (dropData is IValueParameter) {
|
---|
| 200 | var param = (IValueParameter)dropData;
|
---|
| 201 | if (param.Value is DataAnalysisProblemData) validDragOperation = true;
|
---|
[6653] | 202 | }
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
|
---|
| 206 | if (e.Effect != DragDropEffects.None) {
|
---|
[6692] | 207 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
| 208 | if (dropData is DataAnalysisProblemData) {
|
---|
| 209 | DataAnalysisProblemData problemData = (DataAnalysisProblemData)dropData;
|
---|
[6653] | 210 | Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
|
---|
[6692] | 211 | } else if (dropData is IValueParameter) {
|
---|
| 212 | var param = (IValueParameter)dropData;
|
---|
| 213 | DataAnalysisProblemData problemData = param.Value as DataAnalysisProblemData;
|
---|
| 214 | if (problemData != null)
|
---|
| 215 | Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
|
---|
[6653] | 216 | }
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 | #endregion
|
---|
[3884] | 220 | }
|
---|
| 221 | }
|
---|