Search in sources :

Example 21 with Operation

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

the class AddToIndexPresenter method onAddClicked.

/** {@inheritDoc} */
@Override
public void onAddClicked() {
    DevMachine devMachine = appContext.getDevMachine();
    Resource[] resources = appContext.getResources();
    Path projectLocation = appContext.getRootProject().getLocation();
    Path[] paths = new Path[resources.length];
    for (int i = 0; i < resources.length; i++) {
        Path path = resources[i].getLocation().removeFirstSegments(projectLocation.segmentCount());
        paths[i] = path.segmentCount() == 0 ? Path.EMPTY : path;
    }
    final GitOutputConsole console = gitOutputConsoleFactory.create(constant.addToIndexCommandName());
    consolesPanelPresenter.addCommandOutput(devMachine.getId(), console);
    service.add(devMachine, projectLocation, view.isUpdated(), paths).then(new Operation<Void>() {

        @Override
        public void apply(Void arg) throws OperationException {
            console.print(constant.addSuccess());
            notificationManager.notify(constant.addSuccess());
            view.close();
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            console.printError(constant.addFailed());
            notificationManager.notify(constant.addFailed(), FAIL, FLOAT_MODE);
            view.close();
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) PromiseError(org.eclipse.che.api.promises.client.PromiseError) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 22 with Operation

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

the class BranchPresenter method onCheckoutClicked.

/** {@inheritDoc} */
@Override
public void onCheckoutClicked() {
    final CheckoutRequest checkoutRequest = dtoFactory.createDto(CheckoutRequest.class);
    if (selectedBranch.isRemote()) {
        checkoutRequest.setTrackBranch(selectedBranch.getDisplayName());
    } else {
        checkoutRequest.setName(selectedBranch.getDisplayName());
    }
    service.checkout(appContext.getDevMachine(), project.getLocation(), checkoutRequest).then(new Operation<Void>() {

        @Override
        public void apply(Void ignored) throws OperationException {
            getBranches();
            project.synchronize();
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            handleError(error.getCause(), BRANCH_CHECKOUT_COMMAND_NAME);
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) CheckoutRequest(org.eclipse.che.api.git.shared.CheckoutRequest) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 23 with Operation

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

the class CommitPresenter method setAmendCommitMessage.

/** {@inheritDoc} */
@Override
public void setAmendCommitMessage() {
    service.log(appContext.getDevMachine(), project.getLocation(), null, false).then(new Operation<LogResponse>() {

        @Override
        public void apply(LogResponse log) throws OperationException {
            final List<Revision> commits = log.getCommits();
            String message = "";
            if (commits != null && (!commits.isEmpty())) {
                final Revision tip = commits.get(0);
                if (tip != null) {
                    message = tip.getMessage();
                }
            }
            CommitPresenter.this.view.setMessage(message);
            CommitPresenter.this.view.setEnableCommitButton(!message.isEmpty());
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            if (getErrorCode(error.getCause()) == ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED) {
                dialogFactory.createMessageDialog(constant.commitTitle(), constant.initCommitWasNotPerformed(), null).show();
            } else {
                CommitPresenter.this.view.setMessage("");
                notificationManager.notify(constant.logFailed(), FAIL, NOT_EMERGE_MODE);
            }
        }
    });
}
Also used : LogResponse(org.eclipse.che.api.git.shared.LogResponse) Revision(org.eclipse.che.api.git.shared.Revision) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 24 with Operation

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

the class ComparePresenter method showCompareBetweenRevisions.

/**
     *
     * @param file
     *         path of the file
     * @param status
     *         status of the file
     * @param revisionA
     *         hash of the first revision or branch.
     *         If it is set to {@code null}, compare with empty repository state will be performed
     * @param revisionB
     *         hash of the second revision or branch.
     *         If it is set to {@code null}, compare with latest repository state will be performed
     */
public void showCompareBetweenRevisions(final Path file, final Status status, @Nullable final String revisionA, @Nullable final String revisionB) {
    this.compareWithLatest = false;
    final DevMachine devMachine = appContext.getDevMachine();
    final Path projectLocation = appContext.getRootProject().getLocation();
    view.setTitle(file.toString());
    if (status == Status.ADDED) {
        service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse response) throws OperationException {
                view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA == null ? "" : revisionA + locale.compareReadOnlyTitle());
                view.show("", response.getContent(), file.toString(), true);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
            }
        });
    } else if (status == Status.DELETED) {
        service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse response) throws OperationException {
                view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
                view.show(response.getContent(), "", file.toString(), true);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
            }
        });
    } else {
        service.showFileContent(devMachine, projectLocation, file, revisionA).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(final ShowFileContentResponse contentAResponse) throws OperationException {
                service.showFileContent(devMachine, projectLocation, file, revisionB).then(new Operation<ShowFileContentResponse>() {

                    @Override
                    public void apply(ShowFileContentResponse contentBResponse) throws OperationException {
                        view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
                        view.show(contentAResponse.getContent(), contentBResponse.getContent(), file.toString(), true);
                    }
                }).catchError(new Operation<PromiseError>() {

                    @Override
                    public void apply(PromiseError error) throws OperationException {
                        notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
                    }
                });
            }
        });
    }
}
Also used : Path(org.eclipse.che.ide.resource.Path) DevMachine(org.eclipse.che.ide.api.machine.DevMachine) PromiseError(org.eclipse.che.api.promises.client.PromiseError) ShowFileContentResponse(org.eclipse.che.api.git.shared.ShowFileContentResponse) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 25 with Operation

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

the class PullPresenter method updateBranches.

/**
     * Update the list of branches.
     *
     * @param remoteMode
     *         is a remote mode
     */
private void updateBranches(@NotNull final BranchListMode remoteMode) {
    service.branchList(appContext.getDevMachine(), project.getLocation(), remoteMode).then(new Operation<List<Branch>>() {

        @Override
        public void apply(List<Branch> branches) throws OperationException {
            if (LIST_REMOTE.equals(remoteMode)) {
                view.setRemoteBranches(branchSearcher.getRemoteBranchesToDisplay(view.getRepositoryName(), branches));
                updateBranches(LIST_LOCAL);
            } else {
                view.setLocalBranches(branchSearcher.getLocalBranchesToDisplay(branches));
                for (Branch branch : branches) {
                    if (branch.isActive()) {
                        view.selectRemoteBranch(branch.getDisplayName());
                        break;
                    }
                }
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            handleError(error.getCause(), BRANCH_LIST_COMMAND_NAME);
            view.setEnablePullButton(false);
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Branch(org.eclipse.che.api.git.shared.Branch) List(java.util.List) Operation(org.eclipse.che.api.promises.client.Operation) 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