Search in sources :

Example 16 with Path

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

the class PublishDiagnosticsProcessor method processDiagnostics.

public void processDiagnostics(PublishDiagnosticsParamsDTO diagnosticsMessage) {
    EditorPartPresenter openedEditor = editorAgent.getOpenedEditor(new Path(diagnosticsMessage.getUri()));
    //TODO add markers
    if (openedEditor == null) {
        return;
    }
    if (openedEditor instanceof TextEditor) {
        TextEditorConfiguration editorConfiguration = ((TextEditor) openedEditor).getConfiguration();
        AnnotationModel annotationModel = editorConfiguration.getAnnotationModel();
        if (annotationModel != null && annotationModel instanceof DiagnosticCollector) {
            DiagnosticCollector collector = (DiagnosticCollector) annotationModel;
            collector.beginReporting();
            try {
                for (DiagnosticDTO diagnostic : diagnosticsMessage.getDiagnostics()) {
                    collector.acceptDiagnostic(diagnostic);
                }
            } finally {
                collector.endReporting();
            }
        }
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) DiagnosticDTO(org.eclipse.che.api.languageserver.shared.lsapi.DiagnosticDTO) AnnotationModel(org.eclipse.che.ide.api.editor.annotation.AnnotationModel) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) TextEditorConfiguration(org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration)

Example 17 with Path

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

the class CommitPresenter method showDiff.

