Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4011 was 3904, checked in by mkommend, 14 years ago

Added SetEnabledStateOfControls as protected virtual method in !View. Therefore the overloading of OnReadOnlyChanged and OnLockedChanged got obsolete in most views, because the method got called in the !View respectively ContentView. (ticket #1021)

File size: 3.6 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    }
57
58    protected override void SetEnabledStateOfControls() {
59      base.SetEnabledStateOfControls();
60      globalScopeView.Enabled = Content != null;
61      newOperatorGraphButton.Enabled = Content != null && !ReadOnly;
62      openOperatorGraphButton.Enabled = Content != null && !ReadOnly;
63      operatorGraphViewHost.ReadOnly = Content == null || ReadOnly;
64    }
65
66    private void newOperatorGraphButton_Click(object sender, EventArgs e) {
67      Content.OperatorGraph = new OperatorGraph();
68    }
69    private void openOperatorGraphButton_Click(object sender, EventArgs e) {
70      openFileDialog.Title = "Open Operator Graph";
71      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
72        newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = false;
73        operatorGraphViewHost.Enabled = false;
74
75        ContentManager.LoadAsync(openFileDialog.FileName, delegate(IStorableContent content, Exception error) {
76          try {
77            if (error != null) throw error;
78            OperatorGraph operatorGraph = content as OperatorGraph;
79            if (operatorGraph == null)
80              MessageBox.Show(this, "The selected file does not contain an operator graph.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
81            else
82              Content.OperatorGraph = operatorGraph;
83          }
84          catch (Exception ex) {
85            ErrorHandling.ShowErrorDialog(this, ex);
86          }
87          finally {
88            Invoke(new Action(delegate() {
89              operatorGraphViewHost.Enabled = true;
90              newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = true;
91            }));
92          }
93        });
94      }
95    }
96  }
97}
Note: See TracBrowser for help on using the repository browser.