Search in sources :

Example 1 with FunctionException

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

the class BreakpointManagerImpl method restoreBreakpoints.

private void restoreBreakpoints() {
    Storage localStorage = Storage.getLocalStorageIfSupported();
    if (localStorage == null) {
        return;
    }
    String data = localStorage.getItem(LOCAL_STORAGE_BREAKPOINTS_KEY);
    if (data == null || data.isEmpty()) {
        return;
    }
    List<StorableBreakpointDto> allDtoBreakpoints = dtoFactory.createListDtoFromJson(data, StorableBreakpointDto.class);
    Promise<Void> bpPromise = promises.resolve(null);
    for (final StorableBreakpointDto dto : allDtoBreakpoints) {
        bpPromise.thenPromise(new Function<Void, Promise<Void>>() {

            @Override
            public Promise<Void> apply(Void ignored) throws FunctionException {
                return appContext.getWorkspaceRoot().getFile(dto.getPath()).then(new Function<Optional<File>, Void>() {

                    @Override
                    public Void apply(Optional<File> file) throws FunctionException {
                        if (!file.isPresent()) {
                            return null;
                        }
                        if (dto.getType() == Type.CURRENT) {
                            doSetCurrentBreakpoint(file.get(), dto.getLineNumber());
                        } else {
                            addBreakpoint(new Breakpoint(dto.getType(), dto.getLineNumber(), dto.getPath(), file.get(), dto.isActive()));
                        }
                        return null;
                    }
                }).catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError arg) throws OperationException {
                        Log.error(getClass(), "Failed to restore breakpoint. ", arg.getCause());
                    }
                });
            }
        });
    }
}
Also used : Breakpoint(org.eclipse.che.ide.api.debug.Breakpoint) Optional(com.google.common.base.Optional) FunctionException(org.eclipse.che.api.promises.client.FunctionException) Operation(org.eclipse.che.api.promises.client.Operation) StorableBreakpointDto(org.eclipse.che.ide.api.debug.dto.StorableBreakpointDto) Promise(org.eclipse.che.api.promises.client.Promise) Storage(com.google.gwt.storage.client.Storage) PromiseError(org.eclipse.che.api.promises.client.PromiseError) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 2 with FunctionException

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

the class CommandManagerImpl method update.

@Override
public Promise<CommandImpl> update(final String commandName, final CommandImpl command) {
    final String name;
    if (commandName.equals(command.getName())) {
        name = commandName;
    } else {
        name = getUniqueCommandName(command.getType(), command.getName());
    }
    final CommandDto commandDto = dtoFactory.createDto(CommandDto.class).withName(name).withCommandLine(command.getCommandLine()).withType(command.getType()).withAttributes(command.getAttributes());
    return workspaceServiceClient.updateCommand(appContext.getWorkspaceId(), commandName, commandDto).then(new Function<WorkspaceDto, CommandImpl>() {

        @Override
        public CommandImpl apply(WorkspaceDto arg) throws FunctionException {
            final CommandImpl updatedCommand = new CommandImpl(commandDto.getName(), command.getCommandLine(), command.getType(), command.getAttributes());
            commands.remove(commandName);
            commands.put(updatedCommand.getName(), updatedCommand);
            fireCommandUpdated(updatedCommand);
            return updatedCommand;
        }
    });
}
Also used : CommandImpl(org.eclipse.che.ide.api.command.CommandImpl) FunctionException(org.eclipse.che.api.promises.client.FunctionException) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)

Example 3 with FunctionException

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

the class FindSymbolAction method searchSymbols.

private Promise<List<SymbolEntry>> searchSymbols(final String value) {
    WorkspaceSymbolParamsDTO params = dtoFactory.createDto(WorkspaceSymbolParamsDTO.class);
    params.setQuery(value);
    params.setFileUri(editorAgent.getActiveEditor().getEditorInput().getFile().getLocation().toString());
    return workspaceServiceClient.symbol(params).then(new Function<List<SymbolInformationDTO>, List<SymbolEntry>>() {

        @Override
        public List<SymbolEntry> apply(List<SymbolInformationDTO> types) throws FunctionException {
            return toSymbolEntries(types, value);
        }
    });
}
Also used : SymbolInformationDTO(org.eclipse.che.api.languageserver.shared.lsapi.SymbolInformationDTO) FunctionException(org.eclipse.che.api.promises.client.FunctionException) WorkspaceSymbolParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.WorkspaceSymbolParamsDTO) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List)

Example 4 with FunctionException

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

the class LanguageServerEditorProvider method createEditor.

@Override
public Promise<EditorPartPresenter> createEditor(VirtualFile file) {
    if (file instanceof File) {
        File resource = (File) file;
        Promise<InitializeResult> promise = registry.getOrInitializeServer(resource.getRelatedProject().get().getPath(), resource.getExtension(), resource.getLocation().toString());
        final MessageLoader loader = loaderFactory.newLoader("Initializing Language Server for " + resource.getExtension());
        loader.show();
        return promise.thenPromise(new Function<InitializeResult, Promise<EditorPartPresenter>>() {

            @Override
            public Promise<EditorPartPresenter> apply(InitializeResult arg) throws FunctionException {
                loader.hide();
                return Promises.<EditorPartPresenter>resolve(createEditor(editorConfigurationFactory.build(arg.getCapabilities())));
            }
        });
    }
    return null;
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) InitializeResult(io.typefox.lsapi.InitializeResult) MessageLoader(org.eclipse.che.ide.ui.loaders.request.MessageLoader) FunctionException(org.eclipse.che.api.promises.client.FunctionException) File(org.eclipse.che.ide.api.resources.File) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile)

Example 5 with FunctionException

use of org.eclipse.che.api.promises.client.FunctionException 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)

Aggregations

FunctionException (org.eclipse.che.api.promises.client.FunctionException)24 Promise (org.eclipse.che.api.promises.client.Promise)15 Resource (org.eclipse.che.ide.api.resources.Resource)12 Function (org.eclipse.che.api.promises.client.Function)11 Optional (com.google.common.base.Optional)9 Project (org.eclipse.che.ide.api.resources.Project)8 List (java.util.List)7 PromiseError (org.eclipse.che.api.promises.client.PromiseError)7 Path (org.eclipse.che.ide.resource.Path)6 Operation (org.eclipse.che.api.promises.client.Operation)5 ResourceChangedEvent (org.eclipse.che.ide.api.resources.ResourceChangedEvent)5 ArrayList (java.util.ArrayList)4 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)4 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)4 MutableProjectConfig (org.eclipse.che.ide.api.project.MutableProjectConfig)4 SourceStorage (org.eclipse.che.api.core.model.project.SourceStorage)3 TextDocumentPositionParamsDTO (org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO)3 OperationException (org.eclipse.che.api.promises.client.OperationException)3 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 Set (java.util.Set)2