/*
 * Fichero:     Bien.java
 * Fecha:       15/01/07
 * Autor:       Alvaro Sarmiento losada 
 * Asignatura:  Proyecto Fin de Carrera
 * Descripción: Clase que permite mostrar por pantalla a modo de ventana todos los productos
 * que han sido registrados por mi par hasta ese momento.
 *
 * 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.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
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 MostrarMisRegistros extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Label label1;
	private Button button2;
	private Button button1;
	private Label label6;
	private Label label5;
	private List list2;
	private List list1;
	private Label label4;
	private Label label3;
	private Label label2;
	public boolean booleano=false;
	private Label label7;

	/**
	* 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);
			MostrarMisRegistros inst = new MostrarMisRegistros(shell, SWT.NULL);
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}*/
	}

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

	public boolean open(String[] array,String []atributos,String[] valores) {
		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(624, 377);
			dialogShell.setText("Catalogo v1.0");
			{
				label7 = new Label(dialogShell, SWT.NONE);
				label7.setText("Categoria:   "+array[1]);
				FormData label7LData = new FormData();
				label7LData.width = 175;
				label7LData.height = 14;
				label7LData.left =  new FormAttachment(0, 1000, 77);
				label7LData.top =  new FormAttachment(0, 1000, 161);
				label7.setLayoutData(label7LData);
			}
			{
				button2 = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				button2.setText("Siguiente");
				FormData button2LData = new FormData();
				button2LData.width = 56;
				button2LData.height = 21;
				button2LData.left = new FormAttachment(0, 1000, 378);
				button2LData.top = new FormAttachment(0, 1000, 287);
				button2.setLayoutData(button2LData);
				button2.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						button2MouseDoubleClick(evt);
					}
				});
			}
			{
				button1 = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				button1.setText("Terminar");
				FormData button1LData = new FormData();
				button1LData.width = 56;
				button1LData.height = 21;
				button1LData.left = new FormAttachment(0, 1000, 196);
				button1LData.top = new FormAttachment(0, 1000, 287);
				button1.setLayoutData(button1LData);
				button1.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						button1MouseDoubleClick(evt);
					}
				});
			}
			{
				label6 = new Label(dialogShell, SWT.NONE);
				label6.setText("Valores:");
				FormData label6LData = new FormData();
				label6LData.width = 42;
				label6LData.height = 14;
				label6LData.left =  new FormAttachment(0, 1000, 497);
				label6LData.top =  new FormAttachment(0, 1000, 70);
				label6.setLayoutData(label6LData);
			}
			{
				label5 = new Label(dialogShell, SWT.NONE);
				label5.setText("Atributos:");
				FormData label5LData = new FormData();
				label5LData.width = 49;
				label5LData.height = 14;
				label5LData.left =  new FormAttachment(0, 1000, 301);
				label5LData.top =  new FormAttachment(0, 1000, 70);
				label5.setLayoutData(label5LData);
			}
			{
				list2 = new List(dialogShell, SWT.MULTI
					| SWT.V_SCROLL
					| SWT.BORDER);
				int i=0;
				for(i=0;i<valores.length;i++)
					list2.add(valores[i]);
				FormData list2LData = new FormData();
				list2LData.width = 116;
				list2LData.height = 129;
				list2LData.left =  new FormAttachment(0, 1000, 455);
				list2LData.top =  new FormAttachment(0, 1000, 105);
				list2.setLayoutData(list2LData);
			}
			{
				list1 = new List(dialogShell, SWT.MULTI
					| SWT.V_SCROLL
					| SWT.BORDER);
				int i=0;
				for(i=0;i<atributos.length;i++)
					list1.add(atributos[i]);
				FormData list1LData = new FormData();
				list1LData.width = 130;
				list1LData.height = 129;
				list1LData.left =  new FormAttachment(0, 1000, 259);
				list1LData.top =  new FormAttachment(0, 1000, 105);
				list1.setLayoutData(list1LData);
			}
			{
				label4 = new Label(dialogShell, SWT.NONE);
				label4.setText("Estos son tus productos registrados:");
				FormData label4LData = new FormData();
				label4LData.width = 224;
				label4LData.height = 14;
				label4LData.left =  new FormAttachment(0, 1000, 203);
				label4LData.top =  new FormAttachment(0, 1000, 28);
				label4.setLayoutData(label4LData);
			}
			{
				label3 = new Label(dialogShell, SWT.NONE);
				label3.setText("Producto:   "+array[2]);
				FormData label3LData = new FormData();
				label3LData.width = 245;
				label3LData.height = 14;
				label3LData.left =  new FormAttachment(0, 1000, 77);
				label3LData.top =  new FormAttachment(0, 1000, 210);
				label3.setLayoutData(label3LData);
			}
			{
				label2 = new Label(dialogShell, SWT.NONE);
				label2.setText("Identificador:   "+array[0]);
				FormData label2LData = new FormData();
				label2LData.width = 231;
				label2LData.height = 14;
				label2LData.left =  new FormAttachment(0, 1000, 77);
				label2LData.top =  new FormAttachment(0, 1000, 119);
				label2.setLayoutData(label2LData);
			}
			{
				label1 = new Label(dialogShell, SWT.NONE);
				label1.setText("Propietario:   "+array[4]);
				FormData label1LData = new FormData();
				label1LData.width = 252;
				label1LData.height = 14;
				label1LData.left =  new FormAttachment(0, 1000, 77);
				label1LData.top =  new FormAttachment(0, 1000, 77);
				label1.setLayoutData(label1LData);
			}
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return booleano;
	}
	
	private void button2MouseDoubleClick(MouseEvent evt) {
		booleano=false;
		dialogShell.close();
		System.gc();
	}
	
	private void button1MouseDoubleClick(MouseEvent evt) {
		booleano=true;
		dialogShell.close();
		System.gc();
	}

}
