Search in sources :

Example 26 with Consumer

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

the class CloudAccountSelectionEditor method createAccount.

private void createAccount(ServerType<?> cloudType) {
    RemoteServer<?> newAccount = RemoteServersManager.getInstance().createServer(cloudType, generateServerName(cloudType));
    final Ref<Consumer<String>> errorConsumerRef = new Ref<>();
    SingleRemoteServerConfigurable configurable = new SingleRemoteServerConfigurable(newAccount, null, true) {

        @Override
        protected void setConnectionStatusText(boolean error, String text) {
            super.setConnectionStatusText(error, error ? "" : text);
            errorConsumerRef.get().consume(error ? text : null);
        }
    };
    if (!new SingleConfigurableEditor(myMainPanel, configurable, ShowSettingsUtilImpl.createDimensionKey(configurable), false) {

        {
            errorConsumerRef.set(s -> setErrorText(s, myMainPanel));
        }
    }.showAndGet()) {
        return;
    }
    newAccount.setName(configurable.getDisplayName());
    RemoteServersManager.getInstance().addServer(newAccount);
    AccountItem newAccountItem = new AccountItem(newAccount);
    myAccountComboBox.addItem(newAccountItem);
    myAccountComboBox.setSelectedItem(newAccountItem);
}
Also used : Ref(com.intellij.openapi.util.Ref) Consumer(com.intellij.util.Consumer) SingleConfigurableEditor(com.intellij.openapi.options.ex.SingleConfigurableEditor) SingleRemoteServerConfigurable(com.intellij.remoteServer.impl.configuration.SingleRemoteServerConfigurable)

Example 27 with Consumer

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

the class XValueHint method evaluateAndShowHint.

