Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataView.cs @ 12467

Last change on this file since 12467 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

File size: 4.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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
22using System;
23using System.Linq;
24using System.Text;
25using System.Windows.Forms;
26using HeuristicLab.Core;
27using HeuristicLab.Core.Views;
28using HeuristicLab.Data;
29using HeuristicLab.MainForm;
30using HeuristicLab.MainForm.WindowsForms;
31using HeuristicLab.PluginInfrastructure;
32
33namespace HeuristicLab.Problems.DataAnalysis.Views {
34  [View("Problem Data View")]
35  [Content(typeof(DataAnalysisProblemData), true)]
36  public partial class ProblemDataView : ParameterizedNamedItemView {
37
38    public new DataAnalysisProblemData Content {
39      get { return (DataAnalysisProblemData)base.Content; }
40      set { base.Content = value; }
41    }
42
43    public ProblemDataView() {
44      InitializeComponent();
45    }
46
47    protected void FeatureCorrelationButton_Click(object sender, System.EventArgs e) {
48      Type viewType = MainFormManager.GetViewTypes(this.Content.GetType(), true).FirstOrDefault(t => typeof(FeatureCorrelationView).IsAssignableFrom(t));
49      MainFormManager.MainForm.ShowContent(Content, viewType);
50    }
51
52    protected void parameterCollectionView_DragDrop(object sender, DragEventArgs e) {
53      if (e.Effect != DragDropEffects.None) {
54        var stringValueList = (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IFixedValueParameter).Value as ICheckedItemList<StringValue>;
55        SetInputVariables(stringValueList);
56      }
57    }
58
59    private void SetInputVariables(ICheckedItemList<StringValue> stringValueList) {
60      var inputVariables = Content.InputVariables;
61      var stringValues = stringValueList.Select(x => x.Value);
62      var notContainedVariables = inputVariables.Where(x => !stringValues.Contains(x.Value));
63
64      if (notContainedVariables.Count() != 0) {
65        StringBuilder strBuilder = new StringBuilder();
66        foreach (var variable in notContainedVariables) {
67          strBuilder.Append(variable.Value + ", ");
68        }
69        strBuilder.Remove(strBuilder.Length - 2, 2);
70        MessageBox.Show(String.Format("There was an error while changing the input variables. The following input " +
71          "variables have not been contained {0}", strBuilder.ToString()), "Error while changing the input variables",
72          MessageBoxButtons.OK, MessageBoxIcon.Warning);
73      } else {
74        var checkedItems = stringValueList.CheckedItems.Select(x => x.Value.Value);
75        var setChecked = inputVariables.Where(x => checkedItems.Contains(x.Value));
76        foreach (var variable in inputVariables) {
77          if (setChecked.Contains(variable) && !inputVariables.ItemChecked(variable)) {
78            inputVariables.SetItemCheckedState(variable, true);
79          } else if (!setChecked.Contains(variable) && inputVariables.ItemChecked(variable)) {
80            inputVariables.SetItemCheckedState(variable, false);
81          }
82        }
83      }
84    }
85
86    protected void parameterCollectionView_DragEnterOver(object sender, DragEventArgs e) {
87      e.Effect = DragDropEffects.None;
88      if (ReadOnly)
89        return;
90      if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) == null)
91        return;
92
93      var parameter = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IFixedValueParameter;
94      if (parameter == null)
95        return;
96
97      var stringValueList = parameter.Value as ICheckedItemList<StringValue>;
98      if (stringValueList == null)
99        return;
100
101      e.Effect = e.AllowedEffect;
102    }
103
104    private void DataPreprocessingButton_Click(object sender, EventArgs e) {
105      var preprocessingStarters = ApplicationManager.Manager.GetInstances<IDataPreprocessorStarter>();
106      var starter = preprocessingStarters.FirstOrDefault();
107      // TODO: handle possible multiple starters
108      if (starter != null) {
109        starter.Start(Content, this);
110      }
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.