home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / TRIAL / JBUILDER / JVISBRKR.Z / FindMissingRequired.java < prev    next >
Encoding:
Java Source  |  1998-05-08  |  3.9 KB  |  109 lines

  1. /*
  2.  * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
  3.  * 
  4.  * This SOURCE CODE FILE, which has been provided by Borland as part
  5.  * of a Borland product for use ONLY by licensed users of the product,
  6.  * includes CONFIDENTIAL and PROPRIETARY information of Borland.  
  7.  *
  8.  * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
  9.  * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
  10.  * THE PRODUCT.
  11.  *
  12.  * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
  13.  * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
  14.  * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
  15.  * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
  16.  * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
  17.  * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
  18.  * CODE FILE.
  19.  */
  20. //--------------------------------------------------------------------------------------------------
  21. // CORBA Reference Application
  22. // Copyright (c) 1997 by Borland International, All Rights Reserved
  23. //
  24. // Used to find columns that are required and are currently set to null.
  25. //
  26. // The functionality in this class could be incorporated into the
  27. // DataSet control OR a decendant of the DataSet.
  28. //--------------------------------------------------------------------------------------------------
  29.  
  30. package borland.reference.creditapproval.client;
  31.  
  32. import borland.jbcl.dataset.*;
  33. import java.awt.*;
  34. import borland.jbcl.control.*;
  35. import borland.jbcl.view.*;
  36.  
  37.  
  38. /**
  39. * FindMissingRequired looks at every column in the current row to make sure
  40. * that all required columns are not null.
  41. */
  42. public class FindMissingRequired {
  43.  
  44.   public FindMissingRequired() {
  45.   }
  46.  
  47.   /**
  48.   * Return the name of a null-required column. If all required columns have
  49.   * values, return an empty string.
  50.   */
  51.   static Column missingColumn(DataSet dataSet) {
  52.  
  53.     int columnCount;
  54.     String missingColumn = "";
  55.     Column column;
  56.     columnCount = dataSet.getColumnCount();
  57.     for (int loop = 0; loop < columnCount; loop++ ) {
  58.       try {
  59.         column = dataSet.getColumn( loop );
  60.         if (column.isRequired() && (dataSet.isNull(loop) || dataSet.isAssignedNull(loop)))
  61.           return column;
  62.       } catch (Exception e) {
  63.         System.err.println(e);
  64.       }
  65.     }
  66.     return null;
  67.   }
  68.  
  69.   /**
  70.   *  Finds the Control associated with the specified column and
  71.   *  returns its reference.
  72.   */
  73.   static Component findColumnTextField( Container container, String columnName) {
  74.     int controlCount = container.getComponentCount();
  75.     String associatedColumnName = null;
  76.     Component component;
  77.  
  78.     for (int loop = 0; loop < controlCount; loop++) {
  79.  
  80.       component = container.getComponent( loop );
  81.  
  82.       // Recurse Containers
  83.  
  84.       if (component instanceof Container && !(component instanceof FieldView) ) {
  85.         Component nested = FindMissingRequired.findColumnTextField( (Container ) component, columnName );
  86.         if (nested != null ) return nested;
  87.         else continue;
  88.       }
  89.       // If the control is capable of DB Access,
  90.       // compare its column name to the search columnName
  91.       else if (component instanceof TextFieldControl)
  92.         associatedColumnName = ((TextFieldControl) component).getColumnName();
  93.       else if (component instanceof TextAreaControl)
  94.         associatedColumnName = ((TextAreaControl) component).getColumnName();
  95.       else if (component instanceof ListControl)
  96.         associatedColumnName = ((ListControl) component).getColumnName();
  97.       else if (component instanceof FieldControl)
  98.         associatedColumnName = ((FieldControl) component).getColumnName();
  99.       else if (component instanceof ChoiceControl)
  100.         associatedColumnName = ((ChoiceControl) component).getColumnName();
  101.       else continue;
  102.  
  103.       if( associatedColumnName.equalsIgnoreCase(columnName)) return component;
  104.     }
  105.     return null;
  106.   }
  107. }
  108.  
  109.