-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conversion of prefs/bibtexkeygen and appearance to mvvm (#5360)
* Initial * Fix special key, refactor visual appearance, l10n * Fixed Indent and wrong value set * Refurbished css * Added BibtexKeyPatternTable, fixed bugs * Fixed bugs in reset, added reset all * Refactored by PR-suggestions, added jumpToPressedKey, highlite default column, set defaultItem to top of list, * l10n * Changelog * Fixed pattern saving, converted default to property * Changed comments * Added help button * Removed fontTweaksLinux according to PR #5330 * l10n * Changed font size limits
- Loading branch information
1 parent
3bad538
commit 2a5507f
Showing
23 changed files
with
820 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternTable.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.TableColumn?> | ||
<?import javafx.scene.control.TableView?> | ||
|
||
<fx:root editable="true" minWidth="280.0" type="TableView" | ||
xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" | ||
fx:controller="org.jabref.gui.bibtexkeypattern.BibtexKeyPatternTableView"> | ||
<columns> | ||
<TableColumn fx:id="entryTypeColumn" editable="false" minWidth="100.0" text="Name"/> | ||
<TableColumn fx:id="patternColumn" minWidth="100.0" text="Key pattern"/> | ||
<TableColumn fx:id="actionsColumn" editable="false" maxWidth="30.0" minWidth="30.0" prefWidth="30.0" | ||
reorderable="false" resizable="false" sortable="false"/> | ||
</columns> | ||
<columnResizePolicy> | ||
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/> | ||
</columnResizePolicy> | ||
</fx:root> |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternTableItemModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.jabref.gui.bibtexkeypattern; | ||
|
||
import java.util.Objects; | ||
|
||
import javafx.beans.property.ObjectProperty; | ||
import javafx.beans.property.SimpleObjectProperty; | ||
import javafx.beans.property.SimpleStringProperty; | ||
import javafx.beans.property.StringProperty; | ||
|
||
import org.jabref.model.entry.types.EntryType; | ||
|
||
public class BibtexKeyPatternTableItemModel { | ||
private final ObjectProperty<EntryType> entryType = new SimpleObjectProperty<>(); | ||
private final StringProperty pattern = new SimpleStringProperty(""); | ||
|
||
public BibtexKeyPatternTableItemModel(EntryType entryType, String pattern) { | ||
Objects.requireNonNull(entryType); | ||
Objects.requireNonNull(pattern); | ||
this.entryType.setValue(entryType); | ||
this.pattern.setValue(pattern); | ||
} | ||
|
||
public EntryType getEntryType() { return entryType.getValue(); } | ||
|
||
public ObjectProperty<EntryType> entryType() { return entryType; } | ||
|
||
public void setPattern(String pattern) { | ||
this.pattern.setValue(pattern); | ||
} | ||
|
||
public String getPattern() { | ||
return pattern.getValue(); | ||
} | ||
|
||
public StringProperty pattern() { return pattern; } | ||
|
||
@Override | ||
public String toString() { return "[" + entryType.getValue().getName() + "," + pattern.getValue() + "]"; } | ||
} |
123 changes: 123 additions & 0 deletions
123
src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternTableView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package org.jabref.gui.bibtexkeypattern; | ||
|
||
import java.util.Collection; | ||
|
||
import javafx.beans.property.ListProperty; | ||
import javafx.beans.property.ObjectProperty; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TableRow; | ||
import javafx.scene.control.TableView; | ||
import javafx.scene.control.cell.TextFieldTableCell; | ||
import javafx.scene.input.KeyEvent; | ||
|
||
import org.jabref.gui.icon.IconTheme; | ||
import org.jabref.gui.util.ValueTableCellFactory; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; | ||
import org.jabref.model.entry.BibEntryType; | ||
import org.jabref.model.entry.types.EntryType; | ||
import org.jabref.preferences.JabRefPreferences; | ||
|
||
import com.airhacks.afterburner.views.ViewLoader; | ||
|
||
public class BibtexKeyPatternTableView extends TableView<BibtexKeyPatternTableItemModel> { | ||
|
||
@FXML public TableColumn<BibtexKeyPatternTableItemModel, EntryType> entryTypeColumn; | ||
@FXML public TableColumn<BibtexKeyPatternTableItemModel, String> patternColumn; | ||
@FXML public TableColumn<BibtexKeyPatternTableItemModel, EntryType> actionsColumn; | ||
|
||
private BibtexKeyPatternTableViewModel viewModel; | ||
|
||
private long lastKeyPressTime; | ||
private String tableSearchTerm; | ||
|
||
public BibtexKeyPatternTableView(JabRefPreferences preferences, Collection<BibEntryType> entryTypeList, AbstractBibtexKeyPattern keyPattern) { | ||
super(); | ||
|
||
viewModel = new BibtexKeyPatternTableViewModel(preferences, entryTypeList, keyPattern); | ||
|
||
ViewLoader.view(this) | ||
.root(this) | ||
.load(); | ||
} | ||
|
||
@FXML | ||
private void initialize() { | ||
this.setEditable(true); | ||
|
||
entryTypeColumn.setSortable(true); | ||
entryTypeColumn.setReorderable(false); | ||
entryTypeColumn.setCellValueFactory(cellData -> cellData.getValue().entryType()); | ||
new ValueTableCellFactory<BibtexKeyPatternTableItemModel, EntryType>() | ||
.withText(EntryType::getDisplayName) | ||
.install(entryTypeColumn); | ||
this.setOnSort(event -> | ||
viewModel.patternListProperty().sort(BibtexKeyPatternTableViewModel.defaultOnTopComparator)); | ||
|
||
patternColumn.setSortable(true); | ||
patternColumn.setReorderable(false); | ||
patternColumn.setCellValueFactory(cellData -> cellData.getValue().pattern()); | ||
patternColumn.setCellFactory(TextFieldTableCell.forTableColumn()); | ||
patternColumn.setEditable(true); | ||
patternColumn.setOnEditCommit( | ||
(TableColumn.CellEditEvent<BibtexKeyPatternTableItemModel, String> event) -> | ||
event.getRowValue().setPattern(event.getNewValue())); | ||
|
||
actionsColumn.setSortable(false); | ||
actionsColumn.setReorderable(false); | ||
actionsColumn.setCellValueFactory(cellData -> cellData.getValue().entryType()); | ||
new ValueTableCellFactory<BibtexKeyPatternTableItemModel, EntryType>() | ||
.withGraphic(entryType -> IconTheme.JabRefIcons.REFRESH.getGraphicNode()) | ||
.withTooltip(entryType -> | ||
String.format(Localization.lang("Reset %s to default value"), entryType.getDisplayName())) | ||
.withOnMouseClickedEvent(item -> evt -> | ||
viewModel.setItemToDefaultPattern(this.getFocusModel().getFocusedItem())) | ||
.install(actionsColumn); | ||
|
||
this.setRowFactory(item -> new HighlightTableRow()); | ||
this.setOnKeyTyped(this::jumpToSearchKey); | ||
this.itemsProperty().bindBidirectional(viewModel.patternListProperty()); | ||
} | ||
|
||
public void setValues() { viewModel.setValues(); } | ||
|
||
public void resetAll() { viewModel.resetAll(); } | ||
|
||
public ListProperty<BibtexKeyPatternTableItemModel> patternListProperty() { return viewModel.patternListProperty(); } | ||
|
||
public ObjectProperty<BibtexKeyPatternTableItemModel> defaultKeyPatternProperty() { return viewModel.defaultKeyPatternProperty(); } | ||
|
||
private void jumpToSearchKey(KeyEvent keypressed) { | ||
if (keypressed.getCharacter() == null) { | ||
return; | ||
} | ||
|
||
if (System.currentTimeMillis() - lastKeyPressTime < 1000) { | ||
tableSearchTerm += keypressed.getCharacter().toLowerCase(); | ||
} else { | ||
tableSearchTerm = keypressed.getCharacter().toLowerCase(); | ||
} | ||
|
||
lastKeyPressTime = System.currentTimeMillis(); | ||
|
||
this.getItems().stream().filter(item -> item.getEntryType().getName().toLowerCase().startsWith(tableSearchTerm)) | ||
.findFirst().ifPresent(this::scrollTo); | ||
} | ||
|
||
private static class HighlightTableRow extends TableRow<BibtexKeyPatternTableItemModel> { | ||
@Override | ||
public void updateItem(BibtexKeyPatternTableItemModel item, boolean empty) { | ||
super.updateItem(item, empty); | ||
if (item == null || item.getEntryType() == null) { | ||
setStyle(""); | ||
} else if (isSelected()) { | ||
setStyle("-fx-background-color: -fx-selection-bar"); | ||
} else if (item.getEntryType().getName().equals(BibtexKeyPatternTableViewModel.ENTRY_TYPE_DEFAULT_NAME)) { | ||
setStyle("-fx-background-color: -fx-default-button"); | ||
} else { | ||
setStyle(""); | ||
} | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternTableViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.jabref.gui.bibtexkeypattern; | ||
|
||
import java.util.Collection; | ||
import java.util.Comparator; | ||
|
||
import javafx.beans.property.ListProperty; | ||
import javafx.beans.property.ObjectProperty; | ||
import javafx.beans.property.SimpleListProperty; | ||
import javafx.beans.property.SimpleObjectProperty; | ||
import javafx.collections.FXCollections; | ||
|
||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; | ||
import org.jabref.model.entry.BibEntryType; | ||
import org.jabref.model.entry.types.EntryType; | ||
import org.jabref.preferences.JabRefPreferences; | ||
|
||
public class BibtexKeyPatternTableViewModel { | ||
|
||
public static final String ENTRY_TYPE_DEFAULT_NAME = "default"; | ||
|
||
public static Comparator<BibtexKeyPatternTableItemModel> defaultOnTopComparator = (o1, o2) -> { | ||
String itemOneName = o1.getEntryType().getName(); | ||
String itemTwoName = o2.getEntryType().getName(); | ||
|
||
if (itemOneName.equals(itemTwoName)) { | ||
return 0; | ||
} else if (itemOneName.equals(ENTRY_TYPE_DEFAULT_NAME)) { | ||
return -1; | ||
} else if (itemTwoName.equals(ENTRY_TYPE_DEFAULT_NAME)) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
}; | ||
|
||
private final ListProperty<BibtexKeyPatternTableItemModel> patternListProperty = new SimpleListProperty<>(); | ||
private final ObjectProperty<BibtexKeyPatternTableItemModel> defaultItemProperty = new SimpleObjectProperty<>(); | ||
private final AbstractBibtexKeyPattern initialKeyPattern; | ||
private final Collection<BibEntryType> bibEntryTypeList; | ||
private final JabRefPreferences preferences; | ||
|
||
public BibtexKeyPatternTableViewModel(JabRefPreferences preferences, Collection<BibEntryType> entryTypeList, AbstractBibtexKeyPattern initialKeyPattern) { | ||
this.preferences = preferences; | ||
this.bibEntryTypeList = entryTypeList; | ||
this.initialKeyPattern = initialKeyPattern; | ||
} | ||
|
||
public void setValues() { | ||
String defaultPattern; | ||
if ((initialKeyPattern.getDefaultValue() == null) || initialKeyPattern.getDefaultValue().isEmpty()) { | ||
defaultPattern = ""; | ||
} else { | ||
defaultPattern = initialKeyPattern.getDefaultValue().get(0); | ||
} | ||
|
||
defaultItemProperty.setValue(new BibtexKeyPatternTableItemModel(new DefaultEntryType(), defaultPattern)); | ||
patternListProperty.setValue(FXCollections.observableArrayList()); | ||
patternListProperty.add(defaultItemProperty.getValue()); | ||
|
||
bibEntryTypeList.stream() | ||
.map(BibEntryType::getType) | ||
.forEach(entryType -> { | ||
String pattern; | ||
if (initialKeyPattern.isDefaultValue(entryType)) { | ||
pattern = ""; | ||
} else { | ||
pattern = initialKeyPattern.getPatterns().get(entryType).get(0); | ||
} | ||
patternListProperty.add(new BibtexKeyPatternTableItemModel(entryType, pattern)); | ||
}); | ||
} | ||
|
||
public void setItemToDefaultPattern(BibtexKeyPatternTableItemModel item) { | ||
item.setPattern((String) preferences.defaults.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN)); | ||
} | ||
|
||
public void resetAll() { | ||
patternListProperty.forEach(item -> item.setPattern("")); | ||
defaultItemProperty.getValue().setPattern((String) preferences.defaults.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN)); | ||
} | ||
|
||
public ListProperty<BibtexKeyPatternTableItemModel> patternListProperty() { return patternListProperty; } | ||
|
||
public ObjectProperty<BibtexKeyPatternTableItemModel> defaultKeyPatternProperty() { return defaultItemProperty; } | ||
|
||
public static class DefaultEntryType implements EntryType { | ||
@Override | ||
public String getName() { return ENTRY_TYPE_DEFAULT_NAME; } | ||
|
||
@Override | ||
public String getDisplayName() { return Localization.lang("Default pattern"); } | ||
} | ||
} |
Oops, something went wrong.