Java Code Examples for com.intellij.openapi.wm.ToolWindowManager#getInstance()

The following examples show how to use com.intellij.openapi.wm.ToolWindowManager#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestToolWindow.java    From intellij-reference-diagram with Apache License 2.0 6 votes vote down vote up
private static TestToolWindow createViewTab(Project project, PsiElement baseElement) {
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_ID);
    if (toolWindow == null) {
        toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_ID,
                true,
                ToolWindowAnchor.BOTTOM);
    }
    final TestToolWindow view = new TestToolWindow(project);
    ToolWindow finalToolWindow = toolWindow;
    toolWindow.activate(() -> {
        final String text = SymbolPresentationUtil.getSymbolPresentableText(baseElement);
        final ContentImpl content = new ContentImpl(view, "to " + text, true);
        finalToolWindow.getContentManager().addContent(content);
        finalToolWindow.getContentManager().setSelectedContent(content, true);
    });
    return view;
}
 
Example 2
Source File: ExternalSystemUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void ensureToolWindowInitialized(@Nonnull Project project, @Nonnull ProjectSystemId externalSystemId) {
  ToolWindowManager manager = ToolWindowManager.getInstance(project);
  if (!(manager instanceof ToolWindowManagerEx)) {
    return;
  }
  ToolWindowManagerEx managerEx = (ToolWindowManagerEx)manager;
  String id = externalSystemId.getReadableName();
  ToolWindow window = manager.getToolWindow(id);
  if (window != null) {
    return;
  }
  for (final ToolWindowEP bean : ToolWindowEP.EP_NAME.getExtensionList()) {
    if (id.equals(bean.id)) {
      managerEx.initToolWindow(bean);
    }
  }
}
 
Example 3
Source File: LafManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
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);
      }
    }
  }
}
 
Example 4
Source File: FavoritesViewSelectInTarget.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static ActionCallback select(@Nonnull Project project, Object toSelect, VirtualFile virtualFile, boolean requestFocus) {
  final ActionCallback result = new ActionCallback();

  ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
  final ToolWindow favoritesToolWindow = windowManager.getToolWindow(ToolWindowId.FAVORITES_VIEW);

  if (favoritesToolWindow != null) {
    final Runnable runnable = () -> {
      final FavoritesTreeViewPanel panel = UIUtil.findComponentOfType(favoritesToolWindow.getComponent(), FavoritesTreeViewPanel.class);
      if (panel != null) {
        panel.selectElement(toSelect, virtualFile, requestFocus);
        result.setDone();
      }
    };

    if (requestFocus) {
      favoritesToolWindow.activate(runnable, false);
    }
    else {
      favoritesToolWindow.show(runnable);
    }
  }

  return result;
}
 
Example 5
Source File: ToggleDockModeAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void update(AnActionEvent event) {
  super.update(event);
  Presentation presentation = event.getPresentation();
  Project project = event.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    presentation.setEnabled(false);
    return;
  }
  ToolWindowManager mgr = ToolWindowManager.getInstance(project);
  String id = mgr.getActiveToolWindowId();
  if (id == null) {
    presentation.setEnabled(false);
    return;
  }
  ToolWindow toolWindow = mgr.getToolWindow(id);
  presentation.setEnabled(toolWindow.isAvailable() && ToolWindowType.FLOATING != toolWindow.getType());
}
 
Example 6
Source File: StructureViewSelectInTarget.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void selectIn(final SelectInContext context, final boolean requestFocus) {
  final FileEditor fileEditor = context.getFileEditorProvider().get();

  ToolWindowManager windowManager=ToolWindowManager.getInstance(context.getProject());
  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      StructureViewFactoryEx.getInstanceEx(myProject).runWhenInitialized(new Runnable() {
        @Override
        public void run() {
          final StructureViewWrapper structureView = getStructureViewWrapper();
          structureView.selectCurrentElement(fileEditor, context.getVirtualFile(), requestFocus);
        }
      });
    }
  };
  if (requestFocus) {
    windowManager.getToolWindow(ToolWindowId.STRUCTURE_VIEW).activate(runnable);
  }
  else {
    runnable.run();
  }

}
 
Example 7
Source File: TabNavigationActionBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void update(@Nonnull AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  Project project = event.getData(CommonDataKeys.PROJECT);
  presentation.setEnabled(false);
  if (project == null) {
    return;
  }
  final ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
  if (windowManager.isEditorComponentActive()) {
    final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project);
    EditorWindow currentWindow = event.getData(EditorWindow.DATA_KEY);
    if (currentWindow == null) {
      editorManager.getCurrentWindow();
    }
    if (currentWindow != null) {
      final VirtualFile[] files = currentWindow.getFiles();
      presentation.setEnabled(files.length > 1);
    }
    return;
  }

  ContentManager contentManager = event.getData(PlatformDataKeys.NONEMPTY_CONTENT_MANAGER);
  presentation.setEnabled(contentManager != null && contentManager.getContentCount() > 1 && contentManager.isSingleSelection());
}
 
