Search in sources :

Example 1 with ToolWindowManagerAdapter

use of com.intellij.openapi.wm.ex.ToolWindowManagerAdapter in project intellij-leiningen-plugin by derkork.

the class LeiningenProjectNavigator method addPanel.

private void addPanel() {
    initTree();
    myStructure = new LeiningenProjectStructure(myProject, myProjectsManager, myTree);
    JPanel panel = new LeiningenProjectNavigatorPanel(myProject, myTree);
    final ToolWindowManagerEx manager = ToolWindowManagerEx.getInstanceEx(myProject);
    myToolWindow = manager.registerToolWindow(TOOL_WINDOW_ID, panel, ToolWindowAnchor.RIGHT, myProject, true);
    myToolWindow.setIcon(LeiningenIcons.PROJECT_ICON);
    final ToolWindowManagerAdapter listener = new ToolWindowManagerAdapter() {

        boolean wasVisible = false;

        @Override
        public void stateChanged() {
            if (myToolWindow.isDisposed())
                return;
            boolean visible = myToolWindow.isVisible();
            if (!visible || visible == wasVisible)
                return;
            scheduleStructureUpdate();
            wasVisible = visible;
        }
    };
    manager.addToolWindowManagerListener(listener);
    Disposer.register(myProject, new Disposable() {

        public void dispose() {
            manager.removeToolWindowManagerListener(listener);
        }
    });
    scheduleStructureUpdate();
}
Also used : Disposable(com.intellij.openapi.Disposable) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx)

Example 2 with ToolWindowManagerAdapter

use of com.intellij.openapi.wm.ex.ToolWindowManagerAdapter in project intellij-community by JetBrains.

the class ExternalProjectsViewImpl method init.

