Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Clients.Hive/3.3/ServiceClients/HiveItem.cs @ 7887

Last change on this file since 7887 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 4.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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 static Image StaticItemImage {
41      get { return HeuristicLab.Common.Resources.VSImageLibrary.Database; }
42    }
43    public virtual Image ItemImage {
44      get {
45        if (Modified)
46          return HeuristicLab.Common.Resources.VSImageLibrary.DatabaseModified;
47        else
48          return ItemAttribute.GetImage(this.GetType());
49      }
50    }
51
52    private bool modified;
53    public bool Modified {
54      get { return modified; }
55      internal set {
56        if (value != modified) {
57          modified = value;
58          OnModifiedChanged();
59          RaisePropertyChanged("Modified");
60          OnItemImageChanged();
61          RaisePropertyChanged("ItemImage");
62        }
63      }
64    }
65
66    #region Constructor and Cloning
67    public HiveItem() {
68      modified = true;
69    }
70
71    [OnDeserialized]
72    private void OnDeserialized(StreamingContext context) {
73      modified = false;
74    }
75
76    protected HiveItem(HiveItem original, Cloner cloner) {
77      cloner.RegisterClonedObject(original, this);
78      this.Id = original.Id;
79      modified = true;
80    }
81    public virtual IDeepCloneable Clone(Cloner cloner) {
82      return new HiveItem(this, cloner);
83    }
84
85    public object Clone() {
86      return Clone(new Cloner());
87    }
88    #endregion
89
90    public virtual void Store() {
91      HiveClient.Store(this, new System.Threading.CancellationToken());
92      Modified = false;
93    }
94
95    protected virtual void RaisePropertyChanged(string propertyName) {
96      OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
97      if ((propertyName != "Id") && (propertyName != "Modified") && (propertyName != "ItemImage")) {
98        Modified = true;
99      }
100    }
101    protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) {
102      PropertyChangedEventHandler handler = PropertyChanged;
103      if (handler != null) handler(this, e);
104    }
105
106    #region Event handler
107    public event EventHandler ItemImageChanged;
108    protected virtual void OnItemImageChanged() {
109      EventHandler handler = ItemImageChanged;
110      if (handler != null) handler(this, EventArgs.Empty);
111    }
112    public event EventHandler ToStringChanged;
113    protected virtual void OnToStringChanged() {
114      EventHandler handler = ToStringChanged;
115      if (handler != null) handler(this, EventArgs.Empty);
116    }
117    public event EventHandler ModifiedChanged;
118    protected virtual void OnModifiedChanged() {
119      EventHandler handler = ModifiedChanged;
120      if (handler != null) handler(this, EventArgs.Empty);
121    }
122    #endregion
123
124    public override string ToString() {
125      return ItemName;
126    }
127  }
128}
Note: See TracBrowser for help on using the repository browser.