Improve Base Form Properties, Improve PanelManager

This commit is contained in:
Jonathan Jenne 2019-03-11 14:49:48 +01:00
parent e7e6d73411
commit 896426da3b
15 changed files with 145 additions and 61 deletions

View File

@ -10,6 +10,10 @@ Public Class ClassErrorHandler
Public Sub New(Logger As Logger) Public Sub New(Logger As Logger)
_Logger = Logger _Logger = Logger
End Sub End Sub
Public Sub ShowErrorMessage(Exception As Exception)
_Logger.Error(Exception)
MsgBox(GetMessage(Exception), MsgBoxStyle.Critical, "Unexpected Error")
End Sub
Private Function GetMessage(Exception As Exception) Private Function GetMessage(Exception As Exception)
Dim oTargetSite = Exception.TargetSite Dim oTargetSite = Exception.TargetSite
@ -34,11 +38,6 @@ Public Class ClassErrorHandler
Return oMessage Return oMessage
End Function End Function
Public Sub ShowErrorMessage(Exception As Exception)
_Logger.Error(Exception)
MsgBox(GetMessage(Exception), MsgBoxStyle.Critical, "Unexpected Error")
End Sub
Private Function GetMethodName(Exception As Exception) As String Private Function GetMethodName(Exception As Exception) As String
Dim oMethodName = Exception.TargetSite?.ReflectedType?.Name Dim oMethodName = Exception.TargetSite?.ReflectedType?.Name

View File

@ -2,6 +2,7 @@
Imports DevExpress.XtraBars.Docking2010 Imports DevExpress.XtraBars.Docking2010
Imports DevExpress.XtraBars.Docking2010.Views Imports DevExpress.XtraBars.Docking2010.Views
Imports DevExpress.XtraBars.Docking2010.Views.Tabbed Imports DevExpress.XtraBars.Docking2010.Views.Tabbed
Imports DevExpress.XtraGrid
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Public Class ClassPanelManager Public Class ClassPanelManager
@ -88,17 +89,42 @@ Public Class ClassPanelManager
' TODO: determine how much panels at most can be added ' TODO: determine how much panels at most can be added
' check if initial panels should be loaded ' check if initial panels should be loaded
For Each oPanelInfo As PanelInfo In oInitialPanelInfo For Each oPanelInfo As PanelInfo In oInitialPanelInfo
' Create the control ' create the panel
Dim oControl = oPanelInfo.InnerControl
oControl.Dock = DockStyle.Fill
' Create the panel and add the control
Dim oPanel = _dockManager.AddPanel(oPanelInfo.Position) Dim oPanel = _dockManager.AddPanel(oPanelInfo.Position)
' create the control
Dim oControl As BasePanel = GetPanelControl(oPanelInfo)
If oControl Is Nothing Then
Dim oPanelType = oPanelInfo.PanelControl.GetType.ToString
_logger.Warn("Unknown panel type {0}", oPanelType)
Continue For
End If
' configure the panel
oPanel.Options.ShowCloseButton = oPanelInfo.CanBeClosed
oPanel.Options.ShowAutoHideButton = oPanelInfo.CanBePinned
oPanel.Options.ShowMaximizeButton = oPanelInfo.CanBeMaximized
oPanel.Options.AllowFloating = oPanelInfo.CanBeUndocked
' hashcode is needed to know which form a panel belongs to
oPanel.Tag = oForm.GetHashCode oPanel.Tag = oForm.GetHashCode
oPanel.Text = oPanelInfo.Caption oPanel.Text = oPanelInfo.Title
oPanel.Controls.Add(oControl) oPanel.Controls.Add(oControl)
Next Next
' TODO: establish communication channel to load panels on-demand ' TODO: establish communication channel to load panels on-demand
End Sub End Sub
Private Function GetPanelControl(PanelInfo As PanelInfo) As BasePanel
If TypeOf PanelInfo.PanelControl Is DocumentPanel Then
Dim oPanelControl As DocumentPanel = DirectCast(PanelInfo.PanelControl, DocumentPanel)
oPanelControl.Datasource = PanelInfo.Datasource
oPanelControl.Dock = DockStyle.Fill
Return oPanelControl
Else
Return Nothing
End If
End Function
End Class End Class

View File

@ -159,7 +159,6 @@
<Compile Include="Panels\DocumentPanel.vb"> <Compile Include="Panels\DocumentPanel.vb">
<SubType>UserControl</SubType> <SubType>UserControl</SubType>
</Compile> </Compile>
<Compile Include="Panels\IPanel.vb" />
<Compile Include="Panels\PanelInfo.vb" /> <Compile Include="Panels\PanelInfo.vb" />
<Compile Include="_TEST\DockManagerTest.Designer.vb"> <Compile Include="_TEST\DockManagerTest.Designer.vb">
<DependentUpon>DockManagerTest.vb</DependentUpon> <DependentUpon>DockManagerTest.vb</DependentUpon>

View File

@ -14,8 +14,14 @@ Imports DigitalData.Modules.Logging
Public Class BaseForm Public Class BaseForm
Inherits Form Inherits Form
Protected ReadOnly _Logger As Logger Private ReadOnly _Logger As Logger
Protected ReadOnly _ErrorHandler As ClassErrorHandler Private ReadOnly _ErrorHandler As ClassErrorHandler
Protected ReadOnly Property Logger As Logger
Get
Return _Logger
End Get
End Property
Public Sub New() Public Sub New()
' Get the full name of the inheriting form ' Get the full name of the inheriting form
@ -30,4 +36,8 @@ Public Class BaseForm
' depends on a global var like My.LogConfig ' depends on a global var like My.LogConfig
' you might need to check for its existence with ? ' you might need to check for its existence with ?
End Sub End Sub
Public Sub ShowErrorMessage(Exception As Exception)
_ErrorHandler.ShowErrorMessage(Exception)
End Sub
End Class End Class

View File

@ -17,8 +17,14 @@ Imports DigitalData.Modules.Logging
Public Class BaseRibbonForm Public Class BaseRibbonForm
Inherits RibbonForm Inherits RibbonForm
Protected ReadOnly _Logger As Logger Private ReadOnly _Logger As Logger
Protected ReadOnly _ErrorHandler As ClassErrorHandler Private ReadOnly _ErrorHandler As ClassErrorHandler
Protected ReadOnly Property Logger As Logger
Get
Return _Logger
End Get
End Property
Public Sub New() Public Sub New()
' Get the full name of the inheriting form ' Get the full name of the inheriting form
@ -34,6 +40,17 @@ Public Class BaseRibbonForm
' you might need to check for its existence with ? ' you might need to check for its existence with ?
End Sub End Sub
Public Sub ShowErrorMessage(Exception As Exception)
_ErrorHandler.ShowErrorMessage(Exception)
End Sub
''' <summary>
''' Returns a list of panels that will be show when the form is opened.
''' This can be overridden by all inheriting forms to extend the list of panels
''' Panels will be created by PanelManager.
''' </summary>
''' <seealso cref="ClassPanelManager"/>
''' <returns>A list of PanelInformation</returns>
Public Overridable Function GetInitialPanels() As List(Of PanelInfo) Public Overridable Function GetInitialPanels() As List(Of PanelInfo)
Return New List(Of PanelInfo) Return New List(Of PanelInfo)
End Function End Function

View File

@ -1,3 +1,4 @@
Public Class BasePanel Public Class BasePanel
Public Property Caption As String
End Class End Class

View File

@ -1,6 +1,6 @@
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class DocumentPanel Partial Class DocumentPanel
Inherits System.Windows.Forms.UserControl Inherits BasePanel
'UserControl überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. 'UserControl überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
<System.Diagnostics.DebuggerNonUserCode()> _ <System.Diagnostics.DebuggerNonUserCode()> _
@ -22,40 +22,40 @@ Partial Class DocumentPanel
'Das Bearbeiten mit dem Code-Editor ist nicht möglich. 'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
<System.Diagnostics.DebuggerStepThrough()> _ <System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent() Private Sub InitializeComponent()
Me.GridControl1 = New DevExpress.XtraGrid.GridControl() Me.GridControlMain = New DevExpress.XtraGrid.GridControl()
Me.GridView1 = New DevExpress.XtraGrid.Views.Grid.GridView() Me.GridViewMain = New DevExpress.XtraGrid.Views.Grid.GridView()
CType(Me.GridControl1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.GridControlMain, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.GridView1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.GridViewMain, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout() Me.SuspendLayout()
' '
'GridControl1 'GridControlMain
' '
Me.GridControl1.Dock = System.Windows.Forms.DockStyle.Fill Me.GridControlMain.Dock = System.Windows.Forms.DockStyle.Fill
Me.GridControl1.Location = New System.Drawing.Point(0, 0) Me.GridControlMain.Location = New System.Drawing.Point(0, 0)
Me.GridControl1.MainView = Me.GridView1 Me.GridControlMain.MainView = Me.GridViewMain
Me.GridControl1.Name = "GridControl1" Me.GridControlMain.Name = "GridControlMain"
Me.GridControl1.Size = New System.Drawing.Size(1027, 383) Me.GridControlMain.Size = New System.Drawing.Size(1027, 383)
Me.GridControl1.TabIndex = 0 Me.GridControlMain.TabIndex = 0
Me.GridControl1.ViewCollection.AddRange(New DevExpress.XtraGrid.Views.Base.BaseView() {Me.GridView1}) Me.GridControlMain.ViewCollection.AddRange(New DevExpress.XtraGrid.Views.Base.BaseView() {Me.GridViewMain})
' '
'GridView1 'GridViewMain
' '
Me.GridView1.GridControl = Me.GridControl1 Me.GridViewMain.GridControl = Me.GridControlMain
Me.GridView1.Name = "GridView1" Me.GridViewMain.Name = "GridViewMain"
' '
'DocumentPanel 'DocumentPanel
' '
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.Controls.Add(Me.GridControl1) Me.Controls.Add(Me.GridControlMain)
Me.Name = "DocumentPanel" Me.Name = "DocumentPanel"
Me.Size = New System.Drawing.Size(1027, 383) Me.Size = New System.Drawing.Size(1027, 383)
CType(Me.GridControl1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.GridControlMain, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.GridView1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.GridViewMain, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False) Me.ResumeLayout(False)
End Sub End Sub
Friend WithEvents GridControl1 As DevExpress.XtraGrid.GridControl Friend WithEvents GridControlMain As DevExpress.XtraGrid.GridControl
Friend WithEvents GridView1 As DevExpress.XtraGrid.Views.Grid.GridView Friend WithEvents GridViewMain As DevExpress.XtraGrid.Views.Grid.GridView
End Class End Class

View File

@ -1,12 +1,26 @@
Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Imports DigitalData.GUIs.ClientSuite
Public Class DocumentPanel Public Class DocumentPanel
Inherits BasePanel Inherits BasePanel
Public WriteOnly Property Datasource As DataTable
Set(value As DataTable)
GridControlMain.DataSource = value
End Set
End Property
Private Sub DocumentPanel_Load(sender As Object, e As EventArgs) Handles Me.Load Private Sub DocumentPanel_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim oGridPatcher As New ClassControlPatcher(Of GridControl)(Me) Dim oGridPatcher As New ClassControlPatcher(Of GridControl)(Me)
oGridPatcher. oGridPatcher.
ProcessContainer(AddressOf GridControlDefaults.DefaultGridSettings). ProcessContainer(AddressOf GridControlDefaults.DefaultGridSettings).
ProcessContainer(AddressOf GridControlDefaults.ReadOnlyGridSettings) ProcessContainer(AddressOf GridControlDefaults.ReadOnlyGridSettings)
End Sub End Sub
Private Sub GridViewMain_RowClick(sender As Object, e As RowClickEventArgs) Handles GridViewMain.RowClick
If e.Button = MouseButtons.Left And e.Clicks = 2 Then
MsgBox("Open Preview")
End If
End Sub
End Class End Class

View File

@ -1,3 +0,0 @@
Public Interface IPanel
ReadOnly Property PanelName As String
End Interface

View File

@ -1,7 +1,26 @@
Imports DevExpress.XtraBars.Docking Imports DevExpress.XtraBars.Docking
Public Class PanelInfo Public Class PanelInfo
Public Caption As String Public ReadOnly Title As String
Public InnerControl As BasePanel Public ReadOnly PanelControl As BasePanel
Public Position As DockingStyle Public ReadOnly Position As DockingStyle
End Class Public ReadOnly Datasource As DataTable
Public CanBeClosed As Boolean = True
Public CanBePinned As Boolean = True
Public CanBeUndocked As Boolean = True
Public CanBeMaximized As Boolean = True
Public Sub New(PanelControl As BasePanel, Position As DockingStyle)
Me.Title = PanelControl.Caption
Me.PanelControl = PanelControl
Me.Position = Position
End Sub
Public Sub New(PanelControl As BasePanel, Position As DockingStyle, Datasource As DataTable)
Me.Title = PanelControl.Caption
Me.PanelControl = PanelControl
Me.Position = Position
Me.Datasource = Datasource
End Sub
End Class

View File

@ -32,7 +32,7 @@ Public Class frmDocTest
GridControl1.DataSource = oDatatable GridControl1.DataSource = oDatatable
Catch ex As Exception Catch ex As Exception
_ErrorHandler.ShowErrorMessage(ex) ShowErrorMessage(ex)
End Try End Try
End Sub End Sub

View File

@ -11,7 +11,7 @@ Public Class frmFileTest
_fileOp = New Document(My.LogConfig, My.Settings.EDM_NetworkService_Adress) _fileOp = New Document(My.LogConfig, My.Settings.EDM_NetworkService_Adress)
Catch ex As Exception Catch ex As Exception
_Logger.Warn($"Unexpected error in frmFileTest_Load: {ex.Message}") Logger.Warn($"Unexpected error in frmFileTest_Load: {ex.Message}")
End Try End Try
End Sub End Sub
@ -38,7 +38,7 @@ Public Class frmFileTest
listboxLog.Items.Add($"----------------------------------------------------------") listboxLog.Items.Add($"----------------------------------------------------------")
Catch ex As Exception Catch ex As Exception
MsgBox(ex.Message) MsgBox(ex.Message)
_Logger.Error(ex) Logger.Error(ex)
End Try End Try
End Sub End Sub
@ -60,7 +60,7 @@ Public Class frmFileTest
listboxLog.Items.Add($"Filename: {oDocObject.FileName}") listboxLog.Items.Add($"Filename: {oDocObject.FileName}")
listboxLog.Items.Add($"----------------------------------------------------------") listboxLog.Items.Add($"----------------------------------------------------------")
Catch ex As Exception Catch ex As Exception
_ErrorHandler.ShowErrorMessage(ex) ShowErrorMessage(ex)
End Try End Try
End Sub End Sub
@ -82,7 +82,7 @@ Public Class frmFileTest
listboxLog.Items.Add($"Filename: {oDocObject.FileName}") listboxLog.Items.Add($"Filename: {oDocObject.FileName}")
listboxLog.Items.Add($"----------------------------------------------------------") listboxLog.Items.Add($"----------------------------------------------------------")
Catch ex As Exception Catch ex As Exception
_ErrorHandler.ShowErrorMessage(ex) ShowErrorMessage(ex)
End Try End Try
End Sub End Sub
End Class End Class

View File

@ -68,7 +68,7 @@ Public Class frmMain
' We're done loading now ' We're done loading now
_Loading = False _Loading = False
Catch ex As Exception Catch ex As Exception
_ErrorHandler.ShowErrorMessage(ex) ShowErrorMessage(ex)
End Try End Try
End Sub End Sub
@ -96,7 +96,7 @@ Public Class frmMain
'DocumentManager.View.RestoreLayoutFromXml(oLayoutPathForDocumentManager) 'DocumentManager.View.RestoreLayoutFromXml(oLayoutPathForDocumentManager)
End If End If
Catch ex As Exception Catch ex As Exception
_ErrorHandler.ShowErrorMessage(ex) ShowErrorMessage(ex)
End Try End Try
End Sub End Sub
Private Sub SaveLayout() Private Sub SaveLayout()
@ -112,7 +112,7 @@ Public Class frmMain
'DockManager.SaveLayoutToXml(oLayoutPathForDockManager) 'DockManager.SaveLayoutToXml(oLayoutPathForDockManager)
'DocumentManager.View.SaveLayoutToXml(oLayoutPathForDocumentManager) 'DocumentManager.View.SaveLayoutToXml(oLayoutPathForDocumentManager)
Catch ex As Exception Catch ex As Exception
_ErrorHandler.ShowErrorMessage(ex) ShowErrorMessage(ex)
End Try End Try
End Sub End Sub
@ -197,8 +197,6 @@ Public Class frmMain
End Sub End Sub
Private Sub MainNav_SelectedItemChanging(sender As Object, e As DevExpress.XtraBars.Navigation.SelectedItemChangingEventArgs) Handles MainNav.SelectedItemChanging Private Sub MainNav_SelectedItemChanging(sender As Object, e As DevExpress.XtraBars.Navigation.SelectedItemChangingEventArgs) Handles MainNav.SelectedItemChanging
Select Case e.Item.Name Select Case e.Item.Name
Case NavbarItemHome.Name Case NavbarItemHome.Name
Dim oForm As New frmHome() Dim oForm As New frmHome()

View File

@ -32,7 +32,7 @@ Public Class frmObjectEditor
} }
If _Datatable Is Nothing Then If _Datatable Is Nothing Then
_ErrorHandler.ShowErrorMessage(New ArgumentNullException("Datatable is empty")) ShowErrorMessage(New ArgumentNullException("Datatable is empty"))
End If End If
End Sub End Sub
@ -54,7 +54,7 @@ Public Class frmObjectEditor
Await LoadLanguageTableAsync(My.Application.User.Language) Await LoadLanguageTableAsync(My.Application.User.Language)
LoadDetailForm() LoadDetailForm()
Catch ex As Exception Catch ex As Exception
_ErrorHandler.ShowErrorMessage(ex) ShowErrorMessage(ex)
End Try End Try
End Sub End Sub
@ -110,7 +110,7 @@ Public Class frmObjectEditor
Await My.Channel.CloseDatabaseRequestAsync() Await My.Channel.CloseDatabaseRequestAsync()
Catch ex As Exception Catch ex As Exception
_ErrorHandler.ShowErrorMessage(ex) ShowErrorMessage(ex)
End Try End Try
End Function End Function

View File

@ -16,11 +16,15 @@ Public Class frmSearch
Public Overrides Function GetInitialPanels() As List(Of PanelInfo) Public Overrides Function GetInitialPanels() As List(Of PanelInfo)
Dim oList = MyBase.GetInitialPanels() Dim oList = MyBase.GetInitialPanels()
Dim oPanel = New DocumentPanel()
Dim oData As DataTable
oList.Add(New PanelInfo() With { My.Channel.CreateDatabaseRequest("Get Users", False)
.Caption = "Search", oData = My.Channel.ReturnDatatable("SELECT * FROM VWICM_USER").Table
.InnerControl = New DocumentPanel(), My.Channel.CloseDatabaseRequest()
.Position = DockingStyle.Bottom
oList.Add(New PanelInfo(oPanel, DockingStyle.Bottom, oData) With {
.CanBeClosed = False
}) })
Return oList Return oList