Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4718 was 4162, checked in by mkommend, 14 years ago

correct RunCollectionConstraintCollectionView to displayed cloned constraints correctly (ticket #1131)

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