NAME
Tk::DBI::Tree - Megawidget to display a table column in a tree.
SYNOPSIS
use Tk;
use Tk::DBI::Tree;
my $top = MainWindow->new;
my $tkdbi = $top->DBITree(
-dbh => $dbh,
-table => 'Inventory',
-textcolumn => 'name',
-idx => 'id',
-columnWidths => [undef, undef, undef, 150],
-fields => [qw(changed_by changed_at descr)],
-parent_id => 'parent_id',
-start_id => 1,
-maxchars => { descr => 25 },
)->pack(-expand => 1,
-fill => 'both');
MainLoop;
DESCRIPTION
This is a megawidget to display a sql statement from your database in a tree view widget. When you've got one of those nasty self-referential tables that you want to bust out into a tree, this is the module to check out.
WIDGET-SPECIFIC OPTIONS
-dbh => $ref_on_database_handle
A database handle, this will return an error if it is'nt defined.
-debug => [0|1]
This is a switch to turn on debug output to the standard console (STDOUT)
-table => 'tablename'
The table to display.
-idx => 'index_column'
The index column from the table.
-fields => [col0, col1, col2, ...]
List of additional fields to display.
-colNames => [col0, col1, col2, ...]
List of alternative names for every column. This will display on header.
-where => 'WHERE foo == 1, ...'
Additional where statement for choice rows in table.
-textcolumn => colname
The name of the column to be displayed in the tree..
-start_id => integer
The id, where the widget will start to create the tree. Default is 1.
-columnWidths => [colWidth_0, colWidth_1, colWidth_2, ...]
Default field column width.
-command => sub{ ... }
Callback on TreeWidget at browsing.
-entry_create_cb => sub{ ... }
Callback if a entry created. The routine have 2 parameters:
i.e;
-entry_create_cb => sub{
my($w, $path, $row) = @_;
if(exists $DOC->{ $row->{id} } and exists $EVENT->{ $row->{id} } ) {
$w->entryconfigure($path, -image => $pics{'icon_document_event'});
}
},
-highlight => [-foreground = 'blue']>
Style for founded Entries.
-normal => [-foreground = 'black']>
Default style for Entries.
-maxchars => number or {col1 =number}
Maximum number of characters to be displayed within the cells. Global validity or set only for named columns. I.E.:
-maxchars => {
descr => 25,
name => 10,
},
# or ....
-maxchars => 25, # global for all fields
METHODS
These are the methods you can use with this Widget.
$DBITree->refresh('reload');
Refresh the tree. if you call this method with the parameter reload then this will reload the table from database.
$DBITree->close_all;
close all tree branches.
$DBITree->info('anchor, bbox, children, data, dragsite, dropsite ...', $id);
This is a wrapper to the HList Method ->info. The default method is info('data', ...). Please read the manual from Tk::HList.
$DBITree->ListEntrys;
This returnd a sorted ref array with all entrys in the tree.
$DBITree->select_entrys([en1, en2, en3, ...]);
This returns a sorted ref array with all selected entries in the tree or you can set an array of selected entries. Also you can use only the id's, i.e.:
$dbitree->select_entrys(qw/1:2 1:3 1:4/);
# or ...
$dbitree->select_entrys(qw/2 3 4/);
These is friendly if you use i.e. a statement 'select id from table where foo == bla' and you have only the id's without the pathinformation. Tk::DBI::Tree know, select only the entries have at last position this id in path.
$DBITree->zoom;
Shrink or unshrink tree to display only founded entries.
$DBITree->infozoom;
Returnd true if zoom active.
$DBITree->color_all([style]);
Set all entries to normal style without parameters. You can put a new Style to all entries.
i.e:
$DBITree->color_all([-background => 'gray50']);
$DBITree->get_id;
select the row under mouseposition and returnd following parameters.
- path - The path from the entry under mouseposition.
- col - Column name under mouseposition.
- path - Column number under mouseposition.
- value - Cell value under mouseposition.
$DBITree->remember( $hash );
This method is very useful, when you want to remember the last tree status and column widths for the resize button. This returns a ref hash with following keys, if this call is done without parameters.
- widths - a ref array including the width of each column.
- stats - a ref hash with status information(open close none) for each entry.
You can give an old Hash (may eval-load at program start) and the tree remembers this status.
I.E.:
$tree->rembember( $tree->rembember );
# or ...
$tree->remember( {
status => {
'0:1' ='open',
'0:1:2' ='close',
...
},
widths =[165, 24, 546],
} );
ADVERTISED WIDGETS
'tree' => Tree-Widget
This is a normal Tree widget. I.e.:
$DBITree->Subwidget('tree')->configure(
-background => 'gray50',
};
'HB_<column name>' => ResizeButton-Widget
This is a (Resize)Button widget.
CHANGES
$Log: Tree.pm,v $
Revision 1.4 2003/05/11 16:33:47 xpix
* new option -colNames
* new option -entry_create_cb
* new option -higlight
* new option -normal
* new method info
* new method infozoom
* new method color_all
* new method get_id
! much bugfixes
* better select_entrys (without pathinformation)
Revision 1.3 2003/05/05 16:02:06 xpix
* correct the documentation and write a little more ;-)
Revision 1.2 2003/05/04 23:38:25 xpix
! bug in make_tree_list
Revision 1.1 2003/05/04 20:52:13 xpix
* New Widget for display a table in a tree
AUTHOR
Copyright (C) 2003 , Frank (xpix) Herrmann. All rights reserved.
http://www.xpix.de
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
KEYWORDS
Tk::DBI::*, Tk::ResizeButton, Tk::Tree, DBIx::Tree
__END__