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 |
|
---|
22 | using System;
|
---|
23 | using System.Drawing;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Collections;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Core.Views;
|
---|
28 | using HeuristicLab.MainForm;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.PluginInfrastructure;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Optimization.Views {
|
---|
33 | [View("ConstraintCollection View")]
|
---|
34 | [Content(typeof(RunCollectionConstraintCollection), true)]
|
---|
35 | [Content(typeof(IItemCollection<IRunCollectionConstraint>), false)]
|
---|
36 | public partial class RunCollectionConstraintCollectionView : ItemCollectionView<IRunCollectionConstraint> {
|
---|
37 | /// <summary>
|
---|
38 | /// Initializes a new instance of <see cref="VariablesScopeView"/> with caption "Variables Scope View".
|
---|
39 | /// </summary>
|
---|
40 | public RunCollectionConstraintCollectionView() {
|
---|
41 | InitializeComponent();
|
---|
42 | itemsGroupBox.Text = "RunCollection Constraints";
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected override IRunCollectionConstraint CreateItem() {
|
---|
46 | if (typeSelectorDialog == null) {
|
---|
47 | typeSelectorDialog = new TypeSelectorDialog();
|
---|
48 | typeSelectorDialog.Caption = "Select RunCollection Constraint";
|
---|
49 | typeSelectorDialog.TypeSelector.Caption = "Available Constraints";
|
---|
50 | typeSelectorDialog.TypeSelector.Configure(typeof(IRunCollectionConstraint), false, true);
|
---|
51 | }
|
---|
52 |
|
---|
53 | if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
54 | try {
|
---|
55 | return (IRunCollectionConstraint)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
|
---|
56 | }
|
---|
57 | catch (Exception ex) {
|
---|
58 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
59 | }
|
---|
60 | }
|
---|
61 | return null;
|
---|
62 | }
|
---|
63 |
|
---|
64 | protected override void RegisterContentEvents() {
|
---|
65 | base.RegisterContentEvents();
|
---|
66 | foreach (IRunCollectionConstraint constraint in Content)
|
---|
67 | RegisterConstraintEvents(constraint);
|
---|
68 | }
|
---|
69 | protected override void DeregisterContentEvents() {
|
---|
70 | base.DeregisterContentEvents();
|
---|
71 | foreach (IRunCollectionConstraint constraint in Content)
|
---|
72 | DeregisterConstraintEvents(constraint);
|
---|
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)
|
---|
77 | RegisterConstraintEvents(constraint);
|
---|
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)
|
---|
82 | DeregisterConstraintEvents(constraint);
|
---|
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)
|
---|
87 | RegisterConstraintEvents(constraint);
|
---|
88 | foreach (IRunCollectionConstraint constraint in e.Items)
|
---|
89 | DeregisterConstraintEvents(constraint);
|
---|
90 | }
|
---|
91 |
|
---|
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 |
|
---|
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 | }
|
---|
110 | this.AdjustListViewColumnSizes();
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|