home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 8.9 KB | 257 lines |
- /*
- *
- */
-
- package symantec.itools.db.awt;
-
- import java.util.*;
- import symjava.sql.*;
- import java.lang.*;
- import symantec.itools.db.net.*;
- import symantec.itools.db.pro.*;
-
- public class RadioButton extends java.awt.Checkbox implements ProjLink
- {
- /**
- * The ProjBinder object which this component can use to get data from
- * the server, or change data at the database server.
- */
- private ProjBinder m_ProjBinder;
-
- private String m_Data; // Keep in synch with database
- private String m_Input; // Keep in synch with screen text
- private int m_treatBlankAs = 0;
- private boolean m_DynamicUpdate = false;
- private boolean m_ignoreStateChange = true;
-
- public RadioButton()
- {
- super.setLabel("<dbAWARE RadioButton>");
- }
-
- public RadioButton(String label, symantec.itools.db.awt.RadioBox rb, boolean state)
- {
- super(label, rb, state);
- setBinding(rb.getRelView(), rb.getProjection());
- }
-
- public void setTreatBlankAs(String blank)
- {
- if (new String(blank).toUpperCase().equals("DEFAULT"))
- {
- m_treatBlankAs = RelationView.SETBLANKTODEFAULT;
- }
- else if (new String(blank).toUpperCase().equals("NULL"))
- {
- m_treatBlankAs = RelationView.SETBLANKTONULL;
- }
- else if (new String(blank).toUpperCase().equals("BLANK"))
- {
- m_treatBlankAs = RelationView.SETBLANKTOEMPTY;
- }
- }
-
- public void setBinding(RelationView relView, String projection)
- {
- try
- {
- int projectionNumber = relView.findProjByName(projection);
- relView.bindProj(projectionNumber, this);
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from RadioButton.setBinding: "
- + Ex.getMessage());
- }
- }
-
- /**
- * Implement the ProjLink interface function, init().
- * This function is called when the control is first bound to data.
- *
- * @param binder The ProjBinder binder object which this component can use
- * to change data at the database server.
- */
- public void init (ProjBinder binder)
- {
- m_ProjBinder = binder;
- setEditable(m_ProjBinder);
- }
-
- /**
- * Implement the ProjLink interface function, notifyDataChange().
- * This function is called when the projection's data changes at the database.
- *
- * @param binder The ProjBinder binder object which this component can use
- * to get or change data at the database server.
- */
- public void notifyDataChange(ProjBinder binder)
- {
- m_ignoreStateChange = true;
- if (binder != null)
- {
- m_ProjBinder = binder;
- }
-
- String sLabel = new String(getLabel());
- String data = new String();
- try
- {
- if (binder.isReadable() && !binder.isNull())
- {
- data = binder.getStringValue();
- if (sLabel.compareTo(data) == 0)
- {
- setState(true);
- }
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from RadioButton.notifyDataChange: "
- + Ex.getMessage());
- }
- catch (java.io.IOException Ex)
- {
- raiseException(
- "IOException from RadioButton.notifyDataChange: "
- + Ex.getMessage());
- }
- setEditable(m_ProjBinder);
- }
-
- // When the control loses focus, pass the text from the
- // control to dbANYWHERE. This keeps dbANYWHERE up to date.
- // Pass the lostfocus event to the base class. This allows
- // standard lostfocus processing to occur.
- //
- // NOTE: We only pass the data if it has changed.
- /**
- * catch the lost focus notification and pass the new data to the database server.
- *
- * @param evt the lost focus event being caught
- * @param what the object that is losing focus
- */
- public boolean lostFocus(java.awt.Event evt, Object what)
- {
- notifyStateChange();
- return super.lostFocus(evt, what);
- }
-
- public boolean notifySetData(ProjBinder binder)
- {
- return ( notifyStateChange() );
- }
-
- boolean notifyStateChange()
- {
- if (!m_ignoreStateChange)
- {
- java.awt.CheckboxGroup rbg = getCheckboxGroup();
- if (rbg.getCurrent() == this)
- {
- try
- {
- if (m_ProjBinder != null && m_ProjBinder.isWritable())
- {
- m_ProjBinder.setValueFromString(getLabel(), 0, m_treatBlankAs);
- }
- }
- catch (SQLException Ex)
- {
- System.out.println("SQLException from TextField.notifyInputChange.setString: "
- + Ex.getMessage());
- return false;
- }
- catch (java.io.IOException Ex)
- {
- System.out.println("IOException from TextField.notifyInputChange.setString: " + Ex.getMessage());
- return false;
- }
- }
- }
- return true;
- }
-
- /**
- * Handles the event. Returns true if the event is handled and
- * should not be passed to the parent of this component. The default
- * event handler calls some helper methods to make life easier
- * on the programmer.
- * @param evt the event
- * @see #mouseEnter
- * @see #mouseExit
- * @see #mouseMove
- * @see #mouseDown
- * @see #mouseDrag
- * @see #mouseUp
- * @see #keyDown
- * @see #action
- */
- public boolean handleEvent(java.awt.Event evt) {
- m_ignoreStateChange = false;
- notifyStateChange();
- return super.handleEvent(evt);
- }
-
- void setEditable(ProjBinder binder)
- {
- //Disable change of state if binder is not writeable
- disable();
- try
- {
- if (binder != null)
- {
- RelationView rv = binder.getRelationView();
- if (rv != null && (rv.getCurrentRecordState() != Record.RECSTATE_INVALID))
- {
- enable();
- }
- }
- }
- catch (SQLException Ex)
- {
- System.out.println(Ex.getMessage());
- }
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: raiseException //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- void raiseException(String text)
- {
- System.out.println(text);
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setDynamicUpdate //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public void setDynamicUpdate(boolean update)
- {
- m_DynamicUpdate = update;
- }
- }