Example 8
Source File: ToggleDockModeAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void setSelected(AnActionEvent event, boolean flag) {
  Project project = event.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return;
  }
  ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
  String id = windowManager.getActiveToolWindowId();
  if (id == null) {
    return;
  }
  ToolWindow toolWindow = windowManager.getToolWindow(id);
  ToolWindowType type = toolWindow.getType();
  if (ToolWindowType.DOCKED == type) {
    toolWindow.setType(ToolWindowType.SLIDING, null);
  }
  else if (ToolWindowType.SLIDING == type) {
    toolWindow.setType(ToolWindowType.DOCKED, null);
  }
}
 
Example 9
Source File: ToolWindowsGroup.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static List<ActivateToolWindowAction> getToolWindowActions(@Nonnull Project project, boolean shouldSkipHidden) {
  ActionManager actionManager = ActionManager.getInstance();
  ToolWindowManager manager = ToolWindowManager.getInstance(project);
  List<ActivateToolWindowAction> result = ContainerUtil.newArrayList();
  for (String id : manager.getToolWindowIds()) {
    if (shouldSkipHidden && !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;
}
 
Example 10
Source File: ToggleDockModeAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean isSelected(AnActionEvent event) {
  Project project = event.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return false;
  }
  ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
  String id = windowManager.getActiveToolWindowId();
  if (id == null) {
    return false;
  }
  return ToolWindowType.DOCKED == windowManager.getToolWindow(id).getType();
}
 
Example 11
Source File: ToggleFloatingModeAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSelected(AnActionEvent event) {
  Project project = event.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return false;
  }
  ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
  String id = windowManager.getActiveToolWindowId();
  if (id == null) {
    return false;
  }
  return ToolWindowType.FLOATING == windowManager.getToolWindow(id).getType();
}
 
Example 12
Source File: NextSplitAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void update(final AnActionEvent event){
  final Project project = event.getData(CommonDataKeys.PROJECT);
  final Presentation presentation = event.getPresentation();
  if (project == null) {
    presentation.setEnabled(false);
    return;
  }
  final FileEditorManagerEx manager = FileEditorManagerEx.getInstanceEx(project);
  final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
  presentation.setEnabled (toolWindowManager.isEditorComponentActive() && manager.isInSplitter() && manager.getCurrentWindow() != null);
}
 
Example 13
Source File: HierarchyBrowserManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public HierarchyBrowserManager(final Project project) {
  final ToolWindowManager toolWindowManager=ToolWindowManager.getInstance(project);
  final ToolWindow toolWindow = toolWindowManager.registerToolWindow(ToolWindowId.HIERARCHY, true, ToolWindowAnchor.RIGHT, project);
  myContentManager = toolWindow.getContentManager();
  toolWindow.setIcon(AllIcons.Toolwindows.ToolWindowHierarchy);
  new ContentManagerWatcher(toolWindow,myContentManager);
}
 
Example 14
Source File: MaximizeToolWindowAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  if (project == null || project.isDisposed()) return;
  ToolWindow toolWindow = e.getData(PlatformDataKeys.TOOL_WINDOW);
  if (toolWindow == null) return;
  ToolWindowManager manager = ToolWindowManager.getInstance(project);
  manager.setMaximized(toolWindow, !manager.isMaximized(toolWindow));
}
 
Example 15
Source File: JumpToLastWindowAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void update(AnActionEvent event){
  Presentation presentation = event.getPresentation();
  Project project = event.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    presentation.setEnabled(false);
    return;
  }
  ToolWindowManagerEx manager=(ToolWindowManagerEx)ToolWindowManager.getInstance(project);
  String id = manager.getLastActiveToolWindowId();
  presentation.setEnabled(id != null && manager.getToolWindow(id).isAvailable());
}
 
Example 16
Source File: FlutterPerformanceView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Activate the tool window.
 */
private void activateToolWindow() {
  final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);

  final ToolWindow toolWindow = toolWindowManager.getToolWindow(TOOL_WINDOW_ID);
  if (toolWindow.isVisible()) {
    return;
  }

  toolWindow.show(null);
}
 
