Search in sources :

Example 31 with Consumer

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

the class BaseProjectTreeBuilder method _select.

private void _select(final Object element, final VirtualFile file, final boolean requestFocus, final Condition<AbstractTreeNode> nonStopCondition, final ActionCallback result, @NotNull final ProgressIndicator indicator, @Nullable final Ref<Object> virtualSelectTarget, final FocusRequestor focusRequestor, final boolean isSecondAttempt) {
    final AbstractTreeNode alreadySelected = alreadySelectedNode(element);
    final Runnable onDone = () -> {
        if (requestFocus && virtualSelectTarget == null && getUi().isReady()) {
            focusRequestor.requestFocus(getTree(), true);
        }
        result.setDone();
    };
    final Condition<AbstractTreeNode> condition = abstractTreeNode -> !result.isProcessed() && nonStopCondition.value(abstractTreeNode);
    if (alreadySelected == null) {
        expandPathTo(file, (AbstractTreeNode) getTreeStructure().getRootElement(), element, condition, indicator, virtualSelectTarget).doWhenDone(new Consumer<AbstractTreeNode>() {

            @Override
            public void consume(AbstractTreeNode node) {
                if (virtualSelectTarget == null) {
                    select(node, onDone);
                } else {
                    onDone.run();
                }
            }
        }).doWhenRejected(() -> {
            if (isSecondAttempt) {
                result.setRejected();
            } else {
                _select(file, file, requestFocus, nonStopCondition, result, indicator, virtualSelectTarget, focusRequestor, true);
            }
        });
    } else if (virtualSelectTarget == null) {
        scrollTo(alreadySelected, onDone);
    } else {
        onDone.run();
    }
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) UiActivityMonitor(com.intellij.ide.UiActivityMonitor) Arrays(java.util.Arrays) StatusBarProgress(com.intellij.openapi.progress.util.StatusBarProgress) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TreeNode(javax.swing.tree.TreeNode) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) FocusRequestor(com.intellij.openapi.wm.FocusRequestor) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Progressive(com.intellij.openapi.progress.Progressive) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) FavoritesTreeNodeDescriptor(com.intellij.ide.favoritesTreeView.FavoritesTreeNodeDescriptor) TreePath(javax.swing.tree.TreePath) UiActivity(com.intellij.ide.UiActivity) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure) Registry(com.intellij.openapi.util.registry.Registry) PsiDirectory(com.intellij.psi.PsiDirectory) ObjectUtils(com.intellij.util.ObjectUtils) AbstractTreeUpdater(com.intellij.ide.util.treeView.AbstractTreeUpdater) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Consumer(com.intellij.util.Consumer) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) javax.swing(javax.swing) Consumer(com.intellij.util.Consumer) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 32 with Consumer

use of com.intellij.util.Consumer in project intellij-plugins by JetBrains.

the class Struts2TilesModelProvider method computeModels.

