Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataView.cs @ 17526

Last change on this file since 17526 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 4.6 KB
RevLine 
[8578]1#region License Information
2/* HeuristicLab
[17181]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[8578]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
[8593]22using System;
23using System.Linq;
24using System.Text;
[8578]25using System.Windows.Forms;
[8593]26using HeuristicLab.Core;
[8578]27using HeuristicLab.Core.Views;
[8593]28using HeuristicLab.Data;
[8578]29using HeuristicLab.MainForm;
30using HeuristicLab.MainForm.WindowsForms;
[11159]31using HeuristicLab.PluginInfrastructure;
[8578]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
[8593]47    protected void FeatureCorrelationButton_Click(object sender, System.EventArgs e) {
[8833]48      Type viewType = MainFormManager.GetViewTypes(this.Content.GetType(), true).FirstOrDefault(t => typeof(FeatureCorrelationView).IsAssignableFrom(t));
[8689]49      MainFormManager.MainForm.ShowContent(Content, viewType);
[8578]50    }
[8593]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    }
[11159]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    }
[8578]112  }
113}
Note: See TracBrowser for help on using the repository browser.