J6/Treeview/Class

From J Wiki
Jump to: navigation, search

Treeview/Navigator

The code that paints the treeview is in class jtreeview..

Load the treeview by loading the class, for example:

load 'jtreeview'

A treeview is drawn in an isigraph control on a J form. The verb that creates the form should also create an instance of the treeview class, and set values in the instance to define the treeview. The noun NODE a list of node names, and LEVEL a corresponding list of node levels. Other values are set to defaults if not given.

Most events for the isigraph control should be passed to the grid instance for execution, see Events.

The verb show shows the treeview, or refreshes the treeview if it is already displayed. The argument specifies treeviewoptions, either as:

  • a character string of names that can be read from the form locale.
  • a 2 column boxed matrix of names and corresponding values.

Options are listed in Options. Option names are always uppercase in treeview, and are converted if necessary.

The following example is the treeview demo in the system:

load 'jtreeview'
coclass 'jtvdemo'

j=. <;._2 (0 : 0)
0 node 0
1 node 00
2 node 000
2 node 001
2 node 002
0 node 1
1 node 10
1 node 11
0 node 2
1 node 20
1 node 21
2 node 210
2 node 211
2 node 212
2 node 213
3 node 2130
3 node 2131
1 node 22
2 node 220
1 node 23
0 node 3
1 node 30
2 node 300
1 node 31
1 node 32
2 node 320
2 node 321
2 node 322
2 node 323
0 node 4
)

LEVEL=: 0 ". 2 {.&> j
NODE=: 2 }.each j

NB. =========================================================
DEMO=: 0 : 0
pc demo;pn "Treeview Demo";
xywh 4 4 120 160;cc tv isigraph rightmove bottommove;
xywh 130 4 90 45;cc text editm leftmove rightmove;
xywh 142 59 70 12;cc showicon checkbox leftmove rightmove;cn "Icons";
xywh 142 72 70 12;cc showline checkbox leftmove rightmove;cn "Lines";
xywh 142 85 70 12;cc showcbs checkbox leftmove rightmove;cn "Checkboxes";
xywh 142 98 70 12;cc showrow checkbox leftmove rightmove;cn "Select Row";
xywh 142 116 70 13;cc expandall button leftmove rightmove;cn "Expand All";
xywh 142 132 70 13;cc collapseall button leftmove rightmove;cn "Collapse All";
xywh 142 152 70 12;cc showsrc button leftmove rightmove;cn "Show Source";
pas 4 4;pcenter;
rem form end;
)

NB. =========================================================
demo_run=: 3 : 0
wd DEMO
wd 'pcenter'
wdfit ''
formhwnd=: wd'qhwndp'
tv=: '' conew 'jtreeview'
wd 'set showcbs 0'
wd 'set showicon 1'
wd 'set showline 1'
wd 'set showrow 0'
show__tv 'LEVEL NODE'
wd 'pshow;'
)

NB. =========================================================
demo_expandall_button=: 3 : 0
MASK__tv=: 1
show__tv''
tv_showselect''
)

NB. =========================================================
demo_collapseall_button=: 3 : 0
MASK__tv=: 0
show__tv''
tv_showselect''
)

NB. =========================================================
demo_showcbs_button=: 3 : 0
TYPE__tv=: 100*0=TYPE__tv
show__tv''
tv_showselect''
)

NB. =========================================================
demo_showicon_button=: 3 : 0
SHOWICONS__tv=: -.SHOWICONS__tv
show__tv''
)

NB. =========================================================
demo_showline_button=: 3 : 0
SHOWLINES__tv=: -.SHOWLINES__tv
show__tv''
)

NB. =========================================================
demo_showrow_button=: 3 : 0
SELECTALLROW__tv=: -.SELECTALLROW__tv
show__tv''
)

NB. =========================================================
demo_showsrc_button=: 3 : 0
fview jpath '~system/examples/demo/tvdemo.ijs'
)

NB. =========================================================
demo_close=: 3 : 0
destroy__tv''
wd 'pclose'
)

NB. =========================================================
tv_tvhandler=: 3 : 0
select. y
case. 'select' do.
  tv_showselect''
end.
1
)

NB. =========================================================
tv_showselect=: 3 : 0
ndx=. SELECT__tv
txt=. 'row ',":ndx
txt=. txt,LF,'level ',":ndx{LEVEL__tv
txt=. txt,LF,ndx pick NODE__tv
txt=. txt,LF,'unchecked' }.~ 2 * ndx{VALUE__tv
wd 'set text *',txt
)

demo_run''