The Borland Multilingual International Store


Description

The International Sample Application brings together the power and functionality of JBuilder's Java Beans Component Library and DataExpress architecture into an internationally enabled, multilingual, on-line shopping applet/application.

Some of the techniques demonstrated in this sample:

Note: This sample displays messages in English and several different European and Asian languages. You will only be able to see messages in the languages for which you have the appropriate font installed and for which you have the corresponding entry in your JDK font.properties file. sample.font.properties includes the correct settings for several languages supported by the JDK. After modifying it appropriately for your locale, you will need to copy it to the \JBuilder\java\lib directory under the proper name for your operating system locale. For more detailed information, refer to the "Adding Fonts to the Java Runtime" section under the "JDK Guide to New Features/Internationalization" section of JBuilder's JDK Documentation.

Getting started

This sample has been designed to run either as an applet or an application, and to obtain its data from either a DataExpress TextDataFile or the supplied InterBase database. For simplicity, by default it runs as an application and obtains its data from text files installed under your JBuilder samples directory. If you run this sample from the command-line, you must launch it from within the borland/samples/intl directory in order for the text data files to be located.

To run the sample, select Run | Run "IntlDemo" from the main JBuilder menu. To use the InterBase database as the data source, you must first install InterBase and set up an ODBC alias pointing to \JBuilder\samples\borland\samples\intl\application\data\IntlDemo.gdb (or the correct path for your JBuilder installation) using your operating system's ODBC configuration utility. Refer to the "Installing Local InterBase Server" section of the JBuilder Programmer's Guide for detailed instructions on how to do this. Next, you must pass JDBC connection information to the sample via command-line parameters ( Run | Parameters... | Run/Debug | Command line parameters). For example, to use the JDBC-ODBC driver to connect to InterBase, use the following command-line parameters:

jdbc:odbc:IntlDemo SYSDBA masterkey sun.jdbc.odbc.JdbcOdbcDriver

where 'IntlDemo' is the name of the ODBC alias you created which points to the IntlDemo.gdb database.

Running this sample as an applet

Before you can run this sample as an applet, you must install InterBase and create an ODBC alias pointing to the IntlDemo.gdb database. The following applet parameters defined in the APPLET tag within this .html file are used to make a connection to a database source.

To start the applet, select this file in the project's navigation pane, and select 'Run | Run Applet in "IntlDemo.html" from the main menu. Note that because the use of an ODBC driver requires the loading of a .DLL file installed on the client, you will not be able to run this sample as an applet via a browser (such as the JDK1.1 appletviewer) unless you use a 100% pure java JDBC driver (such as Borland's DataGateway or InterBase's InterServer/InterClient) to connect with your web/database server. The basic steps are as follows:

  1. Deploy this sample to a JAR file using the Deployment Wizard, including JBCL and JGL dependencies.
  2. Add the names of the deployed JAR file and JAR or ZIP file containing your 100% Java client-side JDBC driver to an ARCHIVE tag in the applet in this .html file. (For example, if you were using the InterClient JDBC driver, the tag would be ARCHIVE="IntlDemoApplet.jar,interclient.jar". For DataGateway, the tag would be ARCHIVE="IntlDemoApplet.jar,DataGateway.zip".)
  3. Modify the 'url', 'user', 'password' and 'driver' parameters of the APPLET tag in this .html file to correspond to the correct values for your JDBC driver. (If you are using the InterBase InterClient driver, the value of the 'driver' parameter would be "interbase.interclient.Driver" and the url parameter would be "jdbc:interbase://<server name or IP address>/<path to IntlDemo.gdb on your server>" For DataGateway, the 'driver' would be "borland.jdbc.Broker.RemoteDriver" and the url would be "jdbc:BorlandBroker://<server name or IP address>/<BDE alias>". You would need to create the BDE alias on the server using the BDE Administrator program supplied with DataGateway.)
  4. Place the archive files and this .html file (which loads the applet) in a world-readable directory on your Web server.
  5. Install and run the server-side component of your 100% Java JDBC driver on your Web server.  (If you are using InterBase, this would be the InterServer program.  For DataGateway, you would use the DataGateway Server program.)

Look in the documentation included with your JDBC driver for more detailed steps and information.
 

(In a Java-enabled Web browser, you would push the button appearing in this space to run the applet.)

Things to See and Do While Visiting The Borland Multilingual Store

