Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.Clients.OKB-3.3/ServiceClients/OKBItem.cs @ 4441

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

Worked on OKB data model and services (#1174)

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