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

Create a better solution for define multi line fields #9456

Merged
merged 28 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a0ea6c3
multi line field
Freeman647 Dec 15, 2022
06aa986
Merge remote-tracking branch 'upstream/main' into fix-issue-#6448
Siedlerchr Dec 22, 2022
393ee4f
prepare checkbox table cell
Siedlerchr Dec 22, 2022
129b4f6
Merge remote-tracking branch 'upstream/main' into fix-issue-#6448
Siedlerchr Dec 24, 2022
89490cb
prepare multiline fields
Siedlerchr Dec 24, 2022
a1a62cf
add multiline text to field properties as well
Siedlerchr Dec 24, 2022
e1fb9d3
refactor
Siedlerchr Dec 24, 2022
ab0dfd8
checkstyle and remove obsolete method
Siedlerchr Dec 24, 2022
6d06c01
checkstyle
Siedlerchr Dec 24, 2022
7a3a57f
Merge remote-tracking branch 'upstream/main' into fix-issue-#6448
Siedlerchr Dec 26, 2022
95c28b3
collect multiline
Siedlerchr Dec 27, 2022
176cd2d
Merge remote-tracking branch 'upstream/main' into fix-issue-#6448
Siedlerchr Dec 27, 2022
d3684b3
add predicate for checking non wrappable fields
Siedlerchr Dec 27, 2022
b1e483f
use set of fields
Siedlerchr Dec 27, 2022
128386d
fix gui layout
Siedlerchr Dec 27, 2022
7c9d347
add l10n
Siedlerchr Dec 27, 2022
84050ae
fix checkstyle
Siedlerchr Dec 27, 2022
40d0bc6
fix tab chars
Siedlerchr Dec 27, 2022
8ac3dd5
fix tab
Siedlerchr Dec 28, 2022
a11c30c
add changelog
Siedlerchr Dec 28, 2022
3134cd4
add rotated text
Siedlerchr Dec 29, 2022
fc11417
fix display of vertical label
Siedlerchr Dec 29, 2022
bafbe29
group apparently has no css class
Siedlerchr Dec 29, 2022
1f57853
Merge remote-tracking branch 'upstream/main' into fix-issue-#6448
Siedlerchr Jan 1, 2023
b95cb87
fix exception
Siedlerchr Jan 1, 2023
9da72fb
Changed ui
calixtus Jan 1, 2023
af5ca92
fix l10n
Siedlerchr Jan 1, 2023
59eb0b5
adjust changelog
Siedlerchr Jan 2, 2023
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Added


Copy link
Member

Choose a reason for hiding this comment

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

Duplicate changelog entry

- We added a dropdown menu to let users change the library they want to import into during import. [#6177](https://github.com/JabRef/jabref/issues/6177)
- We added the possibility to add/remove a preview style from the selected list using a double click. [#9490](https://github.com/JabRef/jabref/issues/9490)


- We added the option to define fields as "multine" directly in the custom entry types dialog. [#6448](https://github.com/JabRef/jabref/issues/6448)


### Changed
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1383,3 +1383,7 @@ We want to have a look that matches our icons in the tool-bar */
.rating > .container > .button.strong {
-fx-icon-color: -fx-text-base-color;
}

.table-column .rotated > .label {
-fx-content-display: graphic-only;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand All @@ -25,6 +27,7 @@
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldFactory;
import org.jabref.model.entry.field.FieldPriority;
import org.jabref.model.entry.field.FieldProperty;
import org.jabref.model.entry.field.OrFields;
import org.jabref.model.entry.types.EntryType;
import org.jabref.model.entry.types.UnknownEntryType;
Expand Down Expand Up @@ -64,20 +67,24 @@ public Field fromString(String string) {

private final Validator entryTypeValidator;
private final Validator fieldValidator;
private final Set<Field> multiLineFields = new HashSet<>();

Predicate<Field> isMultiline = (field) -> this.multiLineFields.contains(field) || field.getProperties().contains(FieldProperty.MULTILINE_TEXT);

public CustomEntryTypeDialogViewModel(BibDatabaseMode mode, PreferencesService preferencesService, BibEntryTypesManager entryTypesManager, DialogService dialogService) {
this.mode = mode;
this.preferencesService = preferencesService;
this.entryTypesManager = entryTypesManager;
this.dialogService = dialogService;
this.multiLineFields.addAll(preferencesService.getFieldContentParserPreferences().getNonWrappableFields());

addAllTypes();

Predicate<String> notEmpty = input -> (input != null) && !input.trim().isEmpty();
entryTypeValidator = new FunctionBasedValidator<>(entryTypeToAdd, notEmpty, ValidationMessage.error(Localization.lang("Entry type cannot be empty. Please enter a name.")));
fieldValidator = new FunctionBasedValidator<>(newFieldToAdd,
input -> (input != null) && !input.getDisplayName().isEmpty(),
ValidationMessage.error(Localization.lang("Field cannot be empty. Please enter a name.")));
input -> (input != null) && !input.getDisplayName().isEmpty(),
ValidationMessage.error(Localization.lang("Field cannot be empty. Please enter a name.")));
}

public void addAllTypes() {
Expand All @@ -89,9 +96,9 @@ public void addAllTypes() {
for (BibEntryType entryType : allTypes) {
EntryTypeViewModel viewModel;
if (entryTypesManager.isCustomType(entryType.getType(), mode)) {
viewModel = new CustomEntryTypeViewModel(entryType);
viewModel = new CustomEntryTypeViewModel(entryType, isMultiline);
} else {
viewModel = new EntryTypeViewModel(entryType);
viewModel = new EntryTypeViewModel(entryType, isMultiline);
}
this.entryTypesWithFields.add(viewModel);
}
Expand Down Expand Up @@ -128,7 +135,8 @@ public String toString() {

public void addNewField() {
Field field = newFieldToAdd.getValue();
FieldViewModel model = new FieldViewModel(field, true, FieldPriority.IMPORTANT);
String fieldName = newFieldToAdd.getValue().getName();
FieldViewModel model = new FieldViewModel(field, true, FieldPriority.IMPORTANT, false);
ObservableList<FieldViewModel> entryFields = this.selectedEntryType.getValue().fields();
boolean fieldExists = entryFields.stream().anyMatch(fieldViewModel -> fieldViewModel.fieldName().getValue().equals(field.getDisplayName()));

Expand All @@ -143,7 +151,7 @@ public void addNewField() {
public EntryTypeViewModel addNewCustomEntryType() {
EntryType newentryType = new UnknownEntryType(entryTypeToAdd.getValue());
BibEntryType type = new BibEntryType(newentryType, new ArrayList<>(), Collections.emptyList());
EntryTypeViewModel viewModel = new CustomEntryTypeViewModel(type);
EntryTypeViewModel viewModel = new CustomEntryTypeViewModel(type, isMultiline);
this.entryTypesWithFields.add(viewModel);
this.entryTypeToAdd.setValue("");

Expand Down Expand Up @@ -180,7 +188,7 @@ public void removeEntryType(EntryTypeViewModel focusedItem) {
}

public void removeField(FieldViewModel focusedItem) {
selectedEntryType.getValue().removeField(focusedItem);
selectedEntryType.getValue().removeField(focusedItem);
}

public void resetAllCustomEntryTypes() {
Expand All @@ -191,10 +199,14 @@ public void resetAllCustomEntryTypes() {
}

public void apply() {
for (var typeWithField : entryTypesWithFields) {
Set<Field> multilineFields = new HashSet<>();
for (EntryTypeViewModel typeWithField : entryTypesWithFields) {
BibEntryType type = typeWithField.entryType().getValue();
List<FieldViewModel> allFields = typeWithField.fields();

List<Field> multilineFieldsForType = allFields.stream().map(FieldViewModel::getField).filter(Field::isMultiLineDefined).collect(Collectors.toList());
multilineFields.addAll(multilineFieldsForType);

List<OrFields> requiredFields = allFields.stream().filter(field -> field.getFieldType() == FieldType.REQUIRED).map(FieldViewModel::getField).map(OrFields::new).collect(Collectors.toList());
List<BibField> otherFields = allFields.stream().filter(field -> field.getFieldType() == FieldType.OPTIONAL).map(bibField -> new BibField(bibField.getField(), bibField.getFieldPriority())).collect(Collectors.toList());

Expand All @@ -206,6 +218,7 @@ public void apply() {
entryTypesManager.removeCustomOrModifiedEntryType(entryType, mode);
}

preferencesService.getImportExportPreferences().setNonWrappableFields(multilineFields.stream().map(Field::getDisplayName).collect(Collectors.joining(";")));
preferencesService.storeCustomEntryTypes(entryTypesManager);
// Reload types from preferences to make sure any modifications are present when reopening the dialog
entryTypesManager.addCustomOrModifiedTypes(preferencesService.getBibEntryTypes(BibDatabaseMode.BIBTEX),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.jabref.gui.customentrytypes;

import java.util.function.Predicate;

import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.field.Field;

public class CustomEntryTypeViewModel extends EntryTypeViewModel {
public CustomEntryTypeViewModel(BibEntryType entryType) {
super(entryType);

public CustomEntryTypeViewModel(BibEntryType entryType, Predicate<Field> isMultiline) {
super(entryType, isMultiline);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.ComboBox?>
Expand All @@ -14,87 +13,72 @@
<?import javafx.scene.layout.VBox?>
<?import org.jabref.gui.icon.JabRefIconView?>
<DialogPane prefHeight="596.0" prefWidth="680"
xmlns="http://javafx.com/javafx/8.0.171"
xmlns:fx="http://javafx.com/fxml/1"
xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="org.jabref.gui.customentrytypes.CustomizeEntryTypeDialogView">
<content>
<HBox minHeight="-Infinity" minWidth="-Infinity"
prefHeight="400.0" prefWidth="400.0" spacing="10.0">
<children>
<VBox prefHeight="400.0" prefWidth="100.0" spacing="10.0">
<children>
<Label text="%Entry types"/>
<TableView fx:id="entryTypes" minWidth="-Infinity"
VBox.vgrow="ALWAYS">
<columns>
<TableColumn fx:id="entryTypColumn" minWidth="100.0"
prefWidth="100.0" text="%Entry Type"/>
<TableColumn fx:id="entryTypeActionsColumn"
maxWidth="40.0" minWidth="40.0" resizable="false"/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>
<HBox spacing="10.0">
<children>
<TextField fx:id="addNewEntryType"/>
<Button fx:id="addNewEntryTypeButton" prefHeight="20.0" prefWidth="20.0"
styleClass="icon-button,narrow" onAction="#addEntryType">
<graphic>
<JabRefIconView glyph="ADD_NOBOX"/>
</graphic>
<tooltip>
<Tooltip text="%Add new entry type"/>
</tooltip>
</Button>
</children>
<VBox.margin>
<Insets/>
</VBox.margin>
</HBox>
</children>
</VBox>
<VBox prefHeight="400.0" prefWidth="100.0" spacing="10.0"
HBox.hgrow="ALWAYS">
<children>
<Label text="%Required and optional fields"/>
<TableView fx:id="fields" minWidth="-Infinity"
VBox.vgrow="ALWAYS">
<columns>
<TableColumn fx:id="fieldNameColumn"
minWidth="150.0" prefWidth="-1.0" text="%Field"/>
<TableColumn fx:id="fieldTypeColumn"
minWidth="100.0" prefWidth="100.0" text="%Field type"/>
<TableColumn fx:id="fieldTypeActionColumn"
maxWidth="40.0" minWidth="40.0" resizable="false"/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>
<HBox spacing="10.0">
<children>
<ComboBox fx:id="addNewField" editable="true"
prefWidth="150.0"/>
<Button fx:id="addNewFieldButton" prefHeight="20.0" prefWidth="20.0"
styleClass="icon-button,narrow" onAction="#addNewField">
<graphic>
<JabRefIconView glyph="ADD_NOBOX"/>
</graphic>
<tooltip>
<Tooltip text="%Add new Field"/>
</tooltip>
</Button>
</children>
</HBox>
</children>
</VBox>
</children>
prefHeight="400.0" prefWidth="550.0" spacing="10.0">
<VBox prefHeight="400.0" prefWidth="100.0" spacing="10.0">
<Label text="%Entry types"/>
<TableView fx:id="entryTypesTable" minWidth="-Infinity" VBox.vgrow="ALWAYS">
<columns>
<TableColumn fx:id="entryTypColumn"
minWidth="100.0" prefWidth="100.0" text="%Entry Type"/>
<TableColumn fx:id="entryTypeActionsColumn"
maxWidth="40.0" minWidth="40.0" resizable="false"/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>
<HBox spacing="10.0">
<TextField fx:id="addNewEntryType"/>
<Button fx:id="addNewEntryTypeButton"
prefHeight="20.0" prefWidth="20.0"
styleClass="icon-button,narrow" onAction="#addEntryType">
<graphic>
<JabRefIconView glyph="ADD_NOBOX"/>
</graphic>
<tooltip>
<Tooltip text="%Add new entry type"/>
</tooltip>
</Button>
</HBox>
</VBox>
<VBox prefHeight="400.0" prefWidth="400.0" spacing="10.0" HBox.hgrow="ALWAYS">
<Label text="%Required and optional fields"/>
<TableView fx:id="fields" minWidth="-Infinity" VBox.vgrow="ALWAYS">
<columns>
<TableColumn fx:id="fieldNameColumn"
minWidth="120.0" text="%Field"/>
<TableColumn fx:id="fieldTypeColumn"
minWidth="40.0" maxWidth="40.0"/>
<TableColumn fx:id="fieldTypeMultilineColumn"
maxWidth="40.0" minWidth="40.0" resizable="false"/>
<TableColumn fx:id="fieldTypeActionColumn"
maxWidth="40.0" minWidth="40.0" resizable="false"/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>
<HBox spacing="10.0">
<ComboBox fx:id="addNewField" editable="true" prefWidth="150.0"/>
<Button fx:id="addNewFieldButton"
prefHeight="20.0" prefWidth="20.0"
styleClass="icon-button,narrow" onAction="#addNewField">
<graphic>
<JabRefIconView glyph="ADD_NOBOX"/>
</graphic>
<tooltip>
<Tooltip text="%Add new Field"/>
</tooltip>
</Button>
</HBox>
</VBox>
</HBox>
</content>
<ButtonType fx:id="applyButton" buttonData="OK_DONE"
text="%Apply"/>
<ButtonType fx:id="applyButton" buttonData="OK_DONE" text="%Apply"/>
<ButtonType fx:constant="CANCEL"/>
<ButtonType fx:id="resetButton" buttonData="LEFT" text="%Reset" />
</DialogPane>
Loading