Free cookie consent management tool by TermsFeed Policy Generator

source: branches/QAPGenerators/HeuristicLab.Problems.Instances.QAPGenerator.Views/3.3/QAPInstanceGeneratorProviderView.cs @ 14704

Last change on this file since 14704 was 14704, checked in by abeham, 7 years ago

#2738: added branch

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.ComponentModel;
24using System.Linq;
25using HeuristicLab.MainForm;
26using HeuristicLab.Problems.Instances.Views;
27
28namespace HeuristicLab.Problems.Instances.QAPGenerator.Views {
29  [View("QAP Instance Generators")]
30  [Content(typeof(QAPInstanceGeneratorProvider), IsDefaultView = true)]
31  public sealed partial class QAPInstanceGeneratorProviderView : ProblemInstanceProviderView<QAPData> {
32
33    public new QAPInstanceGeneratorProvider Content {
34      get { return (QAPInstanceGeneratorProvider)base.Content; }
35      set { base.Content = value; }
36    }
37
38    private QAPInstanceGeneratorDescriptor SelectedDescriptor {
39      get { return descriptorsComboBox.SelectedIndex >= 0 ? (QAPInstanceGeneratorDescriptor)descriptorsComboBox.SelectedItem : null; }
40    }
41
42    public QAPInstanceGeneratorProviderView() {
43      InitializeComponent();
44      splitContainer1.Visible = false;
45      descriptorsComboBox.DisplayMember = "Name";
46    }
47
48    protected override void OnContentChanged() {
49      base.OnContentChanged();
50      DeregisterDescriptorEvents();
51      descriptorsComboBox.Items.Clear();
52      if (Content == null) {
53        descriptorViewHost.Content = null;
54      } else {
55        foreach (var descriptor in Content.GetDataDescriptors()) {
56          descriptorsComboBox.Items.Add(descriptor);
57        }
58        descriptorsComboBox.SelectedIndex = descriptorsComboBox.Items.Count > 0 ? 0 : -1;
59      }
60    }
61
62    protected override void SetEnabledStateOfControls() {
63      base.SetEnabledStateOfControls();
64      loadButton.Enabled = !ReadOnly && !Locked && Content != null
65        && SelectedDescriptor != null && SelectedDescriptor.IsConfigurationValid
66        && GenericConsumer != null;
67    }
68
69    private void RegisterDescriptorEvents() {
70      if (SelectedDescriptor != null)
71        SelectedDescriptor.PropertyChanged += SelectedDescriptorOnPropertyChanged;
72    }
73
74    private void DeregisterDescriptorEvents() {
75      foreach (var descriptor in descriptorsComboBox.Items.OfType<QAPInstanceGeneratorDescriptor>())
76        descriptor.PropertyChanged -= SelectedDescriptorOnPropertyChanged;
77    }
78
79    private void SelectedDescriptorOnPropertyChanged(object sender, PropertyChangedEventArgs e) {
80      SetEnabledStateOfControls();
81    }
82
83    private void descriptorsComboBox_SelectedIndexChanged(object sender, EventArgs e) {
84      DeregisterDescriptorEvents();
85      RegisterDescriptorEvents();
86      descriptorViewHost.Content = (QAPInstanceGeneratorDescriptor)descriptorsComboBox.SelectedItem;
87      SetEnabledStateOfControls();
88    }
89
90    private void loadButton_Click(object sender, EventArgs e) {
91      GenericConsumer.Load(SelectedDescriptor.GetInstance());
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.