home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-24 | 3.7 KB | 83 lines |
- package borland.samples.tutorial.dataset.lookup;
-
- import java.awt.*;
- import java.awt.event.*;
- import borland.jbcl.control.*;
- import borland.jbcl.layout.*;
- import borland.jbcl.dataset.*;
-
- public class Lookup_Frame extends DecoratedFrame {
- BorderLayout borderLayout1 = new BorderLayout();
- BevelPanel bevelPanel1 = new BevelPanel();
- Database database1 = new Database();
- QueryDataSet queryDataSet1 = new QueryDataSet();
- QueryDataSet queryDataSet2 = new QueryDataSet();
- GridControl gridControl1 = new GridControl();
- Column column1 = new Column();
- GridBagLayout gridBagLayout1 = new GridBagLayout();
-
- //Construct the frame
- public Lookup_Frame() {
- try {
- jbInit();
- }
- catch (Exception e) {
- borland.jbcl.util.Diagnostic.printStackTrace(e);
- }
- }
- //Component initialization
- public void jbInit() throws Exception{
- this.setLayout(borderLayout1);
- this.setTitle("Using Calculated Field for Lookup");
- bevelPanel1.setLayout(gridBagLayout1);
- database1.setConnection(new borland.jbcl.dataset.ConnectionDescriptor("jdbc:odbc:dataset tutorial", "sysdba", "masterkey", false, "sun.jdbc.odbc.JdbcOdbcDriver;borland.interclient.Driver"));
- queryDataSet1.setQuery(new borland.jbcl.dataset.QueryDescriptor(database1, "select * from EMPLOYEE_PROJECT", null, true, false));
- queryDataSet1.addCalcFieldsListener(new Lookup_Frame_queryDataSet1_calcFieldsAdapter(this));
- queryDataSet2.setQuery(new borland.jbcl.dataset.QueryDescriptor(database1, "select EMP_NO, FIRST_NAME, LAST_NAME from EMPLOYEE", null, true, false));
-
- // No UI controls are bound to queryDataSet2, so it's not opened implicitly
- // when the frame opens. We have to open it here - otherwise, its column
- // are unknown when the code in the calcFields method is executed.
- queryDataSet2.open();
-
- gridControl1.setDataSet(queryDataSet1);
- column1.setCalcType(borland.jbcl.dataset.CalcType.CALC);
- column1.setCaption("EMPLOYEE_NAME");
- column1.setColumnName("EMPLOYEE_NAME");
- column1.setDataType(borland.jbcl.util.Variant.STRING);
- this.add(bevelPanel1, BorderLayout.CENTER);
- bevelPanel1.add(gridControl1, new GridBagConstraints2(0, 0, 1, 1, 1.0, 1.0
- ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 8, 10, 8), 74, -327));
- queryDataSet1.setColumns(new Column[] {column1});
- }
-
- void queryDataSet1_calcFields(ReadRow readRow, DataRow dataRow, boolean boolean1) throws DataSetException{
- // Define a DataRow to hold the employee number to look for in
- // queryDataSet2, and another to hold the row of employee data that we find.
- DataRow lookupRow = new DataRow(queryDataSet2, "EMP_NO");
- DataRow resultRow = new DataRow(queryDataSet2);
-
- // The EMP_NO from the current row of queryDataSet1 is our lookup criterion.
- // We look for the first match, since EMP_NO is unique. If the lookup
- // succeeds, concatenate the name fields from the employee data, and put
- // the result in dataRow; otherwise, let the column remain blank.
- lookupRow.setShort("EMP_NO", readRow.getShort("EMP_NO"));
- if (queryDataSet2.lookup(lookupRow, resultRow, Locate.FIRST))
- dataRow.setString("EMPLOYEE_NAME", resultRow.getString("FIRST_NAME") +
- " " + resultRow.getString("LAST_NAME"));
- }
- }
-
- class Lookup_Frame_queryDataSet1_calcFieldsAdapter implements borland.jbcl.dataset.CalcFieldsListener {
- Lookup_Frame adaptee;
-
- Lookup_Frame_queryDataSet1_calcFieldsAdapter(Lookup_Frame adaptee) {
- this.adaptee = adaptee;
- }
-
- public void calcFields(ReadRow readRow, DataRow dataRow, boolean boolean1) throws DataSetException{
- adaptee.queryDataSet1_calcFields(readRow, dataRow, boolean1);
- }
- }
-
-