@Test public void writeEntryWithCustomizedTypeAlsoWritesTypeDeclaration() throws Exception { try { EntryTypes.addOrModifyCustomEntryType( new CustomEntryType("customizedType", "required", "optional"), BibDatabaseMode.BIBTEX); BibEntry entry = new BibEntry(); entry.setType("customizedType"); database.insertEntry(entry); StringSaveSession session = databaseWriter.savePartOfDatabase( bibtexContext, Collections.singletonList(entry), new SavePreferences()); assertEquals( OS.NEWLINE + "@Customizedtype{," + OS.NEWLINE + "}" + OS.NEWLINE + OS.NEWLINE + "@Comment{jabref-meta: databaseType:bibtex;}" + OS.NEWLINE + OS.NEWLINE + "@Comment{jabref-entrytype: Customizedtype: req[required] opt[optional]}" + OS.NEWLINE, session.getStringValue()); } finally { EntryTypes.removeAllCustomEntryTypes(); } }
private static void saveCustomEntryTypes(JabRefPreferences prefs, BibDatabaseMode mode) { List<CustomEntryType> customBiblatexTypes = EntryTypes.getAllValues(mode) .stream() .filter(type -> type instanceof CustomEntryType) .map(entryType -> (CustomEntryType) entryType) .collect(Collectors.toList()); prefs.storeCustomEntryTypes(customBiblatexTypes, mode); }
/** * Will check if the current library uses any entry types from another mode. For example it will * warn the user if he uses entry types defined for Biblatex inside a BibTeX library. */ @Override public List<IntegrityMessage> check(BibEntry entry) { if (EntryTypes.isExclusiveBibLatex(entry.getType())) { return Collections.singletonList( new IntegrityMessage( Localization.lang( "Entry type %0 is only defined for Biblatex but not for BibTeX", entry.getType()), entry, "bibtexkey")); } return Collections.emptyList(); }
private void buildGUI() { JPanel pan = new JPanel(); JScrollPane sp = new JScrollPane(pan); sp.setPreferredSize(new Dimension(100, 100)); sp.setBorder(BorderFactory.createEmptyBorder()); pan.setLayout(gbl); setLayout(gbl); // The header - can be removed JLabel lblEntryType = new JLabel(Localization.lang("Entry type")); Font f = new Font("plain", Font.BOLD, 12); lblEntryType.setFont(f); con.gridx = 0; con.gridy = 0; con.gridwidth = 1; con.gridheight = 1; con.fill = GridBagConstraints.VERTICAL; con.anchor = GridBagConstraints.WEST; con.insets = new Insets(5, 5, 10, 0); gbl.setConstraints(lblEntryType, con); pan.add(lblEntryType); JLabel lblKeyPattern = new JLabel(Localization.lang("Key pattern")); lblKeyPattern.setFont(f); con.gridx = 1; con.gridy = 0; con.gridheight = 1; con.fill = GridBagConstraints.HORIZONTAL; con.anchor = GridBagConstraints.WEST; con.insets = new Insets(5, 5, 10, 5); gbl.setConstraints(lblKeyPattern, con); pan.add(lblKeyPattern); con.gridy = 1; con.gridx = 0; JLabel lab = new JLabel(Localization.lang("Default pattern")); gbl.setConstraints(lab, con); pan.add(lab); con.gridx = 1; gbl.setConstraints(defaultPat, con); pan.add(defaultPat); con.insets = new Insets(5, 5, 10, 5); JButton btnDefault = new JButton(Localization.lang("Default")); btnDefault.addActionListener( e -> defaultPat.setText( (String) Globals.prefs.defaults.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN))); con.gridx = 2; int y = 2; gbl.setConstraints(btnDefault, con); pan.add(btnDefault); BibDatabaseMode mode; // check mode of currently used DB if (panel != null) { mode = panel.getBibDatabaseContext().getMode(); } else { // use preferences value if no DB is open mode = Globals.prefs.getDefaultBibDatabaseMode(); } for (EntryType type : EntryTypes.getAllValues(mode)) { textFields.put(type.getName().toLowerCase(), addEntryType(pan, type, y)); y++; } con.fill = GridBagConstraints.BOTH; con.gridx = 0; con.gridy = 1; con.gridwidth = 3; con.weightx = 1; con.weighty = 1; gbl.setConstraints(sp, con); add(sp); // A help button con.gridwidth = 1; con.gridx = 1; con.gridy = 2; con.fill = GridBagConstraints.HORIZONTAL; // con.weightx = 0; con.weighty = 0; con.anchor = GridBagConstraints.SOUTHEAST; con.insets = new Insets(0, 5, 0, 5); JButton hlb = new JButton(IconTheme.JabRefIcon.HELP.getSmallIcon()); hlb.setToolTipText(Localization.lang("Help on key patterns")); gbl.setConstraints(hlb, con); add(hlb); hlb.addActionListener(help); // And finally a button to reset everything JButton btnDefaultAll = new JButton(Localization.lang("Reset all")); con.gridx = 2; con.gridy = 2; con.weightx = 1; con.weighty = 0; con.anchor = GridBagConstraints.SOUTHEAST; con.insets = new Insets(20, 5, 0, 5); gbl.setConstraints(btnDefaultAll, con); btnDefaultAll.addActionListener( e -> { // reset all fields for (JTextField field : textFields.values()) { field.setText(""); } // also reset the default pattern defaultPat.setText( (String) Globals.prefs.defaults.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN)); }); add(btnDefaultAll); }