private void performValidation(boolean showPopUp) {
   if (!validate()) {
     fireOnFailure();
     imagePanel.removeStyleDependentName("valid");
     imagePanel.addStyleDependentName("invalid");
     if (showPopUp) {
       showMessagePopup();
     }
   } else {
     fireOnSuccess();
     imagePanel.removeStyleDependentName("invalid");
     imagePanel.addStyleDependentName("valid");
     hideMessagePopup();
   }
 }
  public ValidationTextBox() {
    textBox = new TextBox();
    textBox.addKeyUpHandler(
        new KeyUpHandler() {

          @Override
          public void onKeyUp(KeyUpEvent event) {
            performValidation(true);
            fireOnKeyUp(event);
          }
        });

    imagePanel =
        new SimplePanel() {

          @Override
          public void onBrowserEvent(Event event) {
            super.onBrowserEvent(event);
            switch (DOM.eventGetType(event)) {
              case Event.ONMOUSEOVER:
                {
                  if (!validate()) {
                    showMessagePopup();
                  }
                  break;
                }

              case Event.ONMOUSEOUT:
                {
                  hideMessagePopup();
                  break;
                }
            }
          }
        };
    imagePanel.setStylePrimaryName("validation-textbox-image-panel"); // $NON-NLS-1$
    imagePanel.sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT);
    this.add(textBox);
    textBox.setWidth("100%");
    this.setCellWidth(textBox, "100%");
    this.setStylePrimaryName("custom-text-box"); // $NON-NLS-1$
    SimplePanel hSpacer = new SimplePanel();
    hSpacer.setWidth("10px");
    this.add(hSpacer);
    image = new Image(GWT.getModuleBaseURL() + "images/spacer.gif"); // $NON-NLS-1$
    image.setStylePrimaryName("validation-textbox-image");
    imagePanel.add(image);
    imagePanel.addStyleDependentName("invalid");
    this.add(imagePanel);
  }