@Override
protected void evaluateAndShowHint() {
    myEvaluator.evaluate(myExpression, new XEvaluationCallbackBase() {

        @Override
        public void evaluated(@NotNull final XValue result) {
            result.computePresentation(new XValueNodePresentationConfigurator.ConfigurableXValueNodeImpl() {

                private XFullValueEvaluator myFullValueEvaluator;

                private boolean myShown = false;

                @Override
                public void applyPresentation(@Nullable Icon icon, @NotNull XValuePresentation valuePresenter, boolean hasChildren) {
                    if (isHintHidden()) {
                        return;
                    }
                    SimpleColoredText text = new SimpleColoredText();
                    text.append(StringUtil.trimMiddle(myValueName, 200), XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
                    XValueNodeImpl.buildText(valuePresenter, text);
                    if (!hasChildren) {
                        SimpleColoredComponent component = HintUtil.createInformationComponent();
                        text.appendToComponent(component);
                        if (myFullValueEvaluator != null) {
                            component.append(myFullValueEvaluator.getLinkText(), XDebuggerTreeNodeHyperlink.TEXT_ATTRIBUTES, (Consumer<MouseEvent>) event -> DebuggerUIUtil.showValuePopup(myFullValueEvaluator, event, getProject(), getEditor()));
                            LinkMouseListenerBase.installSingleTagOn(component);
                        }
                        showHint(component);
                    } else if (getType() == ValueHintType.MOUSE_CLICK_HINT) {
                        if (!myShown) {
                            showTree(result);
                        }
                    } else {
                        if (getType() == ValueHintType.MOUSE_OVER_HINT) {
                            text.insert(0, "(" + KeymapUtil.getFirstKeyboardShortcutText("ShowErrorDescription") + ") ", SimpleTextAttributes.GRAYED_ATTRIBUTES);
                        }
                        JComponent component = createExpandableHintComponent(text, () -> showTree(result));
                        showHint(component);
                    }
                    myShown = true;
                }

                @Override
                public void setFullValueEvaluator(@NotNull XFullValueEvaluator fullValueEvaluator) {
                    myFullValueEvaluator = fullValueEvaluator;
                }

                @Override
                public boolean isObsolete() {
                    return isHintHidden();
                }
            }, XValuePlace.TOOLTIP);
        }

        @Override
        public void errorOccurred(@NotNull final String errorMessage) {
            if (getType() == ValueHintType.MOUSE_CLICK_HINT) {
                ApplicationManager.getApplication().invokeLater(() -> showHint(HintUtil.createErrorLabel(errorMessage)));
            }
            LOG.debug("Cannot evaluate '" + myExpression + "':" + errorMessage);
        }
    }, myExpressionPosition);
}
Also used : XValueNodeImpl(com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl) XValue(com.intellij.xdebugger.frame.XValue) Disposer(com.intellij.openapi.util.Disposer) Logger(com.intellij.openapi.diagnostic.Logger) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) XDebugSession(com.intellij.xdebugger.XDebugSession) SimpleColoredText(com.intellij.ui.SimpleColoredText) XDebuggerEvaluateActionHandler(com.intellij.xdebugger.impl.actions.handlers.XDebuggerEvaluateActionHandler) HintUtil(com.intellij.codeInsight.hint.HintUtil) XValueNodePresentationConfigurator(com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodePresentationConfigurator) XEvaluationCallbackBase(com.intellij.xdebugger.impl.ui.tree.nodes.XEvaluationCallbackBase) KeymapUtil(com.intellij.openapi.keymap.KeymapUtil) Nullable(org.jetbrains.annotations.Nullable) ConsoleView(com.intellij.execution.ui.ConsoleView) XSourcePosition(com.intellij.xdebugger.XSourcePosition) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) LanguageConsoleView(com.intellij.execution.console.LanguageConsoleView) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) XDebuggerUtil(com.intellij.xdebugger.XDebuggerUtil) ValueHintType(com.intellij.xdebugger.impl.evaluate.quick.common.ValueHintType) DebuggerUIUtil(com.intellij.xdebugger.impl.ui.DebuggerUIUtil) ActionManager(com.intellij.openapi.actionSystem.ActionManager) ExpressionInfo(com.intellij.xdebugger.evaluation.ExpressionInfo) XDebuggerUIConstants(com.intellij.xdebugger.impl.ui.XDebuggerUIConstants) Project(com.intellij.openapi.project.Project) ShortcutSet(com.intellij.openapi.actionSystem.ShortcutSet) AbstractValueHint(com.intellij.xdebugger.impl.evaluate.quick.common.AbstractValueHint) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) XDebuggerTreeNodeHyperlink(com.intellij.xdebugger.frame.XDebuggerTreeNodeHyperlink) StringUtil(com.intellij.openapi.util.text.StringUtil) XFullValueEvaluator(com.intellij.xdebugger.frame.XFullValueEvaluator) Key(com.intellij.openapi.util.Key) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Editor(com.intellij.openapi.editor.Editor) Disposable(com.intellij.openapi.Disposable) XValuePlace(com.intellij.xdebugger.frame.XValuePlace) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) LinkMouseListenerBase(com.intellij.openapi.vcs.changes.issueLinks.LinkMouseListenerBase) Pair(com.intellij.openapi.util.Pair) XValuePresentation(com.intellij.xdebugger.frame.presentation.XValuePresentation) XValueMarkers(com.intellij.xdebugger.impl.frame.XValueMarkers) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) javax.swing(javax.swing) XValuePresentation(com.intellij.xdebugger.frame.presentation.XValuePresentation) MouseEvent(java.awt.event.MouseEvent) XFullValueEvaluator(com.intellij.xdebugger.frame.XFullValueEvaluator) SimpleColoredText(com.intellij.ui.SimpleColoredText) XEvaluationCallbackBase(com.intellij.xdebugger.impl.ui.tree.nodes.XEvaluationCallbackBase) XValue(com.intellij.xdebugger.frame.XValue) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent)

Example 28 with Consumer

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

the class MultipleFileMergeDialog method showMergeDialog.

