Skip to content

Commit

Permalink
Merge pull request #8007 from N-thony/reorder_dataframe
Browse files Browse the repository at this point in the history
Maintaining the selected sheet in the Data View after reordering
  • Loading branch information
lloyddewit authored Dec 11, 2022
2 parents 15723bb + 0e17933 commit 50fb40f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
2 changes: 1 addition & 1 deletion instat/Interface/IGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Public Interface IGrid

Sub UpdateAllWorksheetStyles()

Sub ReOrderWorksheets()
Sub ReOrderWorksheets(strCurrWorksheet As String)

Sub UpdateWorksheetStyle(worksheet As clsWorksheetAdapter)
End Interface
13 changes: 11 additions & 2 deletions instat/UserControls/DataGrid/Linux/ucrLinuxGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ Public MustInherit Class ucrLinuxGrid
Return New clsWorksheetAdapter(tab)
End Function

Private Sub ReOrderWorksheets() Implements IGrid.ReOrderWorksheets
''' <summary>
''' Reorder the worksheets
''' </summary>
Private Sub ReOrderWorksheets(strCurrWorksheet As String) Implements IGrid.ReOrderWorksheets
'assuming the databook will always have all the data frames
'and the grid may not have all the data frame worksheets equivalent
'and all data frames in the data book have changed their order positions
Expand All @@ -95,12 +98,18 @@ Public MustInherit Class ucrLinuxGrid
lstWorkSheetsFound.Add(fillWorkSheet)
End If
Next
If lstWorkSheetsFound.Count > 1 Then

'in the second condition we check if all data frames in the data book
'have the same order positions with all data frame sheets in the grid
'if not this check will return False which means the data frames in the data book are reordered
If lstWorkSheetsFound.Count > 1 AndAlso Not _clsDataBook.DataFrames.Select(Function(x) x.strName).ToList().
SequenceEqual(tcTabs.Controls.OfType(Of TabPage).Select(Function(x) x.Text).ToList) Then
'reorder the worksheets based on the filled list
For i As Integer = 0 To lstWorkSheetsFound.Count - 1
tcTabs.TabPages.Remove(lstWorkSheetsFound(i))
tcTabs.TabPages.Insert(i, lstWorkSheetsFound(i))
Next
tcTabs.SelectedTab = GetTabPage(strCurrWorksheet) 'set the selected sheet back active before reordering
End If
End Sub

Expand Down
14 changes: 11 additions & 3 deletions instat/UserControls/DataGrid/ReoGrid/ucrReoGrid.vb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ Public MustInherit Class ucrReoGrid
Return New clsWorksheetAdapter(fillWorkSheet)
End Function

Private Sub ReOrderWorksheets() Implements IGrid.ReOrderWorksheets
''' <summary>
''' Reorder the worksheets
''' </summary>
Private Sub ReOrderWorksheets(strCurrWorksheet As String) Implements IGrid.ReOrderWorksheets
'assuming the databook will always have all the data frames
'and the grid may not have all the data frame worksheets equivalent
'and all data frames in the data book have changed their order positions
Expand All @@ -84,12 +87,17 @@ Public MustInherit Class ucrReoGrid
lstWorkSheetsFound.Add(fillWorkSheet)
End If
Next
If lstWorkSheetsFound.Count > 1 Then

'in the second condition we check if all data frames in the data book
'have the same order positions with all data frame sheets in the grid
'if not this check will return False which means the data frames in the data book are reordered
If lstWorkSheetsFound.Count > 1 AndAlso Not _clsDataBook.DataFrames.Select(Function(x) x.strName).ToList().
SequenceEqual(grdData.Worksheets.Select(Function(x) x.Name).ToList()) Then
'reorder the worksheets based on the filled list
For i As Integer = 0 To lstWorkSheetsFound.Count - 1
grdData.MoveWorksheet(lstWorkSheetsFound(i), i)
grdData.CurrentWorksheet = lstWorkSheetsFound(i)
Next
grdData.CurrentWorksheet = grdData.GetWorksheetByName(strCurrWorksheet) 'set the selected sheet back active before reordering
End If
End Sub

Expand Down
4 changes: 0 additions & 4 deletions instat/dlgReorderDataFrame.vb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,4 @@ Public Class dlgReorderDataFrame
Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrDataFrameToReorder.ControlContentsChanged
TestOkEnabled()
End Sub

