private void registerToolWindow(@NotNull final ToolWindowManager toolWindowManager) { try { Method method = toolWindowManager .getClass() .getDeclaredMethod( "registerToolWindow", String.class, JComponent.class, ToolWindowAnchor.class, boolean.class, boolean.class, boolean.class); method.setAccessible(true); method.invoke( toolWindowManager, StudyToolWindowFactory.STUDY_TOOL_WINDOW, null, ToolWindowAnchor.LEFT, true, true, true); } catch (Exception e) { final ToolWindow toolWindow = toolWindowManager.getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW); if (toolWindow == null) { toolWindowManager.registerToolWindow( StudyToolWindowFactory.STUDY_TOOL_WINDOW, true, ToolWindowAnchor.RIGHT, myProject, true); } } }
@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; }
public static void showTestResultsToolWindow( @NotNull final Project project, @NotNull final String message, boolean solved) { final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); ToolWindow window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID); if (window == null) { toolWindowManager.registerToolWindow( StudyTestResultsToolWindowFactoryKt.ID, true, ToolWindowAnchor.BOTTOM); window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID); new StudyTestResultsToolWindowFactory().createToolWindowContent(project, window); } final Content[] contents = window.getContentManager().getContents(); for (Content content : contents) { final JComponent component = content.getComponent(); if (component instanceof ConsoleViewImpl) { ((ConsoleViewImpl) component).clear(); if (!solved) { ((ConsoleViewImpl) component).print(message, ConsoleViewContentType.ERROR_OUTPUT); } else { ((ConsoleViewImpl) component).print(message, ConsoleViewContentType.NORMAL_OUTPUT); } window.setAvailable(true, () -> {}); window.show(() -> {}); return; } } }
private void doSelectModuleOrGroup(final Object toSelect, final boolean requestFocus) { ToolWindowManager windowManager = ToolWindowManager.getInstance(myProject); final Runnable runnable = new Runnable() { @Override public void run() { ProjectView projectView = ProjectView.getInstance(myProject); if (requestFocus) { projectView.changeView(getId(), getSubId()); } ((BaseProjectTreeBuilder) getTreeBuilder()) .selectInWidth( toSelect, requestFocus, new Condition<AbstractTreeNode>() { @Override public boolean value(final AbstractTreeNode node) { return node instanceof AbstractModuleNode || node instanceof ModuleGroupNode || node instanceof AbstractProjectNode; } }); } }; if (requestFocus) { windowManager.getToolWindow(ToolWindowId.PROJECT_VIEW).activate(runnable); } else { runnable.run(); } }
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 synchronized void unregisterToolWindow() { if (myToolWindow == null) return; ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject); toolWindowManager.unregisterToolWindow(TOOL_WINDOW_ID); myToolWindow = null; }
private static void copyClassesImpl( final String copyClassName, final Project project, final Map<PsiFile, PsiClass[]> classes, final HashMap<PsiFile, String> map, final Object targetDirectory, final PsiDirectory defaultTargetDirectory, final String commandName, final boolean selectInActivePanel, final boolean openInEditor) { final boolean[] result = new boolean[] {false}; Runnable command = () -> { final Runnable action = () -> { try { PsiDirectory target; if (targetDirectory instanceof PsiDirectory) { target = (PsiDirectory) targetDirectory; } else { target = ((MoveDestination) targetDirectory) .getTargetDirectory(defaultTargetDirectory); } Collection<PsiFile> files = doCopyClasses(classes, map, copyClassName, target, project); if (files != null) { if (openInEditor) { for (PsiFile file : files) { CopyHandler.updateSelectionInActiveProjectView( file, project, selectInActivePanel); } EditorHelper.openFilesInEditor(files.toArray(new PsiFile[files.size()])); } result[0] = true; } } catch (final IncorrectOperationException ex) { ApplicationManager.getApplication() .invokeLater( () -> Messages.showMessageDialog( project, ex.getMessage(), RefactoringBundle.message("error.title"), Messages.getErrorIcon())); } }; ApplicationManager.getApplication().runWriteAction(action); }; CommandProcessor processor = CommandProcessor.getInstance(); processor.executeCommand(project, command, commandName, null); if (result[0]) { ToolWindowManager.getInstance(project) .invokeLater(() -> ToolWindowManager.getInstance(project).activateEditorComponent()); } }
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 ensureVisible(Project project) { if (project == null) return; ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); if (toolWindowManager != null) { ToolWindow toolWindow = toolWindowManager.getToolWindow(ToolWindowId.CVS); if (toolWindow != null) { toolWindow.activate(null, false); } } }
public static void updateStudyToolWindow(Project project) { ToolWindowManager.getInstance(project) .getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW) .getContentManager() .removeAllContents(false); StudyToolWindowFactory factory = new StudyToolWindowFactory(); factory.createToolWindowContent( project, ToolWindowManager.getInstance(project) .getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW)); }
public void ensureVisible(Project project) { if (project == null) { return; } ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); if (toolWindowManager != null) { ToolWindow toolWindow = toolWindowManager.getToolWindow(COMMIT_LOGS_TOOLWINDOW_ID); if (toolWindow != null) { toolWindow.activate(null); } } }
@Override public void disposeComponent() { releaseEditor(); myMappings.disposeMe(); myConnect.disconnect(); Disposer.dispose(myAnnotationLocalChangesListener); myContentManager = null; ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject); if (toolWindowManager != null && toolWindowManager.getToolWindow(ToolWindowId.VCS) != null) { toolWindowManager.unregisterToolWindow(ToolWindowId.VCS); } }
@Override protected void notifyByBalloon( JUnitRunningModel model, boolean started, final JUnitConsoleProperties consoleProperties) { if (myFoundTests) { super.notifyByBalloon(model, started, consoleProperties); } else { final String packageName = myConfiguration.getPackage(); if (packageName == null) return; final Project project = myConfiguration.getProject(); final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(packageName); if (aPackage == null) return; final Module module = myConfiguration.getConfigurationModule().getModule(); if (module == null) return; final Set<Module> modulesWithPackage = new HashSet<Module>(); final PsiDirectory[] directories = aPackage.getDirectories(); for (PsiDirectory directory : directories) { final Module currentModule = ModuleUtil.findModuleForFile(directory.getVirtualFile(), project); if (module != currentModule && currentModule != null) { modulesWithPackage.add(currentModule); } } if (!modulesWithPackage.isEmpty()) { final String testRunDebugId = consoleProperties.isDebug() ? ToolWindowId.DEBUG : ToolWindowId.RUN; final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); final Function<Module, String> moduleNameRef = new Function<Module, String>() { @Override public String fun(Module module) { final String moduleName = module.getName(); return "<a href=\"" + moduleName + "\">" + moduleName + "</a>"; } }; String message = "Tests were not found in module \"" + module.getName() + "\".\n" + "Use "; if (modulesWithPackage.size() == 1) { message += "module \"" + moduleNameRef.fun(modulesWithPackage.iterator().next()) + "\" "; } else { message += "one of\n" + StringUtil.join(modulesWithPackage, moduleNameRef, "\n") + "\n"; } message += "instead"; toolWindowManager.notifyByBalloon( testRunDebugId, MessageType.WARNING, message, null, new ResetConfigurationModuleAdapter( project, consoleProperties, toolWindowManager, testRunDebugId)); } } }
@Nullable public static ToolWindow ensureToolWindowContentInitialized( @NotNull Project project, @NotNull ProjectSystemId externalSystemId) { final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); if (toolWindowManager == null) return null; final ToolWindow toolWindow = toolWindowManager.getToolWindow(externalSystemId.getReadableName()); if (toolWindow == null) return null; if (toolWindow instanceof ToolWindowImpl) { ((ToolWindowImpl) toolWindow).ensureContentInitialized(); } return toolWindow; }
public static List<ActivateToolWindowAction> getToolWindowActions(@NotNull Project project) { ActionManager actionManager = ActionManager.getInstance(); ToolWindowManager manager = ToolWindowManager.getInstance(project); List<ActivateToolWindowAction> result = ContainerUtil.newArrayList(); for (String id : manager.getToolWindowIds()) { if (!manager.getToolWindow(id).isShowStripeButton()) continue; String actionId = ActivateToolWindowAction.getActionIdForToolWindow(id); AnAction action = actionManager.getAction(actionId); if (action instanceof ActivateToolWindowAction) { result.add((ActivateToolWindowAction) action); } } Collections.sort(result, COMPARATOR); return result; }
@Override protected void previewRefactoring(final UsageInfo[] usages) { MigrationPanel panel = new MigrationPanel(myRoot[0], myLabeler, myProject, isPreviewUsages()); String text; if (myRoot[0] instanceof PsiField) { text = "field \'" + ((PsiField) myRoot[0]).getName() + "\'"; } else if (myRoot[0] instanceof PsiParameter) { text = "parameter \'" + ((PsiParameter) myRoot[0]).getName() + "\'"; } else if (myRoot[0] instanceof PsiLocalVariable) { text = "variable \'" + ((PsiLocalVariable) myRoot[0]).getName() + "\'"; } else if (myRoot[0] instanceof PsiMethod) { text = "method \'" + ((PsiMethod) myRoot[0]).getName() + "\' return"; } else { text = Arrays.toString(myRoot); } Content content = UsageViewManager.getInstance(myProject) .addContent( "Migrate Type of " + text + " from \'" + TypeMigrationLabeler.getElementType(myRoot[0]).getPresentableText() + "\' to \'" + myRules.getMigrationRootType().getPresentableText() + "\'", false, panel, true, true); panel.setContent(content); ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND).activate(null); }
@Override public UpdateInfoTree showUpdateProjectInfo( UpdatedFiles updatedFiles, String displayActionName, ActionInfo actionInfo, boolean canceled) { if (!myProject.isOpen() || myProject.isDisposed()) return null; ContentManager contentManager = getContentManager(); if (contentManager == null) { return null; // content manager is made null during dispose; flag is set later } final UpdateInfoTree updateInfoTree = new UpdateInfoTree(contentManager, myProject, updatedFiles, displayActionName, actionInfo); Content content = ContentFactory.SERVICE .getInstance() .createContent( updateInfoTree, canceled ? VcsBundle.message( "toolwindow.title.update.action.canceled.info", displayActionName) : VcsBundle.message("toolwindow.title.update.action.info", displayActionName), true); Disposer.register(content, updateInfoTree); ContentsUtil.addContent(contentManager, content, true); ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.VCS).activate(null); updateInfoTree.expandRootChildren(); return updateInfoTree; }
@Override public Insets getBorderInsets(final Component c) { if (myProject == null) return new Insets(0, 0, 0, 0); ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject); if (!(toolWindowManager instanceof ToolWindowManagerImpl) || !((ToolWindowManagerImpl) toolWindowManager).isToolWindowRegistered(myInfo.getId()) || myWindow.getType() == ToolWindowType.FLOATING) { return new Insets(0, 0, 0, 0); } ToolWindowAnchor anchor = myWindow.getAnchor(); Component component = myWindow.getComponent(); Container parent = component.getParent(); while (parent != null) { if (parent instanceof Splitter) { Splitter splitter = (Splitter) parent; boolean isFirst = splitter.getFirstComponent() == component; boolean isVertical = splitter.isVertical(); return new Insets( 0, anchor == ToolWindowAnchor.RIGHT || (!isVertical && !isFirst) ? 1 : 0, (isVertical && isFirst) ? 1 : 0, anchor == ToolWindowAnchor.LEFT || (!isVertical && isFirst) ? 1 : 0); } component = parent; parent = component.getParent(); } return new Insets( 0, anchor == ToolWindowAnchor.RIGHT ? 1 : 0, anchor == ToolWindowAnchor.TOP ? 1 : 0, anchor == ToolWindowAnchor.LEFT ? 1 : 0); }
public BookmarkInContextInfo invoke() { myBookmarkAtPlace = null; myFile = null; myLine = -1; BookmarkManager bookmarkManager = BookmarkManager.getInstance(myProject); if (ToolWindowManager.getInstance(myProject).isEditorComponentActive()) { Editor editor = CommonDataKeys.EDITOR.getData(myDataContext); if (editor != null) { Document document = editor.getDocument(); myLine = editor.getCaretModel().getLogicalPosition().line; myFile = FileDocumentManager.getInstance().getFile(document); myBookmarkAtPlace = bookmarkManager.findEditorBookmark(document, myLine); } } if (myFile == null) { myFile = CommonDataKeys.VIRTUAL_FILE.getData(myDataContext); myLine = -1; if (myBookmarkAtPlace == null && myFile != null) { myBookmarkAtPlace = bookmarkManager.findFileBookmark(myFile); } } return this; }
@Override protected void hyperlinkActivated(HyperlinkEvent e) { final Module moduleByName = ModuleManager.getInstance(myProject).findModuleByName(e.getDescription()); if (moduleByName != null) { myConfiguration.getConfigurationModule().setModule(moduleByName); try { final Executor executor = myConsoleProperties.isDebug() ? DefaultDebugExecutor.getDebugExecutorInstance() : DefaultRunExecutor.getRunExecutorInstance(); final ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executor.getId(), myConfiguration); assert runner != null; runner.execute( executor, new ExecutionEnvironment( myConfiguration, myProject, getRunnerSettings(), getConfigurationSettings(), null)); final Balloon balloon = myToolWindowManager.getToolWindowBalloon(myTestRunDebugId); if (balloon != null) { balloon.hide(); } } catch (ExecutionException e1) { LOG.error(e1); } } }
@Override protected void previewRefactoring(@NotNull final UsageInfo[] usages) { MigrationPanel panel = new MigrationPanel(myRoot, myLabeler, myProject, isPreviewUsages()); String name; if (myRoot.length == 1) { String fromType = assertNotNull(TypeMigrationLabeler.getElementType(myRoot[0])).getPresentableText(); String toType = myRootTypes.fun(myRoot[0]).getPresentableText(); String text; text = getPresentation(myRoot[0]); name = "Migrate Type of " + text + " from \'" + fromType + "\' to \'" + toType + "\'"; } else { final int rootsInPresentationCount = myRoot.length > MAX_ROOT_IN_PREVIEW_PRESENTATION ? MAX_ROOT_IN_PREVIEW_PRESENTATION : myRoot.length; String[] rootsPresentation = new String[rootsInPresentationCount]; for (int i = 0; i < rootsInPresentationCount; i++) { final PsiElement root = myRoot[i]; rootsPresentation[i] = root instanceof PsiNamedElement ? ((PsiNamedElement) root).getName() : root.getText(); } rootsPresentation = StringUtil.surround(rootsPresentation, "\'", "\'"); name = "Migrate Type of " + StringUtil.join(rootsPresentation, ", "); if (myRoot.length > MAX_ROOT_IN_PREVIEW_PRESENTATION) { name += "..."; } } Content content = UsageViewManager.getInstance(myProject).addContent(name, false, panel, true, true); panel.setContent(content); ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND).activate(null); }
@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 void showToolWindow(boolean activateWindow) { ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.FIND); toolWindow.show(null); if (activateWindow && !toolWindow.isActive()) { toolWindow.activate(null); } }
public void projectClosed() { if (myPaletteWindow != null) { myPaletteWindow.dispose(); ToolWindowManager.getInstance(myProject) .unregisterToolWindow(IdeBundle.message("toolwindow.palette")); myPaletteWindow = null; } }
public void close() { connectionManager.removeStateListener(this); // getTabComponent(Content content) // Project project = // DataKeys.PROJECT.getData(DataManager.getInstance().getDataContext()); ToolWindowManager toolWindowManager = null; try { toolWindowManager = ToolWindowManager.getInstance(project); } catch (Throwable e) { // todo -- fix me } if (toolWindowManager != null) { toolWindowManager.unregisterToolWindow(QUERY_RESULT_PANE); } }
@Nullable private ToolWindow getWindow(AnActionEvent event) { if (myWindow != null) return myWindow; Project project = CommonDataKeys.PROJECT.getData(event.getDataContext()); if (project == null) return null; ToolWindowManager manager = ToolWindowManager.getInstance(project); final ToolWindow window = manager.getToolWindow(manager.getActiveToolWindowId()); if (window == null) return null; final Component context = PlatformDataKeys.CONTEXT_COMPONENT.getData(event.getDataContext()); if (context == null) return null; return SwingUtilities.isDescendingFrom(window.getComponent(), context) ? window : null; }
public ToolWindow getToolWindow() { if (myToolWindow == null) { myToolWindow = ToolWindowManager.getInstance(getProject()) .getToolWindow(PythonConsoleToolWindowFactory.ID); } return myToolWindow; }
private QueryResultPanel getSelectedResultPanel() { ToolWindow wm = ToolWindowManager.getInstance(project).getToolWindow(QUERY_RESULT_PANE); Content selected = wm.getContentManager().getSelectedContent(); if (selected != null) { return getSelectedTab(selected); } return null; }
@Override public ContentManager getContentManager() { if (myContentManager == null && Registry.is("vcs.merge.toolwindows")) { final ToolWindow changes = ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.VCS); myContentManager = changes == null ? null : changes.getContentManager(); } return myContentManager; }
public static void updateToolWindows() { for (Project project : ProjectManager.getInstance().getOpenProjects()) { final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); for (String id : toolWindowManager.getToolWindowIds()) { final ToolWindow toolWindow = toolWindowManager.getToolWindow(id); for (Content content : toolWindow.getContentManager().getContents()) { final JComponent component = content.getComponent(); if (component != null) { IJSwingUtilities.updateComponentTreeUI(component); } } final JComponent c = toolWindow.getComponent(); if (c != null) { IJSwingUtilities.updateComponentTreeUI(c); } } } }