Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button-icon for union/intersection in the groups side panel #3954

Merged
merged 10 commits into from
May 6, 2018
32 changes: 24 additions & 8 deletions src/main/java/org/jabref/gui/SidePaneComponent.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.jabref.gui;

import java.util.Collections;
import java.util.List;

import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
Expand All @@ -11,11 +15,12 @@
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.logic.l10n.Localization;

public abstract class SidePaneComponent {

protected final SidePaneManager manager;
protected final ToggleCommand toggleCommand;
private final SidePaneManager manager;
private final ToggleCommand toggleCommand;
private final JabRefIcon icon;
private final String title;
private Node contentNode;
Expand All @@ -25,6 +30,7 @@ public SidePaneComponent(SidePaneManager manager, JabRefIcon icon, String title)
this.icon = icon;
this.title = title;
this.toggleCommand = new ToggleCommand(this);

}

protected void hide() {
Expand All @@ -35,11 +41,11 @@ protected void show() {
manager.show(this.getType());
}

private void moveUp() {
protected void moveUp() {
manager.moveUp(this);
}

private void moveDown() {
protected void moveDown() {
manager.moveDown(this);
}

Expand Down Expand Up @@ -90,28 +96,38 @@ public final Node getContentPane() {
*/
public final Node getHeader() {
Button close = IconTheme.JabRefIcons.CLOSE.asButton();
close.setTooltip(new Tooltip(Localization.lang("Hide panel")));
close.setOnAction(event -> hide());

Button up = IconTheme.JabRefIcons.UP.asButton();
up.setTooltip(new Tooltip(Localization.lang("Move panel up")));
up.setOnAction(event -> moveUp());

Button down = IconTheme.JabRefIcons.DOWN.asButton();
down.setTooltip(new Tooltip(Localization.lang("Move panel down")));
down.setOnAction(event -> moveDown());

HBox buttonContainer = new HBox();
buttonContainer.getChildren().addAll(up, down, close);
final HBox buttonContainer = new HBox();
buttonContainer.getChildren().addAll(up, down);
buttonContainer.getChildren().addAll(getAddtionalHeaderButtons());
buttonContainer.getChildren().add(close);

BorderPane graphic = new BorderPane();
graphic.setCenter(icon.getGraphicNode());
BorderPane container = new BorderPane();
// container.setLeft(graphic);

final Label label = new Label(title);
BorderPane container = new BorderPane();
container.setCenter(label);
container.setRight(buttonContainer);
container.getStyleClass().add("sidePaneComponentHeader");

return container;
}

protected List<Node> getAddtionalHeaderButtons() {
return Collections.emptyList();
}

/**
* Create the content of this component
*
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/SidePaneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public SidePaneManager(JabRefPreferences preferences, JabRefFrame frame) {

OpenOfficePreferences openOfficePreferences = preferences.getOpenOfficePreferences();
Stream.of(
new FileUpdatePanel(this),
new GroupSidePane(this, preferences),
new GeneralFetcher(this, preferences, frame),
new OpenOfficeSidePanel(this, openOfficePreferences, frame))
new FileUpdatePanel(this),
new GroupSidePane(this, preferences, frame.getDialogService()),
new GeneralFetcher(this, preferences, frame),
new OpenOfficeSidePanel(this, openOfficePreferences, frame))
.forEach(pane -> components.put(pane.getType(), pane));

if (preferences.getBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE)) {
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupModeViewModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jabref.gui.groups;

import javafx.scene.Node;
import javafx.scene.control.Tooltip;

import org.jabref.gui.icon.IconTheme.JabRefIcons;
import org.jabref.logic.l10n.Localization;

public class GroupModeViewModel {

public static Tooltip getUnionIntersectionTooltip(GroupViewMode mode) {
if (mode == GroupViewMode.UNION) {
return new Tooltip(Localization.lang("Toogle intersection"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The texts seem to be interchanged by mistake.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's right. As the tooltip should indicate what happens when you press the button,
If you are in union mode currently -> togle intersection
If you are in intersection mode -> toggle union

}
if (mode == GroupViewMode.INTERSECTION) {
return new Tooltip(Localization.lang("Toogle union"));
}
return new Tooltip();

}

public static Node getUnionIntersectionGraphic(GroupViewMode mode) {

if (mode == GroupViewMode.UNION) {
return JabRefIcons.GROUP_UNION.getGraphicNode();
}
if (mode == GroupViewMode.INTERSECTION) {
return JabRefIcons.GROUP_INTERSECTION.getGraphicNode();
}
//as there is no concept like an empty node/icon, we return simply the other icon
return JabRefIcons.GROUP_INTERSECTION.getGraphicNode();

}
}
38 changes: 37 additions & 1 deletion src/main/java/org/jabref/gui/groups/GroupSidePane.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.jabref.gui.groups;

import java.util.Arrays;
import java.util.List;

import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.layout.Priority;

import org.jabref.gui.DialogService;
import org.jabref.gui.SidePaneComponent;
import org.jabref.gui.SidePaneManager;
import org.jabref.gui.SidePaneType;
Expand All @@ -20,15 +25,25 @@
public class GroupSidePane extends SidePaneComponent {

private final JabRefPreferences preferences;
private final DialogService dialogService;
private final Button intersectionUnionToggle = IconTheme.JabRefIcons.GROUP_INTERSECTION.asButton();

public GroupSidePane(SidePaneManager manager, JabRefPreferences preferences) {
public GroupSidePane(SidePaneManager manager, JabRefPreferences preferences, DialogService dialogService) {
super(manager, IconTheme.JabRefIcons.TOGGLE_GROUPS, Localization.lang("Groups"));
this.preferences = preferences;
this.dialogService = dialogService;
}

@Override
protected List<Node> getAddtionalHeaderButtons() {
intersectionUnionToggle.setOnAction(event -> toggleUnionIntersection());
return Arrays.asList(intersectionUnionToggle);
}

@Override
public void afterOpening() {
preferences.putBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE, Boolean.TRUE);
setGraphicsAndTooltipforButton(preferences.getGroupViewMode());
}

@Override
Expand All @@ -46,6 +61,27 @@ public Action getToggleAction() {
return StandardActions.TOGGLE_GROUPS;
}

private void toggleUnionIntersection() {
GroupViewMode mode = preferences.getGroupViewMode();

if (mode == GroupViewMode.UNION) {
preferences.setGroupViewMode(GroupViewMode.INTERSECTION);
dialogService.notify(Localization.lang("Group view mode set to intersection"));
}

if (mode == GroupViewMode.INTERSECTION) {
preferences.setGroupViewMode(GroupViewMode.UNION);

dialogService.notify(Localization.lang("Group view mode set to union"));
}
setGraphicsAndTooltipforButton(mode);
}

private void setGraphicsAndTooltipforButton(GroupViewMode mode) {
intersectionUnionToggle.setGraphic(GroupModeViewModel.getUnionIntersectionGraphic(mode));
intersectionUnionToggle.setTooltip(GroupModeViewModel.getUnionIntersectionTooltip(mode));
}

@Override
protected Node createContentPane() {
return ViewLoader.view(GroupTreeView.class)
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupViewMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jabref.gui.groups;

public enum GroupViewMode {

INTERSECTION,
UNION,

}
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/icon/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ public enum JabRefIcons implements JabRefIcon {
GROUP_INCLUDING(MaterialDesignIcon.FILTER_OUTLINE) /*css: filter-outline*/,
GROUP_REFINING(MaterialDesignIcon.FILTER) /*css: filter*/,
AUTO_GROUP(MaterialDesignIcon.AUTO_FIX), /*css: auto-fix*/
GROUP_INTERSECTION(JabRefMaterialDesignIcon.SET_CENTER),
GROUP_UNION(JabRefMaterialDesignIcon.SET_ALL),
EMAIL(MaterialDesignIcon.EMAIL) /*css: email*/,
EXPORT_TO_CLIPBOARD(MaterialDesignIcon.CLIPBOARD_ARROW_LEFT) /*css: clipboard-arrow-left */,
ATTACH_FILE(MaterialDesignIcon.PAPERCLIP) /*css: paperclip*/,
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/org/jabref/gui/icon/JabRefMaterialDesignIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ public enum JabRefMaterialDesignIcon implements GlyphIcons {
EMACS("\ue902"),
OPEN_OFFICE("\ue903"),
VIM("\ue904"),
LYX("\ue905"),
WINEDT("\ue906"),
ARXIV("\ue907"),
COPY("\ue908"),
PASTE("\ue909");
VIM2("\ue905"),
LYX("\ue906"),
WINEDT("\ue907"),
ARXIV("\ue908"),
COPY("\ue909"),
PASTE("\ue90a"),
SET_CENTER("\ue90b"),
SET_ALL("\ue90c");


private final String unicode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import javafx.collections.transformation.SortedList;

import org.jabref.Globals;
import org.jabref.gui.groups.GroupViewMode;
import org.jabref.gui.util.BindingsHelper;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.groups.GroupTreeNode;
import org.jabref.model.search.matchers.MatcherSet;
import org.jabref.model.search.matchers.MatcherSets;
import org.jabref.preferences.JabRefPreferences;

public class MainTableDataModel {
private final FilteredList<BibEntryTableViewModel> entriesFiltered;
Expand Down Expand Up @@ -60,8 +60,7 @@ private Optional<MatcherSet> createGroupMatcher(List<GroupTreeNode> selectedGrou
return Optional.empty();
}

final MatcherSet searchRules = MatcherSets.build(
Globals.prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS) ? MatcherSets.MatcherType.AND : MatcherSets.MatcherType.OR);
final MatcherSet searchRules = MatcherSets.build(Globals.prefs.getGroupViewMode() == GroupViewMode.INTERSECTION ? MatcherSets.MatcherType.AND : MatcherSets.MatcherType.OR);

for (GroupTreeNode node : selectedGroups) {
searchRules.addRule(node.getSearchMatcher());
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/org/jabref/gui/preftabs/GroupsPrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import org.jabref.gui.groups.GroupViewMode;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;

Expand All @@ -22,8 +23,7 @@ class GroupsPrefsTab extends JPanel implements PrefsTab {

private final JCheckBox hideNonHits = new JCheckBox(Localization.lang("Hide non-hits"));
private final JCheckBox grayOut = new JCheckBox(Localization.lang("Gray out non-hits"));
private final JCheckBox autoAssignGroup = new JCheckBox(
Localization.lang("Automatically assign new entry to selected groups"));
private final JCheckBox autoAssignGroup = new JCheckBox(Localization.lang("Automatically assign new entry to selected groups"));
private final JRadioButton multiSelectionModeIntersection = new JRadioButton(Localization.lang("Intersection"));
private final JRadioButton multiSelectionModeUnion = new JRadioButton(Localization.lang("Union"));

Expand All @@ -32,7 +32,6 @@ class GroupsPrefsTab extends JPanel implements PrefsTab {

private final JabRefPreferences prefs;


public GroupsPrefsTab(JabRefPreferences prefs) {
this.prefs = prefs;

Expand All @@ -59,9 +58,8 @@ public void focusLost(FocusEvent e) {
multiSelectionModeIntersection.setToolTipText(Localization.lang("Display only entries belonging to all selected groups."));
multiSelectionModeUnion.setToolTipText(Localization.lang("Display all entries belonging to one or more of the selected groups."));


FormLayout layout = new FormLayout("9dlu, pref", //500px",
"p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p");
"p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p");
DefaultFormBuilder builder = new DefaultFormBuilder(layout);
builder.appendSeparator(Localization.lang("View"));
builder.nextLine();
Expand Down Expand Up @@ -91,8 +89,7 @@ public void focusLost(FocusEvent e) {
builder.nextLine();
builder.nextColumn();
// build subcomponent
FormLayout layout2 = new FormLayout("left:pref, 2dlu, left:pref",
"p, 3dlu, p");
FormLayout layout2 = new FormLayout("left:pref, 2dlu, left:pref", "p, 3dlu, p");
DefaultFormBuilder builder2 = new DefaultFormBuilder(layout2);
builder2.append(new JLabel(Localization.lang("Default grouping field") + ":"));
builder2.append(groupingField);
Expand All @@ -114,7 +111,14 @@ public void setValues() {
groupingField.setText(prefs.get(JabRefPreferences.GROUPS_DEFAULT_FIELD));
keywordSeparator.setText(prefs.get(JabRefPreferences.KEYWORD_SEPARATOR));
autoAssignGroup.setSelected(prefs.getBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP));
multiSelectionModeIntersection.setSelected(prefs.getBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS));

GroupViewMode mode = prefs.getGroupViewMode();
if (mode == GroupViewMode.INTERSECTION) {
multiSelectionModeIntersection.setSelected(true);
}
if (mode == GroupViewMode.UNION) {
multiSelectionModeUnion.setSelected(true);
}
}

@Override
Expand All @@ -123,7 +127,13 @@ public void storeSettings() {
prefs.put(JabRefPreferences.GROUPS_DEFAULT_FIELD, groupingField.getText().trim());
prefs.putBoolean(JabRefPreferences.AUTO_ASSIGN_GROUP, autoAssignGroup.isSelected());
prefs.put(JabRefPreferences.KEYWORD_SEPARATOR, keywordSeparator.getText());
prefs.putBoolean(JabRefPreferences.GROUP_INTERSECT_SELECTIONS, multiSelectionModeIntersection.isSelected());

if (multiSelectionModeIntersection.isSelected()) {
prefs.setGroupViewMode(GroupViewMode.INTERSECTION);
}
if (multiSelectionModeUnion.isSelected()) {
prefs.setGroupViewMode(GroupViewMode.UNION);
}
}

@Override
Expand Down
Loading