Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Clients.Access/3.3/ServiceClients/AccessItem.cs

Last change on this file was 17226, checked in by mkommend, 5 years ago

#2521: Merged trunk changes into problem refactoring branch.

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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.Access {
30  [Item("AccessItem", "Base class for all AccessService items.")]
31  public partial class AccessItem : IAccessItem {
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    public void SetUnmodified() {
68      Modified = false;
69    }
70
71    protected AccessItem(AccessItem original, Cloner cloner) {
72      cloner.RegisterClonedObject(original, this);
73      modified = true;
74    }
75    protected AccessItem() {
76      modified = true;
77    }
78
79    [OnDeserialized]
80    private void OnDeserialized(StreamingContext context) {
81      modified = false;
82    }
83
84    public object Clone() {
85      return Clone(new Cloner());
86    }
87    public virtual IDeepCloneable Clone(Cloner cloner) {
88      return new AccessItem(this, cloner);
89    }
90
91    public override string ToString() {
92      return ItemName;
93    }
94
95    protected 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    public event EventHandler ModifiedChanged;
106    protected virtual void OnModifiedChanged() {
107      EventHandler handler = ModifiedChanged;
108      if (handler != null) handler(this, EventArgs.Empty);
109    }
110    public event EventHandler ItemImageChanged;
111    protected virtual void OnItemImageChanged() {
112      EventHandler handler = ItemImageChanged;
113      if (handler != null) handler(this, EventArgs.Empty);
114    }
115    public event EventHandler ToStringChanged;
116    protected virtual void OnToStringChanged() {
117      EventHandler handler = ToStringChanged;
118      if (handler != null) handler(this, EventArgs.Empty);
119    }
120  }
121}
Note: See TracBrowser for help on using the repository browser.