Search in sources :

Example 26 with Operation

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

the class PushToRemotePresenter method onPushClicked.

/** {@inheritDoc} */
@Override
public void onPushClicked() {
    final StatusNotification notification = notificationManager.notify(constant.pushProcess(), PROGRESS, FLOAT_MODE);
    final String repository = view.getRepository();
    final GitOutputConsole console = gitOutputConsoleFactory.create(PUSH_COMMAND_NAME);
    service.push(appContext.getDevMachine(), project.getLocation(), getRefs(), repository, false).then(new Operation<PushResponse>() {

        @Override
        public void apply(PushResponse response) throws OperationException {
            console.print(response.getCommandOutput());
            processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notification.setStatus(SUCCESS);
            if (response.getCommandOutput().contains("Everything up-to-date")) {
                notification.setTitle(constant.pushUpToDate());
            } else {
                notification.setTitle(constant.pushSuccess(repository));
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            handleError(error.getCause(), notification, console);
            processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
        }
    });
    view.close();
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) StatusNotification(org.eclipse.che.ide.api.notification.StatusNotification) Operation(org.eclipse.che.api.promises.client.Operation) PushResponse(org.eclipse.che.api.git.shared.PushResponse) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 27 with Operation

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

the class PushToRemotePresenter method getUpstreamBranch.

/**
     * Get upstream branch for selected local branch. Can invoke {@code onSuccess(null)} if upstream branch isn't set
     */
private void getUpstreamBranch(final AsyncCallback<Branch> result) {
    final String configBranchRemote = "branch." + view.getLocalBranch() + ".remote";
    final String configUpstreamBranch = "branch." + view.getLocalBranch() + ".merge";
    service.config(appContext.getDevMachine(), project.getLocation(), Arrays.asList(configUpstreamBranch, configBranchRemote)).then(new Operation<Map<String, String>>() {

        @Override
        public void apply(Map<String, String> configs) throws OperationException {
            if (configs.containsKey(configBranchRemote) && configs.containsKey(configUpstreamBranch)) {
                String displayName = configs.get(configBranchRemote) + "/" + configs.get(configUpstreamBranch);
                Branch upstream = dtoFactory.createDto(Branch.class).withActive(false).withRemote(true).withDisplayName(displayName).withName("refs/remotes/" + displayName);
                result.onSuccess(upstream);
            } else {
                result.onSuccess(null);
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            result.onFailure(error.getCause());
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Branch(org.eclipse.che.api.git.shared.Branch) Operation(org.eclipse.che.api.promises.client.Operation) Map(java.util.Map) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 28 with Operation

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

the class OrionEditorPresenter method onResourceCreated.

private void onResourceCreated(ResourceDelta delta) {
    if ((delta.getFlags() & (MOVED_FROM | MOVED_TO)) == 0) {
        return;
    }
    final Resource resource = delta.getResource();
    final Path movedFrom = delta.getFromPath();
    //file moved directly
    if (document.getFile().getLocation().equals(movedFrom)) {
        deletedFilesController.add(movedFrom.toString());
        document.setFile((File) resource);
        input.setFile((File) resource);
        updateContent();
    } else if (movedFrom.isPrefixOf(document.getFile().getLocation())) {
        //directory where file moved
        final Path relPath = document.getFile().getLocation().removeFirstSegments(movedFrom.segmentCount());
        final Path newPath = delta.getToPath().append(relPath);
        appContext.getWorkspaceRoot().getFile(newPath).then(new Operation<Optional<File>>() {

            @Override
            public void apply(Optional<File> file) throws OperationException {
                if (file.isPresent()) {
                    final Path location = document.getFile().getLocation();
                    deletedFilesController.add(location.toString());
                    generalEventBus.fireEvent(newFileTrackingStartEvent(file.get().getLocation().toString()));
                    document.setFile(file.get());
                    input.setFile(file.get());
                    updateTabReference(file.get(), location);
                    updateContent();
                }
            }
        });
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) Optional(com.google.common.base.Optional) SVGResource(org.vectomatic.dom.svg.ui.SVGResource) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) VirtualFile(org.eclipse.che.ide.api.resources.VirtualFile) File(org.eclipse.che.ide.api.resources.File)

Example 29 with Operation

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

the class AbstractDebugger method deleteBreakpoint.

@Override
public void deleteBreakpoint(final VirtualFile file, final int lineNumber) {
    if (!isConnected()) {
        return;
    }
    LocationDto locationDto = dtoFactory.createDto(LocationDto.class);
    locationDto.setLineNumber(lineNumber + 1);
    String fqn = pathToFqn(file);
    if (fqn == null) {
        return;
    }
    locationDto.setTarget(fqn);
    Promise<Void> promise = service.deleteBreakpoint(debugSessionDto.getId(), locationDto);
    promise.then(new Operation<Void>() {

        @Override
        public void apply(Void arg) throws OperationException {
            for (DebuggerObserver observer : observers) {
                Breakpoint breakpoint = new Breakpoint(Breakpoint.Type.BREAKPOINT, lineNumber, file.getLocation().toString(), file, false);
                observer.onBreakpointDeleted(breakpoint);
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            Log.error(AbstractDebugger.class, arg.getMessage());
        }
    });
}
Also used : Breakpoint(org.eclipse.che.ide.api.debug.Breakpoint) JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) DebuggerObserver(org.eclipse.che.ide.debug.DebuggerObserver) LocationDto(org.eclipse.che.api.debug.shared.dto.LocationDto) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 30 with Operation

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

the class AbstractDebugger method disconnect.

@Override
public void disconnect() {
    stopCheckingDebugEvents();
    Promise<Void> disconnect;
    if (isConnected()) {
        disconnect = service.disconnect(debugSessionDto.getId());
    } else {
        disconnect = Promises.resolve(null);
    }
    invalidateDebugSession();
    preserveDebuggerState();
    disconnect.then(new Operation<Void>() {

        @Override
        public void apply(Void arg) throws OperationException {
            for (DebuggerObserver observer : observers) {
                observer.onDebuggerDisconnected();
            }
            debuggerManager.setActiveDebugger(null);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            for (DebuggerObserver observer : observers) {
                observer.onDebuggerDisconnected();
            }
            debuggerManager.setActiveDebugger(null);
        }
    });
}
Also used : JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) DebuggerObserver(org.eclipse.che.ide.debug.DebuggerObserver) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

Operation (org.eclipse.che.api.promises.client.Operation)126 OperationException (org.eclipse.che.api.promises.client.OperationException)116 PromiseError (org.eclipse.che.api.promises.client.PromiseError)110 Project (org.eclipse.che.ide.api.resources.Project)51 Resource (org.eclipse.che.ide.api.resources.Resource)45 Promise (org.eclipse.che.api.promises.client.Promise)21 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)21 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)21 List (java.util.List)17 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)16 Path (org.eclipse.che.ide.resource.Path)14 GitOutputConsole (org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)13 Optional (com.google.common.base.Optional)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 File (org.eclipse.che.ide.api.resources.File)10 Credentials (org.eclipse.che.ide.api.subversion.Credentials)10 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)9 JsPromiseError (org.eclipse.che.api.promises.client.js.JsPromiseError)8 TestResult (org.eclipse.che.api.testing.shared.TestResult)7