void (@NotNull Object buildId, @NotNull BuildEvent event) { List<Runnable> runOnEdt = new SmartList<>(); AbstractViewManager.BuildInfo buildInfo; if (event instanceof StartBuildEvent startBuildEvent) { if (isInitializeStarted.get()) { clearOldBuilds(runOnEdt, startBuildEvent); } buildInfo = new AbstractViewManager.BuildInfo(((StartBuildEvent)event).getBuildDescriptor()); myBuildsMap.put(buildId, buildInfo); } else { buildInfo = myBuildsMap.get(buildId); } if (buildInfo == null) { LOG.warn("Build can not be found for buildId: '" + buildId + "'"); return; } runOnEdt.add(() -> { if (event instanceof StartBuildEvent) { buildInfo.message = event.getMessage(); DefaultListModel<AbstractViewManager.BuildInfo> listModel = (DefaultListModel<AbstractViewManager.BuildInfo>)myBuildsList.getModel(); listModel.addElement(buildInfo); RunContentDescriptor contentDescriptor; Supplier<? extends RunContentDescriptor> contentDescriptorSupplier = buildInfo.getContentDescriptorSupplier(); contentDescriptor = contentDescriptorSupplier != null ? contentDescriptorSupplier.get() : null; final Runnable activationCallback; if (contentDescriptor != null) { buildInfo.setActivateToolWindowWhenAdded(contentDescriptor.isActivateToolWindowWhenAdded()); if (contentDescriptor instanceof BuildContentDescriptor) { buildInfo.setNavigateToError(((BuildContentDescriptor)contentDescriptor).isNavigateToError()); buildInfo.setActivateToolWindowWhenFailed(((BuildContentDescriptor)contentDescriptor).isActivateToolWindowWhenFailed()); } buildInfo.setAutoFocusContent(contentDescriptor.isAutoFocusContent()); activationCallback = contentDescriptor.getActivationCallback(); } else { activationCallback = null; } BuildView view = myViewMap.computeIfAbsent(buildInfo, info -> { String selectionStateKey = "build.toolwindow." + myViewManager.getViewName() + ".selection.state"; BuildView buildView = new BuildView(myProject, buildInfo, selectionStateKey, myViewManager); Disposer.register(this, buildView); if (contentDescriptor != null) { Disposer.register(buildView, contentDescriptor); } return buildView; }); view.onEvent(buildId, event); myBuildContentManager.setSelectedContent(myContent, buildInfo.isAutoFocusContent(), buildInfo.isAutoFocusContent(), buildInfo.isActivateToolWindowWhenAdded(), activationCallback); buildInfo.content = myContent; if (myActiveView == null) { setActiveView(view); } if (myBuildsList.getModel().getSize() > 1) { JBScrollPane scrollPane = new JBScrollPane(); scrollPane.setBorder(JBUI.Borders.empty()); scrollPane.setViewportView(myBuildsList); myThreeComponentsSplitter.setFirstComponent(scrollPane); myBuildsList.setVisible(true); myBuildsList.setSelectedIndex(0); for (BuildView consoleView : myViewMap.values()) { BuildTreeConsoleView buildConsoleView = consoleView.getView(BuildTreeConsoleView.class.getName(), BuildTreeConsoleView.class); if (buildConsoleView != null) { buildConsoleView.hideRootNode(); } } } else { myThreeComponentsSplitter.setFirstComponent(null); } myViewManager.onBuildStart(buildInfo); myProgressWatcher.addBuild(buildInfo); ((BuildContentManagerImpl)myBuildContentManager).startBuildNotified(buildInfo, buildInfo.content, buildInfo.getProcessHandler()); } else { if (!isFirstErrorShown.get() && (event instanceof FinishEvent && ((FinishEvent)event).getResult() instanceof FailureResult) || (event instanceof MessageEvent && ((MessageEvent)event).getResult().getKind() == MessageEvent.Kind.ERROR)) { if (isFirstErrorShown.compareAndSet(false, true)) { ListModel<AbstractViewManager.BuildInfo> listModel = myBuildsList.getModel(); IntStream.range(0, listModel.getSize()) .filter(i -> buildInfo == listModel.getElementAt(i)) .findFirst() .ifPresent(myBuildsList::setSelectedIndex); } } BuildView view = myViewMap.get(buildInfo); if (view != null) { view.onEvent(buildId, event); } if (event instanceof FinishBuildEvent) { buildInfo.endTime = event.getEventTime(); buildInfo.message = event.getMessage(); buildInfo.result = ((FinishBuildEvent)event).getResult(); myProgressWatcher.stopBuild(buildInfo); ((BuildContentManagerImpl)myBuildContentManager).finishBuildNotified(buildInfo, buildInfo.content); myViewManager.onBuildFinish(buildInfo); } else { buildInfo.statusMessage = event.getMessage(); } } }); if (myContent == null) { myPostponedRunnables.addAll(runOnEdt); if (isInitializeStarted.compareAndSet(false, true)) { EdtExecutorService.getInstance().execute(() -> { if (myDisposed) return; myBuildsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myBuildsList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { AbstractViewManager.BuildInfo selectedBuild = myBuildsList.getSelectedValue(); if (selectedBuild == null) return; setActiveView(myViewMap.get(selectedBuild)); } }); final JComponent consoleComponent = new MultipleBuildsPanel(); consoleComponent.add(myThreeComponentsSplitter, BorderLayout.CENTER); myToolbarActions = new DefaultActionGroup(); ActionToolbar tb = ActionManager.getInstance().createActionToolbar("BuildView", myToolbarActions, false); tb.setTargetComponent(consoleComponent); tb.getComponent().setBorder(JBUI.Borders.merge(tb.getComponent().getBorder(), JBUI.Borders.customLine(OnePixelDivider.BACKGROUND, 0, 0, 0, 1), true)); consoleComponent.add(tb.getComponent(), BorderLayout.WEST); myContent = new ContentImpl(consoleComponent, myViewManager.getViewName(), true) { @Override public void dispose() { super.dispose(); Disposer.dispose(MultipleBuildsView.this); myViewManager.onBuildsViewRemove(MultipleBuildsView.this); } }; Icon contentIcon = myViewManager.getContentIcon(); if (contentIcon != null) { myContent.setIcon(contentIcon); myContent.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE); } myBuildContentManager.addContent(myContent); List<Runnable> postponedRunnables = new ArrayList<>(myPostponedRunnables); myPostponedRunnables.clear(); for (Runnable postponedRunnable : postponedRunnables) { postponedRunnable.run(); } }); } } else { EdtExecutorService.getInstance().execute(() -> { if (myDisposed) return; for (Runnable runnable : runOnEdt) { runnable.run(); } }); } }