[2851] | 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;
|
---|
[2916] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
[2851] | 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
[2916] | 28 | using HeuristicLab.PluginInfrastructure;
|
---|
[2851] | 29 |
|
---|
[2852] | 30 | namespace HeuristicLab.Optimization.Views {
|
---|
[2851] | 31 | /// <summary>
|
---|
| 32 | /// The base class for visual representations of items.
|
---|
| 33 | /// </summary>
|
---|
[2917] | 34 | [View("EngineAlgorithm View")]
|
---|
[2851] | 35 | [Content(typeof(EngineAlgorithm), true)]
|
---|
| 36 | public partial class EngineAlgorithmView : AlgorithmView {
|
---|
[2916] | 37 | private List<Type> engineTypes;
|
---|
[2851] | 38 |
|
---|
| 39 | public new EngineAlgorithm Content {
|
---|
| 40 | get { return (EngineAlgorithm)base.Content; }
|
---|
| 41 | set { base.Content = value; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | /// <summary>
|
---|
| 45 | /// Initializes a new instance of <see cref="ItemBaseView"/>.
|
---|
| 46 | /// </summary>
|
---|
| 47 | public EngineAlgorithmView() {
|
---|
| 48 | InitializeComponent();
|
---|
| 49 | }
|
---|
[2916] | 50 |
|
---|
[2851] | 51 | /// <summary>
|
---|
| 52 | /// Intializes a new instance of <see cref="ItemBaseView"/> with the given <paramref name="item"/>.
|
---|
| 53 | /// </summary>
|
---|
| 54 | /// <param name="item">The item that should be displayed.</param>
|
---|
| 55 | public EngineAlgorithmView(EngineAlgorithm content)
|
---|
| 56 | : this() {
|
---|
| 57 | Content = content;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected override void DeregisterContentEvents() {
|
---|
| 61 | Content.EngineChanged -= new System.EventHandler(Content_EngineChanged);
|
---|
| 62 | base.DeregisterContentEvents();
|
---|
| 63 | }
|
---|
| 64 | protected override void RegisterContentEvents() {
|
---|
| 65 | base.RegisterContentEvents();
|
---|
| 66 | Content.EngineChanged += new System.EventHandler(Content_EngineChanged);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | protected override void OnContentChanged() {
|
---|
| 70 | base.OnContentChanged();
|
---|
[2916] | 71 |
|
---|
| 72 | if (engineTypes == null) {
|
---|
| 73 | engineTypes = ApplicationManager.Manager.GetTypes(typeof(IEngine)).
|
---|
| 74 | OrderBy(x => {
|
---|
| 75 | string name = ItemAttribute.GetName(x);
|
---|
| 76 | if (name != null) return name;
|
---|
| 77 | else return x.GetPrettyName();
|
---|
| 78 | }).ToList();
|
---|
| 79 | foreach (Type t in engineTypes) {
|
---|
| 80 | string name = ItemAttribute.GetName(t);
|
---|
| 81 | if (name == null) name = t.GetPrettyName();
|
---|
| 82 | engineComboBox.Items.Add(name);
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[2851] | 86 | if (Content == null) {
|
---|
[2916] | 87 | engineViewHost.Content = null;
|
---|
[2998] | 88 | createUserDefinedAlgorithmButton.Enabled = false;
|
---|
[2851] | 89 | } else {
|
---|
[2916] | 90 | if (Content.Engine == null)
|
---|
[3214] | 91 | engineComboBox.SelectedIndex = -1;
|
---|
[2916] | 92 | else
|
---|
| 93 | engineComboBox.SelectedIndex = engineTypes.IndexOf(Content.Engine.GetType());
|
---|
[2949] | 94 | engineViewHost.ViewType = null;
|
---|
[2916] | 95 | engineViewHost.Content = Content.Engine;
|
---|
[2998] | 96 | createUserDefinedAlgorithmButton.Enabled = true;
|
---|
[2851] | 97 | }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[3262] | 100 | protected override void Content_ExecutionStateChanged(object sender, EventArgs e) {
|
---|
[2851] | 101 | if (InvokeRequired)
|
---|
[3262] | 102 | Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);
|
---|
[2998] | 103 | else {
|
---|
[3262] | 104 | createUserDefinedAlgorithmButton.Enabled = Content.ExecutionState != ExecutionState.Started;
|
---|
| 105 | engineComboBox.Enabled = Content.ExecutionState != ExecutionState.Started;
|
---|
| 106 | engineViewHost.Enabled = Content.ExecutionState != ExecutionState.Started;
|
---|
| 107 | base.Content_ExecutionStateChanged(sender, e);
|
---|
[2998] | 108 | }
|
---|
| 109 | }
|
---|
| 110 | protected virtual void Content_EngineChanged(object sender, System.EventArgs e) {
|
---|
| 111 | if (InvokeRequired)
|
---|
[2851] | 112 | Invoke(new EventHandler(Content_EngineChanged), sender, e);
|
---|
[2916] | 113 | else {
|
---|
| 114 | if (Content.Engine == null)
|
---|
[3214] | 115 | engineComboBox.SelectedIndex = -1;
|
---|
[2916] | 116 | else
|
---|
| 117 | engineComboBox.SelectedIndex = engineTypes.IndexOf(Content.Engine.GetType());
|
---|
[2949] | 118 | engineViewHost.ViewType = null;
|
---|
[2916] | 119 | engineViewHost.Content = Content.Engine;
|
---|
| 120 | }
|
---|
[2851] | 121 | }
|
---|
| 122 |
|
---|
[2998] | 123 | protected virtual void engineComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[2916] | 124 | if (Content != null) {
|
---|
[3214] | 125 | if (engineComboBox.SelectedIndex == -1)
|
---|
[2916] | 126 | Content.Engine = null;
|
---|
[3214] | 127 | else {
|
---|
| 128 | Type t = engineTypes[engineComboBox.SelectedIndex];
|
---|
| 129 | if ((Content.Engine == null) || (Content.Engine.GetType() != t))
|
---|
| 130 | Content.Engine = (IEngine)Activator.CreateInstance(t);
|
---|
| 131 | }
|
---|
[2851] | 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[2998] | 135 | protected virtual void createUserDefinedAlgorithmButton_Click(object sender, EventArgs e) {
|
---|
[2864] | 136 | MainFormManager.CreateDefaultView(Content.CreateUserDefinedAlgorithm()).Show();
|
---|
| 137 | }
|
---|
[2851] | 138 | }
|
---|
| 139 | }
|
---|