use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.
the class DroppedFileHandler method linkPdfToEntry.
public void linkPdfToEntry(String fileName, BibEntry entry) {
Optional<ExternalFileType> optFileType = ExternalFileTypes.getInstance().getExternalFileTypeByExt("pdf");
if (!optFileType.isPresent()) {
LOGGER.warn("No file type with extension 'pdf' registered.");
return;
}
ExternalFileType fileType = optFileType.get();
// Show dialog
if (!showLinkMoveCopyRenameDialog(fileName, fileType, entry, panel.getDatabase())) {
return;
}
/*
* Ok, we're ready to go. See first if we need to do a file copy before
* linking:
*/
boolean success = true;
String destFilename;
NamedCompound edits = new NamedCompound(Localization.lang("Drop %0", fileType.getExtension()));
if (linkInPlace.isSelected()) {
destFilename = FileUtil.shortenFileName(Paths.get(fileName), panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences())).toString();
} else {
destFilename = renameCheckBox.isSelected() ? renameToTextBox.getText() : new File(fileName).getName();
if (copyRadioButton.isSelected()) {
success = doCopy(fileName, destFilename, edits);
} else if (moveRadioButton.isSelected()) {
success = doMove(fileName, destFilename, edits);
}
}
if (success) {
doLink(entry, fileType, destFilename, false, edits);
panel.markBaseChanged();
}
edits.end();
panel.getUndoManager().addEdit(edits);
}
use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.
the class AppendDatabaseAction method mergeFromBibtex.
private static void mergeFromBibtex(BasePanel panel, ParserResult parserResult, boolean importEntries, boolean importStrings, boolean importGroups, boolean importSelectorWords) throws KeyCollisionException {
BibDatabase fromDatabase = parserResult.getDatabase();
List<BibEntry> appendedEntries = new ArrayList<>();
List<BibEntry> originalEntries = new ArrayList<>();
BibDatabase database = panel.getDatabase();
NamedCompound ce = new NamedCompound(Localization.lang("Append library"));
MetaData meta = parserResult.getMetaData();
if (importEntries) {
// Add entries
boolean overwriteOwner = Globals.prefs.getBoolean(JabRefPreferences.OVERWRITE_OWNER);
boolean overwriteTimeStamp = Globals.prefs.getBoolean(JabRefPreferences.OVERWRITE_TIME_STAMP);
for (BibEntry originalEntry : fromDatabase.getEntries()) {
BibEntry entry = (BibEntry) originalEntry.clone();
UpdateField.setAutomaticFields(entry, overwriteOwner, overwriteTimeStamp, Globals.prefs.getUpdateFieldPreferences());
database.insertEntry(entry);
appendedEntries.add(entry);
originalEntries.add(originalEntry);
ce.addEdit(new UndoableInsertEntry(database, entry, panel));
}
}
if (importStrings) {
for (BibtexString bs : fromDatabase.getStringValues()) {
if (!database.hasStringLabel(bs.getName())) {
database.addString(bs);
ce.addEdit(new UndoableInsertString(panel, database, bs));
}
}
}
if (importGroups) {
meta.getGroups().ifPresent(newGroups -> {
if (newGroups.getGroup() instanceof AllEntriesGroup) {
try {
ExplicitGroup group = new ExplicitGroup("Imported", GroupHierarchyType.INDEPENDENT, Globals.prefs.getKeywordDelimiter());
newGroups.setGroup(group);
group.add(appendedEntries);
} catch (IllegalArgumentException e) {
LOGGER.error(e);
}
}
addGroups(newGroups, ce);
});
}
if (importSelectorWords) {
for (ContentSelector selector : meta.getContentSelectorList()) {
panel.getBibDatabaseContext().getMetaData().addContentSelector(selector);
}
}
ce.end();
panel.getUndoManager().addEdit(ce);
panel.markBaseChanged();
}
use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.
the class MergeEntriesDialog method init.
/**
* Sets up the dialog
*
* @param selected Selected BibtexEntries
*/
private void init(List<BibEntry> selected) {
// Check if there are two entries selected
if (selected.size() != 2) {
// None selected. Inform the user to select entries first.
JOptionPane.showMessageDialog(panel.frame(), Localization.lang("You have to choose exactly two entries to merge."), MERGE_ENTRIES, JOptionPane.INFORMATION_MESSAGE);
this.dispose();
return;
}
// Store the two entries
BibEntry one = selected.get(0);
BibEntry two = selected.get(1);
MergeEntries mergeEntries = new MergeEntries(one, two, panel.getBibDatabaseContext().getMode());
// Create undo-compound
NamedCompound ce = new NamedCompound(MERGE_ENTRIES);
FormLayout layout = new FormLayout("fill:700px:grow", "fill:400px:grow, 4px, p, 5px, p");
this.setLayout(layout);
this.add(mergeEntries.getMergeEntryPanel(), cc.xy(1, 1));
this.add(new JSeparator(), cc.xy(1, 3));
// Create buttons
ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
JButton cancel = new JButton(Localization.lang("Cancel"));
cancel.setActionCommand("cancel");
cancel.addActionListener(e -> {
panel.output(Localization.lang("Canceled merging entries"));
dispose();
});
JButton replaceentries = new JButton(MERGE_ENTRIES);
replaceentries.setActionCommand("replace");
replaceentries.addActionListener(e -> {
BibEntry mergedEntry = mergeEntries.getMergeEntry();
panel.insertEntry(mergedEntry);
ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), mergedEntry, panel));
ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), one, panel));
panel.getDatabase().removeEntry(one);
ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), two, panel));
panel.getDatabase().removeEntry(two);
ce.end();
panel.getUndoManager().addEdit(ce);
panel.output(Localization.lang("Merged entries"));
dispose();
});
bb.addButton(new JButton[] { replaceentries, cancel });
this.add(bb.getPanel(), cc.xy(1, 5));
// Add some margin around the layout
layout.appendRow(RowSpec.decode(MARGIN));
layout.appendColumn(ColumnSpec.decode(MARGIN));
layout.insertRow(1, RowSpec.decode(MARGIN));
layout.insertColumn(1, ColumnSpec.decode(MARGIN));
WindowLocation pw = new WindowLocation(this, JabRefPreferences.MERGEENTRIES_POS_X, JabRefPreferences.MERGEENTRIES_POS_Y, JabRefPreferences.MERGEENTRIES_SIZE_X, JabRefPreferences.MERGEENTRIES_SIZE_Y);
pw.displayWindowAtStoredLocation();
// Show what we've got
setVisible(true);
}
use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.
the class MergeFetchedEntryDialog method init.
/**
* Sets up the dialog
*/
private void init() {
mergeEntries = new MergeEntries(this.originalEntry, this.fetchedEntry, Localization.lang("Original entry"), Localization.lang("Entry from %0", type), panel.getBibDatabaseContext().getMode());
// Create undo-compound
ce = new NamedCompound(Localization.lang("Merge entry with %0 information", type));
FormLayout layout = new FormLayout("fill:700px:grow", "fill:400px:grow, 4px, p, 5px, p");
this.setLayout(layout);
this.add(mergeEntries.getMergeEntryPanel(), cc.xy(1, 1));
this.add(new JSeparator(), cc.xy(1, 3));
// Create buttons
ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
JButton cancel = new JButton(new CancelAction());
JButton replaceEntry = new JButton(new ReplaceAction());
bb.addButton(replaceEntry, cancel);
this.add(bb.getPanel(), cc.xy(1, 5));
// Add some margin around the layout
layout.appendRow(RowSpec.decode(MARGIN));
layout.appendColumn(ColumnSpec.decode(MARGIN));
layout.insertRow(1, RowSpec.decode(MARGIN));
layout.insertColumn(1, ColumnSpec.decode(MARGIN));
WindowLocation pw = new WindowLocation(this, JabRefPreferences.MERGEENTRIES_POS_X, JabRefPreferences.MERGEENTRIES_POS_Y, JabRefPreferences.MERGEENTRIES_SIZE_X, JabRefPreferences.MERGEENTRIES_SIZE_Y);
pw.displayWindowAtStoredLocation();
}
use of org.jabref.gui.undo.NamedCompound in project jabref by JabRef.
the class MarkEntriesAction method run.
@Override
public void run() {
BasePanel panel = frame.getCurrentBasePanel();
if (panel != null) {
List<BibEntry> bes = panel.getSelectedEntries();
// used at update() to determine output string
besLength = bes.size();
if (!bes.isEmpty()) {
NamedCompound ce = new NamedCompound(Localization.lang("Mark entries"));
for (BibEntry be : bes) {
EntryMarker.markEntry(be, level + 1, false, ce);
}
ce.end();
panel.getUndoManager().addEdit(ce);
}
}
}
Aggregations