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

Conversion of preferences/exportsorting, import, maintable and entryeditor to mvvm #5315

Merged
merged 15 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
"http://www.checkstyle.org/dtds/configuration_1_3.dtd">
Copy link
Member

Choose a reason for hiding this comment

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

Yes, just leave these changes...they are so minimal that they don't justify the overhead of a new PR.


<module name="Checker">
<module name="Header">
Expand Down
2 changes: 1 addition & 1 deletion config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
"http://www.checkstyle.org/dtds/suppressions_1_1.dtd">

<suppressions>
<suppress checks="[a-zA-Z0-9]*" files="[\\/]gen[\\/]" />
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@
requires antlr.runtime;
requires commons.lang3;
requires xmpbox;
requires de.saxsys.mvvmfx.validation;
requires richtextfx;
requires unirest.java;
}
76 changes: 47 additions & 29 deletions src/main/java/org/jabref/gui/SaveOrderConfigDisplay.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,53 @@
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<fx:root prefHeight="200.0" prefWidth="600.0" type="javafx.scene.layout.GridPane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.SaveOrderConfigDisplayView">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="-Infinity" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints prefHeight="30.0" />
<RowConstraints prefHeight="30.0" />
<RowConstraints prefHeight="30.0" />
<RowConstraints prefHeight="30.0" />
<RowConstraints prefHeight="30.0" />
<RowConstraints prefHeight="30.0" />
</rowConstraints>
<?import javafx.scene.layout.VBox?>

<fx:root prefWidth="650.0" spacing="10.0" type="VBox"
xmlns="http://javafx.com/javafx/8.0.212" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="org.jabref.gui.SaveOrderConfigDisplayView">
<fx:define>
<ToggleGroup fx:id="saveOrderToggleGroup" />
<ToggleGroup fx:id="saveOrderToggleGroup"/>
</fx:define>
<children>
<ComboBox fx:id="savePriSort" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<ComboBox fx:id="saveSecSort" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<ComboBox fx:id="saveTerSort" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<RadioButton fx:id="exportInSpecifiedOrder" mnemonicParsing="false" prefHeight="5.0" prefWidth="206.0" text="%Export entries ordered as specified" toggleGroup="$saveOrderToggleGroup" GridPane.columnSpan="3" GridPane.rowIndex="2" />
<RadioButton fx:id="exportInTableOrder" mnemonicParsing="false" text="%Export in current table sort order" toggleGroup="$saveOrderToggleGroup" GridPane.columnSpan="3" GridPane.rowIndex="1" />
<RadioButton fx:id="exportInOriginalOrder" mnemonicParsing="false" text="%Export entries in their original order" toggleGroup="$saveOrderToggleGroup" GridPane.columnSpan="3" />
<CheckBox fx:id="savePriDesc" disable="${!exportInSpecifiedOrder.selected}" mnemonicParsing="false" text="%Descending" GridPane.columnIndex="2" GridPane.rowIndex="3" />
<CheckBox fx:id="saveSecDesc" disable="${!exportInSpecifiedOrder.selected}" mnemonicParsing="false" text="%Descending" GridPane.columnIndex="2" GridPane.rowIndex="4" />
<CheckBox fx:id="saveTerDesc" disable="${!exportInSpecifiedOrder.selected}" mnemonicParsing="false" text="%Descending" GridPane.columnIndex="2" GridPane.rowIndex="5" />
<Label disabled="${!exportInSpecifiedOrder.selected}" text="%Primary sort criterion" GridPane.rowIndex="3" />
<Label disabled="${!exportInSpecifiedOrder.selected}" text="%Secondary sort criterion" GridPane.rowIndex="4" />
<Label disabled="${!exportInSpecifiedOrder.selected}" text="%Tertiary sort criterion" GridPane.rowIndex="5" />
</children>

<RadioButton fx:id="exportInOriginalOrder" text="%Export entries in their original order"
toggleGroup="$saveOrderToggleGroup"/>
<RadioButton fx:id="exportInTableOrder" text="%Export in current table sort order"
toggleGroup="$saveOrderToggleGroup"/>
<RadioButton fx:id="exportInSpecifiedOrder"
text="%Export entries ordered as specified" toggleGroup="$saveOrderToggleGroup"/>

<GridPane alignment="CENTER_LEFT" hgap="10.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="-Infinity" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints prefHeight="30.0"/>
<RowConstraints prefHeight="30.0"/>
<RowConstraints prefHeight="30.0"/>
<RowConstraints prefHeight="30.0"/>
<RowConstraints prefHeight="30.0"/>
<RowConstraints prefHeight="30.0"/>
</rowConstraints>

