Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceClients/HiveItem.cs @ 6200

Last change on this file since 6200 was 6200, checked in by cneumuel, 13 years ago

#1233

  • stability improvements for HiveEngine
File size: 3.9 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 System.ComponentModel;
24using System.Drawing;
25using System.Runtime.Serialization;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28
29namespace HeuristicLab.Clients.Hive {
30  public partial class HiveItem : IHiveItem {
31    public string ItemName {
32      get { return ItemAttribute.GetName(this.GetType()); }
33    }
34    public string ItemDescription {
35      get { return ItemAttribute.GetDescription(this.GetType()); }
36    }
37    public Version ItemVersion {
38      get { return ItemAttribute.GetVersion(this.GetType()); }
39    }
40    public virtual Image ItemImage {
41      get {
42        if (Modified)
43          return HeuristicLab.Common.Resources.VSImageLibrary.DatabaseModified;
44        else
45          return HeuristicLab.Common.Resources.VSImageLibrary.Database;
46      }
47    }
48
49    private bool modified;
50    public bool Modified {
51      get { return modified; }
52      private set {
53        if (value != modified) {
54          modified = value;
55          OnModifiedChanged();
56          RaisePropertyChanged("Modified");
57          OnItemImageChanged();
58          RaisePropertyChanged("ItemImage");
59        }
60      }
61    }
62
63    #region Constructor and Cloning
64    public HiveItem() {
65      modified = true;
66    }
67
68    [OnDeserialized]
69    private void OnDeserialized(StreamingContext context) {
70      modified = false;
71    }
72
73    protected HiveItem(HiveItem original, Cloner cloner) {
74      cloner.RegisterClonedObject(original, this);
75      this.Id = original.Id;
76      modified = true;
77    }
78    public virtual IDeepCloneable Clone(Cloner cloner) {
79      return new HiveItem(this, cloner);
80    }
81
82    public object Clone() {
83      return Clone(new Cloner());
84    }
85    #endregion
86
87    public void Store() {
88      ExperimentManagerClient.Store(this);
89      Modified = false;
90    }
91
92    protected virtual void RaisePropertyChanged(string propertyName) {
93      OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
94      if ((propertyName != "Id") && (propertyName != "Modified") && (propertyName != "ItemImage")) {
95        Modified = true;
96      }
97    }
98    protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) {
99      PropertyChangedEventHandler handler = PropertyChanged;
100      if (handler != null) handler(this, e);
101    }
102
103    #region Event handler
104    public event EventHandler ItemImageChanged;
105    protected virtual void OnItemImageChanged() {
106      EventHandler handler = ItemImageChanged;
107      if (handler != null) handler(this, EventArgs.Empty);
108    }
109    public event EventHandler ToStringChanged;
110    protected virtual void OnToStringChanged() {
111      EventHandler handler = ToStringChanged;
112      if (handler != null) handler(this, EventArgs.Empty);
113    }
114    public event EventHandler ModifiedChanged;
115    protected virtual void OnModifiedChanged() {
116      EventHandler handler = ModifiedChanged;
117      if (handler != null) handler(this, EventArgs.Empty);
118    }
119    #endregion
120
121    public override string ToString() {
122      return ItemName;
123    }
124  }
125}
Note: See TracBrowser for help on using the repository browser.