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

The following examples show how to use com.intellij.ui.content.ContentManager#addContent() . 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: 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 2
Source File: RestfulWindowToolWindowFactory.java    From NutzCodeInsight with Apache License 2.0 6 votes vote down vote up
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
    final SimpleTree apiTree = new SimpleTree();
    apiTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    this.toolWindowEx = (ToolWindowEx) toolWindow;
    RefreshAction refreshAction = new RefreshAction("刷新", "重新加载URL", AllIcons.Actions.Refresh, toolWindowEx, apiTree);
    toolWindowEx.setTitleActions(refreshAction, actionManager.getAction("GoToRequestMapping"));
    apiTree.addMouseListener(new ApiTreeMouseAdapter(apiTree));
    ContentManager contentManager = toolWindow.getContentManager();
    Content content = contentManager.getFactory().createContent(new RestServicesNavigatorPanel(apiTree), null, false);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content);
    if (project.isInitialized()) {
        refreshAction.loadTree(project);
    }
}
 
Example 3
Source File: FlutterView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void updateForEmptyContent(ToolWindow toolWindow) {
  // There's a possible race here where the tool window gets disposed while we're displaying contents.
  if (toolWindow.isDisposed()) {
    return;
  }

  toolWindow.setIcon(FlutterIcons.Flutter_13);

  // Display a 'No running applications' message.
  final ContentManager contentManager = toolWindow.getContentManager();
  final JPanel panel = new JPanel(new BorderLayout());
  final JBLabel label = new JBLabel("No running applications", SwingConstants.CENTER);
  label.setForeground(UIUtil.getLabelDisabledForeground());
  panel.add(label, BorderLayout.CENTER);
  emptyContent = contentManager.getFactory().createContent(panel, null, false);
  contentManager.addContent(emptyContent);
}
 
Example 4
Source File: FlutterPerformanceView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void updateForEmptyContent(ToolWindow toolWindow) {
  // There's a possible race here where the tool window gets disposed while we're displaying contents.
  if (toolWindow.isDisposed()) {
    return;
  }

  toolWindow.setIcon(FlutterIcons.Flutter_13);

  // Display a 'No running applications' message.
  final ContentManager contentManager = toolWindow.getContentManager();
  final JPanel panel = new JPanel(new BorderLayout());
  final JBLabel label = new JBLabel("No running applications", SwingConstants.CENTER);
  label.setForeground(UIUtil.getLabelDisabledForeground());
  panel.add(label, BorderLayout.CENTER);
  emptyContent = contentManager.getFactory().createContent(panel, null, false);
  contentManager.addContent(emptyContent);
}
 
Example 5
Source File: FlutterPerformanceView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void updateForEmptyContent(ToolWindow toolWindow) {
  // There's a possible race here where the tool window gets disposed while we're displaying contents.
  if (toolWindow.isDisposed()) {
    return;
  }

  toolWindow.setIcon(FlutterIcons.Flutter_13);

  // Display a 'No running applications' message.
  final ContentManager contentManager = toolWindow.getContentManager();
  final JPanel panel = new JPanel(new BorderLayout());
  final JBLabel label = new JBLabel("No running applications", SwingConstants.CENTER);
  label.setForeground(UIUtil.getLabelDisabledForeground());
  panel.add(label, BorderLayout.CENTER);
  emptyContent = contentManager.getFactory().createContent(panel, null, false);
  contentManager.addContent(emptyContent);
}
 
Example 6
Source File: DesktopToolWindowImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
protected void init(boolean canCloseContent, @Nullable Object component) {
  final ContentFactory contentFactory = ContentFactory.getInstance();
  myContentUI = new DesktopToolWindowContentUi(this);
  ContentManager contentManager = myContentManager = contentFactory.createContentManager(myContentUI, canCloseContent, myToolWindowManager.getProject());

  if (component != null) {
    final Content content = contentFactory.createContent((JComponent)component, "", false);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content, false);
  }

  myComponent = contentManager.getComponent();

  DesktopInternalDecorator.installFocusTraversalPolicy(myComponent, new LayoutFocusTraversalPolicy());

  UiNotifyConnector notifyConnector = new UiNotifyConnector(myComponent, new Activatable() {
    @Override
    public void showNotify() {
      myShowing.onReady();
    }
  });
  Disposer.register(contentManager, notifyConnector);
}
 
