Search in sources :

Example 1 with ContentManagerAdapter

use of com.intellij.ui.content.ContentManagerAdapter in project intellij-community by JetBrains.

the class JavaDebugProcess method createTabLayouter.

@NotNull
@Override
public XDebugTabLayouter createTabLayouter() {
    return new XDebugTabLayouter() {

        @Override
        public void registerAdditionalContent(@NotNull RunnerLayoutUi ui) {
            registerThreadsPanel(ui);
            registerMemoryViewPanel(ui);
        }

        @NotNull
        @Override
        public Content registerConsoleContent(@NotNull RunnerLayoutUi ui, @NotNull ExecutionConsole console) {
            Content content = null;
            if (console instanceof ExecutionConsoleEx) {
                ((ExecutionConsoleEx) console).buildUi(ui);
                content = ui.findContent(DebuggerContentInfo.CONSOLE_CONTENT);
            }
            if (content == null) {
                content = super.registerConsoleContent(ui, console);
            }
            return content;
        }

        private void registerThreadsPanel(@NotNull RunnerLayoutUi ui) {
            final ThreadsPanel panel = new ThreadsPanel(myJavaSession.getProject(), getDebuggerStateManager());
            final Content threadsContent = ui.createContent(DebuggerContentInfo.THREADS_CONTENT, panel, XDebuggerBundle.message("debugger.session.tab.threads.title"), AllIcons.Debugger.Threads, null);
            Disposer.register(threadsContent, panel);
            threadsContent.setCloseable(false);
            ui.addContent(threadsContent, 0, PlaceInGrid.left, true);
            ui.addListener(new ContentManagerAdapter() {

                @Override
                public void selectionChanged(ContentManagerEvent event) {
                    if (event.getContent() == threadsContent) {
                        if (threadsContent.isSelected()) {
                            panel.setUpdateEnabled(true);
                            if (panel.isRefreshNeeded()) {
                                panel.rebuildIfVisible(DebuggerSession.Event.CONTEXT);
                            }
                        } else {
                            panel.setUpdateEnabled(false);
                        }
                    }
                }
            }, threadsContent);
        }

        private void registerMemoryViewPanel(@NotNull RunnerLayoutUi ui) {
            final XDebugSession session = getSession();
            final DebugProcessImpl process = myJavaSession.getProcess();
            final InstancesTracker tracker = InstancesTracker.getInstance(myJavaSession.getProject());
            final ClassesFilteredView classesFilteredView = new ClassesFilteredView(session, process, tracker);
            final Content memoryViewContent = ui.createContent(MemoryViewManager.MEMORY_VIEW_CONTENT, classesFilteredView, "Memory View", AllIcons.Debugger.MemoryView.Active, null);
            memoryViewContent.setCloseable(false);
            memoryViewContent.setPinned(true);
            memoryViewContent.setShouldDisposeContent(true);
            final MemoryViewDebugProcessData data = new MemoryViewDebugProcessData(classesFilteredView);
            process.putUserData(MemoryViewDebugProcessData.KEY, data);
            ui.addListener(new ContentManagerAdapter() {

                @Override
                public void contentAdded(ContentManagerEvent event) {
                    changeMemoryViewMode(event);
                }

                @Override
                public void contentRemoved(ContentManagerEvent event) {
                    changeMemoryViewMode(event);
                }

                @Override
                public void selectionChanged(ContentManagerEvent event) {
                    changeMemoryViewMode(event);
                }

                private void changeMemoryViewMode(@Nullable ContentManagerEvent event) {
                    if (event != null && event.getContent() == memoryViewContent) {
                        final ContentManagerEvent.ContentOperation operation = event.getOperation();
                        final boolean isAddOperation = operation.equals(ContentManagerEvent.ContentOperation.add);
                        if (isAddOperation || operation.equals(ContentManagerEvent.ContentOperation.remove)) {
                            classesFilteredView.setActive(isAddOperation, process.getManagerThread());
                        }
                    }
                }
            }, classesFilteredView);
            ui.addContent(memoryViewContent, 0, PlaceInGrid.right, true);
        }
    };
}
Also used : ThreadsPanel(com.intellij.debugger.ui.impl.ThreadsPanel) InstancesTracker(com.intellij.debugger.memory.component.InstancesTracker) ContentManagerAdapter(com.intellij.ui.content.ContentManagerAdapter) NotNull(org.jetbrains.annotations.NotNull) ClassesFilteredView(com.intellij.debugger.memory.ui.ClassesFilteredView) MemoryViewDebugProcessData(com.intellij.debugger.memory.component.MemoryViewDebugProcessData) RunnerLayoutUi(com.intellij.execution.ui.RunnerLayoutUi) Content(com.intellij.ui.content.Content) XDebugTabLayouter(com.intellij.xdebugger.ui.XDebugTabLayouter) ExecutionConsole(com.intellij.execution.ui.ExecutionConsole) ExecutionConsoleEx(com.intellij.execution.ui.ExecutionConsoleEx) ContentManagerEvent(com.intellij.ui.content.ContentManagerEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ContentManagerAdapter

use of com.intellij.ui.content.ContentManagerAdapter in project intellij-community by JetBrains.

the class PreviewManagerImpl method checkGlobalState.

protected void checkGlobalState() {
    ToolWindowManagerImpl toolWindowManager = (ToolWindowManagerImpl) ToolWindowManager.getInstance(myProject);
    if (!isAvailable() && toolWindowManager.getToolWindow(ToolWindowId.PREVIEW) != null) {
        myHistory.clear();
        myContentManager.removeAllContents(true);
        toolWindowManager.unregisterToolWindow(ToolWindowId.PREVIEW);
        return;
    }
    if (isAvailable() && toolWindowManager.getToolWindow(ToolWindowId.PREVIEW) == null) {
        myToolWindow = (ToolWindowImpl) toolWindowManager.registerToolWindow(ToolWindowId.PREVIEW, myEmptyStatePanel, ToolWindowAnchor.RIGHT, myProject, false);
        myContentManager = myToolWindow.getContentManager();
        myToolWindow.setIcon(AllIcons.Toolwindows.ToolWindowPreview);
        myToolWindow.setContentUiType(ToolWindowContentUiType.COMBO, null);
        myToolWindow.setAutoHide(true);
        myEmptyStateContent = myContentManager.getContent(0);
        final MoveToStandardViewAction moveToStandardViewAction = new MoveToStandardViewAction();
        myContentManager.addContentManagerListener(new ContentManagerAdapter() {

            @Override
            public void selectionChanged(ContentManagerEvent event) {
                if (myInnerSelectionChange || event.getOperation() != ContentManagerEvent.ContentOperation.add)
                    return;
                PreviewInfo previewInfo = event.getContent().getUserData(INFO_KEY);
                if (previewInfo != null) {
                    preview(previewInfo, false);
                    myToolWindow.setTitleActions(previewInfo.supportsStandardPlace() ? moveToStandardViewAction : null);
                }
            }
        });
        moveToStandardViewAction.registerCustomShortcutSet(new ShortcutSet() {

            @NotNull
            @Override
            public Shortcut[] getShortcuts() {
                Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
                return keymap.getShortcuts("ShowContent");
            }
        }, myToolWindow.getComponent());
        myToolWindow.setTitleActions(moveToStandardViewAction);
        ArrayList<AnAction> myGearActions = new ArrayList<>();
        for (PreviewPanelProvider provider : myProviders) {
            myGearActions.add(new ContentTypeToggleAction(provider));
        }
        myToolWindow.setAdditionalGearActions(new DefaultActionGroup("Preview", myGearActions));
        myToolWindow.activate(() -> myToolWindow.activate(null));
    }
}
Also used : ToolWindowManagerImpl(com.intellij.openapi.wm.impl.ToolWindowManagerImpl) PreviewPanelProvider(com.intellij.openapi.preview.PreviewPanelProvider) ContentManagerAdapter(com.intellij.ui.content.ContentManagerAdapter) NotNull(org.jetbrains.annotations.NotNull) PreviewInfo(com.intellij.openapi.preview.PreviewInfo) ContentManagerEvent(com.intellij.ui.content.ContentManagerEvent) Keymap(com.intellij.openapi.keymap.Keymap)

Example 3 with ContentManagerAdapter

use of com.intellij.ui.content.ContentManagerAdapter in project android by JetBrains.

the class AndroidToolWindowFactory method createToolWindowContent.

@Override
public void createToolWindowContent(@NotNull final Project project, @NotNull final ToolWindow toolWindow) {
    // In order to use the runner layout ui, the runner infrastructure needs to be initialized.
    // Otherwise it is not possible to for example drag one of the tabs out of the tool window.
    // The object that needs to be created is the content manager of the execution manager for this project.
    ExecutionManager.getInstance(project).getContentManager();
    RunnerLayoutUi layoutUi = RunnerLayoutUi.Factory.getInstance(project).create("Android", TOOL_WINDOW_ID, "Profiling Tools", project);
    toolWindow.setIcon(AndroidIcons.AndroidToolWindow);
    toolWindow.setAvailable(true, null);
    toolWindow.setToHideOnEmptyContent(true);
    toolWindow.setTitle(TOOL_WINDOW_ID);
    DeviceContext deviceContext = new DeviceContext();
    // TODO Remove global handlers. These handlers are global, but are set per project.
    // if there are two projects opened, things go very wrong.
    ClientData.setMethodProfilingHandler(new OpenVmTraceHandler(project));
    Content logcatContent = createLogcatContent(layoutUi, project, deviceContext);
    final AndroidLogcatView logcatView = logcatContent.getUserData(AndroidLogcatView.ANDROID_LOGCAT_VIEW_KEY);
    assert logcatView != null;
    logcatContent.setSearchComponent(logcatView.createSearchComponent());
    layoutUi.addContent(logcatContent, 0, PlaceInGrid.center, false);
    MonitorContentFactory.createMonitorContent(project, deviceContext, layoutUi);
    layoutUi.getOptions().setLeftToolbar(getToolbarActions(project, deviceContext), ActionPlaces.UNKNOWN);
    layoutUi.addListener(new ContentManagerAdapter() {

        @Override
        public void selectionChanged(ContentManagerEvent event) {
            Content selectedContent = event.getContent();
            BaseMonitorView view = selectedContent.getUserData(BaseMonitorView.MONITOR_VIEW_KEY);
            if (view != null && event.getOperation() == ContentManagerEvent.ContentOperation.add) {
                UsageTracker.getInstance().log(AndroidStudioEvent.newBuilder().setCategory(AndroidStudioEvent.EventCategory.PROFILING).setKind(AndroidStudioEvent.EventKind.MONITOR_RUNNING).setMonitorType(view.getMonitorType()));
            }
        }
    }, project);
    final JBLoadingPanel loadingPanel = new JBLoadingPanel(new BorderLayout(), project);
    DevicePanel devicePanel = new DevicePanel(project, deviceContext);
    JPanel panel = devicePanel.getComponent();
    panel.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
    loadingPanel.add(panel, BorderLayout.NORTH);
    loadingPanel.add(layoutUi.getComponent(), BorderLayout.CENTER);
    final ContentManager contentManager = toolWindow.getContentManager();
    Content c = contentManager.getFactory().createContent(loadingPanel, "", true);
    // Store references to the logcat & device panel views, so that these views can be retrieved directly from
    // the DDMS tool window. (e.g. to clear logcat before a launch, select a particular device, etc)
    c.putUserData(AndroidLogcatView.ANDROID_LOGCAT_VIEW_KEY, logcatView);
    c.putUserData(DEVICES_PANEL_KEY, devicePanel);
    contentManager.addContent(c);
    ApplicationManager.getApplication().invokeLater(new Runnable() {

        @Override
        public void run() {
            logcatView.activate();
            final ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(TOOL_WINDOW_ID);
            if (window != null && window.isVisible()) {
                ConsoleView console = logcatView.getLogConsole().getConsole();
                if (console != null) {
                    checkFacetAndSdk(project, console);
                }
            }
        }
    }, project.getDisposed());
    final File adb = AndroidSdkUtils.getAdb(project);
    if (adb == null) {
        return;
    }
    loadingPanel.setLoadingText("Initializing ADB");
    loadingPanel.startLoading();
    ListenableFuture<AndroidDebugBridge> future = AdbService.getInstance().getDebugBridge(adb);
    Futures.addCallback(future, new FutureCallback<AndroidDebugBridge>() {

        @Override
        public void onSuccess(@Nullable AndroidDebugBridge bridge) {
            Logger.getInstance(AndroidToolWindowFactory.class).info("Successfully obtained debug bridge");
            loadingPanel.stopLoading();
        }

        @Override
        public void onFailure(@NotNull Throwable t) {
            loadingPanel.stopLoading();
            // If we cannot connect to ADB in a reasonable amount of time (10 seconds timeout in AdbService), then something is seriously
            // wrong. The only identified reason so far is that some machines have incompatible versions of adb that were already running.
            // e.g. Genymotion, some HTC flashing software, Ubuntu's adb package may all conflict with the version of adb in the SDK.
            Logger.getInstance(AndroidToolWindowFactory.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.\n\n" + "Check the Event Log for possible issues.\n" + "This can happen if you have an incompatible version of adb running already.\n" + "Try re-opening %1$s after killing any existing adb daemons.\n\n" + "If this happens repeatedly, please file a bug at http://b.android.com including the following:\n" + "  1. Output of the command: '%2$s devices'\n" + "  2. Your idea.log file (Help | Show Log in Explorer)\n", ApplicationNamesInfo.getInstance().getProductName(), adb.getAbsolutePath());
            }
            Messages.showErrorDialog(msg, "ADB Connection Error");
        }
    }, EdtExecutor.INSTANCE);
}
Also used : ConsoleView(com.intellij.execution.ui.ConsoleView) ContentManager(com.intellij.ui.content.ContentManager) ContentManagerAdapter(com.intellij.ui.content.ContentManagerAdapter) AndroidLogcatView(com.android.tools.idea.logcat.AndroidLogcatView) ToolWindow(com.intellij.openapi.wm.ToolWindow) RunnerLayoutUi(com.intellij.execution.ui.RunnerLayoutUi) DeviceContext(com.android.tools.idea.ddms.DeviceContext) Content(com.intellij.ui.content.Content) DevicePanel(com.android.tools.idea.ddms.DevicePanel) OpenVmTraceHandler(com.android.tools.idea.ddms.OpenVmTraceHandler) JBLoadingPanel(com.intellij.ui.components.JBLoadingPanel) File(java.io.File) ContentManagerEvent(com.intellij.ui.content.ContentManagerEvent) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 4 with ContentManagerAdapter

use of com.intellij.ui.content.ContentManagerAdapter in project flutter-intellij by flutter.

the class ObservatoryActionGroup method listenForRenderTreeActivations.

private static void listenForRenderTreeActivations(@NotNull ToolWindow toolWindow) {
    final ContentManager contentManager = toolWindow.getContentManager();
    contentManager.addContentManagerListener(new ContentManagerAdapter() {

        @Override
        public void selectionChanged(ContentManagerEvent event) {
            final ContentManagerEvent.ContentOperation operation = event.getOperation();
            if (operation == ContentManagerEvent.ContentOperation.add) {
                final String name = event.getContent().getTabName();
                if (Objects.equals(name, RENDER_TREE_LABEL)) {
                    FlutterInitializer.getAnalytics().sendEvent("inspector", "renderTreeSelected");
                } else if (Objects.equals(name, WIDGET_TREE_LABEL)) {
                    FlutterInitializer.getAnalytics().sendEvent("inspector", "widgetTreeSelected");
                }
            }
        }
    });
}
Also used : ContentManager(com.intellij.ui.content.ContentManager) ContentManagerAdapter(com.intellij.ui.content.ContentManagerAdapter) ContentManagerEvent(com.intellij.ui.content.ContentManagerEvent)

Example 5 with ContentManagerAdapter

use of com.intellij.ui.content.ContentManagerAdapter in project intellij-community by JetBrains.

the class ProjectViewImpl method setupImpl.

// public for tests
public synchronized void setupImpl(@NotNull ToolWindow toolWindow, final boolean loadPaneExtensions) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    myActionGroup = new DefaultActionGroup();
    myAutoScrollFromSourceHandler.install();
    myContentManager = toolWindow.getContentManager();
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        toolWindow.setDefaultContentUiType(ToolWindowContentUiType.COMBO);
        ((ToolWindowEx) toolWindow).setAdditionalGearActions(myActionGroup);
        toolWindow.getComponent().putClientProperty(ToolWindowContentUi.HIDE_ID_LABEL, "true");
    }
    GuiUtils.replaceJSplitPaneWithIDEASplitter(myPanel);
    SwingUtilities.invokeLater(() -> splitterProportions.restoreSplitterProportions(myPanel));
    if (loadPaneExtensions) {
        ensurePanesLoaded();
    }
    isInitialized = true;
    doAddUninitializedPanes();
    getContentManager().addContentManagerListener(new ContentManagerAdapter() {

        @Override
        public void selectionChanged(ContentManagerEvent event) {
            if (event.getOperation() == ContentManagerEvent.ContentOperation.add) {
                viewSelectionChanged();
            }
        }
    });
    viewSelectionChanged();
}
Also used : ToolWindowEx(com.intellij.openapi.wm.ex.ToolWindowEx) ContentManagerAdapter(com.intellij.ui.content.ContentManagerAdapter) ContentManagerEvent(com.intellij.ui.content.ContentManagerEvent)

