forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix remove actions for entry types in the editor
fixes JabRef#6906 * Created separate view models for standard and custom entry types, adding remove icon only for the custom ones * Updated CHANGELOG.md
- Loading branch information
Showing
6 changed files
with
112 additions
and
73 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
59 changes: 2 additions & 57 deletions
59
src/main/java/org/jabref/gui/customentrytypes/CustomEntryTypeViewModel.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 |
---|---|---|
@@ -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<BibEntryType> entryType = new SimpleObjectProperty<>(); | ||
private final ObservableList<FieldViewModel> fields; | ||
|
||
public class CustomEntryTypeViewModel extends EntryTypeViewModel { | ||
public CustomEntryTypeViewModel(BibEntryType entryType) { | ||
this.entryType.set(entryType); | ||
|
||
List<FieldViewModel> 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<FieldViewModel> fields() { | ||
return this.fields; | ||
} | ||
|
||
public ObjectProperty<BibEntryType> 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 + "]"; | ||
} | ||
|
||
} |
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
64 changes: 64 additions & 0 deletions
64
src/main/java/org/jabref/gui/customentrytypes/EntryTypeViewModel.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,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 abstract class EntryTypeViewModel { | ||
|
||
private final ObjectProperty<BibEntryType> entryType = new SimpleObjectProperty<>(); | ||
private final ObservableList<FieldViewModel> fields; | ||
|
||
protected EntryTypeViewModel(BibEntryType entryType) { | ||
this.entryType.set(entryType); | ||
|
||
List<FieldViewModel> 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<FieldViewModel> fields() { | ||
return this.fields; | ||
} | ||
|
||
public ObjectProperty<BibEntryType> entryType() { | ||
return this.entryType; | ||
} | ||
|
||
public void removeField(FieldViewModel focusedItem) { | ||
this.fields.remove(focusedItem); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CustomEntryTypeViewModel [entryType=" + entryType + ", fields=" + fields + "]"; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/jabref/gui/customentrytypes/StandardEntryTypeViewModel.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,9 @@ | ||
package org.jabref.gui.customentrytypes; | ||
|
||
import org.jabref.model.entry.BibEntryType; | ||
|
||
public class StandardEntryTypeViewModel extends EntryTypeViewModel { | ||
public StandardEntryTypeViewModel(BibEntryType entryType) { | ||
super(entryType); | ||
} | ||
} |