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
|
/**
TableViewController.m <title>EOMEDocument Class</title>
Copyright (C) Free Software Foundation, Inc.
Author: David Wetzel <dave@turbocat.de>
Date: 2010
This file is part of EOModelEditor.
<license>
EOModelEditor is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
EOModelEditor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with EOModelEditor; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
</license>
**/
#import "TableViewController.h"
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#ifndef GNUSTEP
#import <GNUstepBase/GNUstep.h>
#endif
@implementation TableViewController
- (void) dealloc
{
DESTROY(_boolColumnNames);
[super dealloc];
}
- (id) init
{
self = [super init];
if (self != nil) {
ASSIGN(_boolColumnNames, [NSMutableSet set]);
}
return self;
}
- (NSArray*) selectedObjects
{
NSMutableArray * array = [NSMutableArray array];
NSArray * repObject = [self representedObject];
if (_tableView) {
NSIndexSet * selectedIndexes = nil;
selectedIndexes = [_tableView selectedRowIndexes];
if ([selectedIndexes count] > 0) {
NSUInteger currentIdx = [selectedIndexes firstIndex];
[array addObject:[repObject objectAtIndex:currentIdx]];
while ((currentIdx = [selectedIndexes indexGreaterThanIndex:currentIdx]) && (currentIdx != NSNotFound))
{
[array addObject:[repObject objectAtIndex:currentIdx]];
}
}
}
return array;
}
- (void) addToBoolColumnNames:(NSString *) aValue
{
[_boolColumnNames addObject:aValue];
}
- (NSSet*) boolColumnNames
{
return _boolColumnNames;
}
// representedObject should be anArray like the attributes of an EOEntity
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
NSArray * representedObject = (NSArray*) [self representedObject];
_tableView = aTableView;
if (!representedObject) {
return 0;
}
return [representedObject count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)column
row:(NSInteger)row
{
NSArray * representedObject = (NSArray*) [self representedObject];
id obj, value, identifier;
if (!representedObject) {
return nil;
}
obj = [representedObject objectAtIndex:row];
identifier = [column identifier];
// special case to support row numbering
if ([identifier isEqual:@"_#number"]) {
return [NSNumber numberWithInteger:row];
}
value = [obj valueForKeyPath:identifier];
if ([_boolColumnNames containsObject:identifier]) {
return [NSNumber numberWithInteger:([value boolValue] ? NSOnState : NSOffState)];
}
return value;
}
- (void)tableView:(NSTableView *)tableView
setObjectValue:(id)value
forTableColumn:(NSTableColumn *)column
row:(NSInteger)row
{
id obj = [[self representedObject] objectAtIndex:row];
NSString * identifier = [column identifier];
NSNotificationCenter * defaultCenter = [NSNotificationCenter defaultCenter];
id oldVaue = [obj valueForKeyPath:identifier];
id newValue = value;
NSDictionary * userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
(oldVaue) ? oldVaue : [NSNull null], @"oldValue",
(newValue) ? newValue : [NSNull null], @"newValue",
identifier, @"keyPath",
nil];
[obj setValue:value
forKeyPath:identifier];
[defaultCenter postNotificationName:TableViewDataHasChangedNotification
object:self
userInfo:userInfo];
}
@end
|