@NotNull
public Collection<TilesModel> computeModels(@NotNull final Module module) {
    final Project project = module.getProject();
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
    final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
    // struts2-tiles plugin must be available
    final PsiClass strutsTilesListenerClass = facade.findClass(STRUTS_TILES_LISTENER_CLASS, moduleScope);
    if (strutsTilesListenerClass == null) {
        return Collections.emptyList();
    }
    final PsiClass tilesListenerClass = facade.findClass(TilesConstants.TILES_LISTENER, moduleScope);
    final StrutsPluginDomFactory<TilesDefinitions, TilesModel> factory = StrutsProjectComponent.getInstance(project).getTilesFactory();
    final Set<TilesModel> struts2TilesModels = new HashSet<>();
    final Consumer<Set<XmlFile>> consumer = definitions -> {
        final DomFileElement<TilesDefinitions> domFileElement = factory.createMergedModelRoot(definitions);
        if (domFileElement != null) {
            struts2TilesModels.add(new TilesModelImpl(definitions, domFileElement, STRUTS2_TILES_MODEL));
        }
    };
    final WebDirectoryUtil webDirectoryUtil = WebDirectoryUtil.getWebDirectoryUtil(project);
    final Collection<WebFacet> webFacets = WebFacet.getInstances(module);
    for (final WebFacet webFacet : webFacets) {
        final WebApp webApp = webFacet.getRoot();
        if (webApp == null) {
            continue;
        }
        // determine configured tiles config files
        @NonNls final Set<String> tilesConfigNames = findConfiguredTilesPaths(webApp);
        // no configured paths? use default
        if (tilesConfigNames.isEmpty()) {
            tilesConfigNames.add(DEFAULT_TILES_XML);
        }
        // resolve to XmlFile
        final Set<XmlFile> tilesFileSet = new HashSet<>();
        for (final String tilesPath : tilesConfigNames) {
            final PsiElement tilesXmlFile = webDirectoryUtil.findFileByPath(tilesPath, webFacet);
            if (tilesXmlFile instanceof XmlFile) {
                tilesFileSet.add((XmlFile) tilesXmlFile);
            }
        }
        final List<Listener> listenerList = webApp.getListeners();
        for (final Listener listener : listenerList) {
            final PsiClass listenerClass = listener.getListenerClass().getValue();
            if (strutsTilesListenerClass.equals(listenerClass) || Comparing.equal(tilesListenerClass, listenerClass)) {
                consumer.consume(tilesFileSet);
            }
        }
    }
    return struts2TilesModels;
}
Also used : JavaPsiFacade(com.intellij.psi.JavaPsiFacade) WebFacet(com.intellij.javaee.web.facet.WebFacet) XmlFile(com.intellij.psi.xml.XmlFile) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) HashSet(com.intellij.util.containers.HashSet) NonNls(org.jetbrains.annotations.NonNls) THashSet(gnu.trove.THashSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsProjectComponent(com.intellij.struts.StrutsProjectComponent) PsiClass(com.intellij.psi.PsiClass) Comparing(com.intellij.openapi.util.Comparing) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) TilesModelProvider(com.intellij.struts.TilesModelProvider) WebDirectoryUtil(com.intellij.psi.impl.source.jsp.WebDirectoryUtil) TilesDefinitions(com.intellij.struts.dom.tiles.TilesDefinitions) TilesModel(com.intellij.struts.TilesModel) TilesConstants(com.intellij.tiles.TilesConstants) StringUtil(com.intellij.openapi.util.text.StringUtil) TilesModelImpl(com.intellij.struts.psi.TilesModelImpl) Collection(java.util.Collection) DomFileElement(com.intellij.util.xml.DomFileElement) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) List(java.util.List) WebApp(com.intellij.javaee.model.xml.web.WebApp) ParamValue(com.intellij.javaee.model.xml.ParamValue) Listener(com.intellij.javaee.model.xml.Listener) NotNull(org.jetbrains.annotations.NotNull) StrutsPluginDomFactory(com.intellij.struts.StrutsPluginDomFactory) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) Condition(com.intellij.openapi.util.Condition) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet) Set(java.util.Set) Listener(com.intellij.javaee.model.xml.Listener) TilesModelImpl(com.intellij.struts.psi.TilesModelImpl) DomFileElement(com.intellij.util.xml.DomFileElement) WebDirectoryUtil(com.intellij.psi.impl.source.jsp.WebDirectoryUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet) THashSet(gnu.trove.THashSet) NonNls(org.jetbrains.annotations.NonNls) XmlFile(com.intellij.psi.xml.XmlFile) PsiClass(com.intellij.psi.PsiClass) TilesDefinitions(com.intellij.struts.dom.tiles.TilesDefinitions) TilesModel(com.intellij.struts.TilesModel) Project(com.intellij.openapi.project.Project) WebFacet(com.intellij.javaee.web.facet.WebFacet) WebApp(com.intellij.javaee.model.xml.web.WebApp) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with Consumer

use of com.intellij.util.Consumer in project intellij-plugins by JetBrains.

