Changeset 3416


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

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

Location:
trunk/sources
Files:
26 edited
5 copied

Legend:

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

    r3407 r3416  
    231231      if (listView.SelectedItems.Count == 1) {
    232232        T item = (T)listView.SelectedItems[0].Tag;
    233         IView view = MainFormManager.CreateDefaultView(item, ReadOnly);
    234         if (view != null) view.Show();
     233        IView view = MainFormManager.CreateDefaultView(item);
     234        if (view != null) {
     235          view.ReadOnly = this.ReadOnly;
     236          view.Show();
     237        }
    235238      }
    236239    }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemArrayView.cs

    r3407 r3416  
    230230        T item = itemsListView.SelectedItems[0].Tag as T;
    231231        if (item != null) {
    232           IView view = MainFormManager.CreateDefaultView(item, ReadOnly);
    233           if (view != null) view.Show();
     232          IView view = MainFormManager.CreateDefaultView(item);
     233          if (view != null) {
     234            view.ReadOnly = ReadOnly;
     235            view.Show();
     236          }
    234237        }
    235238      }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs

    r3407 r3416  
    190190      if (itemsListView.SelectedItems.Count == 1) {
    191191        T item = (T)itemsListView.SelectedItems[0].Tag;
    192         IView view = MainFormManager.CreateDefaultView(item, ReadOnly);
    193         if (view != null) view.Show();
     192        IView view = MainFormManager.CreateDefaultView(item);
     193        if (view != null) {
     194          view.ReadOnly = this.ReadOnly;
     195          view.Show();
     196        }
    194197      }
    195198    }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemListView.cs

    r3407 r3416  
    224224      if (itemsListView.SelectedItems.Count == 1) {
    225225        T item = (T)itemsListView.SelectedItems[0].Tag;
    226         IView view = MainFormManager.CreateDefaultView(item, ReadOnly);
    227         if (view != null) view.Show();
     226        IView view = MainFormManager.CreateDefaultView(item);
     227        if (view != null) {
     228          view.ReadOnly = ReadOnly;
     229          view.Show();
     230        }
    228231      }
    229232    }
  • trunk/sources/HeuristicLab.Core.Views/3.3/OperatorTreeView.cs

    r3407 r3416  
    355355        IOperator op = GetOperatorTag(graphTreeView.SelectedNode);
    356356        if (op != null) {
    357           IView view = MainFormManager.CreateDefaultView(op, ReadOnly);
     357          IView view = MainFormManager.CreateDefaultView(op);
    358358          if (view != null) {
     359            view.ReadOnly = this.ReadOnly;
    359360            viewToolStripMenuItem.Enabled = true;
    360361            viewToolStripMenuItem.Tag = view;
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/AsynchronousContentView.cs

    r3342 r3416  
    88using System.Windows.Forms;
    99using System.Threading;
     10using HeuristicLab.Common;
    1011
    1112namespace HeuristicLab.MainForm.WindowsForms {
     
    1516    }
    1617
    17     public AsynchronousContentView(object content)
     18    public AsynchronousContentView(IContent content)
    1819      : this() {
    1920      this.Content = content;
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/AsynchronousStorableContentView.Designer.cs

    r3410 r3416  
    11namespace HeuristicLab.MainForm.WindowsForms {
    2   partial class ContentView {
     2  partial class AsynchronousStorableContentView {
    33    /// <summary>
    44    /// Required designer variable.
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/AsynchronousStorableContentView.cs

    r3410 r3416  
    2828using System.Text;
    2929using System.Windows.Forms;
     30using HeuristicLab.Common;
     31using System.Threading;
    3032
    3133namespace HeuristicLab.MainForm.WindowsForms {
    32   public partial class ContentView : View, IContentView {
    33     private object content;
    34     public object Content {
    35       get { return content; }
    36       set {
    37         if ((value != null) && (!MainFormManager.ViewCanViewObject(this, value)))
    38           throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name));
    39         if (InvokeRequired) {
    40           Invoke(new Action<object>(delegate(object o) { this.Content = o; }), value);
    41         } else {
    42           if (this.content != value) {
    43             if (this.content != null) this.DeregisterContentEvents();
    44             this.content = value;
    45             if (this.content != null) this.RegisterContentEvents();
    46             this.OnContentChanged();
    47           }
    48         }
    49       }
     34  public partial class AsynchronousStorableContentView : StorableContentView {
     35    public AsynchronousStorableContentView()
     36      : base() {
     37      InitializeComponent();
    5038    }
    51     private bool saveEnabled;
    52     public bool SaveEnabled {
    53       get { return saveEnabled; }
    54       protected set {
    55         if (value != saveEnabled) {
    56           saveEnabled = value;
    57           OnChanged();
    58         }
     39    public AsynchronousStorableContentView(IStorableContent content)
     40      : base() {
     41      this.Content = content;
     42    }
     43
     44    /// <summary>
     45    /// Asynchronous call of GUI updating.
     46    /// </summary>
     47    /// <param name="method">The delegate to invoke.</param>
     48    protected new void Invoke(Delegate method) {
     49      // prevents blocking of worker thread in Invoke, if the control is disposed
     50      IAsyncResult result = BeginInvoke(method);
     51      result.AsyncWaitHandle.WaitOne(1000, false);
     52      if (result.IsCompleted) try { EndInvoke(result); }
     53        catch (ObjectDisposedException) { } else {
     54        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
     55          new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
     56          null, -1, true);
    5957      }
    6058    }
    6159
    62     public ContentView()
    63       : base() {
    64       InitializeComponent();
    65       saveEnabled = true;
    66     }
    67     public ContentView(object content)
    68       : this() {
    69       this.content = content;
    70     }
    71 
    7260    /// <summary>
    73     /// Adds eventhandlers to the current instance.
     61    /// Asynchronous call of GUI updating.
    7462    /// </summary>
    75     protected virtual void RegisterContentEvents() {
    76     }
    77 
    78     /// <summary>
    79     /// Removes the eventhandlers from the current instance.
    80     /// </summary>
    81     protected virtual void DeregisterContentEvents() {
    82     }
    83 
    84     /// <summary>
    85     /// Is called when the content property changes.
    86     /// </summary>
    87     protected virtual void OnContentChanged() {
     63    /// <param name="method">The delegate to invoke.</param>
     64    /// <param name="args">The invoke arguments.</param>
     65    protected new void Invoke(Delegate method, params object[] args) {
     66      // prevents blocking of worker thread in Invoke, if the control is disposed
     67      IAsyncResult result = BeginInvoke(method, args);
     68      result.AsyncWaitHandle.WaitOne(1000, false);
     69      if (result.IsCompleted) try { EndInvoke(result); }
     70        catch (ObjectDisposedException) { } else {
     71        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
     72          new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
     73          null, -1, true);
     74      }
    8875    }
    8976  }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ContentView.cs

    r3389 r3416  
    2828using System.Text;
    2929using System.Windows.Forms;
     30using HeuristicLab.Common;
     31using System.Reflection;
    3032
    3133namespace HeuristicLab.MainForm.WindowsForms {
    3234  public partial class ContentView : View, IContentView {
    33     private object content;
    34     public object Content {
     35    private IContent content;
     36    public IContent Content {
    3537      get { return content; }
    3638      set {
     
    3840          throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name));
    3941        if (InvokeRequired) {
    40           Invoke(new Action<object>(delegate(object o) { this.Content = o; }), value);
     42          Invoke(new Action<IContent>(delegate(IContent o) { this.Content = o; }), value);
    4143        } else {
    4244          if (this.content != value) {
     
    4951      }
    5052    }
    51     private bool saveEnabled;
    52     public bool SaveEnabled {
    53       get { return saveEnabled; }
    54       protected set {
    55         if (value != saveEnabled) {
    56           saveEnabled = value;
    57           OnChanged();
    58         }
    59       }
    60     }
    6153
    6254    public ContentView()
    6355      : base() {
    6456      InitializeComponent();
    65       saveEnabled = true;
     57      this.locked = false;
    6658    }
    67     public ContentView(object content)
     59    public ContentView(IContent content)
    6860      : this() {
    6961      this.content = content;
     62    }
     63
     64    private bool locked;
     65    public virtual bool Locked {
     66      get { return this.locked; }
     67      set {
     68        if (InvokeRequired) {
     69          Action<bool> action = delegate(bool b) { this.Locked = b; };
     70          Invoke(action, value);
     71        } else {
     72          if (value != locked) {
     73            locked = value;
     74            PropertyInfo prop = typeof(IContentView).GetProperty("Locked");
     75            PropagateStateChanges(this, typeof(IContentView), prop);
     76            OnLockedChanged();
     77            OnChanged();
     78          }
     79        }
     80      }
     81    }
     82    public event EventHandler LockedChanged;
     83    protected virtual void OnLockedChanged() {
     84      if (InvokeRequired)
     85        Invoke((MethodInvoker)OnLockedChanged);
     86      else {
     87        EventHandler handler = LockedChanged;
     88        if (handler != null)
     89          handler(this, EventArgs.Empty);
     90      }
    7091    }
    7192
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/HeuristicLab.MainForm.WindowsForms-3.2.csproj

    r3281 r3416  
    100100    <None Include="HeuristicLabMainFormWindowsFormsPlugin.cs.frame" />
    101101    <Compile Include="ControlExtensions.cs" />
     102    <Compile Include="AsynchronousStorableContentView.cs">
     103      <SubType>UserControl</SubType>
     104    </Compile>
     105    <Compile Include="AsynchronousStorableContentView.Designer.cs">
     106      <DependentUpon>AsynchronousStorableContentView.cs</DependentUpon>
     107    </Compile>
     108    <Compile Include="StorableContentView.cs">
     109      <SubType>UserControl</SubType>
     110    </Compile>
     111    <Compile Include="StorableContentView.Designer.cs">
     112      <DependentUpon>StorableContentView.cs</DependentUpon>
     113    </Compile>
    102114    <Compile Include="DockForm.cs">
    103115      <SubType>Form</SubType>
     
    167179      <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project>
    168180      <Name>HeuristicLab.Common.Resources-3.2</Name>
     181    </ProjectReference>
     182    <ProjectReference Include="..\..\HeuristicLab.Common\3.3\HeuristicLab.Common-3.3.csproj">
     183      <Project>{A9AD58B9-3EF9-4CC1-97E5-8D909039FF5C}</Project>
     184      <Name>HeuristicLab.Common-3.3</Name>
    169185    </ProjectReference>
    170186    <ProjectReference Include="..\..\HeuristicLab.ExtLibs\HeuristicLab.WinFormsUI\2.3.1\WinFormsUI-2.3.1\WinFormsUI-2.3.1.csproj">
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/StorableContentView.Designer.cs

    r3410 r3416  
    11namespace HeuristicLab.MainForm.WindowsForms {
    2   partial class ContentView {
     2  partial class StorableContentView {
    33    /// <summary>
    44    /// Required designer variable.
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/StorableContentView.cs

    r3410 r3416  
    2828using System.Text;
    2929using System.Windows.Forms;
     30using HeuristicLab.Common;
    3031
    3132namespace HeuristicLab.MainForm.WindowsForms {
    32   public partial class ContentView : View, IContentView {
    33     private object content;
    34     public object Content {
    35       get { return content; }
    36       set {
    37         if ((value != null) && (!MainFormManager.ViewCanViewObject(this, value)))
    38           throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name));
    39         if (InvokeRequired) {
    40           Invoke(new Action<object>(delegate(object o) { this.Content = o; }), value);
    41         } else {
    42           if (this.content != value) {
    43             if (this.content != null) this.DeregisterContentEvents();
    44             this.content = value;
    45             if (this.content != null) this.RegisterContentEvents();
    46             this.OnContentChanged();
    47           }
    48         }
    49       }
     33  public partial class StorableContentView : ContentView, IStorableContentView {
     34    public StorableContentView()
     35      : base() {
     36      InitializeComponent();
    5037    }
    51     private bool saveEnabled;
    52     public bool SaveEnabled {
    53       get { return saveEnabled; }
    54       protected set {
    55         if (value != saveEnabled) {
    56           saveEnabled = value;
    57           OnChanged();
    58         }
    59       }
     38    public StorableContentView(IStorableContent content)
     39      : this() {
     40      this.Content = content;
    6041    }
    6142
    62     public ContentView()
    63       : base() {
    64       InitializeComponent();
    65       saveEnabled = true;
    66     }
    67     public ContentView(object content)
    68       : this() {
    69       this.content = content;
    70     }
    71 
    72     /// <summary>
    73     /// Adds eventhandlers to the current instance.
    74     /// </summary>
    75     protected virtual void RegisterContentEvents() {
    76     }
    77 
    78     /// <summary>
    79     /// Removes the eventhandlers from the current instance.
    80     /// </summary>
    81     protected virtual void DeregisterContentEvents() {
    82     }
    83 
    84     /// <summary>
    85     /// Is called when the content property changes.
    86     /// </summary>
    87     protected virtual void OnContentChanged() {
     43    public new IStorableContent Content {
     44      get { return (IStorableContent)base.Content; }
     45      set { base.Content = value; }
    8846    }
    8947  }
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/View.cs

    r3403 r3416  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Windows.Forms;
     25using System.Reflection;
     26using System.ComponentModel;
    2427
    2528namespace HeuristicLab.MainForm.WindowsForms {
     
    6568          if (value != readOnly) {
    6669            readOnly = value;
     70            PropertyInfo prop = typeof(IView).GetProperty("ReadOnly");
     71            PropagateStateChanges(this, typeof(IView), prop);
    6772            OnReadOnlyChanged();
    6873          }
     
    135140      }
    136141    }
     142    protected void PropagateStateChanges(Control control, Type type, PropertyInfo propertyInfo) {
     143      if (!type.GetProperties().Contains(propertyInfo))
     144        throw new ArgumentException("The specified type " + type + "implement the property " + propertyInfo.Name + ".");
     145      if (!type.IsAssignableFrom(this.GetType()))
     146        throw new ArgumentException("The specified type " + type + "must be the same or a base class / interface of this object.");
     147      if (!propertyInfo.CanWrite)
     148        throw new ArgumentException("The specified property " + propertyInfo.Name + " must have a setter.");
     149
     150      foreach (Control c in control.Controls) {
     151        Type controlType = c.GetType();
     152        PropertyInfo controlPropertyInfo = controlType.GetProperty(propertyInfo.Name, propertyInfo.PropertyType);
     153        if (type.IsAssignableFrom(controlType) && controlPropertyInfo!= null) {
     154          var thisValue = propertyInfo.GetValue(this, null);
     155          controlPropertyInfo.SetValue(c, thisValue, null);
     156        } else
     157          PropagateStateChanges(c, type, propertyInfo);
     158      }
     159    }
    137160    public event EventHandler Changed;
    138161    protected virtual void OnChanged() {
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/ViewHost.cs

    r3403 r3416  
    2525using System.Windows.Forms;
    2626using HeuristicLab.MainForm;
     27using HeuristicLab.Common;
    2728
    2829namespace HeuristicLab.MainForm.WindowsForms {
     
    3839      activeView = null;
    3940    }
    40     public ViewHost(object content)
     41    public ViewHost(IContent content)
    4142      : this() {
    4243      this.Content = content;
     
    7576            View view = activeView as View;
    7677            if (view != null)
    77               view.OnShown(new ViewShownEventArgs(view,false));
     78              view.OnShown(new ViewShownEventArgs(view, false));
    7879          }
    7980          ActiveViewChanged();
     
    9596      }
    9697    }
    97     public new object Content {
     98    public new IContent Content {
    9899      get { return base.Content; }
    99100      set {
     
    116117    }
    117118
    118     protected override void OnReadOnlyChanged() {
    119       base.OnReadOnlyChanged();
    120       foreach (IContentView view in cachedViews.Values)
    121         view.ReadOnly = this.ReadOnly;
    122     }
     119
    123120
    124121    protected override void OnContentChanged() {
     
    162159        view = cachedViews[ViewType];
    163160      else {
    164         view = MainFormManager.CreateView(viewType, Content, ReadOnly);
     161        view = MainFormManager.CreateView(viewType, Content);
     162        view.ReadOnly = this.ReadOnly;
     163        view.Locked = this.Locked;
    165164        cachedViews.Add(viewType, view);
    166165      }
     
    192191      if (ActiveView != null) {
    193192        this.Caption = this.ActiveView.Caption;
    194         this.SaveEnabled = this.ActiveView.SaveEnabled;
     193        this.Locked = this.ActiveView.Locked;
    195194      }
    196195    }
    197196
    198197    #region forwarding of view events
     198    protected override void OnReadOnlyChanged() {
     199      base.OnReadOnlyChanged();
     200      foreach (IContentView view in cachedViews.Values)
     201        view.ReadOnly = this.ReadOnly;
     202    }
     203    protected override void OnLockedChanged() {
     204      base.OnLockedChanged();
     205      foreach (IContentView view in cachedViews.Values)
     206        view.Locked = this.Locked;
     207    }
    199208    internal protected override void OnShown(ViewShownEventArgs e) {
    200209      base.OnShown(e);
     
    203212        view.OnShown(e);
    204213    }
    205 
    206214    internal protected override void OnHidden(EventArgs e) {
    207215      base.OnHidden(e);
     
    210218        view.OnHidden(e);
    211219    }
    212 
    213220    internal protected override void OnClosing(FormClosingEventArgs e) {
    214221      base.OnClosing(e);
     
    216223        view.OnClosing(e);
    217224    }
    218 
    219225    internal protected override void OnClosed(FormClosedEventArgs e) {
    220226      base.OnClosed(e);
     
    246252
    247253    private void viewsLabel_DoubleClick(object sender, EventArgs e) {
    248       MainFormManager.CreateView(viewType, Content, ReadOnly).Show();
     254      IContentView view = MainFormManager.CreateView(viewType, Content);
     255      view.ReadOnly = this.ReadOnly;
     256      view.Locked = this.Locked;
     257      view.Show();
    249258    }
    250259    private void viewContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) {
     
    255264    private bool startDragAndDrop;
    256265    private void viewsLabel_MouseDown(object sender, MouseEventArgs e) {
    257       startDragAndDrop = true;
    258       viewsLabel.Capture = false;
     266      if (!Locked) {
     267        startDragAndDrop = true;
     268        viewsLabel.Capture = false;
     269      }
    259270    }
    260271    private void viewsLabel_MouseLeave(object sender, EventArgs e) {
  • 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
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r3407 r3416  
    153153      else {
    154154        this.ReadOnly = Content.ExecutionState == ExecutionState.Started;
    155         SaveEnabled = Content.ExecutionState != ExecutionState.Started;
     155        Locked = Content.ExecutionState == ExecutionState.Started;
    156156        EnableDisableButtons();
    157157      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.cs

    r3407 r3416  
    120120      else {
    121121        this.ReadOnly = Content.ExecutionState == ExecutionState.Started;
    122         SaveEnabled = Content.ExecutionState != ExecutionState.Started;
     122        Locked = Content.ExecutionState == ExecutionState.Started;
    123123        newAlgorithmButton.Enabled = openAlgorithmButton.Enabled = saveAlgorithmButton.Enabled = Content.ExecutionState != ExecutionState.Started;
    124124        EnableDisableButtons();
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentView.cs

    r3367 r3416  
    107107        nameTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
    108108        descriptionTextBox.Enabled = Content.ExecutionState != ExecutionState.Started;
    109         SaveEnabled = Content.ExecutionState != ExecutionState.Started;
     109        Locked = Content.ExecutionState == ExecutionState.Started;
    110110        EnableDisableButtons();
    111111      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs

    r3393 r3416  
    166166      if (itemsListView.SelectedItems.Count == 1) {
    167167        IRun item = (IRun)itemsListView.SelectedItems[0].Tag;
    168         IView view = MainFormManager.CreateDefaultView(item,ReadOnly);
    169         if (view != null) view.Show();
     168        IView view = MainFormManager.CreateDefaultView(item);
     169        if (view != null) {
     170          view.ReadOnly = ReadOnly;
     171          view.Show();
     172        }
    170173      }
    171174    }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunView.cs

    r3376 r3416  
    120120      if (listView.SelectedItems.Count == 1) {
    121121        viewHost.ViewType = null;
    122         viewHost.Content = listView.SelectedItems[0].Tag;
     122        viewHost.Content = (IContent) listView.SelectedItems[0].Tag;
    123123      } else {
    124124        viewHost.Content = null;
     
    128128      if (listView.SelectedItems.Count == 1) {
    129129        IItem item = (IItem)listView.SelectedItems[0].Tag;
    130         IView view = MainFormManager.CreateDefaultView(item,ReadOnly);
    131         if (view != null) view.Show();
     130        IView view = MainFormManager.CreateDefaultView(item);
     131        if (view != null) {
     132          view.ReadOnly = ReadOnly;
     133          view.Show();
     134        }
    132135      }
    133136    }
     
    141144    }
    142145    private void showAlgorithmButton_Click(object sender, EventArgs e) {
    143       MainFormManager.CreateDefaultView(Content.Algorithm.Clone(),ReadOnly).Show();
     146      IContentView view = MainFormManager.CreateDefaultView(Content.Algorithm.Clone());
     147      if (view != null) {
     148        view.ReadOnly = ReadOnly;
     149        view.Show();
     150      }
    144151    }
    145152  }
  • trunk/sources/HeuristicLab.Optimizer/3.3/FileManager.cs

    r3177 r3416  
    108108    }
    109109    private static void Save(IContentView view) {
    110       if (view.SaveEnabled) {
     110      if (!view.Locked) {
    111111        if ((!files.ContainsKey(view)) || (!File.Exists(files[view].Filename))) {
    112112          SaveAs(view);
     
    127127    }
    128128    public static void SaveAs(IContentView view) {
    129       if (view.SaveEnabled) {
     129      if (!view.Locked) {
    130130        if (saveFileDialog == null) {
    131131          saveFileDialog = new SaveFileDialog();
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/CopyToClipboardMenuItem.cs

    r3376 r3416  
    4848    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    4949      ItemView activeView = MainFormManager.MainForm.ActiveView as ItemView;
    50       ToolStripItem.Enabled = (activeView != null) && (activeView.SaveEnabled);
     50      ToolStripItem.Enabled = (activeView != null) && (!activeView.Locked);
    5151    }
    5252
    5353    public override void Execute() {
    5454      ItemView activeView = MainFormManager.MainForm.ActiveView as ItemView;
    55       if ((activeView != null) && (activeView.SaveEnabled)) {
     55      if ((activeView != null) && (!activeView.Locked)) {
    5656        Clipboard<IItem> clipboard = ((OptimizerMainForm)MainFormManager.MainForm).Clipboard;
    5757        clipboard.AddItem((IItem)activeView.Content.Clone());
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveAllMenuItem.cs

    r2961 r3416  
    4747    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    4848      var views = from v in MainFormManager.MainForm.Views.OfType<IContentView>()
    49                   where v.SaveEnabled
     49                  where !v.Locked
    5050                  select v;
    5151      ToolStripItem.Enabled = views.FirstOrDefault() != null;
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveAsMenuItem.cs

    r2961 r3416  
    4545    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    4646      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    47       ToolStripItem.Enabled = (activeView != null) && (activeView.SaveEnabled);
     47      ToolStripItem.Enabled = (activeView != null) && (!activeView.Locked);
    4848    }
    4949
  • trunk/sources/HeuristicLab.Optimizer/3.3/MenuItems/SaveMenuItem.cs

    r2961 r3416  
    4949    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    5050      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    51       ToolStripItem.Enabled = (activeView != null) && (activeView.SaveEnabled);
     51      ToolStripItem.Enabled = (activeView != null) && (!activeView.Locked);
    5252    }
    5353
  • trunk/sources/HeuristicLab.Optimizer/3.3/ToolBarItems/SaveAllToolBarItem.cs

    r2961 r3416  
    4646    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    4747      var views = from v in MainFormManager.MainForm.Views.OfType<IContentView>()
    48                   where v.SaveEnabled
     48                  where !v.Locked
    4949                  select v;
    5050      ToolStripItem.Enabled = views.FirstOrDefault() != null;
  • trunk/sources/HeuristicLab.Optimizer/3.3/ToolBarItems/SaveToolBarItem.cs

    r2961 r3416  
    4545    protected override void OnActiveViewChanged(object sender, EventArgs e) {
    4646      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
    47       ToolStripItem.Enabled = (activeView != null) && (activeView.SaveEnabled);
     47      ToolStripItem.Enabled = (activeView != null) && (!activeView.Locked);
    4848    }
    4949
Note: See TracChangeset for help on using the changeset viewer.