use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.
the class XsltIncludeIndex method _process.
private static boolean _process(VirtualFile[] files, Project project, Processor<XmlFile> processor) {
final PsiManager psiManager = PsiManager.getInstance(project);
final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, (NullableFunction<VirtualFile, PsiFile>) file -> psiManager.findFile(file));
for (final PsiFile psiFile : psiFiles) {
if (XsltSupport.isXsltFile(psiFile)) {
if (!processor.process((XmlFile) psiFile)) {
return false;
}
}
}
return true;
}
use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.
the class GotoPropertyDeclarationsProvider method getItems.
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull DataContext context) {
final FileEditor editor = PlatformDataKeys.FILE_EDITOR.getData(context);
if (!(editor instanceof ResourceBundleEditor)) {
return Collections.emptyList();
}
final ResourceBundleEditor resourceBundleEditor = (ResourceBundleEditor) editor;
final Collection<ResourceBundleEditorViewElement> elements = resourceBundleEditor.getSelectedElements();
if (elements.size() != 1) {
return Collections.emptyList();
}
final IProperty[] properties = ContainerUtil.getFirstItem(elements).getProperties();
if (properties == null || properties.length != 1 || !(properties[0] instanceof Property)) {
return Collections.emptyList();
}
final IProperty property = properties[0];
final String propertyKey = property.getKey();
final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(property.getPsiElement().getContainingFile());
assert file != null;
final ResourceBundle resourceBundle = file.getResourceBundle();
return ContainerUtil.mapNotNull(resourceBundle.getPropertiesFiles(), (NullableFunction<PropertiesFile, GotoRelatedItem>) f -> {
final IProperty foundProperty = f.findPropertyByKey(propertyKey);
return foundProperty == null ? null : new GotoRelatedItem(foundProperty.getPsiElement(), "Property Declarations");
});
}
use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.
the class TemplateListPanel method createTable.
private JPanel createTable() {
myTreeRoot = new CheckedTreeNode(null);
myTree = new LiveTemplateTree(new CheckboxTree.CheckboxTreeCellRenderer() {
@Override
public void customizeRenderer(final JTree tree, Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) {
if (!(value instanceof DefaultMutableTreeNode))
return;
value = ((DefaultMutableTreeNode) value).getUserObject();
if (value instanceof TemplateImpl) {
TemplateImpl template = (TemplateImpl) value;
TemplateImpl defaultTemplate = TemplateSettings.getInstance().getDefaultTemplate(template);
Color fgColor = defaultTemplate != null && templatesDiffer(template, defaultTemplate) ? JBColor.BLUE : null;
getTextRenderer().append(template.getKey(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, fgColor));
String description = template.getDescription();
if (StringUtil.isNotEmpty(description)) {
getTextRenderer().append(" (" + description + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
}
} else if (value instanceof TemplateGroup) {
getTextRenderer().append(((TemplateGroup) value).getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
}
}
}, myTreeRoot, this);
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(@NotNull final TreeSelectionEvent e) {
TemplateSettings templateSettings = TemplateSettings.getInstance();
TemplateImpl template = getTemplate(getSingleSelectedIndex());
if (template != null) {
templateSettings.setLastSelectedTemplate(template.getGroupName(), template.getKey());
} else {
templateSettings.setLastSelectedTemplate(null, null);
showEmptyCard();
}
if (myUpdateNeeded) {
myAlarm.cancelAllRequests();
myAlarm.addRequest(() -> updateTemplateDetails(false, false), 100);
}
}
});
myTree.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(@Nullable ActionEvent event) {
myCurrentTemplateEditor.focusKey();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_FOCUSED);
installPopup();
DnDSupport.createBuilder(myTree).setBeanProvider((NullableFunction<DnDActionInfo, DnDDragStartBean>) dnDActionInfo -> {
Point point = dnDActionInfo.getPoint();
if (myTree.getPathForLocation(point.x, point.y) == null)
return null;
Map<TemplateImpl, DefaultMutableTreeNode> templates = getSelectedTemplates();
return !templates.isEmpty() ? new DnDDragStartBean(templates) : null;
}).setDisposableParent(this).setTargetChecker(new DnDTargetChecker() {
@Override
public boolean update(DnDEvent event) {
@SuppressWarnings("unchecked") Set<String> oldGroupNames = getAllGroups((Map<TemplateImpl, DefaultMutableTreeNode>) event.getAttachedObject());
TemplateGroup group = getDropGroup(event);
boolean differentGroup = group != null && !oldGroupNames.contains(group.getName());
event.setDropPossible(differentGroup, "");
return true;
}
}).setDropHandler(new DnDDropHandler() {
@Override
public void drop(DnDEvent event) {
//noinspection unchecked
moveTemplates((Map<TemplateImpl, DefaultMutableTreeNode>) event.getAttachedObject(), ObjectUtils.assertNotNull(getDropGroup(event)).getName());
}
}).setImageProvider((NullableFunction<DnDActionInfo, DnDImage>) dnDActionInfo -> {
Point point = dnDActionInfo.getPoint();
TreePath path = myTree.getPathForLocation(point.x, point.y);
return path == null ? null : new DnDImage(DnDAwareTree.getDragImage(myTree, path, point).first);
}).install();
if (myTemplateGroups.size() > 0) {
myTree.setSelectionInterval(0, 0);
}
return initToolbar().createPanel();
}
use of com.intellij.util.NullableFunction in project intellij-community by JetBrains.
the class RelaxIncludeIndex method processRelatedFiles.
private static boolean processRelatedFiles(PsiFile file, VirtualFile[] files, PsiElementProcessor<XmlFile> processor) {
Project project = file.getProject();
final PsiManager psiManager = PsiManager.getInstance(project);
final PsiFile[] psiFiles = ContainerUtil.map2Array(files, PsiFile.class, (NullableFunction<VirtualFile, PsiFile>) file1 -> psiManager.findFile(file1));
for (final PsiFile psiFile : psiFiles) {
if (!processFile(psiFile, processor)) {
return false;
}
}
return true;
}
Aggregations