com.intellij.openapi.util.AsyncResult Java Examples
The following examples show how to use
com.intellij.openapi.util.AsyncResult.
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: WebUIAccessImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull @Override public <T> AsyncResult<T> give(@Nonnull Supplier<T> supplier) { AsyncResult<T> result = AsyncResult.undefined(); if (isValid()) { myUI.access(() -> { try { result.setDone(supplier.get()); } catch (Throwable e) { LOGGER.error(e); result.rejectWithThrowable(e); } }); } else { result.setDone(); } return result; }
Example #2
Source File: ModuleImportProcessor.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess private static AsyncResult<ModuleImportProvider> showImportTarget(@Nonnull List<ModuleImportProvider> providers) { ComboBox<ModuleImportProvider> box = ComboBox.create(providers); box.setRender((render, index, item) -> { assert item != null; render.setIcon(item.getIcon()); render.append(item.getName()); }); box.setValueByIndex(0); LabeledLayout layout = LabeledLayout.create("Select import target", box); DialogBuilder builder = new DialogBuilder(); builder.setTitle("Import Target"); builder.setCenterPanel((JComponent)TargetAWT.to(layout)); AsyncResult<ModuleImportProvider> result = AsyncResult.undefined(); AsyncResult<Void> showResult = builder.showAsync(); showResult.doWhenDone(() -> result.setDone(box.getValue())); showResult.doWhenRejected((Runnable)result::setRejected); return result; }
Example #3
Source File: ProjectUtil.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private static AsyncResult<Integer> confirmOpenNewProjectAsync(UIAccess uiAccess, boolean isNewProject) { final GeneralSettings settings = GeneralSettings.getInstance(); int confirmOpenNewProject = settings.getConfirmOpenNewProject(); if (confirmOpenNewProject == GeneralSettings.OPEN_PROJECT_ASK) { Alert<Integer> alert = Alert.create(); alert.asQuestion(); alert.remember(ProjectNewWindowDoNotAskOption.INSTANCE); alert.title(isNewProject ? IdeBundle.message("title.new.project") : IdeBundle.message("title.open.project")); alert.text(IdeBundle.message("prompt.open.project.in.new.frame")); alert.button(IdeBundle.message("button.existingframe"), () -> GeneralSettings.OPEN_PROJECT_SAME_WINDOW); alert.asDefaultButton(); alert.button(IdeBundle.message("button.newframe"), () -> GeneralSettings.OPEN_PROJECT_NEW_WINDOW); alert.button(Alert.CANCEL, Alert.CANCEL); alert.asExitButton(); AsyncResult<Integer> result = AsyncResult.undefined(); uiAccess.give(() -> alert.showAsync().notify(result)); return result; } return AsyncResult.resolved(confirmOpenNewProject); }
Example #4
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 #5
Source File: EditInspectionToolsSettingsAction.java From consulo with Apache License 2.0 | 6 votes |
public static AsyncResult<Void> editToolSettings(final Project project, final InspectionProfile inspectionProfile, final boolean canChooseDifferentProfile, final String selectedToolShortName) { final ShowSettingsUtil settingsUtil = ShowSettingsUtil.getInstance(); final ErrorsConfigurable errorsConfigurable; if (!canChooseDifferentProfile) { errorsConfigurable = new IDEInspectionToolsConfigurable(InspectionProjectProfileManager.getInstance(project), InspectionProfileManager.getInstance()); } else { errorsConfigurable = ErrorsConfigurable.SERVICE.createConfigurable(project); } return settingsUtil.editConfigurable(project, errorsConfigurable, new Runnable() { @Override public void run() { errorsConfigurable.selectProfile(inspectionProfile); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { errorsConfigurable.selectInspectionTool(selectedToolShortName); } }); } }); }
Example #6
Source File: StorageUtil.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public static AsyncResult<VirtualFile> writeFileAsync(@Nullable File file, @Nonnull Object requestor, @Nullable final VirtualFile fileRef, @Nonnull byte[] content, @Nullable LineSeparator lineSeparatorIfPrependXmlProlog) { return AccessRule.writeAsync(() -> { VirtualFile virtualFile = fileRef; if (file != null && (virtualFile == null || !virtualFile.isValid())) { virtualFile = getOrCreateVirtualFile(requestor, file); } assert virtualFile != null; try (OutputStream out = virtualFile.getOutputStream(requestor)) { if (lineSeparatorIfPrependXmlProlog != null) { out.write(XML_PROLOG); out.write(lineSeparatorIfPrependXmlProlog.getSeparatorBytes()); } out.write(content); } return virtualFile; }); }
Example #7
Source File: AbstractProjectViewPSIPane.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull public AsyncResult<Void> selectCB(Object element, VirtualFile file, boolean requestFocus) { if (file != null) { AbstractTreeBuilder builder = getTreeBuilder(); if (builder instanceof BaseProjectTreeBuilder) { beforeSelect().doWhenDone(() -> UIUtil.invokeLaterIfNeeded(() -> { if (!builder.isDisposed()) { ((BaseProjectTreeBuilder)builder).selectAsync(element, file, requestFocus); } })); } else if (myAsyncSupport != null) { myAsyncSupport.select(myTree, element, file); } } return AsyncResult.resolved(); }
Example #8
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 #9
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 #10
Source File: WinPathChooserDialog.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @RequiredUIAccess @Override public AsyncResult<VirtualFile[]> chooseAsync(@Nullable Project project, @Nonnull VirtualFile[] toSelectFiles) { VirtualFile toSelect = toSelectFiles.length > 0 ? toSelectFiles[0] : null; return chooseAsync(toSelect); }
Example #11
Source File: ProjectStructureConfigurable.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public AsyncResult<Void> select(@Nullable final String moduleToSelect, @Nullable String editorNameToSelect, final boolean requestFocus) { Place place = createModulesPlace(); if (moduleToSelect != null) { final Module module = ModuleManager.getInstance(myProject).findModuleByName(moduleToSelect); assert module != null; place = place.putPath(ModuleStructureConfigurable.TREE_OBJECT, module).putPath(ModuleEditor.SELECTED_EDITOR_NAME, editorNameToSelect); } return navigateTo(place, requestFocus); }
Example #12
Source File: ContentEntryEditor.java From consulo with Apache License 2.0 | 5 votes |
@Override public void showChangeOptionsDialog(ContentEntry contentEntry, ContentFolder contentFolder) { ContentFolderPropertiesDialog c = new ContentFolderPropertiesDialog(getModel().getProject(), contentFolder); AsyncResult<Boolean> booleanAsyncResult = c.showAndGetOk(); if(booleanAsyncResult.getResult() == Boolean.TRUE) { update(); } }
Example #13
Source File: DesktopCommandProcessorImpl.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override protected AsyncResult<Void> invokeLater(@Nonnull Runnable command, @Nonnull Condition<?> expire) { DesktopApplicationImpl application = (DesktopApplicationImpl)Application.get(); ModalityState modalityState = ModalityPerProjectEAPDescriptor.is() ? ModalityState.current() : ModalityState.NON_MODAL; return application.getInvokator().invokeLater(command, modalityState, expire); }
Example #14
Source File: UnityRefreshBeforeRunTaskProvider.java From consulo-unity3d with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Nonnull @Override public AsyncResult<Void> configureTask(RunConfiguration runConfiguration, UnityRefreshBeforeRunTask task) { return AsyncResult.rejected(); }
Example #15
Source File: UIAccess.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull default AsyncResult<Void> give(@RequiredUIAccess @Nonnull Runnable runnable) { return give(() -> { runnable.run(); return null; }); }
Example #16
Source File: NewOrImportModuleUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @RequiredUIAccess public static <T extends ModuleImportContext> AsyncResult<Project> importProject(@Nonnull T context, @Nonnull ModuleImportProvider<T> importProvider) { final ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx(); final String projectFilePath = context.getPath(); String projectName = context.getName(); try { File projectDir = new File(projectFilePath); FileUtil.ensureExists(projectDir); File projectConfigDir = new File(projectDir, Project.DIRECTORY_STORE_FOLDER); FileUtil.ensureExists(projectConfigDir); final Project newProject = projectManager.createProject(projectName, projectFilePath); if (newProject == null) return AsyncResult.rejected(); newProject.save(); ModifiableModuleModel modifiableModel = ModuleManager.getInstance(newProject).getModifiableModel(); importProvider.process(context, newProject, modifiableModel, module -> { }); WriteAction.runAndWait(modifiableModel::commit); newProject.save(); context.dispose(); return AsyncResult.resolved(newProject); } catch (Exception e) { context.dispose(); return AsyncResult.<Project>undefined().rejectWithThrowable(e); } }
Example #17
Source File: ProjectStructureConfigurable.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override public AsyncResult<Void> select(@Nonnull LibraryOrderEntry libraryOrderEntry, final boolean requestFocus) { final Library lib = libraryOrderEntry.getLibrary(); if (lib == null || lib.getTable() == null) { return selectOrderEntry(libraryOrderEntry.getOwnerModule(), libraryOrderEntry); } Place place = createPlaceFor(getConfigurableFor(lib)); place.putPath(BaseStructureConfigurable.TREE_NAME, libraryOrderEntry.getLibraryName()); return navigateTo(place, requestFocus); }
Example #18
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 #19
Source File: Place.java From consulo with Apache License 2.0 | 4 votes |
public static AsyncResult<Void> goFurther(Object object, Place place, final boolean requestFocus) { if (object instanceof Navigator) { return ((Navigator)object).navigateTo(place, requestFocus); } return AsyncResult.resolved(); }
Example #20
Source File: WebProjectIdeFocusManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public AsyncResult<Void> requestDefaultFocus(boolean forced) { return AsyncResult.resolved(null); }
Example #21
Source File: CallChain.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public <SubNewValue> Link<NewValue, SubNewValue> linkAsync(@Nonnull Supplier<AsyncResult<SubNewValue>> function) { return linkAsync(newValue -> function.get()); }
Example #22
Source File: ProjectManager.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public abstract AsyncResult<Void> closeAndDisposeAsync(@Nonnull Project project, @Nonnull UIAccess uiAccess, boolean checkCanClose, boolean save, boolean dispose);
Example #23
Source File: AutoScrollToSourceHandler.java From consulo with Apache License 2.0 | 4 votes |
private AsyncResult<Void> getReady(DataContext context) { ToolWindow toolWindow = context.getData(PlatformDataKeys.TOOL_WINDOW); return toolWindow != null ? toolWindow.getReady(this) : AsyncResult.done(null); }
Example #24
Source File: PathChooserDialog.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @RequiredUIAccess default AsyncResult<VirtualFile[]> chooseAsync(@Nullable VirtualFile toSelect) { throw new AbstractMethodError(); }
Example #25
Source File: WebProjectIdeFocusManagerImpl.java From consulo with Apache License 2.0 | 4 votes |
@Override @Nonnull public AsyncResult<Void> requestFocus(@Nonnull final Component c, final boolean forced) { return IdeFocusManager.getGlobalInstance().requestFocus(c, forced); }
Example #26
Source File: CallChain.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public static Link<Void, Void> first(@Nullable UIAccess uiAccess) { CallChain callChain = new CallChain(uiAccess); return new Link<>(callChain, (f) -> AsyncResult.resolved()); }
Example #27
Source File: NettyKt.java From consulo with Apache License 2.0 | 4 votes |
private static Channel doConnect(Bootstrap bootstrap, InetSocketAddress remoteAddress, AsyncResult<?> asyncResult, int maxAttemptCount, @Nullable Condition<Void> stopCondition) throws Throwable { int attemptCount = 0; if (bootstrap.config().group() instanceof NioEventLoopGroup) { return connectNio(bootstrap, remoteAddress, asyncResult, maxAttemptCount, stopCondition, attemptCount); } bootstrap.validate(); while (true) { try { OioSocketChannel channel = new OioSocketChannel(new Socket(remoteAddress.getAddress(), remoteAddress.getPort())); bootstrap.register().sync(); return channel; } catch (IOException e) { if (stopCondition != null && stopCondition.value(null) || asyncResult != null && !asyncResult.isProcessed()) { return null; } else if (maxAttemptCount == -1) { if (sleep(asyncResult, 300)) { return null; } attemptCount++; } else if (++attemptCount < maxAttemptCount) { if (sleep(asyncResult, attemptCount * NettyUtil.MIN_START_TIME)) { return null; } } else { if (asyncResult != null) { asyncResult.rejectWithThrowable(e); } return null; } } } }
Example #28
Source File: UnifiedContentManager.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public AsyncResult<Void> requestFocus(@Nullable Content content, boolean forced) { return AsyncResult.resolved(); //TODO [VISTALL] }
Example #29
Source File: BeforeRunTaskProvider.java From consulo with Apache License 2.0 | 4 votes |
/** * @return <code>true</code> if task configuration is changed */ @Nonnull @RequiredUIAccess public abstract AsyncResult<Void> configureTask(final RunConfiguration runConfiguration, T task);
Example #30
Source File: ShowSettingsUtil.java From consulo with Apache License 2.0 | 4 votes |
@RequiredUIAccess public AsyncResult<Void> editConfigurable(Project project, Configurable configurable, Runnable advancedInitialization) { return editConfigurable(null, project, configurable, advancedInitialization); }