Example usage for com.google.gwt.user.client.ui FormPanel addSubmitCompleteHandler

List of usage examples for com.google.gwt.user.client.ui FormPanel addSubmitCompleteHandler

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui FormPanel addSubmitCompleteHandler.

Prototype

public HandlerRegistration addSubmitCompleteHandler(SubmitCompleteHandler handler) 

Source Link

Document

Adds a SubmitCompleteEvent handler.

Usage

From source file:org.rstudio.studio.client.server.remote.RemoteServerAuth.java

License:Open Source License

public void updateCredentials(final ServerRequestCallback<Integer> requestCallback) {
    // safely cleanup any previously active update credentials forms
    safeCleanupPreviousUpdateCredentials();

    // create a hidden form panel to submit the update credentials to
    // (we do this so GWT manages the trickiness associated with 
    // managing and reading the contents of a hidden iframe) 
    final FormPanel updateCredentialsForm = new FormPanel();
    updateCredentialsForm.setMethod(FormPanel.METHOD_GET);
    updateCredentialsForm.setEncoding(FormPanel.ENCODING_URLENCODED);

    // form url/*w  w w  . j a  v a 2  s .  c o m*/
    String url = remoteServer_.getApplicationURL("auth-update-credentials");
    updateCredentialsForm.setAction(url);

    // request log entry (fake up a json rpc method call to conform
    // to the data format expected by RequestLog
    String requestId = Integer.toString(Random.nextInt());
    String requestData = createRequestData();
    final RequestLogEntry logEntry = RequestLog.log(requestId, requestData);

    // form submit complete handler
    updateCredentialsForm.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        public void onSubmitComplete(SubmitCompleteEvent event) {
            // parse the results
            String results = event.getResults();
            RpcResponse response = RpcResponse.parse(event.getResults());
            if (response != null) {
                logEntry.logResponse(ResponseType.Normal, results);

                // check for error
                RpcError rpcError = response.getError();
                if (rpcError != null) {
                    if (rpcError.getCode() == RpcError.METHOD_NOT_FOUND) {
                        requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_UNSUPPORTED));
                    } else {
                        requestCallback.onError(new RemoteServerError(rpcError));
                    }
                } else // must be a valid response
                {
                    Bool authenticated = response.getResult();
                    if (authenticated.getValue()) {
                        requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_SUCCESS));
                    } else {
                        requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_FAILURE));
                    }
                }
            } else // error parsing results
            {
                logEntry.logResponse(ResponseType.Error, results);

                // form message
                String msg = "Error parsing results: " + (results != null ? results : "(null)");

                // we don't expect this so debug log to flag our attention
                Debug.log("UPDATE CREDENTIALS: " + msg);

                // return the error
                RpcError rpcError = RpcError.create(RpcError.PARSE_ERROR, msg);
                requestCallback.onError(new RemoteServerError(rpcError));
            }

            // remove the hidden form (from both last-ditch list and DOM)
            previousUpdateCredentialsForms_.remove(updateCredentialsForm);
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                public void execute() {
                    RootPanel.get().remove(updateCredentialsForm);
                }
            });
        }
    });

    // add the (hidden) form panel to the document and last ditch list
    RootPanel.get().add(updateCredentialsForm, -1000, -1000);
    previousUpdateCredentialsForms_.add(updateCredentialsForm);

    // submit the form
    updateCredentialsForm.submit();
}

From source file:org.utgenome.gwt.utgb.client.track.lib.ViewLoaderTrack.java

License:Apache License

public ViewLoaderTrack() {
    super("View Loader");
    // load view via HTTP
    HorizontalPanel hp = new HorizontalPanel();
    hp.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
    hp.add(new FormLabel("View Silk URL: "));
    urlBox.setWidth("400px");
    urlBox.addKeyPressHandler(new KeyPressHandler() {
        public void onKeyPress(KeyPressEvent e) {
            if (e.getCharCode() == KeyCodes.KEY_ENTER) {
                downloadView(urlBox.getText());
            }/*w w w .  j av a2 s.  co  m*/
        }
    });
    Button loadButton = new Button("load");
    loadButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent e) {
            downloadView(urlBox.getText());
        }
    });
    hp.add(urlBox);
    hp.add(loadButton);
    // load view from a file
    final FormPanel fileUploadForm = new FormPanel();
    fileUploadForm.setAction(GWT.getModuleBaseURL() + "utgb-core/loadview");
    fileUploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    fileUploadForm.setMethod(FormPanel.METHOD_POST);
    HorizontalPanel formButtonPanel = new HorizontalPanel();
    FileUpload fileBox = new FileUpload();
    fileBox.setName("file");
    fileBox.setWidth("300px");
    Button uploadButton = new Button("submit");
    uploadButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent e) {
            fileUploadForm.submit();
        }
    });
    formButtonPanel.add(new FormLabel("View Silk File:"));
    formButtonPanel.add(fileBox);
    formButtonPanel.add(uploadButton);
    fileUploadForm.add(formButtonPanel);
    DOM.setStyleAttribute(fileUploadForm.getElement(), "margin", "0");
    fileUploadForm.addSubmitCompleteHandler(new SubmitCompleteHandler() {
        public void onSubmitComplete(SubmitCompleteEvent e) {

            getFrame().setNowLoading();
            String viewXML = extractEmbeddedSilkInComment(e.getResults());
            setViewSilk(viewXML);
        }
    });
    // set panes
    panel.setStyleName("toolbox");
    panel.add(hp);
    panel.add(fileUploadForm);
}