Java Code Examples for com.intellij.ui.content.Content#setComponent()

The following examples show how to use com.intellij.ui.content.Content#setComponent() . 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: BrowseHierarchyActionBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static HierarchyBrowser createAndAddToPanel(@Nonnull Project project, @Nonnull final HierarchyProvider provider, @Nonnull PsiElement target) {
  final HierarchyBrowser hierarchyBrowser = provider.createHierarchyBrowser(target);

  final Content content;

  final HierarchyBrowserManager hierarchyBrowserManager = HierarchyBrowserManager.getInstance(project);

  final ContentManager contentManager = hierarchyBrowserManager.getContentManager();
  final Content selectedContent = contentManager.getSelectedContent();
  if (selectedContent != null && !selectedContent.isPinned()) {
    content = selectedContent;
    final Component component = content.getComponent();
    if (component instanceof Disposable) {
      Disposer.dispose((Disposable)component);
    }
    content.setComponent(hierarchyBrowser.getComponent());
  }
  else {
    content = ContentFactory.getInstance().createContent(hierarchyBrowser.getComponent(), null, true);
    contentManager.addContent(content);
  }
  contentManager.setSelectedContent(content);
  hierarchyBrowser.setContent(content);

  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      provider.browserActivated(hierarchyBrowser);
    }
  };
  ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.HIERARCHY).activate(runnable);
  return hierarchyBrowser;
}
 
Example 2
Source File: TodoView.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void addCustomTodoView(final TodoTreeBuilderFactory factory, final String title, final TodoPanelSettings settings) {
  Content content = ContentFactory.SERVICE.getInstance().createContent(null, title, true);
  final ChangeListTodosPanel panel = new ChangeListTodosPanel(myProject, settings, content) {
    @Override
    protected TodoTreeBuilder createTreeBuilder(JTree tree, Project project) {
      TodoTreeBuilder todoTreeBuilder = factory.createTreeBuilder(tree, project);
      todoTreeBuilder.init();
      return todoTreeBuilder;
    }
  };
  content.setComponent(panel);
  Disposer.register(this, panel);

  if (myContentManager == null) {
    myNotAddedContent.add(content);
  }
  else {
    myContentManager.addContent(content);
  }
  myPanels.add(panel);
  content.setCloseable(true);
  content.setDisposer(new Disposable() {
    @Override
    public void dispose() {
      myPanels.remove(panel);
    }
  });
}
 
Example 3
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 4
Source File: PreviewView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void initToolWindow(@NotNull ToolWindow toolWindow) {
  final ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
  final ContentManager contentManager = toolWindow.getContentManager();

  final Content content = contentFactory.createContent(null, null, false);
  content.setCloseable(false);

  windowPanel = new OutlineComponent(this);
  content.setComponent(windowPanel);

  windowPanel.setToolbar(widgetEditToolbar.getToolbar().getComponent());

  final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();

  tree = new OutlineTree(rootNode);
  tree.setCellRenderer(new OutlineTreeCellRenderer());
  tree.expandAll();

  initTreePopup();

  // Add collapse all, expand all, and show only widgets buttons.
  if (toolWindow instanceof ToolWindowEx) {
    final ToolWindowEx toolWindowEx = (ToolWindowEx)toolWindow;

    final CommonActionsManager actions = CommonActionsManager.getInstance();
    final TreeExpander expander = new DefaultTreeExpander(tree);

    final AnAction expandAllAction = actions.createExpandAllAction(expander, tree);
    expandAllAction.getTemplatePresentation().setIcon(AllIcons.Actions.Expandall);

    final AnAction collapseAllAction = actions.createCollapseAllAction(expander, tree);
    collapseAllAction.getTemplatePresentation().setIcon(AllIcons.Actions.Collapseall);

    final ShowOnlyWidgetsAction showOnlyWidgetsAction = new ShowOnlyWidgetsAction();

    toolWindowEx.setTitleActions(expandAllAction, collapseAllAction, showOnlyWidgetsAction);
  }

  new TreeSpeedSearch(tree) {
    @Override
    protected String getElementText(Object element) {
      final TreePath path = (TreePath)element;
      final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
      final Object object = node.getUserObject();
      if (object instanceof OutlineObject) {
        return ((OutlineObject)object).getSpeedSearchString();
      }
      return null;
    }
  };

  tree.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      if (e.getClickCount() > 1) {
        final TreePath selectionPath = tree.getSelectionPath();
        if (selectionPath != null) {
          selectPath(selectionPath, true);
        }
      }
    }
  });

  tree.addTreeSelectionListener(treeSelectionListener);

  scrollPane = ScrollPaneFactory.createScrollPane(tree);
  content.setPreferredFocusableComponent(tree);

  contentManager.addContent(content);
  contentManager.setSelectedContent(content);

  splitter = new Splitter(true);
  setSplitterProportion(getState().getSplitterProportion());
  getState().addListener(e -> {
    final float newProportion = getState().getSplitterProportion();
    if (splitter.getProportion() != newProportion) {
      setSplitterProportion(newProportion);
    }
  });
  //noinspection Convert2Lambda
  splitter.addPropertyChangeListener("proportion", new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      if (!isSettingSplitterProportion) {
        getState().setSplitterProportion(splitter.getProportion());
      }
    }
  });
  scrollPane.setMinimumSize(new Dimension(1, 1));
  splitter.setFirstComponent(scrollPane);
  windowPanel.setContent(splitter);
}
 
