Java Code Examples for com.intellij.execution.ui.RunContentDescriptor

The following are top voted examples for showing how to use com.intellij.execution.ui.RunContentDescriptor. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: react-native-console   File: RunnerUtil.java   View source code 6 votes vote down vote up
public static final ConsoleView showHelperProcessRunContent(String header, OSProcessHandler runHandler, Project project, Executor defaultExecutor) {
        ProcessTerminatedListener.attach(runHandler);

        ConsoleViewImpl consoleView = new ConsoleViewImpl(project, true);
        DefaultActionGroup toolbarActions = new DefaultActionGroup();

        JPanel panel = new JPanel((LayoutManager) new BorderLayout());
        panel.add((Component) consoleView.getComponent(), "Center");
        ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("unknown", (ActionGroup) toolbarActions, false);
        toolbar.setTargetComponent(consoleView.getComponent());
        panel.add((Component) toolbar.getComponent(), "West");

        RunContentDescriptor runDescriptor = new RunContentDescriptor((ExecutionConsole) consoleView,
                (ProcessHandler) runHandler, (JComponent) panel, header, AllIcons.RunConfigurations.Application);
        AnAction[]
                consoleActions = consoleView.createConsoleActions();
        toolbarActions.addAll((AnAction[]) Arrays.copyOf(consoleActions, consoleActions.length));
        toolbarActions.add((AnAction) new StopProcessAction("Stop process", "Stop process", (ProcessHandler) runHandler));
        toolbarActions.add((AnAction) new CloseAction(defaultExecutor, runDescriptor, project));

        consoleView.attachToProcess((ProcessHandler) runHandler);
//        ExecutionManager.getInstance(environment.getProject()).getContentManager().showRunContent(environment.getExecutor(), runDescriptor);
        showConsole(project, defaultExecutor, runDescriptor);
        return (ConsoleView) consoleView;
    }
 
Example 2
Project: intellij-ce-playground   File: RerunTestsNotification.java   View source code 6 votes vote down vote up
public static void showRerunNotification(@Nullable RunContentDescriptor contentToReuse,
                                         @NotNull final ExecutionConsole executionConsole) {
  if (contentToReuse == null) {
    return;
  }
  String lastActionId = ActionManagerEx.getInstanceEx().getPrevPreformedActionId();
  boolean showNotification = !RerunTestsAction.ID.equals(lastActionId);
  if (showNotification && !PropertiesComponent.getInstance().isTrueValue(KEY)) {
    UiNotifyConnector.doWhenFirstShown(executionConsole.getComponent(), new Runnable() {
      @Override
      public void run() {
        doShow(executionConsole);
      }
    });
  }
}
 
Example 3
Project: intellij-ce-playground   File: ExternalToolRunner.java   View source code 6 votes vote down vote up
protected ConsoleView initConsoleUi() {
  ConsoleView consoleView = createConsoleView();
  consoleView.print(myCommandLine.getCommandLineString() + '\n', ConsoleViewContentType.USER_INPUT);
  consoleView.attachToProcess(myProcessHandler);

  JPanel panel = new JPanel(new BorderLayout());

  DefaultActionGroup toolbarActions = new DefaultActionGroup();
  ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, toolbarActions, false);
  panel.add(actionToolbar.getComponent(), BorderLayout.WEST);
  panel.add(consoleView.getComponent(), BorderLayout.CENTER);
  actionToolbar.setTargetComponent(panel);

  toolbarActions.addAll(consoleView.createConsoleActions());
  fillToolBarActions(toolbarActions);
  panel.updateUI();

  Executor defaultExecutor = DefaultRunExecutor.getRunExecutorInstance();
  final RunContentDescriptor contentDescriptor = new RunContentDescriptor(consoleView, myProcessHandler, panel, myTitle);
  showConsole(defaultExecutor, contentDescriptor);

  myProcessHandler.addProcessListener(new ConsoleListener(myProject, defaultExecutor, myProcessHandler));
  myProcessHandler.startNotify();
  return consoleView;
}
 
Example 4
Project: intellij-ce-playground   File: UnscrambleDialog.java   View source code 6 votes vote down vote up
private static RunContentDescriptor addConsole(final Project project, final List<ThreadState> threadDump, String unscrambledTrace) {
  Icon icon = null;
  String message = IdeBundle.message("unscramble.unscrambled.stacktrace.tab");
  if (!threadDump.isEmpty()) {
    message = IdeBundle.message("unscramble.unscrambled.threaddump.tab");
    icon = AllIcons.Debugger.ThreadStates.Threaddump;
  }
  else {
    String name = getExceptionName(unscrambledTrace);
    if (name != null) {
      message = name;
      icon = AllIcons.Debugger.ThreadStates.Exception;
    }
  }
  if (ContainerUtil.find(threadDump, DEADLOCK_CONDITION) != null) {
    message = IdeBundle.message("unscramble.unscrambled.deadlock.tab");
    icon = AllIcons.Debugger.KillProcess;
  }
  return AnalyzeStacktraceUtil.addConsole(project, threadDump.size() > 1 ? new ThreadDumpConsoleFactory(project, threadDump) : null, message, unscrambledTrace, icon);
}
 
