/*
 * Fichero:     ElementosRegistro.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 tipos de elementos vamos 
 * 				a registrar en la base 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 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.*;

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

	private Shell dialogShell;
	private Text numero_atributos;
	private Text text1;
	private Text text2;
	static String categoria=new String();
	//static String anterior_categoria=new String();
	static String producto=new String();
	private Button button1;
	private Label label5;
	private Label label4;
	private Label label3;
	private Label label2;
	private Label label1;
	private Text catalogos;
	//static String anterior_producto=new String();
	static String atributos=new String();
	//static String anterior_atributos=new String();
	static String catalogo=new String();
	//static String anterior_catalogo=new String();
	String []resultado=new String[5];
	/*static 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);
			ElementosRegistro inst = new ElementosRegistro(shell, SWT.NULL);
			inst.open();
			/*resultado[0]="categoria";
			resultado[1]=categoria;
			resultado[2]="producto";
			resultado[3]=producto;
			resultado[4]="atributos";
			resultado[5]=atributos;
			int i=0;
			for(i=0;i<resultado.length;i++)
				System.out.println(resultado[i]);*/
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public ElementosRegistro(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(435, 321);
			dialogShell.setFont(SWTResourceManager.getFont("Times New Roman", 8, 0, false, false));
			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, 336);
				button1LData.top = new FormAttachment(0, 1000, 252);
				button1.setLayoutData(button1LData);
				button1.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						button1MouseDoubleClick(evt);
					}
				});
			}
			{
				label5 = new Label(dialogShell, SWT.NONE);
				label5.setText("Introduzca los campos del elemento que desea registrar:");
				FormData label5LData = new FormData();
				label5LData.width = 280;
				label5LData.height = 14;
				label5LData.left =  new FormAttachment(0, 1000, 70);
				label5LData.top =  new FormAttachment(0, 1000, 21);
				label5.setLayoutData(label5LData);
			}
			{
				label4 = new Label(dialogShell, SWT.NONE);
				label4.setText("Numero de atributos:");
				FormData label4LData = new FormData();
				label4LData.width = 105;
				label4LData.height = 14;
				label4LData.left =  new FormAttachment(0, 1000, 49);
				label4LData.top =  new FormAttachment(0, 1000, 238);
				label4.setLayoutData(label4LData);
			}
			{
				label3 = new Label(dialogShell, SWT.NONE);
				label3.setText("Catalogo:");
				FormData label3LData = new FormData();
				label3LData.width = 49;
				label3LData.height = 14;
				label3LData.left =  new FormAttachment(0, 1000, 49);
				label3LData.top =  new FormAttachment(0, 1000, 182);
				label3.setLayoutData(label3LData);
			}
			{
				label2 = new Label(dialogShell, SWT.NONE);
				label2.setText("Producto:");
				FormData label2LData = new FormData();
				label2LData.width = 49;
				label2LData.height = 14;
				label2LData.left =  new FormAttachment(0, 1000, 49);
				label2LData.top =  new FormAttachment(0, 1000, 126);
				label2.setLayoutData(label2LData);
			}
			{
				label1 = new Label(dialogShell, SWT.NONE);
				label1.setText("Categoria:");
				FormData label1LData = new FormData();
				label1LData.width = 49;
				label1LData.height = 14;
				label1LData.left =  new FormAttachment(0, 1000, 49);
				label1LData.top =  new FormAttachment(0, 1000, 70);
				label1.setLayoutData(label1LData);
			}
			{
				catalogos = new Text(dialogShell, SWT.BORDER);
				FormData catalogosLData = new FormData();
				catalogosLData.width = 191;
				catalogosLData.height = 15;
				catalogosLData.left =  new FormAttachment(0, 1000, 168);
				catalogosLData.top =  new FormAttachment(0, 1000, 175);
				catalogos.setLayoutData(catalogosLData);
				/*catalogos.addKeyListener(new KeyAdapter() {
					public void keyPressed(KeyEvent ev){
					 	int r=ev.keyCode;
					    char a=(char)r;	
					    if(r==8){  
					    	anterior_catalogo=catalogo.substring(0,(catalogo.length()-1));
					    	catalogo=anterior_catalogo;
					    }
					    else		
					    	catalogo=catalogo+a;
					}
				});*/
			}
			{
				numero_atributos = new Text(dialogShell, SWT.BORDER);
				FormData numero_atributosLData = new FormData();
				numero_atributosLData.width = 30;
				numero_atributosLData.height = 15;
				numero_atributosLData.left =  new FormAttachment(0, 1000, 168);
				numero_atributosLData.top =  new FormAttachment(0, 1000, 231);
				numero_atributos.setLayoutData(numero_atributosLData);
				/*numero_atributos.addKeyListener(new KeyAdapter() {
					public void keyPressed(KeyEvent ev){
					 	int r=ev.keyCode;
					    char a=(char)r;	
					    if(r==8){  
					    	anterior_atributos=atributos.substring(0,(atributos.length()-1));
					    	atributos=anterior_atributos;
					    }
					    else		
					    	atributos=atributos+a;
					

					
					    
					 }
				});*/
			}
			
			{
				text1 = new Text(dialogShell, SWT.MULTI | SWT.BORDER);
				;
				FormData text1LData = new FormData();
				text1LData.width = 191;
				text1LData.height = 15;
				text1LData.left =  new FormAttachment(0, 1000, 168);
				text1LData.top =  new FormAttachment(0, 1000, 63);
				text1.setLayoutData(text1LData);
				
				/*text1.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;
					
						    
						 }
					 
				});*/
			     
			   

				
				
			}
			
			{
				text2 = new Text(dialogShell, SWT.MULTI | SWT.BORDER);
				;
				FormData text1LData = new FormData();
				text1LData.width = 191;
				text1LData.height = 15;
				text1LData.left =  new FormAttachment(0, 1000, 168);
				text1LData.top =  new FormAttachment(0, 1000, 119);
				text2.setLayoutData(text1LData);
				
				/*text2.addKeyListener(new KeyAdapter() {
					 public void keyPressed(KeyEvent ev){
						 	int r=ev.keyCode;
						    char a=(char)r;
						    if(r==8){  
						    	anterior_producto=producto.substring(0,(producto.length()-1));
						    	producto=anterior_producto;
						    }
						    else		
						    	producto=producto+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 (text1.getText()!="" && text2.getText()!="" && catalogos.getText()!=""  && numero_atributos.getText()!=""){
			try{
				atributo = Integer.parseInt(numero_atributos.getText());
			}catch(Exception e){
				atributo =-1;
			}
			if (atributo !=-1){
				//elementos_busqueda=open();
				categoria=text1.getText();
				producto=text2.getText();
				catalogo=catalogos.getText();
				atributos=numero_atributos.getText();
				resultado[0]=categoria;
				resultado[1]=producto;
				resultado[2]=catalogo;
				resultado[3]="atributos";
				resultado[4]=atributos;
				
				categoria="";
				producto="";
				catalogo="";
				atributos="";
				
				dialogShell.close();
				System.gc();
			}
			
			
		}
		
		
	}
	

}

