-
Notifications
You must be signed in to change notification settings - Fork 7
/
SelectionDemo.bbj
148 lines (102 loc) · 3.83 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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")
grid!.setCallback(grid!.ON_GRID_SELECT_ROW(),"onSelection")
grid!.setCallback(grid!.ON_GRID_DOUBLE_CLICK(),"onDoubleCLick")
grid!.setSelectionMode(grid!.GRID_SELECT_CELL())
grid!.setMultipleSelection(1)
gosub fillGrid
process_events
fillGrid:
declare SqlQueryBC sbc!
sbc! = new SqlQueryBC(BBjAPI().getJDBCConnection("CDStore"))
rs! = sbc!.retrieve("SELECT * FROM CDINVENTORY")
grid!.setData(rs!)
return
byebye:
bye
resize:
ev! = BBjAPI().getLastEvent()
grid!.setSize(ev!.getWidth(),ev!.getHeight()-40)
return
onSelection:
ev! = BBjAPI().getLastEvent()
ev! = ev!.getObject()
rows! = grid!.getSelectedRows()
row! = grid!.getSelectedRow()
if INFO(3,6)="5" then
if row! <> null() then
a=msgbox(row!.getId() + " - " + row!.asDataRow().getFieldAsString("TITLE"),0,"DOUBLE CLICK")
else
a = msgbox(str(rows!), 0, "Selection")
fi
else
print "------------------------------------------------------------------------"
print 'SHOW' , "getSelectedRow: "
print row!.getId() , " - " , row!.asDataRow().getFieldAsString("TITLE")
print 'SHOW' , "getSelectedRows: "
it! = rows!.iterator()
while it!.hasNext()
row! = it!.next()
print 'SHOW' , row!.getId() , " - " , row!.asDataRow().getFieldAsString("TITLE")
wend
print 'SHOW',
print ev!.getRowCount(), " ROW(s) AFFECTED By Event:" , ev!.getChangedRows()
print ev!.getSelectedRowCount()," ROW(S) SELECTED By Event: ",ev!.getNewSelectedRows()
print ev!.getDeselectedRowCount()," ROW(S) DESELECTED By Event: ",ev!.getNewDeselectedRows()
print ev!.getSelectedRows().size()," ROW(S) NOW SELECTED : ", ev!.getSelectedRows()
print "------------------------------------------------------------------------"
fi
fi
return
onDoubleCLick:
? 'BR',"DOUBLE CLICK:"
gosub onSelection
? 'ER',
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