Search in sources :

Example 1 with TextFieldCompletionProviderDumbAware

use of com.intellij.util.TextFieldCompletionProviderDumbAware in project intellij-community by JetBrains.

the class MvcRunTargetDialog method createUIComponents.

private void createUIComponents() {
    myTargetField = new ComboBox(MvcRunTargetHistoryService.getInstance().getHistory());
    myTargetField.setLightWeightPopupEnabled(false);
    EditorComboBoxEditor editor = new StringComboboxEditor(myModule.getProject(), PlainTextFileType.INSTANCE, myTargetField);
    myTargetField.setRenderer(new EditorComboBoxRenderer(editor));
    myTargetField.setEditable(true);
    myTargetField.setEditor(editor);
    EditorTextField editorTextField = editor.getEditorComponent();
    myFakePanel = new JPanel(new BorderLayout());
    myFakePanel.add(myTargetField, BorderLayout.CENTER);
    TextFieldCompletionProvider vmOptionCompletionProvider = new TextFieldCompletionProviderDumbAware() {

        @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 TextFieldCompletionProviderDumbAware() {

        @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) {
            for (LookupElement variant : MvcTargetDialogCompletionUtils.collectVariants(myModule, text, offset, prefix)) {
                result.addElement(variant);
            }
        }
    }.apply(editorTextField);
    editorTextField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            setOKActionEnabled(!StringUtil.isEmptyOrSpaces(e.getDocument().getText()));
        }
    });
    setOKActionEnabled(false);
}
Also used : EditorComboBoxEditor(com.intellij.ui.EditorComboBoxEditor) StringComboboxEditor(com.intellij.ui.StringComboboxEditor) ComboBox(com.intellij.openapi.ui.ComboBox) ModulesComboBox(com.intellij.application.options.ModulesComboBox) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) LookupElement(com.intellij.codeInsight.lookup.LookupElement) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) NotNull(org.jetbrains.annotations.NotNull) TextFieldCompletionProviderDumbAware(com.intellij.util.TextFieldCompletionProviderDumbAware) EditorTextField(com.intellij.ui.EditorTextField) TextFieldCompletionProvider(com.intellij.util.TextFieldCompletionProvider) EditorComboBoxRenderer(com.intellij.ui.EditorComboBoxRenderer)

Example 2 with TextFieldCompletionProviderDumbAware

use of com.intellij.util.TextFieldCompletionProviderDumbAware in project intellij-community by JetBrains.

the class ExternalProjectPathField method createTextField.

@NotNull
private static EditorTextField createTextField(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId) {
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
    assert manager != null;
    final AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
    final ExternalSystemUiAware uiAware = ExternalSystemUiUtil.getUiAware(externalSystemId);
    TextFieldCompletionProvider provider = new TextFieldCompletionProviderDumbAware() {

        @Override
        protected void addCompletionVariants(@NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result) {
            for (Map.Entry<ExternalProjectPojo, Collection<ExternalProjectPojo>> entry : settings.getAvailableProjects().entrySet()) {
                String rootProjectPath = entry.getKey().getPath();
                String rootProjectName = uiAware.getProjectRepresentationName(rootProjectPath, null);
                ExternalProjectPathLookupElement rootProjectElement = new ExternalProjectPathLookupElement(rootProjectName, rootProjectPath);
                result.addElement(rootProjectElement);
                for (ExternalProjectPojo subProject : entry.getValue()) {
                    String p = subProject.getPath();
                    if (rootProjectPath.equals(p)) {
                        continue;
                    }
                    String subProjectName = uiAware.getProjectRepresentationName(p, rootProjectPath);
                    ExternalProjectPathLookupElement subProjectElement = new ExternalProjectPathLookupElement(subProjectName, p);
                    result.addElement(subProjectElement);
                }
            }
            result.stopHere();
        }
    };
    EditorTextField result = provider.createEditor(project, false, editor -> {
        collapseIfPossible(editor, externalSystemId, project);
        editor.getSettings().setShowIntentionBulb(false);
    });
    result.setBorder(UIUtil.getTextFieldBorder());
    result.setOneLineMode(true);
    result.setOpaque(true);
    result.setBackground(UIUtil.getTextFieldBackground());
    return result;
}
Also used : AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) NotNull(org.jetbrains.annotations.NotNull) ExternalSystemUiAware(com.intellij.openapi.externalSystem.ExternalSystemUiAware) TextFieldCompletionProviderDumbAware(com.intellij.util.TextFieldCompletionProviderDumbAware) EditorTextField(com.intellij.ui.EditorTextField) TextFieldCompletionProvider(com.intellij.util.TextFieldCompletionProvider) Collection(java.util.Collection) Map(java.util.Map) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)2 EditorTextField (com.intellij.ui.EditorTextField)2 TextFieldCompletionProvider (com.intellij.util.TextFieldCompletionProvider)2 TextFieldCompletionProviderDumbAware (com.intellij.util.TextFieldCompletionProviderDumbAware)2 NotNull (org.jetbrains.annotations.NotNull)2 ModulesComboBox (com.intellij.application.options.ModulesComboBox)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 ExternalSystemUiAware (com.intellij.openapi.externalSystem.ExternalSystemUiAware)1 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)1 AbstractExternalSystemLocalSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 EditorComboBoxEditor (com.intellij.ui.EditorComboBoxEditor)1 EditorComboBoxRenderer (com.intellij.ui.EditorComboBoxRenderer)1 StringComboboxEditor (com.intellij.ui.StringComboboxEditor)1 Collection (java.util.Collection)1 Map (java.util.Map)1