Search in sources :

Example 66 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class ImageViewer method onFileOperation.

/** {@inheritDoc} */
@Override
public void onFileOperation(FileEvent event) {
    if (event.getOperationType() != FileEvent.FileOperation.CLOSE) {
        return;
    }
    final Path eventFilePath = event.getFile().getLocation();
    final Path filePath = input.getFile().getLocation();
    if (filePath.equals(eventFilePath)) {
        workspaceAgent.removePart(this);
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path)

Example 67 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class ResourceManager method findResource.

private Promise<Optional<Resource>> findResource(final Path absolutePath, boolean quiet) {
    //search resource in local cache
    final Optional<Resource> optionalCachedResource = store.getResource(absolutePath);
    if (optionalCachedResource.isPresent()) {
        return promises.resolve(optionalCachedResource);
    }
    //request from server
    final Path projectPath = Path.valueOf(absolutePath.segment(0)).makeAbsolute();
    final Optional<Resource> optProject = store.getResource(projectPath);
    final boolean isPresent = optProject.isPresent();
    checkState(isPresent || quiet, "Resource with path '" + projectPath + "' doesn't exists");
    if (!isPresent) {
        return promises.resolve(Optional.<Resource>absent());
    }
    final Resource project = optProject.get();
    checkState(project.getResourceType() == PROJECT, "Resource with path '" + projectPath + "' isn't a project");
    final int seekDepth = absolutePath.segmentCount() - 1;
    return getRemoteResources((Container) project, seekDepth, true).then(new Function<Resource[], Optional<Resource>>() {

        @Override
        public Optional<Resource> apply(Resource[] resources) throws FunctionException {
            for (Resource resource : resources) {
                if (absolutePath.equals(resource.getLocation())) {
                    return of(resource);
                }
            }
            return absent();
        }
    });
}
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) FunctionException(org.eclipse.che.api.promises.client.FunctionException)

Example 68 with Path

use of org.eclipse.che.ide.resource.Path 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 69 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class EditorTabWidget method onResourceChanged.

@Override
public void onResourceChanged(ResourceChangedEvent event) {
    final ResourceDelta delta = event.getDelta();
    if (delta.getKind() == ADDED) {
        if (!delta.getResource().isFile() || (delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) {
            return;
        }
        final Resource resource = delta.getResource();
        final Path movedFrom = delta.getFromPath();
        if (file.getLocation().equals(movedFrom)) {
            file = (VirtualFile) resource;
            title.setText(file.getDisplayName());
        }
    } else if (delta.getKind() == UPDATED) {
        if (!delta.getResource().isFile()) {
            return;
        }
        final Resource resource = delta.getResource();
        if (file.getLocation().equals(resource.getLocation())) {
            file = (VirtualFile) resource;
            title.setText(file.getDisplayName());
        }
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) ResourceDelta(org.eclipse.che.ide.api.resources.ResourceDelta) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 70 with Path

use of org.eclipse.che.ide.resource.Path in project che by eclipse.

the class InMemoryResourceStore method getResource.

/** {@inheritDoc} */
@Override
public Optional<Resource> getResource(Path path) {
    checkArgument(path != null, "Null path occurred");
    final Path parent = path.parent();
    if (!memoryCache.containsKey(parent)) {
        return absent();
    }
    final Resource[] container = memoryCache.get(parent);
    if (container == null) {
        return absent();
    }
    for (Resource resource : container) {
        if (resource.getLocation().equals(path)) {
            return Optional.of(resource);
        }
    }
    return absent();
}
Also used : Path(org.eclipse.che.ide.resource.Path) Resource(org.eclipse.che.ide.api.resources.Resource)

Aggregations

Path (org.eclipse.che.ide.resource.Path)72 Resource (org.eclipse.che.ide.api.resources.Resource)27 Operation (org.eclipse.che.api.promises.client.Operation)15 OperationException (org.eclipse.che.api.promises.client.OperationException)15 PromiseError (org.eclipse.che.api.promises.client.PromiseError)13 ArrayList (java.util.ArrayList)11 Project (org.eclipse.che.ide.api.resources.Project)11 Promise (org.eclipse.che.api.promises.client.Promise)10 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)10 List (java.util.List)8 Test (org.junit.Test)7 ResourceDelta (org.eclipse.che.ide.api.resources.ResourceDelta)6 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)6 Optional (com.google.common.base.Optional)5 Function (org.eclipse.che.api.promises.client.Function)5 FunctionException (org.eclipse.che.api.promises.client.FunctionException)5 Container (org.eclipse.che.ide.api.resources.Container)5 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)5 HashMap (java.util.HashMap)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4