Search in sources :

Example 96 with Operation

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

the class FetchPresenter method onFetchClicked.

/** {@inheritDoc} */
@Override
public void onFetchClicked() {
    final String remoteUrl = view.getRepositoryUrl();
    final StatusNotification notification = notificationManager.notify(constant.fetchProcess(), PROGRESS, FLOAT_MODE);
    final GitOutputConsole console = gitOutputConsoleFactory.create(FETCH_COMMAND_NAME);
    service.fetch(appContext.getDevMachine(), project.getLocation(), view.getRepositoryName(), getRefs(), view.isRemoveDeletedRefs()).then(new Operation<Void>() {

        @Override
        public void apply(Void ignored) throws OperationException {
            console.print(constant.fetchSuccess(remoteUrl));
            processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notification.setStatus(SUCCESS);
            notification.setTitle(constant.fetchSuccess(remoteUrl));
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            handleError(error.getCause(), remoteUrl, 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) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 97 with Operation

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

the class CompareWithLatestAction method actionPerformed.

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
    final Project project = appContext.getRootProject();
    final Resource resource = appContext.getResource();
    checkState(project != null, "Null project occurred");
    checkState(project.getLocation().isPrefixOf(resource.getLocation()), "Given selected item is not descendant of given project");
    final String selectedItemPath = resource.getLocation().removeFirstSegments(project.getLocation().segmentCount()).removeTrailingSeparator().toString();
    service.diff(appContext.getDevMachine(), project.getLocation(), selectedItemPath.isEmpty() ? null : singletonList(selectedItemPath), NAME_STATUS, false, 0, REVISION, false).then(new Operation<String>() {

        @Override
        public void apply(String diff) throws OperationException {
            if (diff.isEmpty()) {
                dialogFactory.createMessageDialog(locale.compareMessageIdenticalContentTitle(), locale.compareMessageIdenticalContentText(), null).show();
            } else {
                final String[] changedFiles = diff.split("\n");
                if (changedFiles.length == 1) {
                    project.getFile(changedFiles[0].substring(2)).then(new Operation<Optional<File>>() {

                        @Override
                        public void apply(Optional<File> file) throws OperationException {
                            if (file.isPresent()) {
                                comparePresenter.showCompareWithLatest(file.get(), defineStatus(changedFiles[0].substring(0, 1)), REVISION);
                            }
                        }
                    });
                } else {
                    Map<String, Status> items = new HashMap<>();
                    for (String item : changedFiles) {
                        items.put(item.substring(2, item.length()), defineStatus(item.substring(0, 1)));
                    }
                    changedListPresenter.show(items, REVISION, null, project);
                }
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            notificationManager.notify(locale.diffFailed(), FAIL, NOT_EMERGE_MODE);
        }
    });
}
Also used : Status(org.eclipse.che.ide.ext.git.client.compare.FileStatus.Status) FileStatus.defineStatus(org.eclipse.che.ide.ext.git.client.compare.FileStatus.defineStatus) Optional(com.google.common.base.Optional) HashMap(java.util.HashMap) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) PromiseError(org.eclipse.che.api.promises.client.PromiseError) File(org.eclipse.che.ide.api.resources.File) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 98 with Operation

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

the class InitRepositoryPresenter method initRepository.

public void initRepository(final Project project) {
    final GitOutputConsole console = gitOutputConsoleFactory.create(INIT_COMMAND_NAME);
    service.init(appContext.getDevMachine(), project.getLocation(), false).then(new Operation<Void>() {

        @Override
        public void apply(Void ignored) throws OperationException {
            console.print(constant.initSuccess());
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(constant.initSuccess());
            project.synchronize();
        }
    }).catchError(new Operation<PromiseError>() {

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

Example 99 with Operation

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

the class MergePresenter method onMergeClicked.

/** {@inheritDoc} */
@Override
public void onMergeClicked() {
    view.close();
    final GitOutputConsole console = gitOutputConsoleFactory.create(MERGE_COMMAND_NAME);
    service.merge(appContext.getDevMachine(), project.getLocation(), selectedReference.getDisplayName()).then(new Operation<MergeResult>() {

        @Override
        public void apply(MergeResult result) throws OperationException {
            console.print(formMergeMessage(result));
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(formMergeMessage(result));
            project.synchronize();
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            if (error.getCause() instanceof ServerException && ((ServerException) error.getCause()).getErrorCode() == ErrorCodes.NO_COMMITTER_NAME_OR_EMAIL_DEFINED) {
                dialogFactory.createMessageDialog(constant.mergeTitle(), constant.committerIdentityInfoEmpty(), new ConfirmCallback() {

                    @Override
                    public void accepted() {
                    //do nothing
                    }
                }).show();
                return;
            }
            console.printError(error.getMessage());
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(constant.mergeFailed(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : ConfirmCallback(org.eclipse.che.ide.api.dialogs.ConfirmCallback) ServerException(org.eclipse.che.ide.commons.exception.ServerException) PromiseError(org.eclipse.che.api.promises.client.PromiseError) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) MergeResult(org.eclipse.che.api.git.shared.MergeResult) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 100 with Operation

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

the class ComparePresenter method showCompareWithLatest.

/**
     * Show compare window.
     *
     * @param file
     *         file name with its full path
     * @param status
     *         status of the file
     * @param revision
     *         hash of revision or branch
     */
public void showCompareWithLatest(final File file, final Status status, final String revision) {
    this.comparedFile = file;
    this.revision = revision;
    this.compareWithLatest = true;
    if (status.equals(ADDED)) {
        showCompare("");
        return;
    }
    final Optional<Project> project = file.getRelatedProject();
    if (!project.isPresent()) {
        return;
    }
    final Path relPath = file.getLocation().removeFirstSegments(project.get().getLocation().segmentCount());
    if (status.equals(DELETED)) {
        service.showFileContent(appContext.getDevMachine(), project.get().getLocation(), relPath, revision).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse content) throws OperationException {
                view.setTitle(file.getLocation().toString());
                view.setColumnTitles(locale.compareYourVersionTitle(), revision + locale.compareReadOnlyTitle());
                view.show(content.getContent(), "", file.getLocation().toString(), false);
            }
        }).catchError(new Operation<PromiseError>() {

            @Override
            public void apply(PromiseError error) throws OperationException {
                notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
            }
        });
    } else {
        service.showFileContent(appContext.getDevMachine(), project.get().getLocation(), relPath, revision).then(new Operation<ShowFileContentResponse>() {

            @Override
            public void apply(ShowFileContentResponse content) throws OperationException {
                showCompare(content.getContent());
            }
        }).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) Project(org.eclipse.che.ide.api.resources.Project) 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)

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