Skip to content

Commit

Permalink
Other fields fix and changes (JabRef#2075)
Browse files Browse the repository at this point in the history
* Other fields changes

* Fix other fields

* Entry editors cache removed
  • Loading branch information
Jürgen Lange authored and zesaro committed Oct 27, 2016
1 parent 522049c commit 99ccad3
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 93 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Fixed [#2060](https://github.com/JabRef/jabref/issues/2060): Medline fetcher now imports data in UTF-8 encoding
- Fixed file menu displays wrong hotkey in the German translation
- Fixed [#2090](https://github.com/JabRef/jabref/issues/#2090): If special fields were not selected, two menu item separator were shown
- Fixed [#2064](https://github.com/JabRef/jabref/issues/2064): Not all `other fields` are shown on entry change of same type

### Removed
- Removed 2nd preview style
- The non-supported feature of being able to define file directories for any extension is removed. Still, it should work for older databases using the legacy `ps` and `pdf` fields, although we strongly encourage using the `file` field.
- Automatic migration for the `evastar_pdf` field is removed.
- We removed the customizable "content selectors" since they are replaced by the auto-completion feature
- Removed optional fields from `other fields` (BibTeX), Removed deprecated fields from `other fields` (BibLaTeX)



Expand Down
66 changes: 11 additions & 55 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ public class BasePanel extends JPanel implements ClipboardOwner, FileUpdateListe
// Variable to prevent erroneous update of back/forward histories at the time
// when a Back or Forward operation is being processed:
private boolean backOrForwardInProgress;
// To indicate which entry is currently shown.
private final Map<String, EntryEditor> entryEditors = new HashMap<>();

// in switching between entries.
private PreambleEditor preambleEditor;
Expand Down Expand Up @@ -1487,10 +1485,6 @@ public void setupMainPanel() {

createMainTable();

for (EntryEditor ee : entryEditors.values()) {
ee.validateAllFields();
}

splitPane.setTopComponent(mainTable.getPane());

// Remove borders
Expand Down Expand Up @@ -1619,25 +1613,13 @@ public void showEntry(final BibEntry be) {
divLoc = splitPane.getDividerLocation();
}

if (entryEditors.containsKey(be.getType())) {
// We already have an editor for this entry type.
entryEditor = entryEditors.get(be.getType());
entryEditor.switchTo(be);
if (visName != null) {
entryEditor.setVisiblePanel(visName);
}
splitPane.setBottomComponent(entryEditor);
} else {
// We must instantiate a new editor for this type.
entryEditor = new EntryEditor(frame, BasePanel.this, be);
if (visName != null) {
entryEditor.setVisiblePanel(visName);
}
splitPane.setBottomComponent(entryEditor);

entryEditors.put(be.getType(), entryEditor);

// We must instantiate a new editor.
entryEditor = new EntryEditor(frame, BasePanel.this, be);
if (visName != null) {
entryEditor.setVisiblePanel(visName);
}
splitPane.setBottomComponent(entryEditor);

if (divLoc > 0) {
splitPane.setDividerLocation(divLoc);
} else {
Expand All @@ -1658,28 +1640,13 @@ public void showEntry(final BibEntry be) {
*/
public EntryEditor getEntryEditor(BibEntry entry) {
EntryEditor entryEditor;
if (entryEditors.containsKey(entry.getType())) {
EntryEditor visibleNow = currentEditor;

// We already have an editor for this entry type.
entryEditor = entryEditors.get(entry.getType());

// If the cached editor is not the same as the currently shown one,
// make sure the current one stores its current edit:
if ((visibleNow != null) && (!(entryEditor.equals(visibleNow)))) {
visibleNow.storeCurrentEdit();
}
// We must instantiate a new editor. First make sure the old one
// stores its last edit:
storeCurrentEdit();
// Then start the new one:
entryEditor = new EntryEditor(frame, BasePanel.this, entry);

entryEditor.switchTo(entry);
} else {
// We must instantiate a new editor for this type. First make sure the old one
// stores its last edit:
storeCurrentEdit();
// Then start the new one:
entryEditor = new EntryEditor(frame, BasePanel.this, entry);

entryEditors.put(entry.getType(), entryEditor);
}
return entryEditor;
}

Expand Down Expand Up @@ -1809,13 +1776,6 @@ public void storeCurrentEdit() {
}
}

public void rebuildAllEntryEditors() {
for (Map.Entry<String, EntryEditor> stringEntryEditorEntry : entryEditors.entrySet()) {
EntryEditor ed = stringEntryEditorEntry.getValue();
ed.rebuildPanels();
}
}

public void markBaseChanged() {
baseChanged = true;

Expand Down Expand Up @@ -2434,10 +2394,6 @@ public MainTable getMainTable() {
return mainTable;
}

public Map<String, EntryEditor> getEntryEditors() {
return entryEditors;
}

public BibDatabaseContext getDatabaseContext() {
return bibDatabaseContext;
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/net/sf/jabref/gui/EntryCustomizationDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,6 @@ public void actionPerformed(ActionEvent e) {
private void updateTypesForEntries(String typeName) {
for (BasePanel bp : frame.getBasePanelList()) {

// Invalidate associated cached entry editor
bp.getEntryEditors().remove(typeName);

for (BibEntry entry : bp.getDatabase().getEntries()) {
EntryTypes.getType(entry.getType(), bibDatabaseMode).ifPresent(entry::setType);
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/sf/jabref/gui/GenFieldsCustomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ private void okActionPerformed() {
Globals.prefs.purgeSeries(JabRefPreferences.CUSTOM_TAB_FIELDS, i);
Globals.prefs.updateEntryEditorTabList();

parentFrame.removeCachedEntryEditors();
dispose();
}

Expand Down
8 changes: 0 additions & 8 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ public void actionPerformed(ActionEvent evt) {

// update all elements in current base panel
JabRefFrame.this.getCurrentBasePanel().hideBottomComponent();
JabRefFrame.this.getCurrentBasePanel().rebuildAllEntryEditors();
JabRefFrame.this.getCurrentBasePanel().updateEntryEditorIfShowing();
}

Expand Down Expand Up @@ -1825,13 +1824,6 @@ public FileHistoryMenu getFileHistory() {
return fileHistory;
}

public void removeCachedEntryEditors() {
for (int j = 0; j < tabbedPane.getTabCount(); j++) {
BasePanel bp = (BasePanel) tabbedPane.getComponentAt(j);
bp.getEntryEditors().clear();
}
}

/**
* This method shows a wait cursor and blocks all input to the JFrame's contents.
*/
Expand Down
29 changes: 18 additions & 11 deletions src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.swing.AbstractAction;
import javax.swing.Action;
Expand Down Expand Up @@ -226,24 +225,28 @@ private void setupFieldPanels() {
tabbed.removeAll();
tabs.clear();

EntryType type = EntryTypes.getTypeOrDefault(entry.getType(), this.frame.getCurrentBasePanel().getBibDatabaseContext().getMode());
EntryType type = EntryTypes.getTypeOrDefault(entry.getType(),
this.frame.getCurrentBasePanel().getBibDatabaseContext().getMode());

// required fields
List<String> requiredFields = addRequiredTab(type);
addRequiredTab(type);

// optional fields
List<String> displayedOptionalFields = new ArrayList<>();
Set<String> deprecatedFields = new HashSet<>(EntryConverter.FIELD_ALIASES_TEX_TO_LTX.keySet());
Set<String> usedOptionalFieldsDeprecated = new HashSet<>(deprecatedFields);

if ((type.getOptionalFields() != null) && !type.getOptionalFields().isEmpty()) {
if (!frame.getCurrentBasePanel().getBibDatabaseContext().isBiblatexMode()) {
displayedOptionalFields.addAll(type.getOptionalFields());

addOptionalTab(type);
} else {
displayedOptionalFields.addAll(type.getPrimaryOptionalFields());
displayedOptionalFields.addAll(type.getSecondaryOptionalFields());

addOptionalTab(type);

Set<String> deprecatedFields = new HashSet<>(EntryConverter.FIELD_ALIASES_TEX_TO_LTX.keySet());
deprecatedFields.add(FieldName.YEAR);
deprecatedFields.add(FieldName.MONTH);
List<String> secondaryOptionalFields = type.getSecondaryOptionalFields();
Expand All @@ -260,7 +263,6 @@ private void setupFieldPanels() {
}

// Get all optional fields which are deprecated
Set<String> usedOptionalFieldsDeprecated = new HashSet<>(deprecatedFields);
usedOptionalFieldsDeprecated.retainAll(optionalFieldsAndAliases);

// Add tabs
Expand All @@ -269,8 +271,8 @@ private void setupFieldPanels() {
if (optPan2.fileListEditor != null) {
fileListEditor = optPan2.fileListEditor;
}
tabbed.addTab(Localization.lang("Optional fields 2"), IconTheme.JabRefIcon.OPTIONAL.getSmallIcon(), optPan2
.getPane(), Localization.lang("Show optional fields"));
tabbed.addTab(Localization.lang("Optional fields 2"), IconTheme.JabRefIcon.OPTIONAL.getSmallIcon(),
optPan2.getPane(), Localization.lang("Show optional fields"));
tabs.add(optPan2);

if (!usedOptionalFieldsDeprecated.isEmpty()) {
Expand All @@ -280,16 +282,21 @@ private void setupFieldPanels() {
if (optPan3.fileListEditor != null) {
fileListEditor = optPan3.fileListEditor;
}
tabbed.addTab(Localization.lang("Deprecated fields"), IconTheme.JabRefIcon.OPTIONAL.getSmallIcon(), optPan3
.getPane(), Localization.lang("Show deprecated BibTeX fields"));
tabbed.addTab(Localization.lang("Deprecated fields"), IconTheme.JabRefIcon.OPTIONAL.getSmallIcon(),
optPan3.getPane(), Localization.lang("Show deprecated BibTeX fields"));
tabs.add(optPan3);
}
}
}

// other fields
List<String> displayedFields = Stream.concat(requiredFields.stream(), displayedOptionalFields.stream()).map(String::toLowerCase).collect(Collectors.toList());
List<String> otherFields = entry.getFieldNames().stream().map(String::toLowerCase).filter(f -> !displayedFields.contains(f)).collect(Collectors.toList());
List<String> displayedFields = type.getAllFields().stream().map(String::toLowerCase)
.collect(Collectors.toList());
List<String> otherFields = entry.getFieldNames().stream().map(String::toLowerCase)
.filter(f -> !displayedFields.contains(f)).collect(Collectors.toList());
if (!usedOptionalFieldsDeprecated.isEmpty()) {
otherFields.removeAll(usedOptionalFieldsDeprecated);
}
otherFields.remove(BibEntry.KEY_FIELD);
otherFields.removeAll(Globals.prefs.getCustomTabFieldNames());

Expand Down
13 changes: 0 additions & 13 deletions src/main/java/net/sf/jabref/gui/preftabs/EntryEditorPrefsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;

import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.keyboard.EmacsKeyBindings;
import net.sf.jabref.logic.autocompleter.AutoCompleteFirstNameMode;
Expand Down Expand Up @@ -250,18 +249,6 @@ else if (autoCompFF.isSelected()) {
} else {
autoCompletePreferences.setFirstnameMode(AutoCompleteFirstNameMode.BOTH);
}

// We need to remove all entry editors from cache if the source panel setting
// or the autocompletion settings have been changed:
if ((oldAutoComplete != autoComplete.isSelected())
|| !oldAutoCompFields.equals(autoCompFields.getText()) ||
(oldAutoCompFF != autoCompFF.isSelected()) || (oldAutoCompLF != autoCompLF.isSelected()) ||
(oldAutoCompFModeAbbr != firstNameModeAbbr.isSelected()) ||
(oldAutoCompFModeFull != firstNameModeFull.isSelected())) {
for (BasePanel panel : frame.getBasePanelList()) {
panel.getEntryEditors().clear();
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ private void updateAfterPreferenceChanges() {
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);

frame.removeCachedEntryEditors();
Globals.prefs.updateEntryEditorTabList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ private void makeChanges(BasePanel panel, ParserResult pr, boolean upgradePrefs,
sb.append(FieldName.FILE);
Globals.prefs.put(JabRefPreferences.CUSTOM_TAB_FIELDS + "0", sb.toString());
Globals.prefs.updateEntryEditorTabList();
panel.frame().removeCachedEntryEditors();
}
panel.frame().setupAllTables();
}
Expand Down

0 comments on commit 99ccad3

Please sign in to comment.