Search in sources :

Example 1 with BranchFilterByRemote

use of org.eclipse.che.ide.ext.git.client.BranchFilterByRemote in project che by eclipse.

the class PushToRemotePresenter method updateRemoteBranches.

/**
     * Update list of remote branches on view.
     */
void updateRemoteBranches() {
    getBranchesForCurrentProject(LIST_REMOTE, new AsyncCallback<List<Branch>>() {

        @Override
        public void onSuccess(final List<Branch> result) {
            // Need to add the upstream of local branch in the list of remote branches
            // to be able to push changes to the remote upstream branch
            getUpstreamBranch(new AsyncCallback<Branch>() {

                @Override
                public void onSuccess(Branch upstream) {
                    BranchFilterByRemote remoteRefsHandler = new BranchFilterByRemote(view.getRepository());
                    final List<String> remoteBranches = branchSearcher.getRemoteBranchesToDisplay(remoteRefsHandler, result);
                    String selectedRemoteBranch = null;
                    if (upstream != null && upstream.isRemote() && remoteRefsHandler.isLinkedTo(upstream)) {
                        String simpleUpstreamName = remoteRefsHandler.getBranchNameWithoutRefs(upstream);
                        if (!remoteBranches.contains(simpleUpstreamName)) {
                            remoteBranches.add(simpleUpstreamName);
                        }
                        selectedRemoteBranch = simpleUpstreamName;
                    }
                    // Need to add the current local branch in the list of remote branches
                    // to be able to push changes to the remote branch  with same name
                    final String currentBranch = view.getLocalBranch();
                    if (!remoteBranches.contains(currentBranch)) {
                        remoteBranches.add(currentBranch);
                    }
                    if (selectedRemoteBranch == null) {
                        selectedRemoteBranch = currentBranch;
                    }
                    view.setRemoteBranches(remoteBranches);
                    view.selectRemoteBranch(selectedRemoteBranch);
                }

                @Override
                public void onFailure(Throwable caught) {
                    GitOutputConsole console = gitOutputConsoleFactory.create(CONFIG_COMMAND_NAME);
                    console.printError(constant.failedGettingConfig());
                    processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
                    notificationManager.notify(constant.failedGettingConfig(), FAIL, FLOAT_MODE);
                }
            });
        }

        @Override
        public void onFailure(Throwable exception) {
            String errorMessage = exception.getMessage() != null ? exception.getMessage() : constant.remoteBranchesListFailed();
            GitOutputConsole console = gitOutputConsoleFactory.create(BRANCH_LIST_COMMAND_NAME);
            console.printError(errorMessage);
            processesPanelPresenter.addCommandOutput(appContext.getDevMachine().getId(), console);
            notificationManager.notify(constant.remoteBranchesListFailed(), FAIL, FLOAT_MODE);
            view.setEnablePushButton(false);
        }
    });
}
Also used : Branch(org.eclipse.che.api.git.shared.Branch) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) BranchFilterByRemote(org.eclipse.che.ide.ext.git.client.BranchFilterByRemote) GitOutputConsole(org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List)

Aggregations

AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Branch (org.eclipse.che.api.git.shared.Branch)1 BranchFilterByRemote (org.eclipse.che.ide.ext.git.client.BranchFilterByRemote)1 GitOutputConsole (org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)1