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 |
|
---|
22 | using System;
|
---|
23 | using System.ComponentModel;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Runtime.Serialization;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 |
|
---|
29 | namespace 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 | {
|
---|
34 | get { return ItemAttribute.GetName(this.GetType()); }
|
---|
35 | }
|
---|
36 | public virtual string ItemDescription
|
---|
37 | {
|
---|
38 | get { return ItemAttribute.GetDescription(this.GetType()); }
|
---|
39 | }
|
---|
40 | public Version ItemVersion
|
---|
41 | {
|
---|
42 | get { return ItemAttribute.GetVersion(this.GetType()); }
|
---|
43 | }
|
---|
44 | public static Image StaticItemImage
|
---|
45 | {
|
---|
46 | get { return new Bitmap(25, 25); }
|
---|
47 | }
|
---|
48 | public virtual Image ItemImage
|
---|
49 | {
|
---|
50 | get
|
---|
51 | {
|
---|
52 | if (Modified)
|
---|
53 | return HeuristicLab.Common.Resources.VSImageLibrary.DatabaseModified;
|
---|
54 | else
|
---|
55 | return ItemAttribute.GetImage(this.GetType());
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | private bool modified;
|
---|
60 | public bool Modified
|
---|
61 | {
|
---|
62 | get { return modified; }
|
---|
63 | private set
|
---|
64 | {
|
---|
65 | if (value != modified) {
|
---|
66 | modified = value;
|
---|
67 | OnModifiedChanged();
|
---|
68 | RaisePropertyChanged("Modified");
|
---|
69 | OnItemImageChanged();
|
---|
70 | RaisePropertyChanged("ItemImage");
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | protected OKBItem(OKBItem original, Cloner cloner) {
|
---|
76 | cloner.RegisterClonedObject(original, this);
|
---|
77 | modified = true;
|
---|
78 | }
|
---|
79 | protected OKBItem() {
|
---|
80 | modified = true;
|
---|
81 | }
|
---|
82 |
|
---|
83 | [OnDeserialized]
|
---|
84 | private void OnDeserialized(StreamingContext context) {
|
---|
85 | modified = false;
|
---|
86 | }
|
---|
87 |
|
---|
88 | public object Clone() {
|
---|
89 | return Clone(new Cloner());
|
---|
90 | }
|
---|
91 | public virtual IDeepCloneable Clone(Cloner cloner) {
|
---|
92 | return new OKBItem(this, cloner);
|
---|
93 | }
|
---|
94 |
|
---|
95 | public override string ToString() {
|
---|
96 | return ItemName;
|
---|
97 | }
|
---|
98 |
|
---|
99 | public void Store() {
|
---|
100 | AdministrationClient.Store(this);
|
---|
101 | Modified = false;
|
---|
102 | }
|
---|
103 |
|
---|
104 | protected void RaisePropertyChanged(string propertyName) {
|
---|
105 | OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
|
---|
106 | if ((propertyName != "Id") && (propertyName != "Modified") && (propertyName != "ItemImage")) {
|
---|
107 | Modified = true;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) {
|
---|
111 | PropertyChangedEventHandler handler = PropertyChanged;
|
---|
112 | if (handler != null) handler(this, e);
|
---|
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 | public event EventHandler ItemImageChanged;
|
---|
120 | protected virtual void OnItemImageChanged() {
|
---|
121 | EventHandler handler = ItemImageChanged;
|
---|
122 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
123 | }
|
---|
124 | public event EventHandler ToStringChanged;
|
---|
125 | protected virtual void OnToStringChanged() {
|
---|
126 | EventHandler handler = ToStringChanged;
|
---|
127 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|