Search in sources :

Example 1 with Condition

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

the class HgBranchPopup method getInstance.

/**
   * @param currentRepository Current repository, which means the repository of the currently open or selected file.
   */
public static HgBranchPopup getInstance(@NotNull Project project, @NotNull HgRepository currentRepository) {
    HgRepositoryManager manager = HgUtil.getRepositoryManager(project);
    HgProjectSettings hgProjectSettings = ServiceManager.getService(project, HgProjectSettings.class);
    HgMultiRootBranchConfig hgMultiRootBranchConfig = new HgMultiRootBranchConfig(manager.getRepositories());
    Condition<AnAction> preselectActionCondition = new Condition<AnAction>() {

        @Override
        public boolean value(AnAction action) {
            return false;
        }
    };
    return new HgBranchPopup(currentRepository, manager, hgMultiRootBranchConfig, hgProjectSettings, preselectActionCondition);
}
Also used : Condition(com.intellij.openapi.util.Condition) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) HgProjectSettings(org.zmlx.hg4idea.HgProjectSettings) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 2 with Condition

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

the class MavenKeymapExtension method createGroup.

@Override
public KeymapGroup createGroup(Condition<AnAction> condition, final Project project) {
    KeymapGroup result = KeymapGroupFactory.getInstance().createGroup(TasksBundle.message("maven.tasks.action.group.name"), MavenIcons.MavenLogo);
    if (project == null)
        return result;
    Comparator<MavenProject> projectComparator = (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
    Map<MavenProject, Set<Pair<String, String>>> projectToActionsMapping = new TreeMap<>(projectComparator);
    ActionManager actionManager = ActionManager.getInstance();
    //noinspection TestOnlyProblems
    for (String eachId : actionManager.getActionIds(getActionPrefix(project, null))) {
        AnAction eachAction = actionManager.getAction(eachId);
        if (!(eachAction instanceof MavenGoalAction))
            continue;
        if (condition != null && !condition.value(actionManager.getActionOrStub(eachId)))
            continue;
        MavenGoalAction mavenAction = (MavenGoalAction) eachAction;
        MavenProject mavenProject = mavenAction.getMavenProject();
        Set<Pair<String, String>> actions = projectToActionsMapping.get(mavenProject);
        if (actions == null) {
            final List<String> projectGoals = collectGoals(mavenProject);
            actions = new TreeSet<>((o1, o2) -> {
                String goal1 = o1.getFirst();
                String goal2 = o2.getFirst();
                int index1 = projectGoals.indexOf(goal1);
                int index2 = projectGoals.indexOf(goal2);
                if (index1 == index2)
                    return goal1.compareToIgnoreCase(goal2);
                return (index1 < index2 ? -1 : 1);
            });
            projectToActionsMapping.put(mavenProject, actions);
        }
        actions.add(Pair.create(mavenAction.getGoal(), eachId));
    }
    for (Map.Entry<MavenProject, Set<Pair<String, String>>> each : projectToActionsMapping.entrySet()) {
        Set<Pair<String, String>> goalsToActionIds = each.getValue();
        for (Pair<String, String> eachGoalToActionId : goalsToActionIds) {
            result.addActionId(eachGoalToActionId.getSecond());
        }
    }
    Icon icon = SystemInfoRt.isMac ? AllIcons.ToolbarDecorator.Mac.Add : AllIcons.ToolbarDecorator.Add;
    ((Group) result).addHyperlink(new Hyperlink(icon, "Choose a phase/goal to assign a shortcut") {

        @Override
        public void onClick(MouseEvent e) {
            SelectMavenGoalDialog dialog = new SelectMavenGoalDialog(project);
            if (dialog.showAndGet() && dialog.getResult() != null) {
                MavenProjectsStructure.GoalNode goalNode = dialog.getResult();
                String goal = goalNode.getGoal();
                String actionId = MavenShortcutsManager.getInstance(project).getActionId(goalNode.getProjectPath(), goal);
                getOrRegisterAction(goalNode.getMavenProject(), actionId, goal);
                ApplicationManager.getApplication().getMessageBus().syncPublisher(KeymapListener.CHANGE_TOPIC).processCurrentKeymapChanged();
                Settings allSettings = Settings.KEY.getData(DataManager.getInstance().getDataContext(e.getComponent()));
                KeymapPanel keymapPanel = allSettings != null ? allSettings.find(KeymapPanel.class) : null;
                if (keymapPanel != null) {
                    // clear actions filter
                    keymapPanel.showOption("");
                    keymapPanel.selectAction(actionId);
                }
            }
        }
    });
    return result;
}
Also used : KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) Settings(com.intellij.openapi.options.ex.Settings) KeymapGroupFactory(com.intellij.openapi.keymap.KeymapGroupFactory) KeymapPanel(com.intellij.openapi.keymap.impl.ui.KeymapPanel) SystemInfoRt(com.intellij.openapi.util.SystemInfoRt) java.util(java.util) AllIcons(com.intellij.icons.AllIcons) KeymapListener(com.intellij.openapi.keymap.impl.ui.KeymapListener) MavenActionUtil(org.jetbrains.idea.maven.utils.actions.MavenActionUtil) Hyperlink(com.intellij.openapi.keymap.impl.ui.Hyperlink) MavenRunConfigurationType(org.jetbrains.idea.maven.execution.MavenRunConfigurationType) Group(com.intellij.openapi.keymap.impl.ui.Group) SelectMavenGoalDialog(org.jetbrains.idea.maven.navigator.SelectMavenGoalDialog) MavenPluginInfo(org.jetbrains.idea.maven.utils.MavenPluginInfo) ExternalSystemKeymapExtension(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemKeymapExtension) Project(com.intellij.openapi.project.Project) MavenConstants(org.jetbrains.idea.maven.model.MavenConstants) MavenProjectsStructure(org.jetbrains.idea.maven.navigator.MavenProjectsStructure) MavenIcons(icons.MavenIcons) DataManager(com.intellij.ide.DataManager) MavenProject(org.jetbrains.idea.maven.project.MavenProject) MavenRunnerParameters(org.jetbrains.idea.maven.execution.MavenRunnerParameters) MavenAction(org.jetbrains.idea.maven.utils.actions.MavenAction) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) MavenArtifactUtil(org.jetbrains.idea.maven.utils.MavenArtifactUtil) TestOnly(org.jetbrains.annotations.TestOnly) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) MavenPlugin(org.jetbrains.idea.maven.model.MavenPlugin) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) Group(com.intellij.openapi.keymap.impl.ui.Group) SelectMavenGoalDialog(org.jetbrains.idea.maven.navigator.SelectMavenGoalDialog) MavenProject(org.jetbrains.idea.maven.project.MavenProject) Settings(com.intellij.openapi.options.ex.Settings) Pair(com.intellij.openapi.util.Pair) MouseEvent(java.awt.event.MouseEvent) KeymapPanel(com.intellij.openapi.keymap.impl.ui.KeymapPanel) KeymapGroup(com.intellij.openapi.keymap.KeymapGroup) Hyperlink(com.intellij.openapi.keymap.impl.ui.Hyperlink)