Example 7
Source File: FlutterView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void updateForEmptyContent(ToolWindow toolWindow) {
  // There's a possible race here where the tool window gets disposed while we're displaying contents.
  if (toolWindow.isDisposed()) {
    return;
  }

  toolWindow.setIcon(FlutterIcons.Flutter_13);

  // Display a 'No running applications' message.
  final ContentManager contentManager = toolWindow.getContentManager();
  final JPanel panel = new JPanel(new BorderLayout());
  final JBLabel label = new JBLabel("No running applications", SwingConstants.CENTER);
  label.setForeground(UIUtil.getLabelDisabledForeground());
  panel.add(label, BorderLayout.CENTER);
  emptyContent = contentManager.getFactory().createContent(panel, null, false);
  contentManager.addContent(emptyContent);
}
 
Example 8
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 9
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 10
Source File: ConsoleLogToolWindowFactory.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
static void createContent(Project project, ToolWindow toolWindow, ConsoleLogConsole console, String title) {
    // update default Event Log tab title
    ContentManager contentManager = toolWindow.getContentManager();
    Content generalContent = contentManager.getContent(0);
    if (generalContent != null && contentManager.getContentCount() == 1) {
        generalContent.setDisplayName("General");
    }

    final Editor editor = console.getConsoleEditor();

    SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true) {
        @Override
        public Object getData(@NonNls String dataId) {
            return PlatformDataKeys.HELP_ID.is(dataId) ? ConsoleLog.HELP_ID : super.getData(dataId);
        }
    };
    panel.setContent(editor.getComponent());
    panel.addAncestorListener(new LogShownTracker(project));

    ActionToolbar toolbar = createToolbar(project, editor, console);
    toolbar.setTargetComponent(editor.getContentComponent());
    panel.setToolbar(toolbar.getComponent());

    Content content = ContentFactory.SERVICE.getInstance().createContent(panel, title, false);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content);
}
 
Example 11
Source File: SlingPluginToolWindowFactory.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
public void createToolWindowContent(final Project project, final ToolWindow toolWindow) {
    // Plugin is now placed into a Tabbed Pane to add additional views to it
    JBTabbedPane master = new JBTabbedPane(SwingConstants.BOTTOM);
    SlingPluginExplorer explorer = new SlingPluginExplorer(project);
    LOGGER.debug("CTWC: Explorer: '" + explorer + "'");
    master.insertTab("Plugin", null, explorer, "Plugin Windows", 0);

    WebContentFXPanel info = new WebContentFXPanel();
    master.insertTab("Info", null, info, "Plugin Info", 1);

    final AemdcPanel aemdcPanel = ComponentProvider.getComponent(project, AemdcPanel.class);
    LOGGER.debug("AEMDC Panel found: '{}'", aemdcPanel);
    aemdcPanel.setContainer(master);

    final ContentManager contentManager = toolWindow.getContentManager();
    final Content content = contentManager.getFactory().createContent(master, null, false);
    contentManager.addContent(content);
    Disposer.register(project, explorer);

    final ToolWindowManagerAdapter listener = new ToolWindowManagerAdapter() {
        boolean wasVisible = false;

        @Override
        public void stateChanged() {
            if (toolWindow.isDisposed()) {
                return;
            }
            boolean visible = toolWindow.isVisible();
            // If the Plugin became visible then we let the AEMDC Panel know to recrate the JFX Panel
            // to avoid the double buffering
            if(!wasVisible && visible) {
                aemdcPanel.reset();
            }
            wasVisible = visible;
        }
    };
    final ToolWindowManagerEx manager = ToolWindowManagerEx.getInstanceEx(project);
    manager.addToolWindowManagerListener(listener, project);
}
 
Example 12
Source File: UnifiedToolWindowImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
protected void init(boolean canCloseContent, @Nullable Object component) {
  final ContentFactory contentFactory = ContentFactory.getInstance();
  ContentManager contentManager = myContentManager = contentFactory.createContentManager(new UnifiedToolWindowContentUI(this), canCloseContent, myToolWindowManager.getProject());

  if (component != null) {
    final Content content = contentFactory.createUIContent((Component)component, "", false);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content, false);
  }

  myComponent = contentManager.getUIComponent();
}
 
Example 13
Source File: FlutterConsole.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Moves this console to the end of the tool window's tab list, selects it, and shows the tool window.
 */
void bringToFront() {
  // Move the tab to be last and select it.
  final MessageView messageView = MessageView.SERVICE.getInstance(project);
  final ContentManager contentManager = messageView.getContentManager();
  contentManager.addContent(content);
  contentManager.setSelectedContent(content);

  // Show the panel.
  final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW);
  if (toolWindow != null) {
    toolWindow.activate(null, true);
  }
}
 