private void showMergeDialog() {
    DiffRequestFactory requestFactory = DiffRequestFactory.getInstance();
    Collection<VirtualFile> files = myTable.getSelection();
    if (!beforeResolve(files)) {
        return;
    }
    for (final VirtualFile file : files) {
        final MergeData mergeData;
        try {
            mergeData = myProvider.loadRevisions(file);
        } catch (VcsException ex) {
            Messages.showErrorDialog(myRootPanel, "Error loading revisions to merge: " + ex.getMessage());
            break;
        }
        if (mergeData.CURRENT == null || mergeData.LAST == null || mergeData.ORIGINAL == null) {
            Messages.showErrorDialog(myRootPanel, "Error loading revisions to merge");
            break;
        }
        String leftTitle = myMergeDialogCustomizer.getLeftPanelTitle(file);
        String baseTitle = myMergeDialogCustomizer.getCenterPanelTitle(file);
        String rightTitle = myMergeDialogCustomizer.getRightPanelTitle(file, mergeData.LAST_REVISION_NUMBER);
        String title = myMergeDialogCustomizer.getMergeWindowTitle(file);
        final List<byte[]> byteContents = ContainerUtil.list(mergeData.CURRENT, mergeData.ORIGINAL, mergeData.LAST);
        List<String> contentTitles = ContainerUtil.list(leftTitle, baseTitle, rightTitle);
        Consumer<MergeResult> callback = result -> {
            Document document = FileDocumentManager.getInstance().getCachedDocument(file);
            if (document != null)
                FileDocumentManager.getInstance().saveDocument(document);
            checkMarkModifiedProject(file);
            if (result != MergeResult.CANCEL) {
                ApplicationManager.getApplication().runWriteAction(() -> {
                    markFileProcessed(file, getSessionResolution(result));
                });
            }
        };
        MergeRequest request;
        try {
            if (myProvider.isBinary(file)) {
                // respect MIME-types in svn
                request = requestFactory.createBinaryMergeRequest(myProject, file, byteContents, title, contentTitles, callback);
            } else {
                request = requestFactory.createMergeRequest(myProject, file, byteContents, title, contentTitles, callback);
            }
            MergeUtil.putRevisionInfos(request, mergeData);
        } catch (InvalidDiffRequestException e) {
            LOG.error(e);
            Messages.showErrorDialog(myRootPanel, "Can't show merge dialog");
            break;
        }
        DiffManager.getInstance().showMerge(myProject, request);
    }
    updateModelFromFiles();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UIUtil(com.intellij.util.ui.UIUtil) InvalidDiffRequestException(com.intellij.diff.InvalidDiffRequestException) MergeUtil(com.intellij.diff.merge.MergeUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) DiffManager(com.intellij.diff.DiffManager) ColumnInfo(com.intellij.util.ui.ColumnInfo) TableCellRenderer(javax.swing.table.TableCellRenderer) JBLabel(com.intellij.ui.components.JBLabel) SmartList(com.intellij.util.SmartList) DiffUtil(com.intellij.diff.util.DiffUtil) VcsDirtyScopeManager(com.intellij.openapi.vcs.changes.VcsDirtyScopeManager) SpeedSearchUtil(com.intellij.ui.speedSearch.SpeedSearchUtil) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) VcsException(com.intellij.openapi.vcs.VcsException) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) ListSelectionEvent(javax.swing.event.ListSelectionEvent) VirtualFilePresentation(com.intellij.ide.presentation.VirtualFilePresentation) TableView(com.intellij.ui.table.TableView) MergeRequest(com.intellij.diff.merge.MergeRequest) DoubleClickListener(com.intellij.ui.DoubleClickListener) MergeVersion(com.intellij.openapi.diff.impl.mergeTool.MergeVersion) Nullable(org.jetbrains.annotations.Nullable) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) DiffRequestFactory(com.intellij.diff.DiffRequestFactory) Ref(com.intellij.openapi.util.Ref) Consumer(com.intellij.util.Consumer) java.util(java.util) ActionListener(java.awt.event.ActionListener) ColoredTableCellRenderer(com.intellij.ui.ColoredTableCellRenderer) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) ListTableModel(com.intellij.util.ui.ListTableModel) TableSpeedSearch(com.intellij.ui.TableSpeedSearch) StringUtil(com.intellij.openapi.util.text.StringUtil) ProjectManagerEx(com.intellij.openapi.project.ex.ProjectManagerEx) Convertor(com.intellij.util.containers.Convertor) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) VcsBundle(com.intellij.openapi.vcs.VcsBundle) MergeResult(com.intellij.diff.merge.MergeResult) CommandProcessor(com.intellij.openapi.command.CommandProcessor) ListSelectionListener(javax.swing.event.ListSelectionListener) javax.swing(javax.swing) DiffRequestFactory(com.intellij.diff.DiffRequestFactory) InvalidDiffRequestException(com.intellij.diff.InvalidDiffRequestException) MergeResult(com.intellij.diff.merge.MergeResult) Document(com.intellij.openapi.editor.Document) MergeRequest(com.intellij.diff.merge.MergeRequest) VcsException(com.intellij.openapi.vcs.VcsException)

