[3437] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3437] | 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;
|
---|
[4068] | 23 | using System.Reflection;
|
---|
[3437] | 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.MainForm.WindowsForms {
|
---|
| 28 | public partial class ContentView : View, IContentView {
|
---|
[3566] | 29 | public ContentView()
|
---|
| 30 | : base() {
|
---|
| 31 | InitializeComponent();
|
---|
| 32 | this.locked = false;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[3437] | 35 | private IContent content;
|
---|
| 36 | public IContent Content {
|
---|
| 37 | get { return content; }
|
---|
| 38 | set {
|
---|
[3915] | 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()))
|
---|
[3437] | 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) {
|
---|
[3727] | 47 | this.SuspendRepaint();
|
---|
[3437] | 48 | if (this.content != null) this.DeregisterContentEvents();
|
---|
| 49 | this.content = value;
|
---|
| 50 | if (this.content != null) this.RegisterContentEvents();
|
---|
| 51 | this.OnContentChanged();
|
---|
[3904] | 52 | this.SetEnabledStateOfControls();
|
---|
[3483] | 53 | this.OnChanged();
|
---|
[3727] | 54 | this.ResumeRepaint(true);
|
---|
[3437] | 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;
|
---|
[3788] | 70 | OnLockedChanged();
|
---|
[3437] | 71 | PropertyInfo prop = typeof(IContentView).GetProperty("Locked");
|
---|
| 72 | PropagateStateChanges(this, typeof(IContentView), prop);
|
---|
[4519] | 73 | SetEnabledStateOfControls();
|
---|
[3437] | 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 | }
|
---|
[3904] | 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() {
|
---|
[4435] | 111 | base.SetEnabledStateOfControls();
|
---|
[3904] | 112 | }
|
---|
[5079] | 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 | }
|
---|
[3437] | 125 | }
|
---|
| 126 | }
|
---|