/*
 * Fichero:     datosProveedor.java
 * Fecha:       20/10/06
 * Autor:       Alvaro Sarmiento Losada
 * Asignatura:  Proyecto Fin de Carrera
 * Descripción: Clase que representa una interfaz de diálogo con el usuario
 * 				a través de la cual se indica los datos de un peer que se 
 * 				va a registrar como proveedor.
 *
 * Este fichero pertenece al proyecto fin de carrera del autor,
 * consistente en el estudio de JXTA y su aplicación al comercio 
 * electrónico b2b.
 */


package com.pfc.ventanas;


import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class datosProveedor extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Text text2;
	private Text text4;
	private Button button1;
	private Label label6;
	private Label label5;
	private Label label4;
	private Label label3;
	private Label label2;
	private Text text5;
	private Text text3;
	private Text text1;
	private Label label1;
	String[]resultado=new String[6];

	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Dialog inside a new Shell.
	*/
	public static void main(String[] args) {
		try {
			Display display = Display.getDefault();
			Shell shell = new Shell(display);
			datosProveedor inst = new datosProveedor(shell, SWT.NULL);
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public datosProveedor(Shell parent, int style) {
		super(parent, style);
	}

	public String[] open() {
		try {
			Shell parent = getParent();
			dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

			FormLayout dialogShellLayout = new FormLayout();
			dialogShell.setLayout(dialogShellLayout);
			dialogShell.layout();
			dialogShell.pack();
			dialogShell.setSize(449, 461);
			dialogShell.setText("Catalogo v1.0");
			{
				button1 = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				button1.setText("Aceptar");
				FormData button1LData = new FormData();
				button1LData.width = 49;
				button1LData.height = 21;
				button1LData.left =  new FormAttachment(0, 1000, 343);
				button1LData.top =  new FormAttachment(0, 1000, 385);
				button1.setLayoutData(button1LData);
				button1.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						button1MouseDoubleClick(evt);
					}
				});
			}
			{
				label6 = new Label(dialogShell, SWT.NONE);
				label6.setText("Pais:");
				FormData label6LData = new FormData();
				label6LData.width = 28;
				label6LData.height = 14;
				label6LData.left =  new FormAttachment(0, 1000, 35);
				label6LData.top =  new FormAttachment(0, 1000, 329);
				label6.setLayoutData(label6LData);
			}
			{
				label5 = new Label(dialogShell, SWT.NONE);
				label5.setText("Codigo postal:");
				FormData label5LData = new FormData();
				label5LData.width = 70;
				label5LData.height = 14;
				label5LData.left =  new FormAttachment(0, 1000, 35);
				label5LData.top =  new FormAttachment(0, 1000, 273);
				label5.setLayoutData(label5LData);
			}
			{
				label4 = new Label(dialogShell, SWT.NONE);
				label4.setText("Provincia:");
				FormData label4LData = new FormData();
				label4LData.width = 63;
				label4LData.height = 14;
				label4LData.left =  new FormAttachment(0, 1000, 35);
				label4LData.top =  new FormAttachment(0, 1000, 217);
				label4.setLayoutData(label4LData);
			}
			{
				label3 = new Label(dialogShell, SWT.NONE);
				label3.setText("Localidad:");
				FormData label3LData = new FormData();
				label3LData.width = 49;
				label3LData.height = 14;
				label3LData.left =  new FormAttachment(0, 1000, 35);
				label3LData.top =  new FormAttachment(0, 1000, 154);
				label3.setLayoutData(label3LData);
			}
			{
				label2 = new Label(dialogShell, SWT.NONE);
				label2.setText("Direccion:");
				FormData label2LData = new FormData();
				label2LData.width = 49;
				label2LData.height = 14;
				label2LData.left =  new FormAttachment(0, 1000, 35);
				label2LData.top =  new FormAttachment(0, 1000, 91);
				label2.setLayoutData(label2LData);
			}
			{
				text5 = new Text(dialogShell, SWT.MULTI | SWT.BORDER);
				FormData text5LData = new FormData();
				text5LData.width = 219;
				text5LData.height = 15;
				text5LData.left =  new FormAttachment(0, 1000, 154);
				text5LData.top =  new FormAttachment(0, 1000, 322);
				text5.setLayoutData(text5LData);
			}
			{
				text4 = new Text(dialogShell, SWT.MULTI | SWT.BORDER);
				FormData text4LData = new FormData();
				text4LData.width = 219;
				text4LData.height = 15;
				text4LData.left =  new FormAttachment(0, 1000, 154);
				text4LData.top =  new FormAttachment(0, 1000, 266);
				text4.setLayoutData(text4LData);
			}
			{
				text3 = new Text(dialogShell, SWT.MULTI | SWT.BORDER);
				FormData text3LData = new FormData();
				text3LData.width = 219;
				text3LData.height = 15;
				text3LData.left =  new FormAttachment(0, 1000, 154);
				text3LData.top =  new FormAttachment(0, 1000, 210);
				text3.setLayoutData(text3LData);
			}
			{
				text2 = new Text(dialogShell, SWT.MULTI | SWT.BORDER);
				FormData text2LData = new FormData();
				text2LData.width = 219;
				text2LData.height = 15;
				text2LData.left =  new FormAttachment(0, 1000, 154);
				text2LData.top =  new FormAttachment(0, 1000, 147);
				text2.setLayoutData(text2LData);
			}
			{
				text1 = new Text(dialogShell, SWT.MULTI | SWT.BORDER);
				FormData text1LData = new FormData();
				text1LData.width = 219;
				text1LData.height = 15;
				text1LData.left =  new FormAttachment(0, 1000, 154);
				text1LData.top =  new FormAttachment(0, 1000, 84);
				text1.setLayoutData(text1LData);
			}
			{
				label1 = new Label(dialogShell, SWT.NONE);
				label1.setText("Introduzca sus datos para poder almacenarlos:");
				FormData label1LData = new FormData();
				label1LData.width = 224;
				label1LData.height = 14;
				label1LData.left =  new FormAttachment(0, 1000, 105);
				label1LData.top =  new FormAttachment(0, 1000, 35);
				label1.setLayoutData(label1LData);
			}
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return resultado;
	}
	
	private void button1MouseDoubleClick(MouseEvent evt) {
		int atributo=-1;
		if (text1.getText()!="" && text2.getText()!="" && text3.getText()!=""  && text4.getText()!="" && text5.getText()!=""){
			try{
				atributo = Integer.parseInt(text4.getText());
			}catch(Exception e){
				atributo =-1;
			}
			if (atributo !=-1){
				//elementos_busqueda=open();
				
				String direccion=text1.getText();
				String localidad=text2.getText();
				String provincia=text3.getText();
				String codigo=text4.getText();
				String pais=text5.getText();
			
				resultado[1]=direccion;
				resultado[2]=localidad;
				resultado[3]=provincia;
				resultado[4]=codigo;
				resultado[5]=pais;
				
			
				direccion="";
				localidad="";
				provincia="";
				codigo="";
				pais="";
				
				dialogShell.close();
				System.gc();
			}
			
			
		}
		
		
	
	}

}
