Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10964


Ignore:
Timestamp:
06/11/14 10:40:01 (10 years ago)
Author:
rstoll
Message:
  • Refactorings for DataGridContent and FitlerContent
Location:
branches/DataPreprocessing
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs

    r10951 r10964  
    8383      searchIterator = null;
    8484    }
     85    #region methods which override/modify methods from PreprocessingStringConvertibleMatrixView
    8586
    8687    protected override void dataGridView_SelectionChanged(object sender, EventArgs e) {
     
    100101    }
    101102
    102     private void dataGridView_MouseUp(object sender, MouseEventArgs e) {
    103       if (!updateOnMouseUp)
    104         return;
    105 
    106       updateOnMouseUp = false;
    107       dataGridView_SelectionChanged(sender, e);
    108     }
     103    protected override void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
     104      if (!dataGridView.ReadOnly) {
     105        string errorMessage;
     106        if (Content != null) {
     107          if (dataGridView.IsCurrentCellInEditMode && Content.FilterLogic.IsFiltered) {
     108            errorMessage = "A filter is active, you cannot modify data. Press ESC to exit edit mode.";
     109          } else {
     110            Content.DataGridLogic.Validate(e.FormattedValue.ToString(), out errorMessage, e.ColumnIndex);
     111          }
     112
     113          if (!String.IsNullOrEmpty(errorMessage)) {
     114            e.Cancel = true;
     115            dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
     116          }
     117        }
     118      }
     119    }
     120
     121    protected override void dataGridView_CellParsing(object sender, DataGridViewCellParsingEventArgs e) {
     122      triggersOwnEvent(() => base.dataGridView_CellParsing(sender, e));
     123    }
     124
     125    protected override void PasteValuesToDataGridView() {
     126      triggersOwnEvent(() => base.PasteValuesToDataGridView());
     127    }
     128
     129    protected override void SetEnabledStateOfControls() {
     130      base.SetEnabledStateOfControls();
     131      rowsTextBox.ReadOnly = true;
     132      columnsTextBox.ReadOnly = true;
     133    }
     134
     135    protected override int[] Sort(IEnumerable<KeyValuePair<int, SortOrder>> sortedColumns) {
     136      btnApplySort.Enabled = sortedColumns.Any();
     137      return base.Sort(sortedColumns);
     138    }
     139
     140    protected override void ClearSorting() {
     141      btnApplySort.Enabled = false;
     142      base.ClearSorting();
     143    }
     144
     145    #endregion
    109146
    110147    protected override void OnContentChanged() {
     
    137174    }
    138175
    139     void FilterLogic_FilterChanged(object sender, EventArgs e) {
     176    private void FilterLogic_FilterChanged(object sender, EventArgs e) {
    140177      OnContentChanged();
    141178      searchIterator = null;
     
    150187    }
    151188
    152     void Content_Changed(object sender, DataPreprocessingChangedEventArgs e) {
     189    private void Content_Changed(object sender, DataPreprocessingChangedEventArgs e) {
    153190      if (notOwnEvent) {
    154191        switch (e.Type) {
     
    161198            break;
    162199        }
    163        }
     200      }
    164201      searchIterator = null;
    165202    }
    166203
    167     protected override void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
    168       if (!dataGridView.ReadOnly) {
    169         string errorMessage;
    170         if (Content != null) {
    171           if (dataGridView.IsCurrentCellInEditMode && Content.FilterLogic.IsFiltered) {
    172             errorMessage = "A filter is active, you cannot modify data. Press ESC to exit edit mode.";
    173           } else {
    174             Content.DataGridLogic.Validate(e.FormattedValue.ToString(), out errorMessage, e.ColumnIndex);
    175           }
    176 
    177           if (!String.IsNullOrEmpty(errorMessage)) {
    178             e.Cancel = true;
    179             dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
    180           }
    181         }
    182       }
    183     }
    184 
    185     protected override void dataGridView_CellParsing(object sender, DataGridViewCellParsingEventArgs e) {
    186       triggersOwnEvent(() => base.dataGridView_CellParsing(sender, e));
    187     }
    188 
    189     protected override void PasteValuesToDataGridView() {
    190       triggersOwnEvent(() => base.PasteValuesToDataGridView());
    191     }
    192 
    193     protected override void SetEnabledStateOfControls() {
    194       base.SetEnabledStateOfControls();
    195       rowsTextBox.ReadOnly = true;
    196       columnsTextBox.ReadOnly = true;
     204    private void dataGridView_MouseUp(object sender, MouseEventArgs e) {
     205      if (!updateOnMouseUp)
     206        return;
     207
     208      updateOnMouseUp = false;
     209      dataGridView_SelectionChanged(sender, e);
    197210    }
    198211
     
    536549    }
    537550
    538     void dataGridView_KeyDown(object sender, KeyEventArgs e) {
     551    private void dataGridView_KeyDown(object sender, KeyEventArgs e) {
    539552      var selectedRows = dataGridView.SelectedRows;
    540553      if (e.KeyCode == Keys.Delete && selectedRows.Count > 0) {
     
    556569    }
    557570
    558     protected override int[] Sort(IEnumerable<KeyValuePair<int, SortOrder>> sortedColumns) {
    559       btnApplySort.Enabled = sortedColumns.Any();
    560       return base.Sort(sortedColumns);
    561     }
    562 
    563     protected override void ClearSorting() {
    564       btnApplySort.Enabled = false;
    565       base.ClearSorting();
    566     }
    567 
    568571    private IDictionary<int, IList<int>> GetSelectedCells() {
    569572      IDictionary<int, IList<int>> selectedCells = new Dictionary<int, IList<int>>();
     
    594597    }
    595598
    596     private void ReplaceWithAverage_Column_Click(object sender, EventArgs e) {
    597       ReplaceTransaction(() => {
    598         Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), false);
    599       });
    600     }
    601     private void ReplaceWithAverage_Selection_Click(object sender, EventArgs e) {
    602       ReplaceTransaction(() => {
    603         Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), true);
    604       });
    605     }
    606 
    607     private void ReplaceWithMedian_Column_Click(object sender, EventArgs e) {
    608       ReplaceTransaction(() => {
    609         Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), false);
    610       });
    611     }
    612     private void ReplaceWithMedian_Selection_Click(object sender, EventArgs e) {
    613       ReplaceTransaction(() => {
    614         Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), true);
    615       });
    616     }
    617 
    618     private void ReplaceWithRandom_Column_Click(object sender, EventArgs e) {
    619       ReplaceTransaction(() => {
    620         Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), false);
    621       });
    622     }
    623     private void ReplaceWithRandom_Selection_Click(object sender, EventArgs e) {
    624       ReplaceTransaction(() => {
    625         Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), true);
    626       });
    627     }
    628 
    629     private void ReplaceWithMostCommon_Column_Click(object sender, EventArgs e) {
    630       ReplaceTransaction(() => {
    631         Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), false);
    632       });
    633     }
    634     private void ReplaceWithMostCommon_Selection_Click(object sender, EventArgs e) {
    635       ReplaceTransaction(() => {
    636         Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), true);
    637       });
    638     }
    639 
    640     private void ReplaceWithInterpolation_Column_Click(object sender, EventArgs e) {
    641       ReplaceTransaction(() => {
    642         Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells());
    643       });
    644     }
    645 
    646     private void ReplaceWithSmoothing_Selection_Click(object sender, EventArgs e) {
    647       ReplaceTransaction(() => {
    648         Content.ManipulationLogic.ReplaceIndicesBySmoothing(GetSelectedCells());
    649       });
    650     }
    651 
    652599    private void btnSearch_Click(object sender, EventArgs e) {
    653600      CreateFindAndReplaceDialog();
     
    659606      findAndReplaceDialog.ActivateReplace();
    660607    }
     608
     609    #region ContextMenu Events
     610
     611    private void ReplaceWithAverage_Column_Click(object sender, EventArgs e) {
     612      ReplaceTransaction(() => {
     613        Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), false);
     614      });
     615    }
     616    private void ReplaceWithAverage_Selection_Click(object sender, EventArgs e) {
     617      ReplaceTransaction(() => {
     618        Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), true);
     619      });
     620    }
     621
     622    private void ReplaceWithMedian_Column_Click(object sender, EventArgs e) {
     623      ReplaceTransaction(() => {
     624        Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), false);
     625      });
     626    }
     627    private void ReplaceWithMedian_Selection_Click(object sender, EventArgs e) {
     628      ReplaceTransaction(() => {
     629        Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), true);
     630      });
     631    }
     632
     633    private void ReplaceWithRandom_Column_Click(object sender, EventArgs e) {
     634      ReplaceTransaction(() => {
     635        Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), false);
     636      });
     637    }
     638    private void ReplaceWithRandom_Selection_Click(object sender, EventArgs e) {
     639      ReplaceTransaction(() => {
     640        Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), true);
     641      });
     642    }
     643
     644    private void ReplaceWithMostCommon_Column_Click(object sender, EventArgs e) {
     645      ReplaceTransaction(() => {
     646        Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), false);
     647      });
     648    }
     649    private void ReplaceWithMostCommon_Selection_Click(object sender, EventArgs e) {
     650      ReplaceTransaction(() => {
     651        Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), true);
     652      });
     653    }
     654
     655    private void ReplaceWithInterpolation_Column_Click(object sender, EventArgs e) {
     656      ReplaceTransaction(() => {
     657        Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells());
     658      });
     659    }
     660
     661    private void ReplaceWithSmoothing_Selection_Click(object sender, EventArgs e) {
     662      ReplaceTransaction(() => {
     663        Content.ManipulationLogic.ReplaceIndicesBySmoothing(GetSelectedCells());
     664      });
     665    }
     666    #endregion
     667
     668
    661669  }
    662670}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/DataGridContent.cs

    r10900 r10964  
    3535    private readonly IFilterLogic filterLogic;
    3636
    37     public DataGridContent(IDataGridLogic theDataGridLogic, IManipulationLogic theManipulationLogic, IFilterLogic theFilterLogic) {
    38       dataGridLogic = theDataGridLogic;
    39       manipulationLogic = theManipulationLogic;
    40       filterLogic = theFilterLogic;
    41     }
    42 
    43     public DataGridContent(DataGridContent dataGridContent, Cloner cloner)
    44       : base(dataGridContent, cloner) {
    45     }
    46 
    4737    public IManipulationLogic ManipulationLogic {
    4838      get { return manipulationLogic; }
     
    6353    public static new Image StaticItemImage {
    6454      get { return HeuristicLab.Common.Resources.VSImageLibrary.Table; }
    65     }
    66 
    67     public override IDeepCloneable Clone(Cloner cloner) {
    68       return new DataGridContent(this, cloner);
    6955    }
    7056
     
    118104    }
    119105
    120     public bool Validate(string value, out string errorMessage) {
    121       errorMessage = string.Empty;
    122       return true;
     106    public DataGridContent(IDataGridLogic theDataGridLogic, IManipulationLogic theManipulationLogic, IFilterLogic theFilterLogic) {
     107      dataGridLogic = theDataGridLogic;
     108      manipulationLogic = theManipulationLogic;
     109      filterLogic = theFilterLogic;
     110    }
     111
     112    public DataGridContent(DataGridContent dataGridContent, Cloner cloner)
     113      : base(dataGridContent, cloner) {
     114
     115    }
     116
     117    public override IDeepCloneable Clone(Cloner cloner) {
     118      return new DataGridContent(this, cloner);
    123119    }
    124120
     
    129125    public bool SetValue(string value, int rowIndex, int columnIndex) {
    130126      return dataGridLogic.SetValue(value, columnIndex, rowIndex);
     127    }
     128
     129    public event DataPreprocessingChangedEventHandler Changed {
     130      add { dataGridLogic.Changed += value; }
     131      remove { dataGridLogic.Changed -= value; }
     132    }
     133
     134
     135
     136    #region unused stuff/not implemented but necessary due to IStringConvertibleMatrix
     137
     138    // Is not used since DataGridContentView overrides dataGridView_CellValidating and uses
     139    // DataGridLogic#Validate(string value, out string errorMessage, int columnIndex)
     140    public bool Validate(string value, out string errorMessage) {
     141      errorMessage = string.Empty;
     142      return true;
    131143    }
    132144
     
    144156
    145157    public event EventHandler Reset;
     158    #endregion
    146159
    147     public event DataPreprocessingChangedEventHandler Changed {
    148       add { dataGridLogic.Changed += value; }
    149       remove { dataGridLogic.Changed -= value; }
    150     }
    151160  }
    152161}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/FilterContent.cs

    r10877 r10964  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 using System.Collections.Generic;
    2625using HeuristicLab.DataPreprocessing.Filter;
    2726
     
    4039    public bool isAndCombination = true;
    4140
    42     public FilterContent(IFilterLogic theFilterLogic) {
    43       filterLogic = theFilterLogic;
    44     }
    4541
    4642    public IFilterLogic FilterLogic {
     
    5046    }
    5147
    52     public ICheckedItemCollection<IFilter> Filters
    53     {
    54       get
    55       {
     48    public ICheckedItemCollection<IFilter> Filters {
     49      get {
    5650        return this.filters;
    5751      }
    58       set
    59       {
     52      set {
    6053        this.filters = value;
    6154      }
    6255    }
    6356
    64     public bool IsAndCombination
    65     {
    66       get
    67       {
     57    public bool IsAndCombination {
     58      get {
    6859        return this.isAndCombination;
    6960      }
    70       set
    71       {
     61      set {
    7262        this.isAndCombination = value;
    7363      }
    7464    }
    7565
    76     public FilterContent(FilterContent content, Cloner cloner)
     66    public FilterContent(IFilterLogic theFilterLogic) {
     67      filterLogic = theFilterLogic;
     68    }
     69
     70    protected FilterContent(FilterContent content, Cloner cloner)
    7771      : base(content, cloner) {
    78 
    7972    }
    8073
     
    8275      return new FilterContent(this, cloner);
    8376    }
    84 
    85 
    86 
    8777  }
    8878}
Note: See TracChangeset for help on using the changeset viewer.