SWT/Jface [message #986577] |
Tue, 20 November 2012 21:44  |
Eclipse User |
|
|
|
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.
|
|
|
Re: SWT/Jface [message #986839 is a reply to message #986577] |
Wed, 21 November 2012 16:37  |
Eclipse User |
|
|
|
If this is a question on the data binding then you should ask in the
JFace forum/newsgroup. JFace is not part of SWT.
Grant
On 11/20/2012 9:44 PM, Prashant p wrote:
> 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.
>
|
|
|
Powered by
FUDForum. Page generated in 0.05294 seconds