
#import "GSResultItem.h"
#import "GreenstoneApplication.h"

#import "QueryCascadeView.h"


@implementation QueryCascadeView


-(id) initWithFrame:(CGRect)rect withParent:(UIView*)parent 
        withCollection:(NSString*)collection withTitle:(NSString*)title withGID:(NSString*)gid
{
  _queryViews = [[NSMutableArray alloc] initWithCapacity:MCInitCapacity];

  return [super initWithFrame:rect withParent:parent withCollection:collection 
	 withTitle:title withGID:gid];
}

-(void) appendMenuItem:(NSObject*)app withItem:(NSString*)item_label withGID:(NSString*)childGID
{
  [super appendMenuItem:app withItem:item_label withGID:childGID];

  CGRect workarea_rect = [GreenstoneApplication workAreaRect];
  QueryView* queryView = [[QueryView alloc] initWithFrame:workarea_rect 
			withParent:self withCollection:childGID withTitle:item_label];

  [_queryViews addObject:queryView];  

}

-(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]; 

  CGRect workarea_rect = [GreenstoneApplication workAreaRect];
  QueryView* queryView = [_queryViews objectAtIndex:rowId];

  [GreenstoneApplication setInCollection:chosenCollection];
  [GreenstoneApplication transitionView:UITransitionBothShiftLeft 
        fromView:self toView:queryView];
}

-(UIView*) directEntry:(int)rowId
{
  return [_queryViews objectAtIndex:rowId];
}

-(void) dealloc
{
  [_queryViews release];

  [super dealloc];
}


@end
