Search in sources :

Example 1 with UndoableStringChange

use of org.jabref.gui.undo.UndoableStringChange in project jabref by JabRef.

the class StringChange method makeChange.

@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
    if (string == null) {
        // The string was removed or renamed locally. We guess that it was removed.
        BibtexString bs = new BibtexString(label, disk);
        try {
            panel.getDatabase().addString(bs);
            undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs));
        } catch (KeyCollisionException ex) {
            LOGGER.info("Error: could not add string '" + bs.getName() + "': " + ex.getMessage(), ex);
        }
    } else {
        string.setContent(disk);
        undoEdit.addEdit(new UndoableStringChange(panel, string, false, mem, disk));
    }
    // Update tmp database:
    if (tmpString == null) {
        BibtexString bs = new BibtexString(label, disk);
        secondary.addString(bs);
    } else {
        tmpString.setContent(disk);
    }
    return true;
}
Also used : KeyCollisionException(org.jabref.model.database.KeyCollisionException) UndoableInsertString(org.jabref.gui.undo.UndoableInsertString) UndoableStringChange(org.jabref.gui.undo.UndoableStringChange) BibtexString(org.jabref.model.entry.BibtexString)

Example 2 with UndoableStringChange

use of org.jabref.gui.undo.UndoableStringChange in project jabref by JabRef.

the class StringNameChange method makeChange.

@Override
public boolean makeChange(BasePanel panel, BibDatabase secondary, NamedCompound undoEdit) {
    if (panel.getDatabase().hasStringLabel(disk)) {
        // The name to change to is already in the database, so we can't comply.
        LOGGER.info("Cannot rename string '" + mem + "' to '" + disk + "' because the name " + "is already in use.");
    }
    if (string == null) {
        // The string was removed or renamed locally. We guess that it was removed.
        BibtexString bs = new BibtexString(disk, content);
        try {
            panel.getDatabase().addString(bs);
            undoEdit.addEdit(new UndoableInsertString(panel, panel.getDatabase(), bs));
        } catch (KeyCollisionException ex) {
            LOGGER.info("Error: could not add string '" + bs.getName() + "': " + ex.getMessage(), ex);
        }
    } else {
        string.setName(disk);
        undoEdit.addEdit(new UndoableStringChange(panel, string, true, mem, disk));
    }
    // Update tmp database:
    if (tmpString == null) {
        BibtexString bs = new BibtexString(disk, content);
        secondary.addString(bs);
    } else {
        tmpString.setName(disk);
    }
    return true;
}
Also used : KeyCollisionException(org.jabref.model.database.KeyCollisionException) UndoableInsertString(org.jabref.gui.undo.UndoableInsertString) UndoableStringChange(org.jabref.gui.undo.UndoableStringChange) BibtexString(org.jabref.model.entry.BibtexString)

Aggregations

UndoableInsertString (org.jabref.gui.undo.UndoableInsertString)2 UndoableStringChange (org.jabref.gui.undo.UndoableStringChange)2 KeyCollisionException (org.jabref.model.database.KeyCollisionException)2 BibtexString (org.jabref.model.entry.BibtexString)2