Example 5
Project: intellij-ce-playground   File: ExecutionManagerImpl.java   View source code 6 votes vote down vote up
@Override
public void restartRunProfile(@NotNull Project project,
                              @NotNull Executor executor,
                              @NotNull ExecutionTarget target,
                              @Nullable RunnerAndConfigurationSettings configuration,
                              @Nullable ProcessHandler processHandler) {
  ExecutionEnvironmentBuilder builder = createEnvironmentBuilder(project, executor, configuration);
  if (processHandler != null) {
    for (RunContentDescriptor descriptor : getContentManager().getAllDescriptors()) {
      if (descriptor.getProcessHandler() == processHandler) {
        builder.contentToReuse(descriptor);
        break;
      }
    }
  }
  restartRunProfile(builder.target(target).build());
}
 
Example 6
Project: intellij-ce-playground   File: AutoTestManager.java   View source code 6 votes vote down vote up
private static boolean isAutoTestEnabledForDescriptor(@NotNull RunContentDescriptor descriptor) {
  Content content = descriptor.getAttachedContent();
  if (content != null) {
    ExecutionEnvironment watched = EXECUTION_ENVIRONMENT_KEY.get(content);
    if (watched != null) {
      ExecutionEnvironment current = getCurrentEnvironment(content);
      boolean result = current != null && equals(current, watched);
      if (!result) {
        // let GC do its work
        EXECUTION_ENVIRONMENT_KEY.set(content, null);
      }
      return result;
    }
  }
  return false;
}
 
Example 7
Project: intellij-ce-playground   File: ExecutionManagerImpl.java   View source code 6 votes vote down vote up
@NotNull
@Override
public ProcessHandler[] getRunningProcesses() {
  if (myContentManager == null) return EMPTY_PROCESS_HANDLERS;
  List<ProcessHandler> handlers = null;
  for (RunContentDescriptor descriptor : getContentManager().getAllDescriptors()) {
    ProcessHandler processHandler = descriptor.getProcessHandler();
    if (processHandler != null) {
      if (handlers == null) {
        handlers = new SmartList<ProcessHandler>();
      }
      handlers.add(processHandler);
    }
  }
  return handlers == null ? EMPTY_PROCESS_HANDLERS : handlers.toArray(new ProcessHandler[handlers.size()]);
}
 
Example 8
Project: intellij-ce-playground   File: XDebugSessionImpl.java   View source code 6 votes vote down vote up
public XDebugSessionTab init(@NotNull XDebugProcess process, @NotNull XDebugSessionData sessionData, @Nullable RunContentDescriptor contentToReuse) {
  LOG.assertTrue(myDebugProcess == null);
  myDebugProcess = process;
  mySessionData = sessionData;

  if (myDebugProcess.checkCanInitBreakpoints()) {
    initBreakpoints();
  }

  myDebugProcess.getProcessHandler().addProcessListener(new ProcessAdapter() {
    @Override
    public void processTerminated(final ProcessEvent event) {
      stopImpl();
      myDebugProcess.getProcessHandler().removeProcessListener(this);
    }
  });
  //todo[nik] make 'createConsole()' method return ConsoleView
  myConsoleView = (ConsoleView)myDebugProcess.createConsole();
  if (!myShowTabOnSuspend.get()) {
    initSessionTab(contentToReuse);
  }

  return mySessionTab;
}
 
Example 9
Project: intellij-ce-playground   File: XDebugSessionTab.java   View source code 6 votes vote down vote up
private void setSession(@NotNull XDebugSessionImpl session, @Nullable ExecutionEnvironment environment, @Nullable Icon icon) {
  myEnvironment = environment;
  mySession = session;
  mySessionData = session.getSessionData();
  myConsole = session.getConsoleView();

  AnAction[] restartActions;
  List<AnAction> restartActionsList = session.getRestartActions();
  if (ContainerUtil.isEmpty(restartActionsList)) {
    restartActions = AnAction.EMPTY_ARRAY;
  }
  else {
    restartActions = restartActionsList.toArray(new AnAction[restartActionsList.size()]);
  }

  myRunContentDescriptor = new RunContentDescriptor(myConsole, session.getDebugProcess().getProcessHandler(),
                                                    myUi.getComponent(), session.getSessionName(), icon, myRebuildWatchesRunnable, restartActions);
  Disposer.register(myRunContentDescriptor, this);
  Disposer.register(myProject, myRunContentDescriptor);
}
 
