diff --git a/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate b/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate index 642b36d5ce6d7edce83cc9b574ac29d2fda45f75..678d6e0e3bb9192da8830418438bbd8dca25e820 100644 Binary files a/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate and b/openbis-ipad/openBIS/openBIS.xcodeproj/project.xcworkspace/xcuserdata/cramakri.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.h b/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.h index d5c94bcbad144c6e0379bbd3cdbe1e8c14ddba2d..dc311b9042b30c2244c08252e524a1d40bb3af89 100644 --- a/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.h +++ b/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.h @@ -24,16 +24,62 @@ #import <UIKit/UIKit.h> @class CISDOBDetailViewController, CISDOBOpenBisModel, CISDOBIpadServiceManager; +@class CISDOBTableBrowseState, CISDOBTableFilterState, CISDOBTableDisplayState; #import <CoreData/CoreData.h> -@interface CISDOBMasterViewController : UITableViewController <NSFetchedResultsControllerDelegate, UISearchBarDelegate> +@interface CISDOBMasterViewController : UITableViewController <NSFetchedResultsControllerDelegate, UISearchBarDelegate, UISearchDisplayDelegate> @property (strong, nonatomic) CISDOBDetailViewController *detailViewController; @property (strong, nonatomic) CISDOBOpenBisModel *openBisModel; -@property (weak, nonatomic) IBOutlet UISearchBar *searchBar; +@property (strong, nonatomic) CISDOBTableBrowseState *browseState; +@property (strong, nonatomic) CISDOBTableFilterState *filterState; + +@property (weak, nonatomic) IBOutlet UITableView *browseTableView; // Server Communication - (void)didConnectServiceManager:(CISDOBIpadServiceManager *)serviceManager; +// Table Display +- (CISDOBTableDisplayState *)displayStateForTable:(UITableView *)tableView; + +@end + +/** + * \brief An abstract superclass that handles interacting with and displaying the table + */ +@interface CISDOBTableDisplayState : NSObject + +@property (strong, nonatomic) CISDOBOpenBisModel *openBisModel; +@property (weak, nonatomic) CISDOBMasterViewController *controller; + +- (id)initWithController:(CISDOBMasterViewController *)controller; + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section; +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; + @end + +/** + * \brief The state that handles results for browing. + */ +@interface CISDOBTableBrowseState : CISDOBTableDisplayState + + +@end + +/** + * \brief The state that handles results for filtering. + */ +@interface CISDOBTableFilterState : CISDOBTableDisplayState + +@property (strong, nonatomic) NSArray *filteredResults; + +- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString; + +@end + + diff --git a/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.m b/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.m index a1400af5e842cd68b84175e6aaffc22f59ae49b8..dd9363ad8e54f00f0815025d393cab986677e077 100644 --- a/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.m +++ b/openbis-ipad/openBIS/openBIS/CISDOBMasterViewController.m @@ -29,7 +29,9 @@ @interface CISDOBMasterViewController () - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath; +- (void)configureCell:(UITableViewCell *)cell forEntity:(CISDOBIpadEntity *)entity; - (void)initializeDrillDownFromParent:(CISDOBMasterViewController *)parent; +- (void)selectionDidChangeForModel; @end @implementation CISDOBMasterViewController @@ -54,6 +56,9 @@ // UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)]; // self.navigationItem.rightBarButtonItem = addButton; self.detailViewController = (CISDOBDetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController]; + self.browseState = [[CISDOBTableBrowseState alloc] initWithController: self]; + self.filterState = [[CISDOBTableFilterState alloc] initWithController: self]; + } - (void)didReceiveMemoryWarning @@ -72,31 +77,32 @@ } } +- (CISDOBTableDisplayState *)displayStateForTable:(UITableView *)tableView +{ + return (tableView == self.browseTableView) ? self.browseState : self.filterState; +} + #pragma mark - Table View - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return [self.openBisModel numberOfSections]; + return [[self displayStateForTable: tableView] numberOfSectionsInTableView: tableView]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return [self.openBisModel numberOfEntitiesInSection: section]; + return [[self displayStateForTable: tableView] tableView: tableView numberOfRowsInSection: section]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; // This only works in iOS 6, -// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; // iOS5 - [self configureCell:cell atIndexPath:indexPath]; - return cell; + return [[self displayStateForTable: tableView] tableView: tableView cellForRowAtIndexPath: indexPath]; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - return [self.openBisModel titleForHeaderInSection: section]; + return [[self displayStateForTable: tableView] tableView: tableView titleForHeaderInSection: section]; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath @@ -127,8 +133,11 @@ // Segue to the detail view unless we are on the ipad if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPad) return; - [self.openBisModel selectObjectAtIndexPath: indexPath]; + [[self displayStateForTable: tableView] tableView: tableView didSelectRowAtIndexPath: indexPath]; +} +- (void)selectionDidChangeForModel +{ // Figure out what to do with the detail view and the navigation view self.detailViewController.openBisModel = self.openBisModel; if ([self.openBisModel selectionHasChildren]) { @@ -155,10 +164,15 @@ - (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { - CISDOBIpadEntity *object = [self.openBisModel objectAtIndexPath: indexPath]; - cell.textLabel.text = object.summaryHeader; - cell.detailTextLabel.text = object.summary; - if ([self.openBisModel entityHasChildren: object]) { + CISDOBIpadEntity *entity = [self.openBisModel objectAtIndexPath: indexPath]; + [self configureCell: cell forEntity: entity]; +} + +- (void)configureCell:(UITableViewCell *)cell forEntity:(CISDOBIpadEntity *)entity +{ + cell.textLabel.text = entity.summaryHeader; + cell.detailTextLabel.text = entity.summary; + if ([self.openBisModel entityHasChildren: entity]) { cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } else { cell.accessoryType = UITableViewCellAccessoryNone; @@ -227,32 +241,10 @@ } */ -#pragma mark - UISearchBarDelegate -- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar -{ - // TODO Put the controller in search mode - NSLog(@"searchBarTextDidBeginEditing:"); - searchBar.showsCancelButton = YES; -} - -- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar -{ - // TODO Figure out what to do here - NSLog(@"searchBarTextDidEndEditing:"); -} - -- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText -{ - // TODO Update the results - NSLog(@"searchBar:textDidChange:"); -} - -- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar +#pragma mark - UISearchDisplayDelegate +- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { - // TODO Take the controller out of search mode - searchBar.showsCancelButton = NO; - [self.searchBar resignFirstResponder]; - [self.tableView becomeFirstResponder]; + return [self.filterState searchDisplayController: controller shouldReloadTableForSearchString: searchString]; } #pragma mark - Server Communication @@ -265,7 +257,6 @@ #pragma mark - Properties - - (void)setOpenBisModel:(CISDOBOpenBisModel *)openBisModel { _openBisModel = openBisModel; @@ -279,4 +270,113 @@ self.title = parent.openBisModel.selectedObject.summaryHeader; } +@end + +@implementation CISDOBTableDisplayState + +- (id)initWithController:(CISDOBMasterViewController *)controller; +{ + if (!(self = [super init])) return nil; + + self.controller = controller; + self.openBisModel = controller.openBisModel; + + return self; +} + + +// Everything is a subclass responsibility +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 0; } +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 0; } +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { return nil; } +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return nil; } +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } + +@end + + +@implementation CISDOBTableBrowseState + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return [self.openBisModel numberOfSections]; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return [self.openBisModel numberOfEntitiesInSection: section]; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell ; + cell = [tableView dequeueReusableCellWithIdentifier: @"Cell" forIndexPath: indexPath]; // This only works in iOS 6, + [self.controller configureCell: cell atIndexPath: indexPath]; + return cell; +} + +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section +{ + return [self.openBisModel titleForHeaderInSection: section]; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [self.openBisModel selectObjectAtIndexPath: indexPath]; + [self.controller selectionDidChangeForModel]; +} + +@end + +@implementation CISDOBTableFilterState + +- (CISDOBIpadEntity *)entityAtIndexPath:(NSIndexPath *)indexPath +{ + return [self.filteredResults objectAtIndex: [indexPath indexAtPosition: 1]]; +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return (self.filteredResults) ? [self.filteredResults count] : 0; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + NSString *cellId = @"FilterCell"; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellId]; + if (!cell) { + cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: cellId]; + } + + CISDOBIpadEntity *entity = [self entityAtIndexPath: indexPath]; + [self.controller configureCell: cell forEntity: entity]; + return cell; +} + + +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section +{ + return @"Results"; +} + +- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString +{ + NSArray *fullResult = [self.openBisModel.fetchedResultsController fetchedObjects]; + NSPredicate *filterPredicate = [NSPredicate predicateWithFormat: @"SELF.refconJson contains[cd] %@", searchString]; + self.filteredResults = [fullResult filteredArrayUsingPredicate: filterPredicate]; + return YES; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + self.openBisModel.selectedObject = [self entityAtIndexPath: indexPath]; + [self.controller selectionDidChangeForModel]; +} + + @end diff --git a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h index d2148e39c14a1c30a18a888ce73b755fe5bfcd3d..7089711f7e11152b039f51b5cd40f6276a9f75b2 100644 --- a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h +++ b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.h @@ -49,7 +49,7 @@ - (CISDOBIpadEntity *)objectAtIndexPath:(NSIndexPath *)indexPath; // Selection -@property (readonly) CISDOBIpadEntity *selectedObject; +@property (strong, nonatomic) CISDOBIpadEntity *selectedObject; //! Select the object and return it - (CISDOBIpadEntity *)selectObjectAtIndexPath:(NSIndexPath *)indexPath; diff --git a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m index 7173b1bfe0d55bc8057e622d70738830cb9179ac..8bc377d969f3f2fe2726955eed4309ba87ccafcc 100644 --- a/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m +++ b/openbis-ipad/openBIS/openBIS/CISDOBOpenBisModel.m @@ -97,14 +97,14 @@ #pragma mark - Selection - (CISDOBIpadEntity *)selectObjectAtIndexPath:(NSIndexPath *)indexPath { - _selectedObject = [self objectAtIndexPath: indexPath]; - return _selectedObject; + self.selectedObject = [self objectAtIndexPath: indexPath]; + return self.selectedObject; } - (BOOL)selectionHasChildren { - if (!_selectedObject) return NO; - return [self entityHasChildren: _selectedObject]; + if (!self.selectedObject) return NO; + return [self entityHasChildren: self.selectedObject]; } - (BOOL)entityHasChildren:(CISDOBIpadEntity *)entity