Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/FilterView.cs @ 10586

Last change on this file since 10586 was 10558, checked in by pfleck, 10 years ago
  • removed unnecessary references and using
  • added missing license header
  • formatted code according to HL standards
File size: 3.9 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.Collections.Generic;
24using System.ComponentModel;
25using System.Windows.Forms;
26using HeuristicLab.Core;
27using HeuristicLab.Core.Views;
28using HeuristicLab.DataPreprocessing.Filter;
29using HeuristicLab.MainForm;
30
31namespace HeuristicLab.DataPreprocessing.Views {
32
33  [View("Filter View")]
34  [Content(typeof(FilterContent), false)]
35  public partial class FilterView : ItemView {
36
37    public new FilterContent Content {
38      get { return (FilterContent)base.Content; }
39      set { base.Content = value; }
40    }
41
42    public FilterView() {
43      InitializeComponent();
44      listView1.SmallImageList = new ImageList();
45    }
46
47    protected override void OnContentChanged() {
48      base.OnContentChanged();
49    }
50
51    // Filter Contents
52    private IDictionary<IFilter, ListViewItem> filters = new Dictionary<IFilter, ListViewItem>();
53
54    private void listView1_DoubleClick(object sender, EventArgs e) {
55
56    }
57
58    private void newFilter_Click(object sender, EventArgs e) {
59      //TODO Filter Choose View...
60      IFilter filter = new ComparisonFilter();
61      //filter.FilterName = "ComparisonFilter" + (i++);
62      //filter.PropertyChanged += filter_PropertyChanged;
63
64      ListViewItem filterViewItem = CreateListViewItem(filter);
65      filters.Add(filter, filterViewItem);
66      //add view items to content list view
67      listView1.Items.Add(filterViewItem);
68      //select top filter
69      listView1.SelectedIndices.Add(0);
70    }
71
72    private void filter_PropertyChanged(object sender, PropertyChangedEventArgs e) {
73      ListViewItem listViewItem;
74      try {
75        IFilter filter = (IFilter)sender;
76        filters.TryGetValue(filter, out listViewItem);
77        listViewItem.Name = filter.ItemName;
78      } catch (KeyNotFoundException) {
79        //nothing to do
80      }
81
82    }
83
84    private ListViewItem CreateListViewItem(IFilter filter) {
85      ListViewItem listViewItem = new ListViewItem();
86
87      listViewItem.Text = filter.ItemName;
88      listView1.SmallImageList.Images.Add(filter.ItemImage);
89      listViewItem.ImageIndex = listView1.SmallImageList.Images.Count - 1;
90      listViewItem.Tag = filter;
91      return listViewItem;
92    }
93
94    private void deleteFilter_Click(object sender, EventArgs e) {
95      //delete view item of filter
96      //listView1.Items.Remove();
97      //select top filter
98      if (listView1.Items.Count > 0) {
99        listView1.SelectedItems[0].Remove();
100      }
101      if (listView1.Items.Count > 0) {
102        listView1.SelectedIndices.Add(0);
103      }
104    }
105
106    private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
107      if (listView1.SelectedItems.Count > 0) {
108        ListViewItem listViewItem = (ListViewItem)listView1.SelectedItems[0];
109        this.viewHost.Content = (IItem)listViewItem.Tag;
110      }
111    }
112
113    private void listView1_DoubleClick_1(object sender, EventArgs e) {
114      if (listView1.SelectedItems.Count > 0) {
115        ListViewItem listViewItem = (ListViewItem)listView1.SelectedItems[0];
116        MainFormManager.MainForm.ShowContent((IItem)listViewItem.Tag);
117      }
118    }
119
120  }
121}
Note: See TracBrowser for help on using the repository browser.