@Override public Promise<String> apply(String arg) throws FunctionException { return macro .expand() .thenPromise( new Function<String, Promise<String>>() { @Override public Promise<String> apply(String arg) throws FunctionException { stringContainer.setCommandLine( stringContainer.getCommandLine().replace(macro.getName(), arg)); return Promises.resolve(stringContainer.getCommandLine()); } }); } };
private Promise<Void> synchronizeChanges(Container container, ResourceDelta... deltas) { Promise<?> promise; if (deltas == null || deltas.length == 0) { promise = container.synchronize(); } else { stream(deltas).filter(this::isProjectCreatedDelta).forEach(this::notifyProjectCreated); promise = container.synchronize(deltas); } return promise.thenPromise(this::resolvePromise); }
private Promise<String> expandMacros( Promise<String> promise, StringContainer stringContainer, Iterator<Macro> iterator) { if (!iterator.hasNext()) { return promise; } Macro macro = iterator.next(); Promise<String> derivedPromise = promise.thenPromise(expandMacro(stringContainer, macro)); return expandMacros(derivedPromise, stringContainer, iterator); }
/** * Check if node has children. This method make a request to server to read children count. * * @param node node * @return true if node has children, otherwise false */ public Promise<Boolean> hasChildren(@NotNull Node node) { return node.getChildren(false).thenPromise(children -> Promises.resolve(!children.isEmpty())); }
Promise<Optional<Container>> getContainer(final Path absolutePath) { return findResource(absolutePath) .thenPromise( optResource -> { if (optResource.isPresent()) { Resource resource = optResource.get(); checkState(resource instanceof Container, "Not a container"); return promises.resolve(of((Container) resource)); } return promises.resolve(absent()); }); }
@Override public Promise<Void> flushPreferences() { if (changedPreferences.isEmpty()) { return Promises.resolve(null); } return updatePreferences(changedPreferences) .thenPromise( result -> { persistedPreferences.putAll(changedPreferences); changedPreferences.clear(); return Promises.resolve(null); }); }
private Promise<Void> doProcessMultipleChanges(List<FileChange> changes) { Promise<Void> multipleChainPromise = ProjectTreeChangeHandler.this.promises.resolve(null); List<FileChange> preProcessedChanges = skipFilesInTheRootDirectory(changes); multipleChainPromise = multipleChainPromise.thenPromise(ignored -> doProcessDeleteChanges(preProcessedChanges)); multipleChainPromise = multipleChainPromise.thenPromise(ignored -> doProcessUpdateChanges(preProcessedChanges)); return multipleChainPromise; }
/** * Search node in the project explorer tree by storable path. * * @param path path to node * @param select select node after reveal * @param isFocusRequired whether tree should take focus after reveal * @return promise object with found node or promise error if node wasn't found */ public Promise<Node> reveal( final Path path, final boolean select, final boolean isFocusRequired) { return queue.thenPromise( ignored -> createFromAsyncRequest(callback -> reveal(path, select, isFocusRequired, callback))); }
@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()))); }
private Promise<Optional<Resource>> findResourceForExternalOperation(final Path absolutePath) { Promise<Void> derived = promises.resolve(null); for (int i = absolutePath.segmentCount() - 1; i > 0; i--) { final Path pathToCache = absolutePath.removeLastSegments(i); derived = derived.thenPromise(arg -> loadAndRegisterResources(pathToCache)); } return derived.thenPromise(ignored -> findResource(absolutePath)); }
protected Promise<ResourceDelta[]> synchronize(final ResourceDelta[] deltas) { Promise<Void> chain = promises.resolve(null); for (final ResourceDelta delta : deltas) { if (delta.getKind() == ADDED) { if (delta.getFlags() == (MOVED_FROM | MOVED_TO)) { chain = chain.thenPromise(ignored -> onExternalDeltaMoved(delta)); } else { chain = chain.thenPromise(ignored -> onExternalDeltaAdded(delta)); } } else if (delta.getKind() == REMOVED) { chain = chain.thenPromise(ignored -> onExternalDeltaRemoved(delta)); } else if (delta.getKind() == UPDATED) { chain = chain.thenPromise(ignored -> onExternalDeltaUpdated(delta)); } } return chain.thenPromise(ignored -> promises.resolve(deltas)); }
private Promise<Void> onExternalDeltaAdded(final ResourceDelta delta) { return findResource(delta.getToPath()) .thenPromise( resource -> { if (resource.isPresent()) { eventBus.fireEvent( new ResourceChangedEvent( new ResourceDeltaImpl(resource.get(), ADDED | DERIVED))); } return promises.resolve(null); }); }
private Promise<Optional<Resource>> findResource(final Path absolutePath) { String[] segments = absolutePath.segments(); Promise<Optional<Resource>> chain = promises.resolve(null); for (int i = 0; i <= segments.length; i++) { Path pathToRetrieve = absolutePath.removeLastSegments(segments.length - i); chain = chain.thenPromise(ignored -> doFindResource(pathToRetrieve)); } return chain; }
private Promise<Void> doProcessUpdateChanges(List<FileChange> changes) { List<FileChange> updateChanges = getUpdateFileChanges(changes); if (updateChanges.isEmpty()) { return ProjectTreeChangeHandler.this.promises.resolve(null); } List<Path> updatePaths = getUpdateFileChangePaths(updateChanges); Path commonUpdatePath = getCommonUpdatePath(updatePaths); Promise<Optional<Container>> containerByPath = getContainerByPath(commonUpdatePath); return containerByPath.thenPromise( container -> { if (container.isPresent()) { return synchronizeChanges(container.get()); } else { return ProjectTreeChangeHandler.this.promises.resolve(null); } }); }
@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); }
private Promise<Project> recallSubversionImportWithCredentials( Path path, SourceStorage sourceStorage) { return askCredentialsDialog .askCredentials() .thenPromise( credentials -> { sourceStorage.getParameters().put("username", credentials.getUsername()); sourceStorage.getParameters().put("password", credentials.getPassword()); return doImport(path, sourceStorage); }) .catchError( caught -> { callback.onFailure(caught.getCause()); }); } }
/** Updates the commands. */ Promise<List<CommandImpl>> fetchCommands() { return workspaceServiceClient .getWorkspace(appContext.getWorkspaceId()) .thenPromise( workspace -> { updateWorkspace().apply(workspace); return promiseProvider.resolve(getCommands()); }); }
/** Removes the command with the specified {@code commandName}. */ Promise<Void> removeCommand(String commandName) { return workspaceServiceClient .deleteCommand(appContext.getWorkspaceId(), commandName) .thenPromise( arg -> workspaceServiceClient .getWorkspace(appContext.getWorkspaceId()) .then(updateWorkspace())); }
private Promise<Void> onExternalDeltaUpdated(final ResourceDelta delta) { if (delta.getToPath().segmentCount() == 0) { workspaceRoot.synchronize(); return promises.resolve(null); } return findResource(delta.getToPath()) .thenPromise( resource -> { if (resource.isPresent()) { eventBus.fireEvent( new ResourceChangedEvent( new ResourceDeltaImpl(resource.get(), UPDATED | DERIVED))); } return promises.resolve(null); }); }
@Inject public TreeResourceRevealer( ProjectExplorerView projectExplorer, EventBus eventBus, PromiseProvider promises) { this.tree = projectExplorer.getTree(); queue = promises.resolve(null); eventBus.addHandler( RevealResourceEvent.getType(), event -> queue.thenPromise( ignored -> reveal( event.getLocation(), event.isSelectionRequired(), event.isFocusRequired()) .catchError((Function<PromiseError, Void>) arg -> null))); }