Search in sources :

Example 31 with Promise

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);
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) ArrayList(java.util.ArrayList) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) Machine(org.eclipse.che.api.core.model.machine.Machine)

Example 32 with Promise

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);
        }
    });
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) FunctionException(org.eclipse.che.api.promises.client.FunctionException) MoveSettings(org.eclipse.che.ide.ext.java.shared.dto.refactoring.MoveSettings)

Example 33 with Promise

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);
            }
        });
    }
}
Also used : ArrayOf(elemental.util.ArrayOf) HashMap(java.util.HashMap) JsonObject(elemental.json.JsonObject) Operation(org.eclipse.che.api.promises.client.Operation) Promise(org.eclipse.che.api.promises.client.Promise) HasDataObject(org.eclipse.che.ide.api.data.HasDataObject) JsonObject(elemental.json.JsonObject) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) EditorPartStack(org.eclipse.che.ide.api.parts.EditorPartStack) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 34 with Promise

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);
    }
}
Also used : JsonArray(elemental.json.JsonArray) Promise(org.eclipse.che.api.promises.client.Promise) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) JsonObject(elemental.json.JsonObject)

Example 35 with Promise

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));
    }
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) Container(org.eclipse.che.ide.api.resources.Container) Optional(com.google.common.base.Optional) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Operation(org.eclipse.che.api.promises.client.Operation)

Aggregations

Promise (org.eclipse.che.api.promises.client.Promise)37 Operation (org.eclipse.che.api.promises.client.Operation)20 PromiseError (org.eclipse.che.api.promises.client.PromiseError)20 OperationException (org.eclipse.che.api.promises.client.OperationException)18 Project (org.eclipse.che.ide.api.resources.Project)16 FunctionException (org.eclipse.che.api.promises.client.FunctionException)15 Resource (org.eclipse.che.ide.api.resources.Resource)13 ArrayList (java.util.ArrayList)10 Credentials (org.eclipse.che.ide.api.subversion.Credentials)10 Path (org.eclipse.che.ide.resource.Path)10 List (java.util.List)9 Function (org.eclipse.che.api.promises.client.Function)9 Map (java.util.Map)7 Optional (com.google.common.base.Optional)6 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)6 Inject (com.google.inject.Inject)5 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)5 Collectors (java.util.stream.Collectors)4 AsyncPromiseHelper.createFromAsyncRequest (org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest)4 Node (org.eclipse.che.ide.api.data.tree.Node)4