Example 10
Project: intellij-ce-playground   File: XDebuggerManagerImpl.java   View source code 6 votes vote down vote up
@NotNull
@Override
public XDebugSession startSessionAndShowTab(@NotNull String sessionName,
                                            Icon icon,
                                            @Nullable RunContentDescriptor contentToReuse,
                                            boolean showToolWindowOnSuspendOnly,
                                            @NotNull XDebugProcessStarter starter) throws ExecutionException {
  XDebugSessionImpl session = startSession(contentToReuse, starter, new XDebugSessionImpl(null, this, sessionName,
                                                                                          icon, showToolWindowOnSuspendOnly));
  if (!showToolWindowOnSuspendOnly) {
    session.showSessionTab();
  }
  ProcessHandler handler = session.getDebugProcess().getProcessHandler();
  handler.startNotify();
  return session;
}
 
Example 11
Project: intellij-ce-playground   File: XDebuggerManagerImpl.java   View source code 6 votes vote down vote up
public void removeSession(@NotNull final XDebugSessionImpl session) {
  XDebugSessionTab sessionTab = session.getSessionTab();
  mySessions.remove(session.getDebugProcess().getProcessHandler());
  if (sessionTab != null) {
    RunContentDescriptor descriptor = sessionTab.getRunContentDescriptor();
    if (descriptor != null) {
      // in test-mode RunContentWithExecutorListener.contentRemoved events are not sent (see RunContentManagerImpl.showRunContent)
      // so we make sure the mySessions and mySessionData are cleared correctly when session is disposed
      Disposer.register(descriptor, new Disposable() {
        @Override
        public void dispose() {
          mySessions.remove(session.getDebugProcess().getProcessHandler());
        }
      });
    }

    if (!myProject.isDisposed() && !ApplicationManager.getApplication().isUnitTestMode() && XDebuggerSettingsManager.getInstanceImpl().getGeneralSettings().isHideDebuggerOnProcessTermination()) {
      ExecutionManager.getInstance(myProject).getContentManager().hideRunContent(DefaultDebugExecutor.getDebugExecutorInstance(), descriptor);
    }
  }
  if (myActiveSession.compareAndSet(session, null)) {
    onActiveSessionChanged();
  }
}
 
Example 12
Project: intellij-ce-playground   File: ModuleRunConfigurationManagerTest.java   View source code 6 votes vote down vote up
public void testSuppressToolwindowActivation() throws Exception {
  RunnerAndConfigurationSettings settings = new RunnerAndConfigurationSettingsImpl(
    new MyRunManagerImpl(), new MyModuleBasedConfiguration("my-name", getProject(), getModule()), false
  );
  settings.setActivateToolWindowBeforeRun(true);
  MockProgramRunner programRunner = new MockProgramRunner();
  ExecutionEnvironment env = new ExecutionEnvironmentBuilder(getProject(), DefaultRunExecutor.getRunExecutorInstance())
    .runnerAndSettings(programRunner, settings)
    .build();
  RunContentDescriptor descriptorToReuse = new RunContentDescriptor(null, null, new JPanel(), "name");
  descriptorToReuse.setActivateToolWindowWhenAdded(false);
  descriptorToReuse.setReuseToolWindowActivation(true);
  env.setContentToReuse(descriptorToReuse);
  env.getRunner().execute(env);
  RunContentDescriptor lastDescriptor = programRunner.getLastDescriptor();
  assertNotNull(lastDescriptor);
  assertFalse(lastDescriptor.isActivateToolWindowWhenAdded());
  Disposer.dispose(descriptorToReuse);
}
 
Example 13
Project: intellij-ce-playground   File: RunConfigurationsComboBoxAction.java   View source code 6 votes vote down vote up
private static void setConfigurationIcon(final Presentation presentation,
                                         final RunnerAndConfigurationSettings settings,
                                         final Project project) {
  try {
    Icon icon = RunManagerEx.getInstanceEx(project).getConfigurationIcon(settings);
    ExecutionManagerImpl executionManager = ExecutionManagerImpl.getInstance(project);
    List<RunContentDescriptor> runningDescriptors = executionManager.getRunningDescriptors(new Condition<RunnerAndConfigurationSettings>() {
        @Override
        public boolean value(RunnerAndConfigurationSettings s) {
          return s == settings;
        }
      });
    if (runningDescriptors.size() == 1) {
      icon = ExecutionUtil.getLiveIndicator(icon);
    }
    if (runningDescriptors.size() > 1) {
      icon = IconUtil.addText(icon, String.valueOf(runningDescriptors.size()));
    }
    presentation.setIcon(icon);
  }
  catch (IndexNotReadyException ignored) {
  }
}
 
Example 14
Project: intellij-ce-playground   File: ExecutionManagerImpl.java   View source code 6 votes vote down vote up
private static void stop(@Nullable RunContentDescriptor descriptor) {
  ProcessHandler processHandler = descriptor != null ? descriptor.getProcessHandler() : null;
  if (processHandler == null) {
    return;
  }

  if (processHandler instanceof KillableProcess && processHandler.isProcessTerminating()) {
    ((KillableProcess)processHandler).killProcess();
    return;
  }

  if (!processHandler.isProcessTerminated()) {
    if (processHandler.detachIsDefault()) {
      processHandler.detachProcess();
    }
    else {
      processHandler.destroyProcess();
    }
  }
}
 
