Search in sources :

Example 26 with Promise

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);
    });
}
Also used : CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) AsyncPromiseHelper.createFromAsyncRequest(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest) Inject(com.google.inject.Inject) Pair(org.eclipse.che.ide.util.Pair) JavaResources(org.eclipse.che.ide.ext.java.client.JavaResources) PackageFragmentRoot(org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragmentRoot) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Assisted(com.google.inject.assistedinject.Assisted) Promise(org.eclipse.che.api.promises.client.Promise) NodePresentation(org.eclipse.che.ide.ui.smartTree.presentation.NodePresentation) List(java.util.List) Match(org.eclipse.che.ide.ext.java.shared.dto.search.Match) PackageFragment(org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment) Node(org.eclipse.che.ide.api.data.tree.Node) CompilationUnit(org.eclipse.che.ide.ext.java.shared.dto.model.CompilationUnit) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) Map(java.util.Map) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) Node(org.eclipse.che.ide.api.data.tree.Node) ArrayList(java.util.ArrayList)

Example 27 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 28 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 29 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 30 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)

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