home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / prosrc.bin / StateCheckBox.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  8.3 KB  |  289 lines

  1. /*
  2.  * @(#StateCheckBox.java
  3.  *
  4.  * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
  5.  *
  6.  */
  7.  
  8. package symantec.itools.db.awt;
  9.  
  10. import java.applet.*;
  11. import java.sql.*;
  12. import symantec.itools.db.pro.*;
  13.  
  14. /**
  15.  * A dbAWARE StateCheckBox component.
  16.  * <p>
  17.  * This component is similar to the basic StateCheckBox component, but can
  18.  * be "bound" to a projection within a relation view
  19.  * so that it automatically gets and sets the values in that relation.
  20.  *
  21.  * @see symantec.itools.awt.StateCheckBox
  22.  */
  23. public class StateCheckBox
  24.     extends symantec.itools.awt.StateCheckBox implements ProjectionBean
  25. {
  26.     /**
  27.      * A constant indicating how an empty string will be set when updating
  28.      * data on the dbANYWHERE server.
  29.      */
  30.     public final static int Default    =  0;
  31.     /**
  32.      * A constant indicating how an empty string will be set when updating
  33.      * data on the dbANYWHERE server.
  34.      */
  35.     public final static int Null       =  1;
  36.     /**
  37.      * A constant indicating how an empty string will be set when updating
  38.      * data on the dbANYWHERE server.
  39.      */
  40.     public final static int Blank      =  2;
  41.  
  42.     private int    m_currentState;
  43.     private String m_trueValue = new String("true");
  44.     private String m_falseValue = new String("false");
  45.     private String m_otherValue = new String("");
  46.     private ProjectionBeanHelper m_Helper;
  47.  
  48.     /**
  49.      * Constructs a three-state StateCheckBox that is currently unchecked.
  50.      */
  51.     public StateCheckBox()
  52.     {
  53.         super();
  54.         try
  55.         {
  56.             setStyle(THREE_STATE);
  57.         }
  58.         catch (java.beans.PropertyVetoException ex)
  59.         {
  60.         }
  61.         m_Helper = new ProjectionBeanHelper(this);
  62.     }
  63.  
  64.     /**
  65.      * Establishes what database value will be interpreted as the value: true.
  66.      * The default value is "true" (without the quotes).
  67.      *
  68.      * @param trueValue the string to interpret as the value: true
  69.      */
  70.     public void setTrueValue(String trueValue)
  71.     {
  72.         m_trueValue = new String(trueValue);
  73.     }
  74.  
  75.     /**
  76.      * Establishes what database value will be interpreted as the value: false.
  77.      * The default value is "false" (without the quotes).
  78.      *
  79.      * @param falseValue the string to interpret as the value: false
  80.      */
  81.     public void setFalseValue(String falseValue)
  82.     {
  83.         m_falseValue = new String(falseValue);
  84.     }
  85.  
  86.     /**
  87.      * Establishes what database value will be interpreted as the value: other
  88.      * (the third state of this three-state checkbox).
  89.      * The default value is "" (the empty string without quotes).
  90.      *
  91.      * @param otherValue the string to interpret as the value: other
  92.      */
  93.     public void setOtherValue(String otherValue)
  94.     {
  95.         m_otherValue = new String(otherValue);
  96.     }
  97.  
  98.     /**
  99.      * Binds this component to a given projection within the specified
  100.      * relation view.
  101.      *
  102.      * @param relView the relation view to bind with
  103.      * @param projection the projection in relView to bind with
  104.      */
  105.     public void setBinding(RelationView relView, String projection)
  106.     {
  107.         m_Helper.setBinding(relView, projection);
  108.     }
  109.  
  110.     /**
  111.      * Returns the projection in the RelationView that this component is bound with.
  112.      * @see #setBinding
  113.      * @see #setProjection
  114.      */
  115.     public String getProjection() {
  116.         return m_Helper.getProjection();
  117.     }
  118.  
  119.     /**
  120.      * Binds this component to the given projection within the RelationView
  121.      * the component is currently bound with.
  122.      * @see #setBinding
  123.      * @see #getProjection
  124.      * @see #getRelationView
  125.      */
  126.     public void setProjection(String projection) {
  127.         m_Helper.setProjection(projection);
  128.     }
  129.  
  130.     /**
  131.      * Gets the RelationView that this component is bound with.
  132.      * @return the RelationView currently bound with
  133.      * @see #setRelationView
  134.      * @see #setBinding
  135.      * @see #getProjection
  136.      */
  137.     public RelationView getRelationView() {
  138.         return m_Helper.getRelationView();
  139.     }
  140.  
  141.     /**
  142.      * Sets the RelationView that this component is bound with.
  143.      * @param value the RelationView to bind with
  144.      * @see #getRelationView
  145.      * @see #setBinding
  146.      * @see #setProjection
  147.      */
  148.     public void setRelationView(RelationView rv) {
  149.         m_Helper.setRelationView(rv);
  150.     }
  151.  
  152.     /**
  153.      * Specifies how an empty string will be set when updating data on
  154.      * the dbANYWHERE server.
  155.      *
  156.      * @param blank one of "DEFAULT", "NULL", or "BLANK"
  157.      *
  158.      * @see symantec.itools.db.pro.ProjBinder#setValueFromString(java.lang.String, int, int)
  159.      */
  160.     public void setTreatBlankAs(int value) {
  161.         m_Helper.setTreatBlankAs(value);
  162.     }
  163.  
  164.     /**
  165.      * Indicates when the component commits its changes.
  166.      * @see #setDynamicUpdate
  167.      */
  168.     public boolean getDynamicUpdate() {
  169.         return m_Helper.getDynamicUpdate();
  170.     }
  171.  
  172.     /**
  173.      * Sets when the component commits its changes.
  174.      * @param value the new dynamic update mode value
  175.      * @see #getDynamicUpdate
  176.      */
  177.     public void setDynamicUpdate(boolean value) {
  178.         m_Helper.setDynamicUpdate(value);
  179.     }
  180.  
  181.     /**
  182.      * Gets the value of this component.
  183.      * @return the current component value
  184.      * @see #setData
  185.      */
  186.     public Object getData() {
  187.         String value = "";
  188.         switch (getState()) {
  189.         case 1:
  190.             value = m_trueValue;
  191.             break;
  192.  
  193.         case 0:
  194.             value = m_falseValue;
  195.             break;
  196.  
  197.         case 2:
  198.             value = m_otherValue;
  199.             break;
  200.         }
  201.         return value;
  202.     }
  203.  
  204.     /**
  205.      * Sets the value of this component to the given value.
  206.      * @param value the new component value
  207.      * @see #getData
  208.      */
  209.     public void setData(Object value) {
  210.         if (value != null) {
  211.             try {
  212.                 if (value.equals(m_trueValue)) {
  213.                     setState(1);
  214.                 }
  215.                 else if (value.equals(m_falseValue)) {
  216.                     setState(0);
  217.                 }
  218.                 else {
  219.                     setState(2);
  220.                 }
  221.             }
  222.             catch (Exception ex) {
  223.                 m_Helper.raiseException(ex);
  224.             }
  225.         }
  226.     }
  227.  
  228.     /**
  229.      * Sets whether the data value of this component may be modified.
  230.      * @param value <code>true</code> if the value may not be modified,
  231.      * <code>false</code>if the value may be modified
  232.      */
  233.     public void setReadOnly(boolean value) {
  234.     }
  235.  
  236.     /**
  237.      * Gets whether this component saves its value as a text String.
  238.      * @return <code>true</code> if the value is saved as text,
  239.      * <code>false</code> otherwise
  240.      */
  241.     public boolean isTextBased() {
  242.         return true;
  243.     }
  244.  
  245.     /**
  246.      * Gets the number of digits to the right of the decimal point for
  247.      * this component's value.
  248.      * @return the number of digits to the right of the decimal point
  249.      */
  250.     public int getScale() {
  251.         return ProjBinder.DEFAULTSCALE;
  252.     }
  253.  
  254.     /**
  255.      * Registers the standard event listener(s) for this component.
  256.      */
  257.     public void registerListeners() {
  258.         addActionListener(m_Helper);
  259.     }
  260.  
  261.      /**
  262.      * Sets the value of the Empty Means Null property.
  263.      * This determines how an empty string will be saved when updating data on
  264.      * the database server.
  265.      * A value of <code>true</code>indicates an empty string will be saved as a
  266.      * SQL NULL value. Otherwise it will be saved as a blank value.
  267.      * @param propertyValue <code>true</code> for NULL, <code>false</code> for BLANK
  268.      * @see #getEmptyMeansNull
  269.      */
  270.     public void setEmptyMeansNull(boolean propertyValue)
  271.     {
  272.         m_Helper.setEmptyMeansNull(propertyValue);
  273.     }
  274.  
  275.      /**
  276.      * Gets the value of the Empty Means Null property.
  277.      * This determines how an empty string will be saved when updating data on
  278.      * the database server.
  279.      * A value of <code>true</code>indicates an empty string will be saved as a
  280.      * SQL NULL value. Otherwise it will be saved as a blank value.
  281.      * @return <code>true</code> for NULL, <code>false</code> for BLANK
  282.      * @see #setEmptyMeansNull
  283.      */
  284.     public boolean getEmptyMeansNull()
  285.     {
  286.         return m_Helper.getEmptyMeansNull();
  287.     }
  288. }
  289.