home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
jbuilder
/
jsamples.z
/
Frame1.java
< prev
next >
Wrap
Text File
|
1997-07-24
|
5KB
|
135 lines
package borland.samples.tutorial.dataset.filterrows;
import java.awt.*;
import java.awt.event.*;
import borland.jbcl.control.*;
import borland.jbcl.layout.*;
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
public void jbInit() throws Exception{
this.setLayout(borderLayout1);
this.setSize(new Dimension(846, 300));
this.setTitle("Frame Title");
bevelPanel1.setLayout(gridBagLayout1);
queryDataSet1.setQuery(new borland.jbcl.dataset.QueryDescriptor(database1, "select * from employee", null, true, false));
//queryDataSet1.addRowFilterListener(new Frame1_queryDataSet1_rowFilterAdapter(this));
database1.setConnection(new borland.jbcl.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");
// ex.printStackTrace(System.err);
}
}
}
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);
}
}