Skip to content

Commit

Permalink
introducing a separate attributes record that allows reuse of the set…
Browse files Browse the repository at this point in the history
…ting upon refresh of the data
  • Loading branch information
Stephan Wald committed Apr 4, 2018
1 parent d98cc0f commit e9998e7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 26 deletions.
15 changes: 15 additions & 0 deletions BBjGridExWidget.bbj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class public BBjGridExWidget extends BBjWidget
field private BBjString RowNodeId$
field private BBjString ParentNodeId$
field private DataRow ColumnDefinition!
field public DataRow AttributesRecord!
field private BBjNumber Editing! = 0
rem /**
rem * disabled default constructor
Expand Down Expand Up @@ -317,6 +318,20 @@ class public BBjGridExWidget extends BBjWidget
rem */
method public void setData( ResultSet rs!)
#RS! = rs!

if #AttributesRecord! <> NULL() then
rem TODO: use the new method of components as soon as implemented
rem https://github.com/BasisHub/components/issues/87
r1! = rs!.getItem(0)
ar! = #AttributesRecord!

it! = r1!.getFieldNames().iterator()
while it!.hasNext()
f$ = it!.next()
r1!.setFieldAttributes(f$,ar!.getFieldAttributes(f$))
wend
fi

#TREE! = null()
#URL$=""
#performGridDataUpdate()
Expand Down
71 changes: 45 additions & 26 deletions Demo/DatatypesDemo.bbj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ grid!.setEnableFloatingFilter(1)
wnd! .setCallback(BBjAPI.ON_CLOSE,"byebye")
wnd! .setCallback(BBjAPI.ON_RESIZE,"resize")

gosub prepareGrid
gosub fillGrid

process_events
Expand All @@ -38,44 +39,21 @@ fillGrid:
for j=1 to 2

dr! = new DataRow()
dr!.setFieldValue("ID",java.sql.Types.VARCHAR, "ID_" + STR(i))
dr!.setFieldValue("INTEGER",java.sql.Types.INTEGER,i)
dr!.setFieldValue("ICON",java.sql.Types.VARCHAR, "ID_" + STR(i))
dr!.setFieldValue("DOUBLE",java.sql.Types.DOUBLE,x)
dr!.setFieldValue("BOOLEAN 1",java.sql.Types.BOOLEAN,MOD(i,3)=0)
dr!.setFieldValue("BOOLEAN 2",java.sql.Types.BOOLEAN,MOD(i,3)=0)
dr!.setFieldValue("DATE",java.sql.Types.DATE,"1979-08-03")
dr!.setFieldValue("TIMESTAMP",java.sql.Types.TIMESTAMP,"2018-01-02 12:22:13")

if i=1 then
dr!.setFieldAttribute("DOUBLE","RENDERER_MASK","-### ##0.0000")

dr!.setFieldAttribute("BOOLEAN 1","RENDERER_TRUE","&#x2714;")
dr!.setFieldAttribute("BOOLEAN 1","RENDERER_FALSE","&#x2718;")

dr!.setFieldAttribute("BOOLEAN 2","RENDERER_TRUE","switch")
dr!.setFieldAttribute("BOOLEAN 2","RENDERER_FALSE","switch")

dr!.setFieldAttribute("DATE","RENDERER_MASK","%Dz.%Mz.%Yl")
dr!.setFieldAttribute("TIMESTAMP","RENDERER_MASK","%Dz.%Mz.%Yl %Hz:%mz:%sz")

list! = new JsonObject()
list!.addProperty("ID_1","http://www.nodeclipse.org/img/logos/Node-JS-logo.png")
list!.addProperty("ID_3","http://www.nodeclipse.org/img/logos/Node-JS-logo.png")
list!.addProperty("ID_2","https://jsdotgit.com/js-small.gif")
list!.addProperty("ID_4","https://jsdotgit.com/js-small.gif")

dr!.setFieldAttribute("ID","TYPE",grid!.GRID_TYPE_BASIC_IMAGE_FILTERABLE())
dr!.setFieldAttribute("ID","IMAGES_LIST",list!.toString())
fi

