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 / RadioBox.java < prev    next >
Encoding:
Java Source  |  1998-03-19  |  8.4 KB  |  289 lines

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