Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3758 was 3758, checked in by swagner, 14 years ago

Implemented ErrorDialog and OperatorExecutionException (#1007)

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