/*
 * Fichero:     tipoBusqueda.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 escoge el tipo de búsqueda a realizar
 * 				en la based de datos. 
 *
 * 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.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 tipoBusqueda extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Button buscar;
	private Button lista;
	private Label label1;
	String array=new String();

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

	public tipoBusqueda(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(407, 195);
			dialogShell.setText("Catalogo v1.0");
			{
				label1 = new Label(dialogShell, SWT.NONE);
				label1.setText("Elija el tipo de búsqueda que desea realizar:");
				FormData label1LData = new FormData();
				label1LData.width = 210;
				label1LData.height = 14;
				label1LData.left =  new FormAttachment(0, 1000, 91);
				label1LData.top =  new FormAttachment(0, 1000, 21);
				label1.setLayoutData(label1LData);
			}
			{
				lista = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				lista.setText("Listar caracteristicas de productos registrados");
				FormData listaLData = new FormData();
				listaLData.width = 280;
				listaLData.height = 21;
				listaLData.left =  new FormAttachment(0, 1000, 49);
				listaLData.top =  new FormAttachment(0, 1000, 98);
				lista.setLayoutData(listaLData);
				lista.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						listaMouseDoubleClick(evt);
					}
				});
				/*lista.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						array = "lista";
					}
				});*/
			}
			{
				buscar = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				buscar.setText("Buscar un determinado producto");
				FormData buscarLData = new FormData();
				buscarLData.width = 280;
				buscarLData.height = 21;
				buscarLData.left =  new FormAttachment(0, 1000, 49);
				buscarLData.top =  new FormAttachment(0, 1000, 56);
				buscar.setLayoutData(buscarLData);
				buscar.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						buscarMouseDoubleClick(evt);
					}
				});
				/*buscar.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						array = "busca";
					}
				});*/
			}
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return array;
	}
	
	private void buscarMouseDoubleClick(MouseEvent evt) {
		array="busca";
		dialogShell.close();
		System.gc();
	}
	
	private void listaMouseDoubleClick(MouseEvent evt) {
		array="lista";
		dialogShell.close();
		System.gc();
	}

}