Example 17
Source File: RunDashboardManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateDashboard(final boolean withStructure) {
  final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
  toolWindowManager.invokeLater(() -> {
    if (myProject.isDisposed()) {
      return;
    }

    if (withStructure) {
      boolean available = hasContent();
      ToolWindow toolWindow = toolWindowManager.getToolWindow(getToolWindowId());
      if (toolWindow == null) {
        if (available) {
          createToolWindow();
        }
        return;
      }

      boolean doShow = !toolWindow.isAvailable() && available;
      toolWindow.setAvailable(available, null);
      if (doShow) {
        toolWindow.show(null);
      }
    }

    if (myDashboardContent != null) {
      myDashboardContent.updateContent(withStructure);
    }
  });
}
 
Example 18
Source File: InspectionManagerEx.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public InspectionManagerEx(final Project project) {
  super(project);
  if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
    myContentManager = new NotNullLazyValue<ContentManager>() {
      @Nonnull
      @Override
      protected ContentManager compute() {
        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        toolWindowManager.registerToolWindow(ToolWindowId.INSPECTION, true, ToolWindowAnchor.BOTTOM, project);
        return ContentFactory.getInstance().createContentManager(new TabbedPaneContentUI(), true, project);
      }
    };
  }
  else {
    myContentManager = new NotNullLazyValue<ContentManager>() {
      @Nonnull
      @Override
      protected ContentManager compute() {
        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        ToolWindow toolWindow =
                toolWindowManager.registerToolWindow(ToolWindowId.INSPECTION, true, ToolWindowAnchor.BOTTOM, project);
        ContentManager contentManager = toolWindow.getContentManager();
        toolWindow.setIcon(AllIcons.Toolwindows.ToolWindowInspection);
        new ContentManagerWatcher(toolWindow, contentManager);
        return contentManager;
      }
    };
  }
}
 
Example 19
Source File: ChooseByNameBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean isDescendingFromTemporarilyFocusableToolWindow(@Nullable Component component) {
  if (component == null || myProject == null || myProject.isDisposed()) return false;

  ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
  ToolWindow toolWindow = toolWindowManager.getToolWindow(toolWindowManager.getActiveToolWindowId());
  JComponent toolWindowComponent = toolWindow != null ? toolWindow.getComponent() : null;
  return toolWindowComponent != null && toolWindowComponent.getClientProperty(TEMPORARILY_FOCUSABLE_COMPONENT_KEY) != null && SwingUtilities.isDescendingFrom(component, toolWindowComponent);
}
 
Example 20
Source File: RNUtil.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static void processConsole(Project project, ProcessHandler processHandler) {
        ConsoleView consoleView = TextConsoleBuilderFactory.getInstance().createBuilder(project).getConsole();
        consoleView.clear();
        consoleView.attachToProcess(processHandler);
        processHandler.startNotify();

        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        ToolWindow toolWindow;
        toolWindow = toolWindowManager.getToolWindow(TOOL_ID);

        // if already exist tool window then show it
        if (toolWindow != null) {
            toolWindow.show(null);// TODO add more tabs here?
            return;
        }

        toolWindow = toolWindowManager.registerToolWindow(TOOL_ID, true, ToolWindowAnchor.BOTTOM);
        toolWindow.setTitle("Android....");
        toolWindow.setStripeTitle("Android Console");
        toolWindow.setShowStripeButton(true);
        toolWindow.setIcon(PluginIcons.ICON_TOOL_WINDOW);

        JPanel panel = new JPanel((LayoutManager) new BorderLayout());
        panel.add((Component) consoleView.getComponent(), "Center");

        // Create toolbars
        DefaultActionGroup toolbarActions = new DefaultActionGroup();
        AnAction[]
                consoleActions = consoleView.createConsoleActions();// 必须在 consoleView.getComponent() 调用后组件真正初始化之后调用
        toolbarActions.addAll((AnAction[]) Arrays.copyOf(consoleActions, consoleActions.length));
        toolbarActions.add((AnAction) new StopProcessAction("Stop process", "Stop process", processHandler));
//        toolbarActions.add((AnAction) new CloseAction(defaultExecutor, runDescriptor, project));


        ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("unknown", (ActionGroup) toolbarActions, false);
        toolbar.setTargetComponent(consoleView.getComponent());
        panel.add((Component) toolbar.getComponent(), "West");

        ContentImpl consoleContent = new ContentImpl(panel, "Build", false);
        consoleContent.setManager(toolWindow.getContentManager());

        toolbarActions.add(new CloseTabAction(consoleContent));

//        addAdditionalConsoleEditorActions(consoleView, consoleContent);
//        consoleComponent.setActions();
        toolWindow.getContentManager().addContent(consoleContent);
        toolWindow.getContentManager().addContent(new ContentImpl(new JButton("Test"), "Build2", false));
        toolWindow.show(null);
    }