Skip to content

Commit

Permalink
Added checking, storing and specialFields
Browse files Browse the repository at this point in the history
  • Loading branch information
calixtus committed Aug 18, 2019
1 parent 51a412d commit 79ff2f6
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ public class TableColumnsItemModel {

private final SimpleObjectProperty<Field> field;
private final SimpleDoubleProperty length;
private final ReadOnlyBooleanProperty editablePropery;
private final ReadOnlyBooleanProperty editableProperty;

public TableColumnsItemModel() {
this.field = new SimpleObjectProperty<>(new UnknownField(Localization.lang("new Column")));
this.length = new SimpleDoubleProperty(ColumnPreferences.DEFAULT_FIELD_LENGTH);
this.editablePropery = new SimpleBooleanProperty(true);
this.editableProperty = new SimpleBooleanProperty(true);
}

public TableColumnsItemModel(Field field) {
this.field = new SimpleObjectProperty<>(field);
this.length = new SimpleDoubleProperty(ColumnPreferences.DEFAULT_FIELD_LENGTH);
this.editablePropery = new SimpleBooleanProperty(this.field.get() instanceof UnknownField);
this.editableProperty = new SimpleBooleanProperty(this.field.get() instanceof UnknownField);
}

public TableColumnsItemModel(Field field, double length) {
this.field = new SimpleObjectProperty<>(field);
this.length = new SimpleDoubleProperty(length);
this.editablePropery = new SimpleBooleanProperty(this.field.get() instanceof UnknownField);
this.editableProperty = new SimpleBooleanProperty(this.field.get() instanceof UnknownField);
}

public Field getField() {
Expand All @@ -47,13 +47,21 @@ public String getName() {
}

public void setName(String name) {
if (editablePropery.get()) {
if (editableProperty.get()) {
field.setValue(new UnknownField(name));
}
}

public ReadOnlyBooleanProperty editablePropery() {
return editablePropery;
public double getLength() {
return length.get();
}

public void setLength(double length) {
this.length.set(length);
}

public ReadOnlyBooleanProperty editableProperty() {
return editableProperty;
}

}
57 changes: 18 additions & 39 deletions src/main/java/org/jabref/gui/preferences/TableColumnsTabView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import javax.inject.Inject;

import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.cell.CheckBoxListCell;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;

import org.jabref.Globals;
import org.jabref.gui.DialogService;
Expand All @@ -29,7 +27,7 @@
import com.airhacks.afterburner.views.ViewLoader;
import org.controlsfx.control.CheckListView;

public class TableColumnsTabView extends VBox implements PrefsTab {
public class TableColumnsTabView extends AbstractPreferenceTabView implements PreferencesTab {

@FXML private CheckListView<TableColumnsItemModel> columnsList;
@FXML private Button sortUp;
Expand Down Expand Up @@ -59,22 +57,25 @@ public class TableColumnsTabView extends VBox implements PrefsTab {
private long lastKeyPressTime;
private String listSearchTerm;

private TableColumnsTabViewModel viewModel;

public TableColumnsTabView(JabRefPreferences preferences, JabRefFrame frame) {
this.preferences = preferences;
this.frame = frame;

ViewLoader.view(this)
.root(this)
.load();
}

@Override
public String getTabName() {
return Localization.lang("Entry table columns");
}

public void initialize() {
viewModel = new TableColumnsTabViewModel(dialogService, preferences, frame);
TableColumnsTabViewModel tableColumnsTabViewModel = new TableColumnsTabViewModel(dialogService, preferences, frame);
this.viewModel = tableColumnsTabViewModel;

columnsList.itemsProperty().bindBidirectional(viewModel.columnsListProperty());
columnsList.itemsProperty().bindBidirectional(tableColumnsTabViewModel.columnsListProperty());
columnsList.setOnKeyTyped(event -> jumpToSearchKey(columnsList, event));
columnsList.setCellFactory(checkBoxListView -> new CheckBoxListCell<TableColumnsItemModel>(columnsList::getItemBooleanProperty) {
@Override
Expand All @@ -100,17 +101,17 @@ public void updateItem(TableColumnsItemModel item, boolean empty) {
}
});

viewModel.checkedColumnsModelProperty().setValue(columnsList.getCheckModel());
tableColumnsTabViewModel.checkedColumnsModelProperty().setValue(columnsList.getCheckModel());

showFileColumn.selectedProperty().bindBidirectional(viewModel.fileFieldProperty());
showUrlColumn.selectedProperty().bindBidirectional(viewModel.urlFieldEnabledProperty());
urlFirst.selectedProperty().bindBidirectional(viewModel.preferUrlProperty());
doiFirst.selectedProperty().bindBidirectional(viewModel.preferDoiProperty());
showEprintColumn.selectedProperty().bindBidirectional(viewModel.eprintFieldProperty());
enableSpecialFields.selectedProperty().bindBidirectional(viewModel.specialFieldsEnabledProperty());
syncKeywords.selectedProperty().bindBidirectional(viewModel.specialFieldsSyncKeyWordsProperty());
serializeSpecial.selectedProperty().bindBidirectional(viewModel.specialFieldsSerializeProperty());
enableExtraColumns.selectedProperty().bindBidirectional(viewModel.extraFieldsEnabledProperty());
showFileColumn.selectedProperty().bindBidirectional(tableColumnsTabViewModel.showFileColumnProperty());
showUrlColumn.selectedProperty().bindBidirectional(tableColumnsTabViewModel.showUrlColumnProperty());
urlFirst.selectedProperty().bindBidirectional(tableColumnsTabViewModel.preferUrlProperty());
doiFirst.selectedProperty().bindBidirectional(tableColumnsTabViewModel.preferDoiProperty());
showEprintColumn.selectedProperty().bindBidirectional(tableColumnsTabViewModel.showEPrintColumnProperty());
enableSpecialFields.selectedProperty().bindBidirectional(tableColumnsTabViewModel.specialFieldsEnabledProperty());
syncKeywords.selectedProperty().bindBidirectional(tableColumnsTabViewModel.specialFieldsSyncKeyWordsProperty());
serializeSpecial.selectedProperty().bindBidirectional(tableColumnsTabViewModel.specialFieldsSerializeProperty());
enableExtraColumns.selectedProperty().bindBidirectional(tableColumnsTabViewModel.showExtraFileColumnsProperty());

ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs());
actionFactory.configureIconButton(PreferencesActions.COLUMN_SORT_UP, new SimpleCommand() {
Expand All @@ -134,9 +135,6 @@ public void updateItem(TableColumnsItemModel item, boolean empty) {
public void execute() { String ab = "a" + "b"; }
}, updateToTable);
actionFactory.configureIconButton(StandardActions.HELP_SPECIAL_FIELDS, new HelpAction(HelpFile.SPECIAL_FIELDS), enableSpecialFieldsHelp);

viewModel.setValues();
viewModel.setChecks();
}

private void jumpToSearchKey(CheckListView<TableColumnsItemModel> list, KeyEvent keypressed) {
Expand All @@ -155,23 +153,4 @@ private void jumpToSearchKey(CheckListView<TableColumnsItemModel> list, KeyEvent
list.getItems().stream().filter(item -> item.getName().toLowerCase().startsWith(listSearchTerm))
.findFirst().ifPresent(list::scrollTo);
}

@Override
public Node getBuilder() {
return this;
}

@Override
public void setValues() { viewModel.setValues(); }

@Override
public void storeSettings() { viewModel.storeSettings(); }

@Override
public boolean validateSettings() { return viewModel.validateSettings(); }

@Override
public String getTabName() {
return Localization.lang("Entry table columns");
}
}
Loading

0 comments on commit 79ff2f6

Please sign in to comment.