Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2437


Ignore:
Timestamp:
10/18/09 01:08:12 (15 years ago)
Author:
mkommend
Message:

implemented changes regarding detection of view types and default views as discussed with SWA (ticket #771)

Location:
branches/Mainform refactoring
Files:
8 edited
3 copied

Legend:

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

    r2426 r2437  
    99    public void Execute(IMainForm mainform) {
    1010      MessageBox.Show("New form called");
    11       FormView x = new FormView();
     11      FormView1 x = new FormView1();
    1212      x.Caption = "FormView";
    1313      mainform.ShowView(x);
  • branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/ButtonItems/SaveToolStripButtonItem.cs

    r2433 r2437  
    2828        this.ToolStripItem.Enabled = false;
    2929      else
    30         this.ToolStripItem.Enabled = !(mainform.ActiveView is FormView);
     30        this.ToolStripItem.Enabled = !(mainform.ActiveView is FormView1);
    3131    }
    3232
  • branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/EditorView.cs

    r2433 r2437  
    88using System.Windows.Forms;
    99using HeuristicLab.MainForm.WindowsForms;
     10using System.Collections;
    1011
    1112namespace HeuristicLab.MainForm.Test {
    1213  [DefaultView]
    13   public partial class EditorView : ViewBase<object>,IView<string> {
     14  public partial class EditorView : ViewBase<IList> {
    1415    public EditorView() {
    1516      InitializeComponent();
     
    1718
    1819    private void ChangeStateButton_Click(object sender, EventArgs e) {
    19       IEnumerable<Type> views = MainFormManager.GetViewTypes(typeof(string));
     20      IEnumerable<Type> views = MainFormManager.GetViewTypes(typeof(ArrayList));
    2021      views.ToString();
    21       IEnumerable<Type> views1 = MainFormManager.GetViewTypes(typeof(object));
     22      IEnumerable<Type> views1 = MainFormManager.GetViewTypes(typeof(IList));
    2223      views1.ToString();
    23       Type def1 = MainFormManager.GetDefaultViewType(typeof(string));
     24      //IEnumerable<Type> views2 = MainFormManager.GetViewTypes(typeof(object));
     25      //views2.ToString();
     26      Type def2 = MainFormManager.GetDefaultViewType(typeof(IList));
     27      def2.ToString();
     28      Type def1 = MainFormManager.GetDefaultViewType(typeof(ArrayList));
    2429      def1.ToString();
    25       Type def2 = MainFormManager.GetDefaultViewType(typeof(object));
    26       def2.ToString();
    27 
    28       IView<string> v = MainFormManager.CreateDefaultView<string>("x");
    29       v.Caption = "lala";
     30      //Type def3 = MainFormManager.GetDefaultViewType(typeof(object));
     31      //def3.ToString();
    3032
    3133      this.OnChanged();
  • branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/FormView.Designer.cs

    r2250 r2437  
    11namespace HeuristicLab.MainForm.Test {
    2   partial class FormView {
     2  partial class FormView1 {
    33    /// <summary>
    44    /// Required designer variable.
  • branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/FormView.cs

    r2433 r2437  
    1010
    1111namespace HeuristicLab.MainForm.Test {
    12   public partial class FormView : ViewBase<object>  {
     12  [DefaultView]
     13  public partial class FormView1 : ViewBase<ICloneable>  {
    1314    private int[] array;
    14     public FormView() {
     15    public FormView1() {
    1516      InitializeComponent();
    1617    }
  • branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/FormView2.Designer.cs

    r2436 r2437  
    11namespace HeuristicLab.MainForm.Test {
    2   partial class FormView {
     2  partial class FormView2 {
    33    /// <summary>
    44    /// Required designer variable.
  • branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/FormView2.cs

    r2436 r2437  
    11using System;
    2 using System.Collections.Generic;
     2using System.Collections;
    33using System.ComponentModel;
    44using System.Drawing;
     
    1010
    1111namespace HeuristicLab.MainForm.Test {
    12   public partial class FormView : ViewBase<object>  {
     12  public partial class FormView2 : ViewBase<ArrayList>  {
    1313    private int[] array;
    14     public FormView() {
     14    public FormView2() {
    1515      InitializeComponent();
    1616    }
  • branches/Mainform refactoring/HeuristicLab.MainForm.Test/3.2/HeuristicLab.MainForm.Test-3.2.csproj

    r2426 r2437  
    8787    <Compile Include="ButtonItems\SaveToolStripButtonItem.cs" />
    8888    <Compile Include="ButtonItems\OpenToolStripButtonItem.cs" />
     89    <Compile Include="FormView2.cs">
     90      <SubType>UserControl</SubType>
     91    </Compile>
     92    <Compile Include="FormView2.Designer.cs">
     93      <DependentUpon>FormView2.cs</DependentUpon>
     94    </Compile>
    8995    <Compile Include="HeuristicLabSingleDocumentMainFormTestApplication.cs" />
    9096    <Compile Include="HeuristicLabMultipleDocumentMainFormTestApplication.cs" />
     
    140146  </ItemGroup>
    141147  <ItemGroup>
     148    <EmbeddedResource Include="FormView2.resx">
     149      <DependentUpon>FormView2.cs</DependentUpon>
     150    </EmbeddedResource>
    142151    <EmbeddedResource Include="EditorView.resx">
    143152      <DependentUpon>EditorView.cs</DependentUpon>
  • branches/Mainform refactoring/HeuristicLab.MainForm.WindowsForms/3.2/MainFormBase.cs

    r2426 r2437  
    7575    public Type UserInterfaceItemType {
    7676      get { return this.userInterfaceItemType; }
    77       protected set { this.userInterfaceItemType = value; }
    7877    }
    7978
  • branches/Mainform refactoring/HeuristicLab.MainForm/3.2/MainFormManager.cs

    r2433 r2437  
    8484
    8585    public static IEnumerable<Type> GetViewTypes(Type viewableType) {
    86       List<Type> viewsForType;
    87       if (!views.ContainsKey(viewableType))
    88         viewsForType = new List<Type>();
    89       else
    90         viewsForType = views[viewableType];
    91 
    92       if (viewableType.BaseType != null)
    93         viewsForType.AddRange(GetViewTypes(viewableType.BaseType));
     86      List<Type> viewsForType = new List<Type>();
     87      foreach (KeyValuePair<Type, List<Type>> v in views) {
     88        if (v.Key.IsAssignableFrom(viewableType))
     89          viewsForType.AddRange(v.Value);
     90      }
    9491      return viewsForType.Distinct();
    9592    }
     
    10097
    10198    public static Type GetDefaultViewType(Type viewableType) {
    102       if (!defaultViews.ContainsKey(viewableType))
    103         return null;
    104       return defaultViews[viewableType];
     99      if (!defaultViews.ContainsKey(viewableType)) {
     100        List<Type> temp = defaultViews.Keys.Where(x => x.IsAssignableFrom(viewableType)).ToList();
     101        if (temp.Count == 0)
     102          return null;
     103        else if (temp.Count == 1)
     104          return defaultViews[temp[0]];
     105        else {
     106          temp.Sort(delegate(Type t1, Type t2) {
     107            if (t1.IsAssignableFrom(t2))
     108              return 1;
     109            return -1;
     110          }
     111          );
     112          if (!temp[0].IsAssignableFrom(temp[1]) && !temp[1].IsAssignableFrom(temp[0]))
     113            throw new Exception("Could not determine which is the default view for type " + viewableType.ToString() + ".");
     114          else
     115            return defaultViews[temp[0]];
     116        }
     117      } else
     118        return defaultViews[viewableType];
    105119    }
    106120
     
    110124        return null;
    111125      else
    112         return (IView<T>) Activator.CreateInstance(t);
     126        return (IView<T>)Activator.CreateInstance(t);
    113127    }
    114128  }
Note: See TracChangeset for help on using the changeset viewer.