Example 29 with Consumer

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

the class PluginDescriptorChooser method show.

public static void show(final Project project, final Editor editor, final PsiFile file, final Consumer<DomFileElement<IdeaPlugin>> consumer) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    assert module != null;
    List<DomFileElement<IdeaPlugin>> elements = DomService.getInstance().getFileElements(IdeaPlugin.class, project, module.getModuleWithDependentsScope());
    elements = ContainerUtil.filter(elements, element -> {
        VirtualFile virtualFile = element.getFile().getVirtualFile();
        return virtualFile != null && ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile);
    });
    elements = findAppropriateIntelliJModule(module.getName(), elements);
    if (elements.isEmpty()) {
        HintManager.getInstance().showErrorHint(editor, "Cannot find plugin descriptor");
        return;
    }
    if (elements.size() == 1) {
        consumer.consume(elements.get(0));
        return;
    }
    final BaseListPopupStep<PluginDescriptorCandidate> popupStep = new BaseListPopupStep<PluginDescriptorCandidate>("Choose Plugin Descriptor", createCandidates(module, elements)) {

        @Override
        public boolean isSpeedSearchEnabled() {
            return true;
        }

        @Override
        public Icon getIconFor(PluginDescriptorCandidate candidate) {
            return candidate.getIcon();
        }

        @NotNull
        @Override
        public String getTextFor(PluginDescriptorCandidate candidate) {
            return candidate.getText();
        }

        @Nullable
        @Override
        public ListSeparator getSeparatorAbove(PluginDescriptorCandidate candidate) {
            final String separatorText = candidate.getSeparatorText();
            if (separatorText != null) {
                return new ListSeparator(separatorText);
            }
            return null;
        }

        @Override
        public PopupStep onChosen(PluginDescriptorCandidate selectedValue, boolean finalChoice) {
            consumer.consume(selectedValue.myDomFileElement);
            return FINAL_CHOICE;
        }
    };
    JBPopupFactory.getInstance().createListPopup(popupStep).showInBestPositionFor(editor);
}
Also used : IncludedXmlTag(com.intellij.xml.util.IncludedXmlTag) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) ContainerUtil(com.intellij.util.containers.ContainerUtil) IdeaPlugin(org.jetbrains.idea.devkit.dom.IdeaPlugin) Comparing(com.intellij.openapi.util.Comparing) Extensions(org.jetbrains.idea.devkit.dom.Extensions) Map(java.util.Map) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) EmptyIcon(com.intellij.util.ui.EmptyIcon) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) DomFileElement(com.intellij.util.xml.DomFileElement) Editor(com.intellij.openapi.editor.Editor) Nullable(org.jetbrains.annotations.Nullable) ModulesAlphaComparator(com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator) List(java.util.List) ModuleGrouper(com.intellij.openapi.module.ModuleGrouper) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) DomService(com.intellij.util.xml.DomService) Function(com.intellij.util.Function) PopupStep(com.intellij.openapi.ui.popup.PopupStep) HintManager(com.intellij.codeInsight.hint.HintManager) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListSeparator(com.intellij.openapi.ui.popup.ListSeparator) DomFileElement(com.intellij.util.xml.DomFileElement) Module(com.intellij.openapi.module.Module)

