Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/05/10 00:10:13 (14 years ago)
Author:
mkommend
Message:

implemented first version of RunConstraints (ticket #970)

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionConstraintCollectionView.cs

    r3604 r3614  
    2424using HeuristicLab.Collections;
    2525using HeuristicLab.MainForm;
     26using HeuristicLab.Optimization;
     27using System.Drawing;
    2628
    2729namespace HeuristicLab.Core.Views {
    2830  [View("ConstraintCollection View")]
    29   [Content(typeof(ConstraintCollection), true)]
    30   [Content(typeof(IItemCollection<IConstraint>), false)]
    31   public partial class ConstraintCollectionView : ItemCollectionView<IConstraint> {
     31  [Content(typeof(RunCollectionConstraintCollection), true)]
     32  [Content(typeof(IItemCollection<IRunCollectionConstraint>), false)]
     33  public partial class RunCollectionConstraintCollectionView : ItemCollectionView<IRunCollectionConstraint> {
    3234    protected CreateParameterDialog createParameterDialog;
    3335    /// <summary>
    3436    /// Initializes a new instance of <see cref="VariablesScopeView"/> with caption "Variables Scope View".
    3537    /// </summary>
    36     public ConstraintCollectionView() {
     38    public RunCollectionConstraintCollectionView() {
    3739      InitializeComponent();
    38       Caption = "ConstraintCollection";
    39       itemsGroupBox.Text = "Constraints";
     40      Caption = "RunCollectionConstraintCollection";
     41      itemsGroupBox.Text = "RunCollection Constraints";
    4042    }
    4143
    42     protected override IConstraint CreateItem() {
     44    protected override IRunCollectionConstraint CreateItem() {
    4345      if (typeSelectorDialog == null) {
    4446        typeSelectorDialog = new TypeSelectorDialog();
    45         typeSelectorDialog.Caption = "Select Operator";
    46         typeSelectorDialog.TypeSelector.Caption = "Available Operators";
    47         typeSelectorDialog.TypeSelector.Configure(typeof(IConstraint), false, true);
     47        typeSelectorDialog.Caption = "Select RunCollection Constraint";
     48        typeSelectorDialog.TypeSelector.Caption = "Available Constraints";
     49        typeSelectorDialog.TypeSelector.Configure(typeof(IRunCollectionConstraint), false, true);
    4850      }
    4951
    5052      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    5153        try {
    52           return (IConstraint)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     54          return (IRunCollectionConstraint)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    5355        }
    5456        catch (Exception ex) {
     
    5860      return null;
    5961    }
     62
     63    protected override void RegisterContentEvents() {
     64      base.RegisterContentEvents();
     65      foreach (IRunCollectionConstraint constraint in Content)
     66        constraint.ActiveChanged += new EventHandler(constraint_ActiveChanged);
     67    }
     68    protected override void DeregisterContentEvents() {
     69      base.DeregisterContentEvents();
     70      foreach (IRunCollectionConstraint constraint in Content)
     71        constraint.ActiveChanged -= new EventHandler(constraint_ActiveChanged);
     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)
     76        constraint.ActiveChanged += new EventHandler(constraint_ActiveChanged);
     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)
     81        constraint.ActiveChanged -= new EventHandler(constraint_ActiveChanged);
     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)
     86        constraint.ActiveChanged -= new EventHandler(constraint_ActiveChanged);
     87      foreach (IRunCollectionConstraint constraint in e.Items)
     88        constraint.ActiveChanged += new EventHandler(constraint_ActiveChanged);
     89    }
     90
     91    protected virtual void constraint_ActiveChanged(object sender, EventArgs e) {
     92      IRunCollectionConstraint constraint = sender as IRunCollectionConstraint;
     93      if (constraint != null) {
     94        foreach (ListViewItem listViewItem in GetListViewItemsForItem(constraint)) {
     95          if (constraint.Active)
     96            listViewItem.Font = new Font(listViewItem.Font, FontStyle.Bold);
     97          else
     98            listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
     99        }
     100      }
     101    }
     102
     103
    60104  }
    61105}
Note: See TracChangeset for help on using the changeset viewer.