<Label disable="${!exportInSpecifiedOrder.selected}" text="%Primary sort criterion" GridPane.rowIndex="0"/>
<Label disable="${!exportInSpecifiedOrder.selected}" text="%Secondary sort criterion" GridPane.rowIndex="1"/>
<Label disable="${!exportInSpecifiedOrder.selected}" text="%Tertiary sort criterion" GridPane.rowIndex="2"/>

<ComboBox fx:id="savePriSort" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="0"
disable="${!exportInSpecifiedOrder.selected}"/>
<ComboBox fx:id="saveSecSort" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="1"
disable="${!exportInSpecifiedOrder.selected}"/>
<ComboBox fx:id="saveTerSort" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="2"
disable="${!exportInSpecifiedOrder.selected}"/>

<CheckBox fx:id="savePriDesc" disable="${!exportInSpecifiedOrder.selected}" mnemonicParsing="false"
text="%Descending" GridPane.columnIndex="2" GridPane.rowIndex="0"/>
<CheckBox fx:id="saveSecDesc" disable="${!exportInSpecifiedOrder.selected}" mnemonicParsing="false"
text="%Descending" GridPane.columnIndex="2" GridPane.rowIndex="1"/>
<CheckBox fx:id="saveTerDesc" disable="${!exportInSpecifiedOrder.selected}" mnemonicParsing="false"
text="%Descending" GridPane.columnIndex="2" GridPane.rowIndex="2"/>
</GridPane>
</fx:root>
47 changes: 31 additions & 16 deletions src/main/java/org/jabref/gui/SaveOrderConfigDisplayView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,34 @@
import javafx.scene.control.ComboBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;

import org.jabref.gui.util.FieldsUtil;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.field.Field;
import org.jabref.model.metadata.SaveOrderConfig;
import org.jabref.preferences.PreferencesService;

import com.airhacks.afterburner.views.ViewLoader;

