void (final Runnable r) { ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(TOOL_WINDOW_ID); if (toolWindow == null) return; MavenUtil.invokeLater(myProject, () -> { boolean hasMavenProjects = !MavenProjectsManager.getInstance(myProject).getProjects().isEmpty(); if (toolWindow.isAvailable() != hasMavenProjects) { toolWindow.setAvailable(hasMavenProjects); if (hasMavenProjects && myProject.getUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT) == null) { toolWindow.activate(null); } } boolean shouldCreate = myStructure == null; if (shouldCreate) { initStructure(); } r.run(); if (shouldCreate) { TreeState.createFrom(myState.treeState).applyTo(myTree); } }); }