@Nullable public RunContentDescriptor getSelectedContent() { for (String activeWindow : myToolwindowIdZbuffer) { final ContentManager contentManager = myToolwindowIdToContentManagerMap.get(activeWindow); if (contentManager == null) { continue; } final Content selectedContent = contentManager.getSelectedContent(); if (selectedContent == null) { if (contentManager.getContentCount() == 0) { // continue to the next window if the content manager is empty continue; } else { // stop iteration over windows because there is some content in the window and the window // is the last used one break; } } // here we have selected content return getRunContentDescriptorByContent(selectedContent); } return null; }
public int addTab( String s, JComponent component, boolean selectTab, boolean replaceContent, boolean lockable, boolean addDefaultToolbar, ActionGroup toolbarActions, String helpId) { int existing = getComponentNumNamed(s); ContentManager contentManager = getContentManager(); if (existing != -1) { Content existingContent = contentManager.getContent(existing); if (!replaceContent) { contentManager.setSelectedContent(existingContent); return existing; } // if (!existingContent.isPinned()) { // getContentManager().removeContent(existingContent); // existingContent.release(); // } } CommitLogWindowComponent newComponent = new CommitLogWindowComponent( component, addDefaultToolbar, toolbarActions, contentManager, helpId); Content content = ContentFactory.SERVICE .getInstance() .createContent(newComponent.getShownComponent(), s, lockable); newComponent.setContent(content); contentManager.addContent(content); return getComponentAt(contentManager.getContentCount() - 1, selectTab); }
private void initialize() { if (myIsInitialized) { return; } myIsInitialized = true; myIsDisposed = false; myContentManager = ContentFactory.SERVICE.getInstance().createContentManager(true, myProject); myContentManager.addContentManagerListener( new ContentManagerAdapter() { public void contentRemoved(ContentManagerEvent event) { JComponent component = event.getContent().getComponent(); JComponent removedComponent = component instanceof CvsTabbedWindowComponent ? ((CvsTabbedWindowComponent) component).getComponent() : component; if (removedComponent == myErrorsView) { myErrorsView.dispose(); myErrorsView = null; } else if (myOutput != null && removedComponent == myOutput.getComponent()) { EditorFactory.getInstance().releaseEditor(myOutput); myOutput = null; } } }); ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject); ToolWindow toolWindow = toolWindowManager.registerToolWindow( ToolWindowId.CVS, myContentManager.getComponent(), ToolWindowAnchor.BOTTOM); toolWindow.setIcon(AllIcons.Providers.Cvs); toolWindow.installWatcher(myContentManager); }
private void registerToolwindow(@NotNull final Executor executor) { final String toolWindowId = executor.getToolWindowId(); final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject); if (toolWindowManager == null) return; // headless environment if (toolWindowManager.getToolWindow(toolWindowId) != null) { return; } final ToolWindow toolWindow = toolWindowManager.registerToolWindow( toolWindowId, true, ToolWindowAnchor.BOTTOM, this, true); final ContentManager contentManager = toolWindow.getContentManager(); class MyDataProvider implements DataProvider { private int myInsideGetData = 0; public Object getData(String dataId) { myInsideGetData++; try { if (PlatformDataKeys.HELP_ID.is(dataId)) { return executor.getHelpId(); } else { return myInsideGetData == 1 ? DataManager.getInstance() .getDataContext(contentManager.getComponent()) .getData(dataId) : null; } } finally { myInsideGetData--; } } } contentManager.addDataProvider(new MyDataProvider()); toolWindow.setIcon(executor.getToolWindowIcon()); new ContentManagerWatcher(toolWindow, contentManager); contentManager.addContentManagerListener( new ContentManagerAdapter() { public void selectionChanged(final ContentManagerEvent event) { final Content content = event.getContent(); final RunContentDescriptor descriptor = content != null ? getRunContentDescriptorByContent(content) : null; getSyncPublisher().contentSelected(descriptor, executor); } }); myToolwindowIdToContentManagerMap.put(toolWindowId, contentManager); Disposer.register( contentManager, new Disposable() { public void dispose() { unregisterToolwindow(toolWindowId); } }); myToolwindowIdZbuffer.addLast(toolWindowId); }
@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; }
@Nullable public RunContentDescriptor getSelectedContent(final Executor executor) { final ContentManager contentManager = getContentManagerForRunner(executor); if (contentManager != null) { final Content selectedContent = contentManager.getSelectedContent(); if (selectedContent != null) { final RunContentDescriptor runContentDescriptorByContent = getRunContentDescriptorByContent(selectedContent); if (runContentDescriptorByContent != null) { return runContentDescriptorByContent; } } } return null; }
@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 CloseListener(Content content, ContentManager contentManager, Project project) { myContent = content; myContentManager = contentManager; myProject = project; contentManager.addContentManagerListener(this); ProjectManager.getInstance().addProjectManagerListener(myProject, this); }
public RunContentDescriptor[] getAllDescriptors() { final List<RunContentDescriptor> descriptors = new ArrayList<RunContentDescriptor>(); final String[] ids = myToolwindowIdToContentManagerMap .keySet() .toArray(new String[myToolwindowIdToContentManagerMap.size()]); for (String id : ids) { final ContentManager contentManager = myToolwindowIdToContentManagerMap.get(id); final Content[] contents = contentManager.getContents(); for (final Content content : contents) { final RunContentDescriptor descriptor = getRunContentDescriptorByContent(content); if (descriptor != null) { descriptors.add(descriptor); } } } return descriptors.toArray(new RunContentDescriptor[descriptors.size()]); }
@Nullable public RunContentDescriptor getSelectedContent() { final String activeWindow = myToolwindowIdZbuffer.isEmpty() ? null : myToolwindowIdZbuffer.getFirst(); if (activeWindow != null) { final ContentManager contentManager = myToolwindowIdToContentManagerMap.get(activeWindow); if (contentManager != null) { final Content selectedContent = contentManager.getSelectedContent(); if (selectedContent != null) { final RunContentDescriptor runContentDescriptorByContent = getRunContentDescriptorByContent(selectedContent); if (runContentDescriptorByContent != null) { return runContentDescriptorByContent; } } } } return null; }
@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; }
@NotNull public List<RunContentDescriptor> getAllDescriptors() { if (myToolwindowIdToContentManagerMap.isEmpty()) { return Collections.emptyList(); } final String[] ids = myToolwindowIdToContentManagerMap .keySet() .toArray(new String[myToolwindowIdToContentManagerMap.size()]); final List<RunContentDescriptor> descriptors = new ArrayList<RunContentDescriptor>(); for (String id : ids) { final ContentManager contentManager = myToolwindowIdToContentManagerMap.get(id); for (final Content content : contentManager.getContents()) { final RunContentDescriptor descriptor = getRunContentDescriptorByContent(content); if (descriptor != null) { descriptors.add(descriptor); } } } return descriptors; }
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; }
public PanelWithActionsAndCloseButton( ContentManager contentManager, @NonNls String helpId, final boolean verticalToolbar) { super(new BorderLayout()); myContentManager = contentManager; myHelpId = helpId; myVerticalToolbar = verticalToolbar; myCloseEnabled = true; if (myContentManager != null) { myContentManager.addContentManagerListener( new ContentManagerAdapter() { public void contentRemoved(ContentManagerEvent event) { if (event.getContent().getComponent() == PanelWithActionsAndCloseButton.this) { dispose(); myContentManager.removeContentManagerListener(this); } } }); } }
@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; } }
private void initialize() { if (!_isInitialized) { _isInitialized = true; _isDisposed = false; ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(_project); ToolWindow toolWindow = toolWindowManager.registerToolWindow( COMMIT_LOGS_TOOLWINDOW_ID, true, ToolWindowAnchor.BOTTOM); toolWindow.setIcon(COMMIT_LOGS_SMALL_ICON); _contentManager = toolWindow.getContentManager(); toolWindow.installWatcher(_contentManager); // _contentManager = // PeerFactory.getInstance().getContentFactory().createContentManager(true, _project); _contentManager.addContentManagerListener( new ContentManagerAdapter() { @Override public void contentRemoved(ContentManagerEvent event) { JComponent component = event.getContent().getComponent(); JComponent removedComponent = (component instanceof CommitLogWindowComponent) ? ((CommitLogWindowComponent) component).getComponent() : component; // if (removedComponent == myErrorsView) { // myErrorsView.dispose(); // myErrorsView = null; // } else for (Iterator iterator = _commitLogs.iterator(); iterator.hasNext(); ) { Editor editor = (Editor) iterator.next(); if (removedComponent == editor.getComponent()) { EditorFactory.getInstance().releaseEditor(editor); iterator.remove(); } } } }); // final JComponent component = _contentManager.getComponent(); } }
public void setContent(Content content, ContentManager contentManager) { myContent = content; myContentManager = contentManager; contentManager.addContentManagerListener(this); }
@Override public void projectClosed(Project project) { if (project.equals(myProject) && myContent != null) { myContentManager.removeContent(myContent, true); } }
public void projectClosed(Project project) { if (myContent != null) { myContentManager.removeContent(myContent, true); } }
public boolean removeRunContent( @NotNull final Executor executor, final RunContentDescriptor descriptor) { final ContentManager contentManager = getContentManagerForRunner(executor); final Content content = getRunContentByDescriptor(contentManager, descriptor); return content != null && contentManager.removeContent(content, true); }
private void unregisterToolwindow(final String id) { final ContentManager manager = myToolwindowIdToContentManagerMap.get(id); manager.removeAllContents(true); myToolwindowIdToContentManagerMap.remove(id); myToolwindowIdZbuffer.remove(id); }