// This snippet creates a sample database bean
// which has a grid, navigator, and status bar.
// Properties for userName, password, etc are surfaced.
// An entirely new dataset can also be specified.
// <File=DBBean.java>
//Title:
//Version:
//Copyright:
//Author:
//Company:
//Description:
//<PACKAGE>
import java.awt.*;
import java.awt.event.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import borland.jbcl.view.*;
import borland.jbcl.dataset.*;
import borland.jbcl.util.BlackBox;
import borland.sql.dataset.*;
public class DBBean extends BeanPanel implements BlackBox {
private BorderLayout borderLayout1 = new BorderLayout();
private NavigatorControl navigatorControl1 = new NavigatorControl();
private GridControl gridControl1 = new GridControl();
private Database database1 = new Database();
private QueryDataSet queryDataSet1 = new QueryDataSet();
private StatusBar statusBar1 = new StatusBar();
private String userName = "SYSDBA";
private String password = "masterkey";
private String query = "select * from employee";
private String connectionURL = "jdbc:odbc:dataset tutorial";
public DBBean() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception{
navigatorControl1.setDataSet(queryDataSet1);
gridControl1.setDataSet(queryDataSet1);
database1.setConnection(new borland.sql.dataset.ConnectionDescriptor(
connectionURL, userName, password, false, "sun.jdbc.odbc.JdbcOdbcDriver"));
queryDataSet1.setQuery(new borland.sql.dataset.QueryDescriptor(
database1, query, null, true, Load.ALL));
statusBar1.setDataSet(queryDataSet1);
this.setLayout(borderLayout1);
this.add(navigatorControl1, BorderLayout.NORTH);
this.add(gridControl1, BorderLayout.CENTER);
this.add(statusBar1, BorderLayout.SOUTH);
}
// Example properties
public void setPassword(String s){
password=s;
database1.getConnection().setPassword(s);
}
public String getPassword(){
password=database1.getConnection().getPassword();
return password;
}
public void setUserName(String s) {
userName=s;
database1.getConnection().setUserName(s);
}
public String getUserName() {
userName=database1.getConnection().getUserName();
return userName;
}
public void setQueryDataSet(QueryDataSet qds) {
navigatorControl1.setDataSet(qds);
gridControl1.setDataSet(qds);
statusBar1.setDataSet(qds);
queryDataSet1 = qds;
}
public QueryDataSet getQueryDataSet() {
return queryDataSet1;
}
public void setQuery(String s) {
try {
query=s;
queryDataSet1.close();
queryDataSet1.setQuery(new borland.sql.dataset.QueryDescriptor(database1, query));
queryDataSet1.open();
}
catch (Exception e) {
e.printStackTrace();
}
}
public String getQuery() {
query=queryDataSet1.getOriginalQueryString();
return query;
}
public void setConnectionURL(String s) {
connectionURL=s;
database1.getConnection().setConnectionURL(s);
}
public String getConnectionURL() {
connectionURL=database1.getConnection().getConnectionURL();
return connectionURL;
}
// Example events
public static final String EXAMPLE_EVENT = "ExampleEvent";
protected void fireExampleActionEvent() {
//Args: event source,event ID, event command
processActionEvent(new ActionEvent(this,ActionEvent.ACTION_PERFORMED, EXAMPLE_EVENT));
}
}
|