[^andres, yann] IDEA-88872 Support additional flags when creating a Griffon applicati...
authorpeter <peter@jetbrains.com>
Tue, 13 Nov 2012 11:29:33 +0000 (12:29 +0100)
committerpeter <peter@jetbrains.com>
Tue, 13 Nov 2012 12:31:32 +0000 (13:31 +0100)
plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonCreateProjectDialog.form [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonCreateProjectDialog.java [new file with mode: 0644]
plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonFramework.java
plugins/groovy/src/org/jetbrains/plugins/groovy/mvc/MvcFramework.java

diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonCreateProjectDialog.form b/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonCreateProjectDialog.form
new file mode 100644 (file)
index 0000000..420b9b9
--- /dev/null
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.groovy.griffon.GriffonCreateProjectDialog">
+  <grid id="27dc6" binding="myComponent" layout-manager="GridLayoutManager" row-count="6" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+    <margin top="0" left="0" bottom="0" right="0"/>
+    <constraints>
+      <xy x="20" y="20" width="500" height="162"/>
+    </constraints>
+    <properties/>
+    <border type="none"/>
+    <children>
+      <component id="8db57" class="javax.swing.JLabel">
+        <constraints>
+          <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <labelFor value="e4473"/>
+          <text value="Additional &amp;options:"/>
+        </properties>
+      </component>
+      <component id="e4473" class="javax.swing.JTextField" binding="myOptionField">
+        <constraints>
+          <grid row="5" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
+            <minimum-size width="150" height="-1"/>
+            <preferred-size width="150" height="-1"/>
+          </grid>
+        </constraints>
+        <properties>
+          <columns value="100"/>
+        </properties>
+      </component>
+      <component id="64b00" class="javax.swing.JRadioButton" binding="myCreateApp" default-binding="true">
+        <constraints>
+          <grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <selected value="true"/>
+          <text value="Create an &amp;application (create-app)"/>
+        </properties>
+      </component>
+      <component id="34959" class="javax.swing.JRadioButton" binding="myCreatePlugin">
+        <constraints>
+          <grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text value="Create a &amp;plugin (create-plugin)"/>
+        </properties>
+      </component>
+      <component id="58a43" class="javax.swing.JRadioButton" binding="myCreateAddon">
+        <constraints>
+          <grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text value="Create an a&amp;ddon (create-addon)"/>
+        </properties>
+      </component>
+      <component id="d9e96" class="javax.swing.JRadioButton" binding="myCreateArchetype">
+        <constraints>
+          <grid row="4" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text value="Create an a&amp;rchetype (create-archetype)"/>
+        </properties>
+      </component>
+      <component id="5fcd3" class="javax.swing.JLabel" binding="myCreateLabel">
+        <constraints>
+          <grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+        </constraints>
+        <properties>
+          <text value="Label"/>
+        </properties>
+      </component>
+    </children>
+  </grid>
+  <buttonGroups>
+    <group name="myButtonGroup1">
+      <member id="64b00"/>
+      <member id="34959"/>
+      <member id="58a43"/>
+      <member id="d9e96"/>
+    </group>
+  </buttonGroups>
+</form>
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonCreateProjectDialog.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/griffon/GriffonCreateProjectDialog.java
new file mode 100644 (file)
index 0000000..e149c4e
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.griffon;
+
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.DialogWrapper;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.util.ArrayUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+
+/**
+ * @author peter
+ */
+public class GriffonCreateProjectDialog extends DialogWrapper {
+  private JTextField myOptionField;
+  private JPanel myComponent;
+  private JRadioButton myCreateApp;
+  private JRadioButton myCreatePlugin;
+  private JRadioButton myCreateAddon;
+  private JRadioButton myCreateArchetype;
+  private JLabel myCreateLabel;
+
+  public GriffonCreateProjectDialog(@NotNull Module module) {
+    super(module.getProject());
+    setTitle("Create Griffon Structure");
+    myCreateLabel.setText("Create Griffon structure in module '" + module.getName() + "':");
+    init();
+  }
+
+  @Nullable
+  @Override
+  protected JComponent createCenterPanel() {
+    return myComponent;
+  }
+
+  String getCommand() {
+    if (myCreateAddon.isSelected()) return "create-addon";
+    if (myCreateApp.isSelected()) return "create-app";
+    if (myCreateArchetype.isSelected()) return "create-archetype";
+    if (myCreatePlugin.isSelected()) return "create-plugin";
+    throw new AssertionError("No selection");
+  }
+
+  String[] getArguments() {
+    String text = myOptionField.getText();
+    if (StringUtil.isEmptyOrSpaces(text)) {
+      return ArrayUtil.EMPTY_STRING_ARRAY;
+    }
+    return text.split(" ");
+  }
+
+}
index f6c905599f2358b96d09a6c54babeaefb18154d6..fedef4f47beb279586d17b1fe3a50747f35f88b4 100644 (file)
@@ -17,6 +17,7 @@
 package org.jetbrains.plugins.groovy.griffon;
 
 import com.intellij.execution.ExecutionException;
+import com.intellij.execution.configurations.GeneralCommandLine;
 import com.intellij.execution.configurations.JavaParameters;
 import com.intellij.lang.properties.IProperty;
 import com.intellij.lang.properties.psi.PropertiesFile;
@@ -36,9 +37,11 @@ import com.intellij.openapi.vcs.changes.ChangeListManager;
 import com.intellij.openapi.vcs.changes.IgnoredBeanFactory;
 import com.intellij.openapi.vfs.JarFileSystem;
 import com.intellij.openapi.vfs.VfsUtil;
+import com.intellij.openapi.vfs.VfsUtilCore;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.PsiManager;
+import com.intellij.util.ArrayUtil;
 import gnu.trove.TIntArrayList;
 import icons.JetgroovyIcons;
 import org.jetbrains.annotations.NonNls;
@@ -93,6 +96,18 @@ public class GriffonFramework extends MvcFramework {
   public void upgradeFramework(@NotNull Module module) {
   }
 
+  @Nullable
+  @Override
+  protected GeneralCommandLine getCreationCommandLine(Module module) {
+    GriffonCreateProjectDialog dialog = new GriffonCreateProjectDialog(module);
+    dialog.show();
+    if (!dialog.isOK()) {
+      return null;
+    }
+
+    return createCommandAndShowErrors(null, module, true, dialog.getCommand(), dialog.getArguments());
+  }
+
   @Override
   public boolean updatesWholeProject() {
     return false;
@@ -269,7 +284,7 @@ public class GriffonFramework extends MvcFramework {
         throw new ExecutionException("Failed to initialize griffon module: module " + module.getName() + " contains more than one root");
       }
 
-      args = new String[]{roots[0].getName()};
+      args = ArrayUtil.mergeArrays(new String[]{roots[0].getName()}, args);
       rootFile = roots[0].getParent();
     }
     else {
@@ -279,7 +294,7 @@ public class GriffonFramework extends MvcFramework {
       }
     }
 
-    String workDir = VfsUtil.virtualToIoFile(rootFile).getAbsolutePath();
+    String workDir = VfsUtilCore.virtualToIoFile(rootFile).getAbsolutePath();
 
     if (jvmParams != null) {
       params.getVMParametersList().addParametersString(jvmParams);
index e163dfd956d92fa18c8b471f94472399cfd4a913..fa5528b657cdc65aa6280d76ef20eaf4a0589cc3 100644 (file)
@@ -137,15 +137,7 @@ public abstract class MvcFramework {
         ProjectSettingsService.getInstance(module.getProject()).showModuleConfigurationDialog(module.getName(), ClasspathEditor.NAME);
       }
       module.putUserData(CREATE_APP_STRUCTURE, null);
-      String message = "Create default " + getDisplayName() + " directory structure in module '" + module.getName() + "'?";
-      final int result = Messages.showDialog(module.getProject(), message,
-                                             "Create " + getDisplayName() + " application",
-                                             new String[]{"Run 'create-&app'", "Run 'create-&plugin'", "&Cancel"}, 0, getIcon());
-      if (result < 0 || result > 1) {
-        return;
-      }
-
-      final GeneralCommandLine commandLine = createCommandAndShowErrors(null, module, true, result == 0 ? "create-app" : "create-plugin");
+      final GeneralCommandLine commandLine = getCreationCommandLine(module);
       if (commandLine == null) return;
 
       MvcConsole.executeProcess(module, commandLine, new Runnable() {
@@ -164,6 +156,18 @@ public abstract class MvcFramework {
 
   }
 
+  @Nullable
+  protected GeneralCommandLine getCreationCommandLine(Module module) {
+    String message = "Create default " + getDisplayName() + " directory structure in module '" + module.getName() + "'?";
+    final int result = Messages.showDialog(module.getProject(), message, "Create " + getDisplayName() + " application",
+                                           new String[]{"Run 'create-&app'", "Run 'create-&plugin'", "&Cancel"}, 0, getIcon());
+    if (result < 0 || result > 1) {
+      return null;
+    }
+
+    return createCommandAndShowErrors(null, module, true, result == 0 ? "create-app" : "create-plugin");
+  }
+
   public abstract void updateProjectStructure(@NotNull final Module module);
 
   public abstract void ensureRunConfigurationExists(@NotNull Module module);