Search in sources :

Example 1 with Promise

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

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

the class EditorAgentImpl method restoreSplit.

private List<Promise<Void>> restoreSplit(JsonObject files, EditorPartStack editorPartStack, Map<EditorPartPresenter, EditorPartStack> activeEditors) {
    JsonObject splitFirst = files.getObject("SPLIT_FIRST");
    String direction = files.getString("DIRECTION");
    double size = files.getNumber("SIZE");
    EditorPartStack split = editorMultiPartStack.split(editorPartStack, new Constraints(Direction.valueOf(direction), null), size);
    List<Promise<Void>> restoreFirst = restore(splitFirst, editorPartStack, activeEditors);
    JsonObject splitSecond = files.getObject("SPLIT_SECOND");
    List<Promise<Void>> restoreSecond = restore(splitSecond, split, activeEditors);
    List<Promise<Void>> result = new ArrayList<>();
    result.addAll(restoreFirst);
    result.addAll(restoreSecond);
    return result;
}
Also used : Promise(org.eclipse.che.api.promises.client.Promise) Constraints(org.eclipse.che.ide.api.constraints.Constraints) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) JsonObject(elemental.json.JsonObject) EditorPartStack(org.eclipse.che.ide.api.parts.EditorPartStack)

Example 3 with Promise

use of org.eclipse.che.api.promises.client.Promise 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 4 with Promise

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

the class DiffPresenter method showDiff.

public void showDiff() {
    final Project project = appContext.getRootProject();
    checkState(project != null);
    final Resource[] resources = appContext.getResources();
    checkState(!Arrays.isNullOrEmpty(resources));
    performOperationWithCredentialsRequestIfNeeded(new RemoteSubversionOperation<CLIOutputResponse>() {

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

        @Override
        public void apply(CLIOutputResponse response) throws OperationException {
            printResponse(response.getCommand(), response.getOutput(), response.getErrOutput(), constants.commandDiff());
            ;
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(error.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Resource(org.eclipse.che.ide.api.resources.Resource) 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 5 with Promise

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

the class LockUnlockPresenter method doUnlockAction.

private void doUnlockAction(final boolean force, final Path[] paths) {
    final Project project = appContext.getRootProject();
    checkState(project != null);
    performOperationWithCredentialsRequestIfNeeded(new RemoteSubversionOperation<CLIOutputResponse>() {

        @Override
        public Promise<CLIOutputResponse> perform(Credentials credentials) {
            return service.unlock(project.getLocation(), paths, force, credentials);
        }
    }, null).then(new Operation<CLIOutputResponse>() {

        @Override
        public void apply(CLIOutputResponse response) throws OperationException {
            printResponse(response.getCommand(), response.getOutput(), response.getErrOutput(), constants.commandUnlock());
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(error.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : 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)

Aggregations

Promise (org.eclipse.che.api.promises.client.Promise)37 Operation (org.eclipse.che.api.promises.client.Operation)20 PromiseError (org.eclipse.che.api.promises.client.PromiseError)20 OperationException (org.eclipse.che.api.promises.client.OperationException)18 Project (org.eclipse.che.ide.api.resources.Project)16 FunctionException (org.eclipse.che.api.promises.client.FunctionException)15 Resource (org.eclipse.che.ide.api.resources.Resource)13 ArrayList (java.util.ArrayList)10 Credentials (org.eclipse.che.ide.api.subversion.Credentials)10 Path (org.eclipse.che.ide.resource.Path)10 List (java.util.List)9 Function (org.eclipse.che.api.promises.client.Function)9 Map (java.util.Map)7 Optional (com.google.common.base.Optional)6 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)6 Inject (com.google.inject.Inject)5 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)5 Collectors (java.util.stream.Collectors)4 AsyncPromiseHelper.createFromAsyncRequest (org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest)4 Node (org.eclipse.che.ide.api.data.tree.Node)4