diff --git a/CHANGELOG.md b/CHANGELOG.md index bce6d05b888..a5f0e9fc1d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed the wrong behavior that font size changes are not reflected in dialogs. [#6039](https://github.com/JabRef/jabref/issues/6039) - We fixed an issue where the sort order of the entry table was reset after a restart of JabRef. [#6898](https://github.com/JabRef/jabref/pull/6898) - We fixed an issue where no longer a warning was displayed when inserting references into LibreOffice with an invalid "ReferenceParagraphFormat". [#6907](https://github.com/JabRef/jabref/pull/60907). +- We fixed an issue where a remove icon was shown for standard entry types in the custom entry types dialog [6906](https://github.com/JabRef/jabref/issues/6906) ### Removed diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java index 14addc7ea20..d7a034c3225 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeDialogViewModel.java @@ -51,12 +51,12 @@ public Field fromString(String string) { }; private final ObservableList fieldsForAdding = FXCollections.observableArrayList(FieldFactory.getStandardFieldsWithCitationKey()); - private final ObjectProperty selectedEntryType = new SimpleObjectProperty<>(); + private final ObjectProperty selectedEntryType = new SimpleObjectProperty<>(); private final ObjectProperty selectedFieldToAdd = new SimpleObjectProperty<>(); private final StringProperty entryTypeToAdd = new SimpleStringProperty(""); private final ObjectProperty newFieldToAdd = new SimpleObjectProperty<>(); private final BibDatabaseMode mode; - private final ObservableList entryTypesWithFields = FXCollections.observableArrayList(extractor -> new Observable[] {extractor.entryType(), extractor.fields()}); + private final ObservableList entryTypesWithFields = FXCollections.observableArrayList(extractor -> new Observable[] {extractor.entryType(), extractor.fields()}); private final List entryTypesToDelete = new ArrayList<>(); private final PreferencesService preferencesService; @@ -86,12 +86,17 @@ public void addAllTypes() { Collection allTypes = entryTypesManager.getAllTypes(mode); for (BibEntryType entryType : allTypes) { - CustomEntryTypeViewModel viewModel = new CustomEntryTypeViewModel(entryType); + EntryTypeViewModel viewModel; + if (entryTypesManager.isCustomType(entryType.getType(), mode)) { + viewModel = new CustomEntryTypeViewModel(entryType); + } else { + viewModel = new EntryTypeViewModel(entryType); + } this.entryTypesWithFields.add(viewModel); } } - public ObservableList entryTypes() { + public ObservableList entryTypes() { return this.entryTypesWithFields; } @@ -127,17 +132,17 @@ public void addNewField() { newFieldToAddProperty().setValue(null); } - public CustomEntryTypeViewModel addNewCustomEntryType() { + public EntryTypeViewModel addNewCustomEntryType() { EntryType newentryType = new UnknownEntryType(entryTypeToAdd.getValue()); BibEntryType type = new BibEntryType(newentryType, new ArrayList<>(), Collections.emptyList()); - CustomEntryTypeViewModel viewModel = new CustomEntryTypeViewModel(type); + EntryTypeViewModel viewModel = new CustomEntryTypeViewModel(type); this.entryTypesWithFields.add(viewModel); this.entryTypeToAdd.setValue(""); return viewModel; } - public ObjectProperty selectedEntryTypeProperty() { + public ObjectProperty selectedEntryTypeProperty() { return this.selectedEntryType; } @@ -161,7 +166,7 @@ public ValidationStatus fieldValidationStatus() { return fieldValidator.getValidationStatus(); } - public void removeEntryType(CustomEntryTypeViewModel focusedItem) { + public void removeEntryType(EntryTypeViewModel focusedItem) { entryTypesWithFields.remove(focusedItem); entryTypesToDelete.add(focusedItem.entryType().getValue()); } diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeViewModel.java index 4c9de9f9416..e915318e471 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeViewModel.java @@ -1,64 +1,9 @@ package org.jabref.gui.customentrytypes; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; - import org.jabref.model.entry.BibEntryType; -public class CustomEntryTypeViewModel { - - private final ObjectProperty entryType = new SimpleObjectProperty<>(); - private final ObservableList fields; - +public class CustomEntryTypeViewModel extends EntryTypeViewModel { public CustomEntryTypeViewModel(BibEntryType entryType) { - this.entryType.set(entryType); - - List allFieldsForType = entryType.getAllBibFields().stream().map(bibField -> new FieldViewModel(bibField.getField(), entryType.isRequired(bibField.getField()), bibField.getPriority())).collect(Collectors.toList()); - fields = FXCollections.observableArrayList((allFieldsForType)); - } - - @Override - public int hashCode() { - return Objects.hash(entryType, fields); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof CustomEntryTypeViewModel)) { - return false; - } - CustomEntryTypeViewModel other = (CustomEntryTypeViewModel) obj; - return Objects.equals(entryType, other.entryType) && Objects.equals(fields, other.fields); - } - - public void addField(FieldViewModel field) { - this.fields.add(field); - } - - public ObservableList fields() { - return this.fields; - } - - public ObjectProperty entryType() { - return this.entryType; + super(entryType); } - - public void removeField(FieldViewModel focusedItem) { - this.fields.remove(focusedItem); - } - - @Override - public String toString() { - return "CustomEntryTypeViewModel [entryType=" + entryType + ", fields=" + fields + "]"; - } - } diff --git a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java index 38ecf48af78..dfd96432a7c 100644 --- a/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java +++ b/src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java @@ -49,9 +49,9 @@ public class CustomizeEntryTypeDialogView extends BaseDialog { private final BibDatabaseMode mode; private final BibEntryTypesManager entryTypesManager; - @FXML private TableView entryTypes; - @FXML private TableColumn entryTypColumn; - @FXML private TableColumn entryTypeActionsColumn; + @FXML private TableView entryTypes; + @FXML private TableColumn entryTypColumn; + @FXML private TableColumn entryTypeActionsColumn; @FXML private TextField addNewEntryType; @FXML private TableView fields; @FXML private TableColumn fieldNameColumn; @@ -117,10 +117,29 @@ private void setupTable() { entryTypeActionsColumn.setSortable(false); entryTypeActionsColumn.setReorderable(false); entryTypeActionsColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().entryType().get().getType().getDisplayName())); - new ValueTableCellFactory() - .withGraphic(item -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode()) - .withTooltip(name -> Localization.lang("Remove entry type") + " " + name) - .withOnMouseClickedEvent(item -> evt -> viewModel.removeEntryType(entryTypes.getSelectionModel().getSelectedItem())) + new ValueTableCellFactory() + .withGraphic((type, name) -> { + if (type instanceof CustomEntryTypeViewModel) { + return IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode(); + } else { + return null; + } + }) + .withTooltip((type, name) -> { + if (type instanceof CustomEntryTypeViewModel) { + return (Localization.lang("Remove entry type") + " " + name); + } else { + return null; + } + }) + .withOnMouseClickedEvent((type, name) -> { + if (type instanceof CustomEntryTypeViewModel) { + return evt -> viewModel.removeEntryType(entryTypes.getSelectionModel().getSelectedItem()); + } else { + return evt -> { + }; + } + }) .install(entryTypeActionsColumn); fieldTypeColumn.setCellFactory(cellData -> new RadioButtonCell<>(EnumSet.allOf(FieldType.class))); @@ -146,7 +165,9 @@ private void setupTable() { new ValueTableCellFactory() .withGraphic(item -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode()) .withTooltip(name -> Localization.lang("Remove field %0 from currently selected entry type", name)) - .withOnMouseClickedEvent(item -> evt -> viewModel.removeField(fields.getSelectionModel().getSelectedItem())) + .withOnMouseClickedEvent(item -> evt -> { + viewModel.removeField(fields.getSelectionModel().getSelectedItem()); + }) .install(fieldTypeActionColumn); viewModel.newFieldToAddProperty().bindBidirectional(addNewField.valueProperty()); @@ -210,7 +231,7 @@ private void handleOnDragDropped(TableRow row, FieldViewModel or @FXML void addEntryType() { - CustomEntryTypeViewModel newlyAdded = viewModel.addNewCustomEntryType(); + EntryTypeViewModel newlyAdded = viewModel.addNewCustomEntryType(); this.entryTypes.getSelectionModel().select(newlyAdded); this.entryTypes.scrollTo(newlyAdded); } diff --git a/src/main/java/org/jabref/gui/customentrytypes/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/customentrytypes/EntryTypeViewModel.java new file mode 100644 index 00000000000..9b8e4fb7fd6 --- /dev/null +++ b/src/main/java/org/jabref/gui/customentrytypes/EntryTypeViewModel.java @@ -0,0 +1,64 @@ +package org.jabref.gui.customentrytypes; + +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; + +import org.jabref.model.entry.BibEntryType; + +public class EntryTypeViewModel { + + private final ObjectProperty entryType = new SimpleObjectProperty<>(); + private final ObservableList fields; + + public EntryTypeViewModel(BibEntryType entryType) { + this.entryType.set(entryType); + + List allFieldsForType = entryType.getAllBibFields().stream().map(bibField -> new FieldViewModel(bibField.getField(), entryType.isRequired(bibField.getField()), bibField.getPriority())).collect(Collectors.toList()); + fields = FXCollections.observableArrayList((allFieldsForType)); + } + + @Override + public int hashCode() { + return Objects.hash(entryType, fields); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof EntryTypeViewModel)) { + return false; + } + EntryTypeViewModel other = (EntryTypeViewModel) obj; + return Objects.equals(entryType, other.entryType) && Objects.equals(fields, other.fields); + } + + public void addField(FieldViewModel field) { + this.fields.add(field); + } + + public ObservableList fields() { + return this.fields; + } + + public ObjectProperty entryType() { + return this.entryType; + } + + public void removeField(FieldViewModel focusedItem) { + this.fields.remove(focusedItem); + } + + @Override + public String toString() { + return "CustomEntryTypeViewModel [entryType=" + entryType + ", fields=" + fields + "]"; + } + +}