/** {@inheritDoc} */
@Override
public void showDiff(final String path) {
    final Project project = appContext.getRootProject();
    checkState(project != null);
    performOperationWithCredentialsRequestIfNeeded(new RemoteSubversionOperation<CLIOutputResponse>() {

        @Override
        public Promise<CLIOutputResponse> perform(Credentials credentials) {
            return service.showDiff(project.getLocation(), new Path[] { valueOf(path) }, "HEAD", credentials);
        }
    }, null).then(new Operation<CLIOutputResponse>() {

        @Override
        public void apply(CLIOutputResponse response) throws OperationException {
            String content = Joiner.on('\n').join(response.getOutput());
            diffViewerPresenter.showDiff(content);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(error.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) Operation(org.eclipse.che.api.promises.client.Operation) Credentials(org.eclipse.che.ide.api.subversion.Credentials) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 18 with Path

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

the class SubversionActionPresenter method toRelative.

protected Path[] toRelative(Container project, Resource[] paths) {
    if (paths == null || paths.length == 0) {
        return new Path[0];
    }
    Path[] rel = new Path[0];
    for (Resource resource : paths) {
        if (project.getLocation().isPrefixOf(resource.getLocation())) {
            Path temp = resource.getLocation().removeFirstSegments(project.getLocation().segmentCount());
            if (temp.segmentCount() == 0) {
                temp = Path.valueOf(".");
            }
            rel = Arrays.add(rel, temp);
        }
    }
    return rel;
}
Also used : Path(org.eclipse.che.ide.resource.Path) Resource(org.eclipse.che.ide.api.resources.Resource)

Example 19 with Path

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

the class ResourceManager method importProject.

protected Promise<Project> importProject(final Project.ProjectRequest importRequest) {
    checkArgument(checkProjectName(importRequest.getBody().getName()), "Invalid project name");
    checkNotNull(importRequest.getBody().getSource(), "Null source configuration occurred");
    final Path path = Path.valueOf(importRequest.getBody().getPath());
    return findResource(path, true).thenPromise(new Function<Optional<Resource>, Promise<Project>>() {

        @Override
        public Promise<Project> apply(final Optional<Resource> resource) throws FunctionException {
            final SourceStorage sourceStorage = importRequest.getBody().getSource();
            final SourceStorageDto sourceStorageDto = dtoFactory.createDto(SourceStorageDto.class).withType(sourceStorage.getType()).withLocation(sourceStorage.getLocation()).withParameters(sourceStorage.getParameters());
            return ps.importProject(path, sourceStorageDto).thenPromise(new Function<Void, Promise<Project>>() {

                @Override
                public Promise<Project> apply(Void ignored) throws FunctionException {
                    return ps.getProject(path).then(new Function<ProjectConfigDto, Project>() {

                        @Override
                        public Project apply(ProjectConfigDto config) throws FunctionException {
                            cachedConfigs = add(cachedConfigs, config);
                            Resource project = resourceFactory.newProjectImpl(config, ResourceManager.this);
                            checkState(project != null, "Failed to locate imported project's configuration");
                            store.register(project);
                            eventBus.fireEvent(new ResourceChangedEvent(new ResourceDeltaImpl(project, (resource.isPresent() ? UPDATED : ADDED) | DERIVED)));
                            return (Project) project;
                        }
                    });
                }
            });
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Optional(com.google.common.base.Optional) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Promise(org.eclipse.che.api.promises.client.Promise) Function(org.eclipse.che.api.promises.client.Function) Project(org.eclipse.che.ide.api.resources.Project) SourceStorage(org.eclipse.che.api.core.model.project.SourceStorage) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) ResourceChangedEvent(org.eclipse.che.ide.api.resources.ResourceChangedEvent)

Example 20 with Path

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

the class ResourceManager method search.

protected Promise<Resource[]> search(final Container container, String fileMask, String contentMask) {
    QueryExpression queryExpression = new QueryExpression();
    if (!isNullOrEmpty(contentMask)) {
        queryExpression.setText(contentMask);
    }
    if (!isNullOrEmpty(fileMask)) {
        queryExpression.setName(fileMask);
    }
    if (!container.getLocation().isRoot()) {
        queryExpression.setPath(container.getLocation().toString());
    }
    return ps.search(queryExpression).thenPromise(new Function<List<ItemReference>, Promise<Resource[]>>() {

        @Override
        public Promise<Resource[]> apply(final List<ItemReference> references) throws FunctionException {
            if (references.isEmpty()) {
                return promises.resolve(NO_RESOURCES);
            }
            int maxDepth = 0;
            final Path[] paths = new Path[references.size()];
            for (int i = 0; i < paths.length; i++) {
                final Path path = Path.valueOf(references.get(i).getPath());
                paths[i] = path;
                if (path.segmentCount() > maxDepth) {
                    maxDepth = path.segmentCount();
                }
            }
            return getRemoteResources(container, maxDepth, true).then(new Function<Resource[], Resource[]>() {

                @Override
                public Resource[] apply(Resource[] resources) throws FunctionException {
                    Resource[] filtered = NO_RESOURCES;
                    Path[] mutablePaths = paths;
                    outer: for (Resource resource : resources) {
                        if (resource.getResourceType() != FILE) {
                            continue;
                        }
                        for (int i = 0; i < mutablePaths.length; i++) {
                            Path path = mutablePaths[i];
                            if (path.segmentCount() == resource.getLocation().segmentCount() && path.equals(resource.getLocation())) {
                                Resource[] tmpFiltered = copyOf(filtered, filtered.length + 1);
                                tmpFiltered[filtered.length] = resource;
                                filtered = tmpFiltered;
                                //reduce the size of mutablePaths by removing already checked item
                                int size = mutablePaths.length;
                                int numMoved = mutablePaths.length - i - 1;
                                if (numMoved > 0) {
                                    arraycopy(mutablePaths, i + 1, mutablePaths, i, numMoved);
                                }
                                mutablePaths = copyOf(mutablePaths, --size);
                                continue outer;
                            }
                        }
                    }
                    return filtered;
                }
            });
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Resource(org.eclipse.che.ide.api.resources.Resource) FunctionException(org.eclipse.che.api.promises.client.FunctionException) ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) Promise(org.eclipse.che.api.promises.client.Promise) Function(org.eclipse.che.api.promises.client.Function) List(java.util.List) ArrayList(java.util.ArrayList) QueryExpression(org.eclipse.che.ide.api.project.QueryExpression)

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