use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class Tool method execute.
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) {
LOG.assertTrue(!processHandler.isStartNotified(), "ProcessHandler is already startNotified, the listener won't be correctly notified");
processHandler.addProcessListener(processListener);
}
}
});
} else {
GeneralCommandLine commandLine = createCommandLine(dataContext);
if (commandLine == null) {
return;
}
OSProcessHandler handler = new OSProcessHandler(commandLine);
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);
}
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class RunContentExecutor method createConsole.
private ConsoleView createConsole() {
TextConsoleBuilder consoleBuilder = TextConsoleBuilderFactory.getInstance().createBuilder(myProject);
consoleBuilder.filters(myFilterList);
final ConsoleView console = consoleBuilder.getConsole();
if (myHelpId != null) {
console.setHelpId(myHelpId);
}
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
DefaultActionGroup actions = new DefaultActionGroup();
final JComponent consolePanel = createConsolePanel(console, actions);
RunContentDescriptor descriptor = new RunContentDescriptor(console, myProcess, consolePanel, myTitle);
Disposer.register(descriptor, this);
Disposer.register(descriptor, console);
actions.add(new RerunAction(consolePanel));
actions.add(new StopAction());
actions.add(new CloseAction(executor, descriptor, myProject));
ExecutionManager.getInstance(myProject).getContentManager().showRunContent(executor, descriptor);
if (myActivateToolWindow) {
activateToolWindow();
}
return console;
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class RunIdeConsoleAction method getConsoleView.
@NotNull
private static RunContentDescriptor getConsoleView(@NotNull Project project, @NotNull VirtualFile file) {
PsiFile psiFile = ObjectUtils.assertNotNull(PsiManager.getInstance(project).findFile(file));
WeakReference<RunContentDescriptor> ref = psiFile.getCopyableUserData(DESCRIPTOR_KEY);
RunContentDescriptor descriptor = ref == null ? null : ref.get();
if (descriptor == null || descriptor.getExecutionConsole() == null) {
descriptor = createConsoleView(project, psiFile);
psiFile.putCopyableUserData(DESCRIPTOR_KEY, new WeakReference<>(descriptor));
}
return descriptor;
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class RunIdeConsoleAction method createConsoleView.
@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;
}
use of com.intellij.execution.ui.RunContentDescriptor in project intellij-community by JetBrains.
the class ExecutionHelper method selectContentDescriptor.
public static void selectContentDescriptor(@NotNull final DataContext dataContext, @NotNull final Project project, @NotNull Collection<RunContentDescriptor> consoles, String selectDialogTitle, final Consumer<RunContentDescriptor> descriptorConsumer) {
if (consoles.size() == 1) {
RunContentDescriptor descriptor = consoles.iterator().next();
descriptorConsumer.consume(descriptor);
descriptorToFront(project, descriptor);
} else if (consoles.size() > 1) {
final JList list = new JBList(consoles);
final Icon icon = DefaultRunExecutor.getRunExecutorInstance().getIcon();
list.setCellRenderer(new ListCellRendererWrapper<RunContentDescriptor>() {
@Override
public void customize(final JList list, final RunContentDescriptor value, final int index, final boolean selected, final boolean hasFocus) {
setText(value.getDisplayName());
setIcon(icon);
}
});
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
builder.setTitle(selectDialogTitle);
builder.setItemChoosenCallback(() -> {
final Object selectedValue = list.getSelectedValue();
if (selectedValue instanceof RunContentDescriptor) {
RunContentDescriptor descriptor = (RunContentDescriptor) selectedValue;
descriptorConsumer.consume(descriptor);
descriptorToFront(project, descriptor);
}
}).createPopup().showInBestPositionFor(dataContext);
}
}
Aggregations