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 / RecordNumberLabel.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  3.0 KB  |  108 lines

  1. /*
  2.  * @(#RecordNumberLabel.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.awt.*;
  12. import java.util.*;
  13. import java.sql.*;
  14. import java.lang.*;
  15. import symantec.itools.db.net.*;
  16. import symantec.itools.db.pro.*;
  17. import symantec.itools.db.beans.binding.Name;
  18.  
  19. /**
  20.  * A dbAWARE Label that automatically displays the current record number
  21.  * of the RelationView it is bound with.
  22.  */
  23. public class RecordNumberLabel extends java.awt.Label
  24. {
  25.     symantec.itools.db.beans.binding.Mediator m_Mediator;
  26.     private String[] m_GetMethods={"getText()"};
  27.     private String[] m_SetMethods={"setData(Value)"};
  28.  
  29.     /**
  30.      * Constructs a new RecordNumberLabel.
  31.      * By default its label will read: "<Record Number Label>".
  32.      * <p>
  33.      * Call setRelationView() to bind this component to a RelationView and
  34.      * auto-set the label text.
  35.      *
  36.      * @see #setRelationView
  37.      */
  38.     public RecordNumberLabel()
  39.     {
  40.         super("<Record Number Label>");
  41.         m_Mediator=new symantec.itools.db.beans.binding.Mediator();
  42.         if (java.beans.Beans.isDesignTime()) {
  43.             return;
  44.         }
  45.         m_Mediator.setOutput(this);
  46.         m_Mediator.setSetMethods(m_SetMethods);
  47.         m_Mediator.setGetMethods(m_GetMethods);
  48.     }
  49.  
  50.     /**
  51.      * Sets the data source that this component is bound with.
  52.      * @param Tname the name of the data source to bind with
  53.      * @see #getDataSource
  54.      */
  55.     public void setDataSource(String Tname)
  56.     {
  57.         Name name = new Name(Tname,"RowNumber");
  58.        m_Mediator.setDataBinding(name.getFullName());
  59.     }
  60.  
  61.     /**
  62.      * Gets the data source that this component is bound with.
  63.      * @return name of the data source to bind with
  64.      * @see #setDataSource
  65.      */
  66.     public String getDataSource()
  67.     {
  68.         Name name = new Name(m_Mediator.getDataBinding());
  69.        return name.getTableName();
  70.     }
  71.  
  72.     // For backwards compatbilty only
  73.  
  74.     private RelationView m_RelationView;
  75.     /**
  76.      * Sets the RelationView that this component is bound with.
  77.      * @param rv the RelationView to bind with
  78.      * @see #getRelationView
  79.      */
  80.     public void setRelationView (RelationView rv)
  81.     {
  82.         m_RelationView = rv;
  83.         try {
  84.             setDataSource(rv.getName());
  85.         }
  86.         catch (java.sql.SQLException ex) {
  87.             // According to the RelationView class this method may
  88.             // throw an exception.  We don't believe it will happen.
  89.         }
  90.     }
  91.     /**
  92.      * Gets the RelationView that this component is bound with.
  93.      * @return the RelationView currently bound with
  94.      * @see #setRelationView
  95.      */
  96.     public RelationView getRelationView() {
  97.         return m_RelationView;
  98.     }
  99.     /**
  100.      * Sets the value of this component to the given value.
  101.      * @param value the new component value
  102.      */
  103.     public void setData(Object o)
  104.     {
  105.         setText(o.toString());
  106.     }
  107. }
  108.