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

Added model.entry.FieldName that contains field name constants #1602

Merged
merged 5 commits into from
Jul 21, 2016
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
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/BibDatabaseContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.database.BibDatabaseModeDetection;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.preferences.JabRefPreferences;

/**
Expand Down Expand Up @@ -177,6 +178,6 @@ private String getFileDirectoryPath(String directoryName) {
}

public List<String> getFileDirectory() {
return getFileDirectory(Globals.FILE_FIELD);
return getFileDirectory(FieldName.FILE);
}
}
2 changes: 0 additions & 2 deletions src/main/java/net/sf/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@

public class Globals {

public static final String FILE_FIELD = "file";
public static final String FOLDER_FIELD = "folder";
public static final String DIR_SUFFIX = "Directory";

// JabRef version info
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/net/sf/jabref/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.sf.jabref.logic.labelpattern.DatabaseLabelPattern;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.sql.DBStrings;

import org.apache.commons.logging.Log;
Expand All @@ -57,7 +58,7 @@ public class MetaData implements Iterable<String> {
private static final String DATABASE_TYPE = "databaseType";

private static final String GROUPSTREE = "groupstree";
private static final String FILE_DIRECTORY = Globals.FILE_FIELD + Globals.DIR_SUFFIX;
private static final String FILE_DIRECTORY = FieldName.FILE + Globals.DIR_SUFFIX;
public static final String SELECTOR_META_PREFIX = "selector_";
private static final String PROTECTED_FLAG_META = "protectedFlag";

Expand Down Expand Up @@ -126,11 +127,11 @@ public Optional<SaveOrderConfig> getSaveOrderConfig() {
* Add default metadata for new database:
*/
public void initializeNewDatabase() {
metaData.put(SELECTOR_META_PREFIX + "keywords", new Vector<>());
metaData.put(SELECTOR_META_PREFIX + "author", new Vector<>());
metaData.put(SELECTOR_META_PREFIX + "journal", new Vector<>());
metaData.put(SELECTOR_META_PREFIX + "publisher", new Vector<>());
metaData.put(SELECTOR_META_PREFIX + "review", new Vector<>());
metaData.put(SELECTOR_META_PREFIX + FieldName.KEYWORDS, new Vector<>());
metaData.put(SELECTOR_META_PREFIX + FieldName.AUTHOR, new Vector<>());
metaData.put(SELECTOR_META_PREFIX + FieldName.JOURNAL, new Vector<>());
metaData.put(SELECTOR_META_PREFIX + FieldName.PUBLISHER, new Vector<>());
metaData.put(SELECTOR_META_PREFIX + FieldName.REVIEW, new Vector<>());
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@
import net.sf.jabref.model.database.EntrySorter;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.BibtexString;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.preferences.JabRefPreferences;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ChangeScanner implements Runnable {

private static final String[] SORT_BY = new String[] {"year", "author", "title"};
private static final String[] SORT_BY = new String[] {FieldName.YEAR, FieldName.AUTHOR, FieldName.TITLE};

private final File f;

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/sf/jabref/external/AttachFileAction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.sf.jabref.external;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.FileListEntry;
import net.sf.jabref.gui.FileListEntryEditor;
Expand All @@ -9,6 +8,7 @@
import net.sf.jabref.gui.undo.UndoableFieldChange;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

/**
* Created by IntelliJ IDEA.
Expand Down Expand Up @@ -39,13 +39,13 @@ public void action() {
editor.setVisible(true, true);
if (editor.okPressed()) {
FileListTableModel model = new FileListTableModel();
entry.getFieldOptional(Globals.FILE_FIELD).ifPresent(model::setContent);
entry.getFieldOptional(FieldName.FILE).ifPresent(model::setContent);
model.addEntry(model.getRowCount(), flEntry);
String newVal = model.getStringRepresentation();

UndoableFieldChange ce = new UndoableFieldChange(entry, Globals.FILE_FIELD,
entry.getFieldOptional(Globals.FILE_FIELD).orElse(null), newVal);
entry.setField(Globals.FILE_FIELD, newVal);
UndoableFieldChange ce = new UndoableFieldChange(entry, FieldName.FILE,
entry.getFieldOptional(FieldName.FILE).orElse(null), newVal);
entry.setField(FieldName.FILE, newVal);
panel.getUndoManager().addEdit(ce);
panel.markBaseChanged();
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/sf/jabref/external/AutoSetLinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.io.FileUtil;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.preferences.JabRefPreferences;

public class AutoSetLinks {
Expand Down Expand Up @@ -111,7 +112,7 @@ public void run() {
// Iterate over the entries:
for (Entry<BibEntry, List<File>> entryFilePair : result.entrySet()) {
FileListTableModel tableModel;
Optional<String> oldVal = entryFilePair.getKey().getFieldOptional(Globals.FILE_FIELD);
Optional<String> oldVal = entryFilePair.getKey().getFieldOptional(FieldName.FILE);
if (singleTableModel == null) {
tableModel = new FileListTableModel();
oldVal.ifPresent(tableModel::setContent);
Expand Down Expand Up @@ -152,12 +153,12 @@ public void run() {
if (ce != null) {
// store undo information
UndoableFieldChange change = new UndoableFieldChange(entryFilePair.getKey(),
Globals.FILE_FIELD, oldVal.orElse(null), newVal);
FieldName.FILE, oldVal.orElse(null), newVal);
ce.addEdit(change);
}
// hack: if table model is given, do NOT modify entry
if (singleTableModel == null) {
entryFilePair.getKey().setField(Globals.FILE_FIELD, newVal);
entryFilePair.getKey().setField(FieldName.FILE, newVal);
}
if (changedEntries != null) {
changedEntries.add(entryFilePair.getKey());
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/sf/jabref/external/DroppedFileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import net.sf.jabref.logic.xmp.XMPUtil;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.model.entry.IdGenerator;

import com.jgoodies.forms.builder.FormBuilder;
Expand Down Expand Up @@ -395,7 +396,7 @@ private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileTy
private void doLink(BibEntry entry, ExternalFileType fileType, String filename,
boolean avoidDuplicate, NamedCompound edits) {

Optional<String> oldValue = entry.getFieldOptional(Globals.FILE_FIELD);
Optional<String> oldValue = entry.getFieldOptional(FieldName.FILE);
FileListTableModel tm = new FileListTableModel();
oldValue.ifPresent(tm::setContent);

Expand Down Expand Up @@ -441,8 +442,8 @@ private void doLink(BibEntry entry, ExternalFileType fileType, String filename,

tm.addEntry(tm.getRowCount(), new FileListEntry("", filename, fileType));
String newValue = tm.getStringRepresentation();
UndoableFieldChange edit = new UndoableFieldChange(entry, Globals.FILE_FIELD, oldValue.orElse(null), newValue);
entry.setField(Globals.FILE_FIELD, newValue);
UndoableFieldChange edit = new UndoableFieldChange(entry, FieldName.FILE, oldValue.orElse(null), newValue);
entry.setField(FieldName.FILE, newValue);

if (edits == null) {
panel.getUndoManager().addEdit(edit);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/sf/jabref/external/FindFullTextAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

import javax.swing.JOptionPane;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.FileListTableModel;
import net.sf.jabref.gui.undo.UndoableFieldChange;
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.logic.fulltext.FindFullText;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -80,12 +80,12 @@ public void update() {
try {
def.download(result.get(), file -> {
FileListTableModel tm = new FileListTableModel();
entry.getFieldOptional(Globals.FILE_FIELD).ifPresent(tm::setContent);
entry.getFieldOptional(FieldName.FILE).ifPresent(tm::setContent);
tm.addEntry(tm.getRowCount(), file);
String newValue = tm.getStringRepresentation();
UndoableFieldChange edit = new UndoableFieldChange(entry, Globals.FILE_FIELD,
entry.getFieldOptional(Globals.FILE_FIELD).orElse(null), newValue);
entry.setField(Globals.FILE_FIELD, newValue);
UndoableFieldChange edit = new UndoableFieldChange(entry, FieldName.FILE,
entry.getFieldOptional(FieldName.FILE).orElse(null), newValue);
entry.setField(FieldName.FILE, newValue);
basePanel.getUndoManager().addEdit(edit);
basePanel.markBaseChanged();
});
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/net/sf/jabref/external/SynchronizeFileField.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.io.FileUtil;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

import com.jgoodies.forms.builder.ButtonBarBuilder;
import com.jgoodies.forms.builder.FormBuilder;
Expand Down Expand Up @@ -144,7 +145,7 @@ public void run() {
boolean removeAllBroken = false;
mainLoop: for (BibEntry aSel : sel) {
panel.frame().setProgressBarValue(progress++);
final Optional<String> old = aSel.getFieldOptional(Globals.FILE_FIELD);
final Optional<String> old = aSel.getFieldOptional(FieldName.FILE);
// Check if a extension is set:
if (old.isPresent() && !(old.get().isEmpty())) {
FileListTableModel tableModel = new FileListTableModel();
Expand Down Expand Up @@ -254,11 +255,11 @@ public void run() {
// The table has been modified. Store the change:
String toSet = tableModel.getStringRepresentation();
if (toSet.isEmpty()) {
ce.addEdit(new UndoableFieldChange(aSel, Globals.FILE_FIELD, old.orElse(null), null));
aSel.clearField(Globals.FILE_FIELD);
ce.addEdit(new UndoableFieldChange(aSel, FieldName.FILE, old.orElse(null), null));
aSel.clearField(FieldName.FILE);
} else {
ce.addEdit(new UndoableFieldChange(aSel, Globals.FILE_FIELD, old.orElse(null), toSet));
aSel.setField(Globals.FILE_FIELD, toSet);
ce.addEdit(new UndoableFieldChange(aSel, FieldName.FILE, old.orElse(null), toSet));
aSel.setField(FieldName.FILE, toSet);
}
changedEntries.add(aSel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.util.ArrayList;
import java.util.List;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.FileListTableModel;
import net.sf.jabref.logic.util.io.FileUtil;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -44,7 +44,7 @@ public class TransferableFileLinkSelection implements Transferable {

public TransferableFileLinkSelection(BasePanel panel, List<BibEntry> selection) {
FileListTableModel tm = new FileListTableModel();
selection.get(0).getFieldOptional(Globals.FILE_FIELD).ifPresent(tm::setContent);
selection.get(0).getFieldOptional(FieldName.FILE).ifPresent(tm::setContent);
if (tm.getRowCount() > 0) {
// Find the default directory for this field type, if any:
List<String> dirs = panel.getBibDatabaseContext().getFileDirectory();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/sf/jabref/external/WriteXMPAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import net.sf.jabref.logic.xmp.XMPUtil;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

import com.jgoodies.forms.builder.ButtonBarBuilder;

Expand Down Expand Up @@ -138,9 +139,9 @@ public void run() {
.ifPresent(files::add));
// Then check the "file" field:
List<String> dirs = panel.getBibDatabaseContext().getFileDirectory();
if (entry.hasField(Globals.FILE_FIELD)) {
if (entry.hasField(FieldName.FILE)) {
FileListTableModel tm = new FileListTableModel();
entry.getFieldOptional(Globals.FILE_FIELD).ifPresent(tm::setContent);
entry.getFieldOptional(FieldName.FILE).ifPresent(tm::setContent);
for (int j = 0; j < tm.getRowCount(); j++) {
FileListEntry flEntry = tm.getEntry(j);
if ((flEntry.type.isPresent()) && "pdf".equalsIgnoreCase(flEntry.type.get().getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import javax.swing.Action;
import javax.xml.transform.TransformerException;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.FileListEntry;
import net.sf.jabref.gui.FileListTableModel;
Expand All @@ -36,6 +35,7 @@
import net.sf.jabref.logic.util.io.FileUtil;
import net.sf.jabref.logic.xmp.XMPUtil;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;

/**
* Write XMP action for EntryEditor toolbar.
Expand Down Expand Up @@ -73,9 +73,9 @@ public void actionPerformed(ActionEvent actionEvent) {

// Then check the "file" field:
List<String> dirs = panel.getBibDatabaseContext().getFileDirectory();
if (entry.hasField(Globals.FILE_FIELD)) {
if (entry.hasField(FieldName.FILE)) {
FileListTableModel tm = new FileListTableModel();
entry.getFieldOptional(Globals.FILE_FIELD).ifPresent(tm::setContent);
entry.getFieldOptional(FieldName.FILE).ifPresent(tm::setContent);
for (int j = 0; j < tm.getRowCount(); j++) {
FileListEntry flEntry = tm.getEntry(j);
if ((flEntry.type.isPresent()) && "pdf".equalsIgnoreCase(flEntry.type.get().getName())) {
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
import net.sf.jabref.model.database.KeyCollisionException;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.EntryType;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.model.entry.IdGenerator;
import net.sf.jabref.model.event.EntryAddedEvent;
import net.sf.jabref.model.event.EntryChangedEvent;
Expand Down Expand Up @@ -1034,13 +1035,13 @@ private void openExternalFile() {
}

final BibEntry entry = bes.get(0);
if (!entry.hasField(Globals.FILE_FIELD)) {
if (!entry.hasField(FieldName.FILE)) {
// no bibtex field
new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen();
return;
}
FileListTableModel tableModel = new FileListTableModel();
entry.getFieldOptional(Globals.FILE_FIELD).ifPresent(tableModel::setContent);
entry.getFieldOptional(FieldName.FILE).ifPresent(tableModel::setContent);
if (tableModel.getRowCount() == 0) {
// content in bibtex field is not readable
new SearchAndOpenFile(entry, BasePanel.this).searchAndOpen();
Expand Down Expand Up @@ -2055,8 +2056,6 @@ public void action() {

private class OpenURLAction implements BaseAction {

private static final String URL_FIELD = "url";
private static final String DOI_FIELD = "doi";
private static final String PS_FIELD = "ps";
private static final String PDF_FIELD = "pdf";

Expand All @@ -2065,11 +2064,11 @@ private class OpenURLAction implements BaseAction {
public void action() {
final List<BibEntry> bes = mainTable.getSelectedEntries();
if (bes.size() == 1) {
String field = DOI_FIELD;
Optional<String> link = bes.get(0).getFieldOptional(DOI_FIELD);
if (bes.get(0).hasField(URL_FIELD)) {
link = bes.get(0).getFieldOptional(URL_FIELD);
field = URL_FIELD;
String field = FieldName.DOI;
Optional<String> link = bes.get(0).getFieldOptional(FieldName.DOI);
if (bes.get(0).hasField(FieldName.URL)) {
link = bes.get(0).getFieldOptional(FieldName.URL);
field = FieldName.URL;
}
if (link.isPresent()) {
try {
Expand All @@ -2083,10 +2082,10 @@ public void action() {
// Look for web links in the "file" field as a fallback:
FileListEntry entry = null;
FileListTableModel tm = new FileListTableModel();
bes.get(0).getFieldOptional(Globals.FILE_FIELD).ifPresent(tm::setContent);
bes.get(0).getFieldOptional(FieldName.FILE).ifPresent(tm::setContent);
for (int i = 0; i < tm.getRowCount(); i++) {
FileListEntry flEntry = tm.getEntry(i);
if (URL_FIELD.equalsIgnoreCase(flEntry.type.get().getName())
if (FieldName.URL.equalsIgnoreCase(flEntry.type.get().getName())
|| PS_FIELD.equalsIgnoreCase(flEntry.type.get().getName())
|| PDF_FIELD.equalsIgnoreCase(flEntry.type.get().getName())) {
entry = flEntry;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/net/sf/jabref/gui/ContentSelectorDialog2.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.sf.jabref.gui.keyboard.KeyBinder;
import net.sf.jabref.gui.util.FocusRequester;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.FieldName;

import com.jgoodies.forms.builder.ButtonBarBuilder;
import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -320,10 +321,10 @@ private void setupFieldSelector() {
}
if (contents.isEmpty()) {
// if nothing was added, put the default fields (as described in the help)
fieldListModel.addElement("author");
fieldListModel.addElement("journal");
fieldListModel.addElement("keywords");
fieldListModel.addElement("publisher");
fieldListModel.addElement(FieldName.AUTHOR);
fieldListModel.addElement(FieldName.JOURNAL);
fieldListModel.addElement(FieldName.KEYWORDS);
fieldListModel.addElement(FieldName.PUBLISHER);
} else {
for (String s : contents) {
fieldListModel.addElement(s);
Expand Down
Loading