Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveHiveEngine/HeuristicLab.Optimization.Views/3.3/RunCollectionConstraintCollectionView.cs @ 13067

Last change on this file since 13067 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Drawing;
24using System.Windows.Forms;
25using HeuristicLab.Core;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28using HeuristicLab.PluginInfrastructure;
29
30namespace HeuristicLab.Optimization.Views {
31  [View("ConstraintCollection View")]
32  [Content(typeof(RunCollectionConstraintCollection), true)]
33  [Content(typeof(IItemCollection<IRunCollectionConstraint>), false)]
34  public partial class RunCollectionConstraintCollectionView : ItemCollectionView<IRunCollectionConstraint> {
35    public RunCollectionConstraintCollectionView() {
36      InitializeComponent();
37      itemsGroupBox.Text = "RunCollection Constraints";
38    }
39
40    protected override IRunCollectionConstraint CreateItem() {
41      if (typeSelectorDialog == null) {
42        typeSelectorDialog = new TypeSelectorDialog();
43        typeSelectorDialog.Caption = "Select RunCollection Constraint";
44        typeSelectorDialog.TypeSelector.Caption = "Available Constraints";
45        typeSelectorDialog.TypeSelector.Configure(typeof(IRunCollectionConstraint), false, true);
46      }
47
48      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
49        try {
50          return (IRunCollectionConstraint)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
51        }
52        catch (Exception ex) {
53          ErrorHandling.ShowErrorDialog(this, ex);
54        }
55      }
56      return null;
57    }
58
59    protected override ListViewItem CreateListViewItem(IRunCollectionConstraint item) {
60      ListViewItem listViewItem = base.CreateListViewItem(item);
61      if (item != null) {
62        listViewItem.Font = item.Active ? new Font(listViewItem.Font, FontStyle.Bold) : new Font(listViewItem.Font, FontStyle.Regular);
63      }
64      return listViewItem;
65    }
66
67    protected override void DeregisterItemEvents(IRunCollectionConstraint item) {
68      item.ActiveChanged -= new EventHandler(Item_ActiveChanged);
69      base.DeregisterItemEvents(item);
70    }
71    protected override void RegisterItemEvents(IRunCollectionConstraint item) {
72      base.RegisterItemEvents(item);
73      item.ActiveChanged += new EventHandler(Item_ActiveChanged);
74    }
75
76    protected virtual void Item_ActiveChanged(object sender, EventArgs e) {
77      IRunCollectionConstraint constraint = (IRunCollectionConstraint)sender;
78      foreach (ListViewItem listViewItem in GetListViewItemsForItem(constraint)) {
79        if (constraint.Active)
80          listViewItem.Font = new Font(listViewItem.Font, FontStyle.Bold);
81        else
82          listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
83      }
84      this.AdjustListViewColumnSizes();
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.