Skip to content

Commit

Permalink
persist selected hierarchical context in groups preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
aqurilla committed Feb 28, 2023
1 parent 324c0ab commit ef5eb77
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 49 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ public AbstractGroup resultConverter(ButtonType button) {
}

if (resultingGroup != null) {
preferencesService.getGroupsPreferences().setDefaultHierarchicalContext(groupHierarchySelectedProperty.getValue());

resultingGroup.setColor(colorProperty.getValue());
resultingGroup.setDescription(descriptionProperty.getValue());
resultingGroup.setIconName(iconProperty.getValue());
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/org/jabref/gui/preferences/groups/GroupsTab.fxml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<fx:root spacing="10.0" type="VBox"
xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"
Expand All @@ -24,16 +20,4 @@
toggleGroup="$groupViewMode"/>
<CheckBox fx:id="autoAssignGroup" text="%Automatically assign new entry to selected groups"/>
<CheckBox fx:id="displayGroupCount" text="%Display count of items in group"/>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" percentWidth="20.0"/>
<ColumnConstraints hgrow="SOMETIMES"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
</rowConstraints>
<Label text="%Default hierarchical context"/>
<ComboBox fx:id="defaultHierarchicalContext" prefWidth="200.0" GridPane.columnIndex="1"/>
</GridPane>
</fx:root>
10 changes: 0 additions & 10 deletions src/main/java/org/jabref/gui/preferences/groups/GroupsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.RadioButton;

import org.jabref.gui.preferences.AbstractPreferenceTabView;
import org.jabref.gui.preferences.PreferencesTab;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.groups.GroupHierarchyType;

import com.airhacks.afterburner.views.ViewLoader;

Expand All @@ -19,7 +16,6 @@ public class GroupsTab extends AbstractPreferenceTabView<GroupsTabViewModel> imp
@FXML private RadioButton groupViewModeUnion;
@FXML private CheckBox autoAssignGroup;
@FXML private CheckBox displayGroupCount;
@FXML private ComboBox<GroupHierarchyType> defaultHierarchicalContext;

public GroupsTab() {
ViewLoader.view(this)
Expand All @@ -39,11 +35,5 @@ public void initialize() {
groupViewModeUnion.selectedProperty().bindBidirectional(viewModel.groupViewModeUnionProperty());
autoAssignGroup.selectedProperty().bindBidirectional(viewModel.autoAssignGroupProperty());
displayGroupCount.selectedProperty().bindBidirectional(viewModel.displayGroupCount());

new ViewModelListCellFactory<GroupHierarchyType>()
.withText(GroupHierarchyType::getDisplayName)
.install(defaultHierarchicalContext);
defaultHierarchicalContext.itemsProperty().bind(viewModel.hierarchicalContextListProperty());
defaultHierarchicalContext.valueProperty().bindBidirectional(viewModel.selectedHierarchicalContextProperty());
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
package org.jabref.gui.preferences.groups;

import java.util.Comparator;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.transformation.SortedList;

import org.jabref.gui.groups.GroupViewMode;
import org.jabref.gui.groups.GroupsPreferences;
import org.jabref.gui.preferences.PreferenceTabViewModel;
import org.jabref.model.groups.GroupHierarchyType;

public class GroupsTabViewModel implements PreferenceTabViewModel {

private final BooleanProperty groupViewModeIntersectionProperty = new SimpleBooleanProperty();
private final BooleanProperty groupViewModeUnionProperty = new SimpleBooleanProperty();
private final BooleanProperty autoAssignGroupProperty = new SimpleBooleanProperty();
private final BooleanProperty displayGroupCountProperty = new SimpleBooleanProperty();
private final ListProperty<GroupHierarchyType> hierarchicalContextListProperty = new SimpleListProperty<>();
private final ObjectProperty<GroupHierarchyType> selectedHierarchicalContextProperty = new SimpleObjectProperty<>();

private final GroupsPreferences groupsPreferences;

Expand All @@ -45,17 +34,13 @@ public void setValues() {
}
autoAssignGroupProperty.setValue(groupsPreferences.shouldAutoAssignGroup());
displayGroupCountProperty.setValue(groupsPreferences.shouldDisplayGroupCount());
hierarchicalContextListProperty.setValue(
new SortedList<>(FXCollections.observableArrayList(GroupHierarchyType.values()), Comparator.comparing(GroupHierarchyType::getDisplayName)));
selectedHierarchicalContextProperty.setValue(groupsPreferences.getDefaultHierarchicalContext());
}

@Override
public void storeSettings() {
groupsPreferences.setGroupViewMode(groupViewModeIntersectionProperty.getValue() ? GroupViewMode.INTERSECTION : GroupViewMode.UNION);
groupsPreferences.setAutoAssignGroup(autoAssignGroupProperty.getValue());
groupsPreferences.setDisplayGroupCount(displayGroupCountProperty.getValue());
groupsPreferences.setDefaultHierarchicalContext(selectedHierarchicalContextProperty.getValue());
}

public BooleanProperty groupViewModeIntersectionProperty() {
Expand All @@ -73,12 +58,4 @@ public BooleanProperty autoAssignGroupProperty() {
public BooleanProperty displayGroupCount() {
return displayGroupCountProperty;
}

public ListProperty<GroupHierarchyType> hierarchicalContextListProperty() {
return hierarchicalContextListProperty;
}

public ObjectProperty<GroupHierarchyType> selectedHierarchicalContextProperty() {
return selectedHierarchicalContextProperty;
}
}

0 comments on commit ef5eb77

Please sign in to comment.