Java Code Examples for com.intellij.ui.content.ContentManager#removeContent()

The following examples show how to use com.intellij.ui.content.ContentManager#removeContent() . 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: AnalyzeSizeToolWindowFactory.java    From size-analyzer with Apache License 2.0 6 votes vote down vote up
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
  ContentManager contentManager = toolWindow.getContentManager();
  AnalyzeSizeToolWindow analyzeSizeToolWindow =
      new AnalyzeSizeToolWindow(
          toolWindow,
          project,
          categorizedSuggestions,
          categoryDisplayOrder
          );
  Content content =
      ContentFactory.SERVICE
          .getInstance()
          .createContent(analyzeSizeToolWindow.getContent(), CONTENT_TITLE, false);
  // We want only one content tab to exist at a time, but clearing all of them will cause the
  // tool window to disappear, so we add the new tab and remove the others after.
  contentManager.addContent(content);
  contentManager.setSelectedContent(content);
  for (Content otherContent : contentManager.getContents()) {
    if (otherContent != content) {
      contentManager.removeContent(otherContent, true);
    }
  }
  toolWindow.show(null);
}
 
Example 2
Source File: ContentsUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void addOrReplaceContent(ContentManager manager, Content content, boolean select) {
  final String contentName = content.getDisplayName();

  Content[] contents = manager.getContents();
  Content oldContentFound = null;
  for(Content oldContent: contents) {
    if (!oldContent.isPinned() && oldContent.getDisplayName().equals(contentName)) {
      oldContentFound = oldContent;
      break;
    }
  }

  manager.addContent(content);
  if (oldContentFound != null) {
    manager.removeContent(oldContentFound, true);
  }
  if (select) {
    manager.setSelectedContent(content);
  }
}
 
Example 3
Source File: CloseActiveTabAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
  ContentManager contentManager = ContentManagerUtil.getContentManagerFromContext(e.getDataContext(), true);
  boolean processed = false;
  if (contentManager != null && contentManager.canCloseContents()) {
    final Content selectedContent = contentManager.getSelectedContent();
    if (selectedContent != null && selectedContent.isCloseable()) {
      contentManager.removeContent(selectedContent, true);
      processed = true;
    }
  }

  if (!processed && contentManager != null) {
    final DataContext context = DataManager.getInstance().getDataContext(contentManager.getComponent());
    final ToolWindow tw = context.getData(PlatformDataKeys.TOOL_WINDOW);
    if (tw != null) {
      tw.hide(null);
    }
  }
}
 
Example 4
Source File: VcsDockedComponent.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public void removeFromVcsTab(@NotNull @NonNls String title) {
    final ToolWindow toolW = getToolWindow();
    if (toolW == null) {
        // cannot do anything
        return;
    }
    final ContentManager contentManager = getToolWindow().getContentManager();
    final Content existingContent = contentManager.findContent(title);
    if (existingContent != null) {
        if (!existingContent.isPinned()) {
            contentManager.removeContent(existingContent, true);
            existingContent.release();
        }
    }
}
 
Example 5
Source File: VcsDockedComponent.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public boolean addVcsTab(@NotNull @NonNls String title,
        @NotNull JComponent component,
        boolean showTab,
        boolean replaceExistingComponent) {
    if (component instanceof Disposable) {
        Disposer.register(this, (Disposable) component);
    }
    final ToolWindow toolW = getToolWindow();
    if (toolW == null) {
        // cannot do anything
        return false;
    }
    final ContentManager contentManager = getToolWindow().getContentManager();
    final Content existingContent = contentManager.findContent(title);
    if (existingContent != null) {
        if (!replaceExistingComponent) {
            contentManager.setSelectedContent(existingContent);
            return true;
        }
        else if (!existingContent.isPinned()) {
            contentManager.removeContent(existingContent, true);
            existingContent.release();
        }
    }

    final Content content = contentManager.getFactory().createContent(component, title, false);
    contentManager.addContent(content);
    if (showTab) {
        getToolWindow().activate(null, false);
    }

    return true;
}
 
