ctkTreeView - View Perl-structures using Perl/Tk widgets

Syntax

        my $view = ctkTreeView->new(<arguments>);
        $view->addButtons(<buttons arguments>);
        $view->setSeparator(<separator char>);
        $view->tree->configure(<option>);
        $view->showDataTree(<ref to data structure>, <title>, <name of root>);

Applying ctkTreeView

Why ctkTreeView?

        - use ctkTreeView as data explorer
        - investigate data structures using callbacks
        - use ctkTreeView as base class for application specific viewer

Data representation

        - nodes:
                HASH element : <key value>
                ARRAY element :
                        scalar : [<index value>] ='<value>'
                        hash : HASH [<index value>]
                        array : ARRAY [index value>]
                ref to SCALAR : '<dereferenced value>'
        - leafs:
                scalar value : '<value>'
                empty value : ''
                undef : UNDEF
                unsupported objects : ref(<object>) UNKNOWN

Node's identification

        Hash element : key
        array element : index value
        Example : $t= {x => [qw/E0 E2/]}
                        /
                        /x
                        /x/0/E0
                        /x/1/E2

Customizing ctkTreeView

Some basics

        constructor : allocate widgets and data members
                method new
                method _init
                        add default buttons
        showDataTree
                pack all components into toplevel
                add itemstyples
                call lastInit callback
                send autosetmode to the Tree widget
        onOK or onCancel callbacks
                terminate the widget
                callbacks return true to instruct the instance to terminate and
                        false to continue
        userdata
                Store user's data into data member.
                Class code do never modify the content of this data member.
        Pls remember: The toplevel works as a non-modal widget. Therefore many
        instances of ctkTreeView may coexists at the same time!

Customization parameters

        ctkTreeView allows a wide palette of customization parameter:
                - set separator values
                - define buttons for actions (navigation)
                - modify itemStyles
                - set widget options using callback lastInit
        Thereby the provided accessor should be used.
        Basically ctkTreeView may be adapted at any time like a usual
        widget.
        Though there are a few contraints:
                - non modal mode
                - structure of the toplevel
                - buttons
                - limited set of itemStyles
                - itemtypes (text/imageText)
                - handling of special cases (undef)
                - no data editing
                - no public data element
                - no support for class instances which do not base on HASH

Writing derived classes

        It is reasonnable to write a derived class only when the
        customization don't allow to fulfill the requirements.
        - constructor
                - call SUPER::new
        - overload _init method (new widgets)
                - first call SUPER::_init()
                - do the specialized ini process
        - overload showDataTree (pack new widgets)
                - call SUPER::showDataTree to pack standard widgets
                - do the specialized process
        - write new navigation methods (i.e. goto specific node)
                - use the standard methods to perform stadard function
                - add application dependent functionalities
        - add new data members
        - overload method findItem
        - do not overload properties or accessors
        - do not overload xadd method
        - do not use class variables to control process flow, use
          property userdata instead.

save data using property userdata

        Example: user saved the selection. At OK - time this
                selection should still be active.
        my $view = ctkTreeView->new(...);
        $view->tree->configure(-command => sub {
                ## do some useable stuff
                $view->userdata($self->info('selection')); ## save selection
                } );
        $view->showDataTree(...);
        sub onK {
                my $self = shift;
                my $s = $self->userdata;
                return 0 if ($s ne $self->tree->info('selection'));     ## cannot terminate
                return 1;       ## terminate widget
        }

Programming Notes

        This class is not a composite widget.
        While debug mode is on it print trace-entries into STDERR.
        ctkTreeView supports object classes of type ARRAY, HASH, SCALAR, CODE.
        Instances of other kind are supported when they can be accessed as HASH
        and their names match /[A-Za-z0-9_\-]+/ .

Maintenance

        Author : Marco
        Date   : 09.06.2005
        History
        09.06.2005 First draft
        28.02.2006 MO02501
        06.09.2006 version 1.03

new

        Constructor
Arguments
        hwnd     parent widget (mandatory)
        debug    debug mode on/off 1 or 0
        buttons  ref to array of hashes containing buttons definitions.
        onOK     callback for 'OK' - button
        onCancel callback for 'Cancel' - button
        autosetmode call autosetmode (0/1)
Returns
        Always true.
Notes
        It clears the class variables,
        calls _init to initiate widgets.

destroy

        Destructor
Arguments
        None.
Returns
        Always true.
Notes
        It clears the class variables!!!

_init

        Initialize widgets( allocates toplevel, frames, default buttons).
Arguments
        Arguments passed by constructor
        buttons  ref to array of button's argument list
Returns
        Always true.
Notes
        Widgets are not packed into toplevel.

_addDefaultButtons

        Stack default button definition into data member stack buttons.
Arguments
        None.
Returns
        Always true.
Notes
        At least OK button must be defined.

Properties

        hwnd        parent widget
        debug       0/1 debug mode on / off
        tree        ref to widget of class Tree
        path        path of current node (selection)
        toplevel    ref to topLevel widget
        frame1      frame for tree widget
        frame2      frame for buttons
        label       Label widget
        itemStyle   HASH of all defined node styles (instances of class itemStyle)
        buttons     stack of defined buttons (ref to widget)
        separator   level separator

showDataTree

descrition
Arguments
Returns
Notes

xadd

Add an element to the tree
Arguments
Returns
Notes

showAllChildren

Open all children of selected (or given) node
        - get path if none was given by caller
        - show the node
        - set indicator to 'minus'
        - issue recursion to process children
Arguments
Returns
Notes

showNextLevel

Arguments
Returns
Notes

openNextlevel

descrition
Arguments
Returns
Notes

closeAll

Close all nodes starting at root
Arguments
        None.
Returns
        Always 1.
=item Notes
        None.

openAll

Open all nodes starting at root.
Arguments
        None.
Returns
        Always 1.
Notes
        None.
=back

openAllChildren

Open all children of given (or selected) node
Arguments
        Path to node to be open (optional, default selected node).
Returns
Notes
        If no path is geiven and no node is selected then
        no action is done.

closeAllChildren

Close all children of given (or selected) node.
Arguments
        Path to node to be closed (default selected node).
Returns
        Always 1.
=item Notes
        If no path is given and no node is selected then
        no action is done.

closeSelected

The selected node is closed
Arguments
        None.
Returns
Notes
        If no path is given and no node is selected then
        no action is done.

hideAll

Hide all children of the given (or selected) node.
Arguments
        Path to the node to be hidden.
Returns
        Always 1.
Notes
        Do not use this method!

findItem

Search the tree for nodes having entered strig in its name.
        - Open a dialog to enter search string.
        - traverse 'in order' level 0 and 1 to search for the given substring
        - select found item if any has been found.
Arguments
        None.
Returns
        Always 1.
Notes
        Actually this method searches only level 0 and 1 for
        the entered substring.

Back to index