home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
Lookup_Frame.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
5KB
|
103 lines
/*
* Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland as part
* of a Borland product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
* COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
* OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
* OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
* OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
* OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
* CODE FILE.
*/
package borland.samples.tutorial.dataset.lookup;
import java.awt.*;
import java.awt.event.*;
import borland.jbcl.control.*;
import borland.jbcl.layout.*;
import borland.sql.dataset.*;
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
private void jbInit() throws Exception{
this.setLayout(borderLayout1);
this.setTitle("Using Calculated Field for Lookup");
bevelPanel1.setLayout(gridBagLayout1);
database1.setConnection(new borland.sql.dataset.ConnectionDescriptor("jdbc:odbc:dataset tutorial", "sysdba", "masterkey", false, "sun.jdbc.odbc.JdbcOdbcDriver;borland.interclient.Driver"));
queryDataSet1.setQuery(new borland.sql.dataset.QueryDescriptor(database1, "select * from EMPLOYEE_PROJECT", null, true, Load.ALL));
queryDataSet1.addCalcFieldsListener(new Lookup_Frame_queryDataSet1_calcFieldsAdapter(this));
queryDataSet2.setQuery(new borland.sql.dataset.QueryDescriptor(database1, "select EMP_NO, FIRST_NAME, LAST_NAME from EMPLOYEE", null, true, Load.ALL));
// 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);
}
}