Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/UserDefinedAlgorithmView.cs @ 3725

Last change on this file since 3725 was 3725, checked in by abeham, 14 years ago

#893

  • fixed uneditable state of user defined algorithm after execution
File size: 3.8 KB
Line 
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
22using System;
23using System.Windows.Forms;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28using HeuristicLab.Persistence.Default.Xml;
29
30namespace HeuristicLab.Optimization.Views {
31  /// <summary>
32  /// The base class for visual representations of items.
33  /// </summary>
34  [View("UserDefinedAlgorithm View")]
35  [Content(typeof(UserDefinedAlgorithm), true)]
36  public sealed partial class UserDefinedAlgorithmView : EngineAlgorithmView {
37    public new UserDefinedAlgorithm Content {
38      get { return (UserDefinedAlgorithm)base.Content; }
39      set { base.Content = value; }
40    }
41
42    /// <summary>
43    /// Initializes a new instance of <see cref="ItemBaseView"/>.
44    /// </summary>
45    public UserDefinedAlgorithmView() {
46      InitializeComponent();
47    }
48
49    protected override void OnContentChanged() {
50      base.OnContentChanged();
51      if (Content == null)
52        globalScopeView.Content = null;
53      else
54        globalScopeView.Content = Content.GlobalScope;
55      SetEnableStateOfControls();
56    }
57
58    protected override void OnReadOnlyChanged() {
59      base.OnReadOnlyChanged();
60      SetEnableStateOfControls();
61    }
62    protected override void OnLockedChanged() {
63      base.OnLockedChanged();
64      SetEnableStateOfControls();
65    }
66    private void SetEnableStateOfControls() {
67      globalScopeView.Enabled = Content != null;
68      newOperatorGraphButton.Enabled = Content != null && !ReadOnly;
69      openOperatorGraphButton.Enabled = Content != null && !ReadOnly;
70      operatorGraphViewHost.ReadOnly = Content == null || ReadOnly;
71    }
72
73    private void newOperatorGraphButton_Click(object sender, EventArgs e) {
74      Content.OperatorGraph = new OperatorGraph();
75    }
76    private void openOperatorGraphButton_Click(object sender, EventArgs e) {
77      openFileDialog.Title = "Open Operator Graph";
78      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
79        newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = false;
80        operatorGraphViewHost.Enabled = false;
81
82        ContentManager.LoadAsync(openFileDialog.FileName, delegate(IStorableContent content, Exception error) {
83          try {
84            if (error != null) throw error;
85            OperatorGraph operatorGraph = content as OperatorGraph;
86            if (operatorGraph == null)
87              MessageBox.Show(this, "The selected file does not contain an operator graph.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
88            else
89              Content.OperatorGraph = operatorGraph;
90          }
91          catch (Exception ex) {
92            Auxiliary.ShowErrorMessageBox(ex);
93          }
94          finally {
95            Invoke(new Action(delegate() {
96              operatorGraphViewHost.Enabled = true;
97              newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = true;
98            }));
99          }
100        });
101      }
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.