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,11 @@
package org.jabref.gui;

import java.util.Optional;

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,20 +14,23 @@
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 JabRefIcon icon;
private final String title;
protected final JabRefIcon icon;
Copy link
Member

Choose a reason for hiding this comment

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

make them private again

protected final String title;
private Node contentNode;


public SidePaneComponent(SidePaneManager manager, JabRefIcon icon, String title) {
this.manager = manager;
this.icon = icon;
this.title = title;
this.toggleCommand = new ToggleCommand(this);

Copy link
Member

Choose a reason for hiding this comment

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

remove

}

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);
getAddtionalHeaderButtons().ifPresent(btn -> buttonContainer.getChildren().add(btn));
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 Optional<Node> getAddtionalHeaderButtons() {
Copy link
Member

Choose a reason for hiding this comment

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

Just from the name of the method, I would have expected a list of buttons as the return value and not a single one. I think, supporting multiple buttons make sense and is not a big change overall.

return Optional.empty();
}

/**
* 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 = new OpenOfficePreferences(preferences);
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
53 changes: 52 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.Optional;

import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
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,43 @@
public class GroupSidePane extends SidePaneComponent {

private final JabRefPreferences preferences;
private final DialogService dialogService;
private final Button intersectionUnionToggle = IconTheme.JabRefIcons.WWW.asButton();
private final Tooltip toggleUnion = new Tooltip(Localization.lang("Toogle union"));
Copy link
Member

Choose a reason for hiding this comment

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

I think there is no need to have these tooltips as instance variables. I would simply inline them.

private final Tooltip toggleIntersectoin = new Tooltip(Localization.lang("Toogle intersection"));

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 Optional<Node> getAddtionalHeaderButtons() {
intersectionUnionToggle.setOnAction(event -> toggleUnionIntersection());
return Optional.of(intersectionUnionToggle);
}

private Node getUnionIntersectionGraphic() {
return preferences.getGroupViewMode().getIcon().getGraphicNode();
Copy link
Member

Choose a reason for hiding this comment

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

Personally, I would extract these methods to a new class GroupViewModeViewModel which gives you the graphic and the tooltip (constructor accepts the mode). In this way, you clearly separate everything ui-related from the actual model class.

}

private Tooltip getUnionInterSectionToolTip() {
Copy link
Member

Choose a reason for hiding this comment

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

"Intersection" and "Tooltip"

GroupViewMode mode = preferences.getGroupViewMode();
if (mode == GroupViewMode.UNION) {
return toggleIntersectoin;
}
if (mode == GroupViewMode.INTERSECTION) {
return toggleUnion;
}
return new Tooltip();
}

@Override
public void afterOpening() {
preferences.putBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE, Boolean.TRUE);
intersectionUnionToggle.setGraphic(getUnionIntersectionGraphic());
intersectionUnionToggle.setTooltip(getUnionInterSectionToolTip());
}

@Override
Expand All @@ -46,6 +79,24 @@ 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"));
}

intersectionUnionToggle.setGraphic(getUnionIntersectionGraphic());
intersectionUnionToggle.setTooltip(getUnionInterSectionToolTip());
}

@Override
protected Node createContentPane() {
return ViewLoader.view(GroupTreeView.class)
Expand Down
23 changes: 23 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,23 @@
package org.jabref.gui.groups;

import org.jabref.gui.icon.IconTheme.JabRefIcons;

public enum GroupViewMode {

INTERSECTION(JabRefIcons.GROUP_INTERSECTION),
UNION(JabRefIcons.GROUP_UNION);

private JabRefIcons icon;

GroupViewMode(JabRefIcons icon) {
this.icon = icon;
}

GroupViewMode() {
//empty, but needed for valueOf Method
}

public JabRefIcons getIcon() {
return icon;
}
}
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
14 changes: 12 additions & 2 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.jabref.gui.autocompleter.AutoCompletePreferences;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.entryeditor.EntryEditorTabList;
import org.jabref.gui.groups.GroupViewMode;
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.gui.maintable.ColumnPreferences;
import org.jabref.gui.maintable.MainTablePreferences;
Expand Down Expand Up @@ -193,7 +194,8 @@ public class JabRefPreferences implements PreferencesService {
public static final String EDITOR_EMACS_KEYBINDINGS_REBIND_CA = "editorEMACSkeyBindingsRebindCA";
public static final String EDITOR_EMACS_KEYBINDINGS_REBIND_CF = "editorEMACSkeyBindingsRebindCF";
public static final String GROUPS_DEFAULT_FIELD = "groupsDefaultField";
public static final String GROUP_INTERSECT_SELECTIONS = "groupIntersectSelections";
public static final String GROUP_INTERSECT_UNION_VIEW_MODE = "groupIntersectUnionViewModes";
Copy link
Member

Choose a reason for hiding this comment

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

this can be private now, right?

Copy link
Member

Choose a reason for hiding this comment

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

?


public static final String KEYWORD_SEPARATOR = "groupKeywordSeparator";
public static final String AUTO_ASSIGN_GROUP = "autoAssignGroup";
public static final String LIST_OF_FILE_COLUMNS = "listOfFileColumns";
Expand Down Expand Up @@ -578,9 +580,9 @@ private JabRefPreferences() {
defaults.put(AUTOCOMPLETER_FIRST_LAST, Boolean.FALSE); // "Autocomplete names in 'Firstname Lastname' format only"
defaults.put(AUTOCOMPLETER_LAST_FIRST, Boolean.FALSE); // "Autocomplete names in 'Lastname, Firstname' format only"
defaults.put(AUTOCOMPLETER_COMPLETE_FIELDS, "author;editor;title;journal;publisher;keywords;crossref;related;entryset");
defaults.put(GROUP_INTERSECT_SELECTIONS, Boolean.FALSE);
defaults.put(GROUPS_DEFAULT_FIELD, FieldName.KEYWORDS);
defaults.put(AUTO_ASSIGN_GROUP, Boolean.TRUE);
defaults.put(GROUP_INTERSECT_UNION_VIEW_MODE, GroupViewMode.INTERSECTION.name());
defaults.put(KEYWORD_SEPARATOR, ", ");
defaults.put(TOOLBAR_VISIBLE, Boolean.TRUE);
defaults.put(DEFAULT_ENCODING, StandardCharsets.UTF_8.name());
Expand Down Expand Up @@ -1756,4 +1758,12 @@ public void setWorkingDir(Path dir) {
put(WORKING_DIRECTORY, dir.toString());

}

public GroupViewMode getGroupViewMode() {
return GroupViewMode.valueOf(get(GROUP_INTERSECT_UNION_VIEW_MODE));
}

public void setGroupViewMode(GroupViewMode mode) {
put(GROUP_INTERSECT_UNION_VIEW_MODE, mode.name());
}
}
Binary file modified src/main/resources/fonts/JabRefMaterialDesign.ttf
Binary file not shown.
Loading