Example 15
Project: intellij-ce-playground   File: RunIdeConsoleAction.java   View source code 6 votes vote down vote up
private static void executeQuery(@NotNull Project project,
                                 @NotNull VirtualFile file,
                                 @NotNull Editor editor,
                                 @NotNull IdeScriptEngine engine) {
  String command = getCommand(editor);
  String profile = getProfile(file);
  RunContentDescriptor descriptor = getConsoleView(project, file);
  ConsoleViewImpl consoleView = (ConsoleViewImpl)descriptor.getExecutionConsole();

  prepareEngine(project, engine, descriptor);
  try {
    //myHistoryController.getModel().addToHistory(command);
    consoleView.print("> " + command, ConsoleViewContentType.USER_INPUT);
    consoleView.print("\n", ConsoleViewContentType.USER_INPUT);
    Object o = engine.eval(profile == null ? command : profile + "\n" + command);
    consoleView.print("=> " + o, ConsoleViewContentType.NORMAL_OUTPUT);
    consoleView.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
  }
  catch (Throwable e) {
    //noinspection ThrowableResultOfMethodCallIgnored
    Throwable ex = ExceptionUtil.getRootCause(e);
    consoleView.print(ex.getClass().getSimpleName() + ": " + ex.getMessage(), ConsoleViewContentType.ERROR_OUTPUT);
    consoleView.print("\n", ConsoleViewContentType.ERROR_OUTPUT);
  }
  selectContent(descriptor);
}
 
Example 16
Project: intellij-ce-playground   File: RunIdeConsoleAction.java   View source code 6 votes vote down vote up
@NotNull
private static RunContentDescriptor createConsoleView(@NotNull Project project, @NotNull PsiFile psiFile) {
  ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole();

  DefaultActionGroup toolbarActions = new DefaultActionGroup();
  JComponent panel = new JPanel(new BorderLayout());
  panel.add(consoleView.getComponent(), BorderLayout.CENTER);
  ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, toolbarActions, false);
  toolbar.setTargetComponent(consoleView.getComponent());
  panel.add(toolbar.getComponent(), BorderLayout.WEST);

  final RunContentDescriptor descriptor = new RunContentDescriptor(consoleView, null, panel, psiFile.getName()) {
    @Override
    public boolean isContentReuseProhibited() {
      return true;
    }
  };
  Executor executor = DefaultRunExecutor.getRunExecutorInstance();
  toolbarActions.addAll(consoleView.createConsoleActions());
  toolbarActions.add(new CloseAction(executor, descriptor, project));
  ExecutionManager.getInstance(project).getContentManager().showRunContent(executor, descriptor);

  return descriptor;
}
 
Example 17
Project: intellij-ce-playground   File: PyExecuteSelectionAction.java   View source code 6 votes vote down vote up
private static Collection<RunContentDescriptor> getConsoles(Project project) {
  PythonConsoleToolWindow toolWindow = PythonConsoleToolWindow.getInstance(project);

  if (toolWindow != null && toolWindow.getToolWindow().isVisible()) {
    RunContentDescriptor selectedContentDescriptor = toolWindow.getSelectedContentDescriptor();
    return selectedContentDescriptor != null ? Lists.newArrayList(selectedContentDescriptor) : Lists.<RunContentDescriptor>newArrayList();
  }

  Collection<RunContentDescriptor> descriptors =
    ExecutionHelper.findRunningConsole(project, new NotNullFunction<RunContentDescriptor, Boolean>() {
      @NotNull
      @Override
      public Boolean fun(RunContentDescriptor dom) {
        return dom.getExecutionConsole() instanceof PyCodeExecutor && isAlive(dom);
      }
    });

  if (descriptors.isEmpty() && toolWindow != null) {
    return toolWindow.getConsoleContentDescriptors();
  }
  else {
    return descriptors;
  }
}
 
Example 18
Project: intellij-ce-playground   File: ExecutionHelper.java   View source code 6 votes vote down vote up
public static Collection<RunContentDescriptor> findRunningConsole(@NotNull Project project,
                                                                  @NotNull NotNullFunction<RunContentDescriptor, Boolean> descriptorMatcher) {
  RunContentManager contentManager = ExecutionManager.getInstance(project).getContentManager();
  final RunContentDescriptor selectedContent = contentManager.getSelectedContent();
  if (selectedContent != null) {
    final ToolWindow toolWindow = contentManager.getToolWindowByDescriptor(selectedContent);
    if (toolWindow != null && toolWindow.isVisible()) {
      if (descriptorMatcher.fun(selectedContent)) {
        return Collections.singletonList(selectedContent);
      }
    }
  }

  final ArrayList<RunContentDescriptor> result = ContainerUtil.newArrayList();
  for (RunContentDescriptor runContentDescriptor : contentManager.getAllDescriptors()) {
    if (descriptorMatcher.fun(runContentDescriptor)) {
      result.add(runContentDescriptor);
    }
  }
  return result;
}
 
