Search in sources :

Example 1 with ProfileOperationResponse

use of org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse in project rstudio by rstudio.

the class ProfilerPresenter method buildHtmlPath.

public void buildHtmlPath(final OperationWithInput<ProfileOperationResponse> continuation, final Operation onError, final String path) {
    ProfileOperationRequest request = ProfileOperationRequest.create(path);
    server_.openProfile(request, new ServerRequestCallback<ProfileOperationResponse>() {

        @Override
        public void onResponseReceived(ProfileOperationResponse response) {
            if (response.getErrorMessage() != null) {
                globalDisplay_.showErrorMessage("Profiler Error", response.getErrorMessage());
                onError.execute();
                return;
            }
            continuation.execute(response);
        }

        @Override
        public void onError(ServerError error) {
            Debug.logError(error);
            globalDisplay_.showErrorMessage("Failed to Open Profile", error.getMessage());
            onError.execute();
        }
    });
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) ProfileOperationResponse(org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse) ProfileOperationRequest(org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationRequest)

Example 2 with ProfileOperationResponse

use of org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse in project rstudio by rstudio.

the class ProfilerPresenter method onStartProfiler.

@Handler
public void onStartProfiler() {
    dependencyManager_.withProfvis(profilerDependecyUserAction_, new Command() {

        @Override
        public void execute() {
            ProfileOperationRequest request = ProfileOperationRequest.create("");
            server_.startProfiling(request, new ServerRequestCallback<ProfileOperationResponse>() {

                @Override
                public void onResponseReceived(ProfileOperationResponse response) {
                    if (response.getErrorMessage() != null) {
                        globalDisplay_.showErrorMessage("Profiler Error", response.getErrorMessage());
                        return;
                    }
                    pSourceWindowManager_.get().ensureVisibleSourcePaneIfNecessary();
                    response_ = response;
                    sourceServer_.newDocument(FileTypeRegistry.PROFILER.getTypeId(), null, (JsObject) ProfilerContents.create(response.getFileName(), null, null, true).cast(), new SimpleRequestCallback<SourceDocument>("Show Profiler") {

                        @Override
                        public void onResponseReceived(SourceDocument response) {
                            currentDocId_ = response.getId();
                        }

                        @Override
                        public void onError(ServerError error) {
                            Debug.logError(error);
                        }
                    });
                }

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                    globalDisplay_.showErrorMessage("Failed to Stop Profiler", error.getMessage());
                }
            });
        }
    });
}
Also used : Command(com.google.gwt.user.client.Command) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) ServerError(org.rstudio.studio.client.server.ServerError) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) ProfileOperationResponse(org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse) ProfileOperationRequest(org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationRequest) Handler(org.rstudio.core.client.command.Handler)

Example 3 with ProfileOperationResponse

use of org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse in project rstudio by rstudio.

the class ProfilerPresenter method onStopProfiler.

@Handler
public void onStopProfiler() {
    ProfileOperationRequest request = ProfileOperationRequest.create(response_ != null ? response_.getFileName() : null);
    response_ = null;
    server_.stopProfiling(request, new ServerRequestCallback<ProfileOperationResponse>() {

        @Override
        public void onResponseReceived(ProfileOperationResponse response) {
            if (response.getErrorMessage() != null) {
                globalDisplay_.showErrorMessage("Profiler Error", response.getErrorMessage());
                return;
            }
        }

        @Override
        public void onError(ServerError error) {
            Debug.logError(error);
            globalDisplay_.showErrorMessage("Failed to Stop Profiler", error.getMessage());
        }
    });
}
Also used : ServerError(org.rstudio.studio.client.server.ServerError) ProfileOperationResponse(org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse) ProfileOperationRequest(org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationRequest) Handler(org.rstudio.core.client.command.Handler)

Example 4 with ProfileOperationResponse

use of org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse in project rstudio by rstudio.

the class ProfilerEditingTarget method onActivate.

public void onActivate() {
    activeProfilerEditingTarger_ = this;
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

        public void execute() {
            commands_.gotoProfileSource().setEnabled(hasValidPath_);
        }
    });
    final Operation activateOperation = new Operation() {

        @Override
        public void execute() {
            if (!htmlPathInitialized_) {
                htmlPathInitialized_ = true;
                htmlPath_ = getContents().getHtmlPath();
                htmlLocalPath_ = getContents().getHtmlLocalPath();
                isUserSaved_ = getContents().isUserSaved();
                if (htmlPath_ == null) {
                    presenter_.buildHtmlPath(new OperationWithInput<ProfileOperationResponse>() {

                        @Override
                        public void execute(ProfileOperationResponse response) {
                            htmlPath_ = response.getHtmlPath();
                            htmlLocalPath_ = response.getHtmlLocalPath();
                            persistDocumentProperty("htmlPath", htmlPath_);
                            persistDocumentProperty("htmlLocalPath", htmlLocalPath_);
                            view_.showProfilePage(htmlPath_);
                            pSourceWindowManager_.get().maximizeSourcePaneIfNecessary();
                        }
                    }, new Operation() {

                        @Override
                        public void execute() {
                            server_.clearProfile(getPath(), new ServerRequestCallback<JavaScriptObject>() {

                                @Override
                                public void onResponseReceived(JavaScriptObject response) {
                                    commands_.closeSourceDoc().execute();
                                }

                                @Override
                                public void onError(ServerError error) {
                                    Debug.logError(error);
                                    commands_.closeSourceDoc().execute();
                                }
                            });
                        }
                    }, getPath());
                } else {
                    view_.showProfilePage(htmlPath_);
                    Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                        public void execute() {
                            pSourceWindowManager_.get().maximizeSourcePaneIfNecessary();
                        }
                    });
                }
            }
        }
    };
    if (getId() != null && !SourceWindowManager.isMainSourceWindow()) {
        sourceServer_.getSourceDocument(getId(), new ServerRequestCallback<SourceDocument>() {

            @Override
            public void onResponseReceived(SourceDocument document) {
                doc_ = document;
                activateOperation.execute();
            }

            @Override
            public void onError(ServerError error) {
                Debug.logError(error);
            }
        });
    } else {
        activateOperation.execute();
    }
    // This shouldn't happen though.
    if (commandHandlerReg_ != null) {
        Debug.log("Warning: onActivate called twice without intervening onDeactivate");
        commandHandlerReg_.removeHandler();
        commandHandlerReg_ = null;
    }
    commandHandlerReg_ = commandBinder.bind(commands_, this);
}
Also used : ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ServerError(org.rstudio.studio.client.server.ServerError) SourceDocument(org.rstudio.studio.client.workbench.views.source.model.SourceDocument) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback) ProfileOperationResponse(org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse) Operation(org.rstudio.core.client.widget.Operation)

Aggregations

ServerError (org.rstudio.studio.client.server.ServerError)4 ProfileOperationResponse (org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationResponse)4 ProfileOperationRequest (org.rstudio.studio.client.workbench.views.source.editors.profiler.model.ProfileOperationRequest)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 Handler (org.rstudio.core.client.command.Handler)2 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)2 SourceDocument (org.rstudio.studio.client.workbench.views.source.model.SourceDocument)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 Command (com.google.gwt.user.client.Command)1 Operation (org.rstudio.core.client.widget.Operation)1