Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HLScript/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataView.cs @ 11008

Last change on this file since 11008 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

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