@Override public void actionPerformed(ActionEvent e) { BasePanel bp = frame.basePanel(); if (bp == null) { return; } BibtexEntry[] entries = bp.getSelectedEntries(); // Lazy creation of the dialog: if (diag == null) { createDialog(); } cancelled = true; prepareDialog(entries.length > 0); Util.placeDialog(diag, frame); diag.setVisible(true); if (cancelled) { return; } Collection<BibtexEntry> entryList; // If all entries should be treated, change the entries array: if (all.isSelected()) { entryList = bp.database().getEntries(); } else { entryList = Arrays.asList(entries); } String toSet = text.getText(); if (toSet.isEmpty()) { toSet = null; } String[] fields = getFieldNames(field.getText().trim().toLowerCase()); NamedCompound ce = new NamedCompound(Globals.lang("Set field")); if (rename.isSelected()) { if (fields.length > 1) { // TODO: message: can only rename a single field } else { ce.addEdit( Util.massRenameField(entryList, fields[0], renameTo.getText(), overwrite.isSelected())); } } else { for (String field1 : fields) { ce.addEdit( Util.massSetField( entryList, field1, set.isSelected() ? toSet : null, overwrite.isSelected())); } } ce.end(); bp.undoManager.addEdit(ce); bp.markBaseChanged(); }
/** * Cycle through all databases, and make sure everything is updated with the new type * customization. This includes making sure all entries have a valid type, that no obsolete entry * editors are around, and that the right-click menus' change type menu is up-to-date. */ private void updateTypesForEntries(String typeName) { if (frame.getTabbedPane().getTabCount() == 0) { return; } for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) { BasePanel bp = (BasePanel) frame.getTabbedPane().getComponentAt(i); // Invalidate associated cached entry editor bp.entryEditors.remove(typeName); for (BibtexEntry entry : bp.database().getEntries()) { entry.updateType(); } } }
public void run() { // net.sf.jabref.journals.JournalList.downloadJournalList(frame); BibtexEntry[] entries = panel.getSelectedEntries(); if (entries == null) return; NamedCompound ce = new NamedCompound("Abbreviate journal names"); int count = 0; for (BibtexEntry entry : entries) { if (Globals.journalAbbrev.abbreviate(panel.database(), entry, "journal", ce, iso)) count++; if (Globals.journalAbbrev.abbreviate(panel.database(), entry, "journaltitle", ce, iso)) count++; } if (count > 0) { ce.end(); panel.undoManager.addEdit(ce); panel.markBaseChanged(); message = Globals.lang("Abbreviated %0 journal names.", String.valueOf(count)); } else { message = Globals.lang("No journal names could be abbreviated."); } }
private void doRenamePDFs(BibtexEntry entry, NamedCompound ce) { // Extract the path String oldValue = entry.getField(Globals.FILE_FIELD); if (oldValue == null) { return; } FileListTableModel flModel = new FileListTableModel(); flModel.setContent(oldValue); if (flModel.getRowCount() == 0) { return; } boolean changed = false; for (int i = 0; i < flModel.getRowCount(); i++) { String realOldFilename = flModel.getEntry(i).getLink(); if (cleanUpRenamePDFonlyRelativePaths.isSelected() && (new File(realOldFilename).isAbsolute())) { continue; } String newFilename = Util.getLinkedFileName(panel.database(), entry); // String oldFilename = bes.getField(GUIGlobals.FILE_FIELD); // would have to be stored for // undoing purposes // Add extension to newFilename newFilename = newFilename + "." + flModel.getEntry(i).getType().getExtension(); // get new Filename with path // Create new Path based on old Path and new filename File expandedOldFile = FileUtil.expandFilename( realOldFilename, panel.metaData().getFileDirectory(Globals.FILE_FIELD)); if (expandedOldFile.getParent() == null) { // something went wrong. Just skip this entry continue; } String newPath = expandedOldFile .getParent() .concat(System.getProperty("file.separator")) .concat(newFilename); if (new File(newPath).exists()) { // we do not overwrite files // TODO: we could check here if the newPath file is linked with the current entry. And if // not, we could add a link continue; } // do rename boolean renameSuccessful = FileUtil.renameFile(expandedOldFile.toString(), newPath); if (renameSuccessful) { changed = true; // Change the path for this entry String description = flModel.getEntry(i).getDescription(); ExternalFileType type = flModel.getEntry(i).getType(); flModel.removeEntry(i); // we cannot use "newPath" to generate a FileListEntry as newPath is absolute, but we want // to keep relative paths whenever possible File parent = (new File(realOldFilename)).getParentFile(); String newFileEntryFileName; if (parent == null) { newFileEntryFileName = newFilename; } else { newFileEntryFileName = parent.toString().concat(System.getProperty("file.separator")).concat(newFilename); } flModel.addEntry(i, new FileListEntry(description, newFileEntryFileName, type)); } else { unsuccessfulRenames++; } } if (changed) { String newValue = flModel.getStringRepresentation(); assert (!oldValue.equals(newValue)); entry.setField(Globals.FILE_FIELD, newValue); // we put an undo of the field content here // the file is not being renamed back, which leads to inconsistencies // if we put a null undo object here, the change by "doMakePathsRelative" would overwrite the // field value nevertheless. ce.addEdit(new UndoableFieldChange(entry, Globals.FILE_FIELD, oldValue, newValue)); } }
private boolean importPdfFiles(List<String> fileNames) { if (panel == null) return false; for (String fileName : fileNames) { List<BibtexEntry> xmpEntriesInFile = readXmpEntries(fileName); ImportDialog importDialog = new ImportDialog(dropRow, fileName); if (!hasXmpEntries(xmpEntriesInFile)) { importDialog.getRadioButtonXmp().setEnabled(false); } Tools.centerRelativeToWindow(importDialog, frame); importDialog.showDialog(); if (importDialog.getResult() == JOptionPane.OK_OPTION) { if (importDialog.getRadioButtonXmp().isSelected()) { // SplDatabaseChangeListener dataListener = new SplDatabaseChangeListener(frame, panel, // entryTable, fileName); // panel.database().addDatabaseChangeListener(dataListener); ImportMenuItem importer = new ImportMenuItem(frame, (entryTable == null)); importer.automatedImport(new String[] {fileName}); } else if (importDialog.getRadioButtonMrDlib().isSelected()) { MetaDataListDialog metaDataListDialog = new MetaDataListDialog(fileName, true); Tools.centerRelativeToWindow(metaDataListDialog, frame); metaDataListDialog.showDialog(); XmlDocuments documents = metaDataListDialog.getXmlDocuments(); if (documents != null && documents.getDocuments() != null && documents.getDocuments().size() > 0 && metaDataListDialog.getResult() == JOptionPane.OK_OPTION) { int selected = metaDataListDialog.getTableMetadata().getSelectedRow(); if (selected > -1 && selected < documents.getDocuments().size()) { XmlDocument document = documents.getDocuments().get(selected); String id = Util.createNeutralId(); BibtexEntry entry = new BibtexEntry(id); if (fieldExists(document.getType())) { BibtexEntryType type = BibtexEntryType.getStandardType(document.getType()); if (type == null) { type = BibtexEntryType.ARTICLE; } entry.setType(type); } else { entry.setType(BibtexEntryType.ARTICLE); } ArrayList<BibtexEntry> list = new ArrayList<BibtexEntry>(); list.add(entry); Util.setAutomaticFields(list, true, true, false); insertFields(entry.getRequiredFields(), entry, document); insertFields(entry.getGeneralFields(), entry, document); insertFields(entry.getOptionalFields(), entry, document); panel.database().insertEntry(entry); DroppedFileHandler dfh = new DroppedFileHandler(frame, panel); dfh.linkPdfToEntry(fileName, entryTable, entry); LabelPatternUtil.makeLabel(Globals.prefs.getKeyPattern(), panel.database(), entry); } else { createNewBlankEntry(fileName); } } else if (metaDataListDialog.getResult() == JOptionPane.CANCEL_OPTION) { continue; } else if (metaDataListDialog.getResult() == JOptionPane.NO_OPTION) { createNewBlankEntry(fileName); } else if (documents == null || documents.getDocuments() == null || documents.getDocuments().size() <= 0 && metaDataListDialog.getResult() == JOptionPane.OK_OPTION) { createNewBlankEntry(fileName); } } else if (importDialog.getRadioButtonNoMeta().isSelected()) { createNewBlankEntry(fileName); } else if (importDialog.getRadioButtonUpdateEmptyFields().isSelected()) { MetaDataListDialog metaDataListDialog = new MetaDataListDialog(fileName, false); Tools.centerRelativeToWindow(metaDataListDialog, frame); metaDataListDialog.showDialog(); XmlDocuments documents = metaDataListDialog.getXmlDocuments(); if (documents != null && documents.getDocuments() != null && documents.getDocuments().size() > 0 && metaDataListDialog.getResult() == JOptionPane.OK_OPTION) { int selected = metaDataListDialog.getTableMetadata().getSelectedRow(); if (selected > -1 && selected < documents.getDocuments().size()) { XmlDocument document = documents.getDocuments().get(selected); BibtexEntry entry = entryTable.getEntryAt(dropRow); if (fieldExists(document.getType())) { BibtexEntryType type = BibtexEntryType.getStandardType(document.getType()); if (type != null) { entry.setType(type); } } insertFields(entry.getRequiredFields(), entry, document); insertFields(entry.getGeneralFields(), entry, document); insertFields(entry.getOptionalFields(), entry, document); DroppedFileHandler dfh = new DroppedFileHandler(frame, panel); dfh.linkPdfToEntry(fileName, entryTable, dropRow); } } } else if (importDialog.getRadioButtononlyAttachPDF().isSelected()) { DroppedFileHandler dfh = new DroppedFileHandler(frame, panel); dfh.linkPdfToEntry(fileName, entryTable, dropRow); } } } return true; }
private BibtexEntry createNewEntry() { // Find out what type is wanted. EntryTypeDialog etd = new EntryTypeDialog(frame); // We want to center the dialog, to make it look nicer. Util.placeDialog(etd, frame); etd.setVisible(true); BibtexEntryType type = etd.getChoice(); if (type != null) { // Only if the dialog was not cancelled. String id = Util.createNeutralId(); final BibtexEntry be = new BibtexEntry(id, type); try { panel.database().insertEntry(be); // Set owner/timestamp if options are enabled: ArrayList<BibtexEntry> list = new ArrayList<BibtexEntry>(); list.add(be); Util.setAutomaticFields(list, true, true, false); // Create an UndoableInsertEntry object. panel.undoManager.addEdit(new UndoableInsertEntry(panel.database(), be, panel)); panel.output( Globals.lang("Added new") + " '" + type.getName().toLowerCase() + "' " + Globals.lang("entry") + "."); // We are going to select the new entry. Before that, make sure that we are in // show-entry mode. If we aren't already in that mode, enter the WILL_SHOW_EDITOR // mode which makes sure the selection will trigger display of the entry editor // and adjustment of the splitter. if (panel.getMode() != panel.SHOWING_EDITOR) { panel.setMode(panel.WILL_SHOW_EDITOR); } /*int row = entryTable.findEntry(be); if (row >= 0) // Selects the entry. The selection listener will open the editor. if (row >= 0) { try{ entryTable.setRowSelectionInterval(row, row); }catch(IllegalArgumentException e){ System.out.println("RowCount: " + entryTable.getRowCount()); } //entryTable.setActiveRow(row); entryTable.ensureVisible(row); } else { // The entry is not visible in the table, perhaps due to a filtering search // or group selection. Show the entry editor anyway: panel.showEntry(be); } */ panel.showEntry(be); panel.markBaseChanged(); // The database just changed. new FocusRequester(panel.getEntryEditor(be)); return be; } catch (KeyCollisionException ex) { Util.pr(ex.getMessage()); } } return null; }