Example 5
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 6
Source File: PreviewView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void initToolWindow(@NotNull ToolWindow toolWindow) {
  final ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
  final ContentManager contentManager = toolWindow.getContentManager();

  final Content content = contentFactory.createContent(null, null, false);
  content.setCloseable(false);

  windowPanel = new OutlineComponent(this);
  content.setComponent(windowPanel);

  windowPanel.setToolbar(widgetEditToolbar.getToolbar().getComponent());

  final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();

  tree = new OutlineTree(rootNode);
  tree.setCellRenderer(new OutlineTreeCellRenderer());
  tree.expandAll();

  initTreePopup();

  // Add collapse all, expand all, and show only widgets buttons.
  if (toolWindow instanceof ToolWindowEx) {
    final ToolWindowEx toolWindowEx = (ToolWindowEx)toolWindow;

    final CommonActionsManager actions = CommonActionsManager.getInstance();
    final TreeExpander expander = new DefaultTreeExpander(tree);

    final AnAction expandAllAction = actions.createExpandAllAction(expander, tree);
    expandAllAction.getTemplatePresentation().setIcon(AllIcons.Actions.Expandall);

    final AnAction collapseAllAction = actions.createCollapseAllAction(expander, tree);
    collapseAllAction.getTemplatePresentation().setIcon(AllIcons.Actions.Collapseall);

    final ShowOnlyWidgetsAction showOnlyWidgetsAction = new ShowOnlyWidgetsAction();

    toolWindowEx.setTitleActions(expandAllAction, collapseAllAction, showOnlyWidgetsAction);
  }

  new TreeSpeedSearch(tree) {
    @Override
    protected String getElementText(Object element) {
      final TreePath path = (TreePath)element;
      final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
      final Object object = node.getUserObject();
      if (object instanceof OutlineObject) {
        return ((OutlineObject)object).getSpeedSearchString();
      }
      return null;
    }
  };

  tree.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      if (e.getClickCount() > 1) {
        final TreePath selectionPath = tree.getSelectionPath();
        if (selectionPath != null) {
          selectPath(selectionPath, true);
        }
      }
    }
  });

  tree.addTreeSelectionListener(treeSelectionListener);

  scrollPane = ScrollPaneFactory.createScrollPane(tree);
  content.setPreferredFocusableComponent(tree);

  contentManager.addContent(content);
  contentManager.setSelectedContent(content);

  splitter = new Splitter(true);
  setSplitterProportion(getState().getSplitterProportion());
  getState().addListener(e -> {
    final float newProportion = getState().getSplitterProportion();
    if (splitter.getProportion() != newProportion) {
      setSplitterProportion(newProportion);
    }
  });
  //noinspection Convert2Lambda
  splitter.addPropertyChangeListener("proportion", new PropertyChangeListener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      if (!isSettingSplitterProportion) {
        getState().setSplitterProportion(splitter.getProportion());
      }
    }
  });
  scrollPane.setMinimumSize(new Dimension(1, 1));
  splitter.setFirstComponent(scrollPane);
  windowPanel.setContent(splitter);
}