use of org.eclipse.che.api.promises.client.Promise in project che by eclipse.
the class GdbConfigurationPagePresenter method setHosts.
private void setHosts(List<Machine> machines) {
List<Promise<RecipeDescriptor>> recipePromises = new ArrayList<>(machines.size());
for (Machine machine : machines) {
String location = machine.getConfig().getSource().getLocation();
String recipeId = getRecipeId(location);
recipePromises.add(recipeServiceClient.getRecipe(recipeId));
}
@SuppressWarnings("unchecked") final Promise<RecipeDescriptor>[] recipePromisesArray = (Promise<RecipeDescriptor>[]) recipePromises.toArray();
setHostsList(recipePromisesArray, machines);
}
use of org.eclipse.che.api.promises.client.Promise in project che by eclipse.
the class MovePresenter method prepareMovingChanges.
private Promise<ChangeCreationResult> prepareMovingChanges(final RefactoringSession session) {
MoveSettings moveSettings = dtoFactory.createDto(MoveSettings.class);
moveSettings.setSessionId(refactoringSessionId);
moveSettings.setUpdateReferences(view.isUpdateReferences());
moveSettings.setUpdateQualifiedNames(view.isUpdateQualifiedNames());
if (moveSettings.isUpdateQualifiedNames()) {
moveSettings.setFilePatterns(view.getFilePatterns());
}
return refactorService.setMoveSettings(moveSettings).thenPromise(new Function<Void, Promise<ChangeCreationResult>>() {
@Override
public Promise<ChangeCreationResult> apply(Void arg) throws FunctionException {
return refactorService.createChange(session);
}
});
}
use of org.eclipse.che.api.promises.client.Promise in project che by eclipse.
the class EditorAgentImpl method loadState.
@Override
@SuppressWarnings("unchecked")
public void loadState(@NotNull final JsonObject state) {
if (state.hasKey("FILES")) {
JsonObject files = state.getObject("FILES");
EditorPartStack partStack = editorMultiPartStack.createRootPartStack();
final Map<EditorPartPresenter, EditorPartStack> activeEditors = new HashMap<>();
List<Promise<Void>> restore = restore(files, partStack, activeEditors);
Promise<ArrayOf<?>> promise = promiseProvider.all2(restore.toArray(new Promise[restore.size()]));
promise.then(new Operation() {
@Override
public void apply(Object arg) throws OperationException {
String activeFile = "";
if (state.hasKey("ACTIVE_EDITOR")) {
activeFile = state.getString("ACTIVE_EDITOR");
}
EditorPartPresenter activeEditorPart = null;
for (Map.Entry<EditorPartPresenter, EditorPartStack> entry : activeEditors.entrySet()) {
entry.getValue().setActivePart(entry.getKey());
if (activeFile.equals(entry.getKey().getEditorInput().getFile().getLocation().toString())) {
activeEditorPart = entry.getKey();
}
}
workspaceAgent.setActivePart(activeEditorPart);
}
});
}
}
use of org.eclipse.che.api.promises.client.Promise in project che by eclipse.
the class EditorAgentImpl method restore.
private List<Promise<Void>> restore(JsonObject files, EditorPartStack editorPartStack, Map<EditorPartPresenter, EditorPartStack> activeEditors) {
if (files.hasKey("FILES")) {
//plain
JsonArray filesArray = files.getArray("FILES");
List<Promise<Void>> promises = new ArrayList<>();
for (int i = 0; i < filesArray.length(); i++) {
JsonObject file = filesArray.getObject(i);
Promise<Void> openFile = openFile(file, editorPartStack, activeEditors);
promises.add(openFile);
}
return promises;
} else {
//split
return restoreSplit(files, editorPartStack, activeEditors);
}
}
use of org.eclipse.che.api.promises.client.Promise in project che by eclipse.
the class ProjectWizard method complete.
/** {@inheritDoc} */
@Override
public void complete(@NotNull final CompleteCallback callback) {
if (mode == CREATE) {
appContext.getWorkspaceRoot().newProject().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
} else if (mode == UPDATE) {
appContext.getWorkspaceRoot().getContainer(Path.valueOf(dataObject.getPath())).then(new Operation<Optional<Container>>() {
@Override
public void apply(Optional<Container> optContainer) throws OperationException {
checkState(optContainer.isPresent(), "Failed to update non existed path");
final Container container = optContainer.get();
if (container.getResourceType() == PROJECT) {
((Project) container).update().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
} else if (container.getResourceType() == FOLDER) {
((Folder) container).toProject().withBody(dataObject).send().then(onComplete(callback)).catchError(onFailure(callback));
}
}
});
} else if (mode == IMPORT) {
appContext.getWorkspaceRoot().newProject().withBody(dataObject).send().thenPromise(new Function<Project, Promise<Project>>() {
@Override
public Promise<Project> apply(Project project) throws FunctionException {
return project.update().withBody(dataObject).send();
}
}).then(addCommands(callback)).catchError(onFailure(callback));
}
}
Aggregations