Example 30 with Consumer

use of com.intellij.util.Consumer in project android by JetBrains.

the class PackageClassConverter method createReferences.

@NotNull
@Override
public PsiReference[] createReferences(GenericDomValue<PsiClass> value, final PsiElement element, ConvertContext context) {
    assert element instanceof XmlAttributeValue;
    final XmlAttributeValue attrValue = (XmlAttributeValue) element;
    final String strValue = attrValue.getValue();
    final boolean startsWithPoint = strValue.startsWith(".");
    final int start = attrValue.getValueTextRange().getStartOffset() - attrValue.getTextRange().getStartOffset();
    final DomElement domElement = context.getInvocationElement();
    final String manifestPackage = getManifestPackage(context);
    final ExtendClass extendClassAnnotation = domElement.getAnnotation(ExtendClass.class);
    final String[] extendClassesNames = extendClassAnnotation != null ? new String[] { extendClassAnnotation.value() } : myExtendClassesNames;
    final boolean inModuleOnly = domElement.getAnnotation(CompleteNonModuleClass.class) == null;
    AndroidFacet facet = AndroidFacet.getInstance(context);
    // If the source XML file is contained within the test folders, we'll also allow to resolve test classes
    final boolean isTestFile = facet != null && isTestFile(facet, element.getContainingFile().getVirtualFile());
    if (strValue.isEmpty()) {
        return PsiReference.EMPTY_ARRAY;
    }
    final List<PsiReference> result = new ArrayList<>();
    final Module module = context.getModule();
    /**
     * Using inner class here as opposed to anonymous one as with anonymous class it wouldn't be possible to access {@code myPartStart} later
     */
    class CustomConsumer implements Consumer<Integer> {

        int myPartStart = 0;

        private boolean myIsPackage = true;

        @Override
        public void consume(Integer index) {
            if (index > myPartStart) {
                final TextRange range = new TextRange(start + myPartStart, start + index);
                final MyReference reference = new MyReference(element, range, manifestPackage, startsWithPoint, start, myIsPackage, module, extendClassesNames, inModuleOnly, isTestFile);
                result.add(reference);
            }
            myPartStart = index + 1;
        }
    }
    final CustomConsumer consumer = new CustomConsumer();
    AndroidTextUtils.forEachOccurrence(strValue, '.', consumer);
    consumer.myIsPackage = false;
    AndroidTextUtils.forEachOccurrence(strValue, '$', consumer.myPartStart, consumer);
    consumer.consume(strValue.length());
    return result.toArray(new PsiReference[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Consumer(com.intellij.util.Consumer) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Consumer (com.intellij.util.Consumer)59 NotNull (org.jetbrains.annotations.NotNull)41 Project (com.intellij.openapi.project.Project)37 Nullable (org.jetbrains.annotations.Nullable)33 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 List (java.util.List)22 ApplicationManager (com.intellij.openapi.application.ApplicationManager)17 StringUtil (com.intellij.openapi.util.text.StringUtil)17 javax.swing (javax.swing)16 ContainerUtil (com.intellij.util.containers.ContainerUtil)15 Logger (com.intellij.openapi.diagnostic.Logger)14 Module (com.intellij.openapi.module.Module)12 java.awt (java.awt)12 Pair (com.intellij.openapi.util.Pair)11 java.util (java.util)11 File (java.io.File)10 Collection (java.util.Collection)10 PsiElement (com.intellij.psi.PsiElement)9 PsiFile (com.intellij.psi.PsiFile)9 DataContext (com.intellij.openapi.actionSystem.DataContext)8