#import <eointerface/eointerface.h>
#import "MiscClockView.h"
#import "MiscClockView_Foundation.h"
#import "MiscClockViewAssociation.h"

@implementation MiscClockViewAssociation

- initWithController:(EOController *)aController
	key: (NSString *)aKey destination: aDest
{
	[(MiscClockView*)aDest setDelegate:self];
    return [super initWithController:aController key: aKey destination:aDest];
}

- dateChanged:sender
{
	[controller associationDidEdit: self];
	return self;
}

- value
{
	return [(MiscClockView*)destination calendarDate];
}

- (void)selectionDidChange
{
	[self contentsDidChange];
}

- (void)contentsDidChange
{
    NSArray *selectedObjects;
	id selectedObject, aDict, val;
	id array;
	
	selectedObjects = [controller selectedObjects];
    if ([selectedObjects count] == 1)
	{
		array = [[[NSArray alloc] initWithObjects: key, 0] autorelease];
	
		//[(MiscClockView*)destination setEnabled:YES];
		selectedObject = [selectedObjects objectAtIndex: 0];
		aDict = [selectedObject valuesForKeys: array];
		if ((val = [aDict objectForKey: key]))
		{
	   		[(MiscClockView*)destination setCalendarDate:val];
		}
	}
	else
	{
		//[(MiscClockView*)destination setEnabled:NO];
    }
}

@end

@implementation MiscClockView(AssociationClass)

- (Class) associationClass
{
	return [MiscClockViewAssociation class];
}

@end