IDEA-76142: Gradle support - cannot update IDEA projects once one of build.gradle...
[idea/community.git] / plugins / gradle / src / org / jetbrains / plugins / gradle / bootstrap / GradleBootstrap.java
1 package org.jetbrains.plugins.gradle.bootstrap;
2
3 import com.intellij.openapi.components.AbstractProjectComponent;
4 import com.intellij.openapi.project.DumbAwareRunnable;
5 import com.intellij.openapi.project.Project;
6 import com.intellij.openapi.startup.StartupManager;
7 import com.intellij.openapi.wm.ToolWindow;
8 import com.intellij.openapi.wm.ToolWindowAnchor;
9 import com.intellij.openapi.wm.ex.ToolWindowManagerEx;
10 import com.intellij.ui.content.impl.ContentImpl;
11 import org.jetbrains.annotations.NotNull;
12 import org.jetbrains.plugins.gradle.diff.PlatformFacade;
13 import org.jetbrains.plugins.gradle.sync.GradleProjectStructureChangesModel;
14 import org.jetbrains.plugins.gradle.sync.GradleProjectStructureChangesPanel;
15 import org.jetbrains.plugins.gradle.ui.GradleIcons;
16 import org.jetbrains.plugins.gradle.util.GradleBundle;
17
18 /**
19  * Encapsulates initialisation routine of the gradle integration.
20  * 
21  * @author Denis Zhdanov
22  * @since 11/3/11 4:01 PM
23  */
24 public class GradleBootstrap extends AbstractProjectComponent {
25
26   private static final String GRADLE_TOOL_WINDOW_ID = GradleBundle.message("gradle.name");
27   
28   private final GradleProjectStructureChangesModel myChangesModel;
29   private final PlatformFacade myProjectStructureHelper;
30   
31   public GradleBootstrap(@NotNull Project project,
32                          @NotNull GradleProjectStructureChangesModel changesModel,
33                          @NotNull PlatformFacade projectStructureHelper) {
34     super(project);
35     myChangesModel = changesModel;
36     myProjectStructureHelper = projectStructureHelper;
37   }
38
39   @Override
40   public void projectOpened() {
41     StartupManager.getInstance(myProject).registerPostStartupActivity(new DumbAwareRunnable() {
42       @Override
43       public void run() {
44         initToolWindow();
45       }
46     });
47   }
48
49   private void initToolWindow() {
50     final ToolWindowManagerEx manager = ToolWindowManagerEx.getInstanceEx(myProject);
51     ToolWindow toolWindow = manager.registerToolWindow(GRADLE_TOOL_WINDOW_ID, false, ToolWindowAnchor.RIGHT);
52     toolWindow.setIcon(GradleIcons.GRADLE_ICON);
53     String syncTitle = GradleBundle.message("gradle.sync.title.tab");
54     final GradleProjectStructureChangesPanel projectStructureChanges
55       = new GradleProjectStructureChangesPanel(myProject, myChangesModel, myProjectStructureHelper);
56     toolWindow.getContentManager().addContent(new ContentImpl(projectStructureChanges, syncTitle, true)); 
57   }
58 }