Example 19
Project: mybatis-log-plugin   File: TailContentExecutor.java   View source code 5 votes vote down vote up
@NotNull
private ActionGroup createActionToolbar(JComponent consolePanel, ConsoleView consoleView, @NotNull final RunnerLayoutUi myUi, RunContentDescriptor contentDescriptor, Executor runExecutorInstance) {
    final DefaultActionGroup actionGroup = new DefaultActionGroup();
    actionGroup.add(new FilterAction());
    actionGroup.add(new RerunAction(consolePanel, consoleView));
    actionGroup.add(new StopAction());
    actionGroup.add(new FormatAction());
    actionGroup.add(new MyCloseAction(runExecutorInstance, contentDescriptor, myProject));
    return actionGroup;
}
 
Example 20
Project: intellij-ce-playground   File: ExecutionManagerImpl.java   View source code 5 votes vote down vote up
@NotNull
private List<RunContentDescriptor> getRunningDescriptorsOfTheSameConfigType(@NotNull final RunnerAndConfigurationSettings configurationAndSettings) {
  return getRunningDescriptors(new Condition<RunnerAndConfigurationSettings>() {
    @Override
    public boolean value(@Nullable RunnerAndConfigurationSettings runningConfigurationAndSettings) {
      return configurationAndSettings == runningConfigurationAndSettings;
    }
  });
}
 
Example 21
Project: intellij-ce-playground   File: AndroidDebugRunner.java   View source code 5 votes vote down vote up
private static void setActivateToolWindowWhenAddedProperty(Project project,
                                                           Executor executor,
                                                           RunContentDescriptor descriptor,
                                                           String status) {
  final boolean activateToolWindow = shouldActivateExecWindow(project);
  descriptor.setActivateToolWindowWhenAdded(activateToolWindow);

  if (!activateToolWindow) {
    showNotification(project, executor, descriptor, status, false, NotificationType.INFORMATION);
  }
}
 
Example 22
Project: intellij-ce-playground   File: PyAbstractTestProcessRunner.java   View source code 5 votes vote down vote up
@Override
protected void fetchConsoleAndSetToField(@NotNull final RunContentDescriptor descriptor) {
  // Fetch test results from console
  myExecutionConsole = (SMTRunnerConsoleView)descriptor.getExecutionConsole();
  final JComponent component = myExecutionConsole.getComponent();
  assert component != null;
  myConsole = (ConsoleViewImpl)myExecutionConsole.getConsole();
  myTestProxy = myExecutionConsole.getResultsViewer().getTestsRootNode();
}
 
Example 23
Project: lua-for-idea   File: LuaRunner.java   View source code 5 votes vote down vote up
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    ExecutionResult executionResult = state.execute(env.getExecutor(), this);
    if (executionResult == null) return null;

    final RunContentBuilder contentBuilder = new RunContentBuilder(executionResult, env);
    return contentBuilder.showRunContent(env.getContentToReuse());
}
 
Example 24
Project: intellij-ce-playground   File: AndroidSessionInfo.java   View source code 5 votes vote down vote up
public AndroidSessionInfo(@NotNull RunContentDescriptor descriptor,
                          @NotNull AndroidExecutionState state,
                          @NotNull String executorId) {
  myDescriptor = descriptor;
  myState = state;
  myExecutorId = executorId;
}
 
Example 25
Project: intellij-ce-playground   File: FakeRerunAction.java   View source code 5 votes vote down vote up
@Nullable
protected ExecutionEnvironment getEnvironment(@NotNull AnActionEvent event) {
  ExecutionEnvironment environment = event.getData(LangDataKeys.EXECUTION_ENVIRONMENT);
  if (environment == null) {
    Project project = event.getProject();
    RunContentDescriptor contentDescriptor = project == null ? null : ExecutionManager.getInstance(project).getContentManager().getSelectedContent();
    if (contentDescriptor != null) {
      JComponent component = contentDescriptor.getComponent();
      if (component != null) {
        environment = LangDataKeys.EXECUTION_ENVIRONMENT.getData(DataManager.getInstance().getDataContext(component));
      }
    }
  }
  return environment;
}
 
Example 26
Project: RestoreSql   File: TailContentExecutor.java   View source code 5 votes vote down vote up
@NotNull
private ActionGroup createActionToolbar(JComponent consolePanel, ConsoleView consoleView, @NotNull final RunnerLayoutUi myUi, RunContentDescriptor contentDescriptor, Executor runExecutorInstance) {
    final DefaultActionGroup actionGroup = new DefaultActionGroup();
    actionGroup.add(new RerunAction(consolePanel, consoleView));
    actionGroup.add(new StopAction());
    actionGroup.add(new FormatAction());
    actionGroup.add(new MyCloseAction(runExecutorInstance, contentDescriptor, myProject));
    return actionGroup;
}
 
