@Override public void apply(final FactoryDto factory) throws OperationException { factoryService .findFactory( null, null, Collections.singletonList(Pair.of("name", factoryName))) .then(saveFactory(factory, factoryName)) .catchError(logError()); } })
private Operation<Project> addCommands(CompleteCallback callback) { return project -> { Promise<CommandImpl> chain = null; for (final CommandDto command : dataObject.getCommands()) { if (chain == null) { chain = addCommand(project, command); } else { chain = chain.thenPromise(ignored -> addCommand(project, command)); } } if (chain == null) { callback.onCompleted(); } else { chain .then( ignored -> { callback.onCompleted(); }) .catchError(onFailure(callback)); } }; }
@Override public void onExecute() { if (ProjectTreeChangeHandler.this.workingQueue.isEmpty()) { return; } List<FileChange> localCopy = new ArrayList<>(ProjectTreeChangeHandler.this.workingQueue.size()); localCopy.addAll(ProjectTreeChangeHandler.this.workingQueue); ProjectTreeChangeHandler.this.workingQueue.clear(); chainPromise = chainPromise .thenPromise( ignored -> { if (localCopy.size() == 1) { return doProcessSingleChange(localCopy.get(0)); } else { return doProcessMultipleChanges(localCopy); } }) .catchErrorPromise(this::onCatchErrorPromise); }
private Promise<Project> recallSubversionImportWithCredentials( final Path path, final SourceStorage sourceStorage) { return askCredentialsDialog .askCredentials() .thenPromise( new Function<Credentials, Promise<Project>>() { @Override public Promise<Project> apply(Credentials credentials) throws FunctionException { sourceStorage.getParameters().put("username", credentials.getUsername()); sourceStorage.getParameters().put("password", credentials.getPassword()); return doImport(path, sourceStorage); } }) .catchError( error -> { callback.onFailure(error.getCause()); }); }
@Override public Promise<Map<String, String>> loadPreferences() { return getPreferences() .then( (Function<Map<String, String>, Map<String, String>>) preferences -> { persistedPreferences.clear(); persistedPreferences.putAll(preferences); return preferences; }); }
@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()); } }); } };
@Override public void apply(String arg) throws OperationException { Map<String, String> connectionProperties = prepareConnectionProperties(debugConfiguration, arg); debugger .connect(connectionProperties) .catchError( new Operation<PromiseError>() { @Override public void apply(PromiseError arg) throws OperationException { debuggerManager.setActiveDebugger(null); } }); } });
/** 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 void updateErrorWarningsPanel() { preferencesManager .loadPreferences() .then( properties -> { options.forEach(this::provideWidget); }); }
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()); }); } }
/** {@inheritDoc} */ @Override public Promise<Resource[]> getChildren(final boolean forceUpdate) { return resourceManager .childrenOf(this, forceUpdate) .thenPromise( new Function<Resource[], Promise<Resource[]>>() { /** {@inheritDoc} */ @Override public Promise<Resource[]> apply(Resource[] children) throws FunctionException { if (children.length == 0 && !forceUpdate) { return getChildren(true); } return promiseProvider.resolve(children); } }); }
@Override public void actionPerformed(ActionEvent e) { final Resource[] resources = appContext.getResources(); Set<String> pathsToRemove = stream(resources).map(resource -> resource.getLocation().toString()).collect(toSet()); fileWatcherExcludesOperation .removeFromFileWatcherExcludes(pathsToRemove) .catchError( error -> { notificationManager.notify(error.getMessage(), FAIL, EMERGE_MODE); }); }
@Override public Promise<CommandImpl> updateCommand(String name, CommandImpl commandToUpdate) { final CommandImpl existedCommand = commands.get(name); if (existedCommand == null) { return promiseProvider.reject(new Exception("Command '" + name + "' does not exist.")); } return doRemoveCommand(name) .thenPromise( aVoid -> doCreateCommand(commandToUpdate) .then( (Function<CommandImpl, CommandImpl>) updatedCommand -> { // listeners should be notified after returning from #updateCommand // method // so let's postpone notification Scheduler.get() .scheduleDeferred( () -> notifyCommandUpdated(existedCommand, updatedCommand)); return updatedCommand; })); }
/** * Tries to set-up Super DevMode for the current IDE GWT app and shows an appropriate message to * the user. */ private void setUpSuperDevModeWithUI(String codeServerURL) { setUpSuperDevMode(codeServerURL) .then(showSuccessMessage(codeServerURL)) .catchError(handleStartRecompilationError(codeServerURL)); }
/** * Creates edits that describe how to format the given string. Returns the changes required to * format source. Note: Java code formatting is supported only. * * @param projectPath path to the parent project * @param offset The given offset to start recording the edits (inclusive). * @param length the given length to stop recording the edits (exclusive). * @param content the content to format */ public Promise<List<Change>> format( String projectPath, final int offset, final int length, final String content) { return getFormatChanges(projectPath, offset, length, content) .then((Function<List<Change>, List<Change>>) ArrayList::new); }
@Override public Promise<Void> init() { return userInitializer .init() .catchError( (Operation<PromiseError>) err -> { // Fail to initialize the current user. // Since we can't get theme ID from the user's preferences // try to inject CSS styles with a default theme at least // in order to be able to use a minimal UI (dialogs) // for displaying an error information to the user. styleInjector.inject(); // Prevent further initialization steps. throw new OperationException(err.getMessage(), err.getCause()); }) .then(initUI()) .thenPromise(aVoid -> initAppContext()) .then(showUI()) .then( arg -> { eventBus.fireEvent(new BasicIDEInitializedEvent()); }); }
@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))); }
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); }
@Override public void actionPerformed(ActionEvent e) { final Resource[] resources = appContext.getResources(); Set<String> pathsToExclude = stream(resources).map(resource -> resource.getLocation().toString()).collect(toSet()); fileWatcherExcludesOperation .addToFileWatcherExcludes(pathsToExclude) .catchError( error -> { notificationManager.notify(error.getMessage(), FAIL, EMERGE_MODE); }); }
Promise<Void> init() { final CurrentUserImpl user = new CurrentUserImpl(); return loadProfile() .thenPromise( profile -> { user.setId(profile.getUserId()); return loadPreferences() .then( preferences -> { updateGitCommitterPreferencesIfEmpty(preferences, profile); }); }) .then( (Function<Map<String, String>, Void>) preferences -> { user.setPreferences(preferences); ((AppContextImpl) appContext).setCurrentUser(user); return null; }); }