From 25e0ee8a7b88b56b012edde1bd34e2e937731df6 Mon Sep 17 00:00:00 2001 From: Sascha Zeller Date: Mon, 21 Nov 2016 23:54:51 +0100 Subject: [PATCH] first attempt to manage metadata --- .../sf/jabref/model/metadata/MetaData.java | 10 ++++++ .../plugin/jabref/util/BibsonomyMetaData.java | 22 ------------ .../plugin/jabref/util/JabRefFileFactory.java | 19 ++++++---- .../jabref/util/JabRefGlobalsHelper.java | 35 ++++++++++--------- .../worker/AbstractBibsonomyWorker.java | 2 +- .../jabref/worker/RefreshTagListWorker.java | 12 ++++--- 6 files changed, 50 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/org/bibsonomy/plugin/jabref/util/BibsonomyMetaData.java diff --git a/src/main/java/net/sf/jabref/model/metadata/MetaData.java b/src/main/java/net/sf/jabref/model/metadata/MetaData.java index 39a4ce048421..f23586cfcfcf 100644 --- a/src/main/java/net/sf/jabref/model/metadata/MetaData.java +++ b/src/main/java/net/sf/jabref/model/metadata/MetaData.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.Vector; import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern; @@ -41,6 +42,7 @@ public class MetaData { private SaveOrderConfig saveOrderConfig; private Map citeKeyPatterns = new HashMap<>(); // private Map userFileDirectory = new HashMap<>(); // + private Map> bibsonomyData = new HashMap<>(); private String defaultCiteKeyPattern; private FieldFormatterCleanups saveActions; private BibDatabaseMode mode; @@ -54,6 +56,14 @@ public MetaData() { // Do nothing } + public void addBibsonomyData(String key, Vector value){ + bibsonomyData.put(key,value); + } + + public Vector getBibsonomyData(String key){ + return bibsonomyData.get(key); + } + public Optional getSaveOrderConfig() { return Optional.ofNullable(saveOrderConfig); } diff --git a/src/main/java/org/bibsonomy/plugin/jabref/util/BibsonomyMetaData.java b/src/main/java/org/bibsonomy/plugin/jabref/util/BibsonomyMetaData.java deleted file mode 100644 index 680541624f1f..000000000000 --- a/src/main/java/org/bibsonomy/plugin/jabref/util/BibsonomyMetaData.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.bibsonomy.plugin.jabref.util; - - -import net.sf.jabref.model.metadata.MetaData; - -public class BibsonomyMetaData { - - private static MetaData metaData; - - private BibsonomyMetaData() { - } - - public static MetaData getMetaData() { - if (BibsonomyMetaData.metaData == null) { - metaData = new MetaData(); - //TODO: Investigate changes in MetaData - zellerdev - //metaData.initializeNewDatabase(); - } - return metaData; - } - -} diff --git a/src/main/java/org/bibsonomy/plugin/jabref/util/JabRefFileFactory.java b/src/main/java/org/bibsonomy/plugin/jabref/util/JabRefFileFactory.java index fe051f980073..0aea22b19aed 100644 --- a/src/main/java/org/bibsonomy/plugin/jabref/util/JabRefFileFactory.java +++ b/src/main/java/org/bibsonomy/plugin/jabref/util/JabRefFileFactory.java @@ -2,18 +2,23 @@ import java.util.Optional; +import net.sf.jabref.gui.JabRefFrame; + import org.bibsonomy.plugin.jabref.BibsonomyGlobals; import org.bibsonomy.rest.client.util.MultiDirectoryFileFactory; public class JabRefFileFactory extends MultiDirectoryFileFactory { - public JabRefFileFactory() { + private final JabRefFrame jabRefFrame; + + public JabRefFileFactory(JabRefFrame jabRefFrame) { super(null, null, null); + this.jabRefFrame = jabRefFrame; } @Override public String getPsDirectory() { - String psFileDir = JabRefGlobalsHelper.getDBSpecificPSDirectory(); + String psFileDir = JabRefGlobalsHelper.getDBSpecificPSDirectory(jabRefFrame); if (psFileDir != null) return psFileDir; return getFileDirectory(); @@ -21,7 +26,7 @@ public String getPsDirectory() { @Override public String getPdfDirectory() { - String pdfFileDir = JabRefGlobalsHelper.getDBSpecificPDFDirectory(); + String pdfFileDir = JabRefGlobalsHelper.getDBSpecificPDFDirectory(jabRefFrame); if (pdfFileDir != null) return pdfFileDir; return getFileDirectory(); @@ -29,14 +34,14 @@ public String getPdfDirectory() { @Override public String getFileDirectory() { - String fileDir = JabRefGlobalsHelper.getDBSpecificUserFileDirIndividual(); + String fileDir = JabRefGlobalsHelper.getDBSpecificUserFileDirIndividual(jabRefFrame); if (fileDir != null) return fileDir; - fileDir = JabRefGlobalsHelper.getDBSpecificUserFileDir(); + fileDir = JabRefGlobalsHelper.getDBSpecificUserFileDir(jabRefFrame); if (fileDir != null) return fileDir; - Optional fileDirectoryOpt = BibsonomyMetaData.getMetaData().getDefaultFileDirectory(); - if (BibsonomyMetaData.getMetaData() != null && fileDirectoryOpt.isPresent()) { + Optional fileDirectoryOpt = jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getDefaultFileDirectory(); + if (jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData() != null && fileDirectoryOpt.isPresent()) { return fileDirectoryOpt.get(); } diff --git a/src/main/java/org/bibsonomy/plugin/jabref/util/JabRefGlobalsHelper.java b/src/main/java/org/bibsonomy/plugin/jabref/util/JabRefGlobalsHelper.java index 7af6a3af40d6..112af8ca6bc0 100644 --- a/src/main/java/org/bibsonomy/plugin/jabref/util/JabRefGlobalsHelper.java +++ b/src/main/java/org/bibsonomy/plugin/jabref/util/JabRefGlobalsHelper.java @@ -1,45 +1,48 @@ package org.bibsonomy.plugin.jabref.util; +import java.util.Vector; + import net.sf.jabref.Globals; +import net.sf.jabref.gui.JabRefFrame; public class JabRefGlobalsHelper { /** * Returns database specific UserFileDir as String if exists, else null */ - public static String getDBSpecificUserFileDir() { - return getMetaDataValue(Globals.prefs.get("userFileDir")); + public static String getDBSpecificUserFileDir(JabRefFrame jabRefFrame) { + return getMetaDataValue(jabRefFrame, Globals.prefs.get("userFileDir")); } /** * Returns database specific UserFileDirIndividual as String if exists, else null */ - public static String getDBSpecificUserFileDirIndividual() { - return getMetaDataValue(Globals.prefs.get("userFileDirIndividual")); + public static String getDBSpecificUserFileDirIndividual(JabRefFrame jabRefFrame) { + return getMetaDataValue(jabRefFrame, Globals.prefs.get("userFileDirIndividual")); } /** * Returns database specific PDFDirectory as String if exists, else null */ - public static String getDBSpecificPDFDirectory() { - return getMetaDataValue("pdfDirectory"); + public static String getDBSpecificPDFDirectory(JabRefFrame jabRefFrame) { + return getMetaDataValue(jabRefFrame, "pdfDirectory"); } /** * Returns database specific PDFDirectory as String if exists, else null */ - public static String getDBSpecificPSDirectory() { - return getMetaDataValue("psDirectory"); + public static String getDBSpecificPSDirectory(JabRefFrame jabRefFrame) { + return getMetaDataValue(jabRefFrame, "psDirectory"); } - private static String getMetaDataValue(String key) { - /* - *TODO: Investigate changes in MetaData - zellerdev - *List fileDI = BibsonomyMetaData.getMetaData().getData(key); - *if (fileDI != null && fileDI.size() >= 1) { - * return fileDI.get(0).trim(); - *} - */ + private static String getMetaDataValue(JabRefFrame jabRefFrame, String key) { + + //TODO: Investigate changes in MetaData - zellerdev + Vector fileDI = jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getBibsonomyData(key); + if (fileDI != null && fileDI.size() >= 1) { + return fileDI.get(0).trim(); + } + return null; } diff --git a/src/main/java/org/bibsonomy/plugin/jabref/worker/AbstractBibsonomyWorker.java b/src/main/java/org/bibsonomy/plugin/jabref/worker/AbstractBibsonomyWorker.java index acde6edcd142..657ef4c84458 100644 --- a/src/main/java/org/bibsonomy/plugin/jabref/worker/AbstractBibsonomyWorker.java +++ b/src/main/java/org/bibsonomy/plugin/jabref/worker/AbstractBibsonomyWorker.java @@ -22,7 +22,7 @@ public abstract class AbstractBibsonomyWorker extends AbstractWorker { public AbstractBibsonomyWorker(JabRefFrame jabRefFrame) { this.jabRefFrame = jabRefFrame; - this.fileFactory = new JabRefFileFactory(); + this.fileFactory = new JabRefFileFactory(jabRefFrame); } public synchronized void stopFetching() { diff --git a/src/main/java/org/bibsonomy/plugin/jabref/worker/RefreshTagListWorker.java b/src/main/java/org/bibsonomy/plugin/jabref/worker/RefreshTagListWorker.java index 54e94bd0a149..d39cd6be25bc 100644 --- a/src/main/java/org/bibsonomy/plugin/jabref/worker/RefreshTagListWorker.java +++ b/src/main/java/org/bibsonomy/plugin/jabref/worker/RefreshTagListWorker.java @@ -2,6 +2,7 @@ import java.util.LinkedList; import java.util.List; +import java.util.Vector; import javax.swing.JEditorPane; @@ -13,7 +14,6 @@ import org.bibsonomy.model.BibTex; import org.bibsonomy.model.Tag; import org.bibsonomy.plugin.jabref.BibsonomyProperties; -import org.bibsonomy.plugin.jabref.util.BibsonomyMetaData; /** @@ -29,8 +29,6 @@ public class RefreshTagListWorker extends AbstractBibsonomyWorker { private String groupingValue; private List tags; - private MetaData metaData = BibsonomyMetaData.getMetaData(); - public RefreshTagListWorker(JabRefFrame jabRefFrame, JEditorPane tagCloud, GroupingEntity grouping, String groupingValue) { super(jabRefFrame); this.tagCloud = tagCloud; @@ -40,10 +38,15 @@ public RefreshTagListWorker(JabRefFrame jabRefFrame, JEditorPane tagCloud, Group } public void run() { - List keywords = null; + MetaData metaData = null; + //Vector keywords = null; + Vector keywords = null; if (jabRefFrame.getCurrentBasePanel() != null) { //TODO: Investigate changes in MetaData - zellerdev //keywords = metaData.getData(MetaData.SELECTOR_META_PREFIX + "keywords"); + metaData = jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData(); + keywords = metaData.getBibsonomyData("keywords"); + } int start = 0, end = BibsonomyProperties.getTagCloudSize(), max = 1, min = 1; @@ -116,6 +119,7 @@ public void run() { if (metaData != null && keywords != null) { //TODO: Investigate changes in MetaData - zellerdev //metaData.putData(MetaData.SELECTOR_META_PREFIX + "keywords", keywords); + jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().addBibsonomyData("keywords", keywords); } jabRefFrame.output(Localization.lang("Done")); }