use of org.eclipse.che.api.promises.client.Promise in project che by eclipse.
the class PackageFragmentNode method getChildrenImpl.
@Override
protected Promise<List<Node>> getChildrenImpl() {
return createFromAsyncRequest(callback -> {
final List<Node> children = new ArrayList<>();
if (packageFragment.getKind() == PackageFragmentRoot.K_SOURCE) {
for (CompilationUnit compilationUnit : packageFragment.getCompilationUnits()) {
final List<Type> types = compilationUnit.getTypes();
final List<Node> nodes = types.stream().filter(Type::isPrimary).map(type -> nodeFactory.create(type, compilationUnit, null, matches)).collect(Collectors.toList());
children.addAll(nodes);
}
} else {
children.addAll(packageFragment.getClassFiles().stream().map(classFile -> nodeFactory.create(classFile.getType(), null, classFile, matches)).collect(Collectors.toList()));
}
callback.onSuccess(children);
});
}
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);
}
}
Aggregations