the class FlexUnitTestCreator method createTest.

public void createTest(final Project project, final Editor editor, final PsiFile file) {
    final JSClass jsClass = FlexUnitTestFinder.findContextClass(file);
    if (jsClass == null)
        return;
    final String testClassName;
    final String packageName;
    final JSClass superClass;
    final PsiDirectory targetDirectory;
    final boolean generateSetUp;
    final boolean generateTearDown;
    final JSMemberInfo[] selectedMemberInfos;
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        testClassName = jsClass.getName() + "Test";
        packageName = StringUtil.getPackageName(jsClass.getQualifiedName());
        superClass = null;
        targetDirectory = jsClass.getContainingFile().getContainingDirectory();
        generateSetUp = true;
        generateTearDown = true;
        selectedMemberInfos = new JSMemberInfo[0];
    } else {
        final CreateFlexUnitTestDialog dialog = new CreateFlexUnitTestDialog(ModuleUtilCore.findModuleForPsiElement(jsClass), jsClass);
        dialog.show();
        if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
            return;
        }
        testClassName = dialog.getTestClassName();
        packageName = dialog.getPackageName();
        superClass = dialog.getSuperClass();
        targetDirectory = dialog.getTargetDirectory();
        generateSetUp = dialog.isGenerateSetUp();
        generateTearDown = dialog.isGenerateTearDown();
        selectedMemberInfos = dialog.getSelectedMemberInfos();
    }
    final Consumer<JSClass> postProcessRunnable = createdClass -> {
        final String methodsText = getMethodsText(createdClass, generateSetUp, generateTearDown, selectedMemberInfos);
        if (!methodsText.isEmpty()) {
            final PsiElement methods = JSChangeUtil.createJSTreeFromText(project, "{" + methodsText + "}", JavaScriptSupportLoader.ECMA_SCRIPT_L4).getPsi();
            if (methods != null) {
                for (final PsiElement psiElement : PsiTreeUtil.getChildrenOfTypeAsList(methods, JSFunction.class)) {
                    createdClass.add(psiElement);
                }
            }
        }
        CodeStyleManager.getInstance(project).reformat(createdClass);
        createdClass.navigate(true);
    };
    CommandProcessor.getInstance().executeCommand(project, () -> ActionScriptCreateClassOrInterfaceFix.createClass(ActionScriptCreateClassOrInterfaceFix.ACTION_SCRIPT_CLASS_WITH_SUPERS_TEMPLATE_NAME, testClassName, packageName, superClass, Collections.emptyList(), targetDirectory, CodeInsightBundle.message("intention.create.test"), true, Collections.emptyMap(), postProcessRunnable), CodeInsightBundle.message("intention.create.test"), null);
}
Also used : JavaScriptSupportLoader(com.intellij.lang.javascript.JavaScriptSupportLoader) JSChangeUtil(com.intellij.lang.javascript.psi.impl.JSChangeUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) THashSet(gnu.trove.THashSet) ActionScriptCreateClassOrInterfaceFix(com.intellij.lang.javascript.validation.fixes.ActionScriptCreateClassOrInterfaceFix) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) FunctionKind(com.intellij.lang.javascript.psi.JSFunction.FunctionKind) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) TestCreator(com.intellij.testIntegration.TestCreator) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) StringUtil(com.intellij.openapi.util.text.StringUtil) Set(java.util.Set) Editor(com.intellij.openapi.editor.Editor) CommandProcessor(com.intellij.openapi.command.CommandProcessor) JSFunction(com.intellij.lang.javascript.psi.JSFunction) CodeStyleManager(com.intellij.psi.codeStyle.CodeStyleManager) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PsiDirectory(com.intellij.psi.PsiDirectory) JSInheritanceUtil(com.intellij.lang.javascript.psi.resolve.JSInheritanceUtil) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) JSFunction(com.intellij.lang.javascript.psi.JSFunction) PsiDirectory(com.intellij.psi.PsiDirectory) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) JSMemberInfo(com.intellij.lang.javascript.refactoring.util.JSMemberInfo) PsiElement(com.intellij.psi.PsiElement)

