Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3623 was 3614, checked in by mkommend, 15 years ago

implemented first version of RunConstraints (ticket #970)

File size: 4.5 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.Windows.Forms;
24using HeuristicLab.Collections;
25using HeuristicLab.MainForm;
26using HeuristicLab.Optimization;
27using System.Drawing;
28
29namespace HeuristicLab.Core.Views {
30  [View("ConstraintCollection View")]
31  [Content(typeof(RunCollectionConstraintCollection), true)]
32  [Content(typeof(IItemCollection<IRunCollectionConstraint>), false)]
33  public partial class RunCollectionConstraintCollectionView : ItemCollectionView<IRunCollectionConstraint> {
34    protected CreateParameterDialog createParameterDialog;
35    /// <summary>
36    /// Initializes a new instance of <see cref="VariablesScopeView"/> with caption "Variables Scope View".
37    /// </summary>
38    public RunCollectionConstraintCollectionView() {
39      InitializeComponent();
40      Caption = "RunCollectionConstraintCollection";
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          Auxiliary.ShowErrorMessageBox(ex);
58        }
59      }
60      return null;
61    }
62
63    protected override void RegisterContentEvents() {
64      base.RegisterContentEvents();
65      foreach (IRunCollectionConstraint constraint in Content)
66        constraint.ActiveChanged += new EventHandler(constraint_ActiveChanged);
67    }
68    protected override void DeregisterContentEvents() {
69      base.DeregisterContentEvents();
70      foreach (IRunCollectionConstraint constraint in Content)
71        constraint.ActiveChanged -= new EventHandler(constraint_ActiveChanged);
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        constraint.ActiveChanged += new EventHandler(constraint_ActiveChanged);
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        constraint.ActiveChanged -= new EventHandler(constraint_ActiveChanged);
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        constraint.ActiveChanged -= new EventHandler(constraint_ActiveChanged);
87      foreach (IRunCollectionConstraint constraint in e.Items)
88        constraint.ActiveChanged += new EventHandler(constraint_ActiveChanged);
89    }
90
91    protected virtual void constraint_ActiveChanged(object sender, EventArgs e) {
92      IRunCollectionConstraint constraint = sender as IRunCollectionConstraint;
93      if (constraint != null) {
94        foreach (ListViewItem listViewItem in GetListViewItemsForItem(constraint)) {
95          if (constraint.Active)
96            listViewItem.Font = new Font(listViewItem.Font, FontStyle.Bold);
97          else
98            listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
99        }
100      }
101    }
102
103
104  }
105}
Note: See TracBrowser for help on using the repository browser.