@SuppressWarnings("unchecked") @Nullable public static <T> T getToolWindowElement( @NotNull Class<T> clazz, @NotNull Project project, @NotNull DataKey<T> key, @NotNull ProjectSystemId externalSystemId) { if (project.isDisposed() || !project.isOpen()) { return null; } final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); if (toolWindowManager == null) { return null; } final ToolWindow toolWindow = ensureToolWindowContentInitialized(project, externalSystemId); if (toolWindow == null) { return null; } final ContentManager contentManager = toolWindow.getContentManager(); if (contentManager == null) { return null; } for (Content content : contentManager.getContents()) { final JComponent component = content.getComponent(); if (component instanceof DataProvider) { final Object data = ((DataProvider) component).getData(key.getName()); if (data != null && clazz.isInstance(data)) { return (T) data; } } } return null; }
private Content getOrCreateConsoleContent(final ContentManager contentManager) { final String displayName = VcsBundle.message("vcs.console.toolwindow.display.name"); Content content = contentManager.findContent(displayName); if (content == null) { releaseEditor(); final EditorFactory editorFactory = EditorFactory.getInstance(); final Editor editor = editorFactory.createViewer(editorFactory.createDocument(""), myProject); EditorSettings editorSettings = editor.getSettings(); editorSettings.setLineMarkerAreaShown(false); editorSettings.setIndentGuidesShown(false); editorSettings.setLineNumbersShown(false); editorSettings.setFoldingOutlineShown(false); ((EditorEx) editor).getScrollPane().setBorder(null); myEditorAdapter = new EditorAdapter(editor, myProject, false); final JPanel panel = new JPanel(new BorderLayout()); panel.add(editor.getComponent(), BorderLayout.CENTER); content = ContentFactory.SERVICE.getInstance().createContent(panel, displayName, true); contentManager.addContent(content); for (Pair<String, TextAttributes> pair : myPendingOutput) { myEditorAdapter.appendString(pair.first, pair.second); } myPendingOutput.clear(); } return content; }
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); }
@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; }
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); }
@Nullable public static GradleProjectStructureTreeModel getProjectStructureTreeModel( @NotNull Project project) { final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); final ToolWindow toolWindow = toolWindowManager.getToolWindow(GradleConstants.TOOL_WINDOW_ID); if (toolWindow == null) { return null; } final ContentManager contentManager = toolWindow.getContentManager(); if (contentManager == null) { return null; } for (Content content : contentManager.getContents()) { final JComponent component = content.getComponent(); if (component instanceof DataProvider) { final Object data = ((DataProvider) component).getData(GradleDataKeys.SYNC_TREE_MODEL.getName()); if (data instanceof GradleProjectStructureTreeModel) { return (GradleProjectStructureTreeModel) data; } } } return null; }
@Override public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) { AntExplorer explorer = new AntExplorer(project); final ContentManager contentManager = toolWindow.getContentManager(); final Content content = contentManager.getFactory().createContent(explorer, null, false); contentManager.addContent(content); Disposer.register(project, explorer); }
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); }
public void setup(ToolWindowEx toolWindow) { ContentManager contentManager = toolWindow.getContentManager(); Content content = contentManager .getFactory() .createContent(new Symfony2WebProfilerForm(this.project).createComponent(), null, true); contentManager.addContent(content); contentManager.setSelectedContent(content, true); }
/** @return selected content or <code>null</code> */ @Nullable private static Content getContent(final DataContext context) { Content[] contents = ViewContext.CONTENT_KEY.getData(context); if (contents != null && contents.length == 1) return contents[0]; ContentManager contentManager = ContentManagerUtil.getContentManagerFromContext(context, true); if (contentManager == null) { return null; } return contentManager.getSelectedContent(); }
@Override public void createToolWindowContent(Project project, ToolWindow toolWindow) { DiffManager.getInstance().registerDiffTool(new CommentsDiffTool()); final ContentManager contentManager = toolWindow.getContentManager(); final CruciblePanel cruciblePanel = new CruciblePanel(project); final Content content = ContentFactory.SERVICE .getInstance() .createContent(cruciblePanel, CrucibleBundle.message("crucible.main.name"), false); content.setCloseable(false); contentManager.addContent(content); }
@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 HerokuToolWindow addAsContent(ContentManager contentManager) { final Content content = contentManager.getFactory().createContent(this, null, false); setWindowInfo( new ContentInfo() { public void describe(String title, String icon, String description) { content.setIcon(icon(icon)); content.setDescription(description); content.setDisplayName(title); content.setTabName(title); content.setToolwindowTitle(title); } }); content.setCloseable(false); contentManager.addContent(content); return this; }
private void initToolWindow() { myToolWindowForm = new AndroidLayoutPreviewToolWindowForm(this); final String toolWindowId = AndroidBundle.message("android.layout.preview.tool.window.title"); myToolWindow = ToolWindowManager.getInstance(myProject) .registerToolWindow(toolWindowId, false, ToolWindowAnchor.RIGHT, myProject, true); myToolWindow.setIcon(AndroidIcons.AndroidPreview); ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject)) .addToolWindowManagerListener( new ToolWindowManagerAdapter() { private boolean myVisible = false; @Override public void stateChanged() { if (myProject.isDisposed()) { return; } final ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId); if (window != null && window.isAvailable()) { final boolean visible = window.isVisible(); AndroidEditorSettings.getInstance().getGlobalState().setVisible(visible); if (visible && !myVisible) { render(); } myVisible = visible; } } }); final JPanel contentPanel = myToolWindowForm.getContentPanel(); final ContentManager contentManager = myToolWindow.getContentManager(); @SuppressWarnings("ConstantConditions") final Content content = contentManager.getFactory().createContent(contentPanel, null, false); content.setDisposer(myToolWindowForm); content.setCloseable(false); content.setPreferredFocusableComponent(contentPanel); contentManager.addContent(content); contentManager.setSelectedContent(content, true); myToolWindow.setAvailable(false, null); }
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 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 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; }
@Override public void createToolWindowContent( @NotNull final Project project, @NotNull final ToolWindow toolWindow) { toolWindow.setIcon(InteractiveLearningIcons.TaskDescription); StudyTaskManager taskManager = StudyTaskManager.getInstance(project); final Course course = taskManager.getCourse(); if (course != null) { final StudyToolWindow studyToolWindow; if (StudyUtils.hasJavaFx() && StudyTaskManager.getInstance(project).shouldUseJavaFx()) { studyToolWindow = new StudyJavaFxToolWindow(); } else { studyToolWindow = new StudySwingToolWindow(); } studyToolWindow.init(project); final ContentManager contentManager = toolWindow.getContentManager(); final Content content = contentManager.getFactory().createContent(studyToolWindow, null, false); contentManager.addContent(content); Disposer.register(project, studyToolWindow); } }
@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; }
private static void addHierarchyScope(@NotNull Project project, Collection<SearchScope> result) { final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.HIERARCHY); if (toolWindow == null) { return; } final ContentManager contentManager = toolWindow.getContentManager(); final Content content = contentManager.getSelectedContent(); if (content == null) { return; } final String name = content.getDisplayName(); final JComponent component = content.getComponent(); if (!(component instanceof HierarchyBrowserBase)) { return; } final HierarchyBrowserBase hierarchyBrowserBase = (HierarchyBrowserBase) component; final PsiElement[] elements = hierarchyBrowserBase.getAvailableElements(); if (elements.length > 0) { result.add(new LocalSearchScope(elements, "Hierarchy '" + name + "' (visible nodes only)")); } }
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(); } }
public Element getState() { Element element = new Element("TodoView"); if (myContentManager != null) { // all panel were constructed Content content = myContentManager.getSelectedContent(); element.setAttribute( ATTRIBUTE_SELECTED_INDEX, Integer.toString(myContentManager.getIndexOfContent(content))); } Element selectedFileElement = new Element(ELEMENT_TODO_PANEL); selectedFileElement.setAttribute(ATTRIBUTE_ID, VALUE_SELECTED_FILE); myCurrentPanelSettings.writeExternal(selectedFileElement); element.addContent(selectedFileElement); Element allElement = new Element(ELEMENT_TODO_PANEL); allElement.setAttribute(ATTRIBUTE_ID, VALUE_ALL); myAllPanelSettings.writeExternal(allElement); element.addContent(allElement); Element changeListElement = new Element(ELEMENT_TODO_PANEL); changeListElement.setAttribute(ATTRIBUTE_ID, VALUE_DEFAULT_CHANGELIST); myChangeListTodosPanelSettings.writeExternal(changeListElement); element.addContent(changeListElement); return element; }
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 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 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); } } }); } }
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 initToolWindow(ToolWindow toolWindow) { // Create panels Content allTodosContent = ContentFactory.SERVICE .getInstance() .createContent(null, IdeBundle.message("title.project"), false); myAllTodos = new TodoPanel(myProject, myAllPanelSettings, false, allTodosContent) { protected TodoTreeBuilder createTreeBuilder( JTree tree, DefaultTreeModel treeModel, Project project) { AllTodosTreeBuilder builder = new AllTodosTreeBuilder(tree, treeModel, project); builder.init(); return builder; } }; allTodosContent.setComponent(myAllTodos); Disposer.register(this, myAllTodos); Content currentFileTodosContent = ContentFactory.SERVICE .getInstance() .createContent(null, IdeBundle.message("title.todo.current.file"), false); myCurrentFileTodos = new CurrentFileTodosPanel(myProject, myCurrentPanelSettings, currentFileTodosContent) { protected TodoTreeBuilder createTreeBuilder( JTree tree, DefaultTreeModel treeModel, Project project) { CurrentFileTodosTreeBuilder builder = new CurrentFileTodosTreeBuilder(tree, treeModel, project); builder.init(); return builder; } }; Disposer.register(this, myCurrentFileTodos); currentFileTodosContent.setComponent(myCurrentFileTodos); myChangeListTodosContent = ContentFactory.SERVICE .getInstance() .createContent( null, IdeBundle.message( "changelist.todo.title", ChangeListManager.getInstance(myProject).getDefaultChangeList().getName()), false); myChangeListTodos = new ChangeListTodosPanel(myProject, myCurrentPanelSettings, myChangeListTodosContent) { protected TodoTreeBuilder createTreeBuilder( JTree tree, DefaultTreeModel treeModel, Project project) { ChangeListTodosTreeBuilder builder = new ChangeListTodosTreeBuilder(tree, treeModel, project); builder.init(); return builder; } }; Disposer.register(this, myChangeListTodos); myChangeListTodosContent.setComponent(myChangeListTodos); myContentManager = toolWindow.getContentManager(); myContentManager.addContent(allTodosContent); myContentManager.addContent(currentFileTodosContent); if (myVCSManager.getAllActiveVcss().length > 0) { myVcsListener.myIsVisible = true; myContentManager.addContent(myChangeListTodosContent); } Content content = myContentManager.getContent(mySelectedIndex); content = content == null ? allTodosContent : content; myContentManager.setSelectedContent(content); }