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);
}
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);
}
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();
}
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);
}
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()]);
}
Aggregations