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

Removed one Globals call from MetaData #1782

Merged
merged 1 commit into from
Aug 23, 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
5 changes: 3 additions & 2 deletions src/main/java/net/sf/jabref/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern;
import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern;
import net.sf.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.FieldName;

Expand Down Expand Up @@ -250,12 +251,12 @@ private static Optional<String> getNextUnit(Reader reader) throws IOException {
/**
* @return the stored label patterns
*/
public AbstractBibtexKeyPattern getBibtexKeyPattern() {
public AbstractBibtexKeyPattern getBibtexKeyPattern(GlobalBibtexKeyPattern globalPattern) {
if (bibtexKeyPattern != null) {
return bibtexKeyPattern;
}

bibtexKeyPattern = new DatabaseBibtexKeyPattern(Globals.prefs);
bibtexKeyPattern = new DatabaseBibtexKeyPattern(globalPattern);

// read the data from the metadata and store it into the bibtexKeyPattern
for (String key : this) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/gui/BibtexKeyPatternDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import net.sf.jabref.Globals;
import net.sf.jabref.MetaData;
import net.sf.jabref.gui.bibtexkeypattern.BibtexKeyPatternPanel;
import net.sf.jabref.gui.keyboard.KeyBinder;
Expand Down Expand Up @@ -58,7 +59,7 @@ public BibtexKeyPatternDialog(JabRefFrame parent, BasePanel panel) {
public void setPanel(BasePanel panel) {
this.panel = panel;
this.metaData = panel.getBibDatabaseContext().getMetaData();
AbstractBibtexKeyPattern keypatterns = metaData.getBibtexKeyPattern();
AbstractBibtexKeyPattern keypatterns = metaData.getBibtexKeyPattern(Globals.prefs.getKeyPattern());
bibtexKeyPatternPanel.setValues(keypatterns);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected GlobalBibtexKeyPattern getKeyPatternAsGlobalBibtexKeyPattern() {
}

public DatabaseBibtexKeyPattern getKeyPatternAsDatabaseBibtexKeyPattern() {
DatabaseBibtexKeyPattern res = new DatabaseBibtexKeyPattern(Globals.prefs);
DatabaseBibtexKeyPattern res = new DatabaseBibtexKeyPattern(Globals.prefs.getKeyPattern());
fillPatternUsingPanelData(res);
return res;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.sf.jabref.logic.bibtexkeypattern;

import net.sf.jabref.model.bibtexkeypattern.GlobalBibtexKeyPattern;
import net.sf.jabref.preferences.JabRefPreferences;

public class BibtexKeyPatternPreferences {
Expand All @@ -10,15 +11,18 @@ public class BibtexKeyPatternPreferences {
private final boolean alwaysAddLetter;
private final boolean firstLetterA;
private final boolean enforceLegalKey;
private final GlobalBibtexKeyPattern keyPattern;

public BibtexKeyPatternPreferences(String defaultBibtexKeyPattern, String keyPatternRegex, String keyPatternReplacement,
boolean alwaysAddLetter, boolean firstLetterA, boolean enforceLegalKey) {
boolean alwaysAddLetter, boolean firstLetterA, boolean enforceLegalKey,
GlobalBibtexKeyPattern keyPattern) {
this.defaultBibtexKeyPattern = defaultBibtexKeyPattern;
this.keyPatternRegex = keyPatternRegex;
this.keyPatternReplacement = keyPatternReplacement;
this.alwaysAddLetter = alwaysAddLetter;
this.firstLetterA = firstLetterA;
this.enforceLegalKey = enforceLegalKey;
this.keyPattern = keyPattern;
}

public static BibtexKeyPatternPreferences fromPreferences(JabRefPreferences jabRefPreferences) {
Expand All @@ -27,7 +31,8 @@ public static BibtexKeyPatternPreferences fromPreferences(JabRefPreferences jabR
jabRefPreferences.get(JabRefPreferences.KEY_PATTERN_REPLACEMENT),
jabRefPreferences.getBoolean(JabRefPreferences.KEY_GEN_ALWAYS_ADD_LETTER),
jabRefPreferences.getBoolean(JabRefPreferences.KEY_GEN_FIRST_LETTER_A),
jabRefPreferences.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY));
jabRefPreferences.getBoolean(JabRefPreferences.ENFORCE_LEGAL_BIBTEX_KEY),
jabRefPreferences.getKeyPattern());
}

public String getKeyPatternRegex() {
Expand All @@ -51,4 +56,8 @@ public boolean isEnforceLegalKey() {
}

public String getDefaultBibtexKeyPattern() { return defaultBibtexKeyPattern;}

public GlobalBibtexKeyPattern getKeyPattern() {
return keyPattern;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,8 @@ public static void makeLabel(MetaData metaData, BibDatabase dBase, BibEntry entr
// get the type of entry
String entryType = entry.getType();
// Get the arrayList corresponding to the type
List<String> typeList = new ArrayList<>(metaData.getBibtexKeyPattern().getValue(entryType));
List<String> typeList = new ArrayList<>(
metaData.getBibtexKeyPattern(bibtexKeyPatternPreferences.getKeyPattern()).getValue(entryType));
if (!typeList.isEmpty()) {
typeList.remove(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@

import java.util.List;

import net.sf.jabref.preferences.JabRefPreferences;

public class DatabaseBibtexKeyPattern extends AbstractBibtexKeyPattern {

private final JabRefPreferences prefs;
private final GlobalBibtexKeyPattern globalBibtexKeyPattern;


public DatabaseBibtexKeyPattern(JabRefPreferences prefs) {
this.prefs = prefs;
public DatabaseBibtexKeyPattern(GlobalBibtexKeyPattern globalBibtexKeyPattern) {
this.globalBibtexKeyPattern = globalBibtexKeyPattern;
}

@Override
public List<String> getLastLevelBibtexKeyPattern(String key) {
return prefs.getKeyPattern().getValue(key);
return globalBibtexKeyPattern.getValue(key);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void writeEpilogueAndEncoding() throws Exception {

@Test
public void writeMetadata() throws Exception {
DatabaseBibtexKeyPattern bibtexKeyPattern = new DatabaseBibtexKeyPattern(Globals.prefs);
DatabaseBibtexKeyPattern bibtexKeyPattern = new DatabaseBibtexKeyPattern(Globals.prefs.getKeyPattern());
bibtexKeyPattern.setDefaultValue("test");
metaData.setBibtexKeyPattern(bibtexKeyPattern);

Expand All @@ -172,7 +172,7 @@ public void writeMetadata() throws Exception {
@Test
public void writeMetadataAndEncoding() throws Exception {
SavePreferences preferences = new SavePreferences().withEncoding(Charsets.US_ASCII);
DatabaseBibtexKeyPattern bibtexKeyPattern = new DatabaseBibtexKeyPattern(Globals.prefs);
DatabaseBibtexKeyPattern bibtexKeyPattern = new DatabaseBibtexKeyPattern(Globals.prefs.getKeyPattern());
bibtexKeyPattern.setDefaultValue("test");
metaData.setBibtexKeyPattern(bibtexKeyPattern);

Expand Down Expand Up @@ -429,7 +429,7 @@ public void writeSaveOrderConfig() throws Exception {

@Test
public void writeCustomKeyPattern() throws Exception {
AbstractBibtexKeyPattern pattern = new DatabaseBibtexKeyPattern(Globals.prefs);
AbstractBibtexKeyPattern pattern = new DatabaseBibtexKeyPattern(Globals.prefs.getKeyPattern());
pattern.setDefaultValue("test");
pattern.addBibtexKeyPattern("article", "articleTest");
metaData.setBibtexKeyPattern(pattern);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1512,9 +1512,10 @@ public void integrationTestCustomKeyPattern() throws IOException {
+ "@comment{jabref-meta: keypatterndefault:test;}"),
importFormatPreferences);

AbstractBibtexKeyPattern bibtexKeyPattern = result.getMetaData().getBibtexKeyPattern();
AbstractBibtexKeyPattern bibtexKeyPattern = result.getMetaData()
.getBibtexKeyPattern(Globals.prefs.getKeyPattern());

AbstractBibtexKeyPattern expectedPattern = new DatabaseBibtexKeyPattern(Globals.prefs);
AbstractBibtexKeyPattern expectedPattern = new DatabaseBibtexKeyPattern(Globals.prefs.getKeyPattern());
expectedPattern.setDefaultValue("test");
expectedPattern.addBibtexKeyPattern("article", "articleTest");

Expand Down