Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistentDataStructures/HeuristicLab.MainForm.WindowsForms/3.3/Views/ContentView.cs

Last change on this file was 14186, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Reflection;
24using System.Windows.Forms;
25using HeuristicLab.Common;
26
27namespace HeuristicLab.MainForm.WindowsForms {
28  public partial class ContentView : View, IContentView {
29    public ContentView()
30      : base() {
31      InitializeComponent();
32      this.locked = false;
33    }
34
35    private IContent content;
36    public IContent Content {
37      get { return content; }
38      set {
39        //check if the ContentView is tagged with a corresponding ContentAttribute for the type of the Content
40        if ((value != null) && (!MainFormManager.ViewCanViewContent(this, value)) &&
41          ContentAttribute.HasContentAttribute(this.GetType()))
42          throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name));
43        if (InvokeRequired) {
44          Invoke(new Action<IContent>(delegate(IContent o) { this.Content = o; }), value);
45        } else {
46          if (this.content != value) {
47            this.SuspendRepaint();
48            if (this.content != null) this.DeregisterContentEvents();
49            this.content = value;
50            if (this.content != null) this.RegisterContentEvents();
51            this.OnContentChanged();
52            this.SetEnabledStateOfControls();
53            this.OnChanged();
54            this.ResumeRepaint(true);
55          }
56        }
57      }
58    }
59
60    private bool locked;
61    public virtual bool Locked {
62      get { return this.locked; }
63      set {
64        if (InvokeRequired) {
65          Action<bool> action = delegate(bool b) { this.Locked = b; };
66          Invoke(action, value);
67        } else {
68          if (value != locked) {
69            locked = value;
70            OnLockedChanged();
71            PropertyInfo prop = typeof(IContentView).GetProperty("Locked");
72            PropagateStateChanges(this, typeof(IContentView), prop);
73            SetEnabledStateOfControls();
74            OnChanged();
75          }
76        }
77      }
78    }
79    public event EventHandler LockedChanged;
80    protected virtual void OnLockedChanged() {
81      if (InvokeRequired)
82        Invoke((MethodInvoker)OnLockedChanged);
83      else {
84        EventHandler handler = LockedChanged;
85        if (handler != null)
86          handler(this, EventArgs.Empty);
87      }
88    }
89    /// <summary>
90    /// Adds eventhandlers to the current instance.
91    /// </summary>
92    protected virtual void RegisterContentEvents() {
93    }
94
95    /// <summary>
96    /// Removes the eventhandlers from the current instance.
97    /// </summary>
98    protected virtual void DeregisterContentEvents() {
99    }
100
101    /// <summary>
102    /// Is called when the content property changes.
103    /// </summary>
104    protected virtual void OnContentChanged() {
105    }
106
107    /// <summary>
108    /// This method is called if the ReadyOnly, Locked or Content property of the ContentView changes to update the controls of the view.
109    /// </summary>
110    protected override void SetEnabledStateOfControls() {
111      base.SetEnabledStateOfControls();
112    }
113
114    /// <summary>
115    /// Clean up any resources being used.
116    /// </summary>
117    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
118    protected override void Dispose(bool disposing) {
119      if (disposing) {
120        if (Content != null) DeregisterContentEvents();
121        if (components != null) components.Dispose();
122      }
123      base.Dispose(disposing);
124    }
125  }
126}
Note: See TracBrowser for help on using the repository browser.