Java Code Examples for com.intellij.openapi.util.AsyncResult#doWhenDone()
The following examples show how to use
com.intellij.openapi.util.AsyncResult#doWhenDone() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileChooserDialogImpl.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Nonnull @Override public AsyncResult<VirtualFile[]> chooseAsync(@Nullable VirtualFile toSelect) { init(); restoreSelection(toSelect); AsyncResult<VirtualFile[]> result = AsyncResult.undefined(); AsyncResult<Void> showAsync = showAsync(); showAsync.doWhenDone(() -> { if (myChosenFiles.length > 0) { result.setDone(myChosenFiles); } else { result.setRejected(); } }); showAsync.doWhenRejected((Runnable)result::setRejected); return result; }
Example 2
Source File: AbstractArtifactsBeforeRunTaskProvider.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Nonnull @Override public AsyncResult<Void> configureTask(RunConfiguration runConfiguration, T task) { final Artifact[] artifacts = ArtifactManager.getInstance(myProject).getArtifacts(); Set<ArtifactPointer> pointers = new THashSet<>(); for (Artifact artifact : artifacts) { pointers.add(ArtifactPointerManager.getInstance(myProject).create(artifact)); } pointers.addAll(task.getArtifactPointers()); ArtifactChooser chooser = new ArtifactChooser(new ArrayList<>(pointers)); chooser.markElements(task.getArtifactPointers()); chooser.setPreferredSize(new Dimension(400, 300)); DialogBuilder builder = new DialogBuilder(myProject); builder.setTitle(CompilerBundle.message("build.artifacts.before.run.selector.title")); builder.setDimensionServiceKey("#BuildArtifactsBeforeRunChooser"); builder.addOkAction(); builder.addCancelAction(); builder.setCenterPanel(chooser); builder.setPreferredFocusComponent(chooser); AsyncResult<Void> result = builder.showAsync(); result.doWhenDone(() -> task.setArtifactPointers(chooser.getMarkedElements())); return result; }
Example 3
Source File: ModuleImportProcessor.java From consulo with Apache License 2.0 | 6 votes |
/** * Will execute module importing. Will show popup for selecting import providers if more that one, and then show import wizard * * @param project - null mean its new project creation * @return */ @RequiredUIAccess public static <C extends ModuleImportContext> AsyncResult<Pair<C, ModuleImportProvider<C>>> showFileChooser(@Nullable Project project, @Nullable FileChooserDescriptor chooserDescriptor) { boolean isModuleImport = project != null; FileChooserDescriptor descriptor = ObjectUtil.notNull(chooserDescriptor, createAllImportDescriptor(isModuleImport)); VirtualFile toSelect = null; String lastLocation = PropertiesComponent.getInstance().getValue(LAST_IMPORTED_LOCATION); if (lastLocation != null) { toSelect = LocalFileSystem.getInstance().refreshAndFindFileByPath(lastLocation); } AsyncResult<Pair<C, ModuleImportProvider<C>>> result = AsyncResult.undefined(); AsyncResult<VirtualFile> fileChooseAsync = FileChooser.chooseFile(descriptor, project, toSelect); fileChooseAsync.doWhenDone((f) -> { PropertiesComponent.getInstance().setValue(LAST_IMPORTED_LOCATION, f.getPath()); showImportChooser(project, f, AsyncResult.undefined()); }); fileChooseAsync.doWhenRejected((Runnable)result::setRejected); return result; }
Example 4
Source File: ModuleImportProcessor.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @SuppressWarnings("unchecked") public static <C extends ModuleImportContext> void showImportChooser(@Nullable Project project, @Nonnull VirtualFile file, @Nonnull List<ModuleImportProvider> providers, @Nonnull AsyncResult<Pair<C, ModuleImportProvider<C>>> result) { if (providers.size() == 1) { showImportWizard(project, file, providers.get(0), result); } else { AsyncResult<ModuleImportProvider> importResult = showImportTarget(providers); importResult.doWhenDone((r) -> showImportWizard(project, file, r, result)); } }
Example 5
Source File: FileChooserDialogImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @RequiredUIAccess @Override public AsyncResult<VirtualFile[]> chooseAsync(@Nullable Project project, @Nonnull VirtualFile[] toSelect) { init(); if ((myProject == null) && (project != null)) { myProject = project; } if (toSelect.length == 1) { restoreSelection(toSelect[0]); } else if (toSelect.length == 0) { restoreSelection(null); // select last opened file } else { selectInTree(toSelect, true); } AsyncResult<VirtualFile[]> result = AsyncResult.undefined(); AsyncResult<Void> showAsync = showAsync(); showAsync.doWhenDone(() -> { if (myChosenFiles.length > 0) { result.setDone(myChosenFiles); } else { result.setRejected(); } }); showAsync.doWhenRejected((Runnable)result::setRejected); return result; }
Example 6
Source File: ImportModuleAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess public static void executeImportAction(@Nonnull Project project, @Nullable FileChooserDescriptor descriptor) { AsyncResult<Pair<ModuleImportContext, ModuleImportProvider<ModuleImportContext>>> chooser = ModuleImportProcessor.showFileChooser(project, descriptor); chooser.doWhenDone(pair -> { ModuleImportContext context = pair.getFirst(); ModuleImportProvider<ModuleImportContext> provider = pair.getSecond(); ModifiableModuleModel modifiableModel = ModuleManager.getInstance(project).getModifiableModel(); provider.process(context, project, modifiableModel, module -> { }); WriteAction.runAndWait(modifiableModel::commit); }); }
Example 7
Source File: AbstractToolBeforeRunTaskProvider.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @RequiredUIAccess @Override public AsyncResult<Void> configureTask(RunConfiguration runConfiguration, T task) { final ToolSelectDialog dialog = new ToolSelectDialog(runConfiguration.getProject(), task.getToolActionId(), createToolsPanel()); AsyncResult<Void> result = AsyncResult.undefined(); AsyncResult<Void> showAsync = dialog.showAsync(); showAsync.doWhenDone(() -> { boolean isModified = dialog.isModified(); Tool selectedTool = dialog.getSelectedTool(); LOG.assertTrue(selectedTool != null); String selectedToolId = selectedTool.getActionId(); String oldToolId = task.getToolActionId(); if (oldToolId != null && oldToolId.equals(selectedToolId)) { if (isModified) { result.setDone(); } else { result.setRejected(); } return; } task.setToolActionId(selectedToolId); result.setDone(); }); showAsync.doWhenRejected((Runnable)result::setRejected); return result; }
Example 8
Source File: RunConfigurationBeforeRunProvider.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @RequiredUIAccess @Override public AsyncResult<Void> configureTask(RunConfiguration runConfiguration, RunConfigurableBeforeRunTask task) { SelectionDialog dialog = new SelectionDialog(task.getSettings(), getAvailableConfigurations(runConfiguration)); AsyncResult<Void> result = dialog.showAsync(); result.doWhenDone(() -> { RunnerAndConfigurationSettings settings = dialog.getSelectedSettings(); task.setSettings(settings); }); return result; }
Example 9
Source File: NewModuleAction.java From consulo with Apache License 2.0 | 5 votes |
@Override @RequiredUIAccess public void actionPerformed(@Nonnull AnActionEvent e) { final Project project = getEventProject(e); if (project == null) { return; } final VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE); final ModuleManager moduleManager = ModuleManager.getInstance(project); FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(false, true, false, false, false, false) { @Override @RequiredUIAccess public boolean isFileSelectable(VirtualFile file) { if (!super.isFileSelectable(file)) { return false; } for (Module module : moduleManager.getModules()) { VirtualFile moduleDir = module.getModuleDir(); if (moduleDir != null && moduleDir.equals(file)) { return false; } } return true; } }; fileChooserDescriptor.setTitle(ProjectBundle.message("choose.module.home")); AsyncResult<VirtualFile> chooseAsync = FileChooser.chooseFile(fileChooserDescriptor, project, virtualFile != null && virtualFile.isDirectory() ? virtualFile : null); chooseAsync.doWhenDone(moduleDir -> { NewProjectDialog dialog = new NewProjectDialog(project, moduleDir); dialog.showAsync().doWhenDone(() -> { NewProjectPanel panel = dialog.getProjectPanel(); NewOrImportModuleUtil.doCreate(panel, project, moduleDir); }); }); }
Example 10
Source File: ModuleImportProcessor.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess private static <C extends ModuleImportContext> void showImportWizard(@Nullable Project project, @Nonnull VirtualFile targetFile, @Nonnull ModuleImportProvider<C> moduleImportProvider, @Nonnull AsyncResult<Pair<C, ModuleImportProvider<C>>> result) { ModuleImportDialog<C> dialog = new ModuleImportDialog<>(project, targetFile, moduleImportProvider); AsyncResult<Void> showAsync = dialog.showAsync(); showAsync.doWhenDone(() -> result.setDone(Pair.create(dialog.getContext(), moduleImportProvider))); showAsync.doWhenRejected(() -> result.setRejected(Pair.create(dialog.getContext(), moduleImportProvider))); }
Example 11
Source File: MavenImportingTestCase.java From intellij-quarkus with Eclipse Public License 2.0 | 5 votes |
protected MavenArtifactDownloader.DownloadResult downloadArtifacts(Collection<MavenProject> projects, List<MavenArtifact> artifacts) { final MavenArtifactDownloader.DownloadResult[] unresolved = new MavenArtifactDownloader.DownloadResult[1]; AsyncResult<MavenArtifactDownloader.DownloadResult> result = new AsyncResult<>(); result.doWhenDone((AsyncResult.Handler<MavenArtifactDownloader.DownloadResult>) downloadResult -> unresolved[0] = downloadResult); myProjectsManager.scheduleArtifactsDownloading(projects, artifacts, true, true, result); myProjectsManager.waitForArtifactsDownloadingCompletion(); return unresolved[0]; }
Example 12
Source File: AsyncProgramRunner.java From consulo with Apache License 2.0 | 5 votes |
protected static void startRunProfile(ExecutionEnvironment environment, RunProfileState state, ProgramRunner.Callback callback, @javax.annotation.Nullable RunProfileStarter starter) { ThrowableComputable<AsyncResult<RunContentDescriptor>, ExecutionException> func = () -> { AsyncResult<RunContentDescriptor> promise = starter == null ? AsyncResult.done(null) : starter.executeAsync(state, environment); return promise.doWhenDone(it -> BaseProgramRunner.postProcess(environment, it, callback)); }; ExecutionManager.getInstance(environment.getProject()).startRunProfile(runProfileStarter(func), state, environment); }
Example 13
Source File: ChooseComponentsToExportDialog.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @RequiredUIAccess public static AsyncResult<String> chooseSettingsFile(String oldPath, Component parent, final String title, final String description) { FileChooserDescriptor chooserDescriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor(); chooserDescriptor.setDescription(description); chooserDescriptor.setHideIgnored(false); chooserDescriptor.setTitle(title); VirtualFile initialDir; if (oldPath != null) { final File oldFile = new File(oldPath); initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile); if (initialDir == null && oldFile.getParentFile() != null) { initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile.getParentFile()); } } else { initialDir = null; } final AsyncResult<String> result = AsyncResult.undefined(); AsyncResult<VirtualFile[]> fileAsyncResult = FileChooser.chooseFiles(chooserDescriptor, null, parent, initialDir); fileAsyncResult.doWhenDone(files -> { VirtualFile file = files[0]; if (file.isDirectory()) { result.setDone(file.getPath() + '/' + new File(DEFAULT_PATH).getName()); } else { result.setDone(file.getPath()); } }); fileAsyncResult.doWhenRejected((Runnable)result::setRejected); return result; }
Example 14
Source File: FileChooser.java From consulo with Apache License 2.0 | 5 votes |
/** * Shows file/folder open dialog, allows user to choose file/folder and then passes result to callback in EDT. * * @param descriptor file chooser descriptor * @param project project * @param parent parent component * @param toSelect file to preselect */ @Nonnull @RequiredUIAccess public static AsyncResult<VirtualFile> chooseFile(@Nonnull final FileChooserDescriptor descriptor, @Nullable Project project, @Nullable Component parent, @Nullable VirtualFile toSelect) { LOG.assertTrue(!descriptor.isChooseMultiple()); AsyncResult<VirtualFile> result = AsyncResult.undefined(); AsyncResult<VirtualFile[]> filesAsync = chooseFiles(descriptor, project, parent, toSelect); filesAsync.doWhenDone((f) -> result.setDone(f[0])); filesAsync.doWhenRejected((Runnable)result::setRejected); return result; }
Example 15
Source File: FileChooser.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @RequiredUIAccess public static AsyncResult<VirtualFile> chooseFile(@Nonnull final FileChooserDescriptor descriptor, @Nullable final Component parent, @Nullable final Project project, @Nullable final VirtualFile toSelect) { LOG.assertTrue(!descriptor.isChooseMultiple()); AsyncResult<VirtualFile> result = AsyncResult.undefined(); AsyncResult<VirtualFile[]> filesAsync = chooseFiles(descriptor, parent, project, toSelect); filesAsync.doWhenDone((files) -> result.setDone(files[0])); filesAsync.doWhenRejected((Runnable)result::setRejected); return result; }
Example 16
Source File: ImportProjectOpenProcessor.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public AsyncResult<Project> doOpenProjectAsync(@Nonnull VirtualFile virtualFile, @Nonnull UIAccess uiAccess) { File ioPath = VfsUtil.virtualToIoFile(virtualFile); List<ModuleImportProvider> targetProviders = ContainerUtil.filter(myProviders, moduleImportProvider -> moduleImportProvider.canImport(ioPath)); if (targetProviders.size() == 0) { throw new IllegalArgumentException("must be not empty"); } String expectedProjectPath = ModuleImportProvider.getDefaultPath(virtualFile); AsyncResult<ThreeState> askDialogResult = AsyncResult.undefined(); if (!uiAccess.isHeadless() && DefaultProjectOpenProcessor.getInstance().canOpenProject(new File(expectedProjectPath))) { Alert<ThreeState> alert = Alert.create(); alert.title(IdeBundle.message("title.open.project")); alert.text(IdeBundle.message("project.import.open.existing", "an existing project", FileUtil.toSystemDependentName(ioPath.getPath()), virtualFile.getName())); alert.asQuestion(); alert.button(IdeBundle.message("project.import.open.existing.openExisting"), ThreeState.YES); alert.asDefaultButton(); alert.button(IdeBundle.message("project.import.open.existing.reimport"), ThreeState.NO); alert.button(Alert.CANCEL, ThreeState.UNSURE); alert.asExitButton(); uiAccess.give(() -> alert.showAsync().notify(askDialogResult)); } else { askDialogResult.setDone(ThreeState.NO); } AsyncResult<Project> projectResult = AsyncResult.undefined(); askDialogResult.doWhenDone(threeState -> { switch (threeState) { case YES: ProjectManager.getInstance().openProjectAsync(virtualFile, uiAccess).notify(projectResult); break; case NO: uiAccess.give(() -> { AsyncResult<Pair<ModuleImportContext, ModuleImportProvider<ModuleImportContext>>> result = AsyncResult.undefined(); ModuleImportProcessor.showImportChooser(null, virtualFile, targetProviders, result); result.doWhenDone(pair -> { ModuleImportContext context = pair.getFirst(); ModuleImportProvider<ModuleImportContext> provider = pair.getSecond(); AsyncResult<Project> importProjectAsync = NewOrImportModuleUtil.importProject(context, provider); importProjectAsync.doWhenDone((newProject) -> { ProjectUtil.updateLastProjectLocation(expectedProjectPath); ProjectManager.getInstance().openProjectAsync(newProject, uiAccess).notify(projectResult); }); importProjectAsync.doWhenRejected((Runnable)projectResult::setRejected); }); result.doWhenRejected((pair, error) -> { pair.getFirst().dispose(); projectResult.setRejected(); }); }); break; case UNSURE: projectResult.setRejected(); break; } }); return projectResult; }
Example 17
Source File: XLineBreakpointManager.java From consulo with Apache License 2.0 | 4 votes |
@Override public void mouseClicked(final EditorMouseEvent e) { final Editor editor = e.getEditor(); final MouseEvent mouseEvent = e.getMouseEvent(); if (mouseEvent.isPopupTrigger() || mouseEvent.isMetaDown() || mouseEvent.isControlDown() || mouseEvent.getButton() != MouseEvent.BUTTON1 || DiffUtil.isDiffEditor(editor) || !isInsideGutter(e, editor) || ConsoleViewUtil.isConsoleViewEditor(editor) || !isFromMyProject(editor) || (editor.getSelectionModel().hasSelection() && myDragDetected)) { return; } PsiDocumentManager.getInstance(myProject).commitAllDocuments(); final int line = EditorUtil.yPositionToLogicalLine(editor, mouseEvent); final Document document = editor.getDocument(); final VirtualFile file = FileDocumentManager.getInstance().getFile(document); if (line >= 0 && line < document.getLineCount() && file != null) { ActionManagerEx.getInstanceEx().fireBeforeActionPerformed(IdeActions.ACTION_TOGGLE_LINE_BREAKPOINT, e.getMouseEvent()); final AsyncResult<XLineBreakpoint> lineBreakpoint = XBreakpointUtil.toggleLineBreakpoint(myProject, XSourcePositionImpl.create(file, line), editor, mouseEvent.isAltDown(), false); lineBreakpoint.doWhenDone(breakpoint -> { if (!mouseEvent.isAltDown() && mouseEvent.isShiftDown() && breakpoint != null) { breakpoint.setSuspendPolicy(SuspendPolicy.NONE); String selection = editor.getSelectionModel().getSelectedText(); if (selection != null) { breakpoint.setLogExpression(selection); } else { breakpoint.setLogMessage(true); } // edit breakpoint DebuggerUIUtil.showXBreakpointEditorBalloon(myProject, mouseEvent.getPoint(), ((EditorEx)editor).getGutterComponentEx(), false, breakpoint); } }); } }