use of com.intellij.util.NotNullFunction in project intellij-community by JetBrains.
the class CreateResourceBundleDialogComponent method combineToResourceBundleIfNeed.
private void combineToResourceBundleIfNeed(Collection<PsiFile> files) {
Collection<PropertiesFile> createdFiles = ContainerUtil.map(files, (NotNullFunction<PsiFile, PropertiesFile>) dom -> {
final PropertiesFile file = PropertiesImplUtil.getPropertiesFile(dom);
LOG.assertTrue(file != null, dom.getName());
return file;
});
ResourceBundle mainBundle = myResourceBundle;
final Set<ResourceBundle> allBundles = new HashSet<>();
if (mainBundle != null) {
allBundles.add(mainBundle);
}
boolean needCombining = false;
for (PropertiesFile file : createdFiles) {
final ResourceBundle rb = file.getResourceBundle();
if (mainBundle == null) {
mainBundle = rb;
} else if (!mainBundle.equals(rb)) {
needCombining = true;
}
allBundles.add(rb);
}
if (needCombining) {
final List<PropertiesFile> toCombine = new ArrayList<>(createdFiles);
final String baseName = getBaseName();
if (myResourceBundle != null) {
toCombine.addAll(myResourceBundle.getPropertiesFiles());
}
ResourceBundleManager manager = ResourceBundleManager.getInstance(mainBundle.getProject());
for (ResourceBundle bundle : allBundles) {
manager.dissociateResourceBundle(bundle);
}
manager.combineToResourceBundle(toCombine, baseName);
}
}
use of com.intellij.util.NotNullFunction in project intellij-community by JetBrains.
the class FogBugzRepository method getCases.
@SuppressWarnings("unchecked")
private Task[] getCases(String q) throws Exception {
loginIfNeeded();
PostMethod method = new PostMethod(getUrl() + "/api.asp");
method.addParameter("token", myToken);
method.addParameter("cmd", "search");
method.addParameter("q", q);
method.addParameter("cols", "sTitle,fOpen,dtOpened,dtLastUpdated,ixCategory");
int status = getHttpClient().executeMethod(method);
if (status != 200) {
throw new Exception("Error listing cases: " + method.getStatusLine());
}
Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument();
List<Element> errorNodes = XPath.newInstance("/response/error").selectNodes(document);
if (!errorNodes.isEmpty()) {
throw new Exception("Error listing cases: " + errorNodes.get(0).getText());
}
final XPath commentPath = XPath.newInstance("events/event");
final List<Element> nodes = (List<Element>) XPath.newInstance("/response/cases/case").selectNodes(document);
final List<Task> tasks = ContainerUtil.mapNotNull(nodes, (NotNullFunction<Element, Task>) element -> createCase(element, commentPath));
return tasks.toArray(new Task[tasks.size()]);
}
use of com.intellij.util.NotNullFunction in project intellij-community by JetBrains.
the class FileTypeUsagesCollectorTest method doTest.
private void doTest(@NotNull Collection<FileType> fileTypes) throws CollectUsagesException {
final Set<UsageDescriptor> usages = new FileTypeUsagesCollector().getProjectUsages(getProject());
for (UsageDescriptor usage : usages) {
assertEquals(1, usage.getValue());
}
assertEquals(ContainerUtil.map2Set(fileTypes, (NotNullFunction<FileType, String>) fileType -> fileType.getName()), ContainerUtil.map2Set(usages, (NotNullFunction<UsageDescriptor, String>) usageDescriptor -> usageDescriptor.getKey()));
}
use of com.intellij.util.NotNullFunction in project intellij-community by JetBrains.
the class RunIdeConsoleAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
List<String> languages = IdeScriptEngineManager.getInstance().getLanguages();
if (languages.size() == 1) {
runConsole(e, languages.iterator().next());
return;
}
DefaultActionGroup actions = new DefaultActionGroup(ContainerUtil.map(languages, (NotNullFunction<String, AnAction>) language -> new DumbAwareAction(language) {
@Override
public void actionPerformed(@NotNull AnActionEvent e1) {
runConsole(e1, language);
}
}));
JBPopupFactory.getInstance().createActionGroupPopup("Script Engine", actions, e.getDataContext(), JBPopupFactory.ActionSelectionAid.NUMBERING, false).showInBestPositionFor(e.getDataContext());
}
use of com.intellij.util.NotNullFunction in project intellij-community by JetBrains.
the class ImageDuplicateResultsDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
final JPanel panel = new JPanel(new BorderLayout());
DataManager.registerDataProvider(panel, new DataProvider() {
@Override
public Object getData(@NonNls String dataId) {
final TreePath path = myTree.getSelectionPath();
if (path != null) {
Object component = path.getLastPathComponent();
VirtualFile file = null;
if (component instanceof MyFileNode) {
component = ((MyFileNode) component).getParent();
}
if (component instanceof MyDuplicatesNode) {
file = ((MyDuplicatesNode) component).getUserObject().iterator().next();
}
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
return file;
}
if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId) && file != null) {
return new VirtualFile[] { file };
}
}
return null;
}
});
final JBList list = new JBList(new ResourceModules().getModuleNames());
final NotNullFunction<Object, JComponent> modulesRenderer = dom -> new JLabel(dom instanceof Module ? ((Module) dom).getName() : dom.toString(), PlatformIcons.SOURCE_FOLDERS_ICON, SwingConstants.LEFT);
list.installCellRenderer(modulesRenderer);
final JPanel modulesPanel = ToolbarDecorator.createDecorator(list).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final Module[] all = ModuleManager.getInstance(myProject).getModules();
Arrays.sort(all, (o1, o2) -> o1.getName().compareTo(o2.getName()));
final JBList modules = new JBList(all);
modules.installCellRenderer(modulesRenderer);
JBPopupFactory.getInstance().createListPopupBuilder(modules).setTitle("Add Resource Module").setFilteringEnabled(o -> ((Module) o).getName()).setItemChoosenCallback(() -> {
final Object value = modules.getSelectedValue();
if (value instanceof Module && !myResourceModules.contains((Module) value)) {
myResourceModules.add((Module) value);
((DefaultListModel) list.getModel()).addElement(((Module) value).getName());
}
((DefaultTreeModel) myTree.getModel()).reload();
TreeUtil.expandAll(myTree);
}).createPopup().show(button.getPreferredPopupPoint());
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final Object[] values = list.getSelectedValues();
for (Object value : values) {
myResourceModules.remove((String) value);
((DefaultListModel) list.getModel()).removeElement(value);
}
((DefaultTreeModel) myTree.getModel()).reload();
TreeUtil.expandAll(myTree);
}
}).disableDownAction().disableUpAction().createPanel();
modulesPanel.setPreferredSize(new Dimension(-1, 60));
final JPanel top = new JPanel(new BorderLayout());
top.add(new JLabel("Image modules:"), BorderLayout.NORTH);
top.add(modulesPanel, BorderLayout.CENTER);
panel.add(top, BorderLayout.NORTH);
panel.add(new JBScrollPane(myTree), BorderLayout.CENTER);
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
VirtualFile file = getFileFromSelection();
if (file != null) {
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
if (psiFile != null) {
final ImplementationViewComponent viewComponent = new ImplementationViewComponent(new PsiElement[] { psiFile }, 0);
final TreeSelectionListener listener = new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
final VirtualFile selection = getFileFromSelection();
if (selection != null) {
final PsiFile newElement = PsiManager.getInstance(myProject).findFile(selection);
if (newElement != null) {
viewComponent.update(new PsiElement[] { newElement }, 0);
}
}
}
};
myTree.addTreeSelectionListener(listener);
final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(viewComponent, viewComponent.getPreferredFocusableComponent()).setProject(myProject).setDimensionServiceKey(myProject, ImageDuplicateResultsDialog.class.getName(), false).setResizable(true).setMovable(true).setRequestFocus(false).setCancelCallback(() -> {
myTree.removeTreeSelectionListener(listener);
return true;
}).setTitle("Image Preview").createPopup();
final Window window = ImageDuplicateResultsDialog.this.getWindow();
popup.show(new RelativePoint(window, new Point(window.getWidth(), 0)));
viewComponent.setHint(popup, "Image Preview");
}
}
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("ENTER"), panel);
int total = myDuplicates.values().stream().mapToInt(Set::size).sum() - myDuplicates.size();
final JLabel label = new JLabel("<html>Press <b>Enter</b> to preview image<br>Total images found: " + myImages.size() + ". Total duplicates found: " + total + "</html>");
panel.add(label, BorderLayout.SOUTH);
return panel;
}
Aggregations