-
Notifications
You must be signed in to change notification settings - Fork 7
/
BBjGridExWidgetClientJsonFactory.bbj
145 lines (140 loc) · 5.37 KB
/
BBjGridExWidgetClientJsonFactory.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
rem package BBjGridExWidget.Client
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 ::BBjGridExWidget/BBjGridExWidgetClientModels.bbj::BBjGridExWidgetClientRowModel
use ::BBjGridExWidget/BBjGridExWidgetClientModels.bbj::BBjGridExWidgetClientColumnModel
use ::BBjGridExWidget/BBjGridExWidgetClientModels.bbj::BBjGridExWidgetClientCellModel
use ::BBjGridExWidget/BBjGridExWidgetClientModels.bbj::BBjGridExWidgetClientRangeSelectionModel
use com.google.gson.JsonObject
use com.google.gson.JsonParser
REM /**
REM * The class will create client models from JSON
REM *
REM * @author Hyyan Abo Fakher
REM */
class public BBjGridExWidgetClientJsonFactory
rem /**
rem * BBjGridExWidget instnace
rem */
field protected BBjGridExWidget Widget!
rem /**
rem * Disable default constructor
rem */
method private BBjGridExWidgetClientJsonFactory()
methodend
rem /**
rem * Construct new BBjGridExWidgetClientJsonFactory
rem *
rem * @param BBjGridExWidget widget! The widget instnace
rem */
method public BBjGridExWidgetClientJsonFactory(BBjGridExWidget widget!)
#Widget! = widget!
methodend
rem /**
rem * Get the widget instance
rem *
rem * @return BBjGridExWidget
rem */
method public BBjGridExWidget getWidget()
methodret #Widget!
methodend
rem /**
rem * Map a JSON object to BBjGridExWidgetClientRowModel
rem *
rem * @param JsonObject json! Json object
rem *
rem * @return BBjGridExWidgetClientRowModel
rem */
method public BBjGridExWidgetClientRowModel getRow(JsonObject json!)
declare BBjGridExWidgetClientRowModel row!
row! = new BBjGridExWidgetClientRowModel(#getWidget())
row!.setId(json!.get("i").getAsString(),err=*next)
row!.setIndex(json!.get("x").getAsString(),err=*next)
row!.setChildIndex(json!.get("c").getAsInt(),err=*next)
row!.setParentKey(json!.get("p").getAsString(),err=*next)
row!.setIsSelected(iff(json!.get("s").getAsString() = "true" , 1 , 0) , err=*next)
methodret row!
methodend
rem /**
rem * Map a JSON string to BBjGridExWidgetClientRowModel
rem *
rem * @param BBjString json! json string
rem *
rem * @return BBjGridExWidgetClientRowModel
rem */
method public BBjGridExWidgetClientRowModel getRow(BBjString json!)
declare JsonParser parser!
parser! = new JsonParser()
parsedRow! = parser!.parse(json!).getAsJsonObject()
methodret #getRow(parsedRow!)
methodend
rem /**
rem * Map column name to BBjGridExWidgetClientColumnModel
rem *
rem * @param BBjString column! The column name
rem *
rem * @return BBjGridExWidgetClientColumnModel
rem */
method public BBjGridExWidgetClientColumnModel getColumn(BBjString column!)
methodret new BBjGridExWidgetClientColumnModel(#getWidget() , column!)
methodend
rem /**
rem * Map a JSON object to BBjGridExWidgetClientCellModel
rem *
rem * @param JsonObject json! Json object
rem *
rem * @return BBjGridExWidgetClientCellModel
rem */
method public BBjGridExWidgetClientCellModel getCell(JsonObject json!)
cell! = new BBjGridExWidgetClientCellModel()
cell!.setColumn(#getColumn(json!.get("c").getAsString()))
cell!.setRow(#getRow(json!.get("r").getAsJsonObject()))
cell!.setValue(json!.get("v").getAsString())
methodret cell!
methodend
rem /**
rem * Map a JSON string to BBjGridExWidgetClientCellModel
rem *
rem * @param BBjString json! Json string
rem *
rem * @return BBjGridExWidgetClientCellModel
rem */
method public BBjGridExWidgetClientCellModel getCell(BBjString json!)
declare JsonParser parser!
parser! = new JsonParser()
parsedCell! = parser!.parse(json!).getAsJsonObject()
methodret #getCell(parsedCell!)
methodend
rem /**
rem * Map a JSON object to BBjGridExWidgetClientRangeSelectionModel
rem *
rem * @param JsonObject json! Json object
rem *
rem * @return BBjGridExWidgetClientRangeSelectionModel
rem */
method public BBjGridExWidgetClientRangeSelectionModel getRangeSelection(JsonObject json!)
rem a model which describes the range object
rangeModel! = new BBjGridExWidgetClientRangeSelectionModel()
rem loop over the range columns and create a column model for each one
columns! = json!.get("c").getAsJsonArray()
columnsIterator! = columns!.iterator()
while(columnsIterator!.hasNext())
rem create a column model and add it to the range
rangeModel!.getColumns().add(#getColumn(columnsIterator!.next().getAsString()))
wend
rem loop over the range rows and create a row model for each one
rows! = json!.get("r").getAsJsonArray()
rowsIterator! = rows!.iterator()
while(rowsIterator!.hasNext())
rem create a row model and add it to the range
rangeModel!.getRows().add(#getRow(rowsIterator!.next().getAsJsonObject()))
wend
methodret rangeModel!
methodend
classend