Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/17/14 16:05:14 (10 years ago)
Author:
ascheibe
Message:

#2158 added error handling for view nesting problem

File:
1 edited

Legend:

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

    r11171 r11555  
    2020#endregion
    2121
     22using System;
     23using System.Windows.Forms;
    2224using HeuristicLab.MainForm.WindowsForms;
    2325
     
    2729  /// </summary>
    2830  public partial class ItemView : AsynchronousContentView {
     31    public const int MaximumNestingLevel = 37;
     32
    2933    public new IItem Content {
    3034      get { return (IItem)base.Content; }
     
    3842      InitializeComponent();
    3943    }
     44
     45    protected override void OnInitialized(EventArgs e) {
     46      base.OnInitialized(e);
     47
     48      if (CountParentControls() > MaximumNestingLevel) {
     49        NestingLevelErrorControl errorControl = new NestingLevelErrorControl();
     50        errorControl.Dock = DockStyle.Fill;
     51        //capture content, needed because it is set at a later time
     52        errorControl.Content = () => Content;
     53
     54        Controls.Clear();
     55        Controls.Add(errorControl);
     56      }
     57    }
     58
     59    private int CountParentControls() {
     60      int cnt = 0;
     61      Control parent = Parent;
     62      while (parent != null) {
     63        parent = parent.Parent;
     64        cnt++;
     65      }
     66      return cnt;
     67    }
    4068  }
    4169}
Note: See TracChangeset for help on using the changeset viewer.