/[cvs]/nfo/perl/libs/OEF/bin/oedit.pl
ViewVC logotype

Annotation of /nfo/perl/libs/OEF/bin/oedit.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Thu Mar 27 15:32:21 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
initial commit, moved here from elsewhere

1 joko 1.1 #!/usr/bin/perl
2    
3     ## --------------------------------------------------------------------------------
4     ## $Id: oedit.pl,v 1.10 2002/12/19 03:49:53 cvsmax Exp $
5     ## --------------------------------------------------------------------------------
6     ## $Log: oedit.pl,v $
7     ## Revision 1.10 2002/12/19 03:49:53 cvsmax
8     ## + refactored to new structure (e.g. $process->load())
9     ## o some bugs caused by that still not fixed!!
10     ##
11     ## Revision 1.9 2002/12/11 07:18:56 cvsjoko
12     ## - reversed to r1.7
13     ## - '--cli'-code goes to cli.pl
14     ##
15     ## Revision 1.7 2002/12/06 22:34:21 cvsjoko
16     ## + purged code using old object-hierarchy
17     ##
18     ## Revision 1.6 2002/12/03 15:41:28 cvsmax
19     ## + added _getClassInfo(), cause Helper::Common doesn't exists anymore
20     ##
21     ## Revision 1.5 2002/12/03 05:40:15 cvsjoko
22     ## + bugfix regarding new object hierarchy
23     ##
24     ## Revision 1.4 2002/11/28 00:39:37 cvsmax
25     ## + bugfix: changed 'saveObject' to save the object not a hash
26     ##
27     ## Revision 1.2 2002/11/17 08:43:09 cvsmax
28     ## + new boot concept
29     ##
30     ## Revision 1.1 2002/11/17 04:44:25 cvsmax
31     ## + added new Object Editor
32     ##
33     ##
34     ## --------------------------------------------------------------------------------
35    
36     use strict;
37     use warnings;
38     use locale;
39     use Locale::gettext;
40    
41     use attributes;
42     use Data::Dumper;
43     use IPC::Run qw( run timeout pump timer start finish );
44    
45    
46     #------- locales ----------
47     # Import locale-handling tool set from POSIX module.
48    
49    
50     # This example uses: setlocale -- the function call
51     # LC_CTYPE -- explained below
52     use POSIX qw(locale_h);
53    
54     # query and save the old locale
55     my $old_locale = setlocale(LC_CTYPE);
56    
57     setlocale(LC_CTYPE, "de_DE.UTF-8");
58     # LC_CTYPE now in locale "German UTF-8"
59    
60     #setlocale(LC_CTYPE, "");
61     # LC_CTYPE now reset to default defined by LC_ALL/LC_CTYPE/LANG
62     # environment variables.
63    
64     # Get some of locale's numeric formatting parameters
65     my ($thousands_sep, $grouping) = @{localeconv()}{'thousands_sep', 'grouping'};
66    
67     # Apply defaults if values are missing
68     $thousands_sep = ',' unless $thousands_sep;
69     $grouping = 3 unless $grouping;
70    
71     # Format command line params for current locale
72     for (@ARGV) {
73     $_ = int; # Chop non-integer part
74     1 while
75     s/(\d)(\d{$grouping}($|$thousands_sep))/$1$thousands_sep$2/;
76     printf "$_";
77     }
78     print "\n";
79    
80     #setlocale(LC_MESSAGES, "de_DE");
81     #textdomain("my program");
82     #print gettext("Welcome to my program"), "\n";
83     #exit;
84    
85     # dependency startup
86     BEGIN {
87     # $ENV{SUBDIR_LEVEL} = 1;
88     use FindBin;
89     use lib "$FindBin::RealBin";
90     require 'use_libs.pl';
91     }
92    
93     use BizWorks::Boot qw( $bizWorks $bizProcess );
94     #use Helper::Common;
95    
96     my $boot = BizWorks::Boot->new();
97    
98     $bizProcess->load('Core');
99     $bizProcess->load('App/Payment');
100    
101    
102     # get logger instance
103     my $logger = Log::Dispatch::Config->instance;
104    
105     use Curses;
106     use Curses::UI;
107     use Curses::UI::Window;
108     use Curses::UI::Common;
109     use vars qw(@ISA);
110     @ISA = qw(Curses::UI::Common);
111    
112    
113     # Load an initial file if an argument given on the command line.
114     # If the file can't be found, assume that this is a new file.
115     #
116     my $text = "";
117     my $currentfile = shift;
118     my $editor;
119     my $focused_win;
120     my @windows= ();
121     #my %logwin;
122     #my %textwin;
123     #my %label;
124     #my %eObject_win;
125    
126     #if (defined $currentfile and -f $currentfile)
127     #{
128     # open F, "<$currentfile" or die "Can't read $currentfile: $!\n";
129     # while (<F>) { $text .= $_ }
130     # $currentfile = $currentfile;
131     # close F;
132     #}
133    
134     # We don't want STDERR output to clutter the screen.
135     #
136     # Hint: If you need STDERR, write it out to a file and put
137     # a tail on that file to see the STDERR output. Example:
138     #open STDERR, ">>/tmp/editor_errors.$$";
139     open STDERR, ">>/tmp/gui_status";
140    
141     # ----------------------------------------------------------------------
142     # Menu definition
143     # ----------------------------------------------------------------------
144    
145     my @menu = (
146     { -label => 'Main',
147     -submenu => [
148     { -label => 'Run Command ^R', -value => \&command_dialog },
149     { -label => 'Test', -value => \&test },
150     { -label => 'Exit ^Q', -value => \&exit_dialog },
151     ]
152     },
153     { -label => 'Databases',
154     -submenu => [
155     { -label => 'Backend', -submenu => [
156     { -label => 'retreat', -value => \&retreat_backend },
157     { -label => 'deploy', -value => \&deploy_backend },
158     { -label => 'load resources', -value => \&feed_backend },
159     { -label => 'reset (All above!)', -value => \&reset_backend },
160     ],
161     },
162     ]
163     },
164     { -label => 'Objects',
165     -submenu => [
166     { -label => 'Edit Object',
167     -submenu => [
168     { -label => 'by Id', -value => \&editOid_dialog },
169     { -label => 'by filter', -value => \&editOfilter_dialog },
170     ],
171     },
172     { -label => 'List Transactions',
173     -submenu => [
174     { -label => 'all', -value => sub { listTransactions(); } },
175     { -label => 'all transfered', -value => sub { listTransactions('transfered'); } },
176     { -label => 'all opened', -value => sub { listTransactions('opened'); } },
177     { -label => 'all finished', -value => sub { listTransactions('finished'); } },
178     ],
179     },
180     ]
181     },
182     { -label => 'Editor',
183     -submenu => [
184     { -label => 'Start Editor ^E', -value => \&start_editor },
185     { -label => 'Quit Editor ^W', -value => \&close_win },
186     { -label => 'Open file ^O', -value => \&file_open_dialog },
187     { -label => 'Save file ^S', -value => \&file_save_dialog },
188     ]
189     },
190     { -label => 'Help',
191     -submenu => [
192     { -label => 'About', -value => \&about_dialog }
193     ]
194     }
195     );
196    
197     # ----------------------------------------------------------------------
198     # Create basic widgets
199     # ----------------------------------------------------------------------
200    
201     # Create the root. Everything else will be built up from here.
202     my $cui = new Curses::UI (
203     -clear_on_exit => 1
204     );
205    
206    
207     # Add the menu to the root.
208     my $menu = $cui->add(
209     'menu','Menubar',
210     -menu => \@menu,
211     );
212    
213    
214     # Help information for the user.
215     my $status_win = $cui->add(
216     'Status_win', 'Window',
217     -border => 1,
218     -y => -1,
219     -width => -1,
220     -height => 3,
221     );
222     my $status = $status_win->add(
223     'status', 'Label',
224     # -y => -1,
225     # -width => -1,
226     # -height => 3,
227     -reverse => 1,
228     -paddingspaces => 1,
229     # -padright => 8,
230     -text =>
231     " ^Q Quit from the program"
232     . " ^W Close current window"
233     . " ^X Open the menu"
234     . " ^R Runs command",
235     );
236    
237     # ----------------------------------------------------------------------
238     # Callback routines
239     # ----------------------------------------------------------------------
240    
241     #--------- callback: Dialog for Object by ID Selection
242     sub editOid_dialog {
243     my $eoid_dialog = $cui->add(
244     'EditOid_dialog','Window',
245     -centered => 1,
246     -width => 60,
247     -height => 10,
248     -border => 1,
249     -title => "Type Object ID:",
250     -onfocus => sub{
251     $focused_win = 'EditOid_dialog';
252     $status->text("Status: Focus to " . 'EditOid_dialog');
253     },
254     );
255    
256     my $textentry = $eoid_dialog->add(
257     'eoid_textentry', 'TextEntry',
258     -singleline => 1,
259     -maxlength => 50,
260     -border => 1,
261     -centered => 1,
262     );
263     my $button = $eoid_dialog->add(
264     'eoid_button', 'Buttonbox',
265     -buttons => [
266     {
267     -label=> '< OK >',
268     -onpress => sub {
269     _editObject($textentry->get());
270     $cui->delete("EditOid_dialog");
271     },
272     },
273     {
274     -label=> '< CANCEL >',
275     -onpress => \&close_win,
276     }
277     ],
278     -buttonalignment => 'center',
279     -x => 20,
280     -y => -1,
281     );
282    
283     $textentry->focus();
284     push(@windows, 'EditOid_dialog');
285    
286     }
287    
288     #----------- callback: Dialog for Objects Selection
289     sub editOfilter_dialog {
290    
291     my @object_names = Class::Tangram::known_classes();
292     my %concret_names;
293     my @okeys;
294     my $o_cnt;
295     foreach(sort @object_names) {
296     $concret_names{$o_cnt} = $_ if (!Class::Tangram::class_is_abstract($_));
297     push @okeys, $o_cnt if (!Class::Tangram::class_is_abstract($_));
298     $o_cnt++;
299     }
300    
301     my %field_names;
302     my @fkeys;
303    
304    
305     my $eofilter_dialog = $cui->add(
306     'EditOfilter_dialog','Window',
307     -centered => 1,
308     -width => 60,
309     -height => 20,
310     -border => 1,
311     -title => "Type Object-Filter values:",
312     -onfocus => sub{
313     $focused_win = 'EditOfilter_dialog';
314     $status->text("Status: Focus to " . 'EditOfilter_dialog');
315     },
316     );
317    
318    
319     $eofilter_dialog->add(
320     'eofilter:type_label', 'Label',
321     -x => 1,
322     -y => 1,
323     -text => 'Object Type:',
324     );
325     my $type_list = $eofilter_dialog->add(
326     'eofilter:type_list', 'Popupmenu',
327     -x => 15,
328     -y => 1,
329     -values => \@okeys,
330     -labels => \%concret_names,
331     -width => 25,
332     -onchange => sub {
333     my $pm = shift;
334     my $lbl = $pm->parent->getobj('eofilter:field_label');
335     my $val = $pm->get;
336     $val = "<undef>" unless defined $val;
337     my $obj_name = $pm->{-labels}->{$val};
338     my $f_cnt = 0;
339     %field_names = ();
340     @fkeys = ();
341     my %fieldnames_tmp = %{Class::Tangram::attribute_types($obj_name)};
342     foreach ( keys %fieldnames_tmp) {
343     $field_names{$f_cnt} = $_ if (($fieldnames_tmp{$_} eq 'string') || ($fieldnames_tmp{$_} eq 'real'));
344     push @fkeys, $f_cnt if (($fieldnames_tmp{$_} eq 'string') || ($fieldnames_tmp{$_} eq 'real'));
345     $f_cnt++;
346     }
347     $lbl->draw;
348     },
349     );
350    
351     $eofilter_dialog->add(
352     'eofilter:field_label', 'Label',
353     -x => 1,
354     -y => 3,
355     -text => 'Object Field:',
356     );
357     my $field_list = $eofilter_dialog->add(
358     'eofilter:field_list', 'Popupmenu',
359     -x => 15,
360     -y => 3,
361     -values => \@fkeys,
362     -labels => \%field_names,
363     -width => 25,
364     );
365    
366     $eofilter_dialog->add(
367     'eofilter:value_label', 'Label',
368     -x => 1,
369     -y => 5,
370     -text => 'Key Value:',
371     );
372    
373     my $entry = $eofilter_dialog->add(
374     'eofilter:value_entry', 'TextEntry',
375     -x => 15,
376     -y => 5,
377     -singleline => 1,
378     -maxlength => 50,
379     -border => 1,
380     );
381    
382     $eofilter_dialog->add(
383     'eofilter:button', 'Buttonbox',
384     -buttons => [
385     {
386     -label=> '< OK >',
387     -onpress => sub {
388     my $bt = shift;
389     my $type_obj = $bt->parent->getobj('eofilter:type_list');
390     my $field_obj = $bt->parent->getobj('eofilter:field_list');
391     my $entry_obj = $bt->parent->getobj('eofilter:value_entry');
392     _selectObject($concret_names{$type_obj->get()}, $field_names{$field_obj->get()}, $entry_obj->get());
393     $cui->delete("EditOfilter_dialog");
394     $cui->draw();
395     },
396     },
397     {
398     -label=> '< CANCEL >',
399     -onpress => \&close_win,
400     }
401     ],
402     -buttonalignment => 'center',
403     -x => 20,
404     -y => -1,
405     );
406     $eofilter_dialog->focus();
407     push(@windows, 'EditOfilter_dialog');
408     }
409    
410     #-------- Generic Select Objects by Filter
411     sub _selectObject {
412     my %obj_filter;
413     $obj_filter{type} = shift;
414     $obj_filter{field} = shift;
415     $obj_filter{value} = shift;
416    
417     if ($obj_filter{value} eq '*') {
418     $obj_filter{value} = 'all';
419     delete $obj_filter{field};
420     }
421    
422     my $results = $bizProcess->getObjectsByFilter(\%obj_filter);
423     my @results = @{$results};
424     my $keys = $#results;
425     if ($keys !=-1) {
426     foreach (@results) {
427     my $oid = $bizProcess->{storage}->id($_);
428     my $object = $bizProcess->{storage}->getObject($oid);
429     my $class_meta = _getClassInfo($object);
430     $_->{label} = " " . $oid . " " . $class_meta->{class} . " " . $obj_filter{field} . " " . $_->{$obj_filter{field}};
431     }
432     my $topic = "Object ID Object Type Searched Field: Searched string";
433     my $Tlist = _getObjectList( \@results,$topic);
434     } else {
435     $cui->error(-message => "There are no Objects with filter rules Object Type: " . $obj_filter{type} . " Field: " . $obj_filter{field} . " Value: " . $obj_filter{value});
436     }
437     }
438    
439     #-------- List Transaction Objects
440     sub listTransactions {
441     my $selection = shift;
442     my $select;
443     if ($selection) { $select = { field => 'status', value => $selection,};}
444     else { $select = ''; }
445    
446     my $results = $bizProcess->selectTransactions($select);
447     my @results = @{$results};
448     my $keys = $#results;
449     if ($keys !=-1) {
450     foreach (@results) {
451     my $transid = $bizProcess->{storage}->id($_);
452     $_->{label} = " " . $transid . " " . ref( $_->{source}) . " " . ref( $_->{target}) . " " . $_->{amount};
453     }
454     my $topic = "TransactionID Source Destination Amount";
455     my $Tlist = _getObjectList( \@results,$topic);
456     } else {
457     $cui->error(-message => "There are no " . $selection . " Transactions!");
458     }
459     }
460    
461    
462     #--------- Get Objects As List in New Window
463     sub _getObjectList {
464     my $results = shift;
465     my $topic = shift;
466     my %labels;
467     my @objectIds;
468     my $winId = 0;
469    
470     my @results = @{$results};
471     foreach (@results) {
472     push(@objectIds, $bizProcess->{storage}->id($_));
473     $labels{$bizProcess->{storage}->id($_)} = $_->{label} ;
474     $winId = $winId + int $bizProcess->{storage}->id($_);
475     }
476    
477     my $listId = "ObjectList:" . $winId;
478     my $list_win = $cui->getobj($listId);
479     if ($list_win) {
480     $list_win->focus;
481     $status->text("List Window already open! Switched to it....");
482     $cui->draw;
483     return;
484     }
485    
486     my $List_win = $cui->add(
487     $listId,'Window',
488     -padtop => 1,
489     -padbottom => 3,
490     -ipad => 1,
491     -border => 1,
492     -title => $listId,
493     -onfocus => sub{
494     $focused_win = $listId;
495     $status->text("Status: Focus to " . $listId);
496     },
497     );
498    
499     my $listlabel = $List_win->add(
500     'listlabel:'.$#windows, 'Label',
501     -label => 'Tlists',
502     -bold => 1,
503     -text => $topic,
504     );
505    
506     $List_win->add(
507     'listbox:'.$#windows, 'Listbox',
508     -values => \@objectIds,
509     -labels => \%labels,
510     -border => 1,
511     -padtop => 2,
512     -padbottom => 2,
513     -hscrollbar => 1,
514     -vscrollbar => 1,
515     -onchange => \&showObjectById,
516     );
517    
518     $List_win->add(
519     'list_button:'.$#windows, 'Buttonbox',
520     -buttons => [
521     {
522     -label=> '<SELECT>',
523     -onpress => \&showObjectById,
524     },
525     {
526     -label=> '<CLOSE>',
527     -onpress => \&close_win,
528     },
529     ],
530     -width => 16,
531     -buttonalignment => 'center',
532     -y => -1,
533     );
534    
535     $List_win->focus;
536     push(@windows, $listId);
537     }
538    
539     #----------- Show Object by ID
540     sub showObjectById {
541     my $listbox = shift;
542     my $objectId = $listbox->get;
543    
544     my $object_win = $cui->getobj("eObject:".$objectId);
545     if ($object_win) {
546     $object_win->focus;
547     $status->text("Object already open! Switched to it....");
548     $cui->draw;
549     }
550     elsif ($objectId) {
551     my $eObj = _editObject( $objectId );
552     }
553     else {
554     $cui->error(-message => "No Object selected! Use <ENTER> or <SPACEBAR> to select.");
555     }
556     }
557    
558     #---------- Edit Object
559     sub _editObject {
560     my $objectId = shift;
561    
562     my $object_win = $cui->getobj("eObject:".$objectId);
563     if ($object_win) {
564     $object_win->focus;
565     $status->text("Object already open! Switched to it....");
566     return;
567     }
568    
569     my $eObject_winid = "eObject:" . $objectId;
570     my $object = $bizProcess->{storage}->getObject($objectId);
571     my $class_meta = $bizProcess->_getClassInfo($object);
572    
573     my $entry;
574    
575     my $eObject_win = $cui->add(
576     $eObject_winid,'Window',
577     -x => 2,
578     -y => 2,
579     -padbottom => 2,
580     -border => 1,
581     -vscrollbar => 1,
582     -hscrollbar => 1,
583     -title => $eObject_winid,
584     -onfocus => sub{
585     $focused_win = $eObject_winid;
586     $status->text("Status: Focus to " . $eObject_winid);
587     },
588     );
589    
590     my $label = $eObject_win->add(
591     "Olabel:" . $objectId, 'Label',
592     -label => 'Object',
593     -bold => 1,
594     -text => "Edit Object: " . $class_meta->{class} . " ID: " . $objectId,
595     -border => 1,
596     -centered => 1,
597     );
598    
599     $label->draw;
600     my $cnt = 1;
601     foreach (keys %{$object} ) {
602     if ($_ eq 'label') { delete $object->{$_}; next; }
603     my $class_meta = $bizProcess->_getClassInfo($object->{$_});
604     my $oy = $cnt * 3;
605     my $lid = $cnt . $objectId;
606     my $sublabel = $eObject_win->add(
607     $lid, 'Label',
608     -label => 'Object',
609     -bold => 1,
610     -text => $_,
611     -y => $oy,
612     -padleft => 1,
613     );
614    
615     if ($bizProcess->{storage}->id($object->{$_})) {
616     my $oid = $bizProcess->{storage}->id($object->{$_});
617     my $button = $eObject_win->add(
618     'buttons:'.$objectId.':'.$_, 'Buttonbox',
619     -buttons => [{
620     -label=> '< ' . $class_meta->{class} . ' >',
621     -onpress => sub { _editObject($oid); },
622     }],
623     -x => 35,
624     -y => $oy,
625     );
626    
627     }
628     elsif( ((ref($object->{$_}) eq 'ARRAY') || (ref($object->{$_}) eq 'HASH')) ) {
629     my @keys;
630     my $label_ref;
631     my $suboid;
632    
633     if (ref($object->{$_}) eq 'HASH') {
634     my $cnt = 0;
635     my %tmp_hash;
636     foreach (keys %{$object->{$_}}) {
637     $suboid = $bizProcess->{storage}->id($_) if ($bizProcess->{storage}->id($_));
638     $tmp_hash{$suboid} = $_;
639     push @keys, $cnt;
640     $cnt++;
641     }
642     $label_ref = \%tmp_hash;
643     }
644     elsif (ref($object->{$_}) eq 'ARRAY') {
645     my $cnt = 0;
646     my %htmp;
647     my $tmp = $_;
648     foreach (@{$object->{$_}}) {
649     $suboid = $bizProcess->{storage}->id($_) if ($bizProcess->{storage}->id($_));
650     $htmp{$suboid} = $cnt;
651     push @keys, $cnt;
652     $cnt++;
653     }
654     $label_ref = \%htmp;
655     }
656     if ($suboid) {
657     my $id = $objectId . ":" . $_;
658     my $button = $eObject_win->add(
659     'list:'.$objectId.':'.$_, 'Popupmenu',
660     -values => \@keys,
661     -labels => $label_ref,
662     -x => 35,
663     -y => $oy,
664     -onchange => sub {
665     my $oha = shift;
666     my $label = $oha->get();
667     my $oid;
668     foreach (keys %{$label_ref}) { $oid = $_ if($label_ref->{$_} eq $label); }
669     print STDERR "suboid: " , $oid, "\n";
670     _editObject($oid);
671     },
672     );
673     }
674     else {
675     my $dump = Dumper($object->{$_});
676     my $button = $eObject_win->add(
677     'buttons:'.$objectId.':'.$_, 'Buttonbox',
678     -buttons => [{
679     -label=> '< DUMP >',
680     -onpress => sub {
681     my $dumpwin = newLogWin($objectId.':'.$_);
682     $dumpwin->text($dump);
683     $dumpwin->focus();
684     },
685     }],
686     -x => 35,
687     -y => $oy,
688     );
689     }
690     }
691     else {
692     $entry->{$_} = $eObject_win->add(
693     'Otextentry'.$_, 'TextEntry',
694     -singleline => 1,
695     -heigth => 1,
696     -border => 1,
697     -text => $object->{$_},
698     -x => 35,
699     -y => $oy-1,
700     );
701     }
702    
703     $cnt++;
704     $sublabel->draw;
705     }
706     my $button = $eObject_win->add(
707     'button:'.$objectId, 'Buttonbox',
708     -buttons => [
709     {
710     -label=> '< Cancel/Back >',
711     -onpress => \&close_win,
712     },
713     {
714     -label=> '< Save >',
715     -onpress => sub { close_win(); saveObject( $object, $entry ); },
716     },
717     ],
718     -buttonalignment => 'center',
719     -x => 35,
720     -y => -2,
721     );
722    
723     $eObject_win->focus;
724     push(@windows, $eObject_winid);
725     }
726    
727    
728     #---------- Edit Hash / Array of Object
729     sub _editObjectHA {
730     my $object = shift;
731     my $objectId = shift;
732     my $subentry = shift;
733    
734     print STDERR Dumper($subentry);
735    
736     my $oha_win_tmp = $cui->getobj("ohaWin:".$objectId);
737     if ($oha_win_tmp) {
738     $oha_win_tmp->focus;
739     $status->text("Hash or Array of Object: " . $objectId . " already open! Switched to it....");
740     return;
741     }
742    
743     my $oha_winid = "ohaWin:" . $objectId;
744     my $obj_real = $bizProcess->{storage}->getObject($objectId);
745     my $class_meta = $bizProcess->_getClassInfo($obj_real);
746    
747     my $entry;
748    
749     my $oha_win = $cui->add(
750     $oha_winid,'Window',
751     -x => 2,
752     -y => 2,
753     -padbottom => 2,
754     -border => 1,
755     -vscrollbar => 1,
756     -hscrollbar => 1,
757     -title => $oha_winid,
758     -onfocus => sub{
759     $focused_win = $oha_winid;
760     $status->text("Status: Focus to " . $oha_winid);
761     },
762     );
763    
764    
765     my $label = $oha_win->add(
766     "oha_label:" . $objectId, 'Label',
767     -label => 'oha',
768     -bold => 1,
769     -text => "Edit Object: " . $class_meta->{class} . " ID: " . $objectId . "\n" . $subentry->{oentry} . ': ' . $subentry->{oha_entry},
770     -border => 1,
771     -centered => 1,
772     );
773    
774     $label->draw;
775    
776     my $list = $object->{$subentry->{oentry}}->[$subentry->{oha_entry}];
777     print STDERR Dumper($list);
778     if ( ref($list)) {
779     my $cnt = 1;
780     foreach (keys %{$list} ) {
781     my $oy = $cnt * 3;
782     my $lid = $cnt . $objectId;
783     my $sublabel = $oha_win->add(
784     $lid, 'Label',
785     -label => 'Object',
786     -bold => 1,
787     -text => $_,
788     -y => $oy,
789     -padleft => 1,
790     );
791     $entry->{$_} = $oha_win->add(
792     'ohatextentry'.$_, 'TextEntry',
793     -singleline => 1,
794     -heigth => 1,
795     -border => 1,
796     -text => $object->{$_},
797     -x => 35,
798     -y => $oy-1,
799     );
800    
801     $cnt++;
802     $sublabel->draw;
803     }
804     my $button = $oha_win->add(
805     'ohabutton:'.$objectId, 'Buttonbox',
806     -buttons => [
807     {
808     -label=> '< Cancel/Back >',
809     -onpress => \&close_win,
810     },
811     {
812     -label=> '< Save >',
813     -onpress => sub { close_win(); saveObject( $objectId, $entry ); },
814     },
815     ],
816     -buttonalignment => 'center',
817     -x => 35,
818     -y => -2,
819     );
820    
821     $oha_win->focus;
822     push(@windows, $oha_winid);
823     }
824     # if ( ref($object->{$subentry->{entry}}) eq 'ARRAY') {
825     # }
826     else {
827     $cui->error(-message => "Error!");
828     }
829    
830     }
831    
832    
833     #---------- Save Object
834     sub saveObject {
835     my $object = shift;
836     my $entry = shift;
837    
838     foreach(keys %{$entry}) {
839     $object->{$_} = $entry->{$_}->get();
840     }
841     $bizProcess->{storage}->update($object);
842     }
843    
844     #---------- test callback
845     sub test {
846     # no strict refs;
847     my $object_name = 'MoneyTransaction';
848     my $class = Class::Tangram::attribute_types($object_name);
849     my $out = Dumper($class);
850     my $title = "test";
851     my $testwin = newLogWin($title);
852     $testwin->text($out);
853     }
854    
855    
856     #---------- Backend Database Functions
857     sub retreat_backend {
858     my @cmd = ( 'perl', 'db_setup.pl', '--dbkey=backend', '--action=retreat' );
859     my $out = _start_ipc( \@cmd );
860     my $title = join(' ', @cmd);
861     my $retreatlog = newLogWin($title);
862     $retreatlog->text($out);
863     }
864    
865     sub deploy_backend {
866     my @cmd = ( 'perl', 'db_setup.pl', '--dbkey=backend', '--action=deploy' );
867     my $out = _start_ipc( \@cmd );
868     my $title = join(' ', @cmd);
869     my $deploylog = newLogWin($title);
870     $deploylog->text($out);
871     }
872    
873     sub feed_backend {
874     my @cmd = ( 'perl', 'backend_feed.pl', );
875     my $out = _start_ipc( \@cmd );
876     my $title = join(' ', @cmd);
877     my $feedlog = newLogWin($title);
878     $feedlog->text($out);
879     }
880    
881     sub reset_backend {
882     retreat_backend();
883     deploy_backend();
884     feed_backend();
885     }
886    
887    
888     #-------- Run command
889     sub command_dialog {
890     my $cmd_dialog = $cui->add(
891     'Cmd_dialog','Window',
892     -centered => 1,
893     -width => 60,
894     -height => 10,
895     -border => 1,
896     -title => "Type command:",
897     -onfocus => sub{
898     $focused_win = 'Cmd_dialog';
899     $status->text("Status: Focus to " . "Cmd_dialog");
900     },
901     );
902    
903     my $cmd_textentry = $cmd_dialog->add(
904     'cmd_textentry', 'TextEntry',
905     -singleline => 1,
906     -maxlength => 50,
907     -border => 1,
908     -centered => 1,
909     );
910     my $cmd_button = $cmd_dialog->add(
911     'cmd_button', 'Buttonbox',
912     -buttons => [
913     {
914     -label=> '< RUN >',
915     -onpress => sub {
916     _run_command($cmd_textentry->get());
917     $cui->delete('Cmd_dialog');
918     },
919     },
920     {
921     -label=> '< CANCEL >',
922     -onpress => \&close_win,
923     }
924     ],
925     -buttonalignment => 'center',
926     -x => 20,
927     -y => -1,
928     );
929    
930     $cmd_textentry->focus();
931     push(@windows, 'Cmd_dialog');
932     }
933    
934     sub _run_command {
935     my $cmdstring = shift;
936    
937     my @cmd = split(' ', $cmdstring);
938     my $out = _start_ipc( \@cmd );
939     if (!$out) { $cui->error("Unkown command!"); }
940     my $id = rand 3443;
941     my $ident = "Output:$id";
942     my $tmpout = newLogWin($ident);
943     my $outwin = $cui->getobj ( $ident);
944     $outwin->focus();
945     $tmpout->text($out);
946     $cui->draw();
947     }
948    
949    
950     #-------- Gerneric Output Window
951     sub newLogWin {
952     my $ident = shift;
953    
954     my $win = $cui->getobj($ident);
955     if ($win) {
956     $win->focus;
957     $status->text("Window already open! Switched to it....");
958     $cui->draw;
959     return;
960     }
961    
962     my $logwin = $cui->add(
963     $ident,'Window',
964     -x => 1**$#windows,
965     -y => 1**$#windows,
966     -titlereverse => 0,
967     -padright => 5-$#windows,
968     -padleft => 0+$#windows,
969     -padbottom => 3,
970     -ipad => 1,
971     -border => 1,
972     -title => $ident,
973     -onfocus => sub{
974     $status->text("Status: Focus to " . $ident);
975     $focused_win = $ident;
976     },
977     );
978    
979     my $txtid = "t_$ident";
980    
981     my $textwin = $logwin->add(
982     $txtid, 'TextViewer',
983     -showlines => 0,
984     -sbborder => 0,
985     -vscrollbar => 1,
986     -hscrollbar => 1,
987     -showhardreturns => 0,
988     -wrapping => 0, # wrapping slows down the editor :-(
989     -text => '',
990     );
991    
992     # Bring the focus to the editor widget.
993     # $logwin{$ident}->focus;
994    
995     push(@windows, $ident);
996     return $textwin;
997     }
998    
999    
1000     #---------- close windows
1001     sub close_win {
1002     my $tid = 0;
1003     my $cnt=0;
1004     foreach (@windows) {
1005     if ($_ && $_ eq $focused_win) { $tid = $cnt; }
1006     $cnt++;
1007     }
1008    
1009     for(my $i=0;$i<100000000000;) {
1010     my $wid = $tid+$i;
1011     if (!$windows[$wid] || $windows[$wid] eq '') {
1012     $i++;
1013     }
1014     else {
1015     $status->text("Status: window closed");
1016     switch_win();
1017     $cui->delete($windows[$wid]);
1018     delete $windows[$wid];
1019     $cui->layout;
1020     $cui->draw;
1021     last;
1022     }
1023     }
1024     }
1025    
1026     #-------- switch windows
1027     sub switch_win {
1028     return if ($#windows==-1 || $#windows ==1);
1029     my $tmpid = 0;
1030     my $cnt=0;
1031     foreach (@windows) {
1032     if ($_ && $_ eq $focused_win) { $tmpid = $cnt; }
1033     $cnt++;
1034     }
1035     my $obj;
1036     if ($tmpid < $cnt-1) {
1037     for(my $i=1;$i<100000000000;) {
1038     my $wid = $tmpid+$i;
1039     if (!$windows[$wid]) {
1040     $i++;
1041     }
1042     else {
1043     $obj = $cui->getobj($windows[$wid]);
1044     $focused_win = $windows[$wid];
1045     last;
1046     }
1047     }
1048     }
1049     else {
1050     for(my $i=0;$i<100000000000;) {
1051     my $wid = 0+$i;
1052     if (!$windows[$wid]) {
1053     $i++;
1054     }
1055     else {
1056     $obj = $cui->getobj($windows[$wid]);
1057     $focused_win = $windows[$wid];
1058     last;
1059     }
1060     }
1061     }
1062     $obj->focus if ($obj);
1063     }
1064    
1065     # Create the screen for the editor
1066     sub _screen_editor {
1067     my $editor_win = $cui->add(
1068     'Editor', 'Window',
1069     -padtop => 1,
1070     -padbottom => 3,
1071     # -border => 1,
1072     -onfocus => sub{
1073     $focused_win = 'Editor';
1074     $status->text("Status: Focus to " . 'Editor');
1075     },
1076     );
1077     return $editor_win;
1078     }
1079    
1080     sub start_editor {
1081     my $screen = _screen_editor();
1082     # We add the editor widget to this screen.
1083     my $editor = $screen->add(
1084     'txt_editor', 'TextEditor',
1085     -border => 1,
1086     -padtop => 0,
1087     -padbottom => 0,
1088     -showlines => 0,
1089     -sbborder => 0,
1090     -vscrollbar => 1,
1091     -hscrollbar => 1,
1092     -showhardreturns => 0,
1093     -wrapping => 0, # wrapping slows down the editor :-(
1094     -text => $text,
1095     );
1096    
1097     # There is no need for the editor widget to loose focus, so
1098     # the "loose-focus" binding is disabled here. This also enables the
1099     # use of the "TAB" key in the editor, which is nice to have.
1100     # $editor->clear_binding('loose-focus');
1101    
1102     # Bring the focus to the editor widget.
1103     $editor->focus;
1104     push(@windows, 'Editor');
1105     }
1106    
1107     #-------- Edito: Open File Dialog
1108     sub file_open_dialog()
1109     {
1110     my $file = $cui->loadfilebrowser(
1111     -file => $currentfile,
1112     );
1113    
1114     if (defined $file)
1115     {
1116     if (open F, "<$file") {
1117     my $text = "";
1118     while (<F>) { $text .= $_ }
1119     close F;
1120     $editor->text($text);
1121     $editor->cursor_to_home;
1122     $currentfile = $file;
1123     } else {
1124     $cui->error(-message => "Can't read file \"$file\":\n$!");
1125     }
1126     }
1127     }
1128    
1129     #------ Editor: Save File Dialog
1130     sub file_save_dialog()
1131     {
1132    
1133     my $file = $cui->savefilebrowser(
1134     -file => $currentfile,
1135     );
1136     return unless defined $file;
1137    
1138     if (open F, ">$file") {
1139     print F $editor->text;
1140     if (close F) {
1141     $cui->dialog(-message => "File \"$file\"\nsuccessfully saved");
1142     $currentfile = $file;
1143     } else {
1144     $cui->error(-message => "Error on closing file \"$file\":\n$!");
1145     }
1146     } else {
1147     $cui->error(-message => "Can't write to $file:\n$!");
1148     }
1149     }
1150    
1151     #-------- About Dialog
1152     sub about_dialog()
1153     {
1154     $cui->dialog(
1155     -title => 'About gui',
1156     -message => "Program : Curses::UI GUI\n"
1157     . "Author : unkown\n"
1158     . "\n"
1159     );
1160     }
1161    
1162     #--------- Exit Dialog
1163     sub exit_dialog()
1164     {
1165     my $return = $cui->dialog(
1166     -title => "Are you sure???",
1167     -buttons => ['yes', 'no'],
1168     -message => "Do you really want to quit?"
1169     );
1170    
1171     exit(0) if $return;
1172     }
1173    
1174     #-------- sub Start IPC with given CMD
1175     sub _start_ipc {
1176     my $cmd = shift;
1177     my $in;my $out;my $err;
1178     my $t = timer ( 60 );
1179     my $h = start( $cmd, \$in, \$out, \$err, $t);
1180     pump $h; #until $err; #|| $t->is_expired;
1181     # $h->kill_kill; #if ($t->is_expired || $err);
1182     $h->finish;
1183     return $err if($err);
1184     return $out if($out);
1185     # my $ipcrun = start
1186     # $cmd,
1187     # '<pipe', \*IN,
1188     # '>pipe', \*OUT,
1189     # '2>pipe', \*ERR,
1190     # $t ;
1191     # or die "could not open IPC::Run - handle: $?" ;
1192     }
1193    
1194     # ----------------------- Helper Functions ---------------------------
1195     sub _getClassInfo {
1196     my $object = shift;
1197    
1198     # which class is it of?
1199     my $class = ref $object;
1200    
1201     # which classes is this class based on?
1202     my $bases = Class::Tangram::class_bases($class);
1203    
1204     return { class => $class, bases => $bases };
1205     }
1206    
1207    
1208    
1209     # ----------------------------------------------------------------------
1210     # The main loop of the program
1211     # ----------------------------------------------------------------------
1212    
1213    
1214     $cui->set_binding(\&exit_dialog, "\cQ", "\cC");
1215     #$cui->set_binding(\&switch_win, KEY_STAB);
1216     $cui->set_binding(\&switch_win, "\cA");
1217     $cui->set_binding(\&command_dialog, "\cR");
1218     $cui->set_binding(\&start_editor, "\cE");
1219     $cui->set_binding(\&close_win, "\cW");
1220     $cui->set_binding(\&file_save_dialog, "\cS");
1221     $cui->set_binding(\&file_open_dialog, "\cO");
1222     $cui->set_binding(sub {shift()->getobj('menu')->focus}, "\cX", KEY_F(10));
1223     $cui->set_binding(sub {
1224     my $cui = shift;
1225     $cui->layout;
1226     $cui->draw;
1227     }, "\cL");
1228    
1229    
1230    
1231     $cui->mainloop;

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed