Changeset 2456
- Timestamp:
- 10/30/09 11:06:10 (15 years ago)
- 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 11 11 12 12 namespace HeuristicLab.MainForm.Test { 13 [DefaultView ]13 [DefaultViewAttribute] 14 14 public partial class EditorView : ViewBase<ArrayList> { 15 15 public EditorView() { -
branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/FormView.cs
r2443 r2456 11 11 12 12 namespace HeuristicLab.MainForm.Test { 13 [DefaultView ]13 [DefaultViewAttribute] 14 14 public partial class FormView1 : ViewBase<ICollection> { 15 15 private int[] array; -
branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/FormView2.cs
r2443 r2456 10 10 11 11 namespace HeuristicLab.MainForm.Test { 12 public partial class FormView2 : ViewBase<IEnumerable> 12 public partial class FormView2 : ViewBase<IEnumerable> { 13 13 private int[] array; 14 14 public FormView2() { -
branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/ViewBase.cs
r2433 r2456 31 31 namespace HeuristicLab.MainForm.WindowsForms { 32 32 public partial class ViewBase<T> : UserControl, IView<T> { 33 protected T item;33 34 34 public ViewBase() { 35 35 InitializeComponent(); 36 36 item = default(T); 37 37 } 38 39 private T item; 40 public virtual T Item { 41 get { return this.item; } 42 protected set { this.item = value; } 43 } 44 38 45 public virtual void View(T item) { 39 46 } -
branches/Mainform refactoring/HeuristicLab.MainForm/3.2/DefaultViewAttribute.cs
r2453 r2456 26 26 namespace HeuristicLab.MainForm { 27 27 [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; 30 35 } 31 36 } -
branches/Mainform refactoring/HeuristicLab.MainForm/3.2/HeuristicLab.MainForm-3.2.csproj
r2433 r2456 92 92 <Compile Include="Properties\AssemblyInfo.cs" /> 93 93 <Compile Include="UserInterfaceItemBase.cs" /> 94 <Compile Include="DefaultView .cs" />94 <Compile Include="DefaultViewAttribute.cs" /> 95 95 </ItemGroup> 96 96 <ItemGroup> -
branches/Mainform refactoring/HeuristicLab.MainForm/3.2/Interfaces/IUserInterfaceItem.cs
r2426 r2456 31 31 int Position { get; } 32 32 Image Image { get; } 33 string ToolTipText { get; set;}33 string ToolTipText { get; } 34 34 35 35 void Execute(); -
branches/Mainform refactoring/HeuristicLab.MainForm/3.2/Interfaces/IView.cs
r2433 r2456 36 36 public interface IView<T> : IView { 37 37 void View(T item); 38 T Item { get; } 38 39 } 39 40 } -
branches/Mainform refactoring/HeuristicLab.MainForm/3.2/MainFormManager.cs
r2444 r2456 56 56 views[viewableType].Add(t); 57 57 58 object[] attributes = t.GetCustomAttributes(typeof(DefaultView), false); 59 if (attributes != null && attributes.Length == 1) { 58 if (DefaultViewAttribute.IsDefaultView(t)) { 60 59 if (defaultViews.ContainsKey(viewableType)) 61 60 throw new ArgumentException("DefaultView for type " + viewableType + " is " + defaultViews[viewableType] + … … 74 73 IEnumerable<Type> interfaceTypes = 75 74 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") && 77 76 type.IsGenericType && !type.IsGenericTypeDefinition 78 77 select type; 79 78 80 foreach (Type interfaceType in interfaceTypes) { 81 79 foreach (Type interfaceType in interfaceTypes) { 80 yield return interfaceType.GetGenericArguments()[0]; 82 81 } 83 82 } … … 105 104 106 105 public static Type GetDefaultViewType(Type viewableType) { 106 //check if viewableType has a default view 107 107 if (defaultViews.ContainsKey(viewableType)) 108 108 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; 136 114 } 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; 137 128 } 138 129 -
branches/Mainform refactoring/HeuristicLab.MainForm/3.2/UserInterfaceItemBase.cs
r2426 r2456 28 28 public abstract class UserInterfaceItemBase : IUserInterfaceItem{ 29 29 protected UserInterfaceItemBase() { 30 this.toolTipText = string.Empty;31 30 } 32 31 … … 38 37 } 39 38 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; } 44 41 } 45 42
Note: See TracChangeset
for help on using the changeset viewer.