Not sure this will wrap correctly either.
NB.
----------------------------------------------------------------------------
NB. Test program - Edit a simple table
NB.
----------------------------------------------------------------------------
require 'jzgrid'
coclass 'testform2'
WINDOW=: 0 : 0
pc window;
xywh 160 5 45 12;cc add button leftmove rightmove;cn "Add Entry";
xywh 160 25 45 12;cc ok button leftmove rightmove;cn "OK";
xywh 160 40 45 12;cc cancel button leftmove rightmove;cn "Cancel";
xywh 5 5 150 160;cc grid isigraph rightmove bottommove;
pas 5 5;pcenter;
rem form end;
)
NB.
----------------------------------------------------------------------------
NB. create - Create the object and initialize fields
NB.
NB. y = Table to be edited
NB.
----------------------------------------------------------------------------
create =: 3 : 0
original_data =: current_data =: y
display_cols =: i. {: $ y
HDRCOL =: (8!:0) display_cols
wd WINDOW
wd 'pshow;'
grid =: '' conew 'jzgrid'
set_headers 'Category';'Name';'Distance'
show_data ''
)
NB.
----------------------------------------------------------------------------
NB. destroy - Destroy the object
NB.
----------------------------------------------------------------------------
destroy =: 3 : 0
destroy__grid ''
codestroy ''
)
NB.
----------------------------------------------------------------------------
NB. select_columns - Choose which columns to display
NB.
NB. y = List of column indices
NB.
----------------------------------------------------------------------------
select_columns =: 3 : 0
display_cols =: y
)
NB.
----------------------------------------------------------------------------
NB. set_headers - Set the column headers
NB.
NB. y = List of boxed header strings, one for each column to be displayed
NB.
----------------------------------------------------------------------------
set_headers =: 3 : 0
HDRCOL =: y
)
NB.
----------------------------------------------------------------------------
NB. show_data - Display the table
NB.
----------------------------------------------------------------------------
show_data =: 3 : 0
CELLDATA =: display_cols {"1 current_data
HDRROW =: (# CELLDATA) # <'Delete'
show__grid 'CELLDATA HDRCOL HDRROW'
)
NB.
----------------------------------------------------------------------------
NB. grid_gridhandler - Handle Delete key clicks
NB.
----------------------------------------------------------------------------
grid_gridhandler =: 3 : 0
NB. --- A click on a row header ("Delete" button) deletes that row
if. (y -: 'click') *. (Col__grid < 0) *. Row__grid >: 0 do.
current_data =: (Row__grid ~: i. # current_data) # current_data
show_data ''
0
else.
1
end.
)
window_close =: 3 : 0
smoutput current_data
editing =: 0
wd 'pclose'
destroy__grid ''
)
window_add_button =: 3 : 0
wd 'mb "Incomplete" "Apply <enter new table row> GUI here"
mb_iconinformation;'
)
window_cancel_button =: 3 : 0
current_data =: original_data
window_close ''
)
window_ok_button =: 3 : 0
NB. ... update current_data with edited CELLDATA cells ...
window_close ''
)
NB.
============================================================================
test_base_ =: 3 : 0
testdata =: 4 3 $ 'Asteroid';'1
Ceres';2.77;'Comet';'P/Halley';17.8;'Planet';'Mars';1.33;'Star';'Antares';600
gui =. testdata conew 'testform2'
)
NB. ----------------------------------------------------------------------
sab, 26 Dec 2009, McGuinness, Brian skribis:
> I want to create a class that will let me
> create an object of that class, call some
> methods to set options, and then call an
> editor method to that displays a GUI, lets
> the user edit a table using the grid, and then
> returns the edited data. In all my attempts
> so far, the editor returns right away and
> doesn't wait for the user to exit the GUI
> with the Ok or Cancel button. SO far I have
> this (I don't now how it will wrap in this email
> system):
>
> NB.
> ----------------------------------------------------------------------------
> NB. Test program - Edit a simple table
> NB.
> ----------------------------------------------------------------------------
> require 'jzgrid'
> coclass 'testform2'
>
> WINDOW=: 0 : 0
> pc window;
> xywh 160 5 45 12;cc add button leftmove rightmove;cn
> "Add Entry";
> xywh 160 25 45 12;cc ok button leftmove rightmove;cn
> "OK";
> xywh 160 40 45 12;cc cancel button leftmove rightmove;cn
> "Cancel";
> xywh 5 5 150 160;cc grid isigraph rightmove bottommove;
> pas 5 5;pcenter;
> rem form end;
> )
>
> NB.
> ----------------------------------------------------------------------------
> NB. create - Create the object and initialize fields
> NB.
> NB. y = Table to be edited
> NB.
> ----------------------------------------------------------------------------
> create =: 3 : 0
> original_data =: current_data =: y
> display_cols =: i. {: $ y
> HDRCOL =: (8!:0) display_cols
> )
>
> NB.
> ----------------------------------------------------------------------------
> NB. edit - Display the table, let the user edit it, and
> return the results
> NB.
> ----------------------------------------------------------------------------
> edit =: 3 : 0
> editing =: 1
> wd WINDOW
> grid =: '' conew 'jzgrid'
> show_data ''
> NB. ... next line doesn't wait until the GUI is exited
> ...
> wd 'pshow; wait;'
> NB. ... this loop doesn't work; it locks up the GUI ...
> while. editing do.
> (6!:3) 1
> wd 'msgs ;'
> end.
> current_data
> )
>
> NB.
> ----------------------------------------------------------------------------
> NB. destroy - Destroy the object
> NB.
> ----------------------------------------------------------------------------
> destroy =: 3 : 0
> destroy__grid ''
> codestroy ''
> )
>
> NB.
> ----------------------------------------------------------------------------
> NB. select_columns - Choose which columns to display
> NB.
> NB. y = List of column indices
> NB.
> ----------------------------------------------------------------------------
> select_columns =: 3 : 0
> display_cols =: y
> )
>
> NB.
> ----------------------------------------------------------------------------
> NB. set_headers - Set the column headers
> NB.
> NB. y = List of boxed header strings, one for each column
> to be displayed
> NB.
> ----------------------------------------------------------------------------
> set_headers =: 3 : 0
> HDRCOL =: y
> )
>
> NB.
> ----------------------------------------------------------------------------
> NB. show_data - Display the table
> NB.
> ----------------------------------------------------------------------------
> show_data =: 3 : 0
> CELLDATA =: display_cols {"1 current_data
> HDRROW =: (# CELLDATA) # <'Delete'
> show__grid 'CELLDATA HDRCOL HDRROW'
> )
>
> NB.
> ----------------------------------------------------------------------------
> NB. grid_gridhandler - Handle Delete key clicks
> NB.
> ----------------------------------------------------------------------------
> grid_gridhandler =: 3 : 0
> NB. --- A click on a row header ("Delete" button)
> deletes that row
> if. (y -: 'click') *. (Col__grid < 0) *. Row__grid >: 0
> do.
> current_data =: (Row__grid ~: i. # current_data) #
> current_data
> show_data ''
> 0
> else.
> 1
> end.
> )
>
> window_close =: 3 : 0
> editing =: 0
> wd 'pclose'
> destroy__grid ''
> )
>
> window_add_button =: 3 : 0
> wd 'mb "Incomplete" "Apply <enter new table row> GUI
> here" mb_iconinformation;'
> )
>
> window_cancel_button =: 3 : 0
> current_data =: original_data
> window_close ''
> )
>
> window_ok_button =: 3 : 0
> NB. ... update current_data with edited CELLDATA cells
> ...
> window_close ''
> )
>
> NB.
> ============================================================================
>
> test_base_ =: 3 : 0
> testdata =: 4 3 $ 'Asteroid';'1
> Ceres';2.77;'Comet';'P/Halley';17.8;'Planet';'Mars';1.33;'Star';'Antares';600
> gui =. testdata conew 'testform2'
> set_headers__gui 'Category';'Name';'Distance'
> data_base_ =: edit__gui ''
> gui__destroy ''
> )
--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm