Search in sources :

Example 61 with PromiseError

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

the class FetchPresenter 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 {
            final String errorMessage = error.getMessage() != null ? error.getMessage() : constant.branchesListFailed();
            GitOutputConsole console = gitOutputConsoleFactory.create(FETCH_COMMAND_NAME);
            console.printError(errorMessage);
            processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(constant.branchesListFailed(), FAIL, FLOAT_MODE);
            view.setEnableFetchButton(false);
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Branch(org.eclipse.che.api.git.shared.Branch) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 62 with PromiseError

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

the class MergePresenter method showDialog.

/** Show dialog. */
public void showDialog(Project project) {
    this.project = project;
    final GitOutputConsole console = gitOutputConsoleFactory.create(MERGE_COMMAND_NAME);
    selectedReference = null;
    view.setEnableMergeButton(false);
    service.branchList(appContext.getDevMachine(), project.getLocation(), LIST_LOCAL).then(new Operation<List<Branch>>() {

        @Override
        public void apply(List<Branch> branches) throws OperationException {
            List<Reference> references = new ArrayList<>();
            for (Branch branch : branches) {
                if (!branch.isActive()) {
                    Reference reference = new Reference(branch.getName(), branch.getDisplayName(), LOCAL_BRANCH);
                    references.add(reference);
                }
            }
            view.setLocalBranches(references);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            console.printError(error.getMessage());
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(constant.branchesListFailed(), FAIL, FLOAT_MODE);
        }
    });
    service.branchList(appContext.getDevMachine(), project.getLocation(), LIST_REMOTE).then(new Operation<List<Branch>>() {

        @Override
        public void apply(List<Branch> branches) throws OperationException {
            List<Reference> references = new ArrayList<>();
            for (Branch branch : branches) {
                if (!branch.isActive()) {
                    Reference reference = new Reference(branch.getName(), branch.getDisplayName(), REMOTE_BRANCH);
                    references.add(reference);
                }
            }
            view.setRemoteBranches(references);
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            console.printError(error.getMessage());
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(constant.branchesListFailed(), FAIL, FLOAT_MODE);
        }
    });
    view.showDialog();
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) Branch(org.eclipse.che.api.git.shared.Branch) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 63 with PromiseError

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

the class PullPresenter method onPullClicked.

/** {@inheritDoc} */
@Override
public void onPullClicked() {
    view.close();
    final StatusNotification notification = notificationManager.notify(constant.pullProcess(), PROGRESS, FLOAT_MODE);
    service.pull(appContext.getDevMachine(), project.getLocation(), getRefs(), view.getRepositoryName()).then(new Operation<PullResponse>() {

        @Override
        public void apply(PullResponse response) throws OperationException {
            GitOutputConsole console = gitOutputConsoleFactory.create(PULL_COMMAND_NAME);
            console.print(response.getCommandOutput(), GREEN_COLOR);
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notification.setStatus(SUCCESS);
            if (response.getCommandOutput().contains("Already up-to-date")) {
                notification.setTitle(constant.pullUpToDate());
            } else {
                project.synchronize();
                notification.setTitle(constant.pullSuccess(view.getRepositoryUrl()));
            }
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notification.setStatus(FAIL);
            if (getErrorCode(error.getCause()) == ErrorCodes.MERGE_CONFLICT) {
                project.synchronize();
            }
            handleError(error.getCause(), PULL_COMMAND_NAME);
        }
    });
}
Also used : PullResponse(org.eclipse.che.api.git.shared.PullResponse) 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 64 with PromiseError

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

the class ResetFilesPresenter method showDialog.

/** Show dialog. */
public void showDialog(Project project) {
    this.project = project;
    service.getStatus(appContext.getDevMachine(), project.getLocation()).then(new Operation<Status>() {

        @Override
        public void apply(Status status) throws OperationException {
            if (status.isClean()) {
                dialogFactory.createMessageDialog(constant.messagesWarningTitle(), constant.indexIsEmpty(), null).show();
                return;
            }
            indexedFiles = new IndexFile[0];
            for (String path : status.getAdded()) {
                indexedFiles = add(indexedFiles, wrap(path));
            }
            for (String path : status.getChanged()) {
                indexedFiles = add(indexedFiles, wrap(path));
            }
            for (String path : status.getRemoved()) {
                indexedFiles = add(indexedFiles, wrap(path));
            }
            if (indexedFiles.length == 0) {
                dialogFactory.createMessageDialog(constant.messagesWarningTitle(), constant.indexIsEmpty(), null).show();
                return;
            }
            //Mark selected items to reset from index
            Resource[] resources = appContext.getResources();
            if (resources != null) {
                for (Resource selectedItem : resources) {
                    String selectedItemPath = selectedItem.getLocation().removeFirstSegments(1).toString();
                    for (IndexFile file : indexedFiles) if (file.getPath().startsWith(selectedItemPath)) {
                        file.setIndexed(false);
                    }
                }
            }
            view.setIndexedFiles(indexedFiles);
            view.showDialog();
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            String errorMassage = error.getMessage() != null ? error.getMessage() : constant.statusFailed();
            GitOutputConsole console = gitOutputConsoleFactory.create(STATUS_COMMAND_NAME);
            console.printError(errorMassage);
            consolesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(errorMassage);
        }
    });
}
Also used : Status(org.eclipse.che.api.git.shared.Status) PromiseError(org.eclipse.che.api.promises.client.PromiseError) IndexFile(org.eclipse.che.api.git.shared.IndexFile) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 65 with PromiseError

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

Aggregations

PromiseError (org.eclipse.che.api.promises.client.PromiseError)137 OperationException (org.eclipse.che.api.promises.client.OperationException)123 Operation (org.eclipse.che.api.promises.client.Operation)109 Project (org.eclipse.che.ide.api.resources.Project)48 Resource (org.eclipse.che.ide.api.resources.Resource)40 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)21 StatusNotification (org.eclipse.che.ide.api.notification.StatusNotification)20 Promise (org.eclipse.che.api.promises.client.Promise)19 List (java.util.List)15 JsPromiseError (org.eclipse.che.api.promises.client.js.JsPromiseError)13 GitOutputConsole (org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)13 Path (org.eclipse.che.ide.resource.Path)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 DebuggerObserver (org.eclipse.che.ide.debug.DebuggerObserver)11 VirtualFile (org.eclipse.che.ide.api.resources.VirtualFile)10 Credentials (org.eclipse.che.ide.api.subversion.Credentials)10 HashMap (java.util.HashMap)9 Function (org.eclipse.che.api.promises.client.Function)8 FunctionException (org.eclipse.che.api.promises.client.FunctionException)8