Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/20/10 05:00:28 (14 years ago)
Author:
swagner
Message:

Committing first results of the refactoring of HeuristicLab.Core and related plugins (#95)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/ItemBase.cs

    r2546 r2653  
    2222using System;
    2323using System.Collections.Generic;
     24using System.ComponentModel;
    2425using System.Text;
    2526using System.Xml;
     
    3334  /// Represents the base class for all basic item types.
    3435  /// </summary>
     36  [EmptyStorableClass]
    3537  [Item("ItemBase", "Base class for all HeuristicLab items.")]
    36   [EmptyStorableClass]
    37   public abstract class ItemBase : IItem {
    38     public virtual string Name {
    39       get {
    40         if (ItemAttribute.GetName(this.GetType()) != null)
    41           return ItemAttribute.GetName(this.GetType());
    42         else
    43           return this.GetType().Name;
    44       }
     38  public abstract class ItemBase : DeepCloneableBase, IItem {
     39    public virtual string ItemName {
     40      get { return ItemAttribute.GetName(this.GetType()); }
    4541    }
    46     public virtual string Description {
    47       get {
    48         if (ItemAttribute.GetDescription(this.GetType()) != null)
    49           return ItemAttribute.GetDescription(this.GetType());
    50         else
    51           return "No description available.";
    52       }
     42    public virtual string ItemDescription {
     43      get { return ItemAttribute.GetDescription(this.GetType()); }
    5344    }
    54     public virtual Image Image {
    55       get { return Resources.HeuristicLab; }
    56     }
    57 
    58     /// <summary>
    59     /// Creates a deep clone of this instance.
    60     /// </summary>
    61     /// <remarks>
    62     /// This method is the entry point for creating a deep clone of a whole object graph.
    63     /// </remarks>
    64     /// <returns>A clone of this instance.</returns>
    65     public object Clone() {
    66       return Clone(new Cloner());
    67     }
    68 
    69     /// <summary>
    70     /// Creates a deep clone of this instance.
    71     /// </summary>
    72     /// <remarks>This method should not be called directly. It is used for creating clones of
    73     /// objects which are contained in the object that is currently cloned.</remarks>
    74     /// <param name="cloner">The cloner which is responsible for keeping track of all already
    75     /// cloned objects.</param>
    76     /// <returns>A clone of this instance.</returns>
    77     public virtual IItem Clone(ICloner cloner) {
    78       ItemBase clone = (ItemBase)Activator.CreateInstance(this.GetType());
    79       cloner.RegisterClonedObject(this, clone);
    80       return clone;
     45    public virtual Image ItemImage {
     46      get { return VS2008ImageLibrary.Class; }
    8147    }
    8248
     
    8652    /// <returns>The type name of the current instance.</returns>
    8753    public override string ToString() {
    88       return GetType().Name;
     54      return ItemName;
    8955    }
    9056
    91     /// <summary>
    92     /// Fires a new <c>Changed</c> event.
    93     /// </summary>
    94     /// <remarks>Calls <see cref="OnChanged"/>.</remarks>
    95     public void FireChanged() {
    96       OnChanged();
     57    public event ChangedEventHandler Changed;
     58    protected void OnChanged() {
     59      OnChanged(new ChangedEventArgs());
    9760    }
    98 
    99     /// <summary>
    100     /// Occurs when the current item was changed.
    101     /// </summary>
    102     public event EventHandler Changed;
    103     /// <summary>
    104     /// Fires a new <c>Changed</c> event.
    105     /// </summary>
    106     protected virtual void OnChanged() {
    107       if (Changed != null)
    108         Changed(this, new EventArgs());
     61    protected virtual void OnChanged(ChangedEventArgs e) {
     62      if ((e.RegisterChangedObject(this)) && (Changed != null))
     63          Changed(this, e);
    10964    }
    11065  }
Note: See TracChangeset for help on using the changeset viewer.