Example 6
Source File: CompleteReviewAction.java    From Crucible4IDEA with MIT License 5 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
  final Project project = e.getData(PlatformDataKeys.PROJECT);
  if (project == null) return;
  CrucibleManager.getInstance(project).completeReview(myReview.getPermaId());
  final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(CrucibleBundle.message("crucible.toolwindow.id"));
  final ContentManager contentManager = toolWindow.getContentManager();
  final Content foundContent = contentManager.findContent("Details for " + myReview.getPermaId());
  contentManager.removeContent(foundContent, true);

  final Content dash = contentManager.findContent("Dashboard");
  if (dash.getComponent() instanceof CruciblePanel) {
    ((CruciblePanel)dash.getComponent()).getReviewModel().updateModel(CrucibleFilter.ToReview);
  }
}
 
Example 7
Source File: ContentsUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void closeContentTab(@Nonnull ContentManager contentManager, @Nonnull Content content) {
  if (content instanceof TabbedContent) {
    TabbedContent tabbedContent = (TabbedContent)content;
    if (tabbedContent.getTabs().size() > 1) {
      JComponent component = tabbedContent.getComponent();
      tabbedContent.removeContent(component);
      contentManager.setSelectedContent(tabbedContent, true, true);
      dispose(component);
      return;
    }
  }
  contentManager.removeContent(content, true);
}
 
Example 8
Source File: TabbedContentImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void split() {
  List<Pair<String, JComponent>> copy = new ArrayList<Pair<String, JComponent>>(myTabs);
  int selectedTab = ContentUtilEx.getSelectedTab(this);
  ContentManager manager = getManager();
  String prefix = getTitlePrefix();
  manager.removeContent(this, true);
  PropertiesComponent.getInstance().setValue(SPLIT_PROPERTY_PREFIX + prefix, Boolean.TRUE.toString());
  for (int i = 0; i < copy.size(); i++) {
    final boolean select = i == selectedTab;
    final JComponent component = copy.get(i).second;
    final String tabName = copy.get(i).first;
    ContentUtilEx.addTabbedContent(manager, component, prefix, tabName, select);
  }
}
 
Example 9
Source File: CloseOtherViewsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void actionPerformed(final AnActionEvent e, final ViewContext context, final Content[] content) {
  final ContentManager manager = context.getContentManager();
  for (Content c : manager.getContents()) {
    if (c != content[0] && c.isCloseable()) {
      manager.removeContent(c, context.isToDisposeRemovedContent());
    }
  }
}
 
Example 10
Source File: CloseAllViewsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void actionPerformed(final AnActionEvent e, final ViewContext context, final Content[] content) {
  final ContentManager manager = context.getContentManager();
  for (Content c : manager.getContents()) {
    if (c.isCloseable()) {
      manager.removeContent(c, context.isToDisposeRemovedContent());
    }
  }
}
 
Example 11
Source File: FlutterView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void addInspectorViewContent(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow) {
  final ContentManager contentManager = toolWindow.getContentManager();
  final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true);
  final JBRunnerTabs runnerTabs = new JBRunnerTabs(myProject, ActionManager.getInstance(), IdeFocusManager.getInstance(myProject), this);
  runnerTabs.setSelectionChangeHandler(this::onTabSelectionChange);
  final JPanel tabContainer = new JPanel(new BorderLayout());

  final String tabName;
  final FlutterDevice device = app.device();
  if (device == null) {
    tabName = app.getProject().getName();
  }
  else {
    final List<FlutterDevice> existingDevices = new ArrayList<>();
    for (FlutterApp otherApp : perAppViewState.keySet()) {
      existingDevices.add(otherApp.device());
    }
    tabName = device.getUniqueName(existingDevices);
  }

  final Content content = contentManager.getFactory().createContent(null, tabName, false);
  tabContainer.add(runnerTabs.getComponent(), BorderLayout.CENTER);
  content.setComponent(tabContainer);
  content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
  content.setIcon(FlutterIcons.Phone);
  contentManager.addContent(content);

  if (emptyContent != null) {
    contentManager.removeContent(emptyContent, true);
    emptyContent = null;
  }

  contentManager.setSelectedContent(content);

  final PerAppState state = getOrCreateStateForApp(app);
  assert (state.content == null);
  state.content = content;

  final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, inspectorService);
  toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterViewToolbar", toolbarGroup, true).getComponent());

  toolbarGroup.add(new OverflowAction(getOrCreateStateForApp(app), this, app));

  final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("InspectorToolbar", toolbarGroup, true);
  final JComponent toolbarComponent = toolbar.getComponent();
  toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
  tabContainer.add(toolbarComponent, BorderLayout.NORTH);

  final boolean debugConnectionAvailable = app.getLaunchMode().supportsDebugConnection();
  final boolean hasInspectorService = inspectorService != null;

  // If the inspector is available (non-release mode), then show it.
  if (debugConnectionAvailable) {
    if (hasInspectorService) {
      final boolean detailsSummaryViewSupported = inspectorService.isDetailsSummaryViewSupported();
      addInspectorPanel(WIDGET_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.widget, app, inspectorService, toolWindow,
                        toolbarGroup, true, detailsSummaryViewSupported);
      addInspectorPanel(RENDER_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.renderObject, app, inspectorService,
                        toolWindow, toolbarGroup, false, false);
    }
    else {
      // If in profile mode, add disabled tabs for the inspector.
      addDisabledTab(WIDGET_TAB_LABEL, runnerTabs, toolbarGroup);
      addDisabledTab(RENDER_TAB_LABEL, runnerTabs, toolbarGroup);
    }
  }
  else {
    // Add a message about the inspector not being available in release mode.
    final JBLabel label = new JBLabel("Inspector not available in release mode", SwingConstants.CENTER);
    label.setForeground(UIUtil.getLabelDisabledForeground());
    tabContainer.add(label, BorderLayout.CENTER);
  }
}
 
