Changeset 11098


Ignore:
Timestamp:
07/06/14 20:15:28 (5 years ago)
Author:
mkommend
Message:

#2206: Bug fixes regarding the deletion of rows in the grid display and code simplifications.

Location:
branches/DataPreprocessing
Files:
8 edited

Legend:

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

    r11070 r11098  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Drawing;
    2524using System.Linq;
    2625using System.Windows.Forms;
     
    3534  public partial class DataGridContentView : StringConvertibleMatrixView {
    3635
    37     private bool notOwnEvent = true;
    3836    private bool isSearching = false;
    3937    private bool updateOnMouseUp = false;
     
    4947    }
    5048
    51     private IList<int> _highlightedRowIndices;
    52     public IList<int> HighlightedRowIndices {
    53       get { return _highlightedRowIndices; }
    54       set {
    55         _highlightedRowIndices = value;
    56         Refresh();
    57       }
    58     }
    59 
    6049    private IDictionary<int, IList<int>> _highlightedCellsBackground;
    6150    public IDictionary<int, IList<int>> HightlightedCellsBackground {
     
    7059      InitializeComponent();
    7160      dataGridView.CellMouseClick += dataGridView_CellMouseClick;
    72       dataGridView.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(dataGridView_CellPainting);
    7361      dataGridView.KeyDown += dataGridView_KeyDown;
    7462      dataGridView.MouseUp += dataGridView_MouseUp;
    7563      dataGridView.ColumnHeaderMouseClick += dataGridView_ColumnHeaderMouseClick;
    7664      contextMenuCell.Items.Add(ShowHideColumns);
    77       _highlightedRowIndices = new List<int>();
    7865      _highlightedCellsBackground = new Dictionary<int, IList<int>>();
    7966      currentCell = null;
     
    123110
    124111    private void Content_Changed(object sender, DataPreprocessingChangedEventArgs e) {
    125       if (notOwnEvent) {
    126         OnContentChanged();
    127       }
     112      OnContentChanged();
    128113      searchIterator = null;
    129114    }
     
    131116    protected override void dataGridView_SelectionChanged(object sender, EventArgs e) {
    132117      base.dataGridView_SelectionChanged(sender, e);
    133       if (Content != null)
     118      if (Content != null && dataGridView.RowCount != 0 && dataGridView.ColumnCount != 0)
    134119        Content.Selection = GetSelectedCells();
    135120    }
    136121
     122    //couldn't use base.dataGridView_CellValidating as the values have to be validated per column individually
    137123    protected override void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
    138       if (!dataGridView.ReadOnly) {
    139         string errorMessage;
    140         if (Content != null) {
    141           if (dataGridView.IsCurrentCellInEditMode && Content.FilterLogic.IsFiltered) {
    142             errorMessage = "A filter is active, you cannot modify data. Press ESC to exit edit mode.";
    143           } else {
    144             Content.Validate(e.FormattedValue.ToString(), out errorMessage, e.ColumnIndex);
    145           }
    146 
    147           if (!String.IsNullOrEmpty(errorMessage)) {
    148             e.Cancel = true;
    149             dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
    150           }
    151         }
    152       }
    153     }
    154 
    155     protected override void dataGridView_CellParsing(object sender, DataGridViewCellParsingEventArgs e) {
    156       triggersOwnEvent(() => base.dataGridView_CellParsing(sender, e));
    157     }
    158 
    159     protected override void PasteValuesToDataGridView() {
    160       triggersOwnEvent(() => base.PasteValuesToDataGridView());
    161       dataGridView.Refresh();
    162     }
     124      if (dataGridView.ReadOnly) return;
     125      if (Content == null) return;
     126      if (Content.Rows == 0 || Content.Columns == 0) return;
     127
     128      string errorMessage;
     129      if (Content != null) {
     130        if (dataGridView.IsCurrentCellInEditMode && Content.FilterLogic.IsFiltered) {
     131          errorMessage = "A filter is active, you cannot modify data. Press ESC to exit edit mode.";
     132        } else {
     133          Content.Validate(e.FormattedValue.ToString(), out errorMessage, e.ColumnIndex);
     134        }
     135
     136        if (!String.IsNullOrEmpty(errorMessage)) {
     137          e.Cancel = true;
     138          dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
     139        }
     140
     141      }
     142    }
     143
     144
     145    //protected override void PasteValuesToDataGridView() {
     146    //  base.PasteValuesToDataGridView();
     147    //  dataGridView.Refresh();
     148    //}
    163149
    164150    protected override void SetEnabledStateOfControls() {
     
    191177
    192178    private void btnApplySort_Click(object sender, System.EventArgs e) {
    193       triggersOwnEvent(() => {
    194         Content.ManipulationLogic.ReOrderToIndices(virtualRowIndices);
    195         OnContentChanged();
    196       });
    197     }
    198 
    199     private void triggersOwnEvent(Action action) {
    200       notOwnEvent = false;
    201       action();
    202       notOwnEvent = true;
     179      Content.ManipulationLogic.ReOrderToIndices(virtualRowIndices);
     180      OnContentChanged();
    203181    }
    204182
     
    494472    }
    495473
    496     protected void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {
    497       if (Content == null) return;
    498       if (e.RowIndex < 0) return;
    499       if (e.ColumnIndex < 0) return;
    500       if (e.State.HasFlag(DataGridViewElementStates.Selected)) return;
    501       if (!e.PaintParts.HasFlag(DataGridViewPaintParts.Background)) return;
    502       if (HighlightedRowIndices == null) return;
    503 
    504       int rowIndex = virtualRowIndices[e.RowIndex];
    505 
    506       Color backColor = e.CellStyle.BackColor;
    507 
    508       if (HightlightedCellsBackground.ContainsKey(e.ColumnIndex) && HightlightedCellsBackground[e.ColumnIndex].Contains(e.RowIndex)) {
    509         backColor = Color.LightGray;
    510       }
    511 
    512       using (Brush backColorBrush = new SolidBrush(backColor)) {
    513         Rectangle bounds = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height);
    514         e.Graphics.FillRectangle(backColorBrush, bounds);
    515       }
    516 
    517       using (Brush gridBrush = new SolidBrush(Color.LightGray)) {
    518         Pen gridLinePen = new Pen(gridBrush);
    519         e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
    520                e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
    521                e.CellBounds.Bottom - 1);
    522         e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
    523             e.CellBounds.Top, e.CellBounds.Right - 1,
    524             e.CellBounds.Bottom);
    525       }
    526       e.PaintContent(e.CellBounds);
    527       e.Handled = true;
    528     }
    529 
    530474    private void dataGridView_KeyDown(object sender, KeyEventArgs e) {
    531475      var selectedRows = dataGridView.SelectedRows;
     
    535479          rows.Add(selectedRows[i].Index);
    536480        }
    537         triggersOwnEvent(() => {
    538           Content.DeleteRow(rows);
    539           OnContentChanged();
    540         });
     481        Content.DeleteRow(rows);
    541482      } else if (e.Control && e.KeyCode == Keys.F) {
    542483        CreateFindAndReplaceDialog();
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/HistogramView.cs

    r10992 r11098  
    4040      base.OnContentChanged();
    4141      if (Content != null) {
    42 
    4342        classifierComboBox.Items.Clear();
    4443        classifierComboBox.Items.Add("None");
     
    4746          classifierComboBox.Items.Add(var);
    4847        }
    49 
    5048
    5149        if (classifierComboBox.SelectedItem == null && Content.ClassifierVariableIndex < classifierComboBox.Items.Count) {
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingChartView.cs

    r11039 r11098  
    263263
    264264    protected void GenerateChart() {
    265 
    266265      ClearTableLayout();
    267266      if (Content.AllInOneMode) {
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/TransactionalPreprocessingData.cs

    r11068 r11098  
    212212
    213213    public override void DeleteRowsWithIndices(IEnumerable<int> rows) {
    214       foreach (int rowIndex in rows) {
    215         DeleteRow(rowIndex);
    216       }
     214      SaveSnapshot(DataPreprocessingChangedEventType.AddRow, -1, -1);
     215      foreach (int rowIndex in rows.OrderByDescending(x => x)) {
     216        foreach (IList column in variableValues) {
     217          column.RemoveAt(rowIndex);
     218        }
     219      }
     220      if (!IsInTransaction)
     221        OnChanged(DataPreprocessingChangedEventType.DeleteRow, -1, -1);
    217222    }
    218223
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/ProblemDataCreator.cs

    r11068 r11098  
    4242
    4343    public IDataAnalysisProblemData CreateProblemData() {
     44      if (context.Data.Rows == 0 || context.Data.Columns == 0) return null;
     45
    4446      var oldProblemData = context.ProblemData;
    45 
    4647      IDataAnalysisProblemData problemData;
    4748
  • branches/DataPreprocessing/HeuristicLab.MainForm.WindowsForms/3.3/HeuristicLab.MainForm.WindowsForms-3.3.csproj

    r9915 r11098  
    159159    <None Include="Plugin.cs.frame" />
    160160    <Compile Include="Controls\ControlExtensions.cs" />
    161     <Compile Include="MainForms\DockForm.cs">
    162       <SubType>Form</SubType>
    163     </Compile>
     161    <Compile Include="MainForms\DockForm.cs" />
    164162    <Compile Include="MainForms\DockForm.Designer.cs">
    165163      <DependentUpon>DockForm.cs</DependentUpon>
  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionView.cs

    r11070 r11098  
    2222using System;
    2323using System.ComponentModel;
     24using System.Linq;
    2425using System.Windows.Forms;
    2526using HeuristicLab.MainForm;
     
    4445      btnSimplify.Enabled = Content != null && !Locked;
    4546      exportButton.Enabled = Content != null && !Locked;
    46       transformModelButton.Visible = false;
     47      transformModelButton.Visible = Content != null && Content.ProblemData.Transformations.Any();
    4748      transformModelButton.Enabled = Content != null && !Locked;
    4849    }
  • branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Views/3.4/FeatureCorrelation/AbstractFeatureCorrelationView.cs

    r9456 r11098  
    5757      partitionComboBox.DataSource = Partitions;
    5858      partitionComboBox.SelectedItem = TRAININGSAMPLES;
     59      progressPanel.Visible = false;
    5960    }
    6061
     
    7879        CalculateCorrelation();
    7980      } else {
     81        progressPanel.Visible = false;
    8082        dataView.Maximum = 0;
    8183        dataView.Minimum = 0;
Note: See TracChangeset for help on using the changeset viewer.