public void init() {
    Disposer.register(myProject, this);
    initTree();
    final ToolWindowManagerEx manager = ToolWindowManagerEx.getInstanceEx(myProject);
    final ToolWindowManagerAdapter listener = new ToolWindowManagerAdapter() {

        boolean wasVisible = false;

        @Override
        public void stateChanged() {
            if (myToolWindow.isDisposed())
                return;
            boolean visible = myToolWindow.isVisible();
            if (!visible || wasVisible) {
                wasVisible = visible;
                return;
            }
            scheduleStructureUpdate();
            wasVisible = true;
        }
    };
    manager.addToolWindowManagerListener(listener, myProject);
    getShortcutsManager().addListener(new ExternalSystemShortcutsManager.Listener() {

        @Override
        public void shortcutsUpdated() {
            scheduleTasksUpdate();
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                myStructure.updateNodes(RunConfigurationNode.class);
            });
        }
    });
    getTaskActivator().addListener(new ExternalSystemTaskActivator.Listener() {

        @Override
        public void tasksActivationChanged() {
            scheduleTasksUpdate();
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                myStructure.updateNodes(RunConfigurationNode.class);
            });
        }
    });
    ((RunManagerEx) RunManager.getInstance(myProject)).addRunManagerListener(new RunManagerListener() {

        private void changed() {
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                myStructure.visitNodes(ModuleNode.class, node -> node.updateRunConfigurations());
            });
        }

        @Override
        public void runConfigurationAdded(@NotNull RunnerAndConfigurationSettings settings) {
            changed();
        }

        @Override
        public void runConfigurationRemoved(@NotNull RunnerAndConfigurationSettings settings) {
            changed();
        }

        @Override
        public void runConfigurationChanged(@NotNull RunnerAndConfigurationSettings settings) {
            changed();
        }
    });
    ExternalSystemApiUtil.subscribe(myProject, myExternalSystemId, new ExternalSystemSettingsListenerAdapter() {

        @Override
        public void onUseAutoImportChange(boolean currentValue, @NotNull final String linkedProjectPath) {
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                final List<ProjectNode> projectNodes = myStructure.getNodes(ProjectNode.class);
                for (ProjectNode projectNode : projectNodes) {
                    final ProjectData projectData = projectNode.getData();
                    if (projectData != null && projectData.getLinkedExternalProjectPath().equals(linkedProjectPath)) {
                        projectNode.updateProject();
                        break;
                    }
                }
            });
        }
    });
    myToolWindow.setAdditionalGearActions(createAdditionalGearActionsGroup());
    scheduleStructureUpdate();
}
Also used : ExternalSystemTaskActivator(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator) ProjectDataManager(com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) TreeState(com.intellij.ide.util.treeView.TreeState) PopupHandler(com.intellij.ui.PopupHandler) ExternalSystemApiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil) SmartList(com.intellij.util.SmartList) Disposer(com.intellij.openapi.util.Disposer) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) Nullable(org.jetbrains.annotations.Nullable) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) List(java.util.List) SimpleTree(com.intellij.ui.treeStructure.SimpleTree) ApplicationManager(com.intellij.openapi.application.ApplicationManager) WriteExternalException(com.intellij.openapi.util.WriteExternalException) NotNull(org.jetbrains.annotations.NotNull) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) InputEvent(java.awt.event.InputEvent) java.util(java.util) ExternalSystemActionUtil(com.intellij.openapi.externalSystem.action.ExternalSystemActionUtil) ExternalSystemTaskActivator(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator) ExternalSystemViewGearAction(com.intellij.openapi.externalSystem.action.ExternalSystemViewGearAction) NonNls(org.jetbrains.annotations.NonNls) ExternalSystemShortcutsManager(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemShortcutsManager) InvalidDataException(com.intellij.openapi.util.InvalidDataException) ContainerUtil(com.intellij.util.containers.ContainerUtil) ExternalProjectsManager(com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager) NotificationGroup(com.intellij.notification.NotificationGroup) Project(com.intellij.openapi.project.Project) ExternalSystemUiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil) com.intellij.openapi.externalSystem.model(com.intellij.openapi.externalSystem.model) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) DisposeAwareRunnable(com.intellij.util.DisposeAwareRunnable) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) ExternalSystemUiAware(com.intellij.openapi.externalSystem.ExternalSystemUiAware) ExternalSystemTaskLocation(com.intellij.openapi.externalSystem.service.execution.ExternalSystemTaskLocation) Disposable(com.intellij.openapi.Disposable) com.intellij.execution(com.intellij.execution) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) ToolWindowEx(com.intellij.openapi.wm.ex.ToolWindowEx) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) ToolWindowImpl(com.intellij.openapi.wm.impl.ToolWindowImpl) Navigatable(com.intellij.pom.Navigatable) Element(org.jdom.Element) ScrollPaneFactory(com.intellij.ui.ScrollPaneFactory) ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) ExternalSystemShortcutsManager(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemShortcutsManager) SmartList(com.intellij.util.SmartList) List(java.util.List) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 3 with ToolWindowManagerAdapter

use of com.intellij.openapi.wm.ex.ToolWindowManagerAdapter in project android by JetBrains.

the class AndroidThemePreviewToolWindowManager method initToolWindow.

private void initToolWindow() {
    myToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(TOOL_WINDOW_ID, false, ToolWindowAnchor.RIGHT, myProject, false);
    myToolWindow.setIcon(AndroidIcons.ThemesPreview);
    myToolWindow.setAvailable(false, null);
    myToolWindow.setAutoHide(false);
    // Add a listener so we only update the preview when it's visible
    ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject)).addToolWindowManagerListener(new ToolWindowManagerAdapter() {

        @Override
        public void stateChanged() {
            if (myProject.isDisposed()) {
                return;
            }
            final ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(TOOL_WINDOW_ID);
            if (window != null && window.isAvailable()) {
                final boolean visible = window.isVisible();
                AndroidEditorSettings.getInstance().getGlobalState().setVisible(visible);
                if (visible && !myIsToolWindowVisible) {
                    updatePreview();
                }
                myIsToolWindowVisible = visible;
            }
        }
    });
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx)

Example 4 with ToolWindowManagerAdapter

use of com.intellij.openapi.wm.ex.ToolWindowManagerAdapter in project android by JetBrains.

the class NlPreviewManager method initToolWindow.

