home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
Frame1.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
6KB
|
152 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.filterrows;
import java.awt.*;
import java.awt.event.*;
import borland.jbcl.control.*;
import borland.jbcl.layout.*;
import borland.sql.dataset.*;
import borland.jbcl.dataset.*;
import borland.jbcl.model.*;
import borland.jbcl.util.Variant;
public class Frame1 extends DecoratedFrame {
BorderLayout borderLayout1 = new BorderLayout();
BevelPanel bevelPanel1 = new BevelPanel();
QueryDataSet queryDataSet1 = new QueryDataSet();
Database database1 = new Database();
GridControl gridControl1 = new GridControl();
TextFieldControl textFieldControl1 = new TextFieldControl();
TextFieldControl textFieldControl2 = new TextFieldControl();
ButtonControl buttonControl1 = new ButtonControl();
// User defined variables.
String columnName = "Last_Name";
String columnValue = "Young";
VariantFormatter formatter;
RowFilterListener listener;
Variant v = new Variant();
GridBagLayout gridBagLayout1 = new GridBagLayout();
//Construct the frame
public Frame1() {
try {
jbInit();
}
catch (Exception e) {
borland.jbcl.util.Diagnostic.printStackTrace(e);
}
}
//Component initialization
private void jbInit() throws Exception{
this.setLayout(borderLayout1);
this.setTitle("Filter on Selected Column and Value");
bevelPanel1.setLayout(gridBagLayout1);
queryDataSet1.setQuery(new borland.sql.dataset.QueryDescriptor(database1, "select * from employee", null, true, Load.ALL));
database1.setConnection(new borland.sql.dataset.ConnectionDescriptor("jdbc:odbc:dataset tutorial", "SYSDBA", "masterkey", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
gridControl1.setDataSet(queryDataSet1);
buttonControl1.setLabel("Filter now");
buttonControl1.addActionListener(new Frame1_buttonControl1_actionAdapter(this));
this.add(bevelPanel1, BorderLayout.CENTER);
bevelPanel1.add(gridControl1, new GridBagConstraints2(0, 1, 4, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 15, 4, 8), -710, -673));
bevelPanel1.add(textFieldControl1, new GridBagConstraints2(0, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 8, 0, 0), 63, -2));
bevelPanel1.add(textFieldControl2, new GridBagConstraints2(1, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 0, 0, 0), 64, -1));
bevelPanel1.add(buttonControl1, new GridBagConstraints2(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 10, 0, 0), 28, 1));
textFieldControl1.setText(columnName);
textFieldControl2.setText(columnValue);
}
void queryDataSet1_filterRow(ReadRow readRow, RowFilterResponse rowFilterResponse) throws DataSetException
{
if (formatter == null || columnName == null || columnValue == null ||
columnName.length() == 0 || columnValue.length() == 0)
// user set field(s) blank, so add all rows
rowFilterResponse.add();
else {
readRow.getVariant(columnName, v); // fetches row's value of column
String s = formatter.format(v); // formats this to a string
// true means show this row
if (columnValue.equals(s))
rowFilterResponse.add();
else rowFilterResponse.ignore();
}
}
void buttonControl1_actionPerformed(ActionEvent e) {
try {
// Here is where we manufacture a RowFilterListener from the
// textField values. The Filter class is defined below and
// is only one way to implement this.
columnName = textFieldControl1.getText();
columnValue = textFieldControl2.getText();
Column column = queryDataSet1.getColumn(columnName);
formatter = column.getFormatter();
// Remove the old listener and then add it back in again. This will
// trigger a recalc of the filters
if (listener != null)
queryDataSet1.removeRowFilterListener(listener);
listener = new Frame1_queryDataSet1_rowFilterAdapter(this);
queryDataSet1.addRowFilterListener(listener);
queryDataSet1.refilter();
// The grid should now repaint only those rows matching these criteria
}
catch (Exception ex) {
System.err.println("Filter example failed");
}
}
}
class Frame1_queryDataSet1_rowFilterAdapter implements borland.jbcl.dataset.RowFilterListener {
Frame1 adaptee;
Frame1_queryDataSet1_rowFilterAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void filterRow(ReadRow readRow, RowFilterResponse rowFilterResponse) throws DataSetException{
adaptee.queryDataSet1_filterRow(readRow, rowFilterResponse);
}
}
class Frame1_buttonControl1_actionAdapter implements java.awt.event.ActionListener {
Frame1 adaptee;
Frame1_buttonControl1_actionAdapter(Frame1 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.buttonControl1_actionPerformed(e);
}
}