Summary of interesting classes and where they are used

  • JBCL components
  • DataExpress functionality
  • Custom Java Beans
  • Application Overview

    The application can be viewed abstractly as being composed of three major parts--the data module, user interface, and locale manager.  The data module defines the data structures and logic used in the application.  It essentially consists of a Database component and several QueryDataSet components added to it and customized via the UI Designer.  It also exposes public methods used by the GUI to manage the state of the application.  For example, pressing the 'Add To Order' button of the ProductFrame calls the AddProductToOrderLineItem() method of the data module, which adds a row with information about the currently selected row of productsDataSet to orderLineItemDataSet.  The GridControl connected to orderLineItemDataSet is automatically notified of the change and updates its display automatically.  Similarly, other methods of the data module, typically triggered by events occurring on its DataSets, cause other changes to the application's state.  For example, inside the data module, a ColumnChangeListener is attached to the Quantity column of orderLineItemDataSet.  When the value in the Quantity column changes, the data module's quantityColumn_changed() method is triggered, which updates the row's extended price and the order's summary totals.  To get an overview of the data module, design AppDataModule.java in the UI Designer and examine the properties and events set in the Inspector for each DataSet's Column components.

    The frames which comprise the user interface of the sample were also created using the UI Designer.  To allow the frames to be used for several different languages, they were all designed using dynamically sizable layout managers such as BorderLayout, GridLayout, or GridBagLayout in order to accomodate variable length text.  Also, the Resource Strings wizard was used to automatically extract hard-coded strings from visual components and place them into resource bundles which can be loaded dynamically at runtime based upon the user's current locale.

    Finally, each component of the application was designed to be locale-sensitive and resourceable.  Each component registers itself with the LocaleChangeManager, which listens to the LocaleChooser bean for locale changes.  The LocaleChangeManager broadcasts a 'localeChanged' event to each of its registered listeners, which then update themselves accordingly to the new locale.  For example, each frame updates its visual components with strings obtained from the resource bundle for the new locale and redraws itself.  The data module similarly updates any visual data within its DataSets which needs to be localized.  

    Some notes about the Java Beans used in the sample

    The application opens by displaying the WelcomeFrame, which is composed of several Java Beans dropped into and customized in the UI Designer.  The LocaleChooser, WrappingTextViewer, and InternationalClock beans each have their own bean info classes which display localized property descriptions in the UI Designer's pop-up property hints.  LocaleChooser also demonstrates the use of a  custom property editor (actually the LocaleChooser itself) to customize its properties.  One very useful technique when debugging bean property editors in the UI Designer is to set the 'jbuilder.logOutput' flag in the \JBuilder\lib\jbuilder.properties file.  One can then write output from within a custom property editor to a log file or the console.

    Pressing the 'Browse Products' button on the WelcomeFrame brings up the ProductFrame, from which the store's products can be browsed.  The frame uses the WrappingTextViewer's data-aware ability to display product descriptions from the productsDataSet in the data module.  The ViewOnlyNavigationBar is also a data-aware bean, which was connected via the UI Designer to the productsDataSet.  Pressing the navigation buttons calls navigation methods on the productsDataSet.  Because the WrappingTextViewer bean is also attached to productsDataSet, it automatically navigates in unison with the navigation bar.

    The 'View Order' button of the ProductFrame displays the main order entry form, OrderFrame.  It contains several sample beans which take advantage of special features of JBuilder's Model-View component architecture to implement interesting behavior.  These beans can be dropped from the component palette and customized via the UI Designer.  The AnnotatedEmptyItemPainter bean, for example, is a custom 'item painter' which, when asked to paint, displays the word "<required>" if it doesn't have a value.  In the order line item area, the ResourceableItemPainter bean is used as the item painter for the 'description' column.  It takes a product id, looks up the id in a resource bundle, and displays the corresponding localized value.  Finally, the IntegerSpinItemEditor is an example of a custom 'item editor' used to control entry into the 'quantity' column.  It is composed of a MaskableTextItemEditor to restrict entries to digits and a ScrollBar to increase and decrease the entry value. Because its edit mask can be set dynamically, the MaskableTextItemEditor is also used as the item editor for the credit card no column.  When a credit card is selected, its edit mask is set to the appropriate digit entry pattern.
     

    Adding Additional Locales to the sample

    Adding support for an additional locale basically requires adding localized resource files and adding the new locale to the LocaleChooser's locale tree.  First, create localized versions of each of the .properties files in each of the \resources subdirectories of the application.  Next, use the UI Designer to make a localized version of the CustomerInfoPanel used to enter customer information.  If you do so, you must then create a GuiRes file for the locale, and have it return instances of your CustomerInfoPanel.  (Look at the resource files for other locales for examples.)  Second, design the WelcomeFrame in the UI Designer, select the LocaleChooser bean, edit its localeChoices property, and select the locale you wish to add.  Unfortunately, however, the LocaleChooser obtains its list of available locales from a JDK function which has not been updated to contain all the latest supported locales.  If your locale can't be found in the LocaleChooser's list, you will have to add it manually to the line in WelcomeFrame's jbInit() method where LocaleChooser's localeChoices property is set.  Simply add the desired locale to the array of locales where the localeChoices property is set.

    Adding Images as BLOB data to a database

    A quick and easy way to add BLOB image data to a database is to build a simple application via the UI Designer which uses a GridControl and NavigatorControl attached to the target dataset.  Clicking on the BLOB column brings up the ImageItemEditor, which lets you select a file from which to load the image data.  Do this for all the desired images in the dataset, then click the save button of the navigator control to commit the data to the database.

    Package Summary

     
    Package Name Description
    borland.samples.intl main project file and application launcher
    borland.samples.intl.application data module and supporting files; application exception handler
    borland.samples.intl.application.data TextDataFiles and InterBase database used by the sample
    borland.samples.intl.application.resources localized application resources
    borland.samples.intl.beans JavaBeans used in the application
    borland.samples.intl.beans.event event and event listener interface used by locale-sensitive beans
    borland.samples.intl.beans.resources resources (images and resourcing bundles) used by the beans
    borland.samples.intl.gui classes used to build the application's GUI 
    borland.samples.intl.gui.resources resources (images and ResourceBundles) used by GUI elements