cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Praveen_Durbha
Level 6

Populating a ISComboBox with Country Names/Codes

Hi,

I need to populate an IS combo box with different country names and associate each country with a code. So, for example, if the combobox is populated with countries like UNITED STATES(US), INDIA(IN), AUSTRALIA(AU), the combo box will display the country names to the user but will actually be storing the country codes (US,IN, AU etc.) in the background.

I intend to copy over the country code based on what country name the user selects to an output file.

How can I do this using InstallShield?.

Thanks very much!!
Labels (1)
0 Kudos
(9) Replies
jweber
Level 6

Heres an example of code I am using to update some comboboxes....

[CODE] ISComboBox models = arg0.getISPanel().getComboBoxControl("jboss_cmb_deploy_servermodel");
ISComboBox existingServerNames = arg0.getISPanel().getComboBoxControl("jboss_cmb_deploy_servername");

String as_location = arg0.resolveString("$N($V(deploy_fb_appserver_location)/server)");
String servers[] = new File(as_location).list();

int count = 0;
Vector v = new Vector();

for ( int x = 0; x < servers.length ; x++)
{
File f = new File(as_location + "/" + servers);
if ( ( f.isDirectory() ) && ( f.canRead() ) )
{
//System.out.println(servers);
v.add(servers);
count++;
}
}

ISComboBoxDef defModels = (ISComboBoxDef)models.getControlDefinition();
ISComboBoxDef defExistingServerNames = (ISComboBoxDef)existingServerNames.getControlDefinition();

String list[] = new String[v.size()];
v.copyInto(list);

defModels.setValues(list);
defExistingServerNames.setValues(list);

models.refreshExtendedProperties();
existingServerNames.refreshExtendedProperties();[/CODE]
0 Kudos
Praveen_Durbha
Level 6

Here is what I am doing. I have done it for US and INDIA for now, but plan to do the rest along the same lines. I am gonna have to hard code every country that's out there...is there a better way to do this?

Thanks

public void selectionChangedinsite2_country_list(com.installshield.event.ui.ISControlContext arg0)
{
try{
ISFrame frame = ((SwingPanel)arg0.getISContainer()).getISFrame();
ISComboBox cntryComboBox = (ISComboBox)arg0.getISControl();
String cntry = cntryComboBox.getSelectedValue();
if(cntry.equals("UNITED STATES")){
cntry = "US";
}
else if (cntry.equals("INDIA")){
cntry = "IN"
}


arg0.getServices().getISDatabase().setVariableValue("insite2_country",cntry);

} catch(Exception e){
arg0.getServices().logEvent(this, Log.ERROR, "Caught an exception........");
}

}
0 Kudos
jweber
Level 6

Well yes and no... There isnt a way to have the ISComboBox selected value represent another value... In other words there is no internal way to make a selection of 'United Stated' equal US. However, what i would do is this...

Create a string variable called countryCodes. Set the value to be something like
United States=US,INDIA=IN,etc....

Have your panel process this into a map or properties object. Then do something like....

String selectedCountry= cntryComboBox.getSelectedValue();
String countryCode = countryCodesMap.getValue(selectedCountry);
selectedCountry=countryCode;
0 Kudos
Praveen_Durbha
Level 6

There are like 200 countries..it would be hard for me to hard code all the countries..

I was looking at the following two options.

Option 1:
How about I embed a SQL statement in my InstallShield code and use a JDBC connection to retrieve the country code

String countryName = cntryComboBox.getSelectedValue();
String countryCodeQuery = "SELECT CODE
FROM COUNTRY_CODE WHERE COUNTRY_NAME = 'countryName' ;
//use JDBC to retrieve the country code.
executeQuery(countryCodeQuery);

Not sure how I can set up a JDBC/ODBC driver from within InstallShield though..I was also thinking of using an Excel spreadsheet( and not a db table) that will have all the countries/codes.

Is this a possible solution?

Option 2:

The other option I was considering was using a HashMap/HashTable with key/value pairs:

HashMap country = new HashMap()
country.put("US", "UNITED STATES");
country.put("IN","INDIA");
country.put("CA","CANADA");
....
............and so on

String countryName = countryComboBox.getSelectedValue();// Get the user selected country
String countryCode = country.get(countryName); // Get the country code

Option 2 is based on your solution. If 1 is not possible, I will go with 2.

Thanks
0 Kudos
jweber
Level 6

While certainly possible to use a database to access the values, I dont think its practical at all....

There are like 200 countries..it would be hard for me to hard code all the countries..


You would have to enter the country codes into the database to begin with, so why not just do it in code.

Heres a solution that may appeal. Just create a properties file that contains your codes:

United States=US
India=IN
etc...

After the user selects the country. Load the properties from the file and then get the associated code via the key.

I.E.,

Properties p = new Properties();
p.loadProperties(InputSource is );

String countryCode = property.getProperty(userSelectedCountry);
0 Kudos
Praveen_Durbha
Level 6

There are like 200 countries..it would be hard for me to hard code all the countries..

I was looking at the following two options.

Option 1:
How about I embed a SQL statement in my InstallShield code and use a JDBC connection to retrieve the country code

String countryName = cntryComboBox.getSelectedValue();
String countryCodeQuery = "SELECT CODE
FROM COUNTRY_CODE WHERE COUNTRY_NAME = 'countryName' ;
//use JDBC to retrieve the country code.
executeQuery(countryCodeQuery);

Not sure how I can set up a JDBC/ODBC driver from within InstallShield though..I was also thinking of using an Excel spreadsheet( and not a db table) that will have all the countries/codes.

Is this a possible solution?

Option 2:

The other option I was considering was using a HashMap/HashTable with key/value pairs:

HashMap country = new HashMap()
country.put("US", "UNITED STATES");
country.put("IN","INDIA");
country.put("CA","CANADA");
....
............and so on

String countryName = countryComboBox.getSelectedValue();// Get the user selected country
String countryCode = country.get(countryName); // Get the country code

Option 2 is based on your solution. If 1 is not possible, I will go with 2.

Thanks
0 Kudos
Praveen_Durbha
Level 6

I already have an Excel Spreadsheet that has all these countries/codes...was wondering if I could put it to use somehow..

Anyway, let me try your option out..important thing is that it should work.

Thanks
0 Kudos
jweber
Level 6

Personally, i wouldn't go that route, however if you really wanted to try, go for it... Checkout http://sourceforge.net/projects/xlsql. However, I think a properties file, or even a CSV file(which can be exported from excel) is more straight forward.
0 Kudos
Praveen_Durbha
Level 6

Okay..I used the HashMap and it's working now..


Thanks a lot for your help!
0 Kudos