home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 12.6 KB | 406 lines |
- /*
- * @(#ProjectionBeanHelper.java
- *
- * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
- *
- */
-
- package symantec.itools.db.awt;
-
- import symantec.itools.db.pro.*;
- import java.sql.SQLException;
- import java.io.*;
- import java.awt.event.*;
- import java.awt.*;
- import symantec.itools.db.beans.binding.Name;
-
- /**
- * Common code required to implement dbAWARE components.
- */
- public class ProjectionBeanHelper extends KeyAdapter
- implements ProjLink, ActionListener, FocusListener, ItemListener, TextListener {
-
- private ProjBinder m_ProjBinder; // Object used to interact with server
-
- private int m_ColumnType = 0;
- private boolean m_IsBound = false;
- private boolean m_DynamicUpdate = true;
- private boolean m_BinderDetermines = true;
- private Object m_BinderData; // Keep in synch with database
- private Object m_ScreenData; // Keep in synch with screen text
- private RelationView m_RelationView;
- private String m_ProjectionName = "";
-
- private ProjectionBean m_ProjectionBean;
- private String[] m_GetMethods={"getData()"};
- private String[] m_SetMethods={"setData(Value)"};
-
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is ACTION_PERFORMED.
- */
- public static final int Action_Event=0;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is FOCUS_LOST.
- */
- public static final int Focus_Event=1;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is KEY_PRESSED.
- */
- public static final int Key_Event=2;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is ITEM_STATE_CHANGED.
- */
- public static final int Item_Event=5;
- /**
- * Constant value for the Triggering Event property.
- * Indicates the triggering event is TEXT_VALUE_CHANGED.
- */
- public static final int Text_Event=4;
-
- /**
- * A constant value indicating how an empty string will be saved in the database.
- */
- public static final String BLANK="Blank";
- /**
- * A constant value indicating how an empty string will be saved in the database.
- */
- public static final String NULL="Null";
- /**
- * A constant value indicating how an empty string will be saved in the database.
- */
- public static final String DEFAULT="Default";
-
- /**
- * The mediator used to bind this component with the data source.
- */
- public symantec.itools.db.beans.binding.Mediator m_Mediator;
-
- ProjectionBeanHelper(ProjectionBean bean) {
-
- m_ScreenData = new String();
- m_BinderData = new String();
- m_ProjectionBean = bean;
- m_Mediator=new symantec.itools.db.beans.binding.Mediator();
- m_Mediator.setOutput(m_ProjectionBean);
- m_Mediator.setSetMethods(m_SetMethods);
- m_Mediator.setGetMethods(m_GetMethods);
- }
-
- /**
- * Called when this component has been bound to a projection within an
- * RelationView. This component notes the ProjBinder object so that it
- * may notify the dbANYWHERE server of data changes made.
- * <p>
- * This is a method in the ProjLink interface.
- *
- * @param binder used to notify the dbANYWHERE server of any data changes
- * that are to be persistant.
- * This object is a window into the particular column data to which this
- * component has been bound
- *
- * @see symantec.itools.db.pro.ProjLink#init
- */
- public void init(ProjBinder binder) {
- synchronized (this) {
- m_IsBound = true;
- m_ProjBinder = binder;
- setReadOnly(binder);
- }
- }
-
- /**
- * This method is called to ensure the value of this dbAWARE component is
- * not lost.
- * It is called when the dbANYWHERE server has detected a data change made
- * within the current row of the RelationView bound to this component.
- * The ProjBinder object passed into the notification is used to set the
- * new data value.
- * <p>
- * This is a method in the ProjLink interface.
- *
- * @param binder used to notify the dbANYWHERE server of any data changes
- * that are to be persistant.
- * This object is a window into the particular column data to which this
- * component has been bound
- * @return true if success or false if failure.
- * @exception SQLException
- * if a SQL database access error occurred
- * @see symantec.itools.db.pro.ProjLink#notifySetData
- */
- public boolean notifySetData(ProjBinder binder) throws SQLException
- {
- // return notifyInputChanged();
- return false;
- }
-
- /**
- * This method is called to update the value of this dbAWARE component.
- * It is called when the dbANYWHERE server has detected a data change made
- * within the scope of the current row of the RelationView bound to this
- * component.
- * The ProjBinder object passed into the notification is used to get the
- * new data value.
- * <p>
- * This is a method in the ProjLink interface.
- *
- * @param binder used to get the current value from the dbANYWHERE server.
- * This object is a window into the particular column data to which this
- * component has been bound
- *
- * @see symantec.itools.db.pro.ProjLink#notifyDataChange
- */
- // Step 1: set m_ProjBinder equal to binder object //
- // Step 2: synchronize m_BinderData with binder object //
- // Step 3: synchronize m_ScreenData with current screen //
- // Step 4: if the two are different then //
- // - set m_ScreenData equal to m_BinderData to avoid recursion //
- // - call setText to update screen //
- // Step 5: enable or disable editing based on binder //
- // //
-
- public void notifyDataChange(ProjBinder binder)
- {
-
- }
-
- /**
- * This method is called by the component when it
- * may need to be re-bound to the data source.
- */
- public void notifyDataChange()
- {
- setDataBinding(getDataBinding());
- }
-
- void raiseException(Exception ex)
- {
- System.out.println("Exception class [" + ex.getClass().getName() + "]");
- System.out.println("Exception message [" + ex.getMessage() + "]");
- Thread.dumpStack();
- }
-
- void setReadOnly(ProjBinder binder)
- {
- //Disable input if binder is not writeable
- boolean isWritable = false;
-
- try
- {
- if (binder != null)
- {
- isWritable = binder.isWritable();
- }
- }
- catch (Exception Ex)
- {
- raiseException(Ex);
- }
-
- m_ProjectionBean.setReadOnly(!isWritable);
- }
-
-
- boolean notifyInputChanged(Object input)
- {
- m_Mediator.commit();
- return true;
- }
-
- /**
- * 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
- */
- synchronized void setBinding(RelationView relView, String projection)
- {
-
- m_RelationView = relView;
- m_ProjectionName = projection;
-
- if (m_RelationView == null || m_ProjectionName == null) {
- return; // nothing to do
- }
-
- if (m_ProjectionName.equals("")) {
- return; // nothing to do
- }
-
- try {
- Name name = new Name(m_RelationView.getName(),m_ProjectionName);
- m_Mediator.setDataBinding(name.getFullName());
- }
- catch (java.sql.SQLException e) {
- raiseException(e);
- }
-
- }
-
- synchronized void setDataBinding(Name name)
- {
- m_Mediator.setDataBinding(name.getFullName());
- }
-
- synchronized Name getDataBinding()
- {
- return new Name(m_Mediator.getDataBinding());
- }
-
- synchronized void setBinderDeterminesReadOnly(boolean value) {
- m_BinderDetermines = value;
- }
-
- synchronized void setTreatBlankAs(int value) {
- m_Mediator.setEmptyMeansNull(value == m_Mediator.Null);
- }
-
- synchronized void setTreatBlankAsString(String value) {
- if(value.equals(BLANK))
- setTreatBlankAs(symantec.itools.db.beans.binding.Mediator.Blank);
- else if(value.equals(NULL))
- setTreatBlankAs(symantec.itools.db.beans.binding.Mediator.Null);
- else setTreatBlankAs(symantec.itools.db.beans.binding.Mediator.Default);
- }
-
- synchronized void setDynamicUpdate(boolean value) {
- /* if(m_DynamicUpdate!=value && value==true){
- (m_ProjectionBean).setTriggeringEvent(Key_Event);
- }
- if(m_DynamicUpdate!=value && value==false){
- ((Component)m_ProjectionBean).removeKeyListener(this);
- }*/
- m_DynamicUpdate = value;
- }
-
- synchronized boolean getDynamicUpdate() {
- return m_DynamicUpdate;
- }
-
- synchronized void setProjection(String value) {
- setBinding(m_RelationView, value);
- }
-
- synchronized String getProjection() {
- return m_ProjectionName;
- }
-
- synchronized void setRelationView(RelationView value) {
- setBinding(value, m_ProjectionName);
- }
-
- synchronized RelationView getRelationView() {
- return m_RelationView;
- }
-
- synchronized String getRelationViewName() {
- if (m_RelationView != null) {
- try {
- return m_RelationView.getName();
- }
- catch (Exception ex) {
- raiseException(ex);
- }
- }
- return "null";
- }
-
- synchronized ProjBinder getBinder() {
- return m_ProjBinder;
- }
-
- /**
- * Handles Focus Gained events.
- * @param e the FocusEvent
- */
- public void focusGained(FocusEvent e) {
- }
-
- /**
- * Handles Focus Lost events.
- * Used to commit data to the data source.
- * @param e the FocusEvent
- */
-
- public void focusLost(FocusEvent e) {
- m_Mediator.commit();
- }
-
- /**
- * Invoked when a key has been released.
- * Used to commit data to the data source.
- * @param e the event
- */
- public void keyReleased(KeyEvent e) {
- m_Mediator.commit();
-
- }
-
- /**
- * Invoked when an action occurs.
- * Used to commit data to the data source.
- * @param e the event
- */
- public void actionPerformed(ActionEvent e) {
- m_Mediator.commit();
- }
-
- /**
- * Invoked when an item's state has been changed.
- * Used to commit data to the data source.
- * @param e the event
- */
- public void itemStateChanged(ItemEvent e) {
- m_Mediator.commit();
- }
-
- /**
- * Invoked when the value of the text has changed.
- * Used to commit data to the data source.
- * @param e the event
- */
- public void textValueChanged(TextEvent e) {
- m_Mediator.commit();
- }
- /**
- * Gets the mediator used to bind the component to a data source.
- * @return the mediator
- */
- public symantec.itools.db.beans.binding.Mediator getMediator()
- {
- return m_Mediator;
- }
-
- /**
- * 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_Mediator.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_Mediator.getEmptyMeansNull();
- }
- }
-