/*
 * Fichero:     identificadorElemento.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 que elemento se desea eliminar 
 * 				del sistema de bases 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.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 identificadorElemento extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Text identificador;
	static String categoria=new String();
	static String anterior_categoria=new String();
	String resultado=null;
	private Button button1;
	private Label label1;

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

	public identificadorElemento(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(484, 174);
			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, 182);
				button1LData.top = new FormAttachment(0, 1000, 98);
				button1.setLayoutData(button1LData);
				button1.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						button1MouseDoubleClick(evt);
					}
				});
			}
			{
				label1 = new Label(dialogShell, SWT.NONE);
				label1.setText("Introduzca el identificador del elemento que quiere eliminar:");
				FormData label1LData = new FormData();
				label1LData.width = 287;
				label1LData.height = 14;
				label1LData.left =  new FormAttachment(0, 1000, 63);
				label1LData.top =  new FormAttachment(0, 1000, 49);
				label1.setLayoutData(label1LData);
			}
			{
				identificador = new Text(dialogShell, SWT.BORDER);
				FormData identificadorLData = new FormData();
				identificadorLData.width = 36;
				identificadorLData.height = 21;
				identificadorLData.left =  new FormAttachment(0, 1000, 364);
				identificadorLData.top =  new FormAttachment(0, 1000, 35);
				identificador.setLayoutData(identificadorLData);
				/*identificador.addKeyListener(new KeyAdapter() {
					public void keyPressed(KeyEvent ev){
					 	int r=ev.keyCode;
					 	char a=(char)r;	
					    if(r==8){  
					    	anterior_categoria=categoria.substring(0,(categoria.length()-1));
					    	categoria=anterior_categoria;
					    }
					    else		
					    	categoria=categoria+a;
				
					    
					 }
				});*/
			}
			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 (identificador.getText()!=""){
			try{
				atributo = Integer.parseInt(identificador.getText());
			}catch(Exception e){
				atributo =-1;
			}
			if (atributo !=-1){
				//elementos_busqueda=open();
				categoria=identificador.getText();
				resultado=categoria;
				categoria="";
				dialogShell.close();
				System.gc();
			}
			
		}
		
		
	
	}

}
