private void removeAllContents(Project project, Content notRemove) { if (project.isDisposed()) { return; } final MessageView messageView = MessageView.SERVICE.getInstance(project); Content[] contents = messageView.getContentManager().getContents(); for (Content content : contents) { if (content.isPinned()) { continue; } if (content == notRemove) { continue; } boolean toRemove = CONTENT_ID_KEY.get(content) == myContentId; if (!toRemove) { final Object contentSessionId = SESSION_ID_KEY.get(content); toRemove = contentSessionId != null && contentSessionId != mySessionId; // the content was added by previous compilation } if (toRemove) { messageView.getContentManager().removeContent(content, true); } } }
@Nullable private static RunContentDescriptor chooseReuseContentForDescriptor( final ContentManager contentManager, final RunContentDescriptor descriptor) { Content content = null; if (descriptor != null) { if (descriptor.isContentReuseProhibited()) { return null; } final Content attachedContent = descriptor.getAttachedContent(); if (attachedContent != null && attachedContent.isValid()) content = attachedContent; } if (content == null) { content = contentManager.getSelectedContent(); if (content != null && content.isPinned()) content = null; } if (content == null || !isTerminated(content)) { return null; } final RunContentDescriptor oldDescriptor = getRunContentDescriptorByContent(content); if (oldDescriptor != null && !oldDescriptor.isContentReuseProhibited()) { return oldDescriptor; } return null; }
private void close() { MessageView messageView = MessageView.SERVICE.getInstance(myProject); Content[] contents = messageView.getContentManager().getContents(); for (Content content : contents) { if (content.getComponent() == this) { messageView.getContentManager().removeContent(content, true); return; } } }
private int getComponentNumNamed(String s) { for (int i = 0; i < getContentManager().getContentCount(); i++) { final Content content = getContentManager().getContent(i); if (content != null && s.equals(content.getDisplayName())) { return i; } } return -1; }
@Nullable private static Content getRunContentByDescriptor( final ContentManager contentManager, final RunContentDescriptor descriptor) { final Content[] contents = contentManager.getContents(); for (final Content content : contents) { if (descriptor.equals(content.getUserData(DESCRIPTOR_KEY))) { return content; } } return null; }
@Nullable private RunContentDescriptor getDescriptorBy(ProcessHandler handler, Executor runnerInfo) { ContentManager contentManager = getContentManagerForRunner(runnerInfo); Content[] contents = contentManager.getContents(); for (Content content : contents) { RunContentDescriptor runContentDescriptor = content.getUserData(DESCRIPTOR_KEY); if (runContentDescriptor.getProcessHandler() == handler) { return runContentDescriptor; } } return null; }
public void showRunContent( @NotNull final Executor info, RunContentDescriptor descriptor, RunContentDescriptor contentToReuse) { if (contentToReuse != null) { final Content attachedContent = contentToReuse.getAttachedContent(); if (attachedContent.getManager() != null) { descriptor.setAttachedContent(attachedContent); } } showRunContent(info, descriptor); }
public void contentRemoved(ContentManagerEvent event) { if (event.getContent() == myContent) { myContentManager.removeContentManagerListener(this); AntBuildMessageView buildMessageView = myContent.getUserData(KEY); if (!myCloseAllowed) { buildMessageView.stopProcess(); } ProjectManager.getInstance().removeProjectManagerListener(myProject, this); myContent.release(); myContent = null; buildMessageView.myBuildFile = null; buildMessageView.myPlainTextView.dispose(); } }
private Content createNewContent( final ContentManager contentManager, final RunContentDescriptor descriptor, Executor executor) { final String processDisplayName = descriptor.getDisplayName(); final Content content = ContentFactory.SERVICE .getInstance() .createContent(descriptor.getComponent(), processDisplayName, true); content.putUserData(DESCRIPTOR_KEY, descriptor); content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE); contentManager.addContent(content); new CloseListener(content, executor); return content; }
/** @return true if content can be closed */ private boolean closeQuery() { if (myContent == null) { return true; } AntBuildMessageView messageView = myContent.getUserData(KEY); if (messageView.isStoppedOrTerminateRequested()) { return true; } if (myCloseAllowed) return true; int result = Messages.showYesNoCancelDialog( AntBundle.message("ant.process.is.active.terminate.confirmation.text"), AntBundle.message("close.ant.build.messages.dialog.title"), Messages.getQuestionIcon()); if (result == 0) { // yes messageView.stopProcess(); myCloseAllowed = true; return true; } if (result == 1) { // no // close content and leave the process running myCloseAllowed = true; return true; } return false; }
public void actionPerformed(AnActionEvent e) { if (myContentManager != null) { Content content = myContentManager.getContent(PanelWithActionsAndCloseButton.this); if (content != null) { ContentsUtil.closeContentTab(myContentManager, content); if (content instanceof TabbedContent && ((TabbedContent) content).getTabs().size() > 1) { final TabbedContent tabbedContent = (TabbedContent) content; final JComponent component = content.getComponent(); tabbedContent.removeContent(component); myContentManager.setSelectedContent( content, true, true); // we should request focus here } else { myContentManager.removeContent(content, true); } } } }
private void dispose() { if (myContent == null) return; final Content content = myContent; try { final RunContentDescriptor descriptor = getRunContentDescriptorByContent(content); getSyncPublisher().contentRemoved(descriptor, myExecutor); descriptor.dispose(); } finally { content.getManager().removeContentManagerListener(this); ProjectManager.getInstance().removeProjectManagerListener(this); content .release(); // don't invoke myContent.release() because myContent becomes null after // destroyProcess() myContent = null; } }
public boolean canCloseProject(final Project project) { if (project != myProject) return true; if (myContent == null) return true; final boolean canClose = closeQuery(); if (canClose) { myContent.getManager().removeContent(myContent, true); myContent = null; } return canClose; }
public int addTab( String s, JComponent component, boolean selectTab, boolean replaceContent, boolean lockable, boolean addDefaultToolbar, @Nullable final ActionGroup toolbarActions, @NonNls String helpId) { int existing = getComponentNumNamed(s); if (existing != -1) { Content existingContent = getContentManager().getContent(existing); final JComponent existingComponent = existingContent.getComponent(); if (existingComponent instanceof DeactivateListener) { ((DeactivateListener) existingComponent).deactivated(); } if (!replaceContent) { getContentManager().setSelectedContent(existingContent); return existing; } else if (!existingContent.isPinned()) { getContentManager().removeContent(existingContent, true); existingContent.release(); } } CvsTabbedWindowComponent newComponent = new CvsTabbedWindowComponent( component, addDefaultToolbar, toolbarActions, getContentManager(), helpId); Content content = ContentFactory.SERVICE .getInstance() .createContent(newComponent.getShownComponent(), s, lockable); newComponent.setContent(content); getContentManager().addContent(content); return getComponentAt(getContentManager().getContentCount() - 1, selectTab); }
@Override public void contentRemoved(ContentManagerEvent event) { if (event.getContent() == myContent) { synchronized (myMessageViewLock) { if (myErrorTreeView != null) { myErrorTreeView.dispose(); myErrorTreeView = null; if (myIndicator.isRunning()) { cancel(); } if (AppIcon.getInstance().hideProgress(myProject, "compiler")) { AppIcon.getInstance().setErrorBadge(myProject, null); } } } myContentManager.removeContentManagerListener(this); myContent.release(); myContent = null; } }
public static RunContentDescriptor getRunContentDescriptorByContent(final Content content) { return content.getUserData(DESCRIPTOR_KEY); }
/** @return can be null if user cancelled operation */ @Nullable public static AntBuildMessageView openBuildMessageView( Project project, AntBuildFileBase buildFile, String[] targets) { final VirtualFile antFile = buildFile.getVirtualFile(); if (!LOG.assertTrue(antFile != null)) { return null; } // check if there are running instances of the same build file MessageView ijMessageView = MessageView.SERVICE.getInstance(project); Content[] contents = ijMessageView.getContentManager().getContents(); for (Content content : contents) { if (content.isPinned()) { continue; } AntBuildMessageView buildMessageView = content.getUserData(KEY); if (buildMessageView == null) { continue; } if (!antFile.equals(buildMessageView.getBuildFile().getVirtualFile())) { continue; } if (buildMessageView.isStopped()) { ijMessageView.getContentManager().removeContent(content, true); continue; } int result = Messages.showYesNoCancelDialog( AntBundle.message("ant.is.active.terminate.confirmation.text"), AntBundle.message("starting.ant.build.dialog.title"), Messages.getQuestionIcon()); switch (result) { case 0: // yes buildMessageView.stopProcess(); ijMessageView.getContentManager().removeContent(content, true); continue; case 1: // no continue; default: // cancel return null; } } final AntBuildMessageView messageView = new AntBuildMessageView(project, buildFile, targets); String contentName = buildFile.getPresentableName(); contentName = BUILD_CONTENT_NAME + " (" + contentName + ")"; final Content content = ContentFactory.SERVICE .getInstance() .createContent(messageView.getComponent(), contentName, true); content.putUserData(KEY, messageView); ijMessageView.getContentManager().addContent(content); ijMessageView.getContentManager().setSelectedContent(content); content.setDisposer( new Disposable() { @Override public void dispose() { Disposer.dispose(messageView.myAlarm); } }); new CloseListener(content, ijMessageView.getContentManager(), project); // Do not inline next two variabled. Seeking for NPE. ToolWindow messageToolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW); messageToolWindow.activate(null, false); return messageView; }
public void showRunContent( @NotNull final Executor executor, final RunContentDescriptor descriptor) { if (ApplicationManager.getApplication().isUnitTestMode()) return; final ContentManager contentManager = getContentManagerForRunner(executor); RunContentDescriptor oldDescriptor = chooseReuseContentForDescriptor(contentManager, descriptor); final Content content; if (oldDescriptor != null) { content = oldDescriptor.getAttachedContent(); getSyncPublisher().contentRemoved(oldDescriptor, executor); oldDescriptor.dispose(); // is of the same category, can be reused } else { content = createNewContent(contentManager, descriptor, executor); final Icon icon = descriptor.getIcon(); content.setIcon(icon == null ? executor.getToolWindowIcon() : icon); } content.setComponent(descriptor.getComponent()); content.putUserData(DESCRIPTOR_KEY, descriptor); final ProcessHandler processHandler = descriptor.getProcessHandler(); if (processHandler != null) { final ProcessAdapter processAdapter = new ProcessAdapter() { public void startNotified(final ProcessEvent event) { LaterInvocator.invokeLater( new Runnable() { public void run() { final Icon icon = descriptor.getIcon(); content.setIcon(icon == null ? executor.getToolWindowIcon() : icon); } }); } public void processTerminated(final ProcessEvent event) { LaterInvocator.invokeLater( new Runnable() { public void run() { final Icon icon = descriptor.getIcon(); content.setIcon( icon == null ? executor.getDisabledIcon() : IconLoader.getTransparentIcon(icon)); } }); } }; processHandler.addProcessListener(processAdapter); final Disposable disposer = content.getDisposer(); if (disposer != null) { Disposer.register( disposer, new Disposable() { public void dispose() { processHandler.removeProcessListener(processAdapter); } }); } } content.setDisplayName(descriptor.getDisplayName()); descriptor.setAttachedContent(content); content.getManager().setSelectedContent(content); ApplicationManager.getApplication() .invokeLater( new Runnable() { public void run() { ToolWindow window = ToolWindowManager.getInstance(myProject) .getToolWindow(executor.getToolWindowId()); // let's activate tool window, but don't move focus // // window.show() isn't valid here, because it will not // mark the window as "last activated" windows and thus // some action like navigation up/down in stactrace wont // work correctly window.activate(null, false, false); } }); }
public void projectClosed(final Project project) { if (myContent != null && project == myProject) { myContent.getManager().removeContent(myContent, true); dispose(); // Dispose content even if content manager refused to. } }
private CloseListener(@NotNull final Content content, @NotNull Executor executor) { myContent = content; content.getManager().addContentManagerListener(this); ProjectManager.getInstance().addProjectManagerListener(this); myExecutor = executor; }