Search in sources :

Example 1 with NotNullFunction

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);
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) java.util(java.util) AllIcons(com.intellij.icons.AllIcons) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Computable(com.intellij.openapi.util.Computable) ContainerUtil(com.intellij.util.containers.ContainerUtil) ReadAction(com.intellij.openapi.application.ReadAction) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Messages(com.intellij.openapi.ui.Messages) Logger(com.intellij.openapi.diagnostic.Logger) ListSelectionEvent(javax.swing.event.ListSelectionEvent) InputValidatorEx(com.intellij.openapi.ui.InputValidatorEx) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) JBList(com.intellij.ui.components.JBList) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) NotNullFunction(com.intellij.util.NotNullFunction) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) com.intellij.ui(com.intellij.ui) com.intellij.lang.properties(com.intellij.lang.properties) Nullable(org.jetbrains.annotations.Nullable) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) java.awt.event(java.awt.event) FileTemplateUtil(com.intellij.ide.fileTemplates.FileTemplateUtil) PsiDirectory(com.intellij.psi.PsiDirectory) PathUtil(com.intellij.util.PathUtil) NotNull(org.jetbrains.annotations.NotNull) ListSelectionListener(javax.swing.event.ListSelectionListener) javax.swing(javax.swing) PsiFile(com.intellij.psi.PsiFile) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) XmlPropertiesFile(com.intellij.lang.properties.xml.XmlPropertiesFile) ResourceBundle(com.intellij.lang.properties.ResourceBundle)

Example 2 with NotNullFunction

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()]);
}
Also used : XPath(org.jdom.xpath.XPath) SAXBuilder(org.jdom.input.SAXBuilder) TasksIcons(icons.TasksIcons) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Tag(com.intellij.util.xmlb.annotations.Tag) StringUtil(com.intellij.openapi.util.text.StringUtil) Date(java.util.Date) NotNullFunction(com.intellij.util.NotNullFunction) BaseRepository(com.intellij.tasks.impl.BaseRepository) PostMethod(org.apache.commons.httpclient.methods.PostMethod) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ContainerUtil(com.intellij.util.containers.ContainerUtil) BaseRepositoryImpl(com.intellij.tasks.impl.BaseRepositoryImpl) XPath(org.jdom.xpath.XPath) Nullable(org.jetbrains.annotations.Nullable) Document(org.jdom.Document) List(java.util.List) Comparing(com.intellij.openapi.util.Comparing) com.intellij.tasks(com.intellij.tasks) PasswordUtil(com.intellij.openapi.util.PasswordUtil) Logger(com.intellij.openapi.diagnostic.Logger) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) javax.swing(javax.swing) SAXBuilder(org.jdom.input.SAXBuilder) PostMethod(org.apache.commons.httpclient.methods.PostMethod) Element(org.jdom.Element) List(java.util.List) Document(org.jdom.Document) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException)

Example 3 with NotNullFunction

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()));
}
Also used : UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) NotNullFunction(com.intellij.util.NotNullFunction)

Example 4 with NotNullFunction

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());
}
Also used : NotNullFunction(com.intellij.util.NotNullFunction) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction)

Example 5 with NotNullFunction

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UIUtil(com.intellij.util.ui.UIUtil) java.util(java.util) ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) PsiManager(com.intellij.psi.PsiManager) ModuleUtil(com.intellij.openapi.module.ModuleUtil) TreeSelectionListener(javax.swing.event.TreeSelectionListener) PropertyName(com.intellij.ide.util.PropertyName) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Tree(com.intellij.ui.treeStructure.Tree) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) DataManager(com.intellij.ide.DataManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) PlatformIcons(com.intellij.util.PlatformIcons) JBList(com.intellij.ui.components.JBList) TreeUtil(com.intellij.util.ui.tree.TreeUtil) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) TreePath(javax.swing.tree.TreePath) StringUtil(com.intellij.openapi.util.text.StringUtil) NotNullFunction(com.intellij.util.NotNullFunction) com.intellij.ui(com.intellij.ui) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) JBPopup(com.intellij.openapi.ui.popup.JBPopup) File(java.io.File) JBScrollPane(com.intellij.ui.components.JBScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) NotNull(org.jetbrains.annotations.NotNull) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) RelativePoint(com.intellij.ui.awt.RelativePoint) javax.swing(javax.swing) TreeSelectionListener(javax.swing.event.TreeSelectionListener) RelativePoint(com.intellij.ui.awt.RelativePoint) PsiFile(com.intellij.psi.PsiFile) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PsiElement(com.intellij.psi.PsiElement) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) TreePath(javax.swing.tree.TreePath) JBList(com.intellij.ui.components.JBList) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Module(com.intellij.openapi.module.Module) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Aggregations

NotNullFunction (com.intellij.util.NotNullFunction)8 NotNull (org.jetbrains.annotations.NotNull)4 Project (com.intellij.openapi.project.Project)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 List (java.util.List)3 javax.swing (javax.swing)3 Nullable (org.jetbrains.annotations.Nullable)3 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)2 Logger (com.intellij.openapi.diagnostic.Logger)2 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 com.intellij.ui (com.intellij.ui)2 JBList (com.intellij.ui.components.JBList)2 java.util (java.util)2 ImplementationViewComponent (com.intellij.codeInsight.hint.ImplementationViewComponent)1 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)1 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)1 AllIcons (com.intellij.icons.AllIcons)1