home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 8.3 KB | 289 lines |
- /*
- * @(#StateCheckBox.java
- *
- * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
- *
- */
-
- package symantec.itools.db.awt;
-
- import java.applet.*;
- import java.sql.*;
- import symantec.itools.db.pro.*;
-
- /**
- * A dbAWARE StateCheckBox component.
- * <p>
- * This component is similar to the basic StateCheckBox component, but can
- * be "bound" to a projection within a relation view
- * so that it automatically gets and sets the values in that relation.
- *
- * @see symantec.itools.awt.StateCheckBox
- */
- public class StateCheckBox
- extends symantec.itools.awt.StateCheckBox implements ProjectionBean
- {
- /**
- * A constant indicating how an empty string will be set when updating
- * data on the dbANYWHERE server.
- */
- public final static int Default = 0;
- /**
- * A constant indicating how an empty string will be set when updating
- * data on the dbANYWHERE server.
- */
- public final static int Null = 1;
- /**
- * A constant indicating how an empty string will be set when updating
- * data on the dbANYWHERE server.
- */
- public final static int Blank = 2;
-
- private int m_currentState;
- private String m_trueValue = new String("true");
- private String m_falseValue = new String("false");
- private String m_otherValue = new String("");
- private ProjectionBeanHelper m_Helper;
-
- /**
- * Constructs a three-state StateCheckBox that is currently unchecked.
- */
- public StateCheckBox()
- {
- super();
- try
- {
- setStyle(THREE_STATE);
- }
- catch (java.beans.PropertyVetoException ex)
- {
- }
- m_Helper = new ProjectionBeanHelper(this);
- }
-
- /**
- * Establishes what database value will be interpreted as the value: true.
- * The default value is "true" (without the quotes).
- *
- * @param trueValue the string to interpret as the value: true
- */
- public void setTrueValue(String trueValue)
- {
- m_trueValue = new String(trueValue);
- }
-
- /**
- * Establishes what database value will be interpreted as the value: false.
- * The default value is "false" (without the quotes).
- *
- * @param falseValue the string to interpret as the value: false
- */
- public void setFalseValue(String falseValue)
- {
- m_falseValue = new String(falseValue);
- }
-
- /**
- * Establishes what database value will be interpreted as the value: other
- * (the third state of this three-state checkbox).
- * The default value is "" (the empty string without quotes).
- *
- * @param otherValue the string to interpret as the value: other
- */
- public void setOtherValue(String otherValue)
- {
- m_otherValue = new String(otherValue);
- }
-
- /**
- * Binds this component to a given projection within the specified
- * relation view.
- *
- * @param relView the relation view to bind with
- * @param projection the projection in relView to bind with
- */
- public void setBinding(RelationView relView, String projection)
- {
- m_Helper.setBinding(relView, projection);
- }
-
- /**
- * Returns the projection in the RelationView that this component is bound with.
- * @see #setBinding
- * @see #setProjection
- */
- public String getProjection() {
- return m_Helper.getProjection();
- }
-
- /**
- * Binds this component to the given projection within the RelationView
- * the component is currently bound with.
- * @see #setBinding
- * @see #getProjection
- * @see #getRelationView
- */
- public void setProjection(String projection) {
- m_Helper.setProjection(projection);
- }
-
- /**
- * Gets the RelationView that this component is bound with.
- * @return the RelationView currently bound with
- * @see #setRelationView
- * @see #setBinding
- * @see #getProjection
- */
- public RelationView getRelationView() {
- return m_Helper.getRelationView();
- }
-
- /**
- * Sets the RelationView that this component is bound with.
- * @param value the RelationView to bind with
- * @see #getRelationView
- * @see #setBinding
- * @see #setProjection
- */
- public void setRelationView(RelationView rv) {
- m_Helper.setRelationView(rv);
- }
-
- /**
- * Specifies how an empty string will be set when updating data on
- * the dbANYWHERE server.
- *
- * @param blank one of "DEFAULT", "NULL", or "BLANK"
- *
- * @see symantec.itools.db.pro.ProjBinder#setValueFromString(java.lang.String, int, int)
- */
- public void setTreatBlankAs(int value) {
- m_Helper.setTreatBlankAs(value);
- }
-
- /**
- * Indicates when the component commits its changes.
- * @see #setDynamicUpdate
- */
- public boolean getDynamicUpdate() {
- return m_Helper.getDynamicUpdate();
- }
-
- /**
- * Sets when the component commits its changes.
- * @param value the new dynamic update mode value
- * @see #getDynamicUpdate
- */
- public void setDynamicUpdate(boolean value) {
- m_Helper.setDynamicUpdate(value);
- }
-
- /**
- * Gets the value of this component.
- * @return the current component value
- * @see #setData
- */
- public Object getData() {
- String value = "";
- switch (getState()) {
- case 1:
- value = m_trueValue;
- break;
-
- case 0:
- value = m_falseValue;
- break;
-
- case 2:
- value = m_otherValue;
- break;
- }
- return value;
- }
-
- /**
- * Sets the value of this component to the given value.
- * @param value the new component value
- * @see #getData
- */
- public void setData(Object value) {
- if (value != null) {
- try {
- if (value.equals(m_trueValue)) {
- setState(1);
- }
- else if (value.equals(m_falseValue)) {
- setState(0);
- }
- else {
- setState(2);
- }
- }
- catch (Exception ex) {
- m_Helper.raiseException(ex);
- }
- }
- }
-
- /**
- * Sets whether the data value of this component may be modified.
- * @param value <code>true</code> if the value may not be modified,
- * <code>false</code>if the value may be modified
- */
- public void setReadOnly(boolean value) {
- }
-
- /**
- * Gets whether this component saves its value as a text String.
- * @return <code>true</code> if the value is saved as text,
- * <code>false</code> otherwise
- */
- public boolean isTextBased() {
- return true;
- }
-
- /**
- * Gets the number of digits to the right of the decimal point for
- * this component's value.
- * @return the number of digits to the right of the decimal point
- */
- public int getScale() {
- return ProjBinder.DEFAULTSCALE;
- }
-
- /**
- * Registers the standard event listener(s) for this component.
- */
- public void registerListeners() {
- addActionListener(m_Helper);
- }
-
- /**
- * Sets the value of the Empty Means Null property.
- * This determines how an empty string will be saved when updating data on
- * the database server.
- * A value of <code>true</code>indicates an empty string will be saved as a
- * SQL NULL value. Otherwise it will be saved as a blank value.
- * @param propertyValue <code>true</code> for NULL, <code>false</code> for BLANK
- * @see #getEmptyMeansNull
- */
- public void setEmptyMeansNull(boolean propertyValue)
- {
- m_Helper.setEmptyMeansNull(propertyValue);
- }
-
- /**
- * Gets the value of the Empty Means Null property.
- * This determines how an empty string will be saved when updating data on
- * the database server.
- * A value of <code>true</code>indicates an empty string will be saved as a
- * SQL NULL value. Otherwise it will be saved as a blank value.
- * @return <code>true</code> for NULL, <code>false</code> for BLANK
- * @see #setEmptyMeansNull
- */
- public boolean getEmptyMeansNull()
- {
- return m_Helper.getEmptyMeansNull();
- }
- }
-