home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
ResolverFrame.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
8KB
|
182 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.resolverevents;
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.util.*;
import java.lang.*;
public class ResolverFrame extends DecoratedFrame {
BorderLayout borderLayout1 = new BorderLayout();
BevelPanel bevelPanel1 = new BevelPanel();
Database database1 = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
QueryResolver queryResolver1 = new QueryResolver();
ListControl listControl1 = new ListControl();
GridControl gridControl1 = new GridControl();
ButtonControl buttonControl1 = new ButtonControl();
GridBagLayout gridBagLayout1 = new GridBagLayout();
//Construct the frame
public ResolverFrame() {
try {
jbInit();
}
catch (Exception e) {
borland.jbcl.util.Diagnostic.printStackTrace(e);
}
}
//Component initialization
private void jbInit() throws Exception{
this.setLayout(borderLayout1);
this.setTitle("Resolver Example");
bevelPanel1.setLayout(gridBagLayout1);
database1.setConnection(new borland.sql.dataset.ConnectionDescriptor("jdbc:odbc:DataSet Tutorial", "sysdba", "masterkey", false, "sun.jdbc.odbc.JdbcOdbcDriver;"));
queryDataSet1.setQuery(new borland.sql.dataset.QueryDescriptor(database1, "select * from customer", null, true, Load.ALL));
queryDataSet1.setResolver(queryResolver1);
queryResolver1.setUpdateMode(borland.jbcl.dataset.UpdateMode.KEY_COLUMNS);
queryResolver1.addResolverListener(new ResolverFrame_queryResolver1_resolverAdapter(this));
gridControl1.setDataSet(queryDataSet1);
buttonControl1.setLabel("Save Changes");
buttonControl1.addActionListener(new ResolverFrame_buttonControl1_actionAdapter(this));
this.add(bevelPanel1, BorderLayout.CENTER);
bevelPanel1.add(gridControl1, new GridBagConstraints2(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), -800, -100));
this.add(listControl1, BorderLayout.SOUTH);
this.add(buttonControl1, BorderLayout.NORTH);
}
// Restrict an action.
void queryResolver1_deletingRow(ReadWriteRow readWriteRow, ResolverResponse resolverResponse) throws DataSetException{
// Don't allow anybody to delete a customer record.
resolverResponse.abort();
}
// Ignore action errors.
void queryResolver1_insertError(DataSet dataSet, ReadWriteRow readWriteRow, DataSetException dataSetException, ErrorResponse errorResponse) throws DataSetException{
// Display error message with customer name and exception.
listControl1.addItem("Error inserting " + readWriteRow.getString("customer"));
listControl1.addItem(" " + dataSetException.getMessage());
// Ignore the error.
errorResponse.ignore();
}
// Perform some basic validation of a column value before the action.
void queryResolver1_insertingRow(ReadWriteRow readWriteRow, ResolverResponse resolverResponse) throws DataSetException{
// Get the country value from the row to be inserted
String country = readWriteRow.getString("country");
// Validate that the new customers are only from the United States.
if (!country.equals("USA"))
resolverResponse.abort();
}
// Indicate that the action was performed.
void queryResolver1_insertedRow(ReadWriteRow readWriteRow) throws DataSetException{
// Add a line to the list control indicating that the new row was inserted.
listControl1.addItem(readWriteRow.getString("customer") + " was inserted.");
}
// Abort action if error occurs.
void queryResolver1_updateError(DataSet dataSet, ReadWriteRow readWriteRow, ReadRow readRow, ReadWriteRow readWriteRow1, DataSetException dataSetException, ErrorResponse errorResponse) throws DataSetException{
errorResponse.abort();
}
// Using column value as a criteria, indicate that the action was performed.
void queryResolver1_updatedRow(ReadWriteRow readWriteRow, ReadRow readRow) throws DataSetException{
String newCustomer = readWriteRow.getString("customer");
String oldCustomer = readRow.getString("customer");
// If the customer name was changed, use a different message.
if (!oldCustomer.equals(newCustomer))
listControl1.addItem("Customer " + oldCustomer + " was changed to " + newCustomer);
else
listControl1.addItem("Customer " + oldCustomer + " was updated." );
}
void buttonControl1_actionPerformed(ActionEvent e) {
try {
database1.saveChanges(queryDataSet1);
}
catch(DataSetException dse){
listControl1.addItem(dse);
}
}
}
class ResolverFrame_queryResolver1_resolverAdapter extends borland.jbcl.dataset.ResolverAdapter{
ResolverFrame adaptee;
ResolverFrame_queryResolver1_resolverAdapter(ResolverFrame adaptee) {
this.adaptee = adaptee;
}
public void deletingRow(ReadWriteRow readWriteRow, ResolverResponse resolverResponse) throws DataSetException{
adaptee.queryResolver1_deletingRow(readWriteRow, resolverResponse);
}
public void insertError(DataSet dataSet, ReadWriteRow readWriteRow, DataSetException dataSetException, ErrorResponse errorResponse) throws DataSetException{
adaptee.queryResolver1_insertError(dataSet, readWriteRow, dataSetException, errorResponse);
}
public void insertingRow(ReadWriteRow readWriteRow, ResolverResponse resolverResponse) throws DataSetException{
adaptee.queryResolver1_insertingRow(readWriteRow, resolverResponse);
}
public void insertedRow(ReadWriteRow readWriteRow) throws DataSetException{
adaptee.queryResolver1_insertedRow(readWriteRow);
}
public void updateError(DataSet dataSet, ReadWriteRow readWriteRow, ReadRow readRow, ReadWriteRow readWriteRow1, DataSetException dataSetException, ErrorResponse errorResponse) throws DataSetException{
adaptee.queryResolver1_updateError(dataSet, readWriteRow, readRow, readWriteRow1, dataSetException, errorResponse);
}
public void updatedRow(ReadWriteRow readWriteRow, ReadRow readRow) throws DataSetException{
adaptee.queryResolver1_updatedRow(readWriteRow, readRow);
}
}
class ResolverFrame_buttonControl1_actionAdapter implements java.awt.event.ActionListener {
ResolverFrame adaptee;
ResolverFrame_buttonControl1_actionAdapter(ResolverFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.buttonControl1_actionPerformed(e);
}
}