[vcs-log] remove duplication between MultipleValueFilterPopupComponent and FilterModel

This commit is contained in:
Julia Beliaeva
2016-10-04 19:36:25 +03:00
parent ba1f1581e2
commit 56be37f551
4 changed files with 23 additions and 52 deletions
@@ -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<String> values) {
return VcsLogBranchFilterImpl
.fromTextPresentation(values, ContainerUtil.map2Set(myUi.getDataPack().getRefs().getBranches(), VcsRef::getName));
}
@Override
@NotNull
protected Collection<String> 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
}
}
}
@@ -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<String> getSelectedValues() {
List<String> getSelectedValues() {
return ContainerUtil.mapNotNull(StringUtil.tokenize(myTextField.getText(), new String(SEPARATORS)), value -> {
String trimmed = value.trim();
return trimmed.isEmpty() ? null : trimmed;
@@ -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<Filter extends VcsLogFilter> extends FilterPopupComponent<Filter> {
@@ -46,9 +47,6 @@ abstract class MultipleValueFilterPopupComponent<Filter extends VcsLogFilter> ex
myUiProperties = uiProperties;
}
@NotNull
protected abstract Collection<String> getTextValues(@Nullable Filter filter);
@NotNull
protected abstract List<List<String>> getRecentValuesFromSettings();
@@ -57,9 +55,6 @@ abstract class MultipleValueFilterPopupComponent<Filter extends VcsLogFilter> ex
@NotNull
protected abstract List<String> getAllValues();
@NotNull
protected abstract Filter createFilter(@NotNull Collection<String> values);
@NotNull
protected ActionGroup createRecentItemsActionGroup() {
DefaultActionGroup group = new DefaultActionGroup();
@@ -90,7 +85,7 @@ abstract class MultipleValueFilterPopupComponent<Filter extends VcsLogFilter> ex
}
@NotNull
protected AnAction createPredefinedValueAction(@NotNull Collection<String> values) {
protected AnAction createPredefinedValueAction(@NotNull List<String> values) {
return new PredefinedValueAction(values);
}
@@ -108,9 +103,9 @@ abstract class MultipleValueFilterPopupComponent<Filter extends VcsLogFilter> ex
protected class PredefinedValueAction extends DumbAwareAction {
@NotNull protected final Collection<String> myValues;
@NotNull protected final List<String> myValues;
public PredefinedValueAction(@NotNull Collection<String> values) {
public PredefinedValueAction(@NotNull List<String> values) {
super(null, tooltip(values), null);
getTemplatePresentation().setText(displayableText(values), false);
myValues = values;
@@ -118,7 +113,7 @@ abstract class MultipleValueFilterPopupComponent<Filter extends VcsLogFilter> 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<Filter extends VcsLogFilter> ex
}
Filter filter = myFilterModel.getFilter();
final MultilinePopupBuilder popupBuilder = new MultilinePopupBuilder(project, myVariants, getPopupText(getTextValues(filter)),
List<String> 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<String> selectedValues = popupBuilder.getSelectedValues();
List<String> selectedValues = popupBuilder.getSelectedValues();
if (selectedValues.isEmpty()) {
myFilterModel.setFilter(null);
}
else {
myFilterModel.setFilter(createFilter(selectedValues));
myFilterModel.setFilter(myFilterModel.createFilter(selectedValues));
rememberValuesInSettings(selectedValues);
}
}
@@ -47,13 +47,13 @@ class UserFilterPopupComponent extends MultipleValueFilterPopupComponent<VcsLogU
@NotNull
@Override
protected String getText(@NotNull VcsLogUserFilter filter) {
return displayableText(getTextValues(filter));
return displayableText(myFilterModel.getFilterValues(filter));
}
@Nullable
@Override
protected String getToolTip(@NotNull VcsLogUserFilter filter) {
return tooltip(getTextValues(filter));
return tooltip(myFilterModel.getFilterValues(filter));
}
@Override
@@ -62,21 +62,12 @@ class UserFilterPopupComponent extends MultipleValueFilterPopupComponent<VcsLogU
group.add(createAllAction());
group.add(createSelectMultipleValuesAction());
if (!myLogData.getCurrentUser().isEmpty()) {
group.add(createPredefinedValueAction(Collections.singleton(VcsLogUserFilterImpl.ME)));
group.add(createPredefinedValueAction(Collections.singletonList(VcsLogUserFilterImpl.ME)));
}
group.addAll(createRecentItemsActionGroup());
return group;
}
@NotNull
@Override
protected Collection<String> getTextValues(@Nullable VcsLogUserFilter filter) {
if (filter == null) {
return Collections.emptySet();
}
return ContainerUtil.newHashSet(((VcsLogUserFilterImpl)filter).getUserNamesForPresentation());
}
@NotNull
@Override
protected List<List<String>> getRecentValuesFromSettings() {
@@ -98,10 +89,4 @@ class UserFilterPopupComponent extends MultipleValueFilterPopupComponent<VcsLogU
return VcsUserUtil.capitalizeName(firstAndLastName.first) + " " + VcsUserUtil.capitalizeName(firstAndLastName.second);
});
}
@NotNull
@Override
protected VcsLogUserFilter createFilter(@NotNull Collection<String> values) {
return new VcsLogUserFilterImpl(values, myLogData.getCurrentUser(), myLogData.getAllUsers());
}
}