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

The following examples show how to use com.intellij.ui.content.Content#putUserData() . 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: RunnerLayoutUiImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public Content createContent(@Nonnull final String contentId, @Nonnull final ComponentWithActions withActions, @Nonnull final String displayName,
                             @Nullable final Image icon,
                             @Nullable final JComponent toFocus) {
  final Content content = getContentFactory().createContent(withActions.getComponent(), displayName, false);
  content.putUserData(CONTENT_TYPE, contentId);
  content.putUserData(ViewImpl.ID, contentId);
  content.setIcon(icon);
  if (toFocus != null) {
    content.setPreferredFocusableComponent(toFocus);
  }

  if (!withActions.isContentBuiltIn()) {
    content.setSearchComponent(withActions.getSearchComponent());
    content.setActions(withActions.getToolbarActions(), withActions.getToolbarPlace(), withActions.getToolbarContextComponent());
  }

  return content;
}
 
Example 2
Source File: RoutesView.java    From railways with MIT License 5 votes vote down vote up
public void addModulePane(Module module) {
    // Skip if RoutesView is not initialized or if added module is not
    // Rails application.
    RailsApp railsApp = RailsApp.fromModule(module);
    if ((myContentManager == null) || railsApp == null)
        return;

    // Register content, so we'll have a combo-box instead tool window
    // title, and each item will represent a module.
    String contentTitle = module.getName();
    Content content = myContentManager.getFactory().createContent(getComponent(),
            contentTitle, false);
    content.setTabName(contentTitle);
    content.setIcon(ModuleType.get(module).getIcon());

    // Set tool window icon to be the same as selected module icon
    content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
    myContentManager.addContent(content);

    // Bind content with pane for further use
    RoutesViewPane pane = new RoutesViewPane(railsApp, myToolWindow, content);
    myPanes.add(pane);

    // Register contributor
    ChooseByRouteRegistry.getInstance(myProject)
            .addContributorFor(pane.getRoutesManager());

    // Subscribe to RoutesManager events.
    pane.getRoutesManager().addListener(new MyRoutesManagerListener());

    // And select pane if it's the first one.
    if (myPanes.size() == 1)
        setCurrentPane(pane);
}
 
Example 3
Source File: RunnerLayout.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static String getOrCreateContentId(@Nonnull Content content) {
  @NonNls String id = content.getUserData(ViewImpl.ID);
  if (id == null) {
    id = "UnknownView-" + content.getDisplayName();
    content.putUserData(ViewImpl.ID, id);
  }
  return id;
}
 
Example 4
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 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: 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 7
Source File: UsageViewManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
void addContent(@Nonnull UsageViewImpl usageView, @Nonnull UsageViewPresentation presentation) {
  Content content = com.intellij.usageView.UsageViewManager.getInstance(myProject)
          .addContent(presentation.getTabText(), presentation.getTabName(), presentation.getToolwindowTitle(), true, usageView.getComponent(), presentation.isOpenInNewTab(), true);
  usageView.setContent(content);
  content.putUserData(USAGE_VIEW_KEY, usageView);
}
 
Example 8
Source File: ContentUtilEx.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void addTabbedContent(@Nonnull ContentManager manager,
                                    @Nonnull JComponent contentComponent,
                                    @Nonnull String groupPrefix,
                                    @Nonnull String tabName,
                                    boolean select,
                                    @Nullable Disposable childDisposable) {
  if (PropertiesComponent.getInstance().getBoolean(TabbedContent.SPLIT_PROPERTY_PREFIX + groupPrefix)) {
    final Content content = ContentFactory.getInstance().createContent(contentComponent, getFullName(groupPrefix, tabName), true);
    content.putUserData(Content.TABBED_CONTENT_KEY, Boolean.TRUE);
    content.putUserData(Content.TAB_GROUP_NAME_KEY, groupPrefix);

    for (Content c : manager.getContents()) {
      if (c.getComponent() == contentComponent) {
        if (select) {
          manager.setSelectedContent(c);
        }
        return;
      }
    }
    addContent(manager, content, select);

    registerDisposable(content, childDisposable, contentComponent);

    return;
  }

  TabbedContent tabbedContent = findTabbedContent(manager, groupPrefix);

  if (tabbedContent == null) {
    final Disposable disposable = Disposable.newDisposable();
    tabbedContent = new TabbedContentImpl(contentComponent, tabName, true, groupPrefix);
    ContentsUtil.addOrReplaceContent(manager, tabbedContent, select);
    Disposer.register(tabbedContent, disposable);
  }
  else {
    for (Pair<String, JComponent> tab : new ArrayList<>(tabbedContent.getTabs())) {
      if (Comparing.equal(tab.second, contentComponent)) {
        tabbedContent.removeContent(tab.second);
      }
    }
    if (select) {
      manager.setSelectedContent(tabbedContent, true, true);
    }
    tabbedContent.addContent(contentComponent, tabName, true);
  }

  registerDisposable(tabbedContent, childDisposable, contentComponent);
}