Friday, September 25, 2009

iPhone: Display "No Contacts" like in the iPhone contacts

Q. how to show No Contacts in UITableView, which gets displayed in Address Book home screen of iPhone.

create an array with size of no.of cells displayed and populate the center cell.

cell.textLabel.text= @"No Contacts";
cell.textLabel.textAlignment= UITextAlignmentCenter;
cell.textLabel.textColor= [UIColor lightGrayColor];

or
this post fulfill the same

iPhone: create UITabBarController + UINavigationController + UITableViewController

programmatically create a TabBarController application

We can create application by choose File->New Project ,and select 'window-based application'


Give a name (say tabbarsample) and save the project


create tableviewcontroller file to display when click on tab
File->New File, select UIViewController subclass, and check the UITableViewController subclass
give a name (example MyTableViewController)


create an instance of NSObject file to retrieve data from that class
File->New File, select Objective-C class, and select subclass of NSObject
give file name example DataAccess


After doing these steps, we can see six files in our classes folder


This is the final product :





Its better to show the code in all six files, it will tell the remaining part..

//
//  tabbarsampleAppDelegate.h
//  tabbarsample

#import <UIKit/UIKit.h>

@interface tabbarsampleAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    UIWindow *window;
    
    
    UITabBarController *mytabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) UITabBarController *mytabBarController;

@end


//
//  tabbarsampleAppDelegate.m
//  tabbarsample
//

#import "tabbarsampleAppDelegate.h"
#import "MyTableViewController.h"

@implementation tabbarsampleAppDelegate

@synthesize window;
@synthesize mytabBarController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    
    mytabBarController = [[UITabBarController alloc] init];
    
    NSMutableArray *array = [[NSMutableArray alloc] init];
    
    
    MyTableViewController *myTableViewController1 = [[MyTableViewController alloc] initWithParam:1];
    
    UINavigationController *myTableNavController1 = [[UINavigationController alloc] initWithRootViewController:myTableViewController1] ;
    [array addObject:myTableNavController1];
    
    [myTableViewController1 release];
    [myTableNavController1 release];
    myTableViewController1 = nil;
    myTableNavController1 = nil;
    
    
    MyTableViewController *myTableViewController2 = [[MyTableViewController alloc] initWithParam:3];
    
    UINavigationController *myTableNavController2 = [[UINavigationController alloc] initWithRootViewController:myTableViewController2] ;
    [array addObject:myTableNavController2];
    
    [myTableViewController2 release];
    [myTableNavController2 release];
    myTableViewController2 = nil;
    myTableNavController2 = nil;

    
    MyTableViewController *myTableViewController = [[MyTableViewController alloc] initWithParam:6];
    
    UINavigationController *myTableNavController = [[UINavigationController alloc] initWithRootViewController:myTableViewController] ;
    [array addObject:myTableNavController];
    
    [myTableViewController release];
    [myTableNavController release];
    myTableViewController = nil;
    myTableNavController = nil;
    
    
    
    window.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    mytabBarController.view.autoresizingMask =  UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    mytabBarController.viewControllers = array;
    [window setBackgroundColor:[UIColor whiteColor]];
    [window addSubview:mytabBarController.view];
    mytabBarController.delegate = self;
    [array release];
    
    // Override point for customization after application launch
    [window makeKeyAndVisible];
}


- (void)dealloc {
    [mytabBarController release];
    [window release];
    [super dealloc];
}


#pragma mark UITabBarControllerDelegate

- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed{
    
    if(changed){
        //write the object to persistent stroe to retrive on next launch
    }
    
}


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
    NSLog(@"clicked index at %i",tabBarController.selectedIndex);
    
}
@end




//
//  MyTableViewController.h
//  tabbarsample
//


#import 


@interface MyTableViewController : UITableViewController {

    
    NSArray *arrayData;
}

@property(nonatomic, retain) NSArray *arrayData;


- (id)initWithParam:(NSUInteger)param;

@end





//
//  MyTableViewController.m
//  tabbarsample
//

#import "MyTableViewController.h"
#import "DataAccess.h"

@implementation MyTableViewController

@synthesize arrayData;