Aggregations

ContentManagerAdapter (com.intellij.ui.content.ContentManagerAdapter)8 ContentManagerEvent (com.intellij.ui.content.ContentManagerEvent)8 RunnerLayoutUi (com.intellij.execution.ui.RunnerLayoutUi)2 ToolWindow (com.intellij.openapi.wm.ToolWindow)2 Content (com.intellij.ui.content.Content)2 ContentManager (com.intellij.ui.content.ContentManager)2 NotNull (org.jetbrains.annotations.NotNull)2 AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)1 DeviceContext (com.android.tools.idea.ddms.DeviceContext)1 DevicePanel (com.android.tools.idea.ddms.DevicePanel)1 OpenVmTraceHandler (com.android.tools.idea.ddms.OpenVmTraceHandler)1 AndroidLogcatView (com.android.tools.idea.logcat.AndroidLogcatView)1 InstancesTracker (com.intellij.debugger.memory.component.InstancesTracker)1 MemoryViewDebugProcessData (com.intellij.debugger.memory.component.MemoryViewDebugProcessData)1 ClassesFilteredView (com.intellij.debugger.memory.ui.ClassesFilteredView)1 ThreadsPanel (com.intellij.debugger.ui.impl.ThreadsPanel)1 RunConfigurationBase (com.intellij.execution.configurations.RunConfigurationBase)1 ConsoleView (com.intellij.execution.ui.ConsoleView)1 ExecutionConsole (com.intellij.execution.ui.ExecutionConsole)1 ExecutionConsoleEx (com.intellij.execution.ui.ExecutionConsoleEx)1