Free cookie consent management tool by TermsFeed Policy Generator

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

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

Location:
trunk/sources/HeuristicLab.MainForm/3.2
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm/3.2/HeuristicLab.MainForm-3.2.csproj

    r2900 r3416  
    8585  <ItemGroup>
    8686    <None Include="HeuristicLabMainFormPlugin.cs.frame" />
     87    <Compile Include="Interfaces\IStorableContentView.cs" />
    8788    <Compile Include="ViewAttribute.cs" />
    8889    <Compile Include="Interfaces\IContentView.cs" />
     
    109110  </ItemGroup>
    110111  <ItemGroup>
     112    <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
     113      <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
     114      <Name>HeuristicLab.Common-3.3</Name>
     115    </ProjectReference>
    111116    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
    112117      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IContentView.cs

    r3389 r3416  
    2424using System.Text;
    2525using System.ComponentModel;
     26using HeuristicLab.Common;
    2627
    2728namespace HeuristicLab.MainForm {
    2829  public interface IContentView : IView {
    29     object Content { get; set; }
    30     bool SaveEnabled { get; }
     30    IContent Content { get; set; }
     31    bool Locked { get; set; }
     32    event EventHandler LockedChanged;
    3133  }
    3234}
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IStorableContentView.cs

    r3410 r3416  
    2424using System.Text;
    2525using System.ComponentModel;
     26using HeuristicLab.Common;
    2627
    2728namespace HeuristicLab.MainForm {
    28   public interface IContentView : IView {
    29     object Content { get; set; }
    30     bool SaveEnabled { get; }
     29  public interface IStorableContentView : IContentView {
     30    new IStorableContent Content { get; set; }
    3131  }
    3232}
  • trunk/sources/HeuristicLab.MainForm/3.2/Interfaces/IView.cs

    r3350 r3416  
    2727namespace HeuristicLab.MainForm {
    2828  public interface IView {
    29 
    3029    bool IsShown { get; }
    3130    string Caption { get; set; }
  • 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.