Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT/Jface (Displya result on tabel viewer on button click using SWT/Jface)
SWT/Jface [message #986577] Tue, 20 November 2012 21:44 Go to previous message
Prashant p is currently offline Prashant p
Messages: 57
Registered: October 2012
Member
There is one scnerio. I have Search text field which gets autopopulated and On click of submit button it should populate Table viewer as a result of seacrh criteria. Please let me know how can i achieve this with SWT/Jface Data binding.

All process is Database driven.

Below is the code snippet.


text_workplace--> is Text field to auto populate field

text_workplace.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent ke) {
Connection con = null;
Statement st= null;
ResultSet resultSetWorkplaceSrch;
PreparedStatement pstmt;
String query= "SELECT WorkplaceName FROM Workplace where workplaceCode=?";

try
{

Class.forName("org.sqlite.JDBC");
con = DriverManager.getConnection("jdbc:sqlite:C:\\Database\\ProManager");
pstmt = con.prepareStatement(query);
pstmt.setInt(1, 1437);
resultSetWorkplaceSrch= pstmt.executeQuery();

while(resultSetWorkplaceSrch.next()){
text_workplace.setText(resultSetWorkplaceSrch.getString(1));
}
}catch(Exception err){
System.out.println(err);
}
}
});



btnSearch --> Button to display result in SWT table viewer based on value of text field.
workplaceDetail- Is POJO


btnSearch = new Button(composite, SWT.NONE);
btnSearch.setBounds(248, 120, 47, 25);
btnSearch.setText("Search");
btnSearch.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String selected=text_workplace.getText();
IStructuredSelection selection = (IStructuredSelection) m_workplaceViewer.getSelection();
workplaceDetail = (WorkplaceDetail) selection.getFirstElement();
if (selected==""){

WorkplaceDaoImpl workplaceDaoImpl = new WorkplaceDaoImpl();
int code = 1437; workplaceDaoImpl.getWorkplaceDetailsSearchById(code);
bindingContext.updateModels();
}
}
});

WorkplaceDaoImpl - DAO implementation to query result from DB.
 
Read Message
Read Message
Previous Topic:SWT Tools Update Sites
Next Topic:Multiple viewport on the same canvas
Goto Forum:
  


Current Time: Wed May 22 12:32:07 EDT 2013

Powered by FUDForum. Page generated in 0.01615 seconds