Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10549 was 10549, checked in by psteiner, 10 years ago

Added Views and Classes for Filtering

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