Example 34 with Consumer

use of com.intellij.util.Consumer in project intellij-plugins by JetBrains.

the class FlashRunnerParameters method reportWarnings.

public void reportWarnings(final Project project) throws RuntimeConfigurationWarning {
    try {
        final Pair<Module, FlexBuildConfiguration> moduleAndBC = super.checkAndGetModuleAndBC(project);
        final Module module = moduleAndBC.first;
        final FlexBuildConfiguration bc = moduleAndBC.second;
        final Ref<String> errorMessageRef = new Ref<>(null);
        final Consumer<FlashProjectStructureProblem> consumer = problem -> errorMessageRef.set(problem.errorMessage);
        if (bc.getTargetPlatform() == TargetPlatform.Desktop) {
            checkAirVersionIfCustomDescriptor(module, bc.getSdk(), bc.getAirDesktopPackagingOptions(), consumer, true, getBCName());
        } else if (bc.getTargetPlatform() == TargetPlatform.Mobile) {
            switch(myMobileRunTarget) {
                case Emulator:
                    switch(myAppDescriptorForEmulator) {
                        case Android:
                            checkAirVersionIfCustomDescriptor(module, bc.getSdk(), bc.getAndroidPackagingOptions(), consumer, true, getBCName());
                            break;
                        case IOS:
                            checkAirVersionIfCustomDescriptor(module, bc.getSdk(), bc.getIosPackagingOptions(), consumer, true, getBCName());
                            break;
                    }
                    break;
                case AndroidDevice:
                    checkAirVersionIfCustomDescriptor(module, bc.getSdk(), bc.getAndroidPackagingOptions(), consumer, true, getBCName());
                    break;
                case iOSSimulator:
                case iOSDevice:
                    checkAirVersionIfCustomDescriptor(module, bc.getSdk(), bc.getIosPackagingOptions(), consumer, true, getBCName());
                    break;
            }
        }
        if (!errorMessageRef.isNull()) {
            throw new RuntimeConfigurationWarning(errorMessageRef.get());
        }
    } catch (RuntimeConfigurationError e) {
    /* should be already checked somewhere else */
    }
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) OutputType(com.intellij.flex.model.bc.OutputType) ArrayUtil(com.intellij.util.ArrayUtil) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TargetPlatform(com.intellij.flex.model.bc.TargetPlatform) ActionScriptClassResolver(com.intellij.javascript.flex.resolve.ActionScriptClassResolver) PsiManager(com.intellij.psi.PsiManager) FlexCommonUtils(com.intellij.flex.FlexCommonUtils) AirPackagingConfigurableBase(com.intellij.lang.javascript.flex.projectStructure.ui.AirPackagingConfigurableBase) BCUtils(com.intellij.lang.javascript.flex.projectStructure.options.BCUtils) Factory(com.intellij.lang.javascript.flex.projectStructure.model.impl.Factory) FlexmojosSdkType(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) FileUtil(com.intellij.openapi.util.io.FileUtil) FlexSdkUtils(com.intellij.lang.javascript.flex.sdk.FlexSdkUtils) Module(com.intellij.openapi.module.Module) ProjectStructureProblemType(com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureProblemType) FlexCommonBundle(com.intellij.flex.FlexCommonBundle) EnumSet(java.util.EnumSet) XmlTag(com.intellij.psi.xml.XmlTag) FlexSdkComboBoxWithBrowseButton(com.intellij.lang.javascript.flex.sdk.FlexSdkComboBoxWithBrowseButton) MalformedURLException(java.net.MalformedURLException) StringUtil(com.intellij.openapi.util.text.StringUtil) BrowserUtil(com.intellij.ide.BrowserUtil) FlexBundle(com.intellij.lang.javascript.flex.FlexBundle) com.intellij.lang.javascript.flex.projectStructure.model(com.intellij.lang.javascript.flex.projectStructure.model) Sdk(com.intellij.openapi.projectRoots.Sdk) SystemInfo(com.intellij.openapi.util.SystemInfo) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) LinkageType(com.intellij.flex.model.bc.LinkageType) FlashProjectStructureProblem(com.intellij.lang.javascript.flex.build.FlashProjectStructureProblem) Nullable(org.jetbrains.annotations.Nullable) AirPackageUtil(com.intellij.lang.javascript.flex.actions.airpackage.AirPackageUtil) List(java.util.List) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) Pair(com.intellij.openapi.util.Pair) RuntimeConfigurationWarning(com.intellij.execution.configurations.RuntimeConfigurationWarning) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) Collections(java.util.Collections) Consumer(com.intellij.util.Consumer) Ref(com.intellij.openapi.util.Ref) RuntimeConfigurationWarning(com.intellij.execution.configurations.RuntimeConfigurationWarning) FlashProjectStructureProblem(com.intellij.lang.javascript.flex.build.FlashProjectStructureProblem) Module(com.intellij.openapi.module.Module) RuntimeConfigurationError(com.intellij.execution.configurations.RuntimeConfigurationError)

