make server compilation happy
authorDenis.Zhdanov <Denis.Zhdanov@jetbrains.com>
Tue, 31 Jan 2012 14:54:41 +0000 (18:54 +0400)
committerDenis.Zhdanov <Denis.Zhdanov@jetbrains.com>
Tue, 31 Jan 2012 14:54:41 +0000 (18:54 +0400)
plugins/gradle/resources/i18n/GradleBundle.properties
plugins/gradle/src/META-INF/plugin.xml
plugins/gradle/src/org/jetbrains/plugins/gradle/action/AbstractGradleLinkedProjectAction.java [new file with mode: 0644]
plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleLinkToProjectAction.java
plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleOpenScriptAction.java [new file with mode: 0644]
plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleRefreshProjectAction.java
plugins/gradle/testSources/org/jetbrains/plugins/gradle/sync/GradleProjectStructureChangesModelTest.groovy

index be891458642af3ab9225546bea6543ed7847f7e0..0491c6ce225eab0bf06b0e051745c22d1c4619bb 100644 (file)
@@ -70,6 +70,8 @@ gradle.action.link.project.text=Link gradle project
 gradle.action.link.project.description=Allows to link any gradle project to the current IDE project
 gradle.action.refresh.project.text=Refresh gradle project
 gradle.action.refresh.project.description=Allows to force linked gradle project refresh
+gradle.action.open.script.text=Open linked gradle project
+gradle.action.open.script.description=Allows to open project file of the linked gradle project at the editor
 
 gradle.settings.color.text.sample.conflict.node.name=node-with-conflicting-setup
 gradle.settings.color.text.sample.node.sync.name=node-with-same-setup
index 36d93560b32e92128894a848c43327471e4423da..aa9dc8db216558b75ff08db9a82054ed31d61c4d 100644 (file)
   <actions>
     <action id="Gradle.LinkToProject" class="org.jetbrains.plugins.gradle.action.GradleLinkToProjectAction" icon="/general/add.png"/>
     <action id="Gradle.RefreshProject" class="org.jetbrains.plugins.gradle.action.GradleRefreshProjectAction" icon="/actions/sync.png"/>
+    <action id="Gradle.OpenScript" class="org.jetbrains.plugins.gradle.action.GradleOpenScriptAction" icon="/icons/gradle.png"/>
     <group id="Gradle.ChangeActionsToolbar">
-      <reference id="Gradle.LinkToProject"/>
       <reference id="Gradle.RefreshProject"/>
+      <reference id="Gradle.OpenScript"/>
     </group>
   </actions>
   
diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/action/AbstractGradleLinkedProjectAction.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/action/AbstractGradleLinkedProjectAction.java
new file mode 100644 (file)
index 0000000..bbd49d9
--- /dev/null
@@ -0,0 +1,64 @@
+package org.jetbrains.plugins.gradle.action;
+
+import com.intellij.openapi.actionSystem.*;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.text.StringUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.plugins.gradle.config.GradleSettings;
+
+import java.io.File;
+
+/**
+ * Common super class for gradle actions that require {@link GradleSettings#LINKED_PROJECT_FILE_PATH linked project}.
+ * <p/>
+ * Not thread-safe.
+ * 
+ * @author Denis Zhdanov
+ * @since 1/31/12 5:36 PM
+ */
+public abstract class AbstractGradleLinkedProjectAction extends AnAction {
+
+  @Override
+  public void update(AnActionEvent e) {
+    final String path = getLinkedProjectPath(e.getDataContext());
+    final boolean visible = path != null;
+    e.getPresentation().setVisible(visible);
+    if (!visible) {
+      return;
+    }
+    doUpdate(e.getPresentation(), path);
+  }
+
+  @Override
+  public void actionPerformed(AnActionEvent e) {
+    final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
+    if (project == null) {
+      return;
+    }
+    final String path = getLinkedProjectPath(e.getDataContext());
+    if (path == null) {
+      e.getPresentation().setVisible(false);
+      return;
+    }
+    doActionPerformed(project, path);
+  }
+
+  @Nullable
+  protected static String getLinkedProjectPath(@Nullable DataContext context) {
+    if (context == null) {
+      return null;
+    }
+    
+    final Project project = PlatformDataKeys.PROJECT.getData(context);
+    if (project == null) {
+      return null;
+    }
+    
+    final String path = GradleSettings.getInstance(project).LINKED_PROJECT_FILE_PATH;
+    return (StringUtil.isEmpty(path) || !new File(path).isFile()) ? null : path;
+  }
+
+  protected abstract void doUpdate(@NotNull Presentation presentation, @NotNull String linkedProjectPath);
+  protected abstract void doActionPerformed(@NotNull Project project, @NotNull String linkedProjectPath);
+}
index d47e4b8efdd4ef3af08f8b9b11029b8dde46ee58..113156d0ecbaf16569d62bf5c316c80271475f0e 100644 (file)
@@ -11,8 +11,6 @@ import org.jetbrains.plugins.gradle.config.GradleSettings;
 import org.jetbrains.plugins.gradle.util.GradleBundle;
 import org.jetbrains.plugins.gradle.util.GradleUtil;
 
