Search in sources :

Example 1 with CloudAttachDialog

use of com.google.cloud.tools.intellij.debugger.ui.CloudAttachDialog in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebuggerRunner method createContentDescriptor.

private static RunContentDescriptor createContentDescriptor(@Nullable final CloudDebugProcessState processState, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
    final XDebugSession debugSession = XDebuggerManager.getInstance(environment.getProject()).startSession(environment, new XDebugProcessStarter() {

        @NotNull
        @Override
        public XDebugProcess start(@NotNull final XDebugSession session) throws ExecutionException {
            // Clear out the stash state which is queried on debug exit.
            if (processState != null) {
                ProjectRepositoryState.fromProcessState(processState).clearForNextSession();
            }
            CloudDebugProcessState state = processState;
            CloudAttachDialog attachDialog = new CloudAttachDialog(session.getProject(), null);
            attachDialog.setInputState(state);
            DialogManager.show(attachDialog);
            state = attachDialog.getResultState();
            ProjectRepositoryValidator validator = null;
            if (state != null) {
                validator = new ProjectRepositoryValidator(state);
            }
            if (!attachDialog.isOK() || state == null || !validator.isValidDebuggee()) {
                throw new RunCanceledByUserException();
            }
            if (environment.getRunnerAndConfigurationSettings() != null && environment.getRunnerAndConfigurationSettings().getConfiguration() instanceof CloudDebugRunConfiguration) {
                CloudDebugRunConfiguration config = (CloudDebugRunConfiguration) environment.getRunnerAndConfigurationSettings().getConfiguration();
                // State is only stored in the run config between active sessions.
                // Otherwise, the background watcher may hit a check during debug session
                // startup.
                config.setProcessState(null);
            }
            CloudDebugProcess process = new CloudDebugProcess(session);
            process.initialize(state);
            return process;
        }
    });
    RunnerLayoutUi ui = debugSession.getUI();
    if (ui instanceof DataProvider) {
        final RunnerContentUi contentUi = (RunnerContentUi) ((DataProvider) ui).getData(RunnerContentUi.KEY.getName());
        final Project project = debugSession.getProject();
        if (contentUi != null) {
            ApplicationManager.getApplication().invokeLater(new Runnable() {

                @Override
                public void run() {
                    if (project.isOpen() && !project.isDisposed()) {
                        contentUi.restoreLayout();
                    }
                }
            });
        }
    }
    return debugSession.getRunContentDescriptor();
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) NotNull(org.jetbrains.annotations.NotNull) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) DataProvider(com.intellij.openapi.actionSystem.DataProvider) Project(com.intellij.openapi.project.Project) RunnerLayoutUi(com.intellij.execution.ui.RunnerLayoutUi) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) CloudAttachDialog(com.google.cloud.tools.intellij.debugger.ui.CloudAttachDialog) RunnerContentUi(com.intellij.execution.ui.layout.impl.RunnerContentUi) ExecutionException(com.intellij.execution.ExecutionException)

Aggregations

CloudAttachDialog (com.google.cloud.tools.intellij.debugger.ui.CloudAttachDialog)1 ExecutionException (com.intellij.execution.ExecutionException)1 RunCanceledByUserException (com.intellij.execution.RunCanceledByUserException)1 RunnerLayoutUi (com.intellij.execution.ui.RunnerLayoutUi)1 RunnerContentUi (com.intellij.execution.ui.layout.impl.RunnerContentUi)1 DataProvider (com.intellij.openapi.actionSystem.DataProvider)1 Project (com.intellij.openapi.project.Project)1 XDebugProcess (com.intellij.xdebugger.XDebugProcess)1 XDebugProcessStarter (com.intellij.xdebugger.XDebugProcessStarter)1 XDebugSession (com.intellij.xdebugger.XDebugSession)1 NotNull (org.jetbrains.annotations.NotNull)1