001    package com.sptci.echo2;
002    
003    import java.lang.reflect.Field;
004    
005    import nextapp.echo2.app.Button;
006    import nextapp.echo2.app.Column;
007    import nextapp.echo2.app.Component;
008    import nextapp.echo2.app.Extent;
009    import nextapp.echo2.app.ImageReference;
010    import nextapp.echo2.app.Label;
011    import nextapp.echo2.app.PasswordField;
012    import nextapp.echo2.app.Row;
013    import nextapp.echo2.app.TextArea;
014    import nextapp.echo2.app.TextField;
015    import nextapp.echo2.app.event.ActionListener;
016    
017    import echopointng.Menu;
018    import echopointng.MenuItem;
019    import echopointng.PushButton;
020    import echopointng.RichTextArea;
021    
022    import com.sptci.ReflectionUtility;
023    
024    /**
025     * A utility class that provides methods to create and initialise 
026     * standard UI components.
027     *
028     * <p>Copyright 2006 Sans Pareil Technologies, Inc.</p>
029     * @author Rakesh Vidyadharan 2006-01-15
030     * @version $Id: Utilities.java 3115 2007-04-23 14:07:53Z rakesh $
031     */
032    public final class Utilities extends Object
033    {
034      /**
035       * Default constructor.  Cannot be initialised.
036       */
037      private Utilities()
038      {
039        super();
040      }
041    
042      /**
043       * Create the button identified by the specified name.
044       * 
045       * @param view The name of the view to which the component
046       *   is to be added.  This must match the name of the configuration
047       *   setting.
048       * @param name The name used to identify the button to create.
049       *   The name must match the name of the appropriate button.  The
050       *   same name must be configured in the configuration file for
051       *   the properties and resources.
052       * @return Button The new button that was created.
053       */
054      public static final Button createButton( String view, String name )
055      {
056        Button button = new Button( Configuration.getString( 
057              view + "." + name + ".text" ) );
058        button.setStyleName( "Default.Button" );
059        button.setToolTipText( Configuration.getString( 
060              view + "." + name + ".tooltip" ) );
061        button.setActionCommand( name );
062    
063        return button;
064      }
065    
066      /**
067       * Create the button identified by the specified name.
068       * 
069       * @see #createButton( String, String )
070       * @param view The name of the view to which the component
071       *   is to be added.  This must match the name of the configuration
072       *   setting.
073       * @param name The name used to identify the button to create.
074       *   The name must match the name of the appropriate button.  The
075       *   same name must be configured in the configuration file for
076       *   the properties and resources.
077       * @param actionListener The <code>ActionListener</code> to register
078       *   for the newly created button.
079       * @return Button The new button that was created.
080       */
081      public static final Button createButton( String view, String name,
082          ActionListener actionListener )
083      {
084        Button button = createButton( view, name );
085        button.addActionListener( actionListener );
086    
087        return button;
088      }
089    
090      /**
091       * Create the button identified by the specified name.
092       * 
093       * @see #createButton( String, String, ActionListener )
094       * @see #setField
095       * @param view The name of the view to which the component
096       *   is to be added.  This must match the name of the configuration
097       *   setting.
098       * @param name The name used to identify the button to create.
099       *   The name must match the name of the appropriate button.  The
100       *   same name must be configured in the configuration file for
101       *   the properties and resources.
102       * @param actionListener The <code>ActionListener</code> to register
103       *   for the newly created button.
104       * @param viewObject The object whose identically named field is to
105       *   be set with the newly created component.
106       * @return Button The new button that was created.
107       */
108      public static final Button createButton( String view, String name,
109          ActionListener actionListener, Object viewObject )
110      {
111        Button button = createButton( view, name, actionListener );
112        setField( name, viewObject, button );
113    
114        return button;
115      }
116    
117      /**
118       * Create the button identified by the specified name.
119       * 
120       * @param view The name of the view to which the component
121       *   is to be added.  This must match the name of the configuration
122       *   setting.
123       * @param name The name used to identify the button to create.
124       *   The name must match the name of the appropriate button.  The
125       *   same name must be configured in the configuration file for
126       *   the properties and resources.
127       * @param image The image that is to be displayed as the button.
128       * @param actionListener The <code>ActionListener</code> to register
129       *   for the newly created button.
130       * @return Button The new button that was created.
131       */
132      public static final Button createButton( String view, String name,
133          ImageReference image, ActionListener actionListener )
134      {
135        Button button = new Button( image );
136        button.setStyleName( "Image.Button" );
137        button.setToolTipText( Configuration.getString( 
138              view + "." + name + ".tooltip" ) );
139        button.setActionCommand( name );
140        button.addActionListener( actionListener );
141    
142        return button;
143      }
144    
145      /**
146       * Create the button identified by the specified name.
147       * 
148       * @param view The name of the view to which the component
149       *   is to be added.  This must match the name of the configuration
150       *   setting.
151       * @param name The name used to identify the button to create.
152       *   The name must match the name of the appropriate button.  The
153       *   same name must be configured in the configuration file for
154       *   the properties and resources.
155       * @param styleName The name of the style to apply to the button.
156       *   This need only be the sub-part of the fully qualified style
157       *   name.  The name of the view and the default ".Button" will
158       *   be applied.
159       * @return Button The new button that was created.
160       */
161      public static final Button createButton( String view, String name,
162          String styleName )
163      {
164        Button button = new Button( Configuration.getString( 
165              view + "." + name + ".text" ) );
166        button.setToolTipText( Configuration.getString( 
167              view + "." + name + ".tooltip" ) );
168    
169        button.setStyleName( processStyleName( view, styleName, "Button" ) );
170    
171        button.setActionCommand( name );
172    
173        return button;
174      }
175    
176      /**
177       * Create the button identified by the specified name.
178       * 
179       * @see #createButton( String, String, String )
180       * @param view The name of the view to which the component
181       *   is to be added.  This must match the name of the configuration
182       *   setting.
183       * @param name The name used to identify the button to create.
184       *   The name must match the name of the appropriate button.  The
185       *   same name must be configured in the configuration file for
186       *   the properties and resources.
187       * @param styleName The name of the style to apply to the button.
188       *   This need only be the sub-part of the fully qualified style
189       *   name.  The name of the view and the default ".Button" will
190       *   be applied.
191       * @param actionListener The <code>ActionListener</code> to register
192       *   for the newly created button.
193       * @return Button The new button that was created.
194       */
195      public static final Button createButton( String view, String name,
196          String styleName, ActionListener actionListener )
197      {
198        Button button = createButton( view, name, styleName );
199        button.addActionListener( actionListener );
200    
201        return button;
202      }
203    
204      /**
205       * Create the button identified by the specified name.
206       * 
207       * @see #createButton( String, String, String, ActionListener )
208       * @see #setField
209       * @param view The name of the view to which the component
210       *   is to be added.  This must match the name of the configuration
211       *   setting.
212       * @param name The name used to identify the button to create.
213       *   The name must match the name of the appropriate button.  The
214       *   same name must be configured in the configuration file for
215       *   the properties and resources.
216       * @param styleName The name of the style to apply to the button.
217       *   This need only be the sub-part of the fully qualified style
218       *   name.  The name of the view and the default ".Button" will
219       *   be applied.
220       * @param actionListener The <code>ActionListener</code> to register
221       *   for the newly created button.
222       * @param viewObject The object whose identically named field is to
223       *   be set with the newly created component.
224       * @return Button The new button that was created.
225       */
226      public static final Button createButton( String view, String name,
227          String styleName, ActionListener actionListener, 
228          Object viewObject )
229      {
230        Button button = createButton( view, name, styleName );
231        button.addActionListener( actionListener );
232        setField( name, viewObject, button );
233    
234        return button;
235      }
236    
237      /**
238       * Create the button identified by the specified name.
239       * 
240       * @param view The name of the view to which the component
241       *   is to be added.  This must match the name of the configuration
242       *   setting.
243       * @param name The name used to identify the button to create.
244       *   The name must match the name of the appropriate button.  The
245       *   same name must be configured in the configuration file for
246       *   the properties and resources.
247       * @return PushButton The new button that was created.
248       */
249      public static final PushButton createPushButton( String view, 
250          String name )
251      {
252        PushButton button = new PushButton( Configuration.getString( 
253              view + "." + name + ".text" ) );
254        button.setStyleName( "Default.Button" );
255        button.setToolTipText( Configuration.getString( 
256              view + "." + name + ".tooltip" ) );
257        button.setActionCommand( name );
258    
259        return button;
260      }
261    
262      /**
263       * Create the button identified by the specified name.
264       * 
265       * @see #createPushButton( String, String )
266       * @param view The name of the view to which the component
267       *   is to be added.  This must match the name of the configuration
268       *   setting.
269       * @param name The name used to identify the button to create.
270       *   The name must match the name of the appropriate button.  The
271       *   same name must be configured in the configuration file for
272       *   the properties and resources.
273       * @param actionListener The <code>ActionListener</code> to register
274       *   for the newly created button.
275       * @return PushButton The new button that was created.
276       */
277      public static final PushButton createPushButton( String view, 
278          String name, ActionListener actionListener )
279      {
280        PushButton button = createPushButton( view, name );
281        button.addActionListener( actionListener );
282    
283        return button;
284      }
285    
286      /**
287       * Create the button identified by the specified name.
288       * 
289       * @see #createPushButton( String, String, ActionListener )
290       * @see #setField
291       * @param view The name of the view to which the component
292       *   is to be added.  This must match the name of the configuration
293       *   setting.
294       * @param name The name used to identify the button to create.
295       *   The name must match the name of the appropriate button.  The
296       *   same name must be configured in the configuration file for
297       *   the properties and resources.
298       * @param actionListener The <code>ActionListener</code> to register
299       *   for the newly created button.
300       * @param viewObject The object whose identically named field is to
301       *   be set with the newly created component.
302       * @return PushButton The new button that was created.
303       */
304      public static final PushButton createPushButton( String view, 
305          String name, ActionListener actionListener, Object viewObject )
306      {
307        PushButton button = createPushButton( view, name, actionListener );
308        setField( name, viewObject, button );
309    
310        return button;
311      }
312    
313      /**
314       * Create a column and set its style name to <code>Default.Column</code>.
315       *
316       * @see #createColumn( String )
317       * @return Column The newly created column component.
318       */
319      private static final Column createColumn()
320      {
321        return createColumn( "Default.Column" );
322      }
323    
324      /**
325       * Create a column and set its style name to the specified value.
326       *
327       * @param style The name of the style configuration to apply to the
328       *   component.
329       * @return Column The newly created column component.
330       */
331      private static final Column createColumn( String style )
332      {
333        Column column = new Column();
334        column.setStyleName( style );
335        return column;
336      }
337    
338      /**
339       * Create a label using the specified name property.
340       *
341       * @param view The name of the view to which the component
342       *   is to be added.  This must match the name of the configuration
343       *   setting.
344       * @param name The name used to identify the label to create.  The
345       *   same name must be configured in the configuration file for
346       *   the properties and resources.
347       * @return Label The newly created label.
348       */
349      public static final Label createLabel( String view, String name )
350      {
351        Label label = new Label( 
352            Configuration.getString( view + "." + name + ".label" ) );
353        label.setToolTipText( 
354            Configuration.getString( view + "." + name + ".tooltip" ) );
355        label.setStyleName( "Default.Label" );
356    
357        return label;
358      }
359    
360      /**
361       * Create a label using the specified name property and add it to the 
362       * specified component.
363       *
364       * @see #createLabel( String, String )
365       * @see #setField
366       * @param view The name of the view to which the component
367       *   is to be added.  This must match the name of the configuration
368       *   setting.
369       * @param name The name used to identify the label to create.  The
370       *   same name must be configured in the configuration file for
371       *   the properties and resources.
372       * @param viewObject The object in which a Label field is defined with
373       *   <code>name</code> as the field name.
374       * @return Label The newly created label.
375       */
376      public static final Label createLabel( String view, String name,
377          Object viewObject )
378      {
379        Label label = createLabel( view, name );
380        setField( name, viewObject, label );
381    
382        return label;
383      }
384    
385      /**
386       * Create a label using the specified name property and style name.
387       *
388       * @see #createLabel( String, String )
389       * @param view The name of the view to which the component
390       *   is to be added.  This must match the name of the configuration
391       *   setting.
392       * @param name The name used to identify the label to create.  The
393       *   same name must be configured in the configuration file for
394       *   the properties and resources.
395       * @param styleName The name of the style to apply to the button.
396       *   This need only be the sub-part of the fully qualified style
397       *   name.  The name of the view and the default ".Label" will
398       *   be applied.
399       * @return Label The newly created label.
400       */
401      public static final Label createLabel( String view, String name,
402          String styleName )
403      {
404        Label label = createLabel( view, name );
405        label.setStyleName( processStyleName( view, styleName, "Label" ) );
406    
407        return label;
408      }
409    
410      /**
411       * Create a label using the specified name property and style name
412       * and add to the specified viewObject.
413       *
414       * @see #createLabel( String, String, String )
415       * @param view The name of the view to which the component
416       *   is to be added.  This must match the name of the configuration
417       *   setting.
418       * @param name The name used to identify the label to create.  The
419       *   same name must be configured in the configuration file for
420       *   the properties and resources.
421       * @param styleName The name of the style to apply to the button.
422       *   This need only be the sub-part of the fully qualified style
423       *   name.  The name of the view and the default ".Label" will
424       *   be applied.
425       * @param viewObject The object in which a Label field is
426       *   defined with name.
427       * @return Label The newly created label.
428       */
429      public static final Label createLabel( String view, String name,
430          String styleName, Object viewObject )
431      {
432        Label label = createLabel( view, name, styleName );
433        setField( name, viewObject, label );
434    
435        return label;
436      }
437    
438      /**
439       * Create the <code>Menu</code> identified by the specified name.
440       * 
441       * @param view The name of the view to which the component
442       *   is to be added.  This must match the name of the configuration
443       *   setting.
444       * @param name The name used to identify the menu to create.
445       *   The name must match the name of the appropriate menu.  The
446       *   same name must be configured in the configuration file for
447       *   the properties and resources.
448       * @return Menu The new menu that was created.
449       */
450      public static final Menu createMenu( String view, String name )
451      {
452        Menu menu = new Menu( Configuration.getString( 
453              view + "." + name + ".text" ) );
454        menu.setStyleName( "Default.Menu" );
455        menu.setToolTipText( Configuration.getString( 
456              view + "." + name + ".tooltip" ) );
457        menu.setActionCommand( name );
458    
459        return menu;
460      }
461    
462      /**
463       * Create the <code>MenuItem</code> identified by the specified name.
464       * 
465       * @param view The name of the view to which the component
466       *   is to be added.  This must match the name of the configuration
467       *   setting.
468       * @param name The name used to identify the menuItem to create.
469       *   The name must match the name of the appropriate menuItem.  The
470       *   same name must be configured in the configuration file for
471       *   the properties and resources.
472       * @return MenuItem The new menuItem that was created.
473       */
474      public static final MenuItem createMenuItem( String view, String name )
475      {
476        MenuItem menuItem = new MenuItem( Configuration.getString( 
477              view + "." + name + ".text" ) );
478        menuItem.setStyleName( "Default.MenuItem" );
479        menuItem.setToolTipText( Configuration.getString( 
480              view + "." + name + ".tooltip" ) );
481        menuItem.setActionCommand( name );
482    
483        return menuItem;
484      }
485    
486      /**
487       * Create the menuItem identified by the specified name.
488       * 
489       * @see #createMenuItem( String, String )
490       * @param view The name of the view to which the component
491       *   is to be added.  This must match the name of the configuration
492       *   setting.
493       * @param name The name used to identify the menuItem to create.
494       *   The name must match the name of the appropriate menuItem.  The
495       *   same name must be configured in the configuration file for
496       *   the properties and resources.
497       * @param actionListener The <code>ActionListener</code> to register
498       *   for the newly created menuItem.
499       * @return MenuItem The new menuItem that was created.
500       */
501      public static final MenuItem createMenuItem( String view, String name,
502          ActionListener actionListener )
503      {
504        MenuItem menuItem = createMenuItem( view, name );
505        menuItem.addActionListener( actionListener );
506    
507        return menuItem;
508      }
509    
510      /**
511       * Create the menuItem identified by the specified name.
512       * 
513       * @see #createMenuItem( String, String, ActionListener )
514       * @see #setField
515       * @param view The name of the view to which the component
516       *   is to be added.  This must match the name of the configuration
517       *   setting.
518       * @param name The name used to identify the menuItem to create.
519       *   The name must match the name of the appropriate menuItem.  The
520       *   same name must be configured in the configuration file for
521       *   the properties and resources.
522       * @param actionListener The <code>ActionListener</code> to register
523       *   for the newly created menuItem.
524       * @param viewObject The object whose identically named field is to
525       *   be set with the newly created component.
526       * @return MenuItem The new menuItem that was created.
527       */
528      public static final MenuItem createMenuItem( String view, String name,
529          ActionListener actionListener, Object viewObject )
530      {
531        MenuItem menuItem = createMenuItem( view, name, actionListener );
532        setField( name, viewObject, menuItem );
533    
534        return menuItem;
535      }
536    
537      /**
538       * Create a row and set its style name to <code>Default.Row</code>.
539       *
540       * @see #createRow( String )
541       * @return Row The newly created row component.
542       */
543      private static final Row createRow()
544      {
545        return createRow( "Default.Row" );
546      }
547    
548      /**
549       * Create a row and set its style name to the specified value.
550       *
551       * @param style The name of the style configuration to apply to the
552       *   component.
553       * @return Row The newly created row component.
554       */
555      private static final Row createRow( String style )
556      {
557        Row row = new Row();
558        row.setStyleName( style );
559        return row;
560      }
561    
562      /**
563       * Create the text area identified by the name specified.
564       *
565       * @param view The name of the view to which the component
566       *   is to be added.  This must match the name of the configuration
567       *   setting.
568       * @param name The name used to identify the text area to create.
569       *   The name must match the name of the appropriate field
570       *   without the Area suffix (eg. userName, salary, ...).  The
571       *   same name must be configured in the configuration file for
572       *   the properties and resources.
573       * @return TextArea The new textArea component.
574       */
575      public static final TextArea createTextArea( String view, String name )
576      {
577        TextArea textArea = new TextArea();
578        textArea.setActionCommand( name );
579        textArea.setHeight( new Extent(
580            Dimensions.getInt( view + "." + name + ".height" ) ) );
581        textArea.setWidth( new Extent(
582            Dimensions.getInt( view + "." + name + ".width" ) ) );
583        int maxlength = 
584            Dimensions.getInt( view + "." + name + ".maxlength" );
585        if ( maxlength > 0 ) textArea.setMaximumLength( maxlength );
586        textArea.setToolTipText( 
587            Configuration.getString( view + "." + name + ".tooltip" ) );
588        textArea.setStyleName( "Default.TextComponent" );
589    
590        return textArea;
591      }
592    
593      /**
594       * Create the text area identified by the name specified.  Sets the
595       * identically named <code>Area</code> in the <code>viewClass</code>
596       * with the newly created component.
597       *
598       * @see #createTextArea( String, String )
599       * @see #setField
600       * @param view The name of the view to which the component
601       *   is to be added.  This must match the name of the configuration
602       *   setting.
603       * @param name The name used to identify the text field to create.
604       *   The name must match the name of the appropriate field
605       *   without the Area suffix (eg. userName, salary, ...).  The
606       *   same name must be configured in the configuration file for
607       *   the properties and resources.
608       * @param viewObject The object whose field is to be updated with the
609       *   newly created component
610       * @return TextArea The new textArea component.
611       */
612      public static final TextArea createTextArea( String view, 
613          String name, Object viewObject )
614      {
615        TextArea textArea = Utilities.createTextArea( view, name );
616        setField( name, viewObject, textArea );
617    
618        return textArea;
619      }
620    
621      /**
622       * Create the text area identified by the name specified.  Set the
623       * style name of the newly created text area to the style specified.
624       *
625       * @see #createTextArea( String, String )
626       * @param view The name of the view to which the component
627       *   is to be added.  This must match the name of the configuration
628       *   setting.
629       * @param name The name used to identify the text field to create.
630       *   The name must match the name of the appropriate field
631       *   without the Area suffix (eg. userName, salary, ...).  The
632       *   same name must be configured in the configuration file for
633       *   the properties and resources.
634       * @param style The name of the style to apply to the component.
635       * @return TextArea The new textArea component.
636       */
637      public static final TextArea createTextArea( String view, 
638          String name, String style )
639      {
640        TextArea textArea = Utilities.createTextArea( view, name );
641        textArea.setStyleName( style );
642    
643        return textArea;
644      }
645    
646      /**
647       * Create the text area identified by the name specified.  Set the
648       * style name of the newly created text area to the style specified.
649       * Set the field identified by <code>name</code> in the
650       * <code>view</code> with the newly created object.
651       *
652       * @see #createTextArea( String, String )
653       * @param view The name of the view to which the component
654       *   is to be added.  This must match the name of the configuration
655       *   setting.
656       * @param name The name used to identify the text field to create.
657       *   The name must match the name of the appropriate field
658       *   without the Area suffix (eg. userName, salary, ...).  The
659       *   same name must be configured in the configuration file for
660       *   the properties and resources.
661       * @param style The name of the style to apply to the component.
662       * @param viewObject The object whose field is to be updated with the
663       *   newly created component
664       * @return TextArea The new textArea component.
665       */
666      public static final TextArea createTextArea( String view, 
667          String name, String style, Object viewObject )
668      {
669        TextArea textArea = Utilities.createTextArea( view, name, viewObject );
670        textArea.setStyleName( style );
671    
672        return textArea;
673      }
674    
675      /**
676       * Create the text field identified by the name specified.  If the
677       * <code>name</code> is <code>password</code>, then a 
678       * <code>PasswordField</code> is returned instead of a regular
679       * <code>TextField</code>.
680       *
681       * @param view The name of the view to which the component
682       *   is to be added.  This must match the name of the configuration
683       *   setting.
684       * @param name The name used to identify the text field to create.
685       *   The name must match the name of the appropriate field
686       *   without the Field suffix (eg. userName, salary, ...).  The
687       *   same name must be configured in the configuration file for
688       *   the properties and resources.
689       * @return TextField The new textField component.
690       */
691      public static final TextField createTextField( String view, String name )
692      {
693        TextField textField = null;
694    
695        if ( name.toLowerCase().contains( "password" ) )
696        {
697          textField = new PasswordField();
698        }
699        else
700        {
701          textField = new TextField();
702        }
703    
704        textField.setActionCommand( name );
705        textField.setWidth( new Extent(
706            Dimensions.getInt( view + "." + name + ".width" ) ) );
707        int maxlength = 
708            Dimensions.getInt( view + "." + name + ".maxlength" );
709        if ( maxlength > 0 ) textField.setMaximumLength( maxlength );
710        textField.setToolTipText( 
711            Configuration.getString( view + "." + name + ".tooltip" ) );
712        textField.setStyleName( "Default.TextComponent" );
713    
714        return textField;
715      }
716    
717      /**
718       * Create the text field identified by the name specified.  Sets the
719       * identically named <code>Field</code> in the <code>viewClass</code>
720       * with the newly created component.
721       *
722       * @see #createTextField( String, String )
723       * @param view The name of the view to which the component
724       *   is to be added.  This must match the name of the configuration
725       *   setting.
726       * @param name The name used to identify the text field to create.
727       *   The name must match the name of the appropriate field
728       *   without the Field suffix (eg. userName, salary, ...).  The
729       *   same name must be configured in the configuration file for
730       *   the properties and resources.
731       * @param actionListener The action listener to add to the component.
732       * @return TextField The new textField component.
733       */
734      public static final TextField createTextField( String view, 
735          String name, ActionListener actionListener )
736      {
737        TextField textField = Utilities.createTextField( view, name );
738        textField.addActionListener( actionListener );
739        return textField;
740      }
741    
742      /**
743       * Create the text field identified by the name specified.  Sets the
744       * identically named <code>Field</code> in the <code>viewClass</code>
745       * with the newly created component.
746       *
747       * @see #createTextField( String, String )
748       * @see #setField
749       * @param view The name of the view to which the component
750       *   is to be added.  This must match the name of the configuration
751       *   setting.
752       * @param name The name used to identify the text field to create.
753       *   The name must match the name of the appropriate field
754       *   without the Field suffix (eg. userName, salary, ...).  The
755       *   same name must be configured in the configuration file for
756       *   the properties and resources.
757       * @param viewObject The object whose field is to be updated with the
758       *   newly created component
759       * @return TextField The new textField component.
760       */
761      public static final TextField createTextField( String view, 
762          String name, Object viewObject )
763      {
764        TextField textField = Utilities.createTextField( view, name );
765        setField( name, viewObject, textField );
766    
767        return textField;
768      }
769    
770      /**
771       * Create the text field identified by the name specified.  Sets the
772       * identically named <code>Field</code> in the <code>viewClass</code>
773       * with the newly created component.
774       *
775       * @see #createTextField( String, String, Object )
776       * @param view The name of the view to which the component
777       *   is to be added.  This must match the name of the configuration
778       *   setting.
779       * @param name The name used to identify the text field to create.
780       *   The name must match the name of the appropriate field
781       *   without the Field suffix (eg. userName, salary, ...).  The
782       *   same name must be configured in the configuration file for
783       *   the properties and resources.
784       * @param actionListener The action listener to add to the component.
785       * @param viewObject The object whose field is to be updated with the
786       *   newly created component
787       * @return TextField The new textField component.
788       */
789      public static final TextField createTextField( String view, 
790          String name, ActionListener actionListener, Object viewObject )
791      {
792        TextField textField = Utilities.createTextField( view, name, viewObject );
793        textField.addActionListener( actionListener );
794        return textField;
795      }
796    
797      /**
798       * Create the text field identified by the name specified.  If the
799       * <code>name</code> is <code>password</code>, then a 
800       * <code>PasswordField</code> is returned instead of a regular
801       * <code>TextField</code>.
802       *
803       * @param view The name of the view to which the component
804       *   is to be added.  This must match the name of the configuration
805       *   setting.
806       * @param name The name used to identify the text field to create.
807       *   The name must match the name of the appropriate field
808       *   without the Field suffix (eg. userName, salary, ...).  The
809       *   same name must be configured in the configuration file for
810       *   the properties and resources.
811       * @param styleName The name of the style to apply to the button.
812       *   This need only be the sub-part of the fully qualified style
813       *   name.  The name of the view and the default ".TextComponent" will
814       *   be applied.
815       * @return TextField The new textField component.
816       */
817      public static final TextField createTextField( String view, 
818          String name, String styleName )
819      {
820        TextField textField = null;
821    
822        if ( name.equals( "password" ) )
823        {
824          textField = new PasswordField();
825        }
826        else
827        {
828          textField = new TextField();
829        }
830    
831        textField.setActionCommand( name );
832        textField.setWidth( new Extent(
833            Dimensions.getInt( view + "." + name + ".width" ) ) );
834        int maxlength = 
835            Dimensions.getInt( view + "." + name + ".maxlength" );
836        if ( maxlength > 0 ) textField.setMaximumLength( maxlength );
837        textField.setToolTipText( 
838            Configuration.getString( view + "." + name + ".tooltip" ) );
839        textField.setStyleName( 
840            processStyleName( view, styleName, "TextComponent" ) );
841    
842        return textField;
843      }
844    
845      /**
846       * Create the text field identified by the name specified.  Sets the
847       * action handler for the text field to the specified handler.
848       *
849       * @see #createTextField( String, String, String )
850       * @param view The name of the view to which the component
851       *   is to be added.  This must match the name of the configuration
852       *   setting.
853       * @param name The name used to identify the text field to create.
854       *   The name must match the name of the appropriate field
855       *   without the Field suffix (eg. userName, salary, ...).  The
856       *   same name must be configured in the configuration file for
857       *   the properties and resources.
858       * @param styleName The name of the style to apply to the button.
859       *   This need only be the sub-part of the fully qualified style
860       *   name.  The name of the view and the default ".TextComponent" will
861       *   be applied.
862       * @param listener The action listener to asscociated with the text field.
863       * @return TextField The new textField component.
864       */
865      public static final TextField createTextField( String view, 
866          String name, String styleName, ActionListener listener )
867      {
868        TextField textField = 
869          Utilities.createTextField( view, name, styleName );
870        textField.addActionListener( listener );
871    
872        return textField;
873      }
874    
875      /**
876       * Create the text field identified by the name specified.  Sets the
877       * identically named <code>Field</code> in the <code>viewClass</code>
878       * with the newly created component.
879       *
880       * @see #createTextField( String, String, String )
881       * @see #setField
882       * @param view The name of the view to which the component
883       *   is to be added.  This must match the name of the configuration
884       *   setting.
885       * @param name The name used to identify the text field to create.
886       *   The name must match the name of the appropriate field
887       *   without the Field suffix (eg. userName, salary, ...).  The
888       *   same name must be configured in the configuration file for
889       *   the properties and resources.
890       * @param styleName The name of the style to apply to the button.
891       *   This need only be the sub-part of the fully qualified style
892       *   name.  The name of the view and the default ".TextComponent" will
893       *   be applied.
894       * @param viewObject The object whose field is to be updated with the
895       *   newly created component
896       * @return TextField The new textField component.
897       */
898      public static final TextField createTextField( String view, 
899          String name, String styleName, Object viewObject )
900      {
901        TextField textField = 
902          Utilities.createTextField( view, name, styleName );
903        setField( name, viewObject, textField );
904    
905        return textField;
906      }
907    
908      /**
909       * Create the text field identified by the name specified.  Sets the
910       * identically named <code>Field</code> in the <code>viewClass</code>
911       * with the newly created component.  Add the specified action listener
912       * as a registered event handler for the text field.
913       *
914       * @see #createTextField( String, String, String, ActionListener )
915       * @see #setField
916       * @param view The name of the view to which the component
917       *   is to be added.  This must match the name of the configuration
918       *   setting.
919       * @param name The name used to identify the text field to create.
920       *   The name must match the name of the appropriate field
921       *   without the Field suffix (eg. userName, salary, ...).  The
922       *   same name must be configured in the configuration file for
923       *   the properties and resources.
924       * @param styleName The name of the style to apply to the button.
925       *   This need only be the sub-part of the fully qualified style
926       *   name.  The name of the view and the default ".TextComponent" will
927       *   be applied.
928       * @param listener The action listener to asscociated with the text field.
929       * @param viewObject The object whose field is to be updated with the
930       *   newly created component
931       * @return TextField The new textField component.
932       */
933      public static final TextField createTextField( String view, 
934          String name, String styleName, ActionListener listener,
935          Object viewObject )
936      {
937        TextField textField = 
938          Utilities.createTextField( view, name, styleName, listener );
939        setField( name, viewObject, textField );
940    
941        return textField;
942      }
943    
944      /**
945       * Create the rich text area identified by the name specified.
946       *
947       * @param view The name of the view to which the component
948       *   is to be added.  This must match the name of the configuration
949       *   setting.
950       * @param name The name used to identify the text area to create.
951       *   The name must match the name of the appropriate field
952       *   without the Area suffix (eg. userName, salary, ...).  The
953       *   same name must be configured in the configuration file for
954       *   the properties and resources.
955       * @return RichTextArea The new textArea component.
956       */
957      public static final RichTextArea createRichTextArea( String view, 
958          String name )
959      {
960        RichTextArea textArea = new RichTextArea();
961        textArea.setActionCommand( name );
962        textArea.setHeight( new Extent(
963            Dimensions.getInt( view + "." + name + ".height" ) ) );
964        textArea.setWidth( new Extent(
965            Dimensions.getInt( view + "." + name + ".width" ) ) );
966        textArea.setToolTipText( 
967            Configuration.getString( view + "." + name + ".tooltip" ) );
968        textArea.setStyleName( "Default.RichTextArea" );
969    
970        return textArea;
971      }
972    
973      /**
974       * Create the text field identified by the name specified.  Sets the
975       * identically named <code>Area</code> in the <code>viewClass</code>
976       * with the newly created component.
977       *
978       * @see #createRichTextArea( String, String )
979       * @see #setField
980       * @param view The name of the view to which the component
981       *   is to be added.  This must match the name of the configuration
982       *   setting.
983       * @param name The name used to identify the text field to create.
984       *   The name must match the name of the appropriate field
985       *   without the Area suffix (eg. userName, salary, ...).  The
986       *   same name must be configured in the configuration file for
987       *   the properties and resources.
988       * @param viewObject The object whose field is to be updated with the
989       *   newly created component
990       * @return RichTextArea The new textArea component.
991       */
992      public static final RichTextArea createRichTextArea( String view, 
993          String name, Object viewObject )
994      {
995        RichTextArea textArea = Utilities.createRichTextArea( view, name );
996        setField( name, viewObject, textArea );
997    
998        return textArea;
999      }
1000    
1001      /**
1002       * Apply some logical rules to the <code>styleName</code> parameter
1003       * specified.
1004       *
1005       * @param view The view component to which the style name is being
1006       *   applied.  Usually the fully qualified class name.
1007       * @param styleName The name of the style to apply to the button.
1008       *   This need only be the sub-part of the fully qualified style
1009       *   name.  The name of the view and the identifier will be applied.
1010       * @param identifier The identifier for the component.  All style
1011       *   names end with an identifier.
1012       * @return String The modified style name.
1013       */
1014      private static final String processStyleName( String view,
1015          String styleName, String identifier )
1016      {
1017        if ( styleName.indexOf( "." ) == -1 )
1018        {
1019          if ( ! styleName.startsWith( view ) )
1020          {
1021            styleName = ( "".equals( styleName ) ) ? view : view + "." + styleName;
1022          }
1023          if ( ! styleName.endsWith( identifier ) )
1024          {
1025            if ( ! identifier.startsWith( "." ) )
1026            {
1027              identifier = "." + identifier;
1028            }
1029            styleName += identifier;
1030          }
1031        }
1032    
1033        return styleName;
1034      }
1035    
1036      /**
1037       * Set the field identified by the name specified in the object specified
1038       * with the value specified.
1039       *
1040       * @param name The field name.
1041       * @param viewObject The object in which the field is defined.
1042       * @param value The value of the field to set.
1043       */
1044      private static void setField( String name, Object viewObject,
1045          Component value )
1046      {
1047        try
1048        {
1049          Field field = ReflectionUtility.fetchField( name, viewObject );
1050          field.set( viewObject, value );
1051        }
1052        catch ( Throwable t )
1053        {
1054          throw new RuntimeException( t.getMessage(), t );
1055        }
1056      }
1057    }