/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BodegaPOS;

import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JList;

/**
 *
 * @author Daniel
 */
public class WSThread extends Thread {

    private DefaultListModel modelo;
    private ArrayList<Solicitud> solicitud = new ArrayList<Solicitud>();
    private PrinterGui gui;
    private int max = 0;

    public WSThread(DefaultListModel modelo, ArrayList<Solicitud> solicitud, PrinterGui gui) {
        this.modelo = modelo;
        this.solicitud = solicitud;
        this.gui = gui;
    }

    @Override
    public void run() {

            ws.SolicitudesService service = new ws.SolicitudesService();
            ws.Solicitudes port = service.getSolicitudesPort();
            try { // Call Web Service Operation

                // TODO process result here
                java.util.List<ws.Outcome> result = port.findAll();
                System.out.println("Result = " + result);

            
                    modelo.removeAllElements();
                    for (int j = 0; j < result.size(); j++) {
                        Solicitud sol = new Solicitud();
                        sol.id = "" + result.get(j).getId();
                        sol.nombre = result.get(j).getOwner().getFirstname();
                        modelo.addElement(sol.id + "-" + sol.nombre);
                        for (int i = 0; i < result.get(j).getQuantity(); i++) {
                            sol.iditem.add(result.get(j).getOutcomeItemId().get(i));
                            sol.nombreitem.add(result.get(j).getOutcomeItemName().get(i));
                            sol.cantidaditem.add(result.get(j).getOutcomeItemCant().get(i));
                        }
                        this.solicitud.add(sol);
                    }
                    max = result.size();

                    gui.Lista.setModel(modelo);
                    gui.Lista.validate();
                    gui.validate();

            } catch (Exception ex) {
                // TODO handle custom exceptions here
            } finally {
            }
    }
}
