#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.ComponentModel;
using System.Windows.Forms;
using HeuristicLab.Common;
using HeuristicLab.Core.Views;
using HeuristicLab.MainForm;
using HeuristicLab.Optimization;
using HeuristicLab.PluginInfrastructure;
namespace HeuristicLab.OptimizationExpertSystem.Views {
[View("Expert-system Optimizer View")]
[Content(typeof(ExpertSystem), IsDefaultView = true)]
public partial class ExpertSystemView : NamedItemView {
protected TypeSelectorDialog problemTypeSelectorDialog;
protected virtual bool SuppressEvents { get; set; }
public new ExpertSystem Content {
get { return (ExpertSystem)base.Content; }
set { base.Content = value; }
}
public ExpertSystemView() {
InitializeComponent();
}
protected override void Dispose(bool disposing) {
if (disposing) {
if (problemTypeSelectorDialog != null) problemTypeSelectorDialog.Dispose();
if (components != null) components.Dispose();
}
base.Dispose(disposing);
}
protected override void DeregisterContentEvents() {
Content.PropertyChanged -= Content_PropertyChanged;
Content.SuggestedInstances.CollectionReset -= SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsAdded -= SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsMoved -= SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsRemoved -= SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsReplaced -= SuggestedInstancesOnChanged;
base.DeregisterContentEvents();
}
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.PropertyChanged += Content_PropertyChanged;
Content.SuggestedInstances.CollectionReset += SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsAdded += SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsMoved += SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsRemoved += SuggestedInstancesOnChanged;
Content.SuggestedInstances.ItemsReplaced += SuggestedInstancesOnChanged;
}
protected override void OnContentChanged() {
base.OnContentChanged();
SuppressEvents = true;
try {
if (Content == null) {
maxEvaluationsTextBox.Text = String.Empty;
problemViewHost.Content = null;
algorithmViewHost.Content = null;
runsView.Content = null;
algorithmInstancesViewHost.Content = null;
} else {
maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString();
problemViewHost.Content = Content.Problem;
runsView.Content = Content.Runs;
algorithmInstancesViewHost.Content = Content.AlgorithmInstances;
}
} finally { SuppressEvents = false; }
UpdateSuggestedInstancesCombobox();
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
maxEvaluationsTextBox.Enabled = Content != null && !ReadOnly && !Locked;
newProblemButton.Enabled = Content != null && !ReadOnly && !Locked;
openProblemButton.Enabled = Content != null && !ReadOnly && !Locked;
problemViewHost.Enabled = Content != null && !ReadOnly && !Locked;
suggestedInstancesComboBox.Enabled = Content != null && !ReadOnly && !Locked;
algorithmViewHost.Enabled = Content != null && !ReadOnly && !Locked;
runsView.Enabled = Content != null;
algorithmInstancesViewHost.Enabled = Content != null;
}
private void UpdateSuggestedInstancesCombobox() {
var prevSelection = (IAlgorithm)suggestedInstancesComboBox.SelectedItem;
var prevNewIndex = -1;
suggestedInstancesComboBox.Items.Clear();
if (Content == null) return;
for (var i = 0; i < Content.SuggestedInstances.Count; i++) {
suggestedInstancesComboBox.Items.Add(Content.SuggestedInstances[i]);
if (prevSelection == null || Content.SuggestedInstances[i].Name == prevSelection.Name)
prevNewIndex = prevSelection == null ? 0 : i;
}
if (prevNewIndex >= 0) {
suggestedInstancesComboBox.SelectedIndex = prevNewIndex;
}
}
#region Event Handlers
#region Content events
private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) {
if (InvokeRequired) {
Invoke((Action