Example 27
Project: intellij-ce-playground   File: PythonConsoleToolWindow.java   View source code 5 votes vote down vote up
private static void setContent(ToolWindow toolWindow, RunContentDescriptor contentDescriptor) {
  toolWindow.getComponent().putClientProperty(ToolWindowContentUi.HIDE_ID_LABEL, "true");

  Content content = toolWindow.getContentManager().findContent(contentDescriptor.getDisplayName());
  if (content == null) {
    content = createContent(contentDescriptor);
    toolWindow.getContentManager().addContent(content);
  }
  else {
    SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true);
    resetContent(contentDescriptor, panel, content);
  }

  toolWindow.getContentManager().setSelectedContent(content);
}
 
Example 28
Project: intellij-ce-playground   File: PydevConsoleRunner.java   View source code 5 votes vote down vote up
@Override
protected List<AnAction> fillToolBarActions(final DefaultActionGroup toolbarActions,
                                            final Executor defaultExecutor,
                                            final RunContentDescriptor contentDescriptor) {
  AnAction backspaceHandlingAction = createBackspaceHandlingAction();
  //toolbarActions.add(backspaceHandlingAction);
  AnAction interruptAction = createInterruptAction();

  AnAction rerunAction = createRerunAction();
  toolbarActions.add(rerunAction);

  List<AnAction> actions = super.fillToolBarActions(toolbarActions, defaultExecutor, contentDescriptor);

  actions.add(0, rerunAction);

  actions.add(backspaceHandlingAction);
  actions.add(interruptAction);

  actions.add(createSplitLineAction());

  AnAction showVarsAction = new ShowVarsAction();
  toolbarActions.add(showVarsAction);
  toolbarActions.add(ConsoleHistoryController.getController(getConsoleView()).getBrowseHistory());

  toolbarActions.add(new ConnectDebuggerAction());

  toolbarActions.add(new NewConsoleAction());

  return actions;
}
 
Example 29
Project: intellij-ce-playground   File: ExecutionManagerImpl.java   View source code 5 votes vote down vote up
@NotNull
private List<RunContentDescriptor> getIncompatibleRunningDescriptors(@NotNull RunnerAndConfigurationSettings configurationAndSettings) {
  final RunConfiguration configurationToCheckCompatibility = configurationAndSettings.getConfiguration();
  return getRunningDescriptors(new Condition<RunnerAndConfigurationSettings>() {
    @Override
    public boolean value(@Nullable RunnerAndConfigurationSettings runningConfigurationAndSettings) {
      RunConfiguration runningConfiguration = runningConfigurationAndSettings == null ? null : runningConfigurationAndSettings.getConfiguration();
      if (runningConfiguration == null || !(runningConfiguration instanceof CompatibilityAwareRunProfile)) {
        return false;
      }
      return ((CompatibilityAwareRunProfile)runningConfiguration).mustBeStoppedToRun(configurationToCheckCompatibility);
    }
  });
}
 
Example 30
Project: intellij-ce-playground   File: DebuggerPanelsManager.java   View source code 5 votes vote down vote up
@Nullable
public RunContentDescriptor attachVirtualMachine(@NotNull ExecutionEnvironment environment,
                                                 RunProfileState state,
                                                 RemoteConnection remoteConnection,
                                                 boolean pollConnection) throws ExecutionException {
  return attachVirtualMachine(new DefaultDebugUIEnvironment(environment, state, remoteConnection, pollConnection));
}
 
Example 31
Project: intellij-ce-playground   File: DebuggerPanelsManager.java   View source code 5 votes vote down vote up
@Nullable
public RunContentDescriptor attachVirtualMachine(DebugUIEnvironment environment) throws ExecutionException {
  final DebugEnvironment modelEnvironment = environment.getEnvironment();
  final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(myProject).attachVirtualMachine(modelEnvironment);
  if (debuggerSession == null) {
    return null;
  }

  final DebugProcessImpl debugProcess = debuggerSession.getProcess();
  if (debugProcess.isDetached() || debugProcess.isDetaching()) {
    debuggerSession.dispose();
    return null;
  }
  if (modelEnvironment.isRemote()) {
    // optimization: that way BatchEvaluator will not try to lookup the class file in remote VM
    // which is an expensive operation when executed first time
    debugProcess.putUserData(BatchEvaluator.REMOTE_SESSION_KEY, Boolean.TRUE);
  }

  XDebugSession debugSession =
    XDebuggerManager.getInstance(myProject).startSessionAndShowTab(modelEnvironment.getSessionName(), environment.getReuseContent(), new XDebugProcessStarter() {
      @Override
      @NotNull
      public XDebugProcess start(@NotNull XDebugSession session) {
        return JavaDebugProcess.create(session, debuggerSession);
      }
    });
  return debugSession.getRunContentDescriptor();
}
 