protected void initToolWindow() {
    myToolWindowForm = new NlPreviewForm(this);
    final String toolWindowId = getToolWindowId();
    myToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(toolWindowId, false, ToolWindowAnchor.RIGHT, myProject, true);
    myToolWindow.setIcon(AndroidIcons.AndroidPreview);
    ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject)).addToolWindowManagerListener(new ToolWindowManagerAdapter() {

        @Override
        public void stateChanged() {
            if (myProject.isDisposed()) {
                return;
            }
            final ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(toolWindowId);
            if (window != null && window.isAvailable()) {
                final boolean visible = window.isVisible();
                AndroidEditorSettings.getInstance().getGlobalState().setVisible(visible);
                if (myToolWindowForm != null) {
                    if (visible) {
                        myToolWindowForm.activate();
                    } else {
                        myToolWindowForm.deactivate();
                    }
                }
            }
        }
    });
    final JComponent contentPanel = myToolWindowForm.getComponent();
    final ContentManager contentManager = myToolWindow.getContentManager();
    @SuppressWarnings("ConstantConditions") final Content content = contentManager.getFactory().createContent(contentPanel, null, false);
    content.setDisposer(myToolWindowForm);
    content.setCloseable(false);
    content.setPreferredFocusableComponent(contentPanel);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content, true);
    myToolWindow.setAvailable(false, null);
    myToolWindowForm.setUseInteractiveSelector(isUseInteractiveSelector());
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) Content(com.intellij.ui.content.Content) ContentManager(com.intellij.ui.content.ContentManager) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx)

Example 5 with ToolWindowManagerAdapter

use of com.intellij.openapi.wm.ex.ToolWindowManagerAdapter in project intellij-community by JetBrains.

the class RunContentManagerImpl method init.

// must be called on EDT
private void init() {
    ToolWindowManagerEx toolWindowManager = ToolWindowManagerEx.getInstanceEx(myProject);
    if (toolWindowManager == null) {
        return;
    }
    for (Executor executor : ExecutorRegistry.getInstance().getRegisteredExecutors()) {
        registerToolWindow(executor, toolWindowManager);
    }
    RunDashboardManager dashboardManager = RunDashboardManager.getInstance(myProject);
    initToolWindow(null, dashboardManager.getToolWindowId(), dashboardManager.getToolWindowIcon(), dashboardManager.getDashboardContentManager());
    toolWindowManager.addToolWindowManagerListener(new ToolWindowManagerAdapter() {

        @Override
        public void stateChanged() {
            if (myProject.isDisposed()) {
                return;
            }
            ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
            Set<String> currentWindows = new THashSet<>();
            ContainerUtil.addAll(currentWindows, toolWindowManager.getToolWindowIds());
            myToolwindowIdZBuffer.retainAll(currentWindows);
            final String activeToolWindowId = toolWindowManager.getActiveToolWindowId();
            if (activeToolWindowId != null) {
                if (myToolwindowIdZBuffer.remove(activeToolWindowId)) {
                    myToolwindowIdZBuffer.addFirst(activeToolWindowId);
                }
            }
        }
    });
}
Also used : THashSet(gnu.trove.THashSet) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) RunDashboardManager(com.intellij.execution.dashboard.RunDashboardManager) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx)

Aggregations

ToolWindowManagerAdapter (com.intellij.openapi.wm.ex.ToolWindowManagerAdapter)10 ToolWindowManagerEx (com.intellij.openapi.wm.ex.ToolWindowManagerEx)9 ToolWindow (com.intellij.openapi.wm.ToolWindow)5 Content (com.intellij.ui.content.Content)5 ContentManager (com.intellij.ui.content.ContentManager)3 Disposable (com.intellij.openapi.Disposable)2 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)2 AndroidLogcatView (com.android.tools.idea.logcat.AndroidLogcatView)1 LightToolWindow (com.intellij.designer.LightToolWindow)1 com.intellij.execution (com.intellij.execution)1 RunDashboardManager (com.intellij.execution.dashboard.RunDashboardManager)1 ConsoleView (com.intellij.execution.ui.ConsoleView)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 TreeState (com.intellij.ide.util.treeView.TreeState)1 NotificationGroup (com.intellij.notification.NotificationGroup)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ModalityState (com.intellij.openapi.application.ModalityState)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ExternalSystemUiAware (com.intellij.openapi.externalSystem.ExternalSystemUiAware)1