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