Example 35 with Consumer

use of com.intellij.util.Consumer in project android by JetBrains.

the class ScreenshotAction method performAction.

@Override
protected void performAction(@NotNull final IDevice device) {
    final Project project = myProject;
    new ScreenshotTask(project, device) {

        @Override
        public void onSuccess() {
            String msg = getError();
            if (msg != null) {
                Messages.showErrorDialog(project, msg, AndroidBundle.message("android.ddms.actions.screenshot"));
                return;
            }
            try {
                File backingFile = FileUtil.createTempFile("screenshot", SdkConstants.DOT_PNG, true);
                ImageIO.write(getScreenshot(), SdkConstants.EXT_PNG, backingFile);
                final ScreenshotViewer viewer = new ScreenshotViewer(project, getScreenshot(), backingFile, device, device.getProperty(IDevice.PROP_DEVICE_MODEL));
                viewer.showAndGetOk().doWhenDone((Consumer<Boolean>) ok -> {
                    if (ok) {
                        File screenshot = viewer.getScreenshot();
                        VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(screenshot);
                        if (vf != null) {
                            vf.refresh(false, false);
                            FileEditorManager.getInstance(project).openFile(vf, true);
                        }
                    }
                });
            } catch (Exception e) {
                Logger.getInstance(ScreenshotAction.class).warn("Error while displaying screenshot viewer: ", e);
                Messages.showErrorDialog(project, AndroidBundle.message("android.ddms.screenshot.generic.error", e), AndroidBundle.message("android.ddms.actions.screenshot"));
            }
        }
    }.queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Consumer(com.intellij.util.Consumer) ScreenshotTask(com.android.tools.idea.ddms.screenshot.ScreenshotTask) ScreenshotViewer(com.android.tools.idea.ddms.screenshot.ScreenshotViewer) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

Consumer (com.intellij.util.Consumer)59 NotNull (org.jetbrains.annotations.NotNull)41 Project (com.intellij.openapi.project.Project)37 Nullable (org.jetbrains.annotations.Nullable)33 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 List (java.util.List)22 ApplicationManager (com.intellij.openapi.application.ApplicationManager)17 StringUtil (com.intellij.openapi.util.text.StringUtil)17 javax.swing (javax.swing)16 ContainerUtil (com.intellij.util.containers.ContainerUtil)15 Logger (com.intellij.openapi.diagnostic.Logger)14 Module (com.intellij.openapi.module.Module)12 java.awt (java.awt)12 Pair (com.intellij.openapi.util.Pair)11 java.util (java.util)11 File (java.io.File)10 Collection (java.util.Collection)10 PsiElement (com.intellij.psi.PsiElement)9 PsiFile (com.intellij.psi.PsiFile)9 DataContext (com.intellij.openapi.actionSystem.DataContext)8