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();
}
}
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;
}
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);
}
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 */
}
}
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();
}
Aggregations