Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private TableView1 As TableView
Private selectedRows As List
Private tvSelModel As JavaObject
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
MainForm.Show
MainForm.Title = "Table Example with CTRL Function"
TableView1.SetColumns(Array As String("Col1", "Col2"))
For i = 1 To 100
TableView1.Items.Add(Array(i, i))
Next
selectedRows.Initialize
Dim jotable As JavaObject=TableView1
'Get the Selection Mode Enum:
Dim joSelMode As JavaObject
joSelMode.InitializeStatic("javafx.scene.control.SelectionMode")
'get Selection Model:
tvSelModel = jotable.RunMethodJO("getSelectionModel", Null)
'set the selectionmode of the tableview by using the enum
tvSelModel.RunMethod("setSelectionMode",Array(joSelMode.GetField("MULTIPLE")))
Dim r As Reflector
r.Target = TableView1
r.AddEventFilter("TableView1", "javafx.scene.input.MouseEvent.MOUSE_PRESSED")
End Sub
Sub TableView1_Filter (EventData As Event)
Dim jo As JavaObject = EventData
Dim targetType As String = GetType(jo.RunMethod("getTarget", Null))
If targetType = "javafx.scene.control.TableColumn$1$1" Then
Dim row As JavaObject = jo.RunMethodJO("getTarget", Null).RunMethod("getTableRow", Null)
Dim index As Int = row.RunMethod("getIndex", Null)
Dim i As Int = selectedRows.IndexOf(index)
If i > -1 Then
selectedRows.RemoveAt(i)
tvSelModel.RunMethod("clearSelection", Array(index))
Else
selectedRows.Add(index)
Dim indices(selectedRows.Size - 1) As Int
For i = 0 To indices.Length - 1
indices(i) = selectedRows.Get(i + 1)
Next
tvSelModel.RunMethod("selectIndices", Array(selectedRows.Get(0), indices))
End If
EventData.Consume
Else if targetType = "javafx.scene.control.TableRow" Then
EventData.Consume
End If
End Sub