Search in sources :

Example 61 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 62 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 63 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 64 with Operation

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

the class LanguageServerCodeAssistProcessor method computeCompletionProposals.

@Override
public void computeCompletionProposals(TextEditor editor, final int offset, final boolean triggered, final CodeAssistCallback callback) {
    this.lastErrorMessage = null;
    TextDocumentPositionParamsDTO documentPosition = dtoBuildHelper.createTDPP(editor.getDocument(), offset);
    final TextDocumentIdentifierDTO documentId = documentPosition.getTextDocument();
    String currentLine = editor.getDocument().getLineContent(documentPosition.getPosition().getLine());
    final String currentWord = getCurrentWord(currentLine, documentPosition.getPosition().getCharacter());
    if (!triggered && latestCompletionResult.isGoodFor(documentId, offset, currentWord)) {
        // no need to send new completion request
        computeProposals(currentWord, offset - latestCompletionResult.getOffset(), callback);
    } else {
        documentServiceClient.completion(documentPosition).then(new Operation<CompletionListDTO>() {

            @Override
            public void apply(CompletionListDTO list) throws OperationException {
                latestCompletionResult.update(documentId, offset, currentWord, list);
                computeProposals(currentWord, 0, callback);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                lastErrorMessage = error.getMessage();
            }
        });
    }
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) CompletionListDTO(org.eclipse.che.api.languageserver.shared.lsapi.CompletionListDTO) PromiseError(org.eclipse.che.api.promises.client.PromiseError) TextDocumentIdentifierDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentIdentifierDTO) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 65 with Operation

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

the class FindDefinitionAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    EditorPartPresenter activeEditor = editorAgent.getActiveEditor();
    TextEditor textEditor = ((TextEditor) activeEditor);
    TextDocumentPositionParamsDTO paramsDTO = dtoBuildHelper.createTDPP(textEditor.getDocument(), textEditor.getCursorPosition());
    final Promise<List<LocationDTO>> promise = client.definition(paramsDTO);
    promise.then(new Operation<List<LocationDTO>>() {

        @Override
        public void apply(List<LocationDTO> arg) throws OperationException {
            if (arg.size() == 1) {
                presenter.onLocationSelected(arg.get(0));
            } else {
                presenter.openLocation(promise);
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            presenter.showError(arg);
        }
    });
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) TextEditor(org.eclipse.che.ide.api.editor.texteditor.TextEditor) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) EditorPartPresenter(org.eclipse.che.ide.api.editor.EditorPartPresenter) Operation(org.eclipse.che.api.promises.client.Operation) LocationDTO(org.eclipse.che.api.languageserver.shared.lsapi.LocationDTO) 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