[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 |
|
---|
| 139 | #region drag and drop
|
---|
| 140 | protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
|
---|
| 141 | validDragOperation = false;
|
---|
[6692] | 142 | if (ReadOnly) return;
|
---|
| 143 |
|
---|
| 144 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
| 145 | if (dropData is DataAnalysisProblemData) validDragOperation = true;
|
---|
| 146 | else if (dropData is IValueParameter) {
|
---|
| 147 | var param = (IValueParameter)dropData;
|
---|
| 148 | if (param.Value is DataAnalysisProblemData) validDragOperation = true;
|
---|
[6653] | 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
|
---|
| 153 | if (e.Effect != DragDropEffects.None) {
|
---|
[6692] | 154 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
| 155 | if (dropData is DataAnalysisProblemData) {
|
---|
| 156 | DataAnalysisProblemData problemData = (DataAnalysisProblemData)dropData;
|
---|
[6653] | 157 | Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
|
---|
[6692] | 158 | } else if (dropData is IValueParameter) {
|
---|
| 159 | var param = (IValueParameter)dropData;
|
---|
| 160 | DataAnalysisProblemData problemData = param.Value as DataAnalysisProblemData;
|
---|
| 161 | if (problemData != null)
|
---|
| 162 | Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
|
---|
[6653] | 163 | }
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | #endregion
|
---|
[3884] | 167 | }
|
---|
| 168 | }
|
---|