Example 12
Source File: FlutterView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void addInspectorViewContent(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow) {
  final ContentManager contentManager = toolWindow.getContentManager();
  final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true);
  final JBRunnerTabs runnerTabs = new JBRunnerTabs(myProject, ActionManager.getInstance(), IdeFocusManager.getInstance(myProject), this);
  runnerTabs.setSelectionChangeHandler(this::onTabSelectionChange);
  final JPanel tabContainer = new JPanel(new BorderLayout());

  final String tabName;
  final FlutterDevice device = app.device();
  if (device == null) {
    tabName = app.getProject().getName();
  }
  else {
    final List<FlutterDevice> existingDevices = new ArrayList<>();
    for (FlutterApp otherApp : perAppViewState.keySet()) {
      existingDevices.add(otherApp.device());
    }
    tabName = device.getUniqueName(existingDevices);
  }

  final Content content = contentManager.getFactory().createContent(null, tabName, false);
  tabContainer.add(runnerTabs.getComponent(), BorderLayout.CENTER);
  content.setComponent(tabContainer);
  content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
  content.setIcon(FlutterIcons.Phone);
  contentManager.addContent(content);

  if (emptyContent != null) {
    contentManager.removeContent(emptyContent, true);
    emptyContent = null;
  }

  contentManager.setSelectedContent(content);

  final PerAppState state = getOrCreateStateForApp(app);
  assert (state.content == null);
  state.content = content;

  final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, inspectorService);
  toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterViewToolbar", toolbarGroup, true).getComponent());

  toolbarGroup.add(new OverflowAction(getOrCreateStateForApp(app), this, app));

  final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("InspectorToolbar", toolbarGroup, true);
  final JComponent toolbarComponent = toolbar.getComponent();
  toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
  tabContainer.add(toolbarComponent, BorderLayout.NORTH);

  final boolean debugConnectionAvailable = app.getLaunchMode().supportsDebugConnection();
  final boolean hasInspectorService = inspectorService != null;

  // If the inspector is available (non-release mode), then show it.
  if (debugConnectionAvailable) {
    if (hasInspectorService) {
      final boolean detailsSummaryViewSupported = inspectorService.isDetailsSummaryViewSupported();
      addInspectorPanel(WIDGET_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.widget, app, inspectorService, toolWindow,
                        toolbarGroup, true, detailsSummaryViewSupported);
      addInspectorPanel(RENDER_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.renderObject, app, inspectorService,
                        toolWindow, toolbarGroup, false, false);
    }
    else {
      // If in profile mode, add disabled tabs for the inspector.
      addDisabledTab(WIDGET_TAB_LABEL, runnerTabs, toolbarGroup);
      addDisabledTab(RENDER_TAB_LABEL, runnerTabs, toolbarGroup);
    }
  }
  else {
    // Add a message about the inspector not being available in release mode.
    final JBLabel label = new JBLabel("Inspector not available in release mode", SwingConstants.CENTER);
    label.setForeground(UIUtil.getLabelDisabledForeground());
    tabContainer.add(label, BorderLayout.CENTER);
  }
}