From 56be37f551632bd26cf44c9eca382dd2f803adb4 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Wed, 28 Sep 2016 19:56:37 +0300 Subject: [PATCH] [vcs-log] remove duplication between MultipleValueFilterPopupComponent and FilterModel --- .../ui/filter/BranchFilterPopupComponent.java | 24 ++++-------------- .../log/ui/filter/MultilinePopupBuilder.java | 5 ++-- .../MultipleValueFilterPopupComponent.java | 25 +++++++++---------- .../ui/filter/UserFilterPopupComponent.java | 21 +++------------- 4 files changed, 23 insertions(+), 52 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java index 503b96285aef..303f780790c4 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/BranchFilterPopupComponent.java @@ -52,27 +52,13 @@ public class BranchFilterPopupComponent extends MultipleValueFilterPopupComponen @NotNull @Override protected String getText(@NotNull VcsLogBranchFilter filter) { - return displayableText(getTextValues(filter)); + return displayableText(myFilterModel.getFilterValues(filter)); } @Nullable @Override protected String getToolTip(@NotNull VcsLogBranchFilter filter) { - return tooltip(getTextValues(filter)); - } - - @NotNull - @Override - protected VcsLogBranchFilter createFilter(@NotNull Collection values) { - return VcsLogBranchFilterImpl - .fromTextPresentation(values, ContainerUtil.map2Set(myUi.getDataPack().getRefs().getBranches(), VcsRef::getName)); - } - - @Override - @NotNull - protected Collection getTextValues(@Nullable VcsLogBranchFilter filter) { - if (filter == null) return Collections.emptySet(); - return filter.getTextPresentation(); + return tooltip(myFilterModel.getFilterValues(filter)); } @Override @@ -125,10 +111,10 @@ public class BranchFilterPopupComponent extends MultipleValueFilterPopupComponen @NotNull @Override public AnAction createAction(@NotNull String name) { - return new PredefinedValueAction(Collections.singleton(name)) { + return new PredefinedValueAction(Collections.singletonList(name)) { @Override public void actionPerformed(@NotNull AnActionEvent e) { - myFilterModel.setFilter(BranchFilterPopupComponent.this.createFilter(myValues)); // does not add to recent + myFilterModel.setFilter(myFilterModel.createFilter(myValues)); // does not add to recent } }; } @@ -141,7 +127,7 @@ public class BranchFilterPopupComponent extends MultipleValueFilterPopupComponen @NotNull @Override protected AnAction createCollapsedAction(String actionName) { - return createPredefinedValueAction(Collections.singleton(actionName)); // adds to recent + return createPredefinedValueAction(Collections.singletonList(actionName)); // adds to recent } } } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/MultilinePopupBuilder.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/MultilinePopupBuilder.java index 7303224f4875..c1e7c5e68157 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/MultilinePopupBuilder.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/MultilinePopupBuilder.java @@ -40,7 +40,8 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.CompoundBorder; import java.awt.*; -import java.util.Collection; +import java.util.*; +import java.util.List; class MultilinePopupBuilder { private static final char[] SEPARATORS = {'|', '\n'}; @@ -97,7 +98,7 @@ class MultilinePopupBuilder { } @NotNull - Collection getSelectedValues() { + List getSelectedValues() { return ContainerUtil.mapNotNull(StringUtil.tokenize(myTextField.getText(), new String(SEPARATORS)), value -> { String trimmed = value.trim(); return trimmed.isEmpty() ? null : trimmed; diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/MultipleValueFilterPopupComponent.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/MultipleValueFilterPopupComponent.java index 00de611c7551..64f06bf85dcf 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/MultipleValueFilterPopupComponent.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/MultipleValueFilterPopupComponent.java @@ -31,6 +31,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.Collections; import java.util.List; abstract class MultipleValueFilterPopupComponent extends FilterPopupComponent { @@ -46,9 +47,6 @@ abstract class MultipleValueFilterPopupComponent ex myUiProperties = uiProperties; } - @NotNull - protected abstract Collection getTextValues(@Nullable Filter filter); - @NotNull protected abstract List> getRecentValuesFromSettings(); @@ -57,9 +55,6 @@ abstract class MultipleValueFilterPopupComponent ex @NotNull protected abstract List getAllValues(); - @NotNull - protected abstract Filter createFilter(@NotNull Collection values); - @NotNull protected ActionGroup createRecentItemsActionGroup() { DefaultActionGroup group = new DefaultActionGroup(); @@ -90,7 +85,7 @@ abstract class MultipleValueFilterPopupComponent ex } @NotNull - protected AnAction createPredefinedValueAction(@NotNull Collection values) { + protected AnAction createPredefinedValueAction(@NotNull List values) { return new PredefinedValueAction(values); } @@ -108,9 +103,9 @@ abstract class MultipleValueFilterPopupComponent ex protected class PredefinedValueAction extends DumbAwareAction { - @NotNull protected final Collection myValues; + @NotNull protected final List myValues; - public PredefinedValueAction(@NotNull Collection values) { + public PredefinedValueAction(@NotNull List values) { super(null, tooltip(values), null); getTemplatePresentation().setText(displayableText(values), false); myValues = values; @@ -118,7 +113,7 @@ abstract class MultipleValueFilterPopupComponent ex @Override public void actionPerformed(@NotNull AnActionEvent e) { - myFilterModel.setFilter(createFilter(myValues)); + myFilterModel.setFilter(myFilterModel.createFilter(myValues)); rememberValuesInSettings(myValues); } } @@ -140,19 +135,23 @@ abstract class MultipleValueFilterPopupComponent ex } Filter filter = myFilterModel.getFilter(); - final MultilinePopupBuilder popupBuilder = new MultilinePopupBuilder(project, myVariants, getPopupText(getTextValues(filter)), + List values = filter == null + ? Collections.emptyList() + : myFilterModel.getFilterValues(filter); + final MultilinePopupBuilder popupBuilder = new MultilinePopupBuilder(project, myVariants, + getPopupText(values), supportsNegativeValues()); JBPopup popup = popupBuilder.createPopup(); popup.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if (event.isOk()) { - Collection selectedValues = popupBuilder.getSelectedValues(); + List selectedValues = popupBuilder.getSelectedValues(); if (selectedValues.isEmpty()) { myFilterModel.setFilter(null); } else { - myFilterModel.setFilter(createFilter(selectedValues)); + myFilterModel.setFilter(myFilterModel.createFilter(selectedValues)); rememberValuesInSettings(selectedValues); } } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/UserFilterPopupComponent.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/UserFilterPopupComponent.java index a2d75ae312d8..29de5bdbef3a 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/UserFilterPopupComponent.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/filter/UserFilterPopupComponent.java @@ -47,13 +47,13 @@ class UserFilterPopupComponent extends MultipleValueFilterPopupComponent getTextValues(@Nullable VcsLogUserFilter filter) { - if (filter == null) { - return Collections.emptySet(); - } - return ContainerUtil.newHashSet(((VcsLogUserFilterImpl)filter).getUserNamesForPresentation()); - } - @NotNull @Override protected List> getRecentValuesFromSettings() { @@ -98,10 +89,4 @@ class UserFilterPopupComponent extends MultipleValueFilterPopupComponent values) { - return new VcsLogUserFilterImpl(values, myLogData.getCurrentUser(), myLogData.getAllUsers()); - } } \ No newline at end of file