@Nullable public static GradleProjectStructureTreeModel getProjectStructureTreeModel( @NotNull Project project) { final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project); final ToolWindow toolWindow = toolWindowManager.getToolWindow(GradleConstants.TOOL_WINDOW_ID); if (toolWindow == null) { return null; } final ContentManager contentManager = toolWindow.getContentManager(); if (contentManager == null) { return null; } for (Content content : contentManager.getContents()) { final JComponent component = content.getComponent(); if (component instanceof DataProvider) { final Object data = ((DataProvider) component).getData(GradleDataKeys.SYNC_TREE_MODEL.getName()); if (data instanceof GradleProjectStructureTreeModel) { return (GradleProjectStructureTreeModel) data; } } } return null; }
/** * Tries to find the current {@link GradleProjectStructureTreeModel} instance. * * @param context target context (if defined) * @return current {@link GradleProjectStructureTreeModel} instance (if any has been found); * <code>null</code> otherwise */ @Nullable public static GradleProjectStructureTreeModel getProjectStructureTreeModel( @Nullable DataContext context) { if (context != null) { final GradleProjectStructureTreeModel model = GradleDataKeys.SYNC_TREE_MODEL.getData(context); if (model != null) { return model; } } if (context == null) { return null; } final Project project = PlatformDataKeys.PROJECT.getData(context); if (project == null) { return null; } return getProjectStructureTreeModel(project); }