Example 32
Project: intellij-ce-playground   File: DebuggerPanelsManager.java   View source code 5 votes vote down vote up
private static DebuggerSession getSession(Project project, RunContentDescriptor descriptor) {
  for (JavaDebugProcess process : XDebuggerManager.getInstance(project).getDebugProcesses(JavaDebugProcess.class)) {
    if (Comparing.equal(process.getProcessHandler(), descriptor.getProcessHandler())) {
      return process.getDebuggerSession();
    }
  }
  return null;
}
 
Example 33
Project: intellij-ce-playground   File: DefaultDebugUIEnvironment.java   View source code 5 votes vote down vote up
@Override
public void initActions(RunContentDescriptor content, DefaultActionGroup actionGroup) {
  Executor executor = myExecutionEnvironment.getExecutor();
  actionGroup.add(ActionManager.getInstance().getAction(IdeActions.ACTION_RERUN), Constraints.FIRST);

  actionGroup.add(new CloseAction(executor, content, myExecutionEnvironment.getProject()));
  actionGroup.add(new ContextHelpAction(executor.getHelpId()));
}
 
Example 34
Project: intellij-ce-playground   File: GenericDebuggerRunner.java   View source code 5 votes vote down vote up
@Nullable
protected RunContentDescriptor attachVirtualMachine(RunProfileState state,
                                                    @NotNull ExecutionEnvironment env,
                                                    RemoteConnection connection,
                                                    boolean pollConnection) throws ExecutionException {
  DebugEnvironment environment = new DefaultDebugEnvironment(env, state, connection, pollConnection);
  final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(env.getProject()).attachVirtualMachine(environment);
  if (debuggerSession == null) {
    return null;
  }

  final DebugProcessImpl debugProcess = debuggerSession.getProcess();
  if (debugProcess.isDetached() || debugProcess.isDetaching()) {
    debuggerSession.dispose();
    return null;
  }
  if (environment.isRemote()) {
    // optimization: that way BatchEvaluator will not try to lookup the class file in remote VM
    // which is an expensive operation when executed first time
    debugProcess.putUserData(BatchEvaluator.REMOTE_SESSION_KEY, Boolean.TRUE);
  }

  return XDebuggerManager.getInstance(env.getProject()).startSession(env, new XDebugProcessStarter() {
    @Override
    @NotNull
    public XDebugProcess start(@NotNull XDebugSession session) {
      XDebugSessionImpl sessionImpl = (XDebugSessionImpl)session;
      ExecutionResult executionResult = debugProcess.getExecutionResult();
      sessionImpl.addExtraActions(executionResult.getActions());
      if (executionResult instanceof DefaultExecutionResult) {
        sessionImpl.addRestartActions(((DefaultExecutionResult)executionResult).getRestartActions());
        sessionImpl.addExtraStopActions(((DefaultExecutionResult)executionResult).getAdditionalStopActions());
      }
      return JavaDebugProcess.create(session, debuggerSession);
    }
  }).getRunContentDescriptor();
}
 
Example 35
Project: intellij-ce-playground   File: JavaDebuggerLauncherImpl.java   View source code 5 votes vote down vote up
@Override
public void startDebugSession(@NotNull JavaDebugConnectionData info, @NotNull ExecutionEnvironment executionEnvironment, @NotNull RemoteServer<?> server)
  throws ExecutionException {
  final Project project = executionEnvironment.getProject();
  final DebuggerPanelsManager manager = DebuggerPanelsManager.getInstance(project);
  final JavaDebugServerModeHandler serverModeHandler = info.getServerModeHandler();
  boolean serverMode = serverModeHandler != null;
  final RemoteConnection remoteConnection = new RemoteConnection(true, info.getHost(), String.valueOf(info.getPort()), serverMode);
  DebugEnvironment debugEnvironment = new RemoteServerDebugEnvironment(project, remoteConnection, executionEnvironment.getRunProfile());
  DebugUIEnvironment debugUIEnvironment = new RemoteServerDebugUIEnvironment(debugEnvironment, executionEnvironment);
  RunContentDescriptor debugContentDescriptor = manager.attachVirtualMachine(debugUIEnvironment);
  LOG.assertTrue(debugContentDescriptor != null);
  ProcessHandler processHandler = debugContentDescriptor.getProcessHandler();
  LOG.assertTrue(processHandler != null);
  if (serverMode) {
    serverModeHandler.attachRemote();
    DebuggerManager.getInstance(executionEnvironment.getProject())
      .addDebugProcessListener(processHandler, new DebugProcessAdapter() {
        public void processDetached(DebugProcess process, boolean closedByUser) {
          try {
            serverModeHandler.detachRemote();
          }
          catch (ExecutionException e) {
            LOG.info(e);
          }
        }
      });
  }
}
 
