Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/28/18 11:13:37 (6 years ago)
Author:
gkronber
Message:

#2522: merged trunk changes from r13402:15972 to branch resolving conflicts where necessary

Location:
branches/2522_RefactorPluginInfrastructure
Files:
12 edited
4 copied

Legend:

Unmodified
Added
Removed
  • branches/2522_RefactorPluginInfrastructure

  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Optimization.Views

  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBoxPlotView.Designer.cs

    r12012 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    5454      this.yAxisComboBox = new System.Windows.Forms.ComboBox();
    5555      this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
     56      this.openBubbleChartViewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5657      this.noRunsLabel = new System.Windows.Forms.Label();
    5758      this.splitContainer = new System.Windows.Forms.SplitContainer();
     
    132133      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    133134      //
     135      // openBubbleChartViewToolStripMenuItem
     136      //
     137      this.openBubbleChartViewToolStripMenuItem.Name = "openBubbleChartViewToolStripMenuItem";
     138      this.openBubbleChartViewToolStripMenuItem.Size = new System.Drawing.Size(256, 22);
     139      this.openBubbleChartViewToolStripMenuItem.Text = "Open BubbleChart View";
     140      this.openBubbleChartViewToolStripMenuItem.Click += new System.EventHandler(this.openBubbleChartViewToolStripMenuItem_Click);
     141      //
    134142      // noRunsLabel
    135143      //
     
    239247    private System.Windows.Forms.ToolTip tooltip;
    240248    protected System.Windows.Forms.CheckBox showStatisticsCheckBox;
     249    private System.Windows.Forms.ToolStripMenuItem openBubbleChartViewToolStripMenuItem;
    241250  }
    242251}
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBoxPlotView.cs

    r13051 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    4848    public RunCollectionBoxPlotView() {
    4949      InitializeComponent();
     50      chart.ContextMenuStrip.Items.Insert(0, openBubbleChartViewToolStripMenuItem);
     51
    5052      categoricalMapping = new Dictionary<int, Dictionary<object, double>>();
    5153      seriesCache = new SortedDictionary<double, Series>();
     
    211213
    212214    private void UpdateStatistics() {
    213       DoubleMatrix matrix = new DoubleMatrix(9, seriesCache.Count);
     215      DoubleMatrix matrix = new DoubleMatrix(10, seriesCache.Count);
    214216      matrix.SortableView = false;
    215217      List<string> columnNames = new List<string>();
     
    224226            AxisDimension axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), selectedAxis);
    225227            switch (axisDimension) {
    226               case AxisDimension.Color: value = new StringValue(run.Color.ToString());
     228              case AxisDimension.Color:
     229                value = new StringValue(run.Color.ToString());
    227230                break;
    228231            }
     
    236239      }
    237240      matrix.ColumnNames = columnNames;
    238       matrix.RowNames = new string[] { "Count", "Minimum", "Maximum", "Median", "Average", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile" };
     241      matrix.RowNames = new string[] { "Count", "Minimum", "Maximum", "Median", "Average", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Interquartile Range" };
    239242
    240243      for (int i = 0; i < seriesCache.Count; i++) {
     
    250253        matrix[7, i] = seriesValues.Quantile(0.25);
    251254        matrix[8, i] = seriesValues.Quantile(0.75);
     255        matrix[9, i] = matrix[8, i] - matrix[7, i];
    252256      }
    253257      statisticsMatrixView.Content = matrix;
     
    276280      double? yValue;
    277281
    278       if (!xAxisComboBox.DroppedDown)
    279         this.xAxisValue = (string)xAxisComboBox.SelectedItem;
    280       if (!yAxisComboBox.DroppedDown)
    281         this.yAxisValue = (string)yAxisComboBox.SelectedItem;
     282      this.xAxisValue = (string)xAxisComboBox.SelectedItem;
     283      this.yAxisValue = (string)yAxisComboBox.SelectedItem;
    282284
    283285      xValue = GetValue(run, this.xAxisValue);
     
    382384      UpdateDataPoints();
    383385    }
     386
    384387    private void UpdateAxisLabels() {
    385388      Axis xAxis = this.chart.ChartAreas[BoxPlotChartAreaName].AxisX;
    386389      Axis yAxis = this.chart.ChartAreas[BoxPlotChartAreaName].AxisY;
    387390      int axisDimensionCount = Enum.GetNames(typeof(AxisDimension)).Count();
    388       //mkommend: combobox.SelectedIndex could not be used as this changes during hovering over possible values
    389       var xSAxisSelectedIndex = xAxisValue == null ? 0 : xAxisComboBox.Items.IndexOf(xAxisValue);
    390       var ySAxisSelectedIndex = yAxisValue == null ? 0 : xAxisComboBox.Items.IndexOf(yAxisValue);
    391       SetCustomAxisLabels(xAxis, xSAxisSelectedIndex - axisDimensionCount);
    392       SetCustomAxisLabels(yAxis, ySAxisSelectedIndex - axisDimensionCount);
    393       if (xAxisValue != null)
    394         xAxis.Title = xAxisValue;
    395       if (yAxisValue != null)
    396         yAxis.Title = yAxisValue;
     391
     392      SetCustomAxisLabels(xAxis, xAxisComboBox.SelectedIndex - axisDimensionCount);
     393      SetCustomAxisLabels(yAxis, yAxisComboBox.SelectedIndex - axisDimensionCount);
     394
     395      xAxis.Title = (string)xAxisComboBox.SelectedItem;
     396      yAxis.Title = (string)yAxisComboBox.SelectedItem;
    397397    }
    398398
     
    402402
    403403    private void SetCustomAxisLabels(Axis axis, int dimension) {
     404      if (Content == null) { return; }
     405      if (!Content.Any()) { return; }
     406
    404407      axis.CustomLabels.Clear();
    405408      if (categoricalMapping.ContainsKey(dimension)) {
     
    445448    }
    446449
     450    private void openBubbleChartViewToolStripMenuItem_Click(object sender, EventArgs e) {
     451      RunCollectionBubbleChartView bubbleChartView = new RunCollectionBubbleChartView();
     452      bubbleChartView.Content = this.Content;
     453      bubbleChartView.xAxisComboBox.SelectedItem = xAxisComboBox.SelectedItem;
     454      bubbleChartView.yAxisComboBox.SelectedItem = yAxisComboBox.SelectedItem;
     455      bubbleChartView.Show();
     456    }
     457
    447458    private void chart_MouseMove(object sender, MouseEventArgs e) {
    448459      string newTooltipText = string.Empty;
     
    463474    }
    464475
     476    public bool StatisticsVisible {
     477      get { return splitContainer.Panel2Collapsed; }
     478      set { splitContainer.Panel2Collapsed = value; }
     479    }
     480
    465481    public void SetXAxis(string axisName) {
    466482      xAxisComboBox.SelectedItem = axisName;
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBubbleChartView.Designer.cs

    r12012 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    139139      this.xAxisComboBox.Size = new System.Drawing.Size(400, 21);
    140140      this.xAxisComboBox.TabIndex = 7;
     141      this.xAxisComboBox.Sorted = false;
    141142      this.xAxisComboBox.SelectedValueChanged += new System.EventHandler(this.AxisComboBox_SelectedValueChanged);
    142143      //
     
    160161      this.yAxisComboBox.Size = new System.Drawing.Size(400, 21);
    161162      this.yAxisComboBox.TabIndex = 5;
     163      this.yAxisComboBox.Sorted = false;
    162164      this.yAxisComboBox.SelectedValueChanged += new System.EventHandler(this.AxisComboBox_SelectedValueChanged);
    163165      //
     
    183185      this.sizeComboBox.Name = "sizeComboBox";
    184186      this.sizeComboBox.Size = new System.Drawing.Size(300, 21);
     187      this.sizeComboBox.Sorted = false;
    185188      this.sizeComboBox.TabIndex = 14;
    186189      this.sizeComboBox.SelectedValueChanged += new System.EventHandler(this.AxisComboBox_SelectedValueChanged);
     
    198201      // chart
    199202      //
    200       this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    201             | System.Windows.Forms.AnchorStyles.Left) 
     203      this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     204            | System.Windows.Forms.AnchorStyles.Left)
    202205            | System.Windows.Forms.AnchorStyles.Right)));
    203206      chartArea1.Name = "ChartArea1";
     
    264267      this.radioButtonGroup.Controls.Add(this.zoomButton);
    265268      this.radioButtonGroup.Controls.Add(this.selectButton);
    266       this.radioButtonGroup.Location = new System.Drawing.Point(3, 704);
     269      this.radioButtonGroup.Location = new System.Drawing.Point(6, 679);
    267270      this.radioButtonGroup.Name = "radioButtonGroup";
    268271      this.radioButtonGroup.Size = new System.Drawing.Size(122, 32);
     
    275278      this.colorRunsButton.Enabled = false;
    276279      this.colorRunsButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
    277       this.colorRunsButton.Location = new System.Drawing.Point(131, 713);
     280      this.colorRunsButton.Location = new System.Drawing.Point(6, 715);
    278281      this.colorRunsButton.Name = "colorRunsButton";
    279282      this.colorRunsButton.Size = new System.Drawing.Size(21, 21);
     
    317320      this.transparencyTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    318321      this.transparencyTrackBar.LargeChange = 16;
    319       this.transparencyTrackBar.Location = new System.Drawing.Point(302, 715);
     322      this.transparencyTrackBar.Location = new System.Drawing.Point(177, 717);
    320323      this.transparencyTrackBar.Maximum = 254;
    321324      this.transparencyTrackBar.Name = "transparencyTrackBar";
     
    331334      this.hideRunsButton.Enabled = false;
    332335      this.hideRunsButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
    333       this.hideRunsButton.Location = new System.Drawing.Point(172, 713);
     336      this.hideRunsButton.Location = new System.Drawing.Point(47, 715);
    334337      this.hideRunsButton.Name = "hideRunsButton";
    335338      this.hideRunsButton.Size = new System.Drawing.Size(43, 21);
     
    347350      this.colorDialogButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    348351      this.colorDialogButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
    349       this.colorDialogButton.Location = new System.Drawing.Point(152, 713);
     352      this.colorDialogButton.Location = new System.Drawing.Point(27, 715);
    350353      this.colorDialogButton.Name = "colorDialogButton";
    351354      this.colorDialogButton.Size = new System.Drawing.Size(14, 21);
     
    390393      this.transparencyLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    391394      this.transparencyLabel.AutoSize = true;
    392       this.transparencyLabel.Location = new System.Drawing.Point(233, 717);
     395      this.transparencyLabel.Location = new System.Drawing.Point(108, 719);
    393396      this.transparencyLabel.Name = "transparencyLabel";
    394397      this.transparencyLabel.Size = new System.Drawing.Size(75, 13);
     
    452455
    453456    private System.Windows.Forms.Label xAxisLabel;
    454     private System.Windows.Forms.ComboBox xAxisComboBox;
     457    internal System.Windows.Forms.ComboBox xAxisComboBox;
    455458    private System.Windows.Forms.Label yAxisLabel;
    456     private System.Windows.Forms.ComboBox yAxisComboBox;
     459    internal System.Windows.Forms.ComboBox yAxisComboBox;
    457460    private System.Windows.Forms.TrackBar yTrackBar;
    458461    private System.Windows.Forms.TrackBar xTrackBar;
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBubbleChartView.cs

    r12077 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    9393    }
    9494
     95    public string SelectedXAxis {
     96      get { return xAxisValue; }
     97      set {
     98        if (xAxisComboBox.Items.Contains(value)) {
     99          xAxisComboBox.SelectedItem = value;
     100        }
     101      }
     102    }
     103    public string SelectedYAxis {
     104      get { return yAxisValue; }
     105      set {
     106        if (yAxisComboBox.Items.Contains(value)) {
     107          yAxisComboBox.SelectedItem = value;
     108        }
     109      }
     110    }
     111
    95112    protected override void RegisterContentEvents() {
    96113      base.RegisterContentEvents();
     
    227244        string[] additionalAxisDimension = Enum.GetNames(typeof(AxisDimension));
    228245        this.xAxisComboBox.Items.AddRange(additionalAxisDimension);
    229         this.xAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
     246        var comparer = new HeuristicLab.Common.NaturalStringComparer();
     247        var sortedColumnNames = Matrix.ColumnNames.ToArray();
     248        sortedColumnNames.StableSort(comparer);
     249        this.xAxisComboBox.Items.AddRange(sortedColumnNames);
    230250        this.yAxisComboBox.Items.AddRange(additionalAxisDimension);
    231         this.yAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
     251        this.yAxisComboBox.Items.AddRange(sortedColumnNames);
    232252        string[] additionalSizeDimension = Enum.GetNames(typeof(SizeDimension));
    233253        this.sizeComboBox.Items.AddRange(additionalSizeDimension);
    234         this.sizeComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
     254        this.sizeComboBox.Items.AddRange(sortedColumnNames);
    235255        this.sizeComboBox.SelectedItem = SizeDimension.Constant.ToString();
    236256
     
    415435        return GetValue(run, sizeDimension);
    416436      } else {
    417         int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName);
    418         IItem value = Content.GetValue(run, columnIndex);
     437
     438        IItem value = Content.GetValue(run, columnName);
    419439        if (value == null)
    420440          return null;
     
    431451        else if (timeSpanValue != null) {
    432452          ret = timeSpanValue.Value.TotalSeconds;
    433         } else
     453        } else {
     454          int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName);
    434455          ret = GetCategoricalValue(columnIndex, value.ToString());
     456        }
    435457
    436458        return ret;
     
    602624      tooltip = run.Name + System.Environment.NewLine;
    603625
    604       double? xValue = this.GetValue(run, (string)xAxisComboBox.SelectedItem);
    605       double? yValue = this.GetValue(run, (string)yAxisComboBox.SelectedItem);
    606       double? sizeValue = this.GetValue(run, (string)sizeComboBox.SelectedItem);
    607 
    608       string xString = xValue == null ? string.Empty : xValue.Value.ToString();
    609       string yString = yValue == null ? string.Empty : yValue.Value.ToString();
    610       string sizeString = sizeValue == null ? string.Empty : sizeValue.Value.ToString();
    611 
    612       //code to handle TimeSpanValues correct
    613       int axisDimensionCount = Enum.GetNames(typeof(AxisDimension)).Count();
    614       int columnIndex = xAxisComboBox.SelectedIndex - axisDimensionCount;
    615       if (xValue.HasValue && columnIndex > 0 && Content.GetValue(0, columnIndex) is TimeSpanValue) {
    616         TimeSpan time = TimeSpan.FromSeconds(xValue.Value);
    617         xString = string.Format("{0:00}:{1:00}:{2:00.00}", (int)time.TotalHours, time.Minutes, time.Seconds);
    618       }
    619       columnIndex = yAxisComboBox.SelectedIndex - axisDimensionCount;
    620       if (yValue.HasValue && columnIndex > 0 && Content.GetValue(0, columnIndex) is TimeSpanValue) {
    621         TimeSpan time = TimeSpan.FromSeconds(yValue.Value);
    622         yString = string.Format("{0:00}:{1:00}:{2:00.00}", (int)time.TotalHours, time.Minutes, time.Seconds);
    623       }
     626      string xString = GetTooltipValue(run, (string)xAxisComboBox.SelectedItem);
     627      string yString = GetTooltipValue(run, (string)yAxisComboBox.SelectedItem);
     628      string sizeString = GetTooltipValue(run, (string)sizeComboBox.SelectedItem);
    624629
    625630      tooltip += xAxisComboBox.SelectedItem + " : " + xString + Environment.NewLine;
     
    628633
    629634      return tooltip;
     635    }
     636
     637    private string GetTooltipValue(IRun run, string columnName) {
     638      if (columnName == SizeDimension.Constant.ToString())
     639        return string.Empty;
     640
     641      int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName);
     642
     643      //handle non-numeric values correctly
     644      if (categoricalMapping.ContainsKey(columnIndex)) {
     645        return Content.GetValue(run, columnName).ToString();
     646      }
     647
     648      double? value = GetValue(run, columnName);
     649      if (!value.HasValue) return string.Empty;
     650
     651      string valueString = value.Value.ToString();
     652
     653      //code to handle TimeSpanValues correctly
     654      if (columnIndex > 0 && Content.GetValue(0, columnIndex) is TimeSpanValue) {
     655        TimeSpan time = TimeSpan.FromSeconds(value.Value);
     656        valueString = string.Format("{0:00}:{1:00}:{2:00.00}", (int)time.TotalHours, time.Minutes, time.Seconds);
     657      }
     658
     659      return valueString;
    630660    }
    631661    #endregion
     
    726756    }
    727757    private void hideRunsToolStripMenuItem_Click(object sender, EventArgs e) {
    728       //ToList is necessary to prevent lazy evaluation
    729       HideRuns(selectedRuns.ToList());
     758      HideRuns(selectedRuns);
    730759      //could not use ClearSelectedRuns as the runs are not visible anymore
    731760      selectedRuns.Clear();
    732761    }
    733762    private void hideRunsButton_Click(object sender, EventArgs e) {
    734       //ToList is necessary to prevent lazy evaluation
    735       HideRuns(selectedRuns.ToList());
     763      HideRuns(selectedRuns);
    736764      //could not use ClearSelectedRuns as the runs are not visible anymore
    737765      selectedRuns.Clear();
     
    739767
    740768    private void HideRuns(IEnumerable<IRun> runs) {
     769      Content.UpdateOfRunsInProgress = true;
    741770      visibilityConstraint.Active = false;
    742771      if (!Content.Constraints.Contains(visibilityConstraint)) Content.Constraints.Add(visibilityConstraint);
     
    745774      }
    746775      visibilityConstraint.Active = true;
     776      Content.UpdateOfRunsInProgress = false;
    747777    }
    748778
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionChartAggregationView.Designer.cs

    r12012 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionChartAggregationView.cs

    r13181 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionTableView.Designer.cs

    r12012 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionTableView.cs

    r13054 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using System.Linq;
    2626using System.Windows.Forms;
    27 using HeuristicLab.Collections;
    2827using HeuristicLab.Core;
    2928using HeuristicLab.Data.Views;
     
    122121    }
    123122
    124     protected override void UpdateColumnHeaders() {
     123    public override void UpdateColumnHeaders() {
    125124      string[] colNames = base.Content.ColumnNames.ToArray();
    126125      int colCount = colNames.Length;
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionView.Designer.cs

    r12012 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/2522_RefactorPluginInfrastructure/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionView.cs

    r13181 r15973  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    5252    }
    5353
    54     public ListView ItemsListView {
    55       get { return itemsListView; }
    56     }
     54    private int EmptyImageIndex { get { return 0; } }
     55    private int RunImageIndex { get { return 1; } }
    5756
    5857    public RunCollectionView() {
    5958      InitializeComponent();
    60       itemsGroupBox.Text = "Runs";
     59      UpdateGroupBoxText();
     60
     61      itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Nothing);
     62      itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Class);
     63
    6164      itemListViewItemMapping = new Dictionary<IRun, List<ListViewItem>>();
    6265      runCollectionModifiersListView.Evaluator = EvaluateModifications;
     
    8386    }
    8487    private void DeregisterItemEvents(IRun item) {
    85       item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    8688      item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
    8789      item.PropertyChanged -= Item_PropertyChanged;
    8890    }
    8991    private void RegisterItemEvents(IRun item) {
    90       item.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
    9192      item.ToStringChanged += new EventHandler(Item_ToStringChanged);
    9293      item.PropertyChanged += Item_PropertyChanged;
     
    116117      itemsListView.Items.Clear();
    117118      itemListViewItemMapping.Clear();
    118       RebuildImageList();
    119119      viewHost.Content = null;
     120
     121      UpdateGroupBoxText();
    120122
    121123      if (Content != null) {
     
    129131          runCollectionModifiersListView.Content = RunCollection.Modifiers;
    130132        }
     133
     134        ListViewItem[] items = new ListViewItem[Content.Count];
     135        int count = 0;
    131136        foreach (IRun item in Content) {
    132137          ListViewItem listViewItem = CreateListViewItem(item);
    133           AddListViewItem(listViewItem);
     138
    134139          if ((selectedName != null) && item.Name.Equals(selectedName))
    135140            listViewItem.Selected = true;
    136         }
     141          items[count] = listViewItem;
     142          count++;
     143        }
     144        itemsListView.Items.AddRange(items);
    137145        AdjustListViewColumnSizes();
    138146      } else {
     
    166174    }
    167175
    168     private ListViewItem CreateListViewItem(IRun item) {
     176    private static readonly string tooltipText = ItemAttribute.GetName(typeof(Run)) + ": " +
     177                                    ItemAttribute.GetDescription(typeof(Run));
     178    private ListViewItem CreateListViewItem(IRun run) {
    169179      ListViewItem listViewItem = new ListViewItem();
    170       if (item == null) {
     180      if (run == null) {
    171181        listViewItem.Text = "null";
    172         itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Nothing);
    173         listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     182        listViewItem.ImageIndex = EmptyImageIndex;
     183        return listViewItem;
     184      }
     185
     186      listViewItem.Text = run.Name;
     187      listViewItem.ToolTipText = tooltipText;
     188      listViewItem.ImageIndex = RunImageIndex;
     189      listViewItem.Tag = run;
     190
     191      if (run.Visible) {
     192        listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
     193        listViewItem.ForeColor = run.Color;
    174194      } else {
    175         listViewItem.Text = item.ToString();
    176         listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
    177         itemsListView.SmallImageList.Images.Add(item.ItemImage);
    178         listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
    179         listViewItem.Tag = item;
    180 
    181         if (item.Visible) {
    182           listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
    183           listViewItem.ForeColor = item.Color;
    184         } else {
    185           listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
    186           listViewItem.ForeColor = Color.LightGray;
    187         }
    188       }
     195        listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
     196        listViewItem.ForeColor = Color.LightGray;
     197      }
     198
     199      if (!itemListViewItemMapping.ContainsKey(run)) {
     200        itemListViewItemMapping.Add(run, new List<ListViewItem>());
     201        RegisterItemEvents(run);
     202      }
     203      itemListViewItemMapping[run].Add(listViewItem);
     204
    189205      return listViewItem;
    190206    }
    191     private void AddListViewItem(ListViewItem listViewItem) {
    192       if (listViewItem == null) throw new ArgumentNullException();
    193       itemsListView.Items.Add(listViewItem);
    194       IRun run = listViewItem.Tag as IRun;
    195       if (run != null) {
    196         if (!itemListViewItemMapping.ContainsKey(run)) {
    197           itemListViewItemMapping.Add(run, new List<ListViewItem>());
    198           RegisterItemEvents(run);
    199         }
    200         itemListViewItemMapping[run].Add(listViewItem);
    201       }
    202     }
     207
    203208    private void RemoveListViewItem(ListViewItem listViewItem) {
    204209      if (listViewItem == null) throw new ArgumentNullException();
     
    213218      listViewItem.Remove();
    214219    }
    215     private void UpdateListViewItemImage(ListViewItem listViewItem) {
    216       if (listViewItem == null) throw new ArgumentNullException();
    217       IRun item = listViewItem.Tag as IRun;
    218       int i = listViewItem.ImageIndex;
    219       itemsListView.SmallImageList.Images[i] = item == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : item.ItemImage;
    220       listViewItem.ImageIndex = -1;
    221       listViewItem.ImageIndex = i;
    222     }
     220
    223221    private void UpdateListViewItemText(ListViewItem listViewItem) {
    224222      if (listViewItem == null) throw new ArgumentNullException();
     
    239237        return listViewItems == null ? Enumerable.Empty<ListViewItem>() : listViewItems;
    240238      }
     239    }
     240
     241    private void UpdateGroupBoxText() {
     242      if (Content == null || Content.Count == 0) itemsGroupBox.Text = "Runs";
     243      else itemsGroupBox.Text = @"Runs (" + Content.Count + @")";
    241244    }
    242245
     
    268271          }
    269272        }
     273      } else if (e.KeyData == (Keys.A | Keys.Control)) {
     274        try {
     275          itemsListView.BeginUpdate();
     276          foreach (ListViewItem item in itemsListView.Items)
     277            item.Selected = true;
     278        } finally { itemsListView.EndUpdate(); }
    270279      }
    271280    }
     
    393402        RunCollection.UpdateOfRunsInProgress = true;
    394403        RunCollection.Modify();
    395       } finally {
     404      }
     405      finally {
    396406        ReadOnly = false;
    397407        RunCollection.UpdateOfRunsInProgress = false;
     
    406416        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded), sender, e);
    407417      else {
    408         foreach (IRun item in e.Items)
    409           AddListViewItem(CreateListViewItem(item));
    410 
     418        var items = e.Items.Select(CreateListViewItem).ToArray();
     419        itemsListView.Items.AddRange(items);
    411420        AdjustListViewColumnSizes();
    412421        analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
    413422        clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
    414423        runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
     424        UpdateGroupBoxText();
    415425      }
    416426    }
     
    425435          if (listViewItem != null) RemoveListViewItem(listViewItem);
    426436        }
    427         RebuildImageList();
    428437        analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
    429438        clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
    430439        runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
     440        UpdateGroupBoxText();
    431441      }
    432442    }
     
    441451          if (listViewItem != null) RemoveListViewItem(listViewItem);
    442452        }
    443         RebuildImageList();
    444         foreach (IRun item in e.Items)
    445           AddListViewItem(CreateListViewItem(item));
     453        var items = e.Items.Select(CreateListViewItem).ToArray();
     454        itemsListView.Items.AddRange(items);
    446455
    447456        AdjustListViewColumnSizes();
     
    449458        clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
    450459        runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
     460        UpdateGroupBoxText();
    451461      }
    452462    }
     
    456466        suppressUpdates = RunCollection.UpdateOfRunsInProgress;
    457467        if (!suppressUpdates) {
    458           foreach (IRun item in Content) {
    459             //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection
    460             ListViewItem listViewItem = GetListViewItemsForItem(item).FirstOrDefault();
    461             if (listViewItem != null) RemoveListViewItem(listViewItem);
     468          foreach (IRun run in Content) {
     469            DeregisterItemEvents(run);
    462470          }
    463           RebuildImageList();
    464           foreach (IRun item in Content)
    465             AddListViewItem(CreateListViewItem(item));
     471          itemsListView.Items.Clear();
     472          itemListViewItemMapping.Clear();
     473          var items = Content.Select(CreateListViewItem).ToArray();
     474          itemsListView.Items.AddRange(items);
    466475
    467476          AdjustListViewColumnSizes();
     
    469478          clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
    470479          runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
     480          UpdateGroupBoxText();
    471481        }
    472482      }
     
    475485
    476486    #region Item Events
    477     private void Item_ItemImageChanged(object sender, EventArgs e) {
    478       if (suppressUpdates) return;
    479       if (InvokeRequired)
    480         Invoke(new EventHandler(Item_ItemImageChanged), sender, e);
    481       else {
    482         IRun item = (IRun)sender;
    483         foreach (ListViewItem listViewItem in GetListViewItemsForItem(item))
    484           UpdateListViewItemImage(listViewItem);
    485       }
    486     }
    487487    private void Item_ToStringChanged(object sender, EventArgs e) {
    488488      if (suppressUpdates) return;
     
    528528      }
    529529    }
    530     private void RebuildImageList() {
    531       itemsListView.SmallImageList.Images.Clear();
    532       foreach (ListViewItem listViewItem in itemsListView.Items) {
    533         IRun item = listViewItem.Tag as IRun;
    534         itemsListView.SmallImageList.Images.Add(item == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : item.ItemImage);
    535         listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
    536       }
    537     }
    538530    #endregion
    539531  }
Note: See TracChangeset for help on using the changeset viewer.