diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.java index edbb0536622..6acc763c5be 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.java @@ -342,6 +342,9 @@ public interface GitLocalizationConstant extends Messages { @Key("view.branch.delete_ask") String branchDeleteAsk(String name); + @Key("view.branch.filter.label") + String branchFilterLabel(); + @Key("view.branch.title") String branchTitle(); diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenter.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenter.java index 8a01cec59c6..e1db63a3635 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenter.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenter.java @@ -15,6 +15,7 @@ import org.eclipse.che.api.core.ErrorCodes; import org.eclipse.che.api.git.shared.Branch; +import org.eclipse.che.api.git.shared.BranchListMode; import org.eclipse.che.api.git.shared.CheckoutRequest; import org.eclipse.che.ide.api.app.AppContext; import org.eclipse.che.ide.api.dialogs.DialogFactory; @@ -29,7 +30,6 @@ import javax.validation.constraints.NotNull; -import static org.eclipse.che.api.git.shared.BranchListMode.LIST_ALL; import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; import static org.eclipse.che.ide.util.ExceptionUtils.getErrorCode; @@ -170,7 +170,7 @@ public void onCheckoutClicked() { /** Get the list of branches. */ private void getBranches() { - service.branchList(project.getLocation(), LIST_ALL) + service.branchList(project.getLocation(), BranchListMode.from(view.getFilterValue())) .then(branches -> { if (branches.isEmpty()) { dialogFactory.createMessageDialog(constant.branchTitle(), @@ -212,6 +212,11 @@ public void onBranchUnselected() { view.setEnableDeleteButton(false); } + @Override + public void onFilterValueChanged() { + getBranches(); + } + @Override public void onBranchSelected(@NotNull Branch branch) { selectedBranch = branch; diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchView.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchView.java index 3836a3391cf..fc7b5c2376f 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchView.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchView.java @@ -40,7 +40,7 @@ public interface ActionDelegate { void onCreateClicked(); /** - * Performs any action in response to the user having select branch. + * Performs any action in response to the user having selected branch. * * @param branch * selected revision @@ -49,6 +49,11 @@ public interface ActionDelegate { /** Performs any action in response to the user do not have any selected branch. */ void onBranchUnselected(); + + /** + * Performs any action in response to the user having selected branch filter. + */ + void onFilterValueChanged(); } /** @@ -83,6 +88,11 @@ public interface ActionDelegate { */ void setEnableRenameButton(boolean enabled); + /** + * Returns selected branch filter. + */ + String getFilterValue(); + /** Close dialog. */ void close(); diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchViewImpl.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchViewImpl.java index 473168c815f..aa2a650e877 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchViewImpl.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchViewImpl.java @@ -26,12 +26,15 @@ import org.vectomatic.dom.svg.ui.SVGResource; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.uibinder.client.UiHandler; import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.UIObject; import com.google.gwt.user.client.ui.Widget; @@ -60,6 +63,8 @@ interface BranchViewImplUiBinder extends UiBinder { Button btnCheckout; @UiField ScrollPanel branchesPanel; + @UiField + ListBox filter; @UiField(provided = true) final GitResources res; @UiField(provided = true) @@ -128,9 +133,18 @@ public Element createElement() { .create((SimpleList.View)breakPointsElement, coreRes.defaultSimpleListCss(), listBranchesRenderer, listBranchesDelegate); this.branchesPanel.add(branches); + this.filter.addItem("All", "all"); + this.filter.addItem("Local", "local"); + this.filter.addItem("Remote", "remote"); + createButtons(); } + @UiHandler("filter") + public void onFilterChanged(ChangeEvent event) { + delegate.onFilterValueChanged(); + } + private void createButtons() { btnClose = createButton(locale.buttonClose(), "git-branches-close", new ClickHandler() { @@ -249,6 +263,11 @@ public void setEnableRenameButton(boolean enabled) { btnRename.setEnabled(enabled); } + @Override + public String getFilterValue() { + return filter.getSelectedValue(); + } + /** {@inheritDoc} */ @Override public void close() { diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchViewImpl.ui.xml b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchViewImpl.ui.xml index 59f4afc10ad..eb6a9b414b7 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchViewImpl.ui.xml +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/branch/BranchViewImpl.ui.xml @@ -19,8 +19,18 @@ .emptyBorder { margin: 6px; } + + .alignLeft { + float: left; + } - + + + + + + + diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/resources/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.properties b/plugins/plugin-git/che-plugin-git-ext-git/src/main/resources/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.properties index 5ceb701e80d..e3c29fdbcb1 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/resources/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.properties +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/resources/org/eclipse/che/ide/ext/git/client/GitLocalizationConstant.properties @@ -125,6 +125,7 @@ view.branch.title_rename=Enter branch name view.branch.type_rename=Name: view.branch.delete=Delete branch view.branch.delete_ask=Are you sure you want to delete branch {0}? +view.branch.filter.label=Show branches: view.branch.title=Branches #Reset view.reset.files.title=Select files to reset diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenterTest.java b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenterTest.java index 5e09f2eea9c..1d10acb0dcd 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenterTest.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/test/java/org/eclipse/che/ide/ext/git/client/branch/BranchPresenterTest.java @@ -11,6 +11,7 @@ package org.eclipse.che.ide.ext.git.client.branch; import org.eclipse.che.api.git.shared.Branch; +import org.eclipse.che.api.git.shared.BranchListMode; import org.eclipse.che.api.git.shared.CheckoutRequest; import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto; @@ -55,24 +56,24 @@ public class BranchPresenterTest extends BaseTest { @Captor - private ArgumentCaptor inputCallbackCaptor; + private ArgumentCaptor inputCallbackCaptor; @Captor - private ArgumentCaptor confirmCallbackCaptor; + private ArgumentCaptor confirmCallbackCaptor; public static final String BRANCH_NAME = "branchName"; public static final String REMOTE_BRANCH_NAME = "origin/branchName"; public static final boolean IS_REMOTE = true; public static final boolean IS_ACTIVE = true; @Mock - private BranchView view; + private BranchView view; @Mock - private Branch selectedBranch; + private Branch selectedBranch; @Mock - private DialogFactory dialogFactory; + private DialogFactory dialogFactory; @Mock - private DtoFactory dtoFactory; + private DtoFactory dtoFactory; @Mock - private CheckoutRequest checkoutRequest; + private CheckoutRequest checkoutRequest; private BranchPresenter presenter; @@ -98,6 +99,7 @@ public void disarm() { when(service.branchList(anyObject(), anyObject())).thenReturn(branchListPromise); when(branchListPromise.then(any(Operation.class))).thenReturn(branchListPromise); when(branchListPromise.catchError(any(Operation.class))).thenReturn(branchListPromise); + when(view.getFilterValue()).thenReturn("all"); } @Test @@ -120,6 +122,50 @@ public void testShowBranchesWhenGetBranchesRequestIsSuccessful() throws Exceptio verify(constant, never()).branchesListFailed(); } + @Test + public void shouldShowLocalBranchesWheBranchesFilterIsSetToLocal() throws Exception { + //given + final List branches = Collections.singletonList(selectedBranch); + when(service.branchList(anyObject(), eq(BranchListMode.LIST_LOCAL))).thenReturn(branchListPromise); + when(branchListPromise.then(any(Operation.class))).thenReturn(branchListPromise); + when(branchListPromise.catchError(any(Operation.class))).thenReturn(branchListPromise); + when(view.getFilterValue()).thenReturn("local"); + + //when + presenter.showBranches(project); + verify(branchListPromise).then(branchListCaptor.capture()); + branchListCaptor.getValue().apply(branches); + + //then + verify(view).showDialogIfClosed(); + verify(view).setBranches(eq(branches)); + verify(console, never()).printError(anyString()); + verify(notificationManager, never()).notify(anyString(), any(ProjectConfigDto.class)); + verify(constant, never()).branchesListFailed(); + } + + @Test + public void shouldShowRemoteBranchesWheBranchesFilterIsSetToRemote() throws Exception { + //given + final List branches = Collections.singletonList(selectedBranch); + when(service.branchList(anyObject(), eq(BranchListMode.LIST_LOCAL))).thenReturn(branchListPromise); + when(branchListPromise.then(any(Operation.class))).thenReturn(branchListPromise); + when(branchListPromise.catchError(any(Operation.class))).thenReturn(branchListPromise); + when(view.getFilterValue()).thenReturn("remote"); + + //when + presenter.showBranches(project); + verify(branchListPromise).then(branchListCaptor.capture()); + branchListCaptor.getValue().apply(branches); + + //then + verify(view).showDialogIfClosed(); + verify(view).setBranches(eq(branches)); + verify(console, never()).printError(anyString()); + verify(notificationManager, never()).notify(anyString(), any(ProjectConfigDto.class)); + verify(constant, never()).branchesListFailed(); + } + @Test public void testOnCloseClicked() throws Exception { presenter.onCloseClicked(); diff --git a/wsagent/che-core-api-git-shared/src/main/java/org/eclipse/che/api/git/shared/BranchListMode.java b/wsagent/che-core-api-git-shared/src/main/java/org/eclipse/che/api/git/shared/BranchListMode.java index 4981f489796..f52b10d71a1 100644 --- a/wsagent/che-core-api-git-shared/src/main/java/org/eclipse/che/api/git/shared/BranchListMode.java +++ b/wsagent/che-core-api-git-shared/src/main/java/org/eclipse/che/api/git/shared/BranchListMode.java @@ -32,5 +32,18 @@ public enum BranchListMode { * Show only local branches.
* Corresponds to -l or empty option in console git. */ - LIST_LOCAL + LIST_LOCAL; + + public static BranchListMode from(String mode) { + switch (mode.toLowerCase()) { + case "all": + return LIST_ALL; + case "remote": + return LIST_REMOTE; + case "local": + return LIST_LOCAL; + default: + return null; + } + } }