Example 36
Project: intellij-ce-playground   File: AbstractConsoleRunnerWithHistory.java   View source code 5 votes vote down vote up
protected void createContentDescriptorAndActions() {
  final Executor defaultExecutor = DefaultRunExecutor.getRunExecutorInstance();
  final DefaultActionGroup toolbarActions = new DefaultActionGroup();
  final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, toolbarActions, false);

  // Runner creating
  final JPanel panel = new JPanel(new BorderLayout());
  panel.add(actionToolbar.getComponent(), BorderLayout.WEST);
  panel.add(myConsoleView.getComponent(), BorderLayout.CENTER);

  actionToolbar.setTargetComponent(panel);

  final RunContentDescriptor contentDescriptor =
    new RunContentDescriptor(myConsoleView, myProcessHandler, panel, constructConsoleTitle(myConsoleTitle));

  contentDescriptor.setFocusComputable(new Computable<JComponent>() {
    @Override
    public JComponent compute() {
      return getConsoleView().getConsoleEditor().getContentComponent();
    }
  });
  contentDescriptor.setAutoFocusContent(isAutoFocusContent());


  // tool bar actions
  final List<AnAction> actions = fillToolBarActions(toolbarActions, defaultExecutor, contentDescriptor);
  registerActionShortcuts(actions, getConsoleView().getConsoleEditor().getComponent());
  registerActionShortcuts(actions, panel);

  showConsole(defaultExecutor, contentDescriptor);
}
 
Example 37
Project: intellij-ce-playground   File: Tool.java   View source code 5 votes vote down vote up
public void execute(AnActionEvent event, DataContext dataContext, long executionId, @Nullable final ProcessListener processListener) {
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return;
  }

  FileDocumentManager.getInstance().saveAllDocuments();
  try {
    if (isUseConsole()) {
      ExecutionEnvironment environment = ExecutionEnvironmentBuilder.create(project,
                                                                            DefaultRunExecutor.getRunExecutorInstance(),
                                                                            new ToolRunProfile(this, dataContext)).build();
      environment.setExecutionId(executionId);
      environment.getRunner().execute(environment, new ProgramRunner.Callback() {
        @Override
        public void processStarted(RunContentDescriptor descriptor) {
          ProcessHandler processHandler = descriptor.getProcessHandler();
          if (processHandler != null && processListener != null) {
            processHandler.addProcessListener(processListener);
          }
        }
      });
    }
    else {
      GeneralCommandLine commandLine = createCommandLine(dataContext);
      if (commandLine == null) {
        return;
      }
      OSProcessHandler handler = new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString());
      handler.addProcessListener(new ToolProcessAdapter(project, synchronizeAfterExecution(), getName()));
      if (processListener != null) {
        handler.addProcessListener(processListener);
      }
      handler.startNotify();
    }
  }
  catch (ExecutionException ex) {
    ExecutionErrorDialog.show(ex, ToolsBundle.message("tools.process.start.error"), project);
  }
}
 
Example 38
Project: intellij-ce-playground   File: UnscrambleDialog.java   View source code 5 votes vote down vote up
@Nullable
static RunContentDescriptor showUnscrambledText(@Nullable UnscrambleSupport unscrambleSupport,
                                                String logName,
                                                Project project,
                                                String textToUnscramble) {
  String unscrambledTrace = unscrambleSupport == null ? textToUnscramble : unscrambleSupport.unscramble(project,textToUnscramble, logName);
  if (unscrambledTrace == null) return null;
  List<ThreadState> threadStates = ThreadDumpParser.parse(unscrambledTrace);
  return addConsole(project, threadStates, unscrambledTrace);
}
 
Example 39
Project: intellij-ce-playground   File: PythonRunner.java   View source code 5 votes vote down vote up
@Override
protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException {
  FileDocumentManager.getInstance().saveAllDocuments();

  ExecutionResult executionResult;
  RunProfile profile = env.getRunProfile();
  if (state instanceof PythonCommandLineState && profile instanceof CommandLinePatcher) {
    executionResult = ((PythonCommandLineState)state).execute(env.getExecutor(), (CommandLinePatcher)profile);
  }
  else {
    executionResult = state.execute(env.getExecutor(), this);
  }
  return executionResult == null ? null : new RunContentBuilder(executionResult, env).showRunContent(env.getContentToReuse());
}
 
Example 40
Project: intellij-ce-playground   File: PyOpenDebugConsoleAction.java   View source code 5 votes vote down vote up
private static Collection<RunContentDescriptor> getConsoles(Project project) {
  return ExecutionHelper.findRunningConsole(project, new NotNullFunction<RunContentDescriptor, Boolean>() {
    @NotNull
    @Override
    public Boolean fun(RunContentDescriptor dom) {
      return dom.getExecutionConsole() instanceof PythonDebugLanguageConsoleView && isAlive(dom);
    }
  });
}