Search in sources :

Example 31 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class FullTextSearchPresenter method search.

@Override
public void search(final String text) {
    final Path startPoint = isNullOrEmpty(view.getPathToSearch()) ? defaultStartPoint : Path.valueOf(view.getPathToSearch());
    appContext.getWorkspaceRoot().getContainer(startPoint).then(new Operation<Optional<Container>>() {

        @Override
        public void apply(Optional<Container> optionalContainer) throws OperationException {
            if (!optionalContainer.isPresent()) {
                view.showErrorMessage("Path '" + startPoint + "' doesn't exists");
                return;
            }
            final Container container = optionalContainer.get();
            container.search(view.getFileMask(), prepareQuery(text)).then(new Operation<Resource[]>() {

                @Override
                public void apply(Resource[] result) throws OperationException {
                    view.close();
                    findResultPresenter.handleResponse(result, text);
                }
            });
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Container(org.eclipse.che.ide.api.resources.Container) Optional(com.google.common.base.Optional) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 32 with Container

use of org.eclipse.che.ide.api.resources.Container 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 33 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class InMemoryResourceStore method dispose.

/** {@inheritDoc} */
@Override
public void dispose(Path path, boolean withChildren) {
    checkArgument(path != null, "Null path occurred");
    final Path parent = path.segmentCount() == 1 ? Path.ROOT : path.parent();
    Resource[] container = memoryCache.get(parent);
    if (container != null) {
        int index = -1;
        for (int i = 0; i < container.length; i++) {
            if (container[i].getName().equals(path.lastSegment())) {
                index = i;
                break;
            }
        }
        if (index != -1) {
            int size = container.length;
            int numMoved = container.length - index - 1;
            if (numMoved > 0) {
                System.arraycopy(container, index + 1, container, index, numMoved);
            }
            container = copyOf(container, --size);
            memoryCache.put(parent, container);
        }
    }
    if (memoryCache.containsKey(path)) {
        container = memoryCache.remove(path);
        if (container != null && withChildren) {
            for (Resource resource : container) {
                if (resource instanceof Container) {
                    dispose(resource.getLocation(), true);
                }
            }
        }
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 34 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class ResourceImpl method getParentWithMarker.

/** {@inheritDoc} */
@Override
public Optional<Resource> getParentWithMarker(String type) {
    checkArgument(!isNullOrEmpty(type), "Invalid marker type occurred");
    if (getMarker(type).isPresent()) {
        return Optional.<Resource>of(this);
    }
    Container optParent = getParent();
    while (optParent != null) {
        Container parent = optParent;
        final Optional<Marker> marker = parent.getMarker(type);
        if (marker.isPresent()) {
            return Optional.<Resource>of(parent);
        }
        optParent = parent.getParent();
    }
    return absent();
}
Also used : Container(org.eclipse.che.ide.api.resources.Container) Resource(org.eclipse.che.ide.api.resources.Resource) Marker(org.eclipse.che.ide.api.resources.marker.Marker)

Example 35 with Container

use of org.eclipse.che.ide.api.resources.Container in project che by eclipse.

the class ResourceImpl method getRelatedProject.

/** {@inheritDoc} */
@Override
public Optional<Project> getRelatedProject() {
    if (this instanceof Project) {
        return of((Project) this);
    }
    Container optionalParent = getParent();
    if (optionalParent == null) {
        return absent();
    }
    Container parent = optionalParent;
    while (!(parent instanceof Project)) {
        optionalParent = parent.getParent();
        if (optionalParent == null) {
            return absent();
        }
        parent = optionalParent;
    }
    return of((Project) parent);
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Container(org.eclipse.che.ide.api.resources.Container)

Aggregations

Container (org.eclipse.che.ide.api.resources.Container)38 Resource (org.eclipse.che.ide.api.resources.Resource)32 Project (org.eclipse.che.ide.api.resources.Project)13 Operation (org.eclipse.che.api.promises.client.Operation)7 OperationException (org.eclipse.che.api.promises.client.OperationException)7 Optional (com.google.common.base.Optional)5 PromiseError (org.eclipse.che.api.promises.client.PromiseError)5 File (org.eclipse.che.ide.api.resources.File)5 Path (org.eclipse.che.ide.resource.Path)5 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)4 SVGResource (org.vectomatic.dom.svg.ui.SVGResource)4 List (java.util.List)3 FunctionException (org.eclipse.che.api.promises.client.FunctionException)3 Folder (org.eclipse.che.ide.api.resources.Folder)3 JavaUtil.isJavaProject (org.eclipse.che.ide.ext.java.client.util.JavaUtil.isJavaProject)3 RevealResourceEvent (org.eclipse.che.ide.resources.reveal.RevealResourceEvent)3 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2 Promise (org.eclipse.che.api.promises.client.Promise)2 Node (org.eclipse.che.ide.api.data.tree.Node)2