[2655] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Windows.Forms;
|
---|
| 29 | using System.Linq;
|
---|
| 30 | using HeuristicLab.MainForm;
|
---|
| 31 |
|
---|
| 32 | namespace 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;
|
---|
[2665] | 55 | messageLabel.Visible = false;
|
---|
[2655] | 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);
|
---|
[2665] | 66 | if (viewComboBox.Items.Count == 0) {
|
---|
| 67 | messageLabel.Visible = true;
|
---|
| 68 | } else {
|
---|
[2655] | 69 | viewLabel.Visible = true;
|
---|
| 70 | viewComboBox.Enabled = true;
|
---|
| 71 | viewComboBox.Visible = true;
|
---|
[2665] | 72 | messageLabel.Visible = false;
|
---|
[2655] | 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 | private 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 | }
|
---|