Example 14
Source File: BPMNPaletteToolWindowManager.java    From intellij-bpmn-editor with GNU General Public License v3.0 5 votes vote down vote up
protected void initToolWindow() {
    toolWindow = ToolWindowManager.getInstance(myProject)
            .registerToolWindow("BPMN Palette", false, ToolWindowAnchor.RIGHT, myProject, true);
    toolWindow.setIcon(AllIcons.Toolwindows.ToolWindowPalette);

    ContentManager contentManager = toolWindow.getContentManager();
    Content content = contentManager.getFactory().createContent(palette, null, false);
    content.setCloseable(false);
    content.setPreferredFocusableComponent(palette);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content, true);
    toolWindow.setAvailable(false, null);
}
 
Example 15
Source File: EventLogToolWindowFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void createContent(Project project, ToolWindow toolWindow, EventLogConsole console, String title) {
  // update default Event Log tab title
  ContentManager contentManager = toolWindow.getContentManager();
  Content generalContent = contentManager.getContent(0);
  if (generalContent != null && contentManager.getContentCount() == 1) {
    generalContent.setDisplayName("General");
  }

  final Editor editor = console.getConsoleEditor();

  SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true) {
    @Override
    public Object getData(@Nonnull @NonNls Key dataId) {
      return PlatformDataKeys.HELP_ID == dataId ? EventLog.HELP_ID : super.getData(dataId);
    }
  };
  panel.setContent(editor.getComponent());
  panel.addAncestorListener(new LogShownTracker(project));

  ActionToolbar toolbar = createToolbar(project, editor, console);
  toolbar.setTargetComponent(editor.getContentComponent());
  panel.setToolbar(toolbar.getComponent());

  Content content = ContentFactory.getInstance().createContent(panel, title, false);
  contentManager.addContent(content);
  contentManager.setSelectedContent(content);
}
 
Example 16
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 17
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 18
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 19
Source File: LogviewFactory.java    From logviewer with Apache License 2.0 4 votes vote down vote up
@Override
public void createToolWindowContent(@NotNull final Project project, @NotNull final ToolWindow toolWindow) {

    final File adb = AndroidSdkUtils.getAdb(project);
    ExecutionManager.getInstance(project).getContentManager();

    RunnerLayoutUi layoutUi = RunnerLayoutUi.Factory.getInstance(project).create("LogViewer", TOOL_WINDOW_ID, "Logview Tools", project);

    toolWindow.setIcon(LogviewerPluginIcons.TOOL_ICON);
    toolWindow.setAvailable(true, null);
    toolWindow.setToHideOnEmptyContent(true);
    toolWindow.setTitle(TOOL_WINDOW_ID);


    DeviceContext deviceContext = new DeviceContext();

    Content logcatContent = createLogcatContent(layoutUi, project, deviceContext);
    final LogView logcatView = logcatContent.getUserData(LOG_VIEW_KEY);
    layoutUi.addContent(logcatContent, 0, PlaceInGrid.center, false);

    final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), project);
    loadingPanel.add(layoutUi.getComponent(), BorderLayout.CENTER);

    final ContentManager contentManager = toolWindow.getContentManager();
    Content c = contentManager.getFactory().createContent(loadingPanel, "", true);
    c.putUserData(LOG_VIEW_KEY, logcatView);
    contentManager.addContent(c);
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            logcatView.activate();
        }
    }, project.getDisposed());


    if (adb != null) {
        loadingPanel.setLoadingText("Initializing ADB");
        loadingPanel.startLoading();

        //ListenableFuture<AndroidDebugBridge> future = AdbService.getInstance().getDebugBridge(adb);
        ListenableFuture<AndroidDebugBridge> future = AdbBridgeFactory.getAdb(adb);
        Futures.addCallback(future, new FutureCallback<AndroidDebugBridge>() {
            @Override
            public void onSuccess(@Nullable AndroidDebugBridge bridge) {
                Logger.getInstance(LogviewFactory.class).info("Successfully obtained debug bridge");
                loadingPanel.stopLoading();
            }

            @Override
            public void onFailure(@NotNull Throwable t) {
                loadingPanel.stopLoading();
                Logger.getInstance(LogviewFactory.class).info("Unable to obtain debug bridge", t);
                String msg;
                if (t.getMessage() != null) {
                    msg = t.getMessage();
                } else {
                    msg = String.format("Unable to establish a connection to adb",
                            ApplicationNamesInfo.getInstance().getProductName(), adb.getAbsolutePath());
                }
                Messages.showErrorDialog(msg, "ADB Connection Error");
            }
        }, EdtExecutor.INSTANCE);
    } else {
        logcatView.showHint("No adb connection!.\n\nDrag and drop log files to view them.");
    }
}
 
Example 20
Source File: ContentsUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void addContent(final ContentManager manager, final Content content, final boolean select) {
  manager.addContent(content);
  if (select) {
    manager.setSelectedContent(content);
  }
}