Search in sources :

Example 1 with StorableBreakpointDto

use of org.eclipse.che.ide.api.debug.dto.StorableBreakpointDto 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 StorableBreakpointDto

use of org.eclipse.che.ide.api.debug.dto.StorableBreakpointDto in project che by eclipse.

the class BreakpointManagerImpl method preserveBreakpoints.

private void preserveBreakpoints() {
    Storage localStorage = Storage.getLocalStorageIfSupported();
    if (localStorage != null) {
        List<StorableBreakpointDto> allDtoBreakpoints = new LinkedList<StorableBreakpointDto>();
        List<Breakpoint> allBreakpoints = getBreakpointList();
        if (currentBreakpoint != null) {
            allBreakpoints.add(currentBreakpoint);
        }
        for (Breakpoint breakpoint : allBreakpoints) {
            StorableBreakpointDto dto = dtoFactory.createDto(StorableBreakpointDto.class);
            dto.setType(breakpoint.getType());
            dto.setPath(breakpoint.getPath());
            dto.setLineNumber(breakpoint.getLineNumber());
            if (breakpoint.getFile() instanceof Resource) {
                final Optional<Project> project = ((Resource) breakpoint.getFile()).getRelatedProject();
                if (project.isPresent()) {
                    final ProjectConfigDto projectDto = dtoFactory.createDto(ProjectConfigDto.class).withName(project.get().getName()).withPath(project.get().getPath()).withType(project.get().getType()).withDescription(project.get().getDescription()).withAttributes(project.get().getAttributes()).withMixins(project.get().getMixins());
                    //TODO need to think to change argument type from dto to model interface
                    dto.setFileProjectConfig(projectDto);
                }
            }
            dto.setActive(breakpoint.isActive());
            allDtoBreakpoints.add(dto);
        }
        String data = dtoFactory.toJson(allDtoBreakpoints);
        localStorage.setItem(LOCAL_STORAGE_BREAKPOINTS_KEY, data);
    }
}
Also used : Breakpoint(org.eclipse.che.ide.api.debug.Breakpoint) Project(org.eclipse.che.ide.api.resources.Project) Storage(com.google.gwt.storage.client.Storage) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) Resource(org.eclipse.che.ide.api.resources.Resource) StorableBreakpointDto(org.eclipse.che.ide.api.debug.dto.StorableBreakpointDto) LinkedList(java.util.LinkedList)

Aggregations

Storage (com.google.gwt.storage.client.Storage)2 Breakpoint (org.eclipse.che.ide.api.debug.Breakpoint)2 StorableBreakpointDto (org.eclipse.che.ide.api.debug.dto.StorableBreakpointDto)2 Optional (com.google.common.base.Optional)1 LinkedList (java.util.LinkedList)1 FunctionException (org.eclipse.che.api.promises.client.FunctionException)1 Operation (org.eclipse.che.api.promises.client.Operation)1 Promise (org.eclipse.che.api.promises.client.Promise)1 PromiseError (org.eclipse.che.api.promises.client.PromiseError)1 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)1 File (org.eclipse.che.ide.api.resources.File)1 Project (org.eclipse.che.ide.api.resources.Project)1 Resource (org.eclipse.che.ide.api.resources.Resource)1 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)1