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