Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP.Grammar.Editor/HeuristicLab.Optimization.Views/3.3/RunCollectionModificationEvaluatorView.cs @ 6675

Last change on this file since 6675 was 6675, checked in by mkommend, 13 years ago

#1479: Integrated trunk changes.

File size: 2.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.Common;
10using HeuristicLab.Core;
11using HeuristicLab.Core.Views;
12using HeuristicLab.MainForm;
13
14namespace HeuristicLab.Optimization.Views {
15
16  [View("RunCollection Calculator View")]
17  [Content(typeof(RunCollectionModificationEvaluator), IsDefaultView = true)]
18  public sealed partial class RunCollectionModificationEvaluatorView : NamedItemView {
19
20    public new RunCollectionModificationEvaluator Content {
21      get { return (RunCollectionModificationEvaluator)base.Content; }
22      set { base.Content = value; }
23    }
24
25    public RunCollectionModificationEvaluatorView() {
26      InitializeComponent();
27    }
28
29    protected override void DeregisterContentEvents() {
30      Content.RunCollectionParameter.ValueChanged -= new EventHandler(RunCollection_Changed);
31      Content.ModifiersParameter.ValueChanged -= new EventHandler(Modifiers_Changed);
32      base.DeregisterContentEvents();
33    }
34
35    protected override void RegisterContentEvents() {
36      base.RegisterContentEvents();
37      Content.RunCollectionParameter.ValueChanged += new EventHandler(RunCollection_Changed);
38      Content.ModifiersParameter.ValueChanged += new EventHandler(Modifiers_Changed);
39    }
40
41    #region Event Handlers (Content)
42    private void RunCollection_Changed(object sender, EventArgs args) {
43      if (InvokeRequired)
44        Invoke(new EventHandler(RunCollection_Changed), sender, args);
45      else
46        runCollectionViewHost.Content = Content.RunCollection;
47    }
48    private void Modifiers_Changed(object sender, EventArgs args) {
49      if (InvokeRequired)
50        Invoke(new EventHandler(Modifiers_Changed), sender, args);
51      else
52        modifiersViewHost.Content = Content.Modifiers;
53    }
54    #endregion
55
56    protected override void OnContentChanged() {
57      base.OnContentChanged();
58      if (Content == null) {
59        runCollectionViewHost.Content = null;
60        modifiersViewHost.Content = null;
61      } else {
62        runCollectionViewHost.Content = Content.RunCollection;
63        modifiersViewHost.Content = Content.Modifiers;
64      }
65    }
66
67    protected override void SetEnabledStateOfControls() {
68      base.SetEnabledStateOfControls();
69      evaluateButton.Enabled = Content != null;
70    }
71
72    #region Event Handlers (child controls)
73    private void evaluateButton_Click(object sender, EventArgs e) {
74      evaluateButton.Enabled = false;
75      var worker = new BackgroundWorker();
76      worker.DoWork += (s, a) => Content.Evaluate();
77      worker.RunWorkerCompleted += (s, a) => { evaluateButton.Enabled = Content != null; };
78      worker.RunWorkerAsync();
79    }       
80    #endregion
81
82  }
83}
Note: See TracBrowser for help on using the repository browser.