Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Optimization.Views/3.3/RunCollectionConstraintViews/RunCollectionConstraintCollectionView.cs @ 17953

Last change on this file since 17953 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

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