-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExptInfoController.m
1004 lines (659 loc) · 29.8 KB
/
ExptInfoController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#import "ExptInfoController.h"
#import "BarExperiment.h"
#import "DailyData.h"
#import "BarDocument.h"
#import "BarSubject.h"
#import "BarItem.h"
#import "BarGroup.h"
#import "BarDrug.h"
#import "BarPhase.h"
#import "BarDirectories.h"
#import "DailyDataDocument.h"
#import "BCBarcodeLabelsWebView.h"
#import "Bartender_Constants.h"
@implementation ExptInfoController
-(id)init {
self = [super initWithWindowNibName:@"ExptInfoWindow"];
if (self) {
// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
[exptNameView setStringValue:@"Untitled"];
[exptCodeView setStringValue:@"AA"];
NSLog(@"ExptInfoController initialized");
}
return self;
}
-(void)awakeFromNib {
[dailyDataTableView setTarget:self];
[dailyDataTableView setDoubleAction:@selector(handleDailyDataDoubleClick:)];
}
-(void)setBartender:(BarDocument *)newBartender {
// we are created and destroyed by a BarDocument
bartender = newBartender;
NSLog(@"bartender set");
}
- (IBAction)cancelButtonPressed:(id)sender {
// NOTE -- need to implement this as a real cancel button...
// user cancelled, so just close the window without creating a new expt
// user cancelled, so do NOT copy edited fields back into originalExperiment
// instead, just let theExperiment get released when we're closed...
originalExperiment = nil;
theExperiment = nil;
NSLog(@"ExptInfo Cancel Button pressed");
[[self window] performClose:self];
// as a window controller, we need to be closed by our owner...
[bartender closeExptInfo:self andSaveExpt:NO];
}
// global buttons
- (IBAction)saveButtonPressed:(id)sender {
NSLog(@" ExptInfo Save Button pressed");
// replace the data of original experiment with the edited fields of theExperiment
// [originalExperiment resetToExperiment:theExperiment];
// theExperiment = nil;
// NOTE: post warning if new experiment of same name?
// NOTE: check for required attributes of experiment? i.e. CODE, at least 1 item?
[[self window] performClose:self];
// as a window controller, we need to be closed by our owner...
[bartender closeExptInfo:self andSaveExpt:YES];
}
- (IBAction)saveTemplateButtonPressed:(id)sender {
NSLog(@" ExptInfo Save Template Button pressed");
NSSavePanel *savePanel;
NSInteger result;
/* create or get the shared instance of NSSavePanel */
savePanel = [NSSavePanel savePanel];
/* set up new attributes */
[savePanel setAllowedFileTypes:[NSArray arrayWithObjects:@"bartemplate",nil]];
// set to the template directory
NSString *templateDirectoryPath = GetTemplateDirectoryPath();
// NSString *templateFilePath = [[templateDirectoryPath stringByAppendingPathComponent:templateName] stringByAppendingPathExtension:@"bartemplate"];
NSURL * templateDirectoryURL = [NSURL fileURLWithPath:templateDirectoryPath] ;
[savePanel setDirectoryURL:templateDirectoryURL ];
/*prompt */
[savePanel setPrompt:@"Save Bartender Template As:"];
/* set the suggested file name */
NSString *fileName = [NSString stringWithFormat:@"%@ Template.bartemplate",[theExperiment code]];
[savePanel setNameFieldStringValue:fileName];
/* display the NSSavePanel */
result = [savePanel runModal];
if (result == NSModalResponseOK) {
NSString *myFilePath = [[savePanel filename] copy];
// update the experiment from the expt info window
[self getExperiment];
// save the experiment, but as a template...
[theExperiment saveToPath:myFilePath];
[[self window] performClose:self];
// as a window controller, we need to be closed by our owner...
[bartender closeExptInfo:self andSaveExpt:NO];
NSLog(@"Should have called closeExptInfo");
}
}
- (IBAction)applyTemplateButtonPressed:(id)sender {
// apply template to the experiment being edited...
NSInteger result;
NSLog(@" ExptInfo Apply Template Button pressed");
// choose a template
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setPrompt:@"Select Bartender Template:"];
// set to the template directory
NSString *templateDirectoryPath = GetTemplateDirectoryPath();
NSURL * templateDirectoryURL = [NSURL fileURLWithPath:templateDirectoryPath] ;
[openPanel setDirectoryURL: templateDirectoryURL];
[openPanel setAllowedFileTypes:[NSArray arrayWithObjects:@"bartemplate",nil]];
[openPanel setAllowsMultipleSelection:NO];
result = [openPanel runModal];
if (result == NSModalResponseOK) {
// load & apply the template experiment to current experiment
NSString *templateFilePath = [[openPanel filenames] objectAtIndex:0];
[theExperiment loadFromTemplatePath:templateFilePath];
// reset the exptInfo window
[self loadTheExpt];
}
}
- (void)setTheExperiment:(BarExperiment *)newExpt {
// set the values in the new expt panel
// using the values in the given expt
originalExperiment = newExpt;
// theExperiment = [originalExperiment copy];
theExperiment = newExpt;
[self loadTheExpt];
numDataDays = [theExperiment numberOfDays];
// load all daily data into memory
dailyDataArray = [NSMutableArray arrayWithCapacity: numDataDays];
for (NSUInteger d=0;d< numDataDays; d++ ) {
[dailyDataArray addObject: [theExperiment dailyDataForDay:d]];
}
}
-(void) windowDidLoad {
[self loadTheExpt];
}
-(void) loadTheExpt {
// populate the info tab view
[exptNameView setStringValue:[theExperiment name]];
[exptCodeView setStringValue: [theExperiment code]];
[exptInvestigatorsView setStringValue: [theExperiment investigators]];
[exptProtocolView setStringValue: [theExperiment protocol]];
[exptWikiView setStringValue: [theExperiment wiki]];
[exptProjCodeView setStringValue: [theExperiment project_code]];
[exptProjNameView setStringValue: [theExperiment project_name]];
[exptSubjectsView setIntegerValue: (NSInteger)[theExperiment numberOfSubjects]];
// set the text of the description view...
NSRange wholeRange = NSMakeRange(0,[[exptSummaryView textStorage] length]);
[[exptSummaryView textStorage] replaceCharactersInRange:wholeRange withString:[theExperiment description]];
// populate the info tab view
// set the preference values...
[calcPreference setState:[theExperiment hasPreference]];
[self setItemPopupMenus];
[prefTypes selectCellAtRow:[theExperiment usePreferenceOverTotal] column:0];
[self setGroupPopupMenu];
[self setPhasePopupMenu];
[itemsTableView reloadData];
[groupsTableView reloadData];
[drugsTableView reloadData];
[phasesTableView reloadData];
[subjectsTableView reloadData];
[dailyDataTableView reloadData];
// set the back up data path
NSString *backupSummaryPath = [[NSUserDefaults standardUserDefaults] valueForKey:kBartenderLocalBackupDirectoryKey];
[backupSummaryPathView setStringValue:backupSummaryPath];
}
-(void)addItemsToMenu:(NSMenu *)itemMenu; {
BarItem *theItem;
NSString *itemName;
NSMenuItem *itemNameItem;
NSArray *itemsForMenu = [theExperiment items];
// clear out the menu
[itemMenu removeAllItems];
if (0 == [itemsForMenu count]) {
itemNameItem = [[NSMenuItem alloc] initWithTitle:@"<none>" action:NULL keyEquivalent:[NSString string]];
// default "no-item" menu item with default action & no key equivalent
// add the menu item to the menu
[itemMenu addItem:itemNameItem];
}
else {
for (theItem in itemsForMenu) {
// only include item if it is one of the desired types of item, based on flags...
itemName = [[NSString alloc] initWithString:[theItem name]];
itemNameItem = [[NSMenuItem alloc] initWithTitle:itemName action:NULL keyEquivalent:[NSString string]];
// menu item with default action & no key equivalent
// add the menu item to the menu
[itemMenu addItem:itemNameItem];
} // added all the items
}
// all the items have been added, now we can return
}
-(void)setItemPopupMenus; {
if ( prefItemPopupMenu != nil && refItemPopupMenu != nil) {
NSMenu *itemMenu;
itemMenu = [prefItemPopupMenu menu];
[self addItemsToMenu:itemMenu];
itemMenu = [refItemPopupMenu menu];
[self addItemsToMenu:itemMenu];
if ([theExperiment numberOfItems] > 0) {
if ([theExperiment prefItemIndex ] <= [theExperiment numberOfItems]) {
[prefItemPopupMenu selectItemAtIndex:(NSInteger)[theExperiment prefItemIndex ]];
}
else {[prefItemPopupMenu selectItemAtIndex:0]; }
if ([theExperiment baseItemIndex ] <= [theExperiment numberOfItems]) {
[refItemPopupMenu selectItemAtIndex:(NSInteger)[theExperiment baseItemIndex ]];
}
else { [refItemPopupMenu selectItemAtIndex:0]; }
}
}
}
-(void)setGroupPopupMenu; {
groupPopupMenu = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
// make sure to specify pullsDown:NO for use in a NSTableView!!!
[groupPopupMenu setBordered:NO];
[groupPopupMenu setEditable:YES];
[groupPopupMenu setTarget:self];
[groupPopupMenu setAutoenablesItems:YES];
// [groupPopupMenu setAltersStateOfSelectedItem: NO];
NSMutableArray *groupNames = [[NSMutableArray alloc] init];
for (BarGroup *theGroup in [theExperiment groups]) {
NSLog(@"Adding group name: %@",[theGroup name]);
[groupNames addObject: [theGroup name]];
}
[groupPopupMenu addItemsWithTitles:groupNames];
// for (NSString *name in groupNames) {
// NSMenuItem *theItem = [groupPopupMenu itemWithTitle:name];
// [theItem setHidden:NO];
// [theItem setEnabled:YES];
// }
[[subjectsTableView tableColumnWithIdentifier:@"groupName"] setDataCell:groupPopupMenu];
[subjectsTableView reloadData];
}
-(void)setPhasePopupMenu; {
phasePopupMenu = [[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:NO];
// make sure to specify pullsDown:NO for use in a NSTableView!!!
[phasePopupMenu setBordered:NO];
[phasePopupMenu setEditable:YES];
[phasePopupMenu setTarget:self];
[phasePopupMenu setAutoenablesItems:YES];
// [phasePopupMenu setAltersStateOfSelectedItem: NO];
NSMutableArray *phaseNames = [[NSMutableArray alloc] init];
for (BarPhase *thePhase in [theExperiment phases]) {
NSLog(@"Adding phase name: %@",[thePhase name]);
[phaseNames addObject: [thePhase name]];
}
[phasePopupMenu addItemsWithTitles:phaseNames];
[[dailyDataTableView tableColumnWithIdentifier:@"phaseName"] setDataCell:phasePopupMenu];
[dailyDataTableView reloadData];
}
- (BarExperiment *)getExperiment {
// set up the experiment using the values in the new expt panel and
[theExperiment setName:[exptNameView stringValue]];
[theExperiment setCode:[exptCodeView stringValue]];
[theExperiment setInvestigators:[exptInvestigatorsView stringValue]];
[theExperiment setProtocol:[exptProtocolView stringValue]];
[theExperiment setWiki:[exptWikiView stringValue]];
[theExperiment setProjectCode:[exptProjCodeView stringValue]];
[theExperiment setProjectName:[exptProjNameView stringValue]];
[theExperiment setNumberOfSubjects: (NSUInteger)[exptSubjectsView integerValue]];
// retrieve the text of the description view...
[theExperiment setDescription:[NSString stringWithString:[[exptSummaryView textStorage] mutableString]]];
// item view
// get preferences...
[theExperiment setHasPreference: (BOOL)[calcPreference state]];
[theExperiment setPreferenceIndexofItem:(NSUInteger)[prefItemPopupMenu indexOfSelectedItem]
overItem:(NSUInteger)[refItemPopupMenu indexOfSelectedItem]];
[theExperiment setUsePreferenceOverTotal: (BOOL)[prefTypes selectedRow] ];
// [theExperiment setBackupSummaryPath:[backupSummaryPathView stringValue]];
return theExperiment;
}
// tab specific buttons
// expt code
-(IBAction)exptCodeEdited:(id)sender; {
[theExperiment setCode:[exptCodeView stringValue]];
[subjectsTableView reloadData];
}
// items
- (IBAction)addItem:(id)sender {
NSLog(@" ExptInfo Add Item Button pressed");
[theExperiment addNewItem];
[itemsTableView reloadData];
[self setItemPopupMenus];
}
- (IBAction)deleteItem:(id)sender {
NSLog(@" ExptInfo Delete Item pressed");
NSInteger selectedItemIndex = [itemsTableView selectedRow];
if (selectedItemIndex == -1) return; // no selection
//otherwise last row selected
[theExperiment deleteItemAtIndex:(NSUInteger)selectedItemIndex];
[itemsTableView reloadData];
[self setItemPopupMenus];
}
- (IBAction)addGroup:(id)sender {
NSLog(@" ExptInfo Add Group Button pressed");
[theExperiment addNewGroup];
[groupsTableView reloadData];
//have to update group listings in subject table too
[self setGroupPopupMenu];
[subjectsTableView reloadData];
}
- (IBAction)deleteGroup:(id)sender {
NSLog(@" ExptInfo Delete Group pressed");
NSInteger selectedGroupIndex = [groupsTableView selectedRow];
if (selectedGroupIndex == -1) return; // no selection
//otherwise last row selected
[theExperiment deleteGroupAtIndex:(NSUInteger)selectedGroupIndex];
[groupsTableView reloadData];
//have to update group listings in subject table too
[self setGroupPopupMenu];
[subjectsTableView reloadData];
}
- (IBAction)addDrug:(id)sender {
NSLog(@" ExptInfo Add Drug Button pressed");
[theExperiment addNewDrug];
[drugsTableView reloadData];
}
- (IBAction)deleteDrug:(id)sender {
NSLog(@" ExptInfo Delete Drug pressed");
NSInteger selectedDrugIndex = [drugsTableView selectedRow];
if (selectedDrugIndex == -1) return; // no selection
//otherwise last row selected
[theExperiment deleteDrugAtIndex:(NSUInteger)selectedDrugIndex];
[drugsTableView reloadData];
}
// SUBJECTS *********************************************************************
-(IBAction)numberOfSubjectsChanged:(id)sender {
NSLog(@" number of Subjects Changed...");
[theExperiment setNumberOfSubjects: (NSUInteger)[exptSubjectsView integerValue]];
[subjectsTableView reloadData];
}
- (IBAction)assignGroupsAlternating:(id)sender {
NSLog(@" assign Groups Alternating Button pressed");
[theExperiment setAlternatingGroups];
[subjectsTableView reloadData];
}
- (IBAction)assignGroupsBlocks:(id)sender {
NSLog(@" assign Groups Blocks Button pressed");
[theExperiment setBlockGroups];
[subjectsTableView reloadData];
}
- (IBAction)printBarcodeLabels:(id)sender; {
// If you want users to be able to print a document, you must override printOperationWithSettings: error:, possibly providing a modified NSPrintInfo object.
// get page size from [self printInfo]
// NSRect paperRect = NSMakeRect(0,0,[[self printInfo] paperSize].width, [[self printInfo] paperSize].height);
// Obtain a custom view that will be printed
// NSView *printView = [[BCDailyDataWebView alloc] initWithDailyData:dailyData andTable:dailyTableView];
// put all the item codes into an array
NSMutableArray *itemCodes = [[NSMutableArray alloc] init];
for (BarItem *theItem in [theExperiment items]) {
[itemCodes addObject:[theItem code]];
}
BCBarcodeLabelsWebView *myWebView = [[BCBarcodeLabelsWebView alloc]
initWithExptCode:[theExperiment code]
andItemCodes:itemCodes
forSubjectsCount:[theExperiment numberOfSubjects]];
NSView *printView = [[[myWebView mainFrame] frameView] documentView];
// Construct the print operation and setup Print panel
// NSPrintOperation *printOp = [NSPrintOperation
// printOperationWithView:printView
// printInfo:[self printInfo]];
// don't pass NSDocument printInfo to printOp: printView will show up in printPanel preview but won't print
// maybe because printView is not associated with an actual NSDocument
NSPrintOperation *printOp = [NSPrintOperation printOperationWithView:printView];
while ([myWebView isLoading]) { [[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];}
[printOp runOperation];
// the rest of this is for modal print
//
// [printOp setShowsPrintPanel:showPanels];
//
// if (showPanels) {
// // Add accessory view, if needed
// }
//
//
//
// // Run operation, which shows the Print panel if showPanels was YES
//
// [self runModalPrintOperation:printOp
// delegate:self
// didRunSelector:@selector(documentDidRunModalPrintOperation:success:contextInfo:)
// contextInfo:NULL];
//
}
// PHASES *********************************************************************
- (IBAction)addPhase:(id)sender {
NSLog(@" ExptInfo Add Phase Button pressed");
[theExperiment addNewPhase];
[phasesTableView reloadData];
}
- (IBAction)deletePhase:(id)sender {
NSLog(@" ExptInfo Delete Phase pressed");
NSInteger selectedPhaseIndex = [phasesTableView selectedRow];
if (selectedPhaseIndex == -1) return; // no selection
//otherwise last row selected
[theExperiment deletePhaseAtIndex:(NSUInteger)selectedPhaseIndex];
[phasesTableView reloadData];
}
// ***************************************************************************************
// ***************************************************************************************
// Methods for getting Table Text for display in NSTableView dailyView
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
// Getting Values for the table
-(NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView {
if (theExperiment == nil) return 0;
if (aTableView == itemsTableView) return( (NSInteger)[theExperiment numberOfItems] );
else if (aTableView == groupsTableView) return( (NSInteger)[theExperiment numberOfGroups] );
else if (aTableView == drugsTableView) return( (NSInteger)[theExperiment numberOfDrugs] );
else if (aTableView == phasesTableView) return( (NSInteger)[theExperiment numberOfPhases] );
else if (aTableView == subjectsTableView) return( (NSInteger)[theExperiment numberOfSubjects] );
else if (aTableView == dailyDataTableView) return( (NSInteger)[theExperiment numberOfDays] );
return 0;
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
// should be able to use the identifier to get the value pretty directly...
NSObject *objectAtIndex = nil;
NSString *identifier = [aTableColumn identifier];
if (theExperiment == nil) return nil;
if (aTableView == subjectsTableView) {
}
else if (aTableView == dailyDataTableView) {
DailyData *theDay = [dailyDataArray objectAtIndex:(NSUInteger)rowIndex];
if ([identifier compare:@"dayIndex"] == NSOrderedSame) {
return [NSNumber numberWithLong:(rowIndex+1)];
}
else if ([identifier compare:@"onTime"] == NSOrderedSame) {
return [theDay shortTimeStringFromDate:[theDay onTime]];
}
else if ([identifier compare:@"offTime"] == NSOrderedSame) {
return [theDay shortTimeStringFromDate:[theDay offTime]];
}
else if ([identifier isEqualToString:@"phaseName"]) {
// return the menu index of the daily data's phase
NSString *phaseName = [theDay phaseName];
NSInteger itemIndex = [[aTableColumn dataCell] indexOfItemWithTitle:phaseName];
return [NSNumber numberWithLong:itemIndex];
// try returning the pop menu
// [groupPopupMenu selectItemAtIndex:[theExperiment indexOfGroupOfSubjectAtIndex:rowIndex]];
// return groupPopupMenu;
}
else if ([identifier compare:@"phaseDay"] == NSOrderedSame) {
return [NSNumber numberWithLong:[theDay phaseDayIndex]];
}
else if ([identifier compare:@"comment"] == NSOrderedSame) {
return [theDay comment];
}
}
else {
if (aTableView == itemsTableView) {
objectAtIndex = (NSObject *)[theExperiment itemAtIndex:(NSUInteger)rowIndex];
}
else if (aTableView == groupsTableView) {
objectAtIndex = (NSObject *)[theExperiment groupAtIndex:(NSUInteger)rowIndex];
}
else if (aTableView == drugsTableView) {
objectAtIndex = (NSObject *)[theExperiment drugAtIndex:(NSUInteger)rowIndex];
}
else if (aTableView == phasesTableView) {
objectAtIndex = (NSObject *)[theExperiment phaseAtIndex:(NSUInteger)rowIndex];
}
return [objectAtIndex valueForKey:identifier];
}
return nil;
}
// Setting Values
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
// should be able to use the identifier to get the value pretty directly...
NSObject *barObjectAtIndex = nil;
NSString *identifier = [aTableColumn identifier];
// just assume that only strings are being set by the table...
if (theExperiment == nil) { return; }
if (aTableView == itemsTableView) {
barObjectAtIndex = (BarObject *)[theExperiment itemAtIndex:(NSUInteger)rowIndex];
[barObjectAtIndex setValue:anObject forKey:identifier];
}
else if (aTableView == groupsTableView) {
barObjectAtIndex = (BarObject *)[theExperiment groupAtIndex:(NSUInteger)rowIndex];
[barObjectAtIndex setValue:anObject forKey:identifier];
//have to update group listings in subject table too
[self setGroupPopupMenu];
[subjectsTableView reloadData];
}
else if (aTableView == drugsTableView) {
barObjectAtIndex = (BarObject *)[theExperiment drugAtIndex:(NSUInteger)rowIndex];
[barObjectAtIndex setValue:anObject forKey:identifier];
}
else if (aTableView == phasesTableView) {
barObjectAtIndex = (BarObject *)[theExperiment phaseAtIndex:(NSUInteger)rowIndex];
[barObjectAtIndex setValue:anObject forKey:identifier];
}
else if (aTableView == subjectsTableView) {
// barObjectAtIndex = (BarObject *)[theExperiment subjectAtIndex:rowIndex];
if ([identifier isEqualToString:@"groupName"]) {
// the objects intValue is the index of the selected pop-up menu item
int groupIndexFromObject = [anObject intValue];
if (0 <= groupIndexFromObject && groupIndexFromObject < (NSInteger)[theExperiment numberOfGroups]) {
[[theExperiment subjectAtIndex:(NSUInteger)rowIndex] setGroupIndex:(NSUInteger)groupIndexFromObject];
// NSPopUpButtonCell *popupCell = [aTableColumn dataCell];
// [popupCell selectItemAtIndex:groupIndexFromObject];
// [subjectsTableView reloadData];
}
}
}
else if (aTableView == dailyDataTableView) {
// barObjectAtIndex = (BarObject *)[theExperiment subjectAtIndex:rowIndex];
if ([identifier isEqualToString:@"phaseName"]) {
// the objects intValue is the index of the selected pop-up menu item
int phaseIndexFromObject = [anObject intValue];
if (0 <= phaseIndexFromObject && phaseIndexFromObject < (NSInteger)[theExperiment numberOfPhases]) {
[[dailyDataArray objectAtIndex:(NSUInteger)rowIndex] setPhaseName:[theExperiment nameOfPhaseAtIndex:(NSUInteger)phaseIndexFromObject]];
[[dailyDataArray objectAtIndex:(NSUInteger)rowIndex] setCurrentState:kUserEditing];
[[dailyDataArray objectAtIndex:(NSUInteger)rowIndex] setPhaseDayIndex:0];
[(DailyData *)[dailyDataArray objectAtIndex:(NSUInteger)rowIndex] save];
// tell the daily data to save itself
}
}
}
}
// display the cell (used to display pop-up menu item for group assignment in subjectsTableView
-(void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
{
if (aTableView == subjectsTableView) {
if ([[aTableColumn identifier] isEqualToString:@"groupName"]) {
if ([aCell isKindOfClass:[NSPopUpButtonCell class]]) {
NSString *title = [theExperiment nameOfGroupOfSubjectAtIndex:(NSUInteger)rowIndex];
[aCell setTitle:title];
}
}
else if ([[aTableColumn identifier] isEqualToString:@"subjectName"]) {
NSString *title = [theExperiment nameOfSubjectAtIndex:(NSUInteger)rowIndex];
[aCell setTitle:title];
}
}
if (aTableView == dailyDataTableView) {
if ([[aTableColumn identifier] isEqualToString:@"phaseName"]) {
if ([aCell isKindOfClass:[NSPopUpButtonCell class]]) {
NSString *title = [theExperiment nameOfPhaseOfDay:(NSUInteger)rowIndex];
[aCell setTitle:title];
}
}
}
}
//Dragging
//– tableView:acceptDrop:row:dropOperation:
//– tableView:namesOfPromisedFilesDroppedAtDestination:forDraggedRowsWithIndexes:
//– tableView:validateDrop:proposedRow:proposedDropOperation:
//– tableView:writeRowsWithIndexes:toPasteboard:
// Sorting
//– tableView:sortDescriptorsDidChange:
// data view
// -(IBAction)selectPath:(id)sender; {
//
// NSLog(@" ExptInfo selectPath Button pressed");
//
//
// NSOpenPanel *openPanel;
// NSInteger result;
//
// /* create or get the shared instance of NSSavePanel */
// openPanel = [NSOpenPanel openPanel];
//
// /* set up new attributes */
// [openPanel setAllowedFileTypes:[NSArray arrayWithObjects:@"txt",nil]];
//
// // set to the document directory
//
// NSString *docDirectoryPath = GetDocDirectoryPath();
//
// NSURL * docDirectoryURL = [NSURL fileURLWithPath:docDirectoryPath] ;
// [openPanel setDirectoryURL:docDirectoryURL ];
//
// // just select a directory
// [openPanel setCanChooseFiles:NO];
// [openPanel setCanChooseDirectories:YES];
// [openPanel setCanCreateDirectories:YES];
//
//
// /*prompt */
// [openPanel setPrompt:@"Location for Summary Data Backup"];
//
// /* display the NSSavePanel */
// result = [openPanel runModal];
//
// if (result == NSOKButton) {
//
// NSString *myFilePath = [[openPanel filename] copy];
//
// // save the experiment, but as a template...
//// [backupSummaryPathView setStringValue:myFilePath];
//
// }
//
//
// }
-(void)handleDailyDataDoubleClick:(id)sender; {
// what is the currently selected row of the table view?
NSInteger selectedRowIndex = [dailyDataTableView selectedRow];
if (selectedRowIndex == -1) return; // no row is currently selected
// create a new DailyData Document for ON weights with window, etc..
DailyDataDocument *theDailyDataDoc = [bartender openDailyData];
[theDailyDataDoc startEditingDailyDay:selectedRowIndex WithTheExperiment: theExperiment];
}
@end
//
//
//- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
//{
// if ([[aTableColumn identifier] isEqualToString:LXDetailItemDataType])
// {
// NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
// NSString *title = [rowDictionary objectForKey:LXDetailItemDataType];
//
// NSLog(@"objectValueForTableColumn: %@", title); //DEBUG
//
// return [NSNumber numberWithInt:[[aTableColumn dataCell] indexOfItemWithTitle:title]];
// }
// else if ([[aTableColumn identifier] isEqualToString:LXDetailItemDevice])
// {
// NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
// NSString *title = [rowDictionary objectForKey:LXDetailItemDevice];
//
// NSLog(@"objectValueForTableColumn: %@", title); //DEBUG
//
// return [NSNumber numberWithInt:[[aTableColumn dataCell] indexOfItemWithTitle:title]];
// }
// else
// {
// NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
// return [rowDictionary objectForKey:[aTableColumn identifier]];
// }
//}
//
//
//- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
//{
// if ([[aTableColumn identifier] isEqualToString:LXDetailItemDataType])
// {
// NSMenuItem *menuItem = [[aTableColumn dataCell] itemAtIndex:[anObject integerValue]];
//
// NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
//
// NSLog(@"%@", [menuItem title]); //DEBUG
//
// //Update the object value at the column index
// [rowDictionary setObject:[menuItem title] forKey:LXDetailItemDataType];
// }
// else if ([[aTableColumn identifier] isEqualToString:LXDetailItemDevice])
// {
// NSMenuItem *menuItem = [[aTableColumn dataCell] itemAtIndex:[anObject integerValue]];
//
// NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
//
// NSLog(@"%@", [menuItem title]); //DEBUG
//
// //Update the object value at the column index
// [rowDictionary setObject:[menuItem title] forKey:LXDetailItemDevice];
// }
// else
// {
// //Get the row
// NSMutableDictionary *rowDictionary = [tableContents objectAtIndex:rowIndex];
//