/** * Pops up a command type chooser dialog at the position relative to the browser's client area. * * @param left the left position, in pixels * @param top the top position, in pixels * @return promise that will be resolved with a chosen {@link CommandType} or rejected in case * command type selection has been cancelled */ public Promise<CommandType> show(int left, int top) { final List<CommandType> commandTypes = new ArrayList<>(commandTypeRegistry.getCommandTypes()); if (commandTypes.size() == 1) { return promiseProvider.resolve(commandTypes.get(0)); } commandTypes.sort(comparing(CommandType::getDisplayName)); view.setCommandTypes(commandTypes); view.show(left, top); return promiseProvider.create( Executor.create( (ExecutorBody<CommandType>) (resolve, reject) -> { resolveFunction = resolve; rejectFunction = reject; })); }
@Override public Promise<List<? extends Breakpoint>> getAllBreakpoints() { if (!isConnected()) { promiseProvider.reject("Debugger is not connected"); } return service .getAllBreakpoints(debugSessionDto.getId()) .thenPromise( breakpoints -> promiseProvider.resolve( breakpoints.stream().map(BreakpointImpl::new).collect(Collectors.toList()))); }
@Override protected Promise<List<Node>> getChildrenImpl() { return promiseProvider.resolve(children); }
/** * Returns list of the classpath entries. If the classpath already exist for this project - * returns its otherwise gets classpath from the server. * * @param projectPath path to the project * @return list of the classpath entries */ public Promise<List<ClasspathEntry>> getClasspathEntries(String projectPath) { if (classpath.containsKey(projectPath)) { return classpath.get(projectPath); } else { Promise<List<ClasspathEntry>> result = extensionService .classpathTree(projectPath) .catchErrorPromise( error -> { classpath.remove(projectPath); return promiseProvider.reject(error); }); classpath.put(projectPath, result); return result; } }
private Promise<Boolean> toPromise(JsonRpcPromise<Boolean> jsonRpcPromise) { return promises.create( (AsyncCallback<Boolean> callback) -> { jsonRpcPromise.onSuccess(callback::onSuccess); jsonRpcPromise.onFailure( jsonRpcError -> callback.onFailure(new Throwable(jsonRpcError.getMessage()))); }); }
@Override public Promise<Void> loadState(JsonObject state) { if (state.hasKey(PERSPECTIVES)) { JsonObject perspectives = state.getObject(PERSPECTIVES); Map<String, Perspective> perspectiveMap = perspectiveManagerProvider.get().getPerspectives(); ArrayOf<Promise<?>> perspectivePromises = Collections.arrayOf(); for (String key : perspectives.keys()) { if (perspectiveMap.containsKey(key)) { perspectivePromises.push(perspectiveMap.get(key).loadState(perspectives.getObject(key))); } } return promises.all2(perspectivePromises).thenPromise(ignored -> promises.resolve(null)); } return promises.resolve(null); }
/** Removes the command without notifying listeners. */ private Promise<Void> doRemoveCommand(String name) { final CommandImpl command = commands.get(name); if (command == null) { return promiseProvider.reject(new Exception("Command '" + name + "' does not exist.")); } final ApplicableContext context = command.getApplicableContext(); final ArrayOf<Promise<?>> commandPromises = Collections.arrayOf(); if (context.isWorkspaceApplicable()) { commandPromises.push(workspaceCommandManager.removeCommand(name)); } for (final String projectPath : context.getApplicableProjects()) { final Project project = getProjectByPath(projectPath); if (project == null) { continue; } commandPromises.push(projectCommandManager.removeCommand(project, name)); } return promiseProvider .all2(commandPromises) .then( (Function<ArrayOf<?>, Void>) arg -> { commands.remove(command.getName()); return null; }); }
.all(deleteAll) .then( new Operation<JsArrayMixed>() {
.all2(imports.toArray(new Promise<?>[imports.size()])) .then( ignored -> {
@Override protected Promise<List<Node>> getChildrenImpl() { return promiseProvider.resolve(packages); } }
/** Removes the command with the specified {@code commandName}. */ Promise<Void> removeCommand(Project project, String commandName) { final List<CommandImpl> commands = getCommands(project); if (commands.isEmpty()) { return promiseProvider.reject( new Exception( "Command '" + commandName + "' is not associated with the project '" + project.getName() + "'")); } final List<CommandImpl> commandsToUpdate = new ArrayList<>(); for (CommandImpl projectCommand : commands) { if (!commandName.equals(projectCommand.getName())) { commandsToUpdate.add(projectCommand); } } return updateProject(project, new ArrayList<>(commandsToUpdate)); } }
@Override protected Promise<List<Node>> getChildrenImpl() { if (!element.getMatches().isEmpty()) { return presenter .computeMatches(this) .then( (List<MatchNode> matches) -> { List<Node> result = new ArrayList<>(matches); result.addAll(computeChildren()); return result; }); } else { return promiseProvider.create( Executor.create( (resolve, reject) -> { resolve.apply(computeChildren()); })); } }
List<Promise<Void>> restore = restore(files, editorPartStackConsumer, activeEditors); Promise<ArrayOf<?>> promise = promiseProvider.all2(restore.toArray(new Promise[restore.size()])); promise.then( (Operation) }); return promise.thenPromise(ignored -> promiseProvider.resolve(null)); return promiseProvider.resolve(null);
final ApplicableContext context = command.getApplicableContext(); if (!context.isWorkspaceApplicable() && context.getApplicableProjects().isEmpty()) { return promiseProvider.reject( new Exception("Command has to be applicable to the workspace or at least one project")); .all2(commandPromises) .then( (Function<ArrayOf<?>, CommandImpl>)
private Promise<Void> resolvePromise(Object ignored) { return ProjectTreeChangeHandler.this.promises.resolve(null); }
Promise<Optional<VirtualFile>> getResource(String path) { if (path.startsWith("commands/")) { final String commandName = path.substring(path.lastIndexOf('/') + 1); final Optional<CommandImpl> command = commandManager.getCommand(commandName); if (command.isPresent()) { CommandFileNode node = nodeFactory.newCommandFileNode(command.get()); return promiseProvider.resolve(Optional.of(node)); } else { return promiseProvider.reject(new Exception("Command " + commandName + " not found")); } } else { return appContext .getWorkspaceRoot() .getFile(path) .then( (Function<com.google.common.base.Optional<File>, Optional<VirtualFile>>) arg -> ofNullable(arg.orNull())); } } }
@Override public Promise<List<ThreadStateDto>> getThreadDump() { if (!isConnected()) { promiseProvider.reject("Debugger is not connected"); } return service.getThreadDump(debugSessionDto.getId()); }
/** * Pops up a dialog for choosing a machine. * * <p><b>Note:</b> if there is only one machine running in the workspace then returned promise * will be resolved with that machine without asking user. * * @return promise that will be resolved with a chosen {@link MachineImpl} or rejected in case * machine selection has been cancelled. */ public Promise<MachineImpl> show() { final WorkspaceImpl workspace = appContext.getWorkspace(); final RuntimeImpl runtime = workspace.getRuntime(); if (runtime != null) { final List<? extends MachineImpl> machines = new ArrayList<>(runtime.getMachines().values()); if (machines.size() == 1) { return promiseProvider.resolve(machines.get(0)); } view.setMachines(machines); } view.show(); return promiseProvider.create( Executor.create( (ExecutorBody<MachineImpl>) (resolve, reject) -> { resolveFunction = resolve; rejectFunction = reject; })); }