- (id)initWithParam:(NSUInteger)param {
    // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
    if (self = [super init]) {
        
        DataAccess *dataAccess = [[DataAccess alloc]init];
        self.arrayData = [dataAccess getDataForType:param];
        [dataAccess release];
        
        
        self.title = [NSString stringWithFormat:@"type_%i", param];
        self.tabBarItem.image = [UIImage imageNamed:@"images.png"];
        //self.tabBarItem.tag = param;//can use for CustomizingViewControllers
    }
    return self;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
            NSUInteger countt = [arrayData count];
 if(countt>0){
  return [arrayData count];
 }
 else{
  return 4;//to show "No Items" on 4rd cell
 }
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = nil;
 if([arrayData count] > 0){
  
  static NSString *CellIdentifier = @"Cell";
  
  cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
   
  }
  
  // Set up the cell...
  cell.textLabel.text = [arrayData objectAtIndex:indexPath.row];
 }else{
  
  static NSString *CellIdentifier = @"NoData";
  
  cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
   cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
   
  }
  cell.selectionStyle = UITableViewCellSelectionStyleNone;
  // Set up the cell...
  if(indexPath.row == 3){
   cell.textLabel.text= @"No Items";
   cell.textLabel.textAlignment= UITextAlignmentCenter;
   cell.textLabel.textColor= [UIColor lightGrayColor];
  }else{
   cell.textLabel.text = @"";
  }
 }
    return cell;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 
}
- (void)dealloc {
    [arrayData release];
    [super dealloc];
}


@end





//
//  DataAccess.h
//  tabbarsample
//

#import 

@interface DataAccess : NSObject {    
}

-(NSArray *)getDataForType:(NSUInteger)typeOfData;

@end





//
//  DataAccess.m
//  tabbarsample
//


#import "DataAccess.h"


@implementation DataAccess

-(NSArray *)getDataForType:(NSUInteger)typeOfData{
    
     //to test "No Items"
 if(typeOfData == 6){
  NSMutableArray *array = [[NSMutableArray alloc] init];
  return [array autorelease];
 }else
    if(typeOfData == 1){
        
        NSArray *array = [NSArray arrayWithObjects:@"type1 cell0",@"type1 cell1",@"type1 cell2",@"type1 cell3",nil];
        return array;
    }else{
        
        NSMutableArray *array = [[NSMutableArray alloc] init];
        for(int i=0 ; i<3*typeofdata>
            
            [array addObject:[NSString stringWithFormat:@"type%i cell_%i",typeOfData,i]];
        }
        return [array autorelease];
    }
}

@end


used iPhone sdk 3.1
tested with Simulator 3.1/Debug

thanks to reading..:)

Thursday, September 24, 2009

connecting Microsoft Dynamic CRM 3.0 with java code

hi All, I would like to share my experience to connecting ms crm with java code...

Its not difficult to connect ms crm 3.0 with java code using both ntlm and basic authentication..

First Step: download web service description files(CrmService.asmx, MetadataService.asmx) from Mircosoft Dynamics CRM

And convert to equivalent java classes

create a folder CrmService and execute this command

java -classpath C:\java\axis-1_4\lib\axis.jar;C:\java\axis-1_4\lib\activation.jar;C:\java\axis-1_4\lib\mail.jar;C:\java\axis-1_4\lib\axis-ant.jar;C:\java\axis-1_4\lib\commons-discovery-0.2.jar;C:\java\axis-1_4\lib\commons-logging-1.0.4.jar;C:\java\axis-1_4\lib\jaxrpc.jar;C:\java\axis-1_4\lib\log4j-1.2.8.jar;C:\java\axis-1_4\lib\saaj.jar;C:\java\axis-1_4\lib\wsdl4j-1.5.1.jar org.apache.axis.wsdl.WSDL2Java -v -a -O -1 CrmService.wsdl -o ./CrmService
pause

do the same for metadataservice to convert to java code.

combine both sources..

Create new project in your eclipse, and test login..


For basic authentication , we can use axis1.4 file

To connect with ntlm authentication, we have to edit the client-config.wsdd file in axis1.4 jar, Hope that you all know about this.. please comment if you need further help with this..

/*added on +20101220 */
easy way to edit is: open the axis.jar file with winrar application
go to the folder org->apache->axis->client and open the file client-config.wsdd and edit the following changes and save. check once again the changes are there.


/*********/


The following is the sample client-config.wsdd

<?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultClientConfig"
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalconfiguration>
<parameter name="disablePrettyXML" value="true">
</globalconfiguration>
<transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender">
<transport name="local" pivot="java:org.apache.axis.transport.local.LocalSender">
<transport name="java" pivot="java:org.apache.axis.transport.java.JavaSender">
</deployment>


Along with axis jar, we need these two(commons-httpclient-3.1.jar, commons-codec-1.3.jar) jar files in our class-path to get ntlm authentication


sample code to login
CrmServiceSoapStub stub =  (CrmServiceSoapStub)
new CrmServiceLocator().getCrmServiceSoap(
new URL("http://###.###.#.###/MSCRMServices/2006/CrmService.asmx"));

stub.setUsername("crm\\user");
stub.setPassword("#######");
WhoAmIRequest request=new WhoAmIRequest();
WhoAmIResponse response=(WhoAmIResponse)stub.execute(Request);
System.out.println("----------getBusinessUnitId()--------->"+response.getBusinessUnitId());
System.out.println("----------getUserId()----------------->"+response.getUserId());

//can write on next post about connecting mscrm 4.0 with java code