Fill a jCombobox using join and hibernate

1

I am doing a job in college that where should I create a scheduling system for sellers from a car dealership. The technologies used are Java, Swing, and Hibernate.

I divided the project into layers to make it easier, I created the client, vendor, and commitment classes to schedule vendor activities with clients. For each of these classes are in the domain layer, the connection save methods, search delete are in the dao layer, and there is a layer called control that calls the methods of an interface of each DAO class.

I made the client screen, I made the Vendors screen, but in the Commitment screen it has a JComboBox that was to show the sellers and another to show the clients, but only their references appear, not the names.

/ p>

How do I get the names of sellers and customers?

BitBucket Project

Following appointment control code:

package control;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;
import model.dao.CompromissoDao;
import model.dao.CompromissoDaoImp;
import model.domain.Cliente;
import model.domain.Compromisso;
import model.domain.Vendedor;
import model.service.ServiceLocator;
import org.jdesktop.observablecollections.ObservableCollections;

/**
 *
 * @author joao.rolim
 */
public final class CompromissoControl {
    private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
    private Compromisso compromissoDigitado;
    private Compromisso compromissoSelecionado;
    private List<Vendedor> vendedorTabela;
    private List<Cliente> clienteTable;
    private List<Compromisso> compromissoTabela;
    private final CompromissoDao compromissoDao;

    public CompromissoControl() {
        compromissoDao = ServiceLocator.getCompromissoDao();
        compromissoTabela = ObservableCollections.observableList(new ArrayList<Compromisso>());

        clienteTable = ObservableCollections.observableList(
                new ArrayList<Cliente>());
        clienteTable.addAll(compromissoDao.buscarClientes());

        vendedorTabela = ObservableCollections.observableList(new ArrayList<Vendedor>());
        vendedorTabela.addAll(compromissoDao.buscarVendedores());        
        novo();
        pesquisar();
    }

    public Compromisso getCompromissoDigitado() {
        return compromissoDigitado;
    }

    public void setCompromissoDigitado(Compromisso compromissoDigitado) {
        Compromisso oldcompromissoDigitado = this.compromissoDigitado;
        this.compromissoDigitado = compromissoDigitado;
        propertyChangeSupport.firePropertyChange("compromissoDigitado",oldcompromissoDigitado,compromissoDigitado);
    }

    public Compromisso getCompromissoSelecionado() {
        return compromissoSelecionado;
    }

    public void setCompromissoSelecionado(Compromisso compromissoSelecionado) {
        this.compromissoSelecionado = compromissoSelecionado;
        if (this.compromissoSelecionado != null) {
            setCompromissoDigitado(compromissoSelecionado);
        }

    }

    public List<Compromisso> getCompromissoTabela() {
        return compromissoTabela;
    }

    public void setCompromissoTabela(List<Compromisso> compromissoTabela) {
        this.compromissoTabela = compromissoTabela;
    }


    public void addPropertyChangeListener(PropertyChangeListener property){
       propertyChangeSupport.addPropertyChangeListener(property);
    }
    public void removePropertyChangeListener(PropertyChangeListener property){
        propertyChangeSupport.removePropertyChangeListener(property);
    }

    public void novo() {
        setCompromissoDigitado(new Compromisso());
    }


    public void salvar(){
        compromissoDao.salvarAtualizar(compromissoDigitado);
    }

    public void excluir(){
        compromissoDao.exluir(compromissoSelecionado);
    }

    public void pesquisar() {
        compromissoTabela.clear();
        compromissoTabela.addAll(compromissoDao.pesquisaGeral(compromissoDigitado));
    }

    public List<Vendedor> getVendedorTabela() {
        return vendedorTabela;

    }

    public void setVendedorTabela(List<Vendedor> vendedorTabela) {
        //Vendedor vendedor = this.vendedorTabela.
        this.vendedorTabela = vendedorTabela;
    }


    public List<Cliente> getClienteTable() {
        return this.clienteTable;


    }

    public void setClienteTable(List<Cliente> clienteTable) {
        this.clienteTable = clienteTable;
    }


}
    
asked by anonymous 27.06.2016 / 12:41

1 answer

1

The simplest way to resolve the JComboBox display problem is overwriting the toString() method of your two Sales and Customer classes, returning what you want to display. From what I saw in the codes, you can do so for both classes:

public String toString(){
    return this.nome;
}

In this way, the JCombobox will display the name of the seller and the name of the Client. Another way is creating your own ComboModel , but then you would have to create one for each combo.

    
27.06.2016 / 14:29