forked from youknowone/VisualJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVJDocument.m
More file actions
716 lines (573 loc) · 22.6 KB
/
VJDocument.m
File metadata and controls
716 lines (573 loc) · 22.6 KB
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
//
// VJDocument.m
// VisualJSON
//
// Created by 2012 youknowone.org on 12. 6. 4..
// Copyright (c) 2012 youknowone.org. All rights reserved.
//
#import "VJDocument.h"
#import "VJRequest.h"
#import "VJJsonDocumentDelegate.h"
#import "VJXMLDocumentDelegate.h"
#import "VJDocumentHistory.h"
#import <AFNetworking/AFURLConnectionOperation.h>
@interface VJDocument()
- (BOOL)setMetadataForStoreAtURL:(NSURL *)URL;
@end
@implementation VJDocument
@synthesize delegate=_delegate;
@synthesize headerItems=_headerItems, querydataItems=_querydataItems;
@synthesize addressComboBox=_addressComboBox, methodMatrix=_methodMatrix, methodTextField=_methodTextField, querydataTextField=_querydataTextField, contentTextView=_contentTextView;
@synthesize dataOutlineView=_dataOutlineView, dataTextView=_dataTextView;
@synthesize drawer=_drawer;
@synthesize querydataTableView=_querydataTableView, querydataTextView=_querydataTextView, headerTableView=_headerTableView, headerTextField=_headerTextField;
@synthesize circularProgressIndicator=_circularProgressIndicator;
@synthesize data=_data;
- (NSString *)defaultHeader {
#if defined(JSON)
return @"Accept:application/json#!;#!;Content-Type:application/json";
#elif defined(XML)
return @"Accept:text/xml#!;#!;Content-Type:text/xml";
#else
#error define JSON or XML
#endif
}
- (void)awakeFromNib {
[super awakeFromNib];
self.querydata = self.request.querydata;
self.method = self.request.method;
self.header = self.request.header;
}
- (NSString *)address {
return self->_addressComboBox.stringValue;
}
- (void)setAddress:(NSString *)address {
if (address == nil) address = @"";
self->_addressComboBox.stringValue = address;
if ([self.request.address isEqualToString:address]) return;
self.request.address = address;
}
- (NSString *)header {
return self->_header;
}
- (void)setHeader:(NSString *)header {
if (header == nil) header = self.defaultHeader;
[self->_header autorelease];
self->_header = [header retain];
if ([self.request.header isEqualToString:header]) return;
self.request.header = header;
self.headerTextField.stringValue = header;
[self->_headerItems release];
NSMutableArray *headerItems = [[NSMutableArray alloc] init];
for (NSString *item in [self.header componentsSeparatedByString:@"#!;#!;"]) {
NSRange delimeterRange = [item rangeOfString:@":"];
NSString *field, *value = @"";
if (delimeterRange.location == NSNotFound) {
field = item;
} else {
field = [item substringToIndex:delimeterRange.location];
value = [item substringFromIndex:delimeterRange.location + delimeterRange.length];
}
[headerItems addObject:[NSAMutableTuple tupleWithFirst:field second:value]];
}
self->_headerItems = headerItems;
[self.headerTableView reloadData];
}
- (NSString *)method {
return self->_method;
}
- (void)setMethod:(NSString *)method {
if (method == nil) method = @"GET";
[self->_method autorelease];
self->_method = [method retain];
if ([self.request.method isEqualToString:method]) return;
self.request.method = method;
self.methodTextField.stringValue = method;
NSInteger index = [@[@"GET", @"POST", @"PUT", @"DELETE"] indexOfObject:method];
if (index < 0) index = 0;
[self.methodMatrix selectCellAtRow:0 column:index];
}
- (NSString *)querydata {
return self->_querydata;
}
- (void)setQuerydata:(NSString *)data {
if (data == nil) data = @"";
[self->_querydata autorelease];
self->_querydata = [data retain];
if ([self.request.querydata isEqualToString:data]) return;
self.request.querydata = data;
[self->_querydataItems release];
NSMutableArray *items = [[NSMutableArray alloc] init];
for (NSString *item in [self.querydata componentsSeparatedByString:@"&"]) {
NSRange delimeterRange = [item rangeOfString:@"="];
NSString *field, *value;
if (delimeterRange.location != NSNotFound) {
field = [item substringToIndex:delimeterRange.location];
value = [item substringFromIndex:delimeterRange.location + delimeterRange.length];
} else {
field = nil;
value = item;
}
[items addObject:[NSAMutableTuple tupleWithFirst:field second:value]];
}
self->_querydataItems = items;
self->_querydataTextField.stringValue = data;
self->_querydataTextView.string = data;
[self->_querydataTableView reloadData];
}
- (NSString *)content {
return self->_contentTextView.string;
}
- (void)setContent:(NSString *)content {
if (content == nil) content = @"";
self->_contentTextView.string = content;
if ([self.request.content isEqualToString:content]) return;
self.request.content = content;
}
- (void)dealloc {
[self->_header release];
[self->_method release];
[self->_querydata release];
[self->_headerItems release];
[self->_querydataItems release];
self.request = nil;
self.drawer = nil;
self.delegate = nil;
[super dealloc];
}
- (void)addressComboBoxChanged:(id)sender {
self.address = [sender stringValue];
[self refresh:sender];
}
- (IBAction)methodMatrixChanged:(id)sender {
NSMatrix *methodMatrix = sender;
NSDictionary *methods = @{@0 : @"GET", @1: @"POST", @2: @"PUT", @3: @"DELETE"};
self.method = [methods objectForKey:[NSNumber numberWithInteger:methodMatrix.selectedColumn]];
[self refresh:sender];
}
- (void)methodTextFieldChanged:(id)sender {
self.method = [sender stringValue];
}
- (void)querydataTextFieldChanged:(id)sender {
self.querydata = [sender stringValue];
[self refresh:sender];
}
- (void)headerTextFieldChanged:(id)sender {
self.header = [sender stringValue];
}
- (void)setDefaultHeader:(id)sender {
self.header = self.defaultHeader;
[self refresh:sender];
}
#pragma mark - NSPersistentDocument methods
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return @"VJDocument";
}
- (id)initWithType:(NSString *)typeName error:(NSError **)outError {
self = [super initWithType:typeName error:outError];
if (self != nil) {
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
self.request = [NSEntityDescription insertNewObjectForEntityForName:@"Request"
inManagedObjectContext:managedObjectContext];
// To avoid undo registration for this insertion, removeAllActions on the undoManager.
// First call processPendingChanges on the managed object context to force the undo registration
// for this insertion, then call removeAllActions.
[managedObjectContext processPendingChanges];
[managedObjectContext.undoManager removeAllActions];
[self updateChangeCount:NSChangeCleared];
self->visualizeThread = [[NSThread alloc] initWithTarget:self selector:@selector(visualizeBackground) object:nil];
}
return self;
}
- (VJRequest *)request {
if (self->_request == nil) {
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSError *fetchError = nil;
NSArray *fetchResults;
@try {
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Request" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
fetchResults = [context executeFetchRequest:fetchRequest error:&fetchError];
}
@finally {
[fetchRequest release];
}
if ((fetchResults != nil) && (fetchResults.count == 1) && (fetchError == nil)) {
self.request = [fetchResults objectAtIndex:0];
}
else if (fetchError != nil) {
[self presentError:fetchError];
}
else {
// should present custom error message...
}
}
return self->_request;
}
- (void)setRequest:(VJRequest *)request {
[self->_request autorelease];
self->_request = [request retain];
}
-(BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation originalContentsURL:(NSURL *)absoluteOriginalContentsURL error:(NSError **)error {
// needed -- configure not called for writing existing document
if (self.fileURL != nil)
{
[self setMetadataForStoreAtURL:self.fileURL];
}
return [super writeToURL:absoluteURL ofType:typeName
forSaveOperation:saveOperation
originalContentsURL:absoluteOriginalContentsURL
error:error];
}
- (BOOL)configurePersistentStoreCoordinatorForURL:(NSURL *)url ofType:(NSString *)fileType modelConfiguration:(NSString *)configuration storeOptions:(NSDictionary *)storeOptions error:(NSError **)error {
dlog(TRUE, @"url: %@, type: %@", url, fileType);
BOOL ok = [super configurePersistentStoreCoordinatorForURL:url ofType:fileType modelConfiguration:configuration storeOptions:storeOptions error:error];
if (ok)
{
NSPersistentStoreCoordinator *coordinator = self.managedObjectContext.persistentStoreCoordinator;
id pStore = [coordinator persistentStoreForURL:url];
// configurePersistentStoreCoordinatorForURL is called when document reopened
// Check for existing metadata to avoid overwriting unnecessarily
id existingMetadata = [[coordinator metadataForPersistentStore:pStore] objectForKey:(NSString *)kMDItemKeywords];
if (existingMetadata == nil)
{
ok = [self setMetadataForStoreAtURL:url];
}
}
return ok;
}
- (BOOL)setMetadataForStoreAtURL:(NSURL *)url
{
NSPersistentStoreCoordinator *coordinator = self.managedObjectContext.persistentStoreCoordinator;
id pStore = [coordinator persistentStoreForURL:url];
NSString *uniqueKey = [NSString stringWithFormat:@"%@:%@:%@:%@:%@", self.request.address, self.method, self.request.querydata, self.request.header, self.request.content];
if ((pStore != nil) && (uniqueKey != nil))
{
// metadata auto-configured with NSStoreType and NSStoreUUID
NSMutableDictionary *metadata = [[coordinator metadataForPersistentStore:pStore] mutableCopy];
[metadata setObject:[NSArray arrayWithObject:uniqueKey] forKey:(NSString *)kMDItemKeywords];
[coordinator setMetadata:metadata forPersistentStore:pStore];
[metadata release];
return YES;
}
return NO;
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document's window.
[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(visualize:) userInfo:nil repeats:NO]; // rough waiting to load document
}
- (NSPrintOperation *)printOperationWithSettings:(NSDictionary *)printSettings error:(NSError **)outError {
NSPrintOperation *printOperation = [NSPrintOperation printOperationWithView:self.dataTextView];
return printOperation;
}
//+ (BOOL)autosavesInPlace
//{
// return YES;
//}
- (void)refresh:(id)sender {
if (self.address.length == 0) return;
[self.circularProgressIndicator startAnimation:nil];
if (self->refreshThread) {
[self->refreshThread cancel];
[self->refreshThread release];
}
self->refreshThread = [[NSThread alloc] initWithTarget:self selector:@selector(refreshBackground) object:nil];
[self->refreshThread start];
}
- (void)refreshBackground {
@autoreleasepool {
if (self->tempContent) {
id x = self->tempContent;
self->tempContent = nil;
[x release];
}
NSString *address = self.address;
if (self.querydata.length && (self.method.length == 0 || [self.method isEqualToString:@"GET"])) {
address = [address stringByAppendingFormat:@"?%@", self.querydata];
}
// decide local or remote
NSURL *URL = [address hasPrefix:@"/"] ? address.fileURL : address.URL;
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:URL];
for (NSAMutableTuple *item in self.headerItems) {
if ([item.first length] == 0) continue;
[req addValue:item.second forHTTPHeaderField:item.first];
}
if (self.method && ![self.method isEqualToString:@"GET"]) {
[req setHTTPMethod:self.method];
[req setHTTPBody:self.querydata.dataUsingUTF8Encoding];
}
AFURLConnectionOperation *operation = [[AFURLConnectionOperation alloc] initWithRequest:req];
[operation setAuthenticationAgainstProtectionSpaceBlock:^BOOL(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace) {
NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"ShouldAllowInvalidSSLCertificates"];
BOOL allowInvalid = value.boolValue;
return allowInvalid;
}];
[operation setAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) {
NSNumber *value = [[NSUserDefaults standardUserDefaults] objectForKey:@"ShouldAllowInvalidSSLCertificates"];
BOOL allowInvalid = value.boolValue;
if (allowInvalid) {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
} else {
[challenge.sender cancelAuthenticationChallenge:challenge];
}
}];
[operation setCompletionBlock:^{
// set content field with data
NSError *error = operation.error;
NSData *data = operation.responseData;
if (data != nil && error == nil) {
tempContent = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (tempContent == nil) {
tempContent = [error retain];
}
} else {
tempContent = [error retain];
}
[self performSelectorOnMainThread:@selector(refreshFinished) withObject:nil waitUntilDone:NO];
}];
[operation start];
}
}
- (void)refreshFinished {
if (tempContent == nil) return;
if ([tempContent isKindOfClass:[NSError class]]) {
self.content = [NSString stringWithFormat:@"Error on getting raw data text: %@", tempContent];
} else {
self.content = tempContent;
[self visualize:nil];
}
id x = tempContent;
tempContent = nil;
[x release];
[self.circularProgressIndicator stopAnimation:nil];
[[VJDocumentHistory defaultHistory] addHistory:self.address];
[self.addressComboBox reloadData];
[[VJDocumentHistory defaultHistory] performSelectorInBackground:@selector(synchronize) withObject:NULL];
}
- (void)visualize:(id)sender {
if (self->visualizeThread) {
[self->visualizeThread cancel];
[self->visualizeThread release];
}
self->visualizeThread = [[NSThread alloc] initWithTarget:self selector:@selector(visualizeBackground) object:nil];
[self->visualizeThread start];
}
- (void)visualizeBackground {
id x = nil;
@synchronized(self) {
if (tempData) {
x = tempData;
tempData = nil;
}
}
if (x) {
[x release];
}
if ([[VJXMLDocumentDelegate sharedObject] document:self dataIsValid:self.content]) {
self.delegate = [VJXMLDocumentDelegate sharedObject];
} else {
self.delegate = [VJJsonDocumentDelegate sharedObject];
}
x = [[self.delegate document:self structuredDataFromRawDataString:self.content] retain];
@synchronized(self) {
tempData = x;
}
[self performSelectorOnMainThread:@selector(visualizeFinished) withObject:nil waitUntilDone:NO];
}
- (void)visualizeFinished {
@synchronized(self) {
self.data = tempData;
[tempData release];
tempData = nil;
}
[self.dataOutlineView reloadData];
self.dataTextView.string = [self.delegate document:self prettyTextFromData:self.data];
}
- (void)toggleDrawer:(id)sender {
[self.drawer toggle:sender];
}
- (void)openWebsite:(id)sender {
NSURL *URL = @"http://youknowone.github.com/VisualJSON#help".URL;
[[NSWorkspace sharedWorkspace] openURL:URL];
}
- (NSString *)title {
return self.address;
}
#pragma mark - combobox delegate
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox {
return [[VJDocumentHistory defaultHistory] count];
}
- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index {
return [[VJDocumentHistory defaultHistory] itemAtIndex:index].address;
}
#pragma mark - text view changed
- (void)textDidChange:(NSNotification *)notification {
self.content = self.contentTextView.string;
[self visualize:self.contentTextView];
}
#pragma mark - outline delegate for 'tree' view
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
if (item == nil) {
return 1;
}
return (NSInteger)[self.delegate document:self outlineChildrenCountForItem:item];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
if (item == nil) {
return YES;
}
return [self.delegate document:self outlineIsItemExpandable:item];
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
if (item == nil) {
return self.data;
}
return [self.delegate document:self outlineChild:index ofItem:item];
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
if (item == nil) item = self.data;
NSString *title = [tableColumn.headerCell title];
if ([title isEqualToString:@"node"]) {
return [self.delegate document:self outlineTitleForItem:item];
} else if ([title isEqualToString:@"description"]) {
return [self.delegate document:self outlineDescriptionForItem:item];
} else {
dassert(NO);
}
return nil;
}
@end
#pragma mark -
@implementation VJHeaderTableViewController
- (NSString *)_headerFromHeaderItems {
NSMutableArray *array = [[NSMutableArray alloc] init];
for (NSAMutableTuple *tuple in self->document.headerItems) {
NSString *item = tuple.first ? [NSString stringWithFormat:@"%@:%@", tuple.first, tuple.second] : tuple.second;
[array addObject:item];
}
NSString *result = [array componentsJoinedByString:@"#!;#!;"];
[array release];
return result;
}
- (void)addRow:(id)sender {
NSInteger index = tableView.selectedRow;
NSAMutableTuple *newItem = [NSAMutableTuple tupleWithFirst:@"field" second:@"value"];
if (index < 0) {
[self->document.headerItems addObject:newItem];
} else {
[self->document.headerItems insertObject:newItem atIndex:index];
}
self->document.header = [self _headerFromHeaderItems];
}
- (void)removeRow:(id)sender {
NSUInteger index = tableView.selectedRow;
if (index == NSNotFound) return;
[self->document.headerItems removeObjectAtIndex:index];
self->document.header = [self _headerFromHeaderItems];
}
#pragma mark table view delegate
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return self->document.headerItems.count;
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSAMutableTuple *item = [self->document.headerItems objectAtIndex:row];
switch ([aTableView.tableColumns indexOfObjectIdenticalTo:tableColumn]) {
case 0:
return item.first;
case 1:
return item.second;
default:
dassert(NO);
break;
}
dassert(NO);
return nil;
}
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSAMutableTuple *tuple = [self->document.headerItems objectAtIndex:row];
switch ([aTableView.tableColumns indexOfObjectIdenticalTo:tableColumn]) {
case 0:
tuple.first = object;
break;
case 1:
tuple.second = object;
break;
default:
dassert(NO);
break;
}
self->document.header = [self _headerFromHeaderItems];
}
@end
#pragma mark -
@implementation VJQuerydataTableViewController
- (NSString *)_querydataFromQuerydataItems {
NSMutableArray *array = [[NSMutableArray alloc] init];
for (NSAMutableTuple *tuple in self->document.querydataItems) {
NSString *item = tuple.first ? [NSString stringWithFormat:@"%@=%@", tuple.first, tuple.second] : tuple.second;
[array addObject:item];
}
NSString *result = [array componentsJoinedByString:@"&"];
[array release];
return result;
}
- (void)addRow:(id)sender {
NSInteger index = tableView.selectedRow;
NSAMutableTuple *newItem = [NSAMutableTuple tupleWithFirst:nil second:@""];
if (index < 0) {
[self->document.querydataItems addObject:newItem];
} else {
[self->document.querydataItems insertObject:newItem atIndex:index];
}
self->document.querydata = [self _querydataFromQuerydataItems];
}
- (void)removeRow:(id)sender {
NSUInteger index = tableView.selectedRow;
if (index == NSNotFound) return;
[self->document.querydataItems removeObjectAtIndex:index];
self->document.querydata = [self _querydataFromQuerydataItems];
}
#pragma mark text view delegate
- (void)textDidEndEditing:(NSNotification *)notification {
self->document.querydata = self->textView.string;
}
#pragma mark table view delegate
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return self->document.querydataItems.count;
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSAMutableTuple *item = [self->document.querydataItems objectAtIndex:row];
switch ([aTableView.tableColumns indexOfObjectIdenticalTo:tableColumn]) {
case 0:
return item.first;
case 1:
return item.second;
default:
dassert(NO);
break;
}
dassert(NO);
return nil;
}
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSAMutableTuple *tuple = [self->document.querydataItems objectAtIndex:row];
switch ([aTableView.tableColumns indexOfObjectIdenticalTo:tableColumn]) {
case 0:
tuple.first = object;
break;
case 1:
tuple.second = object;
break;
default:
dassert(NO);
break;
}
self->document.querydata = [self _querydataFromQuerydataItems];
}
@end