Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionConstraintCollectionView.cs @ 4094

Last change on this file since 4094 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 4.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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.Collections;
26using HeuristicLab.Core;
27using HeuristicLab.Core.Views;
28using HeuristicLab.MainForm;
29using HeuristicLab.PluginInfrastructure;
30
31namespace HeuristicLab.Optimization.Views {
32  [View("ConstraintCollection View")]
33  [Content(typeof(RunCollectionConstraintCollection), true)]
34  [Content(typeof(IItemCollection<IRunCollectionConstraint>), false)]
35  public partial class RunCollectionConstraintCollectionView : ItemCollectionView<IRunCollectionConstraint> {
36    /// <summary>
37    /// Initializes a new instance of <see cref="VariablesScopeView"/> with caption "Variables Scope View".
38    /// </summary>
39    public RunCollectionConstraintCollectionView() {
40      InitializeComponent();
41      itemsGroupBox.Text = "RunCollection Constraints";
42    }
43
44    protected override IRunCollectionConstraint CreateItem() {
45      if (typeSelectorDialog == null) {
46        typeSelectorDialog = new TypeSelectorDialog();
47        typeSelectorDialog.Caption = "Select RunCollection Constraint";
48        typeSelectorDialog.TypeSelector.Caption = "Available Constraints";
49        typeSelectorDialog.TypeSelector.Configure(typeof(IRunCollectionConstraint), false, true);
50      }
51
52      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
53        try {
54          return (IRunCollectionConstraint)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
55        }
56        catch (Exception ex) {
57          ErrorHandling.ShowErrorDialog(this, ex);
58        }
59      }
60      return null;
61    }
62
63    protected override void RegisterContentEvents() {
64      base.RegisterContentEvents();
65      foreach (IRunCollectionConstraint constraint in Content)
66        RegisterConstraintEvents(constraint);
67    }
68    protected override void DeregisterContentEvents() {
69      base.DeregisterContentEvents();
70      foreach (IRunCollectionConstraint constraint in Content)
71        DeregisterConstraintEvents(constraint);
72    }
73    protected override void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRunCollectionConstraint> e) {
74      base.Content_ItemsAdded(sender, e);
75      foreach (IRunCollectionConstraint constraint in e.Items)
76        RegisterConstraintEvents(constraint);
77    }
78    protected override void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRunCollectionConstraint> e) {
79      base.Content_ItemsRemoved(sender, e);
80      foreach (IRunCollectionConstraint constraint in e.Items)
81        DeregisterConstraintEvents(constraint);
82    }
83    protected override void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRunCollectionConstraint> e) {
84      base.Content_CollectionReset(sender, e);
85      foreach (IRunCollectionConstraint constraint in e.OldItems)
86        RegisterConstraintEvents(constraint);
87      foreach (IRunCollectionConstraint constraint in e.Items)
88        DeregisterConstraintEvents(constraint);
89    }
90
91    protected virtual void RegisterConstraintEvents(IRunCollectionConstraint constraint) {
92      constraint.ActiveChanged += new EventHandler(constraint_ActiveChanged);
93    }
94
95    protected virtual void DeregisterConstraintEvents(IRunCollectionConstraint constraint) {
96      constraint.ActiveChanged -= new EventHandler(constraint_ActiveChanged);
97    }
98
99    protected virtual void constraint_ActiveChanged(object sender, EventArgs e) {
100      IRunCollectionConstraint constraint = sender as IRunCollectionConstraint;
101      if (constraint != null) {
102        foreach (ListViewItem listViewItem in GetListViewItemsForItem(constraint)) {
103          if (constraint.Active)
104            listViewItem.Font = new Font(listViewItem.Font, FontStyle.Bold);
105          else
106            listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
107        }
108      }
109      this.AdjustListViewColumnSizes();
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.