public class SaveOrderConfigDisplayView extends GridPane {

private final SaveOrderConfig config;
public class SaveOrderConfigDisplayView extends VBox {

@FXML private ToggleGroup saveOrderToggleGroup;
@FXML private ComboBox<Field> savePriSort;
@FXML private ComboBox<Field> saveSecSort;
@FXML private ComboBox<Field> saveTerSort;
@FXML private RadioButton exportInSpecifiedOrder;
@FXML private RadioButton exportInTableOrder;
@FXML private RadioButton exportInOriginalOrder;
@FXML private ComboBox<Field> savePriSort;
@FXML private ComboBox<Field> saveSecSort;
@FXML private ComboBox<Field> saveTerSort;
@FXML private CheckBox savePriDesc;
@FXML private CheckBox saveSecDesc;
@FXML private CheckBox saveTerDesc;
@Inject private PreferencesService preferencesService;

private SaveOrderConfigDisplayViewModel viewModel;

public SaveOrderConfigDisplayView(SaveOrderConfig config) {
this.config = config;

public SaveOrderConfigDisplayView() {
ViewLoader.view(this)
.root(this)
.load();
Expand All @@ -45,26 +43,43 @@ public SaveOrderConfigDisplayView(SaveOrderConfig config) {
@FXML
private void initialize() {

viewModel = new SaveOrderConfigDisplayViewModel(config, preferencesService);
viewModel = new SaveOrderConfigDisplayViewModel(preferencesService);

exportInSpecifiedOrder.selectedProperty().bindBidirectional(viewModel.saveInSpecifiedOrderProperty());
exportInTableOrder.selectedProperty().bindBidirectional(viewModel.saveInTableOrderProperty());
exportInOriginalOrder.selectedProperty().bindBidirectional(viewModel.saveInOriginalProperty());
exportInTableOrder.selectedProperty().bindBidirectional(viewModel.saveInTableOrderProperty());
exportInSpecifiedOrder.selectedProperty().bindBidirectional(viewModel.saveInSpecifiedOrderProperty());

new ViewModelListCellFactory<Field>()
.withText(FieldsUtil::getNameWithType)
.install(savePriSort);
savePriSort.itemsProperty().bindBidirectional(viewModel.priSortFieldsProperty());
saveSecSort.itemsProperty().bindBidirectional(viewModel.secSortFieldsProperty());
saveTerSort.itemsProperty().bindBidirectional(viewModel.terSortFieldsProperty());

savePriSort.valueProperty().bindBidirectional(viewModel.savePriSortSelectedValueProperty());
savePriSort.setConverter(FieldsUtil.fieldStringConverter);

new ViewModelListCellFactory<Field>()
.withText(FieldsUtil::getNameWithType)
.install(saveSecSort);
saveSecSort.itemsProperty().bindBidirectional(viewModel.secSortFieldsProperty());
saveSecSort.valueProperty().bindBidirectional(viewModel.saveSecSortSelectedValueProperty());
saveSecSort.setConverter(FieldsUtil.fieldStringConverter);

new ViewModelListCellFactory<Field>()
.withText(FieldsUtil::getNameWithType)
.install(saveTerSort);
saveTerSort.itemsProperty().bindBidirectional(viewModel.terSortFieldsProperty());
saveTerSort.valueProperty().bindBidirectional(viewModel.saveTerSortSelectedValueProperty());
saveTerSort.setConverter(FieldsUtil.fieldStringConverter);

savePriDesc.selectedProperty().bindBidirectional(viewModel.savePriDescPropertySelected());
saveSecDesc.selectedProperty().bindBidirectional(viewModel.saveSecDescPropertySelected());
saveTerDesc.selectedProperty().bindBidirectional(viewModel.saveTerDescPropertySelected());

}

public void setValues(SaveOrderConfig config) {
viewModel.setSaveOrderConfig(config);
}

public void changeExportDescriptionToSave() {
exportInOriginalOrder.setText(Localization.lang("Save entries in their original order"));
exportInSpecifiedOrder.setText(Localization.lang("Save entries ordered as specified"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ public class SaveOrderConfigDisplayViewModel {

private final PreferencesService prefs;

public SaveOrderConfigDisplayViewModel(SaveOrderConfig config, PreferencesService prefs) {
public SaveOrderConfigDisplayViewModel(PreferencesService prefs) {
this.prefs = prefs;

Set<Field> fieldNames = FieldFactory.getCommonFields();
priSortFieldsProperty.addAll(fieldNames);
secSortFieldsProperty.addAll(fieldNames);
terSortFieldsProperty.addAll(fieldNames);

setSaveOrderConfig(config);
}

public ListProperty<Field> priSortFieldsProperty() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/icon/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ public enum JabRefIcons implements JabRefIcon {
PREVIOUS_UP(MaterialDesignIcon.CHEVRON_UP),
NEXT_RIGHT(MaterialDesignIcon.CHEVRON_RIGHT),
NEXT_DOWN(MaterialDesignIcon.CHEVRON_DOWN),
LIST_MOVE_LEFT(MaterialDesignIcon.CHEVRON_LEFT),
LIST_MOVE_UP(MaterialDesignIcon.CHEVRON_UP),
LIST_MOVE_RIGHT(MaterialDesignIcon.CHEVRON_RIGHT),
LIST_MOVE_DOWN(MaterialDesignIcon.CHEVRON_DOWN),
FIT_WIDTH(MaterialDesignIcon.ARROW_EXPAND_ALL),
FIT_SINGLE_PAGE(MaterialDesignIcon.NOTE),
ZOOM_OUT(MaterialDesignIcon.MAGNIFY_MINUS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,9 @@ private void initialize() {
encoding.disableProperty().bind(viewModel.encodingDisableProperty());
protect.disableProperty().bind(viewModel.protectDisableProperty());

saveOrderConfigDisplayView = new SaveOrderConfigDisplayView();
Optional<SaveOrderConfig> storedSaveOrderConfig = panel.getBibDatabaseContext().getMetaData().getSaveOrderConfig();
if (storedSaveOrderConfig.isPresent()) {
saveOrderConfigDisplayView = new SaveOrderConfigDisplayView(storedSaveOrderConfig.get());
oldSaveOrderConfig = storedSaveOrderConfig.get();
} else {
oldSaveOrderConfig = preferencesService.loadExportSaveOrder();
saveOrderConfigDisplayView = new SaveOrderConfigDisplayView(preferencesService.loadExportSaveOrder());
}
oldSaveOrderConfig = storedSaveOrderConfig.orElseGet(preferencesService::loadExportSaveOrder);

saveOrderConfigDisplayView.changeExportDescriptionToSave();
fieldFormatterCleanupsPanel = new FieldFormatterCleanupsPanel(Localization.lang("Enable save actions"),
Expand All @@ -103,6 +98,7 @@ private void initialize() {

private void setValues() {
fieldFormatterCleanupsPanel.setValues(panel.getBibDatabaseContext().getMetaData());
saveOrderConfigDisplayView.setValues(oldSaveOrderConfig);
}

@FXML
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import org.jabref.gui.util.TaskExecutor;
import org.jabref.preferences.JabRefPreferences;

public abstract class AbstractPreferenceTabView extends VBox implements PreferencesTab {
public abstract class AbstractPreferenceTabView<T extends PreferenceTabViewModel> extends VBox implements PreferencesTab {

@Inject protected TaskExecutor taskExecutor;
@Inject protected DialogService dialogService;

protected PreferenceTabViewModel viewModel;
protected T viewModel;

protected JabRefPreferences preferences;

Expand Down
Loading