Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4054 was 3797, checked in by mkommend, 14 years ago

corrected namespaces and removed resources files in HL 3.3 solution (ticket #893)

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