[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 | }
|
---|
| 56 | protected override void DeregisterContentEvents() {
|
---|
| 57 | base.DeregisterContentEvents();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[3884] | 60 | protected override void OnContentChanged() {
|
---|
[5829] | 61 | string selectedName = null;
|
---|
| 62 | if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null && itemsListView.SelectedItems[0].Tag is Type))
|
---|
| 63 | selectedName = itemsListView.SelectedItems[0].Text;
|
---|
| 64 |
|
---|
[3884] | 65 | base.OnContentChanged();
|
---|
[6642] | 66 | AddEvaluationViewTypes();
|
---|
[5829] | 67 |
|
---|
| 68 | //recover selection
|
---|
| 69 | if (selectedName != null) {
|
---|
| 70 | foreach (ListViewItem item in itemsListView.Items) {
|
---|
| 71 | if (item.Tag != null && item.Tag is Type && item.Text == selectedName)
|
---|
| 72 | item.Selected = true;
|
---|
| 73 | }
|
---|
[3884] | 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[6652] | 77 | protected override IResult CreateItem() {
|
---|
| 78 | return null;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
[6642] | 81 | protected virtual void AddEvaluationViewTypes() {
|
---|
[6666] | 82 | if (Content != null && !Content.ProblemData.IsEmpty) {
|
---|
[6642] | 83 | var viewTypes = MainFormManager.GetViewTypes(Content.GetType(), true)
|
---|
| 84 | .Where(t => typeof(IDataAnalysisSolutionEvaluationView).IsAssignableFrom(t));
|
---|
| 85 | foreach (var viewType in viewTypes)
|
---|
| 86 | AddViewListViewItem(viewType, ((IDataAnalysisSolutionEvaluationView)Activator.CreateInstance(viewType)).ViewImage);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[5829] | 90 | protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
|
---|
[6652] | 91 | if (itemsListView.SelectedItems.Count != 1) return;
|
---|
| 92 |
|
---|
| 93 | IResult result = itemsListView.SelectedItems[0].Tag as IResult;
|
---|
| 94 | Type viewType = itemsListView.SelectedItems[0].Tag as Type;
|
---|
| 95 | if (result != null) {
|
---|
| 96 | IContentView view = MainFormManager.MainForm.ShowContent(result, typeof(ResultView));
|
---|
| 97 | if (view != null) {
|
---|
| 98 | view.ReadOnly = ReadOnly;
|
---|
| 99 | view.Locked = Locked;
|
---|
| 100 | }
|
---|
| 101 | } else if (viewType != null) {
|
---|
[5829] | 102 | MainFormManager.MainForm.ShowContent(Content, viewType);
|
---|
[6652] | 103 | }
|
---|
[3884] | 104 | }
|
---|
[3915] | 105 |
|
---|
[5829] | 106 | protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 107 | if (itemsListView.SelectedItems.Count == 1 && itemsListView.SelectedItems[0].Tag is Type) {
|
---|
| 108 | detailsGroupBox.Enabled = true;
|
---|
| 109 | Type viewType = (Type)itemsListView.SelectedItems[0].Tag;
|
---|
| 110 | viewHost.ViewType = viewType;
|
---|
| 111 | viewHost.Content = Content;
|
---|
| 112 | } else
|
---|
| 113 | base.itemsListView_SelectedIndexChanged(sender, e);
|
---|
[3884] | 114 | }
|
---|
[3915] | 115 |
|
---|
[6612] | 116 | protected void AddViewListViewItem(Type viewType, Image image) {
|
---|
[5829] | 117 | ListViewItem listViewItem = new ListViewItem();
|
---|
| 118 | listViewItem.Text = ViewAttribute.GetViewName(viewType);
|
---|
[6612] | 119 | itemsListView.SmallImageList.Images.Add(image);
|
---|
[5829] | 120 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
| 121 | listViewItem.Tag = viewType;
|
---|
| 122 | itemsListView.Items.Add(listViewItem);
|
---|
| 123 |
|
---|
| 124 | AdjustListViewColumnSizes();
|
---|
[3915] | 125 | }
|
---|
[5829] | 126 |
|
---|
| 127 | protected void RemoveViewListViewItem(Type viewType) {
|
---|
[6612] | 128 | List<ListViewItem> itemsToRemove = itemsListView.Items.Cast<ListViewItem>().Where(item => item.Tag as Type == viewType).ToList();
|
---|
[5829] | 129 |
|
---|
| 130 | foreach (ListViewItem item in itemsToRemove)
|
---|
| 131 | itemsListView.Items.Remove(item);
|
---|
[3884] | 132 | }
|
---|
[6653] | 133 |
|
---|
| 134 | #region drag and drop
|
---|
| 135 | protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
|
---|
| 136 | validDragOperation = false;
|
---|
[6692] | 137 | if (ReadOnly) return;
|
---|
| 138 |
|
---|
| 139 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
| 140 | if (dropData is DataAnalysisProblemData) validDragOperation = true;
|
---|
| 141 | else if (dropData is IValueParameter) {
|
---|
| 142 | var param = (IValueParameter)dropData;
|
---|
| 143 | if (param.Value is DataAnalysisProblemData) validDragOperation = true;
|
---|
[6653] | 144 | }
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
|
---|
| 148 | if (e.Effect != DragDropEffects.None) {
|
---|
[6692] | 149 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
| 150 | if (dropData is DataAnalysisProblemData) {
|
---|
| 151 | DataAnalysisProblemData problemData = (DataAnalysisProblemData)dropData;
|
---|
[6653] | 152 | Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
|
---|
[6692] | 153 | } else if (dropData is IValueParameter) {
|
---|
| 154 | var param = (IValueParameter)dropData;
|
---|
| 155 | DataAnalysisProblemData problemData = param.Value as DataAnalysisProblemData;
|
---|
| 156 | if (problemData != null)
|
---|
| 157 | Content.ProblemData = (DataAnalysisProblemData)problemData.Clone();
|
---|
[6653] | 158 | }
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 | #endregion
|
---|
[3884] | 162 | }
|
---|
| 163 | }
|
---|