Private Sub ucrBase_ClickOk(sender As Object, e As EventArgs) Handles ucrBase.ClickOk
frmMain.ReOrderWorkSheets()
End Sub
End Class
5 changes: 0 additions & 5 deletions instat/frmMain.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1513,11 +1513,6 @@ Public Class frmMain
ucrColumnMeta.SetCurrentDataFrame(iIndex)
End Sub

Public Sub ReOrderWorkSheets()
ucrDataViewer.ReOrderWorkSheets()
ucrColumnMeta.ReOrderWorkSheets()
End Sub

Private Sub CummulativeDistributionToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles mnuDescribeSpecificCummulativeDistribution.Click
dlgCumulativeDistribution.ShowDialog()
End Sub
Expand Down
8 changes: 4 additions & 4 deletions instat/ucrColumnMetadata.vb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Public Class ucrColumnMetadata

Private Sub AddAndUpdateWorksheets()
Dim firstAddedWorksheet As clsWorksheetAdapter = Nothing
Dim strCurrWorksheet As String = If(_grid.CurrentWorksheet Is Nothing, Nothing, _grid.CurrentWorksheet.Name)
For Each clsDataFrame In _clsDataBook.DataFrames
Dim worksheet As clsWorksheetAdapter = _grid.GetWorksheet(clsDataFrame.strName)
If worksheet Is Nothing Then
Expand All @@ -73,6 +74,9 @@ Public Class ucrColumnMetadata
End If
RefreshWorksheet(worksheet, clsDataFrame)
Next
If strCurrWorksheet IsNot Nothing Then
_grid.ReOrderWorksheets(strCurrWorksheet)
End If
If firstAddedWorksheet IsNot Nothing Then
_grid.CurrentWorksheet = firstAddedWorksheet
End If
Expand Down Expand Up @@ -123,10 +127,6 @@ Public Class ucrColumnMetadata
_grid.SetCurrentDataFrame(iIndex)
End Sub

Public Sub ReOrderWorkSheets()
_grid.ReOrderWorksheets()
End Sub

Private Sub DeleteLables(strColumnName As String)
Dim clsDeleteLabelsFunction As New RFunction

Expand Down
12 changes: 5 additions & 7 deletions instat/ucrDataView.vb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Public Class ucrDataView

Private Sub AddAndUpdateWorksheets()
Dim firstAddedWorksheet As clsWorksheetAdapter = Nothing
Dim strCurrWorksheet As String = GetCurrentDataFrameNameFocus()
For Each clsDataFrame In _clsDataBook.DataFrames
Dim worksheet As clsWorksheetAdapter = _grid.GetWorksheet(clsDataFrame.strName)
If worksheet Is Nothing Then
Expand All @@ -128,6 +129,9 @@ Public Class ucrDataView
End If
RefreshWorksheet(worksheet, clsDataFrame)
Next
If strCurrWorksheet IsNot Nothing Then
_grid.ReOrderWorksheets(strCurrWorksheet)
End If
If firstAddedWorksheet IsNot Nothing Then
_grid.CurrentWorksheet = firstAddedWorksheet
End If
Expand Down Expand Up @@ -230,20 +234,14 @@ Public Class ucrDataView
End Sub

Public Sub CurrentWorksheetChanged()
If GetWorkSheetCount() <> 0 Then
frmMain.ucrColumnMeta.SetCurrentDataFrame(_grid.CurrentWorksheet.Name)
End If
frmMain.ucrColumnMeta.SetCurrentDataFrame(GetCurrentDataFrameNameFocus())
RefreshDisplayInformation()
End Sub

Public Function GetWorkSheetCount() As Integer
Return _grid.GetWorksheetCount
End Function

Public Sub ReOrderWorkSheets()
_grid.ReOrderWorksheets()
End Sub

Private Sub RefreshDisplayInformation()
If GetWorkSheetCount() <> 0 AndAlso _clsDataBook IsNot Nothing AndAlso GetCurrentDataFrameFocus() IsNot Nothing Then
frmMain.tstatus.Text = _grid.CurrentWorksheet.Name
Expand Down

0 comments on commit 50fb40f

Please sign in to comment.