-import java.io.File;
-
 /**
  * Allows to link gradle project to the current IntelliJ IDEA project.
  * <p/>
@@ -28,17 +26,6 @@ public class GradleLinkToProjectAction extends AnAction implements DumbAware {
     getTemplatePresentation().setDescription(GradleBundle.message("gradle.action.link.project.description"));
   }
 
-  @Override
-  public void update(AnActionEvent e) {
-    final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
-    if (project == null) {
-      e.getPresentation().setVisible(false);
-      return;
-    }
-    final String path = GradleSettings.getInstance(project).LINKED_PROJECT_FILE_PATH;
-    e.getPresentation().setVisible(path == null || !new File(path).isFile());
-  }
-
   @Override
   public void actionPerformed(AnActionEvent e) {
     final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleOpenScriptAction.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleOpenScriptAction.java
new file mode 100644 (file)
index 0000000..c6922d6
--- /dev/null
@@ -0,0 +1,35 @@
+package org.jetbrains.plugins.gradle.action;
+
+import com.intellij.openapi.actionSystem.AnAction;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.Presentation;
+import com.intellij.openapi.project.DumbAware;
+import com.intellij.openapi.project.Project;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.plugins.gradle.config.GradleSettings;
+import org.jetbrains.plugins.gradle.util.GradleBundle;
+
+/**
+ * Forces the IntelliJ IDEA to open {@link GradleSettings#LINKED_PROJECT_FILE_PATH linked gradle project} at the editor
+ * <p/>
+ * Not thread-safe.
+ * 
+ * @author Denis Zhdanov
+ * @since 1/31/12 5:16 PM
+ */
+public class GradleOpenScriptAction extends AbstractGradleLinkedProjectAction implements DumbAware {
+
+  public GradleOpenScriptAction() {
+    getTemplatePresentation().setText(GradleBundle.message("gradle.action.open.script.text"));
+    getTemplatePresentation().setDescription(GradleBundle.message("gradle.action.open.script.description"));
+  }
+
+  @Override
+  protected void doUpdate(@NotNull Presentation presentation, @NotNull String linkedProjectPath) {
+  }
+
+  @Override
+  protected void doActionPerformed(@NotNull Project project, @NotNull String linkedProjectPath) {
+    // TODO den implement 
+  }
+}
index d70525040139f5e1431d8c68d304338eb6134d59..17fa3a0fbc4eaf09a4d381fea4745c28c18cbfd6 100644 (file)
@@ -1,8 +1,6 @@
 package org.jetbrains.plugins.gradle.action;
 
-import com.intellij.openapi.actionSystem.AnAction;
-import com.intellij.openapi.actionSystem.AnActionEvent;
-import com.intellij.openapi.actionSystem.PlatformDataKeys;
+import com.intellij.openapi.actionSystem.Presentation;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.progress.Task;
@@ -13,7 +11,6 @@ import org.jetbrains.plugins.gradle.config.GradleSettings;
 import org.jetbrains.plugins.gradle.task.GradleResolveProjectTask;
 import org.jetbrains.plugins.gradle.util.GradleBundle;
 
-import java.io.File;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
@@ -24,7 +21,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
  * @author Denis Zhdanov
  * @since 1/23/12 3:48 PM
  */
-public class GradleRefreshProjectAction extends AnAction implements DumbAware {
+public class GradleRefreshProjectAction extends AbstractGradleLinkedProjectAction implements DumbAware {
 
   private final AtomicBoolean myInProgress = new AtomicBoolean();
   
@@ -34,39 +31,24 @@ public class GradleRefreshProjectAction extends AnAction implements DumbAware {
   }
 
   @Override
-  public void update(AnActionEvent e) {
-    final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
-    if (project == null) {
-      e.getPresentation().setVisible(false);
-      return;
-    }
-    final String path = GradleSettings.getInstance(project).LINKED_PROJECT_FILE_PATH;
-    final boolean visible = path != null && new File(path).isFile();
-    e.getPresentation().setVisible(visible);
-    e.getPresentation().setEnabled(!myInProgress.get());
+  protected void doUpdate(@NotNull Presentation presentation, @NotNull String linkedProjectPath) {
+    presentation.setEnabled(!myInProgress.get()); 
   }
 
   @Override
-  public void actionPerformed(AnActionEvent e) {
-    final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
-    if (project == null) {
-      e.getPresentation().setVisible(false);
-      return;
-    }
-    // Assuming that the linked project is available if this action is called (update() is successful)
-    final String projectPath = GradleSettings.getInstance(project).LINKED_PROJECT_FILE_PATH;
+  protected void doActionPerformed(@NotNull final Project project, @NotNull final String linkedProjectPath) {
     myInProgress.set(true);
     ProgressManager.getInstance().run(new Task.Backgroundable(project, GradleBundle.message("gradle.sync.progress.text")) {
       @Override
       public void run(@NotNull final ProgressIndicator indicator) {
         try {
-          GradleResolveProjectTask task = new GradleResolveProjectTask(project, projectPath, true);
+          GradleResolveProjectTask task = new GradleResolveProjectTask(project, linkedProjectPath, true);
           task.execute(indicator);
         }
         finally {
           myInProgress.set(false);
         }
       }
-    });
+    }); 
   }
 }
index efb25809b82fa6c611bf2ded46aca4f2e74989f7..593ccb1821d17437d4ac1b233b2621022301397d 100644 (file)
@@ -106,7 +106,7 @@ public class GradleProjectStructureChangesModelTest {
     treeModel = container.getComponentInstance(GradleProjectStructureTreeModel) as GradleProjectStructureTreeModel
     changesModel.addListener({ old, current ->
       treeModel.update(current)
-      treeModel.pruneObsoleteNodes(ContainerUtil.<GradleProjectStructureChange>subtract(old, current));
+      treeModel.pruneObsoleteNodes(ContainerUtil.subtract(old, current));
     } as GradleProjectStructureChangeListener)
     changesModel.update(gradle.project)
   }