Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Clients.Hive/3.3/ServiceClients/HiveItem.cs @ 15866

Last change on this file since 15866 was 13656, checked in by ascheibe, 9 years ago

#2582 created branch for Hive Web Job Manager

File size: 4.0 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.Hive {
30  public partial class HiveItem : IHiveItem {
31    public string ItemName
32    {
33      get { return ItemAttribute.GetName(this.GetType()); }
34    }
35    public string ItemDescription
36    {
37      get { return ItemAttribute.GetDescription(this.GetType()); }
38    }
39    public Version ItemVersion
40    {
41      get { return ItemAttribute.GetVersion(this.GetType()); }
42    }
43    public static Image StaticItemImage
44    {
45      get { return new Bitmap(25, 25); }
46    }
47    public virtual Image ItemImage
48    {
49      get
50      {
51        if (Modified)
52          return HeuristicLab.Common.Resources.VSImageLibrary.DatabaseModified;
53        else
54          return ItemAttribute.GetImage(this.GetType());
55      }
56    }
57
58    private bool modified;
59    public bool Modified
60    {
61      get { return modified; }
62      internal set
63      {
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}
Note: See TracBrowser for help on using the repository browser.