NAME

Tk::DBIx::Tree - Megawidget to display a table column in a tree.

SYNOPSIS

  use Tk;
  use Tk::DBIx::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.

-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

-time_column => $name_from_time_column

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. If you call this without parameter, then look this widget is the table changed (update date) at the last refresh. If this true, then load this the complete table and redraw the tree.

$DBITree->refresh_id( entry, data );

This will refresh (delete -> new) a Tree item.

$DBITree->copy( entry, to_parent_entry, data );

Copy an entry (entry) to a parent branch (to_parent_entry) with data (data);

$DBITree->move( entry, to_parent_entry, data );

Move an entry (from_entry) to a parent branch (to_parent_entry) with data (data);

$DBITree->dele( entry );

Delete a entry.

$DBITree->neu( entry, to_parent_entry, data );

Create a entry.

$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->id2path(id);

This returns the path for given id.

$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::DBIx::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_clear([qw/1 2 3/], [-background => 'gray50']);

$DBITree->color_clear([entrys], style);

Remove all higlighted styles from the functions see and select_entrys. if you don't give entrys, tree take the internal foundentrys. if you don't give style, tree take the normal style.

i.e:

$DBITree->color_clear([-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->childs($item);

Return an array with paths from childs for $item, include $item.

$DBITree->parent_id($path);

Return the actually id from the parentree (only the integer id, not the hole path)

$DBITree->see($id);

Jump to id (only database id)

$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],
  } );

CALLBACKS

-command => sub{ ... }

Callback on TreeWidget at browsing.

-entry_create_cb => sub{ ... }

Callback if an entry created. The routine have 2 parameters:

entry - a ref to created entry
data - a ref hash with row information.

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'});
	}
  },

-opencmd => sub{ ... }

Callback on TreeWidget if this entry activate(from User or Automatic) to open. if this return false, then Tree doesn't refresh the tree. i.E. -opencmd => sub{ &display_prj_items( @_ ) },

-closecmd => sub{ ... }

Callback on TreeWidget if this entry activate(from User or Automatic) to close.

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.2  2003/11/06 17:55:56  xpix
! bugfixes in refresh_id
* not hudge load for tree

Revision 1.1  2003/10/24 10:46:28  xpix
* new Name for CPAN
* new Parser for tree, at ths time is possible only read a one Tree

!! new cvs name !!

Revision 1.11  2003/08/13 12:58:13  xpix
* colored debug output
* new method childs, output an array with complete paths from childs
* new methods neu, move, dele to transfering from entrys
* new option maxchars
! many, many bug fixes

Revision 1.8  2003/07/18 16:14:15  xpix
! Fehler im Table_is_Change algo, fix
! Komplett refresh bei TreeStatusaenderung
! to_parent_open macht jetzt wirklich nur die Vaeter und nicht noch den Sohn auf ;-)
! unit. value in Form.pm

Revision 1.10  2003/07/17 14:59:54  xpix
! many little bugfixes

Revision 1.3  2003/06/24 16:38:44  xpix
* add symbolic to cvs
* new loking mechanism in Form.pm

Revision 1.9  2003/06/23 16:15:22  xpix
! cvs error

Revision 1.8  2003/06/18 15:31:47  xpix
* new methods: copy, move, neu ... dele. This will work only on the Tree Widget (not in table)
* change a little bit the docu

Revision 1.7  2003/06/16 12:58:01  xpix
! No Error, if the id ot exists in selct_entrys

Revision 1.6  2003/05/23 13:47:46  xpix
! No debug if debug = 0

Revision 1.5  2003/05/20 13:51:50  xpix
* add field parent_id to data entry

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