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 |
|
---|
22 | using System;
|
---|
23 | using System.Windows.Forms;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Core.Views;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 | using HeuristicLab.Persistence.Default.Xml;
|
---|
29 | using HeuristicLab.PluginInfrastructure;
|
---|
30 |
|
---|
31 | namespace 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 | }
|
---|