Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2710 was 2708, checked in by swagner, 15 years ago

Adapted HL 3.3 plugins according to changes in MainForm (#857)

File size: 4.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 Dictionary<Type, ToolStripMenuItem> typeMenuItemTable;
35
36    private object obj;
37    public object Object {
38      get { return obj; }
39      set {
40        if (value != obj) {
41          obj = value;
42          Initialize();
43        }
44      }
45    }
46
47    public ViewHost() {
48      typeMenuItemTable = new Dictionary<Type, ToolStripMenuItem>();
49      InitializeComponent();
50      Initialize();
51    }
52
53    protected virtual void Initialize() {
54      viewsLabel.Enabled = false;
55      viewsLabel.Visible = false;
56      typeMenuItemTable.Clear();
57      contextMenuStrip.Items.Clear();
58      contextMenuStrip.Enabled = false;
59      messageLabel.Visible = false;
60      if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();
61      viewPanel.Controls.Clear();
62      viewPanel.Enabled = false;
63      viewPanel.Visible = false;
64
65      if (Object != null) {
66        var viewTypes = from t in MainFormManager.GetViewTypes(Object.GetType())
67                        orderby t.Name ascending
68                        select t;
69        foreach (Type viewType in viewTypes) {
70          ToolStripMenuItem item = new ToolStripMenuItem(viewType.Name);
71          item.Name = viewType.FullName;
72          item.ToolTipText = viewType.FullName;
73          item.Tag = viewType;
74          contextMenuStrip.Items.Add(item);
75          typeMenuItemTable.Add(viewType, item);
76        }
77        if (contextMenuStrip.Items.Count == 0) {
78          messageLabel.Visible = true;
79        } else {
80          viewsLabel.Enabled = true;
81          viewsLabel.Visible = true;
82          contextMenuStrip.Enabled = true;
83          messageLabel.Visible = false;
84        }
85
86        Control view = (Control)MainFormManager.CreateDefaultView(Object);
87        if (view != null) {
88          viewPanel.Controls.Add(view);
89          viewPanel.Tag = view;
90          view.Dock = DockStyle.Fill;
91          viewPanel.Enabled = true;
92          viewPanel.Visible = true;
93          typeMenuItemTable[view.GetType()].Checked = true;
94          typeMenuItemTable[view.GetType()].Enabled = false;
95        }
96      }
97    }
98
99    private void viewsLabel_DoubleClick(object sender, EventArgs e) {
100      MainFormManager.CreateView(viewPanel.Tag.GetType(), Object).Show();
101    }
102    protected void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) {
103      Type viewType = (Type)e.ClickedItem.Tag;
104      foreach (ToolStripMenuItem item in typeMenuItemTable.Values) {
105        item.Checked = false;
106        item.Enabled = true;
107      }
108      typeMenuItemTable[viewType].Checked = true;
109      typeMenuItemTable[viewType].Enabled = false;
110
111      if (viewPanel.Controls.Count > 0) viewPanel.Controls[0].Dispose();
112      viewPanel.Controls.Clear();
113      Control view = (Control)MainFormManager.CreateView(viewType, Object);
114      viewPanel.Controls.Add(view);
115      viewPanel.Tag = view;
116      view.Dock = DockStyle.Fill;
117    }
118  }
119}
Note: See TracBrowser for help on using the repository browser.