Java Code Examples for com.intellij.openapi.util.AsyncResult#rejected()
The following examples show how to use
com.intellij.openapi.util.AsyncResult#rejected() .
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: 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 2
Source File: ProjectStructureConfigurable.java From consulo with Apache License 2.0 | 5 votes |
@Override public AsyncResult<Void> navigateTo(@Nullable final Place place, final boolean requestFocus) { if(myProjectStructureDialog == null) { return AsyncResult.rejected(); } final Configurable toSelect = (Configurable)place.getPath(CATEGORY); if (mySelectedConfigurable != toSelect) { if (mySelectedConfigurable instanceof BaseStructureConfigurable) { ((BaseStructureConfigurable)mySelectedConfigurable).onStructureUnselected(); } removeSelected(); if (toSelect != null) { myProjectStructureDialog.accept(toSelect); } setSelectedConfigurable(toSelect); if (toSelect instanceof MasterDetailsComponent) { final MasterDetailsComponent masterDetails = (MasterDetailsComponent)toSelect; masterDetails.setHistory(myHistory); } if (toSelect instanceof BaseStructureConfigurable) { ((BaseStructureConfigurable)toSelect).onStructureSelected(); } } final AsyncResult<Void> result = AsyncResult.undefined(); Place.goFurther(toSelect, place, requestFocus).notifyWhenDone(result); if (!myHistory.isNavigatingNow() && mySelectedConfigurable != null) { myHistory.pushQueryPlace(); } return result; }
Example 3
Source File: AbstractToolBeforeRunTaskProvider.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull @Override @SuppressWarnings("unchecked") public AsyncResult<Void> executeTaskAsync(UIAccess uiAccess, DataContext context, RunConfiguration configuration, ExecutionEnvironment env, T task) { if (!task.isExecutable()) { return AsyncResult.rejected(); } return task.execute(uiAccess, context, env.getExecutionId()); }
Example 4
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 5
Source File: CommandLineProcessor.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public static AsyncResult<Project> processExternalCommandLine(@Nonnull CommandLineArgs commandLineArgs, @Nullable String currentDirectory) { String file = commandLineArgs.getFile(); if (file == null) { return AsyncResult.rejected(); } int line = commandLineArgs.getLine(); if (StringUtil.isQuotedString(file)) { file = StringUtil.stripQuotesAroundValue(file); } if (!new File(file).isAbsolute()) { file = currentDirectory != null ? new File(currentDirectory, file).getAbsolutePath() : new File(file).getAbsolutePath(); } File projectFile = findProjectDirectoryOrFile(file); File targetFile = new File(file); UIAccess uiAccess = Application.get().getLastUIAccess(); if (projectFile != null) { return ProjectUtil.openAsync(projectFile.getPath(), null, true, uiAccess).doWhenDone(project -> { if (!FileUtil.filesEqual(projectFile, targetFile) && !targetFile.isDirectory()) { final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetFile); if (virtualFile != null) { openFile(uiAccess, project, virtualFile, line); } } }); } else { final VirtualFile targetVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetFile); if (targetVFile == null) { Messages.showErrorDialog("Cannot find file '" + file + "'", "Cannot find file"); return AsyncResult.rejected(); } Project bestProject = findBestProject(targetVFile); openFile(uiAccess, bestProject, targetVFile, line); return AsyncResult.resolved(bestProject); } }
Example 6
Source File: ProjectUtil.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public static AsyncResult<Project> openAsync(@Nonnull String path, @Nullable final Project projectToCloseFinal, boolean forceOpenInNewFrame, @Nonnull UIAccess uiAccess) { final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(path); if (virtualFile == null) return AsyncResult.rejected("file path not find"); return PooledAsyncResult.create((result) -> { ProjectOpenProcessor provider = ProjectOpenProcessors.getInstance().findProcessor(VfsUtilCore.virtualToIoFile(virtualFile)); if (provider != null) { result.doWhenDone((project) -> { uiAccess.give(() -> { if (project.isDisposed()) return; final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.PROJECT_VIEW); if (toolWindow != null && toolWindow.getType() != ToolWindowType.SLIDING) { toolWindow.activate(null); } }); }); result.doWhenRejected(() -> WelcomeFrameManager.getInstance().showIfNoProjectOpened()); AsyncResult<Void> reopenAsync = AsyncResult.undefined(); Project projectToClose = projectToCloseFinal; Project[] openProjects = ProjectManager.getInstance().getOpenProjects(); if (!forceOpenInNewFrame && openProjects.length > 0) { if (projectToClose == null) { projectToClose = openProjects[openProjects.length - 1]; } final Project finalProjectToClose = projectToClose; confirmOpenNewProjectAsync(uiAccess, false).doWhenDone(exitCode -> { if (exitCode == GeneralSettings.OPEN_PROJECT_SAME_WINDOW) { AsyncResult<Void> closeResult = ProjectManagerEx.getInstanceEx().closeAndDisposeAsync(finalProjectToClose, uiAccess); closeResult.doWhenDone((Runnable)reopenAsync::setDone); closeResult.doWhenRejected(() -> result.reject("not closed project")); } else if (exitCode != GeneralSettings.OPEN_PROJECT_NEW_WINDOW) { // not in a new window result.reject("not open in new window"); } else { reopenAsync.setDone(); } }); } else { reopenAsync.setDone(); } // we need reexecute it due after dialog - it will be executed in ui thread reopenAsync.doWhenDone(() -> PooledAsyncResult.create(() -> provider.doOpenProjectAsync(virtualFile, uiAccess)).notify(result)); } else { result.reject("provider for file path is not find"); } }); }
Example 7
Source File: BeforeRunTaskProvider.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @SuppressWarnings("deprecation") public AsyncResult<Void> executeTaskAsync(UIAccess uiAccess, DataContext context, RunConfiguration configuration, ExecutionEnvironment env, T task) { return executeTask(context, configuration, env, task) ? AsyncResult.resolved() : AsyncResult.rejected(); }
Example 8
Source File: XBreakpointUtil.java From consulo with Apache License 2.0 | 4 votes |
/** * Toggle line breakpoint with editor support: * - unfolds folded block on the line * - if folded, checks if line breakpoints could be toggled inside folded text */ @Nonnull public static AsyncResult<XLineBreakpoint> toggleLineBreakpoint(@Nonnull Project project, @Nonnull XSourcePosition position, @Nullable Editor editor, boolean temporary, boolean moveCaret) { int lineStart = position.getLine(); VirtualFile file = position.getFile(); // for folded text check each line and find out type with the biggest priority int linesEnd = lineStart; if (editor != null) { FoldRegion region = FoldingUtil.findFoldRegionStartingAtLine(editor, lineStart); if (region != null && !region.isExpanded()) { linesEnd = region.getDocument().getLineNumber(region.getEndOffset()); } } final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager(); XLineBreakpointType<?>[] lineTypes = XDebuggerUtil.getInstance().getLineBreakpointTypes(); XLineBreakpointType<?> typeWinner = null; int lineWinner = -1; for (int line = lineStart; line <= linesEnd; line++) { for (XLineBreakpointType<?> type : lineTypes) { final XLineBreakpoint<? extends XBreakpointProperties> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line); if (breakpoint != null && temporary && !breakpoint.isTemporary()) { breakpoint.setTemporary(true); } else if(breakpoint != null) { typeWinner = type; lineWinner = line; break; } } XLineBreakpointType<?> breakpointType = XLineBreakpointResolverTypeExtension.INSTANCE.resolveBreakpointType(project, file, line); if(breakpointType != null) { typeWinner = breakpointType; lineWinner = line; } // already found max priority type - stop if (typeWinner != null) { break; } } if (typeWinner != null) { XSourcePosition winPosition = (lineStart == lineWinner) ? position : XSourcePositionImpl.create(file, lineWinner); if (winPosition != null) { AsyncResult<XLineBreakpoint> res = XDebuggerUtilImpl.toggleAndReturnLineBreakpoint(project, typeWinner, winPosition, temporary, editor); if (editor != null && lineStart != lineWinner) { int offset = editor.getDocument().getLineStartOffset(lineWinner); ExpandRegionAction.expandRegionAtOffset(project, editor, offset); if (moveCaret) { editor.getCaretModel().moveToOffset(offset); } } return res; } } return AsyncResult.rejected(); }
Example 9
Source File: RunConfigurationBeforeRunProvider.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @Override public AsyncResult<Void> executeTaskAsync(UIAccess uiAccess, DataContext context, RunConfiguration configuration, ExecutionEnvironment env, RunConfigurableBeforeRunTask task) { RunnerAndConfigurationSettings settings = task.getSettings(); if (settings == null) { return AsyncResult.rejected(); } final Executor executor = DefaultRunExecutor.getRunExecutorInstance(); String executorId = executor.getId(); final ProgramRunner runner = ProgramRunnerUtil.getRunner(executorId, settings); if (runner == null) return AsyncResult.rejected(); final ExecutionEnvironment environment = new ExecutionEnvironment(executor, runner, settings, myProject); environment.setExecutionId(env.getExecutionId()); if (!ExecutionTargetManager.canRun(settings, env.getExecutionTarget())) { return AsyncResult.rejected(); } if (!runner.canRun(executorId, environment.getRunProfile())) { return AsyncResult.rejected(); } else { AsyncResult<Void> result = AsyncResult.undefined(); uiAccess.give(() -> { try { runner.execute(environment, descriptor -> { ProcessHandler processHandler = descriptor != null ? descriptor.getProcessHandler() : null; if (processHandler != null) { processHandler.addProcessListener(new ProcessAdapter() { @Override public void processTerminated(ProcessEvent event) { if(event.getExitCode() == 0) { result.setDone(); } else { result.setRejected(); } } }); } }); } catch (ExecutionException e) { result.setRejected(); LOG.error(e); } }).doWhenRejectedWithThrowable(result::rejectWithThrowable); return result; } }
Example 10
Source File: UnknownBeforeRunTaskProvider.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @RequiredUIAccess @Override public AsyncResult<Void> configureTask(RunConfiguration runConfiguration, UnknownTask task) { return AsyncResult.rejected(); }
Example 11
Source File: CompileStepBeforeRun.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @RequiredUIAccess @Override public AsyncResult<Void> configureTask(RunConfiguration runConfiguration, MakeBeforeRunTask task) { return AsyncResult.rejected(); }
Example 12
Source File: CompileStepBeforeRun.java From consulo with Apache License 2.0 | 4 votes |
static AsyncResult<Void> doMake(UIAccess uiAccess, final Project myProject, final RunConfiguration configuration, final boolean ignoreErrors) { if (!(configuration instanceof RunProfileWithCompileBeforeLaunchOption)) { return AsyncResult.rejected(); } if (configuration instanceof RunConfigurationBase && ((RunConfigurationBase)configuration).excludeCompileBeforeLaunchOption()) { return AsyncResult.resolved(); } final RunProfileWithCompileBeforeLaunchOption runConfiguration = (RunProfileWithCompileBeforeLaunchOption)configuration; AsyncResult<Void> result = AsyncResult.undefined(); try { final CompileStatusNotification callback = (aborted, errors, warnings, compileContext) -> { if ((errors == 0 || ignoreErrors) && !aborted) { result.setDone(); } else { result.setRejected(); } }; TransactionGuard.submitTransaction(myProject, () -> { CompileScope scope; final CompilerManager compilerManager = CompilerManager.getInstance(myProject); if (Comparing.equal(Boolean.TRUE.toString(), System.getProperty(MAKE_PROJECT_ON_RUN_KEY))) { // user explicitly requested whole-project make scope = compilerManager.createProjectCompileScope(); } else { final Module[] modules = runConfiguration.getModules(); if (modules.length > 0) { for (Module module : modules) { if (module == null) { LOG.error("RunConfiguration should not return null modules. Configuration=" + runConfiguration.getName() + "; class=" + runConfiguration.getClass().getName()); } } scope = compilerManager.createModulesCompileScope(modules, true); } else { scope = compilerManager.createProjectCompileScope(); } } if (!myProject.isDisposed()) { compilerManager.make(scope, callback); } else { result.setRejected(); } }); } catch (Exception e) { result.rejectWithThrowable(e); } return result; }
Example 13
Source File: CompileStepBeforeRunNoErrorCheck.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull @RequiredUIAccess @Override public AsyncResult<Void> configureTask(RunConfiguration runConfiguration, MakeBeforeRunTaskNoErrorCheck task) { return AsyncResult.rejected(); }