Changeset 3329


Ignore:
Timestamp:
04/13/10 17:07:10 (11 years ago)
Author:
mkommend
Message:

added ViewHost in ExperimentView for the RunCollection and implemented IStringConvertibleMatrix in RunCollection (ticket #970)

Location:
trunk/sources
Files:
5 edited

Legend:

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

    r3266 r3329  
    2525    /// <param name="method">The delegate to invoke.</param>
    2626    protected new void Invoke(Delegate method) {
    27       // prevent blocking of worker thread in Invoke, if the control is disposed
     27      // prevents blocking of worker thread in Invoke, if the control is disposed
     28      if (!IsHandleCreated)
     29        return;
    2830      IAsyncResult result = BeginInvoke(method);
    2931      result.AsyncWaitHandle.WaitOne(1000, false);
    30       if (result.IsCompleted) try { EndInvoke(result); } catch (ObjectDisposedException) { }
    31       else {
     32      if (result.IsCompleted) try { EndInvoke(result); }
     33        catch (ObjectDisposedException) { } else {
    3234        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
    3335          new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
     
    4244    /// <param name="args">The invoke arguments.</param>
    4345    protected new void Invoke(Delegate method, params object[] args) {
    44       // prevent blocking of worker thread in Invoke, if the control is disposed
     46      // prevents blocking of worker thread in Invoke, if the control is disposed
     47      if (!IsHandleCreated)
     48        return;
    4549      IAsyncResult result = BeginInvoke(method, args);
    4650      result.AsyncWaitHandle.WaitOne(1000, false);
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentView.Designer.cs

    r3275 r3329  
    4545    /// </summary>
    4646    private void InitializeComponent() {
     47      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ExperimentView));
    4748      this.tabControl = new System.Windows.Forms.TabControl();
    4849      this.optimizersTabPage = new System.Windows.Forms.TabPage();
    4950      this.optimizerListView = new HeuristicLab.Optimization.Views.OptimizerListView();
     51      this.runsTabPage = new System.Windows.Forms.TabPage();
    5052      this.startButton = new System.Windows.Forms.Button();
    5153      this.stopButton = new System.Windows.Forms.Button();
     
    5456      this.executionTimeTextBox = new System.Windows.Forms.TextBox();
    5557      this.pauseButton = new System.Windows.Forms.Button();
    56       this.runsTabPage = new System.Windows.Forms.TabPage();
    57       this.runsView = new HeuristicLab.Optimization.Views.RunCollectionView();
     58      this.runsViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    5859      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5960      this.tabControl.SuspendLayout();
     
    108109      this.optimizerListView.TabIndex = 0;
    109110      //
     111      // runsTabPage
     112      //
     113      this.runsTabPage.Controls.Add(this.runsViewHost);
     114      this.runsTabPage.Location = new System.Drawing.Point(4, 22);
     115      this.runsTabPage.Name = "runsTabPage";
     116      this.runsTabPage.Padding = new System.Windows.Forms.Padding(3);
     117      this.runsTabPage.Size = new System.Drawing.Size(671, 374);
     118      this.runsTabPage.TabIndex = 2;
     119      this.runsTabPage.Text = "Runs";
     120      this.runsTabPage.UseVisualStyleBackColor = true;
     121      //
    110122      // startButton
    111123      //
    112124      this.startButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    113       this.startButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Play;
     125      this.startButton.Image = ((System.Drawing.Image)(resources.GetObject("startButton.Image")));
    114126      this.startButton.Location = new System.Drawing.Point(0, 458);
    115127      this.startButton.Name = "startButton";
     
    123135      //
    124136      this.stopButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    125       this.stopButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Stop;
     137      this.stopButton.Image = ((System.Drawing.Image)(resources.GetObject("stopButton.Image")));
    126138      this.stopButton.Location = new System.Drawing.Point(60, 458);
    127139      this.stopButton.Name = "stopButton";
     
    135147      //
    136148      this.resetButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    137       this.resetButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Restart;
     149      this.resetButton.Image = ((System.Drawing.Image)(resources.GetObject("resetButton.Image")));
    138150      this.resetButton.Location = new System.Drawing.Point(90, 458);
    139151      this.resetButton.Name = "resetButton";
     
    166178      //
    167179      this.pauseButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    168       this.pauseButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Pause;
     180      this.pauseButton.Image = ((System.Drawing.Image)(resources.GetObject("pauseButton.Image")));
    169181      this.pauseButton.Location = new System.Drawing.Point(30, 458);
    170182      this.pauseButton.Name = "pauseButton";
     
    175187      this.pauseButton.Click += new System.EventHandler(this.pauseButton_Click);
    176188      //
    177       // runsTabPage
    178       //
    179       this.runsTabPage.Controls.Add(this.runsView);
    180       this.runsTabPage.Location = new System.Drawing.Point(4, 22);
    181       this.runsTabPage.Name = "runsTabPage";
    182       this.runsTabPage.Padding = new System.Windows.Forms.Padding(3);
    183       this.runsTabPage.Size = new System.Drawing.Size(671, 374);
    184       this.runsTabPage.TabIndex = 2;
    185       this.runsTabPage.Text = "Runs";
    186       this.runsTabPage.UseVisualStyleBackColor = true;
    187       //
    188       // runsView
    189       //
    190       this.runsView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     189      // runsViewHost
     190      //
     191      this.runsViewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    191192                  | System.Windows.Forms.AnchorStyles.Left)
    192193                  | System.Windows.Forms.AnchorStyles.Right)));
    193       this.runsView.Caption = "RunCollection";
    194       this.runsView.Content = null;
    195       this.runsView.Location = new System.Drawing.Point(6, 6);
    196       this.runsView.Name = "runsView";
    197       this.runsView.Size = new System.Drawing.Size(659, 362);
    198       this.runsView.TabIndex = 0;
     194      this.runsViewHost.Content = null;
     195      this.runsViewHost.Location = new System.Drawing.Point(2, 6);
     196      this.runsViewHost.Name = "runsViewHost";
     197      this.runsViewHost.Size = new System.Drawing.Size(663, 362);
     198      this.runsViewHost.TabIndex = 0;
     199      this.runsViewHost.ViewType = null;
    199200      //
    200201      // ExperimentView
     
    242243    private OptimizerListView optimizerListView;
    243244    private System.Windows.Forms.TabPage runsTabPage;
    244     private RunCollectionView runsView;
     245    private HeuristicLab.MainForm.WindowsForms.ViewHost runsViewHost;
    245246
    246247  }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/ExperimentView.cs

    r3275 r3329  
    7171      if (Content == null) {
    7272        optimizerListView.Content = null;
    73         runsView.Content = null;
     73        runsViewHost.Content = null;
    7474        tabControl.Enabled = false;
    7575        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
     
    7878      } else {
    7979        optimizerListView.Content = Content.Optimizers;
    80         runsView.Content = Content.Runs;
     80        runsViewHost.Content = Content.Runs;
    8181        tabControl.Enabled = true;
    8282        EnableDisableButtons();
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/HeuristicLab.Optimization.Views-3.3.csproj

    r3274 r3329  
    180180      <Name>HeuristicLab.Core-3.3</Name>
    181181    </ProjectReference>
     182    <ProjectReference Include="..\..\HeuristicLab.Data\3.3\HeuristicLab.Data-3.3.csproj">
     183      <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project>
     184      <Name>HeuristicLab.Data-3.3</Name>
     185    </ProjectReference>
    182186    <ProjectReference Include="..\..\HeuristicLab.MainForm.WindowsForms\3.2\HeuristicLab.MainForm.WindowsForms-3.2.csproj">
    183187      <Project>{AB687BBE-1BFE-476B-906D-44237135431D}</Project>
  • trunk/sources/HeuristicLab.Optimization/3.3/RunCollection.cs

    r3317 r3329  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
    2425using HeuristicLab.Core;
     26using HeuristicLab.Data;
    2527using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     28using HeuristicLab.Common;
    2629
    2730namespace HeuristicLab.Optimization {
    2831  [StorableClass]
    2932  [Item("RunCollection", "Represents a collection of runs.")]
    30   public class RunCollection : ItemCollection<IRun> {
    31     public RunCollection() : base() { }
    32     public RunCollection(int capacity) : base(capacity) { }
    33     public RunCollection(IEnumerable<IRun> collection) : base(collection) { }
     33  public class RunCollection : ItemCollection<IRun>, IStringConvertibleMatrix {
     34    public RunCollection() : base() { Initialize(); }
     35    public RunCollection(int capacity) : base(capacity) { Initialize(); }
     36    public RunCollection(IEnumerable<IRun> collection) : base(collection) { Initialize(); this.OnItemsAdded(collection); }
     37
     38    protected static Type[] viewableDataTypes = new Type[]{typeof(BoolValue), typeof(DoubleValue), typeof(IntValue),
     39      typeof(PercentValue), typeof(StringValue)};
     40
     41    protected override void OnCollectionReset(IEnumerable<IRun> items, IEnumerable<IRun> oldItems) {
     42      parameterNames.Clear();
     43      resultNames.Clear();
     44      foreach (IRun run in items) {
     45        foreach (KeyValuePair<string, IItem> parameter in run.Parameters)
     46          AddParameter(parameter.Key, parameter.Value);
     47        foreach (KeyValuePair<string, IItem> result in run.Results)
     48          AddResult(result.Key, result.Value);
     49      }
     50      base.OnCollectionReset(items, oldItems);
     51      OnReset();
     52      OnColumnNamesChanged();
     53      OnRowNamesChanged();
     54    }
     55    protected override void OnItemsAdded(IEnumerable<IRun> items) {
     56      bool columnNamesChanged = false;
     57      foreach (IRun run in items) {
     58        foreach (KeyValuePair<string, IItem> parameter in run.Parameters)
     59          columnNamesChanged |= AddParameter(parameter.Key, parameter.Value);
     60        foreach (KeyValuePair<string, IItem> result in run.Results)
     61          columnNamesChanged |= AddResult(result.Key, result.Value);
     62      }
     63      base.OnItemsAdded(items);
     64      OnReset();
     65      if (columnNamesChanged)
     66        OnColumnNamesChanged();
     67      OnRowNamesChanged();
     68    }
     69    protected override void OnItemsRemoved(IEnumerable<IRun> items) {
     70      bool columnNamesChanged = false;
     71      foreach (IRun run in items) {
     72        foreach (string parameterName in run.Parameters.Keys)
     73          columnNamesChanged |= RemoveParameterName(parameterName);
     74        foreach (string resultName in run.Results.Keys)
     75          columnNamesChanged |= RemoveResultName(resultName);
     76      }
     77      base.OnItemsRemoved(items);
     78      OnReset();
     79      if (columnNamesChanged)
     80        OnColumnNamesChanged();
     81      OnRowNamesChanged();
     82    }
     83
     84    private void Initialize() {
     85      parameterNames = new List<string>();
     86      resultNames = new List<string>();
     87      this.ReadOnlyView = true;
     88    }
     89
     90    private bool AddParameter(string name, IItem value) {
     91      if (value == null)
     92        return false;
     93      if (!parameterNames.Contains(name) &&
     94          viewableDataTypes.Any(x => x.IsAssignableFrom(value.GetType()))) {
     95        parameterNames.Add(name);
     96        return true;
     97      }
     98      return false;
     99    }
     100    private bool AddResult(string name, IItem value) {
     101      if (value == null)
     102        return false;
     103      if (!resultNames.Contains(name) &&
     104          viewableDataTypes.Any(x => x.IsAssignableFrom(value.GetType()))) {
     105        resultNames.Add(name);
     106        return true;
     107      }
     108      return false;
     109    }
     110    private bool RemoveParameterName(string name) {
     111      if (!list.Any(x => x.Parameters.ContainsKey(name))) {
     112        parameterNames.Remove(name);
     113        return true;
     114      }
     115      return false;
     116    }
     117    private bool RemoveResultName(string name) {
     118      if (!list.Any(x => x.Results.ContainsKey(name))) {
     119        resultNames.Remove(name);
     120        return true;
     121      }
     122      return false;
     123    }
     124
     125    #region IStringConvertibleMatrix Members
     126    private List<string> parameterNames;
     127    private List<string> resultNames;
     128    public int Rows {
     129      get { return this.Count; }
     130      set { throw new System.NotImplementedException(); }
     131    }
     132    public int Columns {
     133      get { return parameterNames.Count + resultNames.Count; }
     134      set { throw new NotSupportedException(); }
     135    }
     136    public IEnumerable<string> ColumnNames {
     137      get {
     138        List<string> value = new List<string>(parameterNames);
     139        value.AddRange(resultNames);
     140        return value;
     141      }
     142      set { throw new NotSupportedException(); }
     143    }
     144    public IEnumerable<string> RowNames {
     145      get { return list.Select(x => x.Name).ToList(); }
     146      set { throw new NotSupportedException(); }
     147    }
     148    public bool SortableView {
     149      get { return true; }
     150      set { throw new NotSupportedException(); }
     151    }
     152
     153    public string GetValue(int rowIndex, int columnIndex) {
     154      IRun run = this.list[rowIndex];
     155      string value = string.Empty;
     156
     157      if (columnIndex < parameterNames.Count) {
     158        string parameterName = parameterNames[columnIndex];
     159        if (run.Parameters.ContainsKey(parameterName)) {
     160          IItem param = run.Parameters[parameterName];
     161          if (param != null) value = param.ToString();
     162        }
     163      } else if (columnIndex < parameterNames.Count + resultNames.Count) {
     164        string resultName = resultNames[columnIndex - parameterNames.Count];
     165        if (run.Results.ContainsKey(resultName)) {
     166          IItem result = run.Results[resultName];
     167          if (result != null) value = result.ToString();
     168        }
     169      }
     170      return value;
     171    }
     172
     173    public event EventHandler<EventArgs<int, int>> ItemChanged;
     174    protected virtual void OnItemChanged(int rowIndex, int columnIndex) {
     175      if (ItemChanged != null)
     176        ItemChanged(this, new EventArgs<int, int>(rowIndex, columnIndex));
     177      OnToStringChanged();
     178    }
     179    public event EventHandler Reset;
     180    protected virtual void OnReset() {
     181      if (Reset != null)
     182        Reset(this, EventArgs.Empty);
     183      OnToStringChanged();
     184    }
     185    public event EventHandler ColumnNamesChanged;
     186    protected virtual void OnColumnNamesChanged() {
     187      EventHandler handler = ColumnNamesChanged;
     188      if (handler != null)
     189        handler(this, EventArgs.Empty);
     190    }
     191    public event EventHandler RowNamesChanged;
     192    protected virtual void OnRowNamesChanged() {
     193      EventHandler handler = RowNamesChanged;
     194      if (handler != null)
     195        handler(this, EventArgs.Empty);
     196    }
     197
     198    public event EventHandler SortableViewChanged;
     199    public bool Validate(string value, out string errorMessage) { throw new NotSupportedException(); }
     200    public bool SetValue(string value, int rowIndex, int columnIndex) { throw new NotSupportedException(); }
     201    #endregion
    34202  }
    35203}
Note: See TracChangeset for help on using the changeset viewer.