/*
 * Fichero:     NewDialog.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 escogemos el tipo de petición que deseamos
 * 				realizar.
 *
 * 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 com.cloudgarden.resource.SWTResourceManager;


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;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

/**
* 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 NewDialog extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Button buscar;
	private Label label1;
	private Button button2;
	private Button button1;
	private Button eliminar;
	private Button registrar;
	String []array=new String[1];

	/**
	* 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);
			shell.setEnabled(false);
			NewDialog inst = new NewDialog(shell, SWT.NULL);
			String []peticion=inst.open();
			System.out.println(peticion[0]);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

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

	public String[] open() {

		try {
			Shell parent = getParent();
			dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

				{
					//Register as a resource user - SWTResourceManager will
					//handle the obtaining and disposing of resources
					SWTResourceManager.registerResourceUser(dialogShell);
				}


			FormLayout dialogShellLayout = new FormLayout();
			dialogShell.setLayout(dialogShellLayout);
			dialogShell.layout();
			dialogShell.pack();
			dialogShell.setSize(470, 279);
			dialogShell.setFont(SWTResourceManager.getFont("Webdings", 8, 0, false, false));
			dialogShell.setText("Catalogo v1.0");
			{
				button2 = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				button2.setText("Características de los productos que interesan");
				FormData button2LData = new FormData();
				button2LData.width = 413;
				button2LData.height = 21;
				button2LData.left =  new FormAttachment(0, 1000, 21);
				button2LData.top =  new FormAttachment(0, 1000, 203);
				button2.setLayoutData(button2LData);
				button2.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						button2MouseDoubleClick(evt);
					}
				});
			}
			{
				button1 = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				button1.setText("Ver sus productos registrados");
				FormData button1LData = new FormData();
				button1LData.width = 413;
				button1LData.height = 21;
				button1LData.left =  new FormAttachment(0, 1000, 21);
				button1LData.top =  new FormAttachment(0, 1000, 161);
				button1.setLayoutData(button1LData);
				button1.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						button1MouseDoubleClick(evt);
					}
				});
			}
			{
				label1 = new Label(dialogShell, SWT.NONE);
				label1.setText("Escoja una operación:");
				FormData label1LData = new FormData();
				label1LData.width = 105;
				label1LData.height = 14;
				label1LData.left =  new FormAttachment(0, 1000, 182);
				label1LData.top =  new FormAttachment(0, 1000, 14);
				label1.setLayoutData(label1LData);
			}
			{
				eliminar = new Button(dialogShell, SWT.TOGGLE | SWT.CENTER);
				eliminar.setText("eliminar");
				FormData eliminarLData = new FormData();
				eliminarLData.width = 413;
				eliminarLData.height = 21;
				eliminarLData.left =  new FormAttachment(0, 1000, 21);
				eliminarLData.top =  new FormAttachment(0, 1000, 119);
				eliminar.setLayoutData(eliminarLData);
				eliminar.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						eliminarMouseDoubleClick(evt);
					}
				});
				eliminar.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent evt) {
						array[0] = "eliminar";
					}
				});
				/*eliminar.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e){
						array[0]="eliminar";
					}
				});*/
			}
			{
				buscar = new Button(dialogShell, SWT.TOGGLE | SWT.CENTER);
				buscar.setText("buscar");
				FormData buscarLData = new FormData();
				buscarLData.width = 413;
				buscarLData.height = 21;
				buscarLData.left =  new FormAttachment(0, 1000, 21);
				buscarLData.top =  new FormAttachment(0, 1000, 84);
				buscar.setLayoutData(buscarLData);
				buscar.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						buscarMouseDoubleClick(evt);
					}
				});
				buscar.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent evt) {
						array[0] = "buscar";
					}
				});
				/*buscar.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e){
						array[0]="buscar";
					}
				});*/
			}
			{
				registrar = new Button(dialogShell, SWT.TOGGLE | SWT.CENTER);
				registrar.setText("registrar");
				FormData registrarLData = new FormData();
				registrarLData.width = 413;
				registrarLData.height = 21;
				registrarLData.left =  new FormAttachment(0, 1000, 21);
				registrarLData.top =  new FormAttachment(0, 1000, 49);
				registrar.setLayoutData(registrarLData);
				registrar.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						registrarMouseDoubleClick(evt);
					}
				});
				/*registrar.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						array[0] = "registrar";
					}
				});*/
			}
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return array;
	}
	
	private void registrarMouseDoubleClick(MouseEvent evt) {
		array[0]="registrar";
		dialogShell.close();
		System.gc();
	}
	
	private void buscarMouseDoubleClick(MouseEvent evt) {
		array[0]="buscar";
		dialogShell.close();
		System.gc();
	}
	
	private void eliminarMouseDoubleClick(MouseEvent evt) {
		array[0]="eliminar";
		dialogShell.close();
		System.gc();
	}
	
	private void button1MouseDoubleClick(MouseEvent evt) {
		array[0]="registros";
		dialogShell.close();
		System.gc();
	}
	
	private void button2MouseDoubleClick(MouseEvent evt) {
		array[0]="buscados";
		dialogShell.close();
		System.gc();
	}

}