rs!.addItem(dr!)

i=i+1
x=x*-i

dr! = new DataRow()
dr!.setFieldValue("ID",java.sql.Types.VARCHAR, "ID_" + STR(i))
dr!.setFieldValue("INTEGER",java.sql.Types.INTEGER,i)
dr!.setFieldValue("ICON",java.sql.Types.VARCHAR, "ID_" + STR(i))
dr!.setFieldValue("DOUBLE",java.sql.Types.DOUBLE,x)
dr!.setFieldValue("BOOLEAN 1",java.sql.Types.BOOLEAN,MOD(i,3)=0)
dr!.setFieldValue("BOOLEAN 2",java.sql.Types.BOOLEAN,MOD(i,3)=0)
Expand All @@ -88,16 +66,57 @@ fillGrid:
x=x*-i

next


rem a row with most columns empty
dr! = new DataRow()
dr!.setFieldValue("STRING","ROW NUMBER "+str(i))
rs!.addItem(dr!)

grid!.setData(rs!)

return

prepareGrid:

rem build the attributes record that describes meta data for the result set
rem using the separate method setAttributesRecord to avoid setting this things over and over again for each refresh of the data

ar! = new DataRow()
ar!.setFieldValue("INTEGER",java.sql.Types.INTEGER,i)
ar!.setFieldValue("ICON",java.sql.Types.VARCHAR, "ID_" + STR(i))
ar!.setFieldValue("DOUBLE",java.sql.Types.DOUBLE,x)
ar!.setFieldValue("BOOLEAN 1",java.sql.Types.BOOLEAN,MOD(i,3)=0)
ar!.setFieldValue("BOOLEAN 2",java.sql.Types.BOOLEAN,MOD(i,3)=0)
ar!.setFieldValue("DATE",java.sql.Types.DATE,"2013-02-01")
ar!.setFieldValue("TIMESTAMP",java.sql.Types.TIMESTAMP,"2016-11-12 23:22:00")

ar!.setFieldAttribute("DOUBLE","RENDERER_MASK","-### ##0.0000")
ar!.setFieldAttribute("DOUBLE","LABEL","A Double Value")

REM this is also the default:
ar!.setFieldAttribute("BOOLEAN 1","RENDERER_TRUE","&#x2714;")
ar!.setFieldAttribute("BOOLEAN 1","RENDERER_FALSE","&#x2718;")

ar!.setFieldAttribute("BOOLEAN 2","RENDERER_TRUE","switch")
ar!.setFieldAttribute("BOOLEAN 2","RENDERER_FALSE","switch")

ar!.setFieldAttribute("DATE","RENDERER_MASK","%Dz.%Mz.%Yl")
ar!.setFieldAttribute("TIMESTAMP","RENDERER_MASK","%Dz.%Mz.%Yl %Hz:%mz:%sz")

list! = new JsonObject()
list!.addProperty("ID_1","https://raw.githubusercontent.com/google/material-design-icons/master/notification/1x_web/ic_airline_seat_individual_suite_black_36dp.png")
list!.addProperty("ID_2","https://raw.githubusercontent.com/google/material-design-icons/master/notification/1x_web/ic_confirmation_number_black_36dp.png")
list!.addProperty("ID_3","https://raw.githubusercontent.com/google/material-design-icons/master/notification/1x_web/ic_drive_eta_black_36dp.png")
list!.addProperty("ID_4","https://raw.githubusercontent.com/google/material-design-icons/master/notification/1x_web/ic_adb_black_36dp.png")

ar!.setFieldAttribute("ICON","TYPE",grid!.GRID_TYPE_BASIC_IMAGE_FILTERABLE())
ar!.setFieldAttribute("ICON","IMAGES_LIST",list!.toString())

grid!.setAttributesRecord(ar!)

return

byebye:
bye

Expand Down

0 comments on commit e9998e7

Please sign in to comment.