$APE::Tk::ProcessRoleSelector::VERSION = '0.1';

package APE::Tk::ProcessRoleSelector;

use Tk::widgets qw/Frame/;
use base qw/Tk::Derived Tk::Frame/;
use strict;
use warnings;
use Carp;

Construct Tk::Widget 'ProcessRoleSelector';

use constant TRUE  => 1;
use constant FALSE => 0;

## Standard Tk mega widget method for creating this mega widget and
## initialising the super class widget.
sub ClassInit {
    my ($class,$mw) = @_;
    $class->SUPER::ClassInit($mw);
}


## Standard Tk mega widget method for defining mega widget
## characteristics and capturing arguments unknown to Tk.
sub Populate {
    my ($self,$args) = @_;
    $self->SUPER::Populate($args);
    $self->{_processList} = delete $args->{-roleList} || croak "Error: attribute '-roleList' is required";
    unless($self->_verifyProcessList) {
	croak "Error: process is not of type 'APE::Process'";
    }
}


## Method to verify that each of the passed processes is of type
## APE::Process. Each process may of course be derived from an
## APE::Process.
sub _verifyProcessList {
    my $self = shift;
    my $processList = $self->{_processList};
    foreach my $process (@$processList) {
	return FALSE unless UNIVERSAL::isa($process,"APE::Process");
    }
    return TRUE;
}
