Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.webgocommerce.client.view.uimantlocalidad; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyUpEvent; import com.google.gwt.event.dom.client.KeyUpHandler; import com.google.gwt.event.logical.shared.ResizeEvent; import com.google.gwt.event.logical.shared.ResizeHandler; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.TextBox; import com.webgocommerce.client.beanproxy.LocalidadProxy; import com.webgocommerce.client.model.UIMantenimiento; import static com.webgocommerce.client.model.UIMantenimiento.MODOINSERTAR; import static com.webgocommerce.client.model.UIMantenimiento.MODOUPDATE; import com.webgocommerce.client.uiutil.Notification; import com.webgocommerce.shared.FieldVerifier; /** * * @author SISTEMAS */ public class UIMantLocalidad extends UIMantenimiento implements InterUIMantLocalidad, KeyUpHandler { protected TextBox txtId; protected TextBox txtDescripcion; protected LocalidadProxy bean; public UIMantLocalidad() { initComponents(); initListener(); reCalcularWindows(); } private void initComponents() { txtId = new TextBox(); txtDescripcion = new TextBox(); txtDescripcion.getElement().setAttribute("required", "required"); //this.addWidget("ID", txtId); this.addWidget("DESCRIPCION (*)", txtDescripcion); Window.addResizeHandler(new ResizeHandler() { @Override public void onResize(ResizeEvent event) { reCalcularWindows(); } }); } private void initListener() { txtDescripcion.addKeyUpHandler(this); } private void reCalcularWindows() { int alto = Window.getClientHeight() - 220; this.scrollPanel.setHeight(alto + "px"); } @Override public void loadFields() { if (this.modo.equals(UIMantenimiento.MODOUPDATE)) { txtId.setText(this.bean.getIdLocalidad().toString()); txtDescripcion.setText(this.bean.getDescripcion()); txtId.setEnabled(false); txtDescripcion.setEnabled(true); txtDescripcion.setFocus(true); txtDescripcion.selectAll(); this.btnOperacion.setDisabled(false); } else if (this.modo.equals(UIMantenimiento.MODODELETE)) { txtId.setText(this.bean.getIdLocalidad().toString()); txtDescripcion.setText(this.bean.getDescripcion()); txtId.setEnabled(false); txtDescripcion.setEnabled(false); this.btnOperacion.setDisabled(false); } else if (this.modo.equals(UIMantenimiento.MODODETALLE)) { txtId.setText(this.bean.getIdLocalidad().toString()); txtDescripcion.setText(this.bean.getDescripcion()); txtId.setEnabled(false); txtDescripcion.setEnabled(false); this.btnOperacion.setDisabled(true); } else { txtId.setEnabled(false); txtDescripcion.setFocus(true); txtDescripcion.setEnabled(true); txtDescripcion.selectAll(); this.btnOperacion.setDisabled(false); } } public void setBean(LocalidadProxy bean) { this.bean = bean; } @Override public void cleanForm() { txtId.setText(null); txtDescripcion.setText(null); } @Override public void onKeyUp(KeyUpEvent event) { if (event.getSource().equals(txtDescripcion)) { if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) { if (modo.equalsIgnoreCase(MODOINSERTAR)) { processInsertar(); } else if (modo.equalsIgnoreCase(MODOUPDATE)) { processActualizar(); } else { //Window.alert("Operacin no contemplada"); Notification not = new Notification(Notification.ALERT, "Operacin no contemplada"); not.showPopup(); } } } } @Override public void goToUILocalidad() { cleanForm(); } @Override public boolean isValidData() { if (FieldVerifier.isEmpty(txtDescripcion.getText())) { //Window.alert("Descripcion es un campo obligatorio"); Notification not = new Notification(Notification.ALERT, "Descripcion es un campo obligatorio"); not.showPopup(); txtDescripcion.setFocus(true); return false; } return true; } }