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] Wed, 21 November 2012 02:44 Go to next message
Prashant p is currently offline Prashant pFriend
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.
Re: SWT/Jface [message #986839 is a reply to message #986577] Wed, 21 November 2012 21:37 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2151
Registered: July 2009
Senior Member
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.
>
Previous Topic:SWT Tools Update Sites
Next Topic:Multiple viewport on the same canvas
Goto Forum:
  


Current Time: Fri Nov 28 11:29:54 GMT 2014

Powered by FUDForum. Page generated in 0.01615 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software