-
Notifications
You must be signed in to change notification settings - Fork 7
/
SelectionDemo.bbj
123 lines (86 loc) · 3.3 KB
/
SelectionDemo.bbj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use ::BBjGridExWidget/BBjGridExWidget.bbj::BBjGridExWidget
use com.basiscomponents.bc.SqlQueryBC
use java.sql.Types
? 'HIDE'
declare auto BBjTopLevelWindow wnd!
declare auto BBjListButton lb_db!
declare auto BBjListButton lb_tbl!
declare auto BBjToolButton btn_fit!
declare BBjGridExWidget grid!
wnd! = BBjAPI().openSysGui("X0").addWindow(10,10,800,600,"BBj Grid Ex Demo")
grid! = new BBjGridExWidget(wnd!,100,0,40,800,560)
wnd! .setCallback(BBjAPI.ON_CLOSE,"byebye")
wnd! .setCallback(BBjAPI.ON_RESIZE,"resize")
st! = wnd!.addStaticText(200,20,10,200,25,"Enter rows to select, e.g. ""5,7""")
ed! = wnd!.addEditBox(201,200,10,250,22,"")
btn! = wnd!.addButton(202,460,10,80,22,"SELECT")
cb! = wnd!.addCheckBox(203,550,10,200,22,"Use Selection Checkbox")
btn!.setCallback(BBjAPI.ON_BUTTON_PUSH,"onSelectButton")
cb!.setCallback(BBjAPI.ON_CHECK_OFF,"onUseCheckbox")
cb!.setCallback(BBjAPI.ON_CHECK_ON,"onUseCheckbox")
gosub fillGrid
process_events
fillGrid:
declare SqlQueryBC sbc!
sbc! = new SqlQueryBC(BBjAPI().getJDBCConnection("CDStore"))
rs! = sbc!.retrieve("SELECT * FROM CDINVENTORY")
grid!.setData(rs!,"CDNUMBER")
grid!.setCallback(grid!.ON_GRID_SELECT_ROW(),"onRowSelect")
grid!.setCallback(grid!.ON_GRID_DOUBLE_CLICK(),"onRowDoubleclick")
grid!.setSelectionMode(grid!.GRID_SELECT_ROW())
grid!.setMultipleSelection(1)
return
byebye:
bye
resize:
ev! = BBjAPI().getLastEvent()
grid!.setSize(ev!.getWidth(),ev!.getHeight()-40)
return
onRowSelect:
ev! = BBjAPI().getLastEvent()
ev! = ev!.getObject()
print 'SHOW', ev!.getRowCount(), " ROW(s) AFFECTED By Event:" , ev!.getRows()
print ev!.getSelectedRowCount()," ROW(S) SELECTED By Event: ",ev!.getSelectedIds()
print ev!.getDeselectedRowCount()," ROW(S) DESELECTED By Event: ",ev!.getDeselectedIds()
print 'BR',grid!.getSelectedRows().size()," GET SELECTED ROWS : ", grid!.getSelectedRows(),'ER'
print 'BR',grid!.getSelectedRows().size()," GET SELECTED ROW : ", grid!.getSelectedRow(),'ER'
print "------------------------------------------------------------------------"
return
onRowDoubleclick:
ev! = BBjAPI().getLastEvent()
ev! = ev!.getObject()
if INFO(3,6)="5" then
a=msgbox(str(ev!.getRow()),0,"DOUBLE CLICK")
else
print 'SHOW', "DOUBLE CLICK" ,ev!.getRow()
fi
return
onSelectButton:
selection! = ed!.getText()
sel = num(selection!,err=multiple_selection)
grid!.setSelectedRow(sel)
rem now make sure this row is visible, in the middle
grid!.setVisibleRow(sel,grid!.GRID_ROWPOS_MIDDLE())
return
multiple_selection:
if pos(","=selection!)=0 then
a=msgbox("Enter row numbers, separated by comma!",0,"INPUT ERROR")
return
fi
x! = java.util.Arrays.asList(selection!.split(","))
s! = new BBjVector()
for i=0 to x!.size()
s!.addItem(num(x!.get(i),err=*continue))
next i
grid!.setSelectedRows(s!)
if (s!.size()>0) then
rem now make sure the first selected row is visible on top
grid!.setVisibleRow(s!.getItem(0),grid!.GRID_ROWPOS_TOP())
fi
return
onUseCheckbox:
useCheckbox = cb!.isSelected()
grid!.setShowSelectionCheckbox(useCheckbox)
rem this definition requires a refresh!
gosub fillGrid
return