2 // LBVirtualIPTypeViewController.m
5 // Created by Mike Mayo on 5/2/11.
6 // Copyright 2011 __MyCompanyName__. All rights reserved.
9 #import "LBVirtualIPTypeViewController.h"
10 #import "OpenStackAccount.h"
11 #import "LoadBalancer.h"
12 #import "AccountManager.h"
13 #import "UIViewController+Conveniences.h"
14 #import "LBLinkSharedVIPViewController.h"
18 #define kSharedVirtualIP 2
20 @implementation LBVirtualIPTypeViewController
22 @synthesize account, loadBalancer;
24 - (id)initWithAccount:(OpenStackAccount *)a loadBalancer:(LoadBalancer *)lb {
25 self = [self initWithNibName:@"LBVirtualIPTypeViewController" bundle:nil];
28 self.loadBalancer = lb;
29 descriptions = [[NSDictionary alloc] initWithObjectsAndKeys:
30 @"This Load Balancer is accessible over the Internet.", @"Public",
31 @"This Load Balancer can only be reached from within the data center. Inbound and outbound bandwidth fees don’t apply.", @"ServiceNet",
32 @"Share a common address between multiple load balancers. Useful to balance HTTP and HTTPS on a common IP for DNS. Unique ports must be used for each load balancer behind the IP.", @"Shared Virtual IP",
38 - (id)initWithStyle:(UITableViewStyle)style
40 self = [super initWithStyle:style];
42 // Custom initialization
50 [loadBalancer release];
51 [descriptions release];
55 - (void)didReceiveMemoryWarning
57 // Releases the view if it doesn't have a superview.
58 [super didReceiveMemoryWarning];
60 // Release any cached data, images, etc that aren't in use.
63 #pragma mark - View lifecycle
67 self.navigationItem.title = @"Virtual IP Type";
72 [super viewDidUnload];
73 // Release any retained subviews of the main view.
74 // e.g. self.myOutlet = nil;
77 - (void)viewWillAppear:(BOOL)animated
79 [super viewWillAppear:animated];
82 - (void)viewDidAppear:(BOOL)animated
84 [super viewDidAppear:animated];
87 - (void)viewWillDisappear:(BOOL)animated
89 [super viewWillDisappear:animated];
92 - (void)viewDidDisappear:(BOOL)animated
94 [super viewDidDisappear:animated];
97 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
98 return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait);
101 #pragma mark - Table view data source
103 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
104 NSString *endpoint = [self.account loadBalancerEndpointForRegion:self.loadBalancer.region];
105 return [self.account.loadBalancers objectForKey:endpoint] > 0 ? 3 : 2;
108 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
112 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
113 if (indexPath.row == 0) {
114 return tableView.rowHeight;
116 NSString *description = @"";
117 if (indexPath.section == kPublic) {
118 description = [descriptions objectForKey:@"Public"];
119 } else if (indexPath.section == kServiceNet) {
120 description = [descriptions objectForKey:@"ServiceNet"];
121 } else if (indexPath.section == kSharedVirtualIP) {
122 description = [descriptions objectForKey:@"Shared Virtual IP"];
124 UIFont *font = [UIFont systemFontOfSize:14];
125 CGSize size = [description sizeWithFont:font constrainedToSize:CGSizeMake(tableView.frame.size.width - 40, 25000) lineBreakMode:UILineBreakModeWordWrap];
126 return 30 + size.height;
130 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
131 static NSString *CellIdentifier = @"Cell";
133 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
135 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
136 cell.textLabel.backgroundColor = [UIColor clearColor];
137 cell.detailTextLabel.numberOfLines = 0;
140 // Configure the cell...
141 if (indexPath.row == 0) {
142 cell.selectionStyle = UITableViewCellSelectionStyleBlue;
143 cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"grey-highlight.png"]] autorelease];
145 cell.selectionStyle = UITableViewCellSelectionStyleNone;
148 if (indexPath.section == kPublic) {
149 if (indexPath.row == 0) {
150 cell.textLabel.text = @"Public";
151 cell.detailTextLabel.text = @"";
153 cell.textLabel.text = @"";
154 cell.detailTextLabel.text = [descriptions objectForKey:@"Public"];
156 } else if (indexPath.section == kServiceNet) {
157 if (indexPath.row == 0) {
158 cell.textLabel.text = @"ServiceNet";
159 cell.detailTextLabel.text = @"";
161 cell.textLabel.text = @"";
162 cell.detailTextLabel.text = [descriptions objectForKey:@"ServiceNet"];
164 } else if (indexPath.section == kSharedVirtualIP) {
165 if (indexPath.row == 0) {
166 cell.textLabel.text = @"Shared Virtual IP";
167 cell.detailTextLabel.text = @"";
169 cell.textLabel.text = @"";
170 cell.detailTextLabel.text = [descriptions objectForKey:@"Shared Virtual IP"];
174 if ([self.loadBalancer.virtualIPType isEqualToString:cell.textLabel.text]) {
175 cell.accessoryType = UITableViewCellAccessoryCheckmark;
176 [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
178 cell.accessoryType = UITableViewCellAccessoryNone;
179 [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
185 #pragma mark - Table view delegate
187 - (void)selectRow:(NSTimer *)timer {
188 [self.tableView selectRowAtIndexPath:[timer.userInfo objectForKey:@"indexPath"] animated:NO scrollPosition:UITableViewScrollPositionNone];
191 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
192 if (indexPath.row == 1) {
193 [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:indexPath.section] animated:NO scrollPosition:UITableViewScrollPositionNone];
196 if (indexPath.section == kPublic) {
197 self.loadBalancer.virtualIPType = @"Public";
198 } else if (indexPath.section == kServiceNet) {
199 self.loadBalancer.virtualIPType = @"ServiceNet";
200 } else if (indexPath.section == kSharedVirtualIP) {
201 self.loadBalancer.virtualIPType = @"Shared Virtual IP";
202 LBLinkSharedVIPViewController *vc = [[LBLinkSharedVIPViewController alloc] initWithAccount:self.account loadBalancer:self.loadBalancer];
203 [self.navigationController pushViewController:vc animated:YES];
207 [self.tableView reloadData];