From 0d4500154cca93b127f04a304704af2446535d61 Mon Sep 17 00:00:00 2001 From: matthiasgeiger Date: Mon, 5 Dec 2016 13:51:49 +0100 Subject: [PATCH] rework to use database mode specific custom types --- .../net/sf/jabref/gui/EntryTypeDialog.java | 31 +++++++++++-------- .../jabref/gui/menus/ChangeEntryTypeMenu.java | 15 ++++++--- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/EntryTypeDialog.java b/src/main/java/net/sf/jabref/gui/EntryTypeDialog.java index 2fb61ef08cb..82eaea8aaf3 100644 --- a/src/main/java/net/sf/jabref/gui/EntryTypeDialog.java +++ b/src/main/java/net/sf/jabref/gui/EntryTypeDialog.java @@ -32,9 +32,9 @@ import net.sf.jabref.logic.importer.FetcherException; import net.sf.jabref.logic.importer.IdBasedFetcher; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.model.EntryTypes; -import net.sf.jabref.model.database.BibDatabaseContext; +import net.sf.jabref.model.database.BibDatabaseMode; import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.model.entry.BibLatexEntryTypes; import net.sf.jabref.model.entry.BibtexEntryTypes; import net.sf.jabref.model.entry.EntryType; import net.sf.jabref.model.entry.IEEETranEntryTypes; @@ -59,10 +59,8 @@ public class EntryTypeDialog extends JDialog implements ActionListener { private JComboBox comboBox; private final JabRefFrame frame; private static final int COLUMN = 3; - private final boolean biblatexMode; private final CancelAction cancelAction = new CancelAction(); - private final BibDatabaseContext bibDatabaseContext; static class TypeButton extends JButton implements Comparable { @@ -90,10 +88,6 @@ public EntryTypeDialog(JabRefFrame frame) { this.frame = frame; - bibDatabaseContext = frame.getCurrentBasePanel().getBibDatabaseContext(); - biblatexMode = bibDatabaseContext.isBiblatexMode(); - - setTitle(Localization.lang("Select entry type")); addWindowListener(new WindowAdapter() { @@ -115,14 +109,25 @@ private JPanel createEntryGroupsPanel() { JPanel panel = new JPanel(); panel.setLayout(new VerticalLayout()); - if (biblatexMode) { - panel.add(createEntryGroupPanel("BibLateX", EntryTypes.getAllValues(bibDatabaseContext.getMode()))); + if (frame.getCurrentBasePanel().getBibDatabaseContext().isBiblatexMode()) { + panel.add(createEntryGroupPanel("BibLateX", BibLatexEntryTypes.ALL)); + + if (CustomEntryTypesManager.CUSTOM_TYPES_BY_MODE_MAP.containsKey(BibDatabaseMode.BIBLATEX) && + !CustomEntryTypesManager.CUSTOM_TYPES_BY_MODE_MAP.get(BibDatabaseMode.BIBLATEX).isEmpty()) { + panel.add(createEntryGroupPanel(Localization.lang("Custom"), CustomEntryTypesManager.CUSTOM_TYPES_BY_MODE_MAP + .get( + BibDatabaseMode.BIBLATEX))); + } + } else { panel.add(createEntryGroupPanel("BibTeX", BibtexEntryTypes.ALL)); panel.add(createEntryGroupPanel("IEEETran", IEEETranEntryTypes.ALL)); - if (!CustomEntryTypesManager.ALL.isEmpty()) { - panel.add(createEntryGroupPanel(Localization.lang("Custom"), CustomEntryTypesManager.ALL)); + if (CustomEntryTypesManager.CUSTOM_TYPES_BY_MODE_MAP.containsKey(BibDatabaseMode.BIBTEX) && + !CustomEntryTypesManager.CUSTOM_TYPES_BY_MODE_MAP.get(BibDatabaseMode.BIBTEX).isEmpty()) { + panel.add(createEntryGroupPanel(Localization.lang("Custom"), CustomEntryTypesManager.CUSTOM_TYPES_BY_MODE_MAP + .get( + BibDatabaseMode.BIBTEX))); } } panel.add(createIdFetcherPanel()); @@ -146,7 +151,7 @@ private JPanel createCancelButtonBarPanel() { return buttons; } - private JPanel createEntryGroupPanel(String groupTitle, Collection entries) { + private JPanel createEntryGroupPanel(String groupTitle, Collection entries) { JPanel panel = new JPanel(); GridBagLayout bagLayout = new GridBagLayout(); panel.setLayout(bagLayout); diff --git a/src/main/java/net/sf/jabref/gui/menus/ChangeEntryTypeMenu.java b/src/main/java/net/sf/jabref/gui/menus/ChangeEntryTypeMenu.java index 73a9106d01c..40483c2b2ef 100644 --- a/src/main/java/net/sf/jabref/gui/menus/ChangeEntryTypeMenu.java +++ b/src/main/java/net/sf/jabref/gui/menus/ChangeEntryTypeMenu.java @@ -57,19 +57,26 @@ private void populateChangeEntryTypeMenu(JMenu menu, BasePanel panel) { for (EntryType type : EntryTypes.getAllValues(BibDatabaseMode.BIBLATEX)) { menu.add(new ChangeTypeAction(type, panel)); } + if (!CustomEntryTypesManager.CUSTOM_TYPES_BY_MODE_MAP.get(BibDatabaseMode.BIBLATEX).isEmpty()) { + menu.addSeparator(); + // custom types + createEntryTypeSection(panel, menu, "Custom Entries", CustomEntryTypesManager.CUSTOM_TYPES_BY_MODE_MAP.get(BibDatabaseMode.BIBTEX)); + } } else { // Bibtex createEntryTypeSection(panel, menu, "BibTeX Entries", BibtexEntryTypes.ALL); menu.addSeparator(); // ieeetran createEntryTypeSection(panel, menu, "IEEETran Entries", IEEETranEntryTypes.ALL); - menu.addSeparator(); - // custom types - createEntryTypeSection(panel, menu, "Custom Entries", CustomEntryTypesManager.ALL); + if (!CustomEntryTypesManager.CUSTOM_TYPES_BY_MODE_MAP.get(BibDatabaseMode.BIBTEX).isEmpty()) { + menu.addSeparator(); + // custom types + createEntryTypeSection(panel, menu, "Custom Entries", CustomEntryTypesManager.CUSTOM_TYPES_BY_MODE_MAP.get(BibDatabaseMode.BIBTEX)); + } } } - private void createEntryTypeSection(BasePanel panel, JMenu menu, String title, java.util.List types) { + private void createEntryTypeSection(BasePanel panel, JMenu menu, String title, java.util.List types) { // bibtex JMenuItem header = new JMenuItem(title); Font font = new Font(menu.getFont().getName(), Font.ITALIC, menu.getFont().getSize());