mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
vcs: Utilized "ComboBoxAction" for "LabeledComboBoxAction" implementation (instead of just using custom combo box), updated "SelectFilteringAction" and "SelectGroupingAction" accordingly
This commit is contained in:
+6
-1
@@ -79,7 +79,7 @@ public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataP
|
||||
private final RepositoryChangesBrowser myDetailsView;
|
||||
private List<CommittedChangeList> myChangeLists;
|
||||
private List<CommittedChangeList> mySelectedChangeLists;
|
||||
private ChangeListGroupingStrategy myGroupingStrategy = new DateChangeListGroupingStrategy();
|
||||
@NotNull private ChangeListGroupingStrategy myGroupingStrategy = new DateChangeListGroupingStrategy();
|
||||
private final CompositeChangeListFilteringStrategy myFilteringStrategy = new CompositeChangeListFilteringStrategy();
|
||||
private final JPanel myLeftPanel;
|
||||
private final FilterChangeListener myFilterChangeListener = new FilterChangeListener();
|
||||
@@ -254,6 +254,11 @@ public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataP
|
||||
updateModel();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ChangeListGroupingStrategy getGroupingStrategy() {
|
||||
return myGroupingStrategy;
|
||||
}
|
||||
|
||||
private void updateBySelectionChange() {
|
||||
List<CommittedChangeList> selection = new ArrayList<CommittedChangeList>();
|
||||
final TreePath[] selectionPaths = myChangesTree.getSelectionPaths();
|
||||
|
||||
+13
-39
@@ -15,60 +15,34 @@
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.committed;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.actionSystem.ex.CustomComponentAction;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public abstract class LabeledComboBoxAction extends AnAction implements CustomComponentAction {
|
||||
public abstract class LabeledComboBoxAction extends ComboBoxAction {
|
||||
|
||||
@NotNull private final JLabel myLabel;
|
||||
@Nullable private JPanel myPanel;
|
||||
@NotNull private final ComboBox myComboBox;
|
||||
@NotNull private final String myLabel;
|
||||
|
||||
protected LabeledComboBoxAction(@NotNull String label) {
|
||||
myComboBox = new ComboBox();
|
||||
myLabel = new JLabel(label);
|
||||
myLabel = label;
|
||||
}
|
||||
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
}
|
||||
@Override
|
||||
public JComponent createCustomComponent(@NotNull Presentation presentation) {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
|
||||
@NotNull
|
||||
public JComponent createCustomComponent(Presentation presentation) {
|
||||
if (myPanel == null) {
|
||||
myPanel = new JPanel(new BorderLayout());
|
||||
myPanel.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4));
|
||||
myPanel.add(myLabel, BorderLayout.WEST);
|
||||
myComboBox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
selectionChanged(myComboBox.getSelectedItem());
|
||||
}
|
||||
});
|
||||
myComboBox.setModel(createModel());
|
||||
myPanel.add(myComboBox, BorderLayout.CENTER);
|
||||
}
|
||||
return myPanel;
|
||||
}
|
||||
panel.add(new JLabel(myLabel), BorderLayout.WEST);
|
||||
panel.add(super.createCustomComponent(presentation), BorderLayout.CENTER);
|
||||
UIUtil.addInsets(panel, JBUI.insets(0, 6, 0, 0));
|
||||
|
||||
protected abstract void selectionChanged(Object selection);
|
||||
|
||||
@NotNull
|
||||
protected abstract ComboBoxModel createModel();
|
||||
|
||||
@NotNull
|
||||
protected JComboBox getComboBox() {
|
||||
return myComboBox;
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
|
||||
+50
-13
@@ -15,12 +15,16 @@
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.committed;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vcs.*;
|
||||
import com.intellij.ui.CollectionComboBoxModel;
|
||||
import com.intellij.util.NotNullFunction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
@@ -32,18 +36,41 @@ public class SelectFilteringAction extends LabeledComboBoxAction {
|
||||
|
||||
@NotNull private final Project myProject;
|
||||
@NotNull private final CommittedChangesTreeBrowser myBrowser;
|
||||
@Nullable private CommittedChangesFilterKey myPreviousSelection;
|
||||
@NotNull private ChangeListFilteringStrategy myPreviousSelection;
|
||||
|
||||
public SelectFilteringAction(@NotNull Project project, @NotNull CommittedChangesTreeBrowser browser) {
|
||||
super(VcsBundle.message("committed.changes.filter.title"));
|
||||
myProject = project;
|
||||
myBrowser = browser;
|
||||
myPreviousSelection = null;
|
||||
myPreviousSelection = ChangeListFilteringStrategy.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
e.getPresentation().setText(myPreviousSelection.toString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected ComboBoxModel createModel() {
|
||||
return new CollectionComboBoxModel<ChangeListFilteringStrategy>(collectStrategies());
|
||||
@Override
|
||||
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
|
||||
return new DefaultActionGroup(ContainerUtil.map(collectStrategies(), new NotNullFunction<ChangeListFilteringStrategy, AnAction>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public AnAction fun(@NotNull ChangeListFilteringStrategy strategy) {
|
||||
return new SetFilteringAction(strategy);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Condition<AnAction> getPreselectCondition() {
|
||||
return new Condition<AnAction>() {
|
||||
@Override
|
||||
public boolean value(@NotNull AnAction action) {
|
||||
return ((SetFilteringAction)action).myStrategy.getKey().equals(myPreviousSelection.getKey());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -74,14 +101,24 @@ public class SelectFilteringAction extends LabeledComboBoxAction {
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void selectionChanged(@NotNull Object selection) {
|
||||
if (myPreviousSelection != null) {
|
||||
myBrowser.removeFilteringStrategy(myPreviousSelection);
|
||||
private class SetFilteringAction extends DumbAwareAction {
|
||||
|
||||
@NotNull private final ChangeListFilteringStrategy myStrategy;
|
||||
|
||||
private SetFilteringAction(@NotNull ChangeListFilteringStrategy strategy) {
|
||||
super(strategy.toString());
|
||||
myStrategy = strategy;
|
||||
}
|
||||
final ChangeListFilteringStrategy strategy = (ChangeListFilteringStrategy)selection;
|
||||
if (!ChangeListFilteringStrategy.NONE.equals(selection)) {
|
||||
myBrowser.setFilteringStrategy(strategy);
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
if (!ChangeListFilteringStrategy.NONE.equals(myPreviousSelection)) {
|
||||
myBrowser.removeFilteringStrategy(myPreviousSelection.getKey());
|
||||
}
|
||||
if (!ChangeListFilteringStrategy.NONE.equals(myStrategy)) {
|
||||
myBrowser.setFilteringStrategy(myStrategy);
|
||||
}
|
||||
myPreviousSelection = myStrategy;
|
||||
}
|
||||
myPreviousSelection = strategy.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
+45
-6
@@ -15,10 +15,15 @@
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.committed;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vcs.*;
|
||||
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
|
||||
import com.intellij.ui.CollectionComboBoxModel;
|
||||
import com.intellij.util.NotNullFunction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -38,16 +43,35 @@ public class SelectGroupingAction extends LabeledComboBoxAction {
|
||||
super(VcsBundle.message("committed.changes.group.title"));
|
||||
myProject = project;
|
||||
myBrowser = browser;
|
||||
getComboBox().setPrototypeDisplayValue("Date+");
|
||||
}
|
||||
|
||||
protected void selectionChanged(@NotNull Object selection) {
|
||||
myBrowser.setGroupingStrategy((ChangeListGroupingStrategy)selection);
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
e.getPresentation().setText(myBrowser.getGroupingStrategy().toString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected ComboBoxModel createModel() {
|
||||
return new CollectionComboBoxModel<ChangeListGroupingStrategy>(collectStrategies());
|
||||
@Override
|
||||
protected DefaultActionGroup createPopupActionGroup(JComponent button) {
|
||||
return new DefaultActionGroup(
|
||||
ContainerUtil.map(collectStrategies(), new NotNullFunction<ChangeListGroupingStrategy, DumbAwareAction>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public DumbAwareAction fun(@NotNull ChangeListGroupingStrategy strategy) {
|
||||
return new SetGroupingAction(strategy);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Condition<AnAction> getPreselectCondition() {
|
||||
return new Condition<AnAction>() {
|
||||
@Override
|
||||
public boolean value(AnAction action) {
|
||||
return ((SetGroupingAction)action).myStrategy.equals(myBrowser.getGroupingStrategy());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -72,6 +96,21 @@ public class SelectGroupingAction extends LabeledComboBoxAction {
|
||||
return result;
|
||||
}
|
||||
|
||||
private class SetGroupingAction extends DumbAwareAction {
|
||||
|
||||
@NotNull private final ChangeListGroupingStrategy myStrategy;
|
||||
|
||||
private SetGroupingAction(@NotNull ChangeListGroupingStrategy strategy) {
|
||||
super(strategy.toString());
|
||||
myStrategy = strategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
myBrowser.setGroupingStrategy(myStrategy);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CustomChangeListColumnGroupingStrategy implements ChangeListGroupingStrategy {
|
||||
|
||||
@NotNull private final ChangeListColumn<CommittedChangeList> myColumn;
|
||||
|
||||
Reference in New Issue
Block a user