Example 3 with Condition

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

the class JavaFxLocationReferenceProvider method collectRefs.

private PsiReference[] collectRefs(@NotNull PsiElement element, String value, int startInElement) {
    final int atSignIndex = value.indexOf('@');
    if (atSignIndex >= 0 && (atSignIndex == 0 || StringUtil.trimLeading(value).startsWith("@"))) {
        value = value.substring(atSignIndex + 1);
        startInElement += atSignIndex + 1;
    }
    final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true) {

        @Override
        protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
            return item -> {
                if (item instanceof PsiDirectory)
                    return true;
                final VirtualFile virtualFile = item.getVirtualFile();
                if (virtualFile == null)
                    return false;
                final FileType fileType = virtualFile.getFileType();
                return myAcceptedFileTypes.contains(fileType);
            };
        }
    };
    if (value.startsWith("/")) {
        set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
    }
    return set.getAllReferences();
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) StringUtil(com.intellij.openapi.util.text.StringUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Set(java.util.Set) FileType(com.intellij.openapi.fileTypes.FileType) ContainerUtil(com.intellij.util.containers.ContainerUtil) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet) ArrayList(java.util.ArrayList) List(java.util.List) com.intellij.psi(com.intellij.psi) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Condition(com.intellij.openapi.util.Condition) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileType(com.intellij.openapi.fileTypes.FileType) FileReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet)

Example 4 with Condition

use of com.intellij.openapi.util.Condition in project kotlin by JetBrains.

the class AbstractUnwrapRemoveTest method doTest.

private void doTest(@NotNull String path, final Class<? extends Unwrapper> unwrapperClass) throws Exception {
    configureByFile(path);
    String fileText = FileUtil.loadFile(new File(path), true);
    String isApplicableString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// IS_APPLICABLE: ");
    boolean isApplicableExpected = isApplicableString == null || isApplicableString.equals("true");
    String option = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// OPTION: ");
    Integer optionIndex = option != null ? Integer.parseInt(option) : 0;
    List<Pair<PsiElement, Unwrapper>> unwrappersWithPsi = new KotlinUnwrapDescriptor().collectUnwrappers(getProject(), getEditor(), getFile());
    if (isApplicableExpected) {
        final Pair<PsiElement, Unwrapper> selectedUnwrapperWithPsi = unwrappersWithPsi.get(optionIndex);
        assertEquals(unwrapperClass, selectedUnwrapperWithPsi.second.getClass());
        final PsiElement first = selectedUnwrapperWithPsi.first;
        ApplicationManager.getApplication().runWriteAction(new Runnable() {

            @Override
            public void run() {
                selectedUnwrapperWithPsi.second.unwrap(getEditor(), first);
            }
        });
        checkResultByFile(path + ".after");
    } else {
        assertTrue(ContainerUtil.and(unwrappersWithPsi, new Condition<Pair<PsiElement, Unwrapper>>() {

            @Override
            public boolean value(Pair<PsiElement, Unwrapper> pair) {
                return pair.second.getClass() != unwrapperClass;
            }
        }));
    }
}
Also used : Condition(com.intellij.openapi.util.Condition) Unwrapper(com.intellij.codeInsight.unwrap.Unwrapper) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair)

