
#import "GSResultItem.h"
#import "GreenstoneApplication.h"

#import "PrefCascadeView.h"

@implementation PrefCascadeView

-(id) initWithFrame:(CGRect)rect withParent:(UIView*)parent 
        withCollection:(NSString*)collection withTitle:(NSString*)title withGID:(NSString*)gid
{
  self = [super initWithFrame:rect withParent:parent withCollection:collection 
	  withTitle:title withGID:gid];

  _prefViews = [[NSMutableArray alloc] initWithCapacity:MCInitCapacity];

  return self;
}

-(void) appendMenuItem:(NSObject*)app withItem:(NSString*)item_label withGID:(NSString*)childGID
{
  [super appendMenuItem:app withItem:item_label withGID:childGID];

  CGRect workarea_rect = [GreenstoneApplication workAreaRect];
  PrefView* prefView = [[PrefView alloc] initWithFrame:workarea_rect 
			withParent:self withCollection:childGID withTitle:item_label];

  [_prefViews addObject:prefView];  

}

-(UIView*) directEntry:(int)rowId
{
  return [_prefViews objectAtIndex:rowId];
}



//***********
//* Delegates
//***********
-(void) tableRowSelected:(NSNotification*)notification
{
  UITable* table = [notification object];
  int rowId = [table selectedRow];

  GreenstoneAPI* greenstoneAPI = [GreenstoneApplication greenstoneAPI];

  NSString* childTitle = [[_oidItem objectAtIndex:rowId] title];
  NSString* childGID = [[_oidItem  objectAtIndex:rowId] oid]; 

  NSString* chosenCollection = [[NSString alloc] initWithString:childGID];

  PrefView* prefView = [_prefViews objectAtIndex:rowId];
  
  [GreenstoneApplication setInCollection:chosenCollection];
  [GreenstoneApplication transitionView:UITransitionBothShiftLeft 
        fromView:self toView:prefView];

}

-(void) dealloc
{
  [_prefViews release];

  [super dealloc];
}

@end
