[6976] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[6976] | 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.Hive {
|
---|
| 30 | public partial class HiveItem : IHiveItem {
|
---|
[13656] | 31 | public string ItemName
|
---|
| 32 | {
|
---|
[6976] | 33 | get { return ItemAttribute.GetName(this.GetType()); }
|
---|
| 34 | }
|
---|
[13656] | 35 | public string ItemDescription
|
---|
| 36 | {
|
---|
[6976] | 37 | get { return ItemAttribute.GetDescription(this.GetType()); }
|
---|
| 38 | }
|
---|
[13656] | 39 | public Version ItemVersion
|
---|
| 40 | {
|
---|
[6976] | 41 | get { return ItemAttribute.GetVersion(this.GetType()); }
|
---|
| 42 | }
|
---|
[13656] | 43 | public static Image StaticItemImage
|
---|
| 44 | {
|
---|
| 45 | get { return new Bitmap(25, 25); }
|
---|
[7201] | 46 | }
|
---|
[13656] | 47 | public virtual Image ItemImage
|
---|
| 48 | {
|
---|
| 49 | get
|
---|
| 50 | {
|
---|
[6976] | 51 | if (Modified)
|
---|
| 52 | return HeuristicLab.Common.Resources.VSImageLibrary.DatabaseModified;
|
---|
| 53 | else
|
---|
[7201] | 54 | return ItemAttribute.GetImage(this.GetType());
|
---|
[6976] | 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | private bool modified;
|
---|
[13656] | 59 | public bool Modified
|
---|
| 60 | {
|
---|
[6976] | 61 | get { return modified; }
|
---|
[13656] | 62 | internal set
|
---|
| 63 | {
|
---|
[6976] | 64 | if (value != modified) {
|
---|
| 65 | modified = value;
|
---|
| 66 | OnModifiedChanged();
|
---|
| 67 | RaisePropertyChanged("Modified");
|
---|
| 68 | OnItemImageChanged();
|
---|
| 69 | RaisePropertyChanged("ItemImage");
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | #region Constructor and Cloning
|
---|
| 75 | public HiveItem() {
|
---|
| 76 | modified = true;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | [OnDeserialized]
|
---|
| 80 | private void OnDeserialized(StreamingContext context) {
|
---|
| 81 | modified = false;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | protected HiveItem(HiveItem original, Cloner cloner) {
|
---|
| 85 | cloner.RegisterClonedObject(original, this);
|
---|
| 86 | this.Id = original.Id;
|
---|
| 87 | modified = true;
|
---|
| 88 | }
|
---|
| 89 | public virtual IDeepCloneable Clone(Cloner cloner) {
|
---|
| 90 | return new HiveItem(this, cloner);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | public object Clone() {
|
---|
| 94 | return Clone(new Cloner());
|
---|
| 95 | }
|
---|
| 96 | #endregion
|
---|
| 97 |
|
---|
| 98 | public virtual void Store() {
|
---|
| 99 | HiveClient.Store(this, new System.Threading.CancellationToken());
|
---|
| 100 | Modified = false;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | protected virtual void RaisePropertyChanged(string propertyName) {
|
---|
| 104 | OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
|
---|
| 105 | if ((propertyName != "Id") && (propertyName != "Modified") && (propertyName != "ItemImage")) {
|
---|
| 106 | Modified = true;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 | protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) {
|
---|
| 110 | PropertyChangedEventHandler handler = PropertyChanged;
|
---|
| 111 | if (handler != null) handler(this, e);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | #region Event handler
|
---|
| 115 | public event EventHandler ItemImageChanged;
|
---|
| 116 | protected virtual void OnItemImageChanged() {
|
---|
| 117 | EventHandler handler = ItemImageChanged;
|
---|
| 118 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 119 | }
|
---|
| 120 | public event EventHandler ToStringChanged;
|
---|
| 121 | protected virtual void OnToStringChanged() {
|
---|
| 122 | EventHandler handler = ToStringChanged;
|
---|
| 123 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 124 | }
|
---|
| 125 | public event EventHandler ModifiedChanged;
|
---|
| 126 | protected virtual void OnModifiedChanged() {
|
---|
| 127 | EventHandler handler = ModifiedChanged;
|
---|
| 128 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
| 129 | }
|
---|
| 130 | #endregion
|
---|
| 131 |
|
---|
| 132 | public override string ToString() {
|
---|
| 133 | return ItemName;
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 | }
|
---|