Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceOverhaul/HeuristicLab.Clients.OKB/3.3/Administration/ServiceClient/OKBItem.cs @ 14712

Last change on this file since 14712 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

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