Formulario de sitios añadido
[Ocio20.git] / src / com / Ocio20 / client / FormularioSitio.java
blobf8e47f81bbf6975102370c39ae0d8e8e05c61d8a
1 package com.Ocio20.client;
3 import com.google.gwt.core.client.EntryPoint;
4 import com.google.gwt.core.client.GWT;
5 import com.google.gwt.event.dom.client.ClickEvent;
6 import com.google.gwt.event.dom.client.ClickHandler;
7 import com.google.gwt.event.dom.client.KeyCodes;
8 import com.google.gwt.event.dom.client.KeyUpEvent;
9 import com.google.gwt.event.dom.client.KeyUpHandler;
10 import com.google.gwt.user.client.rpc.AsyncCallback;
11 import com.google.gwt.user.client.ui.Button;
12 import com.google.gwt.user.client.ui.DialogBox;
13 import com.google.gwt.user.client.ui.Grid;
14 import com.google.gwt.user.client.ui.HTML;
15 import com.google.gwt.user.client.ui.Label;
16 import com.google.gwt.user.client.ui.ListBox;
17 import com.google.gwt.user.client.ui.RootPanel;
18 import com.google.gwt.user.client.ui.StackPanel;
19 import com.google.gwt.user.client.ui.TextBox;
20 import com.google.gwt.user.client.ui.VerticalPanel;
22 /**
23 * Entry point classes define <code>onModuleLoad()</code>.
25 public class FormularioSitio implements EntryPoint {
26 /**
27 * The message displayed to the user when the server cannot be reached or
28 * returns an error.
30 private static final String SERVER_ERROR = "An error occurred while "
31 + "attempting to contact the server. Please check your network "
32 + "connection and try again.";
34 /**
35 * Create a remote service proxy to talk to the server-side Greeting service.
37 private final GreetingServiceAsync greetingService = GWT
38 .create(GreetingService.class);
40 /**
41 * This is the entry point method.
43 public void onModuleLoad() {
44 final Button sendButton = new Button("Send");
45 final TextBox nameField = new TextBox();
46 nameField.setText("GWT User");
48 // We can add style names to widgets
49 sendButton.addStyleName("sendButton");
51 // Add the nameField and sendButton to the RootPanel
52 // Use RootPanel.get() to get the entire body element
53 RootPanel.get("nameFieldContainer").add(nameField);
54 RootPanel.get("sendButtonContainer").add(sendButton);
56 //----------------------------------------------------------------------------------------------------------------
58 /* Datos basicos
59 nombre
60 direccion
61 tipo de sitio (restaurante, pub, heladeria, bar, cafe, ...) TODO: metemos un textbox con busqueda de los ya definidos ->
62 rellenamos una variable en js que tenga la lista y ahí buscamos.
63 geolocalizacion -> eso en el mapa!
67 // CONSTANTES
68 final int MAX_LENGTH_NOMBRE = 35;
69 final int VISIBLE_LENGTH_NOMBRE = 35;
70 final int MAX_LENGTH_DIRECCION = 35;
71 final int VISIBLE_LENGTH_DIRECCION = 35;
72 final int MAX_LENGTH_TIPO = 35;
73 final int VISIBLE_LENGTH_TIPO = 35;
76 //final VerticalPanel vpDatosBasicos = new VerticalPanel();
77 final Grid gDatosBasicos = new Grid(3, 2);
79 final TextBox txtNombre = new TextBox();
80 final Label lNombre = new Label("Nombre: ");
81 txtNombre.setMaxLength(MAX_LENGTH_NOMBRE);
82 txtNombre.setVisibleLength(VISIBLE_LENGTH_NOMBRE);
83 gDatosBasicos.setWidget(0, 0, lNombre);
84 gDatosBasicos.setWidget(0, 1, txtNombre);
86 final TextBox txtDireccion = new TextBox();
87 final Label lDireccion = new Label("Direccion: ");
88 txtDireccion.setMaxLength(MAX_LENGTH_DIRECCION);
89 txtDireccion.setVisibleLength(VISIBLE_LENGTH_DIRECCION);
90 gDatosBasicos.setWidget(1, 0, lDireccion);
91 gDatosBasicos.setWidget(1, 1, txtDireccion);
93 final TextBox txtTipo = new TextBox();
94 final Label lTipo = new Label("Tipo: ");
95 txtTipo.setMaxLength(MAX_LENGTH_TIPO);
96 txtTipo.setVisibleLength(VISIBLE_LENGTH_TIPO);
97 gDatosBasicos.setWidget(2, 0, lTipo);
98 gDatosBasicos.setWidget(2, 1, txtTipo);
103 /* Añadidos -> meterlos como constante
104 Foto, web, contacto, telefono, web, mail, aforo, tranquilidad, musica en vivo, musica, familiar, romantico, no fumadores
105 horario, edades, productoEspecial, precioCaña/refresco/agua/copa/cafe, apropiadoConocerGenteNueva, vistas,
106 terraza, climatizado, zonaDeOcio, nacional/extranjero, futbol/basket/.../canalesDePago, tipoAmbiente (pijo, alternativo, descuidado, gay),
107 gogo, limpieza, actividadesCulturales, bailar, wifi / ordenadores, parkingPrivado, facilidadAparcar, juegosMesa,
108 billar, futbolin, dardos, otrasMaquinas, promocionEspecial (2x1, cada x veces 1 gratis,...), aceptaTarjeta (visa, MasterCard, 4B, ...)
109 diasDeMovimiento, precioEntrada, requisitosEspeciales, localEmblemático, familias, empresas, popularidad
113 final VerticalPanel vpContacto = new VerticalPanel();
115 final TextBox telefono = new TextBox();
116 vpContacto.add(telefono);
121 // Creamos el StackPanel para meter los formularios
122 final StackPanel stDatosSitio = new StackPanel();
123 stDatosSitio.add(gDatosBasicos, "Datos básicos");
124 stDatosSitio.add(vpContacto, "Contacto");
126 // Make a new list box, adding a few items to it.
127 /* ListBox lb = new ListBox();
128 lb.addItem("foo");
129 lb.addItem("bar");
130 lb.addItem("baz");
131 lb.addItem("toto");
132 lb.addItem("tintin");
134 // Make enough room for all five items (setting this value to 1 turns it
135 // into a drop-down list).
136 lb.setVisibleItemCount(0);
138 // Add it to the root panel.
139 RootPanel.get().add(lb);
142 RootPanel.get().add(stDatosSitio);
143 //----------------------------------------------------------------------------------------------------------------
145 // Focus the cursor on the name field when the app loads
146 nameField.setFocus(true);
147 nameField.selectAll();
149 // Create the popup dialog box
150 final DialogBox dialogBox = new DialogBox();
151 dialogBox.setText("Remote Procedure Call");
152 dialogBox.setAnimationEnabled(true);
153 final Button closeButton = new Button("Close");
154 // We can set the id of a widget by accessing its Element
155 closeButton.getElement().setId("closeButton");
156 final Label textToServerLabel = new Label();
157 final HTML serverResponseLabel = new HTML();
158 VerticalPanel dialogVPanel = new VerticalPanel();
159 dialogVPanel.addStyleName("dialogVPanel");
160 dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
161 dialogVPanel.add(textToServerLabel);
162 dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
163 dialogVPanel.add(serverResponseLabel);
164 dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
165 dialogVPanel.add(closeButton);
166 dialogBox.setWidget(dialogVPanel);
168 // Add a handler to close the DialogBox
169 closeButton.addClickHandler(new ClickHandler() {
170 public void onClick(ClickEvent event) {
171 dialogBox.hide();
172 sendButton.setEnabled(true);
173 sendButton.setFocus(true);
177 // Create a handler for the sendButton and nameField
178 class MyHandler implements ClickHandler, KeyUpHandler {
180 * Fired when the user clicks on the sendButton.
182 public void onClick(ClickEvent event) {
183 sendNameToServer();
187 * Fired when the user types in the nameField.
189 public void onKeyUp(KeyUpEvent event) {
190 if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
191 sendNameToServer();
196 * Send the name from the nameField to the server and wait for a response.
198 private void sendNameToServer() {
199 sendButton.setEnabled(false);
200 String textToServer = nameField.getText();
201 textToServerLabel.setText(textToServer);
202 serverResponseLabel.setText("");
203 greetingService.greetServer(textToServer,
204 new AsyncCallback<String>() {
205 public void onFailure(Throwable caught) {
206 // Show the RPC error message to the user
207 dialogBox
208 .setText("Remote Procedure Call - Failure");
209 serverResponseLabel
210 .addStyleName("serverResponseLabelError");
211 serverResponseLabel.setHTML(SERVER_ERROR);
212 dialogBox.center();
213 closeButton.setFocus(true);
216 public void onSuccess(String result) {
217 dialogBox.setText("Remote Procedure Call");
218 serverResponseLabel
219 .removeStyleName("serverResponseLabelError");
220 serverResponseLabel.setHTML(result);
221 dialogBox.center();
222 closeButton.setFocus(true);
228 // Add a handler to send the name to the server
229 MyHandler handler = new MyHandler();
230 sendButton.addClickHandler(handler);
231 nameField.addKeyUpHandler(handler);