Skip to content

Commit

Permalink
[formMapping] Ability to inherit from other field classes
Browse files Browse the repository at this point in the history
  • Loading branch information
brunow committed Jun 16, 2012
1 parent a3d1499 commit caf6d77
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
24 changes: 12 additions & 12 deletions Code/FormMapping/BKFormMapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -241,52 +241,52 @@ - (BKSimpleField *)cellWithAttributeMapping:(BKFormAttributeMapping *)attributeM
BKFormAttributeMappingType type = attributeMapping.type;

if (type == BKFormAttributeMappingTypeText) {
field = [BKTextField cellForTableView:self.tableView];
field = [_formMapping.textFieldClass cellForTableView:self.tableView];
[[(BKTextField *)field textField] setDelegate:self];
[[(BKTextField *)field textField] setFormAttributeMapping:attributeMapping];

} else if (type == BKFormAttributeMappingTypeFloat) {
field = [BKFloatField cellForTableView:self.tableView];
field = [_formMapping.floatFieldClass cellForTableView:self.tableView];

} else if (type == BKFormAttributeMappingTypeInteger) {
field = [BKIntegerField cellForTableView:self.tableView];
field = [_formMapping.integerFieldClass cellForTableView:self.tableView];
[[(BKIntegerField *)field textField] setDelegate:self];
[[(BKIntegerField *)field textField] setFormAttributeMapping:attributeMapping];

} else if (type == BKFormAttributeMappingTypeLabel) {
field = [BKLabelField cellForTableView:self.tableView];
field = [_formMapping.labelFieldClass cellForTableView:self.tableView];

} else if (type == BKFormAttributeMappingTypePassword) {
field = [BKPasswordTextField cellForTableView:self.tableView];
field = [_formMapping.passwordFieldClass cellForTableView:self.tableView];
[[(BKPasswordTextField *)field textField] setDelegate:self];
[[(BKPasswordTextField *)field textField] setFormAttributeMapping:attributeMapping];

} else if (type == BKFormAttributeMappingTypeBoolean) {
field = [BKSwitchField cellForTableView:self.tableView];
field = [_formMapping.switchFieldClass cellForTableView:self.tableView];

} else if (type == BKFormAttributeMappingTypeSaveButton) {
field = [BKSaveButtonField cellForTableView:self.tableView];
field = [_formMapping.saveButtonFieldClass cellForTableView:self.tableView];

} else if (type == BKFormAttributeMappingTypeButton) {
field = [BKButtonField cellForTableView:self.tableView];
field = [_formMapping.buttonFieldClass cellForTableView:self.tableView];

} else if (type == BKFormAttributeMappingTypeSelect ||
type == BKFormAttributeMappingTypeTimePicker ||
type == BKFormAttributeMappingTypeDatePicker ||
type == BKFormAttributeMappingTypeDateTimePicker) {
field = [BKLabelField cellForTableView:self.tableView];
field = [_formMapping.labelFieldClass cellForTableView:self.tableView];

} else if (type == BKFormAttributeMappingTypeBigText) {
field = [BKBigTextField cellForTableView:self.tableView];
field = [_formMapping.bigTextFieldClass cellForTableView:self.tableView];

} else if (type == BKFormAttributeMappingTypeCustomCell) {
field = [attributeMapping.customCell cellForTableView:self.tableView];

} else if (type == BKFormAttributeMappingTypeSlider) {
field = [BKSliderField cellForTableView:self.tableView];
field = [_formMapping.sliderFieldClass cellForTableView:self.tableView];

} else {
field = [BKLabelField cellForTableView:self.tableView];
field = [_formMapping.labelFieldClass cellForTableView:self.tableView];
}

return field;
Expand Down
10 changes: 10 additions & 0 deletions Code/FormMapping/BKFormMapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
@property (nonatomic, readonly) NSDictionary *sectionTitles;
@property (nonatomic, retain) NSArray *fieldsOrder;
@property (nonatomic, retain) BKFormAttributeMapping *saveAttribute;
@property (nonatomic, assign) Class textFieldClass;
@property (nonatomic, assign) Class floatFieldClass;
@property (nonatomic, assign) Class integerFieldClass;
@property (nonatomic, assign) Class labelFieldClass;
@property (nonatomic, assign) Class passwordFieldClass;
@property (nonatomic, assign) Class switchFieldClass;
@property (nonatomic, assign) Class saveButtonFieldClass;
@property (nonatomic, assign) Class bigTextFieldClass;
@property (nonatomic, assign) Class sliderFieldClass;
@property (nonatomic, assign) Class buttonFieldClass;

- (id)initWithObjectClass:(Class)objectClass;

Expand Down
25 changes: 21 additions & 4 deletions Code/FormMapping/BKFormMapping.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#import "BKFormAttributeMapping.h"
#import "BKMacrosDefinitions.h"
#import "BaseKitFormField.h"


////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -40,30 +41,46 @@ @implementation BKFormMapping
@synthesize objectClass = _objectClass;
@synthesize fieldsOrder = _fieldsOrder;
@synthesize saveAttribute = _saveAttribute;
@synthesize textFieldClass = _textFieldClass;
@synthesize floatFieldClass = _floatFieldClass;
@synthesize integerFieldClass = _integerFieldClass;
@synthesize labelFieldClass = _labelFieldClass;
@synthesize passwordFieldClass = _passwordFieldClass;
@synthesize switchFieldClass = _switchFieldClass;
@synthesize saveButtonFieldClass = _saveButtonFieldClass;
@synthesize bigTextFieldClass = _bigTextFieldClass;
@synthesize sliderFieldClass = _sliderFieldClass;
@synthesize buttonFieldClass = _buttonFieldClass;


////////////////////////////////////////////////////////////////////////////////////////////////////
- (id)init {
self = [super init];

if (self) {
_attributeMappings = [[NSMutableDictionary alloc] init];
_sectionTitles = [[NSMutableDictionary alloc] init];
_fieldsOrder = [[NSMutableArray alloc] init];
_textFieldClass = [BKTextField class];
_floatFieldClass = [BKFloatField class];
_integerFieldClass = [BKIntegerField class];
_labelFieldClass = [BKLabelField class];
_passwordFieldClass = [BKPasswordTextField class];
_switchFieldClass = [BKSwitchField class];
_saveButtonFieldClass = [BKSaveButtonField class];
_bigTextFieldClass = [BKBigTextField class];
_sliderFieldClass = [BKSliderField class];
_buttonFieldClass = [BKButtonField class];
}

return self;
}


////////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithObjectClass:(Class)objectClass {
self = [self init];

if (self) {
self.objectClass = objectClass;
}

return self;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ - (void)viewDidLoad {

self.movie = movie;

[BKFormMapping mappingForClass:[Movie class] block:^(BKFormMapping *formMapping) {
[BKFormMapping mappingForClass:[Movie class] block:^(BKFormMapping *formMapping) {
[formMapping sectiontTitle:@"Information section" identifier:@"info"];
[formMapping mapAttribute:@"title" title:@"Title" type:BKFormAttributeMappingTypeText];
[formMapping mapAttribute:@"releaseDate" title:@"ReleaseDate" type:BKFormAttributeMappingTypeDatePicker dateFormat:@"yyyy-MM-dd HH:mm:ss"];
Expand Down

0 comments on commit caf6d77

Please sign in to comment.