Complete system property names in "VM option" field in Grails Run Target Dialog.

This commit is contained in:
Sergey Evdokimov
2011-09-08 18:34:30 +04:00
parent c6343bf710
commit c6b3aa4cd6
4 changed files with 45 additions and 16 deletions
@@ -46,4 +46,8 @@ public abstract class TextFieldCompletionProvider {
}
protected abstract void addCompletionVariants(@NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result);
public EditorTextField createEditor(Project project) {
return new EditorTextField(createDocument(project), project, PlainTextLanguage.INSTANCE.getAssociatedFileType());
}
}
@@ -61,14 +61,6 @@
<text value="VM options:"/>
</properties>
</component>
<component id="8904c" class="javax.swing.JTextField" binding="myVmOptionsField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="b107f" class="javax.swing.JLabel" binding="myModuleLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
@@ -83,6 +75,12 @@
</constraints>
<properties/>
</component>
<component id="b192e" class="com.intellij.ui.EditorTextField" binding="myVmOptionsField" custom-create="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
@@ -44,7 +44,7 @@ public class MvcRunTargetDialog extends DialogWrapper {
private JPanel contentPane;
private JLabel myTargetLabel;
private JPanel myFakePanel;
private JTextField myVmOptionsField;
private EditorTextField myVmOptionsField;
private JComboBox myModuleBox;
private JLabel myModuleLabel;
private JLabel myVmOptionLabel;
@@ -140,6 +140,22 @@ public class MvcRunTargetDialog extends DialogWrapper {
myFakePanel = new JPanel(new BorderLayout());
myFakePanel.add(myTargetField, BorderLayout.CENTER);
TextFieldCompletionProvider vmOptionCompletionProvider = new TextFieldCompletionProvider() {
@NotNull
@Override
protected String getPrefix(@NotNull String currentTextPrefix) {
return MvcRunTargetDialog.getPrefix(currentTextPrefix);
}
@Override
protected void addCompletionVariants(@NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result) {
if (prefix.endsWith("-D")) {
result.addAllElements(MvcTargetDialogCompletionUtils.getSystemPropertiesVariants());
}
}
};
myVmOptionsField = vmOptionCompletionProvider.createEditor(myModule.getProject());
new TextFieldCompletionProvider() {
@NotNull
@@ -53,20 +53,31 @@ public class MvcTargetDialogCompletionUtils {
"grails.testing.functional.baseUrl", "grails.compile.artefacts.closures.convert"
};
private static List<LookupElement> SYSTEM_PROPERTIES_VARIANTS;
private MvcTargetDialogCompletionUtils() {
}
public static Collection<LookupElement> collectVariants(@NotNull Module module, @NotNull String text, int offset, @NotNull String prefix) {
List<LookupElement> res = new ArrayList<LookupElement>();
if (prefix.startsWith("-D")) {
for (String property : SYSTEM_PROPERTIES) {
res.add(TailTypeDecorator.withTail(LookupElementBuilder.create("-D" + property), MyTailTypeEQ.INSTANCE));
public static List<LookupElement> getSystemPropertiesVariants() {
if (SYSTEM_PROPERTIES_VARIANTS == null) {
LookupElement[] res = new LookupElement[SYSTEM_PROPERTIES.length];
for (int i = 0; i < res.length; i++) {
res[i] = TailTypeDecorator.withTail(LookupElementBuilder.create("-D" + SYSTEM_PROPERTIES[i]), MyTailTypeEQ.INSTANCE);
}
return res;
SYSTEM_PROPERTIES_VARIANTS = Arrays.asList(res);
}
return SYSTEM_PROPERTIES_VARIANTS;
}
public static Collection<LookupElement> collectVariants(@NotNull Module module, @NotNull String text, int offset, @NotNull String prefix) {
if (prefix.startsWith("-D")) {
return getSystemPropertiesVariants();
}
List<LookupElement> res = new ArrayList<LookupElement>();
if (text.substring(0, offset).matches("\\s*(?:(:?-\\S+|dev|prod|test)\\s+)*\\S*")) {
// Complete command name because command name is not typed.
for (String completionVariant : getAllTargetNames(module)) {