-
Notifications
You must be signed in to change notification settings - Fork 7
/
CellsConditionalStylingDemo.bbj
98 lines (84 loc) · 3.45 KB
/
CellsConditionalStylingDemo.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
rem /**
rem * This file is part of the BBjGridExWidget plugin.
rem * (c) Basis Europe <eu@basis.com>
rem *
rem * For the full copyright and license information, please view the LICENSE
rem * file that was distributed with this source code.
rem */
use ::BBjGridExWidget/BBjGridExWidget.bbj::BBjGridExWidget
use com.basiscomponents.db.ResultSet
use com.basiscomponents.bc.SqlQueryBC
use com.google.gson.JsonObject
? 'HIDE'
declare auto BBjTopLevelWindow wnd!
declare BBjGridExWidget grid!
wnd! = BBjAPI().openSysGui("X0").addWindow(10,10,1100,600,"Cells Conditional Styling Demo")
wnd!.setCallback(BBjAPI.ON_CLOSE,"byebye")
wnd!.setCallback(BBjAPI.ON_RESIZE,"resize")
REM init the grid
grid! = new BBjGridExWidget(wnd!,100,0,0,1100,600)
gosub main
process_events
rem /**
rem * Retrive the data from the database and configure the grid.
rem *
rem * The demo shows how to achieve cell condition styling using cell class rules.
rem * Ever column has its own cell class rules (JsonObject) every entry in the rules
rem * composes of a RuleNme/Selector (key) and a condition (value).
rem *
rem * The (RuleNme/Selector) is used later to pickup any style object bounded to the same (RuleNme/Selector)
rem * The condition should return true or false , when true the style is applied , ignored otherwise
rem *
rem * Inside the condition you can use serveral predefined params, some of these params are :
rem *
rem * 1. x => maps value
rem * 2. ctx => maps the grid context
rem * 3. data => maps the current data row
rem * 4. rowIndex => maps the current row index
rem */
main:
declare SqlQueryBC sbc!
declare ResultSet rs!
sbc! = new SqlQueryBC(BBjAPI().getJDBCConnection("CDStore"))
rs! = sbc!.retrieve("SELECT CDNUMBER , ARTIST, PLAYINGTIME, TITLE, MUSICTYPE , LABEL FROM CDINVENTORY")
grid!.addColumn("CDNUMBER","Item#")
grid!.addColumn("ARTIST","Artist Name")
grid!.addColumn("PLAYINGTIME","Playing Time (min)")
grid!.addColumn("TITLE","Record Title")
grid!.addColumn("MUSICTYPE","Genre")
grid!.addColumn("LABEL","Publisher")
grid!.setColumnBackColor("CDNUMBER",BBjAPI().makeColor("LTGRAY"))
grid!.setColumnForeColor("CDNUMBER",BBjAPI().makeColor("BLUE"))
grid!.pinColumn("CDNUMBER","left")
grid!.setColumnWidth("CDNUMBER",120)
grid!.setColumnAlignment("CDNUMBER",grid!.GRID_ALIGN_CENTER())
generRules! = new JsonObject()
generRules!.addProperty("gener-rock","x == 'Rock' || x== 'Classical Rock' || x=='Hard Rock'")
grid!.getColumn("MUSICTYPE").setCellClassRules(generRules!)
grid!.addStyle("gener-rock" , "{""background"": ""#aaaaff""}")
timesRules! = new JsonObject()
timesRules!.addProperty("time-normal","x >= 10 && x <= 50")
timesRules!.addProperty("time-long","x >= 50 && x <= 70")
timesRules!.addProperty("time-tooLong","x > 70")
grid!.getColumn("PLAYINGTIME").setCellClassRules(timesRules!)
grid!.addStyle("time-normal" , "{""background"": ""lightgreen""}")
grid!.addStyle("time-long" , "{""background"": ""lightsalmon""}")
grid!.addStyle("time-tooLong" , "{""background"": ""lightcoral""}")
rem The second parameter tells the grid to index the rows using the CDNUMBER column
grid!.setData(rs!,"CDNUMBER")
return
rem /**
rem * Listen to the BBjTopLevelWindow resize events and
rem * resize the grid to fill the available space.
rem */
resize:
ev! = BBjAPI().getLastEvent()
w=ev!.getWidth()
h=ev!.getHeight()
grid!.setSize(w,h)
return
rem /**
rem * Close the demo
rem */
byebye:
bye