Return to jTable search results without SQL (with DAOMock)

I have this action ActionFindPeople

and I want to search in the db for people by first and last name inserted in 2 different text boxes.

public class ActionFindPeople extends AbstractAction{

    private Control control;

    public ActionFindPeople (Control control) {
        this.control = control;
        this.putValue(Action.NAME, "FIND");
        this.putValue(Action.SHORT_DESCRIPTION, "Find People");
        this.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_F));
        this.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("CTRL F"));
    }

    public void actionPerformed(ActionEvent e) {

        Vist vist = (Vist) this.control.getVist();
        PanelInitial pi = (PanelInitial ) vist.getUnderVist(Costant.PANEL_INITIAL);
        PannelResult pr = (PannelResult) vist.getUnderVist(Costant.PANEL_RESULT);
        Model model = (Model) this.control.getModel();

        String name = pi.getTextFieldName().getText();
        String surname = pi.getTextFieldSurname().getText();

        Db db=  (Db) control.getModel().getBean(Costant.DB);

        Person personToFind = findPerson(name, surname, db);
        if(personToFind != null) {
            model.putBean(Costant.PERSON_FOUND, personToFind );
            prp.changeComponent((Person) this.control.getModel().getBean(Costant.PERSON_FOUND));
            vist.changePanel();
        } else {
            vist.windowError("Insesistent people for " + name+ " " + surname);
        }
    }

    public Person findPerson(String name, String surname, Db db) {
        List<Person> listPerson = db.getListPerson();
        for (Person p : listPerson){
            if(p.getName().equalsIgnoreCase(name) && p.getSurname().equalsIgnoreCase(surname)){
                return p;
            }
        }
        return null;
    }

}

      

I want to try and put people who have first and last name equal in jTable, but when I do that, if people exist, it will return all people in DataBase to me! How can I solve this problem ??? Here is the code to update the table model.

public void refreshModel() {

    Model model = (Model) this.vist.getModel();
    Person person = (Person) model.getBean(Costanti.PERSON);
    Db a = (Db) model.getBean(Costanti.DB);

    ModelTable mt = new ModelTable (a);
    this.jTable.setModel(mt);
    this.jTable.setSelectionMode(SINGLE_SELECTION);
    this.jScrollPane1.setViewportView(this.jTable);

}

      

+3


source to share





All Articles