Search in sources :

Example 1 with SubmitCompleteHandler

use of com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler in project rstudio by rstudio.

the class RemoteServerAuth method updateCredentials.

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
    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();
}
Also used : FormPanel(com.google.gwt.user.client.ui.FormPanel) RequestLogEntry(org.rstudio.core.client.jsonrpc.RequestLogEntry) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Bool(org.rstudio.studio.client.server.Bool) RpcError(org.rstudio.core.client.jsonrpc.RpcError) JSONString(com.google.gwt.json.client.JSONString) SubmitCompleteEvent(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler) RpcResponse(org.rstudio.core.client.jsonrpc.RpcResponse)

Example 2 with SubmitCompleteHandler

use of com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler in project gwt-test-utils by gwt-test-utils.

the class BrowserTest method submit.

@Test()
public void submit() {
    // Given
    final StringBuilder sb = new StringBuilder();
    FormPanel form = new FormPanel();
    form.addSubmitHandler(new SubmitHandler() {

        public void onSubmit(SubmitEvent event) {
            sb.append("onSubmit");
        }
    });
    form.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        public void onSubmitComplete(SubmitCompleteEvent event) {
            sb.append(" complete : ").append(event.getResults());
        }
    });
    // Attach to the DOM
    RootPanel.get().add(form);
    // Given
    Browser.submit(form, "mock result");
    // Then
    assertThat(sb.toString()).isEqualTo("onSubmit complete : mock result");
}
Also used : SubmitHandler(com.google.gwt.user.client.ui.FormPanel.SubmitHandler) SubmitCompleteEvent(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler) SubmitEvent(com.google.gwt.user.client.ui.FormPanel.SubmitEvent) Test(org.junit.Test)

Example 3 with SubmitCompleteHandler

use of com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler in project pentaho-platform by pentaho.

the class ImportFileCommand method performOperation.

protected void performOperation(boolean feedback) {
    // delete file
    importDialog = new ImportDialog(repositoryFile, SolutionBrowserPanel.getInstance().isAdministrator());
    importDialog.getForm().addSubmitCompleteHandler(new SubmitCompleteHandler() {

        @Override
        public void onSubmitComplete(SubmitCompleteEvent sce) {
            new RefreshRepositoryCommand().execute(false);
        }
    });
    final IDialogCallback callback = new IDialogCallback() {

        public void cancelPressed() {
            importDialog.hide();
        }

        public void okPressed() {
            importDialog.getForm().submit();
        }
    };
    importDialog.setCallback(callback);
    importDialog.center();
}
Also used : ImportDialog(org.pentaho.mantle.client.dialogs.ImportDialog) SubmitCompleteEvent(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler) IDialogCallback(org.pentaho.gwt.widgets.client.dialogs.IDialogCallback)

Example 4 with SubmitCompleteHandler

use of com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler in project data-access by pentaho.

the class GwtDatasourceEditorEntryPoint method showAnalysisImportDialog.

public void showAnalysisImportDialog(final DialogListener listener) {
    final DialogListener<AnalysisImportDialogModel> importDialoglistener = new DialogListener<AnalysisImportDialogModel>() {

        public void onDialogCancel() {
            final AnalysisImportDialogController controller = importDialog.getAnalysisImportDialogController();
            final FormPanel analysisDataFormPanel = controller.getFormPanel();
            controller.removeHiddenPanels();
            controller.buildAndSetParameters();
            analysisDataFormPanel.removeFromParent();
            RootPanel.get().add(analysisDataFormPanel);
        }

        public void onDialogAccept(final AnalysisImportDialogModel importDialogModel) {
            final AnalysisImportDialogController controller = importDialog.getAnalysisImportDialogController();
            final FormPanel analysisDataFormPanel = controller.getFormPanel();
            controller.removeHiddenPanels();
            controller.buildAndSetParameters();
            analysisDataFormPanel.removeFromParent();
            RootPanel.get().add(analysisDataFormPanel);
            analysisDataFormPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {

                @Override
                public void onSubmitComplete(SubmitCompleteEvent event) {
                    String results = event.getResults();
                    String message = controller.convertToNLSMessage(results, controller.getFileName());
                    if (!SUCCESS_3.equals(results)) {
                        if (OVERWRITE_8.equals(results) || OVERWRITE__CATALOG_7.equals(results)) {
                            overwriteFileDialog(analysisDataFormPanel, message, controller);
                        } else {
                            listener.onDialogError(message);
                        }
                    } else {
                        analysisDataFormPanel.removeFromParent();
                        listener.onDialogAccept(null);
                    }
                }
            });
            analysisDataFormPanel.submit();
        }

        public void onDialogReady() {
        }

        @Override
        public void onDialogError(String errorMessage) {
            listener.onDialogError(errorMessage);
        }
    };
    final AsyncConstructorListener<GwtImportDialog> constructorListener = new AsyncConstructorListener<GwtImportDialog>() {

        public void asyncConstructorDone(GwtImportDialog dialog) {
            dialog.showAnalysisImportDialog(importDialoglistener);
        }
    };
    if (importDialog == null) {
        importDialog = new GwtImportDialog(constructorListener);
    } else {
        importDialog.showAnalysisImportDialog(importDialoglistener);
    }
}
Also used : AnalysisImportDialogController(org.pentaho.platform.dataaccess.datasource.ui.importing.AnalysisImportDialogController) FormPanel(com.google.gwt.user.client.ui.FormPanel) DialogListener(org.pentaho.ui.xul.util.DialogController.DialogListener) SubmitCompleteEvent(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler) GwtImportDialog(org.pentaho.platform.dataaccess.datasource.ui.importing.GwtImportDialog) AsyncConstructorListener(org.pentaho.ui.xul.gwt.util.AsyncConstructorListener) AnalysisImportDialogModel(org.pentaho.platform.dataaccess.datasource.ui.importing.AnalysisImportDialogModel)

Example 5 with SubmitCompleteHandler

use of com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler in project data-access by pentaho.

the class MetadataImportDialogController method createSubmitCompleteHandler.

private SubmitCompleteHandler createSubmitCompleteHandler() {
    return new SubmitCompleteHandler() {

        @Override
        public void onSubmitComplete(SubmitCompleteEvent event) {
            // delete all surrounded tags
            final String jsonResponseText = new HTML(event.getResults()).getText();
            final JSONObject jsonResponse;
            JSONValue jsonVal = JSONParser.parseStrict(jsonResponseText);
            if (jsonVal != null) {
                jsonResponse = jsonVal.isObject();
            } else {
                jsonResponse = null;
            }
            if (jsonResponse == null) {
                onImportError("wrong data from xmi file checker");
                return;
            }
            String tempFileName = jsonResponse.get("xmiFileName").isString().stringValue();
            RequestBuilder checkFileRequest = new RequestBuilder(RequestBuilder.GET, METADATA_CHECK_URL + "?tempFileName=" + URL.encode(tempFileName));
            checkFileRequest.setCallback(new RequestCallback() {

                @Override
                public void onResponseReceived(Request request, Response response) {
                    if (response.getStatusCode() == HttpStatus.SC_OK) {
                        if (Boolean.TRUE.toString().equalsIgnoreCase(response.getText())) {
                            promptImportMetadata(resBundle.getString("importDialog.IMPORT_METADATA"), resBundle.getString("importDialog.CONFIRMATION_LOAD_DSW"), resBundle.getString("importDialog.DIALOG_DSW_RADIO", "Data Source Wizard (Includes Analysis model)"), resBundle.getString("importDialog.DIALOG_METADATA_RADIO", "Metadata model"), new AsyncCallback<Boolean>() {

                                @Override
                                public void onSuccess(Boolean result) {
                                    new XmiImporterRequest((Boolean) result ? METADATA_IMPORT_DSW_URL : METADATA_IMPORT_XMI_URL, jsonResponse).doImport(false);
                                }

                                @Override
                                public void onFailure(Throwable caught) {
                                    onImportError(caught.getMessage());
                                }
                            });
                        } else if (Boolean.FALSE.toString().equals(response.getText())) {
                            new XmiImporterRequest(METADATA_IMPORT_XMI_URL, jsonResponse).doImport(false);
                        } else {
                            onImportError("wrong data from xmi file checker");
                        }
                    } else {
                        onImportError("[server data error] , wrong code: " + response.getStatusCode());
                    }
                }

                @Override
                public void onError(Request request, Throwable exception) {
                    onImportError("[request error] " + exception.getMessage());
                }
            });
            try {
                checkFileRequest.send();
            } catch (RequestException e) {
                onImportError(e.getMessage());
            }
        }
    };
}
Also used : RequestBuilder(com.google.gwt.http.client.RequestBuilder) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Request(com.google.gwt.http.client.Request) HTML(com.google.gwt.user.client.ui.HTML) SubmitCompleteEvent(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler) RequestException(com.google.gwt.http.client.RequestException) JSONValue(com.google.gwt.json.client.JSONValue) Response(com.google.gwt.http.client.Response) JSONObject(com.google.gwt.json.client.JSONObject) RequestCallback(com.google.gwt.http.client.RequestCallback)

Aggregations

SubmitCompleteEvent (com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent)6 SubmitCompleteHandler (com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler)6 FormPanel (com.google.gwt.user.client.ui.FormPanel)3 AnalysisImportDialogController (org.pentaho.platform.dataaccess.datasource.ui.importing.AnalysisImportDialogController)2 AnalysisImportDialogModel (org.pentaho.platform.dataaccess.datasource.ui.importing.AnalysisImportDialogModel)2 GwtImportDialog (org.pentaho.platform.dataaccess.datasource.ui.importing.GwtImportDialog)2 AsyncConstructorListener (org.pentaho.ui.xul.gwt.util.AsyncConstructorListener)2 DialogListener (org.pentaho.ui.xul.util.DialogController.DialogListener)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 Request (com.google.gwt.http.client.Request)1 RequestBuilder (com.google.gwt.http.client.RequestBuilder)1 RequestCallback (com.google.gwt.http.client.RequestCallback)1 RequestException (com.google.gwt.http.client.RequestException)1 Response (com.google.gwt.http.client.Response)1 JSONObject (com.google.gwt.json.client.JSONObject)1 JSONString (com.google.gwt.json.client.JSONString)1 JSONValue (com.google.gwt.json.client.JSONValue)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 SubmitEvent (com.google.gwt.user.client.ui.FormPanel.SubmitEvent)1 SubmitHandler (com.google.gwt.user.client.ui.FormPanel.SubmitHandler)1