Openbravo Forum End of Life Notice

Dear Openbravo Forum User,

Because of continued very low usage we decided to stop the forums on 31st of August 2017

In case of questions: webmaster "at" openbravo.com

JStringEditor keyboard event handlers

<<

DaveHackett

Site Admin

Posts: 2

Joined: Wed Jan 09, 2013 7:50 am

Post Mon Jan 02, 2017 6:25 am

JStringEditor keyboard event handlers

New to OpenBravo. Trying to do some simple mods for our club to have it work with members instead of customers.

I'd like to change the Find Customer form to use only 1 field and perform a search as the user types rather than clicking the Execute button. I think I've got the search worked out Ok and have it searching on 3 database fields using just the 1 input field but I cannot get the JStringEdit field to fire any keyboard events. I see that it is a descendant of a JPanel but I don't see any code that would prevent the listeners from working. Other events happen (focus & exit for example) but none of the 3 key listeners.

What am I not seeing?

Thanks in advance,
DaveH
<<

DaveHackett

Site Admin

Posts: 2

Joined: Wed Jan 09, 2013 7:50 am

Post Tue Jan 03, 2017 7:29 pm

Re: JStringEditor keyboard event handlers

Answer to my own question...

The original authors comply with the PropertyChange model for swing fields. Therefore, create a PropertyChangeListener class and hook that up to the JStringEditor.

Code example:

private void init(DataLogicCustomers dlCustomers) {
...
m_jtxtSearchFor.addPropertyChangeListener("Text", new TextFieldListener());
...
}

defined within JCustomerFinder.java...

private class TextFieldListener implements PropertyChangeListener
{
@Override
public void propertyChange(PropertyChangeEvent e)
{
Object source = e.getSource();
if (source == m_jtxtSearchFor)
{
if (e.getNewValue() != e.getOldValue())
executeSearch();
}
}
}

I removed the Execute button but kept the Reset button. Changed the SQL Search query to use an OR clause instead of an AND clause. Now it searches the database on the SearchKey, Name and Tax Id as the user types in the SearchFor field.

Almost every sale for our club is for a member so this really speeds up the checkout process.

DaveH

Return to Developers

Who is online

Users browsing this forum: No registered users and 7 guests

cron
Website Terms


Designed by ST Software for PTF.