Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/14 16:28:26 (11 years ago)
Author:
rstoll
Message:
  • copied StringConvertibleMatrixView since we need to override dataGridView_CellValidating and dataGridView_CellParsing as well as PasteValuesToDataGridView
  • optimising event subscription, do not refresh if event is triggered by the view itself
Location:
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/CopyOfStringConvertibleMatrixView.Designer.cs

    r10571 r10583  
    2020#endregion
    2121
    22 namespace HeuristicLab.Data.Views {
    23   partial class StringConvertibleMatrixView {
     22namespace HeuristicLab.DataPreprocessing.Views {
     23  partial class CopyOfStringConvertibleMatrixView {
    2424    /// <summary>
    2525    /// Required designer variable.
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/CopyOfStringConvertibleMatrixView.cs

    r10571 r10583  
    2828using System.Windows.Forms;
    2929using HeuristicLab.Common;
     30using HeuristicLab.Data;
     31using HeuristicLab.Data.Views;
    3032using HeuristicLab.MainForm;
    3133using HeuristicLab.MainForm.WindowsForms;
    3234
    33 namespace HeuristicLab.Data.Views {
     35namespace HeuristicLab.DataPreprocessing.Views {
    3436  [View("StringConvertibleMatrix View")]
    35   [Content(typeof(IStringConvertibleMatrix), true)]
    36   public partial class StringConvertibleMatrixView : AsynchronousContentView {
     37  [Content(typeof(IStringConvertibleMatrix), false)]
     38  public partial class CopyOfStringConvertibleMatrixView : AsynchronousContentView {
     39
     40    // Was private before
     41    protected virtual void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
     42      if (!dataGridView.ReadOnly) {
     43        string errorMessage;
     44        if (Content != null && !Content.Validate(e.FormattedValue.ToString(), out errorMessage)) {
     45          e.Cancel = true;
     46          dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
     47        }
     48      }
     49    }
     50
     51    // Was private before
     52    protected virtual void dataGridView_CellParsing(object sender, DataGridViewCellParsingEventArgs e) {
     53      if (!dataGridView.ReadOnly) {
     54        string value = e.Value.ToString();
     55        int rowIndex = virtualRowIndices[e.RowIndex];
     56        e.ParsingApplied = Content.SetValue(value, rowIndex, e.ColumnIndex);
     57        if (e.ParsingApplied) e.Value = Content.GetValue(rowIndex, e.ColumnIndex);
     58      }
     59    }
     60
     61    // Was private before
     62    protected virtual void PasteValuesToDataGridView() {
     63      string[,] values = SplitClipboardString(Clipboard.GetText());
     64      int rowIndex = 0;
     65      int columnIndex = 0;
     66      if (dataGridView.CurrentCell != null) {
     67        rowIndex = dataGridView.CurrentCell.RowIndex;
     68        columnIndex = dataGridView.CurrentCell.ColumnIndex;
     69      }
     70      if (Content.Rows < values.GetLength(1) + rowIndex) Content.Rows = values.GetLength(1) + rowIndex;
     71      if (Content.Columns < values.GetLength(0) + columnIndex) Content.Columns = values.GetLength(0) + columnIndex;
     72
     73      for (int row = 0; row < values.GetLength(1); row++) {
     74        for (int col = 0; col < values.GetLength(0); col++) {
     75          Content.SetValue(values[col, row], row + rowIndex, col + columnIndex);
     76        }
     77      }
     78      ClearSorting();
     79    }
     80
     81    #region unchanged copied from original - see  HeuristicLab.Data.Views.StringConvertibleMatrix
     82
    3783    protected int[] virtualRowIndices;
    3884    private List<KeyValuePair<int, SortOrder>> sortedColumnIndices;
     
    74120    }
    75121
    76     public StringConvertibleMatrixView() {
     122    public CopyOfStringConvertibleMatrixView() {
    77123      InitializeComponent();
    78124      ShowRowsAndColumnsTextBox = true;
     
    261307
    262308    #region DataGridView Events
    263     private void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
    264       if (!dataGridView.ReadOnly) {
    265         string errorMessage;
    266         if (Content != null && !Content.Validate(e.FormattedValue.ToString(), out errorMessage)) {
    267           e.Cancel = true;
    268           dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
    269         }
    270       }
    271     }
    272     private void dataGridView_CellParsing(object sender, DataGridViewCellParsingEventArgs e) {
    273       if (!dataGridView.ReadOnly) {
    274         string value = e.Value.ToString();
    275         int rowIndex = virtualRowIndices[e.RowIndex];
    276         e.ParsingApplied = Content.SetValue(value, rowIndex, e.ColumnIndex);
    277         if (e.ParsingApplied) e.Value = Content.GetValue(rowIndex, e.ColumnIndex);
    278       }
    279     }
     309
    280310    private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
    281311      dataGridView.Rows[e.RowIndex].ErrorText = string.Empty;
     
    364394    }
    365395
    366     private void PasteValuesToDataGridView() {
    367       string[,] values = SplitClipboardString(Clipboard.GetText());
    368       int rowIndex = 0;
    369       int columnIndex = 0;
    370       if (dataGridView.CurrentCell != null) {
    371         rowIndex = dataGridView.CurrentCell.RowIndex;
    372         columnIndex = dataGridView.CurrentCell.ColumnIndex;
    373       }
    374       if (Content.Rows < values.GetLength(1) + rowIndex) Content.Rows = values.GetLength(1) + rowIndex;
    375       if (Content.Columns < values.GetLength(0) + columnIndex) Content.Columns = values.GetLength(0) + columnIndex;
    376 
    377       for (int row = 0; row < values.GetLength(1); row++) {
    378         for (int col = 0; col < values.GetLength(0); col++) {
    379           Content.SetValue(values[col, row], row + rowIndex, col + columnIndex);
    380         }
    381       }
    382       ClearSorting();
    383     }
    384396    private string[,] SplitClipboardString(string clipboardText) {
    385397      if (clipboardText.EndsWith(Environment.NewLine))
     
    566578    }
    567579  }
     580    #endregion
    568581}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/DataGridContentView.cs

    r10574 r10583  
    2424using System.Linq;
    2525using System.Windows.Forms;
    26 using HeuristicLab.Data.Views;
    2726using HeuristicLab.MainForm;
    2827using System.Drawing;
     
    3130  [View("Data Grid Content View")]
    3231  [Content(typeof(IDataGridContent), true)]
    33   public partial class DataGridContentView : StringConvertibleMatrixView {
     32  public partial class DataGridContentView : CopyOfStringConvertibleMatrixView {
    3433
    3534    private int lastClickedRow;
    3635    private int lastClickedColumn;
     36
     37    private bool notOwnEvent = true;
    3738
    3839    public new IDataGridContent Content {
     
    7576
    7677    void Content_Changed(object sender, DataPreprocessingChangedEventArgs e) {
    77       dataGridView.Refresh();
     78      if (notOwnEvent) {
     79        dataGridView.Refresh();
     80      }
    7881    }
    7982
    80     private void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
     83    protected override void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
    8184      if (!dataGridView.ReadOnly) {
    8285        string errorMessage;
     
    8790      }
    8891    }
     92
     93    protected override void dataGridView_CellParsing(object sender, DataGridViewCellParsingEventArgs e) {
     94      notOwnEvent = false;
     95      base.dataGridView_CellParsing(sender, e);
     96      notOwnEvent = true;
     97    }
     98
     99    protected override void PasteValuesToDataGridView() {
     100      notOwnEvent = false;
     101      base.PasteValuesToDataGridView();
     102      notOwnEvent = true;
     103    }
     104
    89105
    90106    protected override void SetEnabledStateOfControls() {
     
    163179    private void ReplaceWithAverage_Click(object sender, EventArgs e) {
    164180      Content.PreprocessingDataManipulation.ReplaceIndicesByAverageValue(lastClickedColumn, new List<int>() { lastClickedRow });
    165       OnContentChanged();
    166181    }
    167182
    168183    private void ReplaceWithMedian_Click(object sender, EventArgs e) {
    169184      Content.PreprocessingDataManipulation.ReplaceIndicesByMedianValue(lastClickedColumn, new List<int>() { lastClickedRow });
    170       OnContentChanged();
    171185    }
    172186
    173187    private void ReplaceWithRandom_Click(object sender, EventArgs e) {
    174188      Content.PreprocessingDataManipulation.ReplaceIndicesByRandomValue(lastClickedColumn, new List<int>() { lastClickedRow });
    175       OnContentChanged();
    176189    }
    177190
    178191    private void ReplaceWithMostCommon_Click(object sender, EventArgs e) {
    179192      Content.PreprocessingDataManipulation.ReplaceIndicesByMostCommonValue(lastClickedColumn, new List<int>() { lastClickedRow });
    180       OnContentChanged();
    181193    }
    182194
    183195    private void ReplaceWithInterpolation_Click(object sender, EventArgs e) {
    184196      Content.PreprocessingDataManipulation.ReplaceIndicesByLinearInterpolationOfNeighbours(lastClickedColumn, new List<int>() { lastClickedRow });
    185       OnContentChanged();
    186197    }
    187198  }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/HeuristicLab.DataPreprocessing.Views-3.3.csproj

    r10559 r10583  
    9696      <DependentUpon>StatisticsView.cs</DependentUpon>
    9797    </Compile>
     98    <Compile Include="CopyOfStringConvertibleMatrixView.cs">
     99      <SubType>UserControl</SubType>
     100    </Compile>
     101    <Compile Include="CopyOfStringConvertibleMatrixView.Designer.cs">
     102      <DependentUpon>CopyOfStringConvertibleMatrixView.cs</DependentUpon>
     103    </Compile>
    98104    <Compile Include="TransformationView.cs">
    99105      <SubType>UserControl</SubType>
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/Plugin.cs.frame

    r10542 r10583  
    3030  [PluginDependency("HeuristicLab.DataPreprocessing", "3.3")]
    3131  [PluginDependency("HeuristicLab.Data.Views","3.3")]
     32  [PluginDependency("HeuristicLab.Data","3.3")]
    3233  [PluginDependency("HeuristicLab.MainForm", "3.3")]
    3334  [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")]
Note: See TracChangeset for help on using the changeset viewer.