Search in sources :

Example 21 with Promise

use of org.eclipse.che.api.promises.client.Promise in project che by eclipse.

the class DeleteResourceManager method onConfirm.

private ConfirmCallback onConfirm(final Resource[] resources, final AsyncCallback<Void> callback) {
    return new ConfirmCallback() {

        @Override
        public void accepted() {
            if (resources == null) {
                //sometimes we may occur NPE here while reading length
                callback.onFailure(new IllegalStateException());
                return;
            }
            Promise<?>[] deleteAll = new Promise<?>[resources.length];
            for (int i = 0; i < resources.length; i++) {
                final Resource resource = resources[i];
                deleteAll[i] = resource.delete().catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError error) throws OperationException {
                        notificationManager.notify("Failed to delete '" + resource.getName() + "'", error.getMessage(), FAIL, StatusNotification.DisplayMode.FLOAT_MODE);
                    }
                });
            }
            promiseProvider.all(deleteAll).then(new Operation<JsArrayMixed>() {

                @Override
                public void apply(JsArrayMixed arg) throws OperationException {
                    callback.onSuccess(null);
                }
            });
        }
    };
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) JsArrayMixed(com.google.gwt.core.client.JsArrayMixed) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 22 with Promise

use of org.eclipse.che.api.promises.client.Promise in project che by eclipse.

the class JavaProjectNode method getChildrenImpl.

@Override
protected Promise<List<Node>> getChildrenImpl() {
    return createFromAsyncRequest(callback -> {
        final List<Node> childrenNodes = new ArrayList<>();
        for (PackageFragmentRoot packageFragmentRoot : project.getPackageFragmentRoots()) {
            final List<PackageFragment> packageFragments = packageFragmentRoot.getPackageFragments();
            final List<Node> nodes = packageFragments.stream().map(packageFragment -> nodeFactory.create(packageFragment, matches, packageFragmentRoot)).collect(Collectors.toList());
            childrenNodes.addAll(nodes);
        }
        callback.onSuccess(childrenNodes);
    });
}
Also used : AsyncPromiseHelper.createFromAsyncRequest(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest) JavaProject(org.eclipse.che.ide.ext.java.shared.dto.model.JavaProject) Inject(com.google.inject.Inject) 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) Map(java.util.Map) NodesResources(org.eclipse.che.ide.project.shared.NodesResources) PackageFragment(org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragment) PackageFragmentRoot(org.eclipse.che.ide.ext.java.shared.dto.model.PackageFragmentRoot) Node(org.eclipse.che.ide.api.data.tree.Node) ArrayList(java.util.ArrayList)

Example 23 with Promise

use of org.eclipse.che.api.promises.client.Promise in project che by eclipse.

the class TypeNode method getChildrenImpl.

@Override
protected Promise<List<Node>> getChildrenImpl() {
    return createFromAsyncRequest(callback -> {
        List<Node> children = new ArrayList<>();
        if (compilationUnit != null && type.isPrimary()) {
            for (ImportDeclaration importDeclaration : compilationUnit.getImports()) {
                createNodeForAllMatches(importDeclaration.getHandleIdentifier(), children);
            }
            for (Type subType : compilationUnit.getTypes()) {
                if (subType == type) {
                    continue;
                }
                children.add(nodeFactory.create(subType, compilationUnit, classFile, matches));
            }
        }
        createNodeForAllMatches(type.getHandleIdentifier(), children);
        for (Initializer initializer : type.getInitializers()) {
            createNodeForAllMatches(initializer.getHandleIdentifier(), children);
        }
        for (Field field : type.getFields()) {
            createNodeForAllMatches(field.getHandleIdentifier(), children);
        }
        final List<Node> typeNodes = type.getTypes().stream().map(subType -> nodeFactory.create(subType, compilationUnit, classFile, matches)).collect(Collectors.toList());
        children.addAll(typeNodes);
        final List<Node> methodNodes = type.getMethods().stream().map(method -> nodeFactory.create(method, matches, compilationUnit, classFile)).collect(Collectors.toList());
        children.addAll(methodNodes);
        Collections.sort(children, new NodeComparator());
        callback.onSuccess(children);
    });
}
Also used : AsyncPromiseHelper.createFromAsyncRequest(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest) Inject(com.google.inject.Inject) Flags(org.eclipse.che.ide.ext.java.client.util.Flags) JavaResources(org.eclipse.che.ide.ext.java.client.JavaResources) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Nullable(org.eclipse.che.commons.annotation.Nullable) ArrayList(java.util.ArrayList) Assisted(com.google.inject.assistedinject.Assisted) ImportDeclaration(org.eclipse.che.ide.ext.java.shared.dto.model.ImportDeclaration) 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) Initializer(org.eclipse.che.ide.ext.java.shared.dto.model.Initializer) 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) Field(org.eclipse.che.ide.ext.java.shared.dto.model.Field) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) ClassFile(org.eclipse.che.ide.ext.java.shared.dto.model.ClassFile) Collections(java.util.Collections) Field(org.eclipse.che.ide.ext.java.shared.dto.model.Field) Type(org.eclipse.che.ide.ext.java.shared.dto.model.Type) Initializer(org.eclipse.che.ide.ext.java.shared.dto.model.Initializer) Node(org.eclipse.che.ide.api.data.tree.Node) ArrayList(java.util.ArrayList) ImportDeclaration(org.eclipse.che.ide.ext.java.shared.dto.model.ImportDeclaration)

Example 24 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)

Example 25 with Promise

use of org.eclipse.che.api.promises.client.Promise in project che by eclipse.

the class DeleteResourceManager method delete.

/**
     * Deletes the given resources and its descendants in the standard manner from file system.
     * Method requires a confirmation from the user before resource will be removed.
     *
     * @param needConfirmation
     *         true if confirmation is need
     * @param resources
     *         the resources to delete
     * @return the {@link Promise} with void if removal has successfully completed
     * @see #delete(Resource...)
     */
public Promise<Void> delete(boolean needConfirmation, Resource... resources) {
    checkArgument(resources != null, "Null resource occurred");
    checkArgument(resources.length > 0, "No resources were provided to remove");
    final Resource[] filtered = filterDescendants(resources);
    if (!needConfirmation) {
        Promise<?>[] deleteAll = new Promise<?>[resources.length];
        for (int i = 0; i < resources.length; i++) {
            deleteAll[i] = resources[i].delete();
        }
        return promiseProvider.all(deleteAll).then(new Function<JsArrayMixed, Void>() {

            @Override
            public Void apply(JsArrayMixed arg) throws FunctionException {
                return null;
            }
        });
    }
    List<Resource> projectsList = newArrayList();
    for (Resource resource : filtered) {
        if (resource.getResourceType() == PROJECT) {
            projectsList.add(resource);
        }
    }
    Resource[] projects = projectsList.toArray(new Resource[projectsList.size()]);
    if (projectsList.isEmpty()) {
        //if no project were found in nodes list
        return promptUserToDelete(filtered);
    } else if (projects.length < filtered.length) {
        //inform user that we can't delete mixed list of the nodes
        return promiseProvider.reject(JsPromiseError.create(localization.mixedProjectDeleteMessage()));
    } else {
        //delete only project nodes
        return promptUserToDelete(projects);
    }
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) JsArrayMixed(com.google.gwt.core.client.JsArrayMixed)

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