Skip to content

Commit

Permalink
rework to use database mode specific custom types
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgeiger committed Dec 5, 2016
1 parent 1d20cd6 commit 46772ba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
31 changes: 18 additions & 13 deletions src/main/java/net/sf/jabref/gui/EntryTypeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,10 +59,8 @@ public class EntryTypeDialog extends JDialog implements ActionListener {
private JComboBox<String> 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<TypeButton> {

Expand Down Expand Up @@ -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() {
Expand All @@ -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());
Expand All @@ -146,7 +151,7 @@ private JPanel createCancelButtonBarPanel() {
return buttons;
}

private JPanel createEntryGroupPanel(String groupTitle, Collection<EntryType> entries) {
private JPanel createEntryGroupPanel(String groupTitle, Collection<? extends EntryType> entries) {
JPanel panel = new JPanel();
GridBagLayout bagLayout = new GridBagLayout();
panel.setLayout(bagLayout);
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/net/sf/jabref/gui/menus/ChangeEntryTypeMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntryType> types) {
private void createEntryTypeSection(BasePanel panel, JMenu menu, String title, java.util.List<? extends EntryType> types) {
// bibtex
JMenuItem header = new JMenuItem(title);
Font font = new Font(menu.getFont().getName(), Font.ITALIC, menu.getFont().getSize());
Expand Down

0 comments on commit 46772ba

Please sign in to comment.