Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.ExternalEvaluation.Views/3.3/EvaluationCacheView.cs @ 6345

Last change on this file since 6345 was 6291, checked in by epitzer, 13 years ago

fixed synchronization issue in evaluation cache and simplified event handling (#1516)

File size: 2.4 KB
RevLine 
[6169]1using System;
2using System.Windows.Forms;
[6140]3using HeuristicLab.Core.Views;
4using HeuristicLab.MainForm;
[6265]5using System.Threading;
6using System.IO;
7using System.ComponentModel;
[6140]8
[6169]9namespace HeuristicLab.Problems.ExternalEvaluation.Views {
10
[6140]11  [View("EvaluationCacheView")]
12  [Content(typeof(EvaluationCache), IsDefaultView = true)]
[6169]13  public sealed partial class EvaluationCacheView : ParameterizedNamedItemView {
[6140]14
15    public new EvaluationCache Content {
16      get { return (EvaluationCache)base.Content; }
17      set { base.Content = value; }
18    }
19
20    public EvaluationCacheView() {
21      InitializeComponent();
22    }
23
24    protected override void DeregisterContentEvents() {
[6291]25      Content.Changed -= new System.EventHandler(Content_StatusChanged);
[6140]26      base.DeregisterContentEvents();
27    }
28
29    protected override void RegisterContentEvents() {
30      base.RegisterContentEvents();
[6291]31      Content.Changed += new System.EventHandler(Content_StatusChanged);
[6140]32    }
33
34    #region Event Handlers (Content)
[6169]35    void Content_StatusChanged(object sender, EventArgs e) {
36      if (InvokeRequired)
37        Invoke(new EventHandler(Content_StatusChanged), sender, e);
38      else
[6183]39        hits_sizeTextBox.Text = string.Format("{0}/{1} ({2} active)", Content.Hits, Content.Size, Content.ActiveEvaluations);
[6140]40    }
41
42    #endregion
43
44    protected override void OnContentChanged() {
45      base.OnContentChanged();
46      if (Content == null) {
[6169]47        hits_sizeTextBox.Text = "#/#";
[6140]48      } else {
[6169]49        Content_StatusChanged(this, EventArgs.Empty);
[6140]50      }
51    }
52
53    protected override void SetEnabledStateOfControls() {
54      base.SetEnabledStateOfControls();
55      clearButton.Enabled = !ReadOnly && Content != null;
[6265]56      saveButton.Enabled = !ReadOnly && Content != null;
[6140]57    }
58
59    #region Event Handlers (child controls)
[6169]60    private void clearButton_Click(object sender, EventArgs e) {
[6140]61      Content.Reset();
62    }
63    #endregion
[6265]64   
65    private void saveButton_Click(object sender, EventArgs e) {
66      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
67        saveButton.Enabled = false;
68        BackgroundWorker worker = new BackgroundWorker();
69        worker.DoWork += (s, a) => {
70          Content.Save((string)a.Argument);
71        };
72        worker.RunWorkerCompleted += (s, a) => {
73          SetEnabledStateOfControls();
74        };
75        worker.RunWorkerAsync(saveFileDialog.FileName);
76      }
77    }   
[6140]78  }
79}
Note: See TracBrowser for help on using the repository browser.