Free cookie consent management tool by TermsFeed Policy Generator

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

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

Committing first results of the refactoring of HeuristicLab.Core and related plugins (#95)

File size: 3.0 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    private void Initialize() {
51      viewLabel.Visible = false;
52      viewComboBox.Items.Clear();
53      viewComboBox.Enabled = false;
54      viewComboBox.Visible = false;
55      if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();
56      viewPanel.Controls.Clear();
57      viewPanel.Enabled = false;
58
59      if (Object != null) {
60        var viewTypes = from t in MainFormManager.GetViewTypes(Object.GetType())
61                        orderby t.Name ascending
62                        select t;
63        foreach (Type viewType in viewTypes)
64          viewComboBox.Items.Add(viewType);
65        if (viewComboBox.Items.Count > 0) {
66          viewLabel.Visible = true;
67          viewComboBox.Enabled = true;
68          viewComboBox.Visible = true;
69        }
70
71        Control view = (Control)MainFormManager.CreateDefaultView(Object);
72        if (view != null) {
73          viewPanel.Controls.Add(view);
74          viewPanel.Tag = view;
75          view.Dock = DockStyle.Fill;
76          viewPanel.Enabled = true;
77          viewComboBox.SelectedItem = view.GetType();
78        }
79      }
80    }
81
82    private void viewComboBox_SelectedIndexChanged(object sender, EventArgs e) {
83      if (viewComboBox.SelectedItem != viewPanel.Tag) {
84        if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();
85        viewPanel.Controls.Clear();
86        Control view = (Control)MainFormManager.CreateView((Type)viewComboBox.SelectedItem, Object);
87        viewPanel.Controls.Add(view);
88        viewPanel.Tag = view;
89        view.Dock = DockStyle.Fill;
90      }
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.