Example 5 with Condition

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

the class TreeFileChooserDialog method filterFiles.

private Object[] filterFiles(final Object[] list) {
    Condition<PsiFile> condition = psiFile -> {
        if (myFilter != null && !myFilter.accept(psiFile)) {
            return false;
        }
        boolean accepted = myFileType == null || psiFile.getFileType() == myFileType;
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null && !accepted) {
            accepted = virtualFile.getFileType() == myFileType;
        }
        return accepted;
    };
    final List<Object> result = new ArrayList<>(list.length);
    for (Object o : list) {
        final PsiFile psiFile;
        if (o instanceof PsiFile) {
            psiFile = (PsiFile) o;
        } else if (o instanceof PsiFileNode) {
            psiFile = ((PsiFileNode) o).getValue();
        } else {
            psiFile = null;
        }
        if (psiFile != null && !condition.value(psiFile)) {
            continue;
        } else {
            if (o instanceof ProjectViewNode) {
                final ProjectViewNode projectViewNode = (ProjectViewNode) o;
                if (!projectViewNode.canHaveChildrenMatching(condition)) {
                    continue;
                }
            }
        }
        result.add(o);
    }
    return ArrayUtil.toObjectArray(result);
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) FileTypeIndex(com.intellij.psi.search.FileTypeIndex) BaseProjectTreeBuilder(com.intellij.ide.projectView.BaseProjectTreeBuilder) ProjectTreeBuilder(com.intellij.ide.projectView.impl.ProjectTreeBuilder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) THashSet(gnu.trove.THashSet) ChooseByNamePopupComponent(com.intellij.ide.util.gotoByName.ChooseByNamePopupComponent) ChooseByNamePanel(com.intellij.ide.util.gotoByName.ChooseByNamePanel) PsiManager(com.intellij.psi.PsiManager) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) ProjectAbstractTreeStructureBase(com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase) JBUI(com.intellij.util.ui.JBUI) Disposer(com.intellij.openapi.util.Disposer) ChangeListener(javax.swing.event.ChangeListener) PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) AbstractProjectTreeStructure(com.intellij.ide.projectView.impl.AbstractProjectTreeStructure) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ChangeEvent(javax.swing.event.ChangeEvent) TreePath(javax.swing.tree.TreePath) GotoFileCellRenderer(com.intellij.ide.util.gotoByName.GotoFileCellRenderer) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) KeyEvent(java.awt.event.KeyEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IdeBundle(com.intellij.ide.IdeBundle) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Function(com.intellij.util.Function) ApplicationManager(com.intellij.openapi.application.ApplicationManager) WindowManagerEx(com.intellij.openapi.wm.ex.WindowManagerEx) NotNull(org.jetbrains.annotations.NotNull) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) TreeStructureProvider(com.intellij.ide.projectView.TreeStructureProvider) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) FilenameIndex(com.intellij.psi.search.FilenameIndex) ContainerUtil(com.intellij.util.containers.ContainerUtil) KeyAdapter(java.awt.event.KeyAdapter) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ChooseByNameModel(com.intellij.ide.util.gotoByName.ChooseByNameModel) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) AlphaComparator(com.intellij.ide.util.treeView.AlphaComparator) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Tree(com.intellij.ui.treeStructure.Tree) DumbAware(com.intellij.openapi.project.DumbAware) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) FileType(com.intellij.openapi.fileTypes.FileType) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) Condition(com.intellij.openapi.util.Condition) ScrollPaneFactory(com.intellij.ui.ScrollPaneFactory) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) PsiFile(com.intellij.psi.PsiFile)

Aggregations

Condition (com.intellij.openapi.util.Condition)48 NotNull (org.jetbrains.annotations.NotNull)26 Nullable (org.jetbrains.annotations.Nullable)23 Project (com.intellij.openapi.project.Project)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 List (java.util.List)16 StringUtil (com.intellij.openapi.util.text.StringUtil)15 ContainerUtil (com.intellij.util.containers.ContainerUtil)14 javax.swing (javax.swing)13 PsiElement (com.intellij.psi.PsiElement)11 Module (com.intellij.openapi.module.Module)10 java.util (java.util)10 Logger (com.intellij.openapi.diagnostic.Logger)9 ApplicationManager (com.intellij.openapi.application.ApplicationManager)8 NonNls (org.jetbrains.annotations.NonNls)8 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)7 Collection (java.util.Collection)7 ModalityState (com.intellij.openapi.application.ModalityState)6 Document (com.intellij.openapi.editor.Document)6 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)6