Hi,
>From a Form I call a method that launches the Dialog component. The launch
code is this:
mbNombre.addActionListener((e) -> {
if (seleccion) {
Command ok = new Command("ok");
Visita v = new Visita();
v.visitaId.set(null);
v.clienteId.set(clt.clienteId.get());
v.latitud.set(clt.latitud.get());
v.longitud.set(clt.longitud.get());
*Dialog d = creaVisita(v, clt.nombre.get(), ok);*
if (d.showDialog() == ok) {
procesaRegistro(v, VISITA);
formaVisita.creaItemVisitas(v);
muestraVisitas(formaVisita.getContenedorVisitas());
}
fRetorno.showBack();
}
});
The method displays the Dialog compent with all the components that you add
to it without problems. Pressing the btAceptar button performs 2
validations and displays the error messages in each case. The problem is
that it automatically executes the "dispose" and returns control to the
small code where it was launched (as if it were pressing the "ok"
component).
private Dialog creaVisita(Visita v, String nombre, Command ok) {
Dialog dlVisita = new Dialog(new BorderLayout());
Label lbTitulo = new Label(nombre, "MultiLine1");
lbTitulo.getAllStyles().setAlignment(Component.CENTER);
dlVisita.setTitleComponent(lbTitulo);
dlVisita.setDialogUIID("Form");
Label lbDescripcion = new Label(idioma.getDescripcion() + ":");
TextArea txDescripcion = new TextArea();
txDescripcion.setFocus(true);
Container cnDescripcion = new Container(new
BoxLayout(BoxLayout.Y_AXIS)).add(lbDescripcion).add(txDescripcion);
Tarea t = new Tarea();
ArrayList aTarea = consultaTablas(t, TAREA);
if (aTarea.isEmpty()) {
Dialog.show(idioma.getError(), "Inexplicable: No existen tareas
creadas", idioma.getContinuar(), null);
dlVisita.dispose();
}
Label lbTarea = new Label(idioma.getMensaje12() + ":");
RadioButton[] rb = new RadioButton[aTarea.size() + 1];
Container cnTarea = new Container(new BoxLayout(BoxLayout.Y_AXIS));
cnTarea.setScrollableY(true);
for (int i = 0; i < aTarea.size(); i++) {
t = (Tarea) aTarea.get(i);
rb[i] = new RadioButton(t.descripcion.get());
rb[i].getAllStyles().setAlignment(Component.LEFT);
// rb[i].setUIID("Label");
cnTarea.add(rb[i]);
}
Container cnTareas = new Container(new
BoxLayout(BoxLayout.Y_AXIS)).add(lbTarea).add(cnTarea);
Container cnItem = new Container(new BorderLayout());
cnItem.add(BorderLayout.NORTH, cnDescripcion);
cnItem.add(BorderLayout.CENTER, cnTareas);;
Style sItem = cnItem.getUnselectedStyle();
sItem.setBgTransparency(255);
sItem.setBgColor(0xeeeeee);
sItem.setMarginUnit(Style.UNIT_TYPE_DIPS);
sItem.setPaddingUnit(Style.UNIT_TYPE_DIPS);
sItem.setMargin(1, 0, 1, 1);
sItem.setPadding(2, 1, 2, 2);
Button btCancelar = new Button(idioma.getCancelar(), "MensajeRojo");
btCancelar.addActionListener((e) -> {
dlVisita.dispose();
});
Button btAceptar = new Button(ok);
btAceptar.setText(idioma.getAceptar());
btAceptar.setUIID("MensajeVerde");
btAceptar.addActionListener((e) -> {
if (txDescripcion.getText().isEmpty()) {
Dialog.show(idioma.getError(), idioma.getDescripcion() + "
" + idioma.getMensaje6(), idioma.getContinuar(), null);
return;
}
boolean encontro = false;
for (int i = 0; i < rb.length - 1; i++) {
if (rb[i].isSelected()) {
encontro = true;
break;
}
}
if (!encontro) {
Dialog.show(idioma.getError(), idioma.getTarea() + " " +
idioma.getMensaje6(), idioma.getContinuar(), null);
return;
}
v.descripcion.set(txDescripcion.getText());
v.fechaFuente.set(Preferences.get("fecha",
System.currentTimeMillis()));
v.distancia.set(distancia(v.latitud.get() == null ? 0d :
v.latitud.get(), v.longitud.get() == null ? 0d : v.longitud.get()));
v.modoPendiente.set(MODO_ADICION);
v.estado.set(PENDIENTE);
adicionaVisita(v);
dlVisita.dispose();
});
Container cnBotones = new Container(new GridLayout(1,
2)).add(btCancelar).add(btAceptar);
dlVisita.add(BorderLayout.NORTH, cnItem);
dlVisita.add(BorderLayout.SOUTH, cnBotones);
return dlVisita;
}
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/3b1aeb9b-1748-4362-849d-c4c5a1c00b63o%40googlegroups.com.