Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/19/10 21:00:30 (14 years ago)
Author:
mkommend
Message:

implemented ContentViews and propagation of view state changes (ticket #982)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm/3.2/MainFormManager.cs

    r3389 r3416  
    2626using HeuristicLab.PluginInfrastructure;
    2727using System.Diagnostics;
     28using HeuristicLab.Common;
    2829
    2930namespace HeuristicLab.MainForm {
     
    7576
    7677    public static IEnumerable<Type> GetViewTypes(Type contentType) {
     78      CheckForContentType(contentType);
    7779      List<Type> viewTypes = (from v in views
    7880                              where ContentAttribute.CanViewType(v, contentType)
     
    8688
    8789    public static IEnumerable<Type> GetViewTypes(Type contentType, bool returnOnlyMostSpecificViewTypes) {
     90      CheckForContentType(contentType);
    8891      List<Type> viewTypes = new List<Type>(GetViewTypes(contentType));
    8992      if (returnOnlyMostSpecificViewTypes) {
     
    102105    }
    103106
    104     public static bool ViewCanViewObject(IContentView view, object content) {
     107    public static bool ViewCanViewObject(IContentView view, IContent content) {
    105108      return ContentAttribute.CanViewType(view.GetType(), content.GetType());
    106109    }
    107110
    108111    public static Type GetDefaultViewType(Type contentType) {
     112      CheckForContentType(contentType);
    109113      //check base classes for default view
    110114      Type type = contentType;
     
    148152      return (IContentView)Activator.CreateInstance(t, content);
    149153    }
    150     public static IContentView CreateDefaultView(object content, bool readOnly) {
    151       IContentView view = CreateDefaultView(content);
    152       if (view != null)
    153         view.ReadOnly = readOnly;
    154       return view;
    155     }
    156 
    157154    public static IContentView CreateView(Type viewType) {
    158       if (!typeof(IContentView).IsAssignableFrom(viewType))
     155      if (!typeof(IView).IsAssignableFrom(viewType))
    159156        throw new ArgumentException("View can not be created becaues given type " + viewType.ToString() + " is not of type IView.");
    160157      if (viewType.IsGenericTypeDefinition)
     
    163160      return (IContentView)Activator.CreateInstance(viewType);
    164161    }
    165     public static IContentView CreateView(Type viewType, bool readOnly) {
    166       IContentView view = CreateView(viewType);
    167       view.ReadOnly = readOnly;
    168       return view;
    169     }
    170 
    171162    public static IContentView CreateView(Type viewType, object content) {
    172       if (!typeof(IContentView).IsAssignableFrom(viewType))
    173         throw new ArgumentException("View can not be created becaues given type " + viewType.ToString() + " is not of type IView.");
     163      CheckForContentType(content.GetType());
     164      CheckForContentViewType(viewType);
     165
    174166      Type view = viewType;
    175167      if (view.IsGenericTypeDefinition)
     
    178170      return (IContentView)Activator.CreateInstance(view, content);
    179171    }
    180     public static IContentView CreateView(Type viewType, object content, bool readOnly) {
    181       IContentView view = CreateView(viewType, content);
    182       view.ReadOnly = readOnly;
    183       return view;
     172
     173    private static void CheckForContentType(Type contentType) {
     174          if (!typeof(IContent).IsAssignableFrom(contentType))
     175        throw new ArgumentException("DefaultViews are only specified for types of IContent and not for " + contentType + ".");
     176    }
     177    private static void CheckForContentViewType(Type viewType) {
     178      if (!typeof(IContentView).IsAssignableFrom(viewType))
     179        throw new ArgumentException("View can not be created becaues given type " + viewType.ToString() + " is not of type IContentView.");
    184180    }
    185181
Note: See TracChangeset for help on using the changeset viewer.