| 1 | package UR::Object::View::Default::Gtk; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | require UR; | ||
| 6 | our $VERSION = "0.46"; # UR $VERSION; | ||
| 7 | |||
| 8 | UR::Object::Type->define( | ||
| 9 | class_name => __PACKAGE__, | ||
| 10 | is => 'UR::Object::View', | ||
| 11 | has_constant => [ | ||
| 12 | perspective => { value => 'default' }, | ||
| 13 | toolkit => { value => 'gtk' }, | ||
| 14 | ] | ||
| 15 | ); | ||
| 16 | |||
| 17 | sub _create_widget { | ||
| 18 | my $self = shift; | ||
| 19 | my $label = Gtk::Label->new("<new>"); | ||
| 20 | return $label; | ||
| 21 | } | ||
| 22 | |||
| 23 | sub _update_view_from_subject { | ||
| 24 | my $self = shift; | ||
| 25 | my @changes = @_; # this is not currently resolved and passed-in | ||
| 26 | |||
| 27 | my $subject = $self->subject(); | ||
| 28 | my @aspects = $self->aspects; | ||
| 29 | my $widget = $self->widget(); | ||
| 30 | |||
| 31 | my $text = $self->subject_class_name; | ||
| 32 | $text .= " with id " . $subject->id if $subject; | ||
| 33 | |||
| 34 | # Don't recurse back into something we're already in the process of showing | ||
| 35 | if ($self->_subject_is_used_in_an_encompassing_view()) { | ||
| 36 | $text .= " (REUSED ADDR)\n"; | ||
| 37 | } else { | ||
| 38 | $text .= "\n"; | ||
| 39 | my @sorted_aspects = map { $_->[1] } | ||
| 40 | sort { $a->[0] <=> $b->[0] } | ||
| 41 | map { [ $_->position, $_ ] } | ||
| 42 | @aspects; | ||
| 43 | for my $aspect (@sorted_aspects) { | ||
| 44 | my $label = $aspect->label; | ||
| 45 | $text .= "\n" . $label . ": "; | ||
| 46 | if ($subject) { | ||
| 47 | my @value = $subject->$label; | ||
| 48 | $text .= join(", ", @value); | ||
| 49 | } | ||
| 50 | else { | ||
| 51 | $text .= "-"; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | } | ||
| 55 | $widget->set_text($text); | ||
| 56 | return 1; | ||
| 57 | } | ||
| 58 | |||
| 59 | sub _update_subject_from_view { | ||
| 60 | Carp::confess("This widget shouldn't be able to write to the object, it's a label? How did I get called?"); | ||
| 61 | } | ||
| 62 | |||
| 63 | sub _add_aspect { | ||
| 64 | shift->_update_view_from_subject; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub _remove_aspect { | ||
| 68 | shift->_update_view_from_subject; | ||
| 69 | } | ||
| 70 | |||
| 71 | 1; | ||
| 72 | |||
| 73 | =pod | ||
| 74 | |||
| 75 | =head1 NAME | ||
| 76 | |||
| 77 | UR::Object::View::Default::Gtk - Gtk adaptor for object views | ||
| 78 | |||
| 79 | =head1 DESCRIPTION | ||
| 80 | |||
| 81 | This class provides code that implements a basic Gtk renderer for UR objects. | ||
| 82 | |||
| 83 | =head1 SEE ALSO | ||
| 84 | |||
| 85 | UR::Object::View, UR::Object | ||
| 86 | |||
| 87 | =cut | ||
| 88 |