Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2456


Ignore:
Timestamp:
10/30/09 11:06:10 (15 years ago)
Author:
mkommend
Message:

implemented last changes in MainForm as discussed with SWA (ticket #771)

Location:
branches/Mainform refactoring
Files:
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/EditorView.cs

    r2443 r2456  
    1111
    1212namespace HeuristicLab.MainForm.Test {
    13   [DefaultView]
     13  [DefaultViewAttribute]
    1414  public partial class EditorView : ViewBase<ArrayList> {
    1515    public EditorView() {
  • branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/FormView.cs

    r2443 r2456  
    1111
    1212namespace HeuristicLab.MainForm.Test {
    13   [DefaultView]
     13  [DefaultViewAttribute]
    1414  public partial class FormView1 : ViewBase<ICollection> {
    1515    private int[] array;
  • branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/FormView2.cs

    r2443 r2456  
    1010
    1111namespace HeuristicLab.MainForm.Test {
    12   public partial class FormView2 : ViewBase<IEnumerable>  {
     12  public partial class FormView2 : ViewBase<IEnumerable> {
    1313    private int[] array;
    1414    public FormView2() {
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/ViewBase.cs

    r2433 r2456  
    3131namespace HeuristicLab.MainForm.WindowsForms {
    3232  public partial class ViewBase<T> : UserControl, IView<T> {
    33     protected T item;
     33   
    3434    public ViewBase() {
    3535      InitializeComponent();
    3636      item = default(T);
    3737    }
     38
     39    private T item;
     40    public virtual T Item {
     41      get { return this.item; }
     42      protected set { this.item = value; }
     43    }
     44
    3845    public virtual void View(T item) {
    3946    }
  • branches/Mainform refactoring/HeuristicLab.MainForm/3.2/DefaultViewAttribute.cs

    r2453 r2456  
    2626namespace HeuristicLab.MainForm {
    2727  [AttributeUsage(AttributeTargets.Class)]
    28   public class DefaultView : Attribute {
    29     public DefaultView() {
     28  public class DefaultViewAttribute : Attribute {
     29    public DefaultViewAttribute() {
     30    }
     31
     32    public static bool IsDefaultView(Type t) {
     33      object[] attributes = t.GetCustomAttributes(typeof(DefaultViewAttribute), false);
     34      return attributes != null && attributes.Length > 0;
    3035    }
    3136  }
  • branches/Mainform refactoring/HeuristicLab.MainForm/3.2/HeuristicLab.MainForm-3.2.csproj

    r2433 r2456  
    9292    <Compile Include="Properties\AssemblyInfo.cs" />
    9393    <Compile Include="UserInterfaceItemBase.cs" />
    94     <Compile Include="DefaultView.cs" />
     94    <Compile Include="DefaultViewAttribute.cs" />
    9595  </ItemGroup>
    9696  <ItemGroup>
  • branches/Mainform refactoring/HeuristicLab.MainForm/3.2/Interfaces/IUserInterfaceItem.cs

    r2426 r2456  
    3131    int Position { get; }
    3232    Image Image { get; }
    33     string ToolTipText { get; set; }
     33    string ToolTipText { get; }
    3434
    3535    void Execute();
  • branches/Mainform refactoring/HeuristicLab.MainForm/3.2/Interfaces/IView.cs

    r2433 r2456  
    3636  public interface IView<T> : IView {
    3737    void View(T item);
     38    T Item { get; }
    3839  }
    3940}
  • branches/Mainform refactoring/HeuristicLab.MainForm/3.2/MainFormManager.cs

    r2444 r2456  
    5656                views[viewableType].Add(t);
    5757
    58                 object[] attributes = t.GetCustomAttributes(typeof(DefaultView), false);
    59                 if (attributes != null && attributes.Length == 1) {
     58                if (DefaultViewAttribute.IsDefaultView(t)) {
    6059                  if (defaultViews.ContainsKey(viewableType))
    6160                    throw new ArgumentException("DefaultView for type " + viewableType + " is " + defaultViews[viewableType] +
     
    7473      IEnumerable<Type> interfaceTypes =
    7574       from type in t.GetInterfaces()
    76        where type.Namespace == "HeuristicLab.MainForm" && type.Name.StartsWith("IView")  &&
     75       where type.Namespace == "HeuristicLab.MainForm" && type.Name.StartsWith("IView") &&
    7776             type.IsGenericType && !type.IsGenericTypeDefinition
    7877       select type;
    7978
    80       foreach (Type interfaceType in interfaceTypes) {     
    81           yield return interfaceType.GetGenericArguments()[0];
     79      foreach (Type interfaceType in interfaceTypes) {
     80        yield return interfaceType.GetGenericArguments()[0];
    8281      }
    8382    }
     
    105104
    106105    public static Type GetDefaultViewType(Type viewableType) {
     106      //check if viewableType has a default view
    107107      if (defaultViews.ContainsKey(viewableType))
    108108        return defaultViews[viewableType];
    109       else {
    110         List<Type> temp = (from t in defaultViews.Keys
    111                            where t.IsAssignableFrom(viewableType)
    112                            select t).ToList();
    113         //no assignable type found
    114         if (temp.Count == 0)
    115           return null;
    116         //only one assignable type found => return this one
    117         else if (temp.Count == 1)
    118           return defaultViews[temp[0]];
    119         //more assignable types found => sort the types according to their assignable types
    120         //and return most specific type => except there is a conflict
    121         else {
    122           temp.Sort(delegate(Type t1, Type t2) {
    123             if (t1.IsAssignableFrom(t2))
    124               return 1;
    125             else if (t2.IsAssignableFrom(t1))
    126               return -1;
    127             else
    128               return 0;
    129           }
    130           );
    131           if (temp[1].IsAssignableFrom(temp[0]))
    132             return defaultViews[temp[0]];
    133           else
    134             throw new Exception("Could not determine which is the default view for type " + viewableType.ToString() + ".");
    135         }
     109
     110      //check base classes for default view
     111      Type type = viewableType;
     112      while (type.BaseType != null && !defaultViews.ContainsKey(type)) {
     113        type = type.BaseType;
    136114      }
     115      if (defaultViews.ContainsKey(type))
     116        return defaultViews[type];
     117
     118      //check if exact one implemented interface has a default view
     119      List<Type> temp = (from t in defaultViews.Keys
     120                         where t.IsAssignableFrom(viewableType) && t.IsInterface
     121                         select t).ToList();
     122      if (temp.Count == 1)
     123        return defaultViews[temp[0]];
     124      //more than one default view for implemented interfaces are found
     125      if (temp.Count > 1)
     126        throw new Exception("Could not determine which is the default view for type " + viewableType.ToString() + ". Because more than one implemented interfaces have a default view.");
     127      return null;
    137128    }
    138129
  • branches/Mainform refactoring/HeuristicLab.MainForm/3.2/UserInterfaceItemBase.cs

    r2426 r2456  
    2828  public abstract class UserInterfaceItemBase : IUserInterfaceItem{
    2929    protected UserInterfaceItemBase() {
    30       this.toolTipText = string.Empty;
    3130    }
    3231
     
    3837    }
    3938
    40     protected string toolTipText;
    41     public virtual string ToolTipText {
    42       get { return toolTipText; }
    43       set { this.toolTipText = value; }
     39    public virtual string ToolTipText {
     40      get { return string.Empty; }
    4441    }
    4542
Note: See TracChangeset for help on using the changeset viewer.