Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Collections

'Wersja klasy Bridge z sortowaniem danych
Public Class ListBridge
  Implements Bridger
  'most pomiędzy listami, a obiektami prezentacyjnymi
  Private visL As VisList
  '-----    
  Public Sub New(ByVal vis As VisList)
    MyBase.New()
    visL = vis
  End Sub
  '-----    
  Public Sub addData(ByVal col As ArrayList) _
          Implements Bridger.addData
    Dim i, j, max As Integer
    Dim p As Product
    max = col.Count
    Dim products(max) As Product
    For i = 0 To max - 1
      products(i) = CType(col(i), Product)
    Next i
    'uporządkuj tablicę
    For i = 0 To max - 1
      For j = i To max - 1
        If products(i).getName > products(j).getName Then
          p = products(i)
          products(i) = products(j)
          products(j) = p
        End If
      Next j
    Next i
    'dodaj dane do listy
    For i = 0 To max - 1
      visL.addLine(products(i))
    Next i
  End Sub
End Class
