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

Fix #3411: ordering of fields in customized entry types works again #3422

Merged
merged 1 commit into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -54,16 +54,12 @@ public class EntryCustomizationDialog extends JabRefDialog implements ListSelect

protected GridBagLayout gbl = new GridBagLayout();
protected GridBagConstraints con = new GridBagConstraints();
protected JButton helpButton;
protected JButton delete;
private final JabRefFrame frame;
private FieldSetComponent reqComp;
private FieldSetComponent optComp;
private FieldSetComponent optComp2;
private EntryTypeList typeComp;
private JButton ok;
private JButton cancel;
private JButton apply;
private final List<String> preset = InternalBibtexFields.getAllPublicFieldNames();
private String lastSelected;
private final Map<String, Set<String>> reqLists = new HashMap<>();
Expand Down Expand Up @@ -103,9 +99,7 @@ private void initGui() {
right.setLayout(new GridLayout(biblatexMode ? 2 : 1, 2));

List<String> entryTypes = new ArrayList<>();
for (String s : EntryTypes.getAllTypes(bibDatabaseMode)) {
entryTypes.add(s);
}
entryTypes.addAll(EntryTypes.getAllTypes(bibDatabaseMode));

typeComp = new EntryTypeList(entryTypes, bibDatabaseMode);
typeComp.addListSelectionListener(this);
Expand Down Expand Up @@ -137,9 +131,9 @@ private void initGui() {

//right.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Globals.lang("Fields")));
right.setBorder(BorderFactory.createEtchedBorder());
ok = new JButton(Localization.lang("OK"));
cancel = new JButton(Localization.lang("Cancel"));
apply = new JButton(Localization.lang("Apply"));
JButton ok = new JButton(Localization.lang("OK"));
JButton cancel = new JButton(Localization.lang("Cancel"));
JButton apply = new JButton(Localization.lang("Apply"));
ok.addActionListener(e -> {
applyChanges();
dispose();
Expand Down Expand Up @@ -342,7 +336,7 @@ private void deleteType(String name) {
}
}
EntryTypes.removeType(name, bibDatabaseMode);
updateEntriesForChangedTypes(Arrays.asList(name.toLowerCase(Locale.ENGLISH)));
updateEntriesForChangedTypes(Collections.singletonList(name.toLowerCase(Locale.ENGLISH)));
Copy link
Member

Choose a reason for hiding this comment

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

You are aware that Collections,singletonList is immutable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the hint, I was actually not aware of it. In this case, however, it does not matter since updateEntriesForChangedTypes only invokes contains on the list.

changed.remove(name);
reqLists.remove(name);
optLists.remove(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.awt.event.FocusListener;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
Expand Down Expand Up @@ -220,7 +221,7 @@ public void setEnabled(boolean en) {
* Return the current list.
*/
public Set<String> getFields() {
Set<String> res = new HashSet<>(listModel.getSize());
Set<String> res = new LinkedHashSet<>(listModel.getSize());
Enumeration<String> elements = listModel.elements();
while (elements.hasMoreElements()) {
res.add(elements.nextElement());
Expand Down