Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/ViewHost.cs @ 2676

Last change on this file since 2676 was 2676, checked in by swagner, 14 years ago

Operator architecture refactoring (#95)

  • continued work on adapting and refactoring HeuristicLab.Data according to the changes in HeuristicLab.Core
  • unified visual appearance of views
File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using System.Linq;
30using HeuristicLab.MainForm;
31
32namespace HeuristicLab.Core.Views {
33  public partial class ViewHost : UserControl {
34    private object obj;
35    public object Object {
36      get { return obj; }
37      set {
38        if (value != obj) {
39          obj = value;
40          Initialize();
41        }
42      }
43    }
44
45    public ViewHost() {
46      InitializeComponent();
47      Initialize();
48    }
49
50    protected virtual void Initialize() {
51      viewLabel.Visible = false;
52      viewComboBox.Items.Clear();
53      viewComboBox.Enabled = false;
54      viewComboBox.Visible = false;
55      messageLabel.Visible = false;
56      if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();
57      viewPanel.Controls.Clear();
58      viewPanel.Enabled = false;
59
60      if (Object != null) {
61        var viewTypes = from t in MainFormManager.GetViewTypes(Object.GetType())
62                        orderby t.Name ascending
63                        select t;
64        foreach (Type viewType in viewTypes)
65          viewComboBox.Items.Add(viewType);
66        if (viewComboBox.Items.Count == 0) {
67          messageLabel.Visible = true;
68        } else {
69          viewLabel.Visible = true;
70          viewComboBox.Enabled = true;
71          viewComboBox.Visible = true;
72          messageLabel.Visible = false;
73        }
74
75        Control view = (Control)MainFormManager.CreateDefaultView(Object);
76        if (view != null) {
77          viewPanel.Controls.Add(view);
78          viewPanel.Tag = view;
79          view.Dock = DockStyle.Fill;
80          viewPanel.Enabled = true;
81          viewComboBox.SelectedItem = view.GetType();
82        }
83      }
84    }
85
86    protected virtual void viewComboBox_SelectedIndexChanged(object sender, EventArgs e) {
87      if (viewComboBox.SelectedItem != viewPanel.Tag) {
88        if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();
89        viewPanel.Controls.Clear();
90        Control view = (Control)MainFormManager.CreateView((Type)viewComboBox.SelectedItem, Object);
91        viewPanel.Controls.Add(view);
92        viewPanel.Tag = view;
93        view.Dock = DockStyle.Fill;
94      }
95    }
96  }
97}
Note: See TracBrowser for help on using the repository browser.