Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/ItemView.cs @ 2958

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

Implemented enabling and disabling of save buttons and menu items to prevent saving of running algorithms (#685)

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 HeuristicLab.MainForm;
24using HeuristicLab.MainForm.WindowsForms;
25
26namespace HeuristicLab.Core.Views {
27  /// <summary>
28  /// Base class for all visual representations.
29  /// </summary>
30  [View("Item View")]
31  [Content(typeof(Item), false)]
32  [Content(typeof(IItem), false)]
33  public partial class ItemView : ContentView {
34    public new IItem Content {
35      get { return (IItem)base.Content; }
36      set { base.Content = value; }
37    }
38    private bool enableFileOperations;
39    public bool EnableFileOperations {
40      get { return enableFileOperations; }
41      protected set {
42        if (value != enableFileOperations) {
43          enableFileOperations = value;
44          OnChanged();
45        }
46      }
47    }
48
49    /// <summary>
50    /// Initializes a new instance of <see cref="ViewBase"/> with the caption "View".
51    /// </summary>
52    public ItemView() {
53      InitializeComponent();
54      Caption = "View";
55      enableFileOperations = true;
56    }
57    public ItemView(IItem content)
58      : this() {
59      Content = content;
60    }
61
62    protected override void OnContentChanged() {
63      base.OnContentChanged();
64      if (Content == null) {
65        Caption = "View";
66      } else {
67        Caption = Content.ItemName;
68      }
69    }
70
71    /// <summary>
72    /// Asynchron call of GUI updating.
73    /// </summary>
74    /// <param name="method">The delegate to invoke.</param>
75    protected new void Invoke(Delegate method) {
76      // enforce context switch to improve GUI response time
77      System.Threading.Thread.Sleep(0);
78
79      // prevent blocking of worker thread in Invoke, if the control is disposed
80      IAsyncResult result = BeginInvoke(method);
81      while ((!result.AsyncWaitHandle.WaitOne(100, false)) && (!IsDisposed)) { }
82      if (!IsDisposed) EndInvoke(result);
83    }
84    /// <summary>
85    /// Asynchron call of GUI updating.
86    /// </summary>
87    /// <param name="method">The delegate to invoke.</param>
88    /// <param name="args">The invoke arguments.</param>
89    protected new void Invoke(Delegate method, params object[] args) {
90      // enforce context switch to improve GUI response time
91      System.Threading.Thread.Sleep(0);
92
93      // prevent blocking of worker thread in Invoke, if the control is disposed
94      IAsyncResult result = BeginInvoke(method, args);
95      while ((!result.AsyncWaitHandle.WaitOne(100, false)) && (!IsDisposed)) { }
96      if (!IsDisposed) EndInvoke(result);
97    }
98  }
99}
Note: See TracBrowser for help on using the repository browser.