Search in sources :

Example 11 with Abbreviation

use of org.jabref.logic.journals.Abbreviation in project jabref by JabRef.

the class ManageJournalAbbreviationsViewModelTest method testMixedFileUsage.

@Test
public void testMixedFileUsage() throws Exception {
    Abbreviation testAbbreviation = new Abbreviation("Entry", "E");
    Abbreviation testAbbreviation2 = new Abbreviation("EntryEntry", "EE");
    // simulate open file button twice
    when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile3Entries));
    viewModel.addNewFile();
    when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile4Entries));
    viewModel.addNewFile();
    viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(1));
    // size of the list of journal files should be incremented by two
    Assert.assertEquals(2, viewModel.journalFilesProperty().size());
    // our second test file has 4 abbreviations
    Assert.assertEquals(5, viewModel.abbreviationsProperty().size());
    // check some abbreviation
    Assert.assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation)));
    // simulate add new file button
    when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(emptyTestFile));
    viewModel.addNewFile();
    viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(2));
    // size of the list of journal files should be incremented by one
    Assert.assertEquals(3, viewModel.journalFilesProperty().size());
    // a new file has zero abbreviations
    Assert.assertEquals(1, viewModel.abbreviationsProperty().size());
    // simulate open file button
    when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile5EntriesWithDuplicate));
    viewModel.addNewFile();
    viewModel.currentFileProperty().set(viewModel.journalFilesProperty().get(3));
    // size of the list of journal files should be incremented by one
    Assert.assertEquals(4, viewModel.journalFilesProperty().size());
    Assert.assertEquals(5, viewModel.abbreviationsProperty().size());
    // check some abbreviation
    Assert.assertTrue(viewModel.abbreviationsProperty().contains(new AbbreviationViewModel(testAbbreviation2)));
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation) Test(org.junit.Test)

Example 12 with Abbreviation

use of org.jabref.logic.journals.Abbreviation in project jabref by JabRef.

the class ManageJournalAbbreviationsViewModelTest method testDeleteAbbreviationSelectsNextOne.

@Test
public void testDeleteAbbreviationSelectsNextOne() throws Exception {
    when(dialogService.showFileSaveDialog(any())).thenReturn(Optional.of(testFile1Entries));
    viewModel.addNewFile();
    viewModel.selectLastJournalFile();
    Abbreviation testAbbreviation = new Abbreviation("YetAnotherEntry", "YAE");
    addAbbrevaition(testAbbreviation);
    viewModel.currentAbbreviationProperty().set(viewModel.abbreviationsProperty().get(1));
    viewModel.deleteAbbreviation();
    Assert.assertEquals(new AbbreviationViewModel(testAbbreviation), viewModel.currentAbbreviationProperty().get());
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation) Test(org.junit.Test)

Example 13 with Abbreviation

use of org.jabref.logic.journals.Abbreviation in project jabref by JabRef.

the class ManageJournalAbbreviationsViewModel method addAbbreviation.

/**
     * Method to add a new abbreviation to the abbreviations list property.
     * It also sets the currentAbbreviation property to the new abbreviation.
     *
     * @param name         of the abbreviation object
     * @param abbreviation of the abbreviation object
     */
public void addAbbreviation(String name, String abbreviation) {
    Abbreviation abbreviationObject = new Abbreviation(name, abbreviation);
    AbbreviationViewModel abbreviationViewModel = new AbbreviationViewModel(abbreviationObject);
    if (abbreviations.contains(abbreviationViewModel)) {
        dialogService.showErrorDialogAndWait(Localization.lang("Duplicated Journal Abbreviation"), Localization.lang("Abbreviation %s for journal %s already defined.", abbreviation, name));
    } else {
        abbreviations.add(abbreviationViewModel);
        currentAbbreviation.set(abbreviationViewModel);
    }
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation)

Example 14 with Abbreviation

use of org.jabref.logic.journals.Abbreviation in project jabref by JabRef.

the class JournalAbbreviationsUtil method getTableModel.

public static TableModel getTableModel(Collection<Abbreviation> abbreviations) {
    Object[][] cells = new Object[abbreviations.size()][2];
    int row = 0;
    for (Abbreviation abbreviation : abbreviations) {
        cells[row][0] = abbreviation.getName();
        cells[row][1] = abbreviation.getIsoAbbreviation();
        row++;
    }
    return new DefaultTableModel(cells, new Object[] { Localization.lang("Full name"), Localization.lang("Abbreviation") }) {

        @Override
        public boolean isCellEditable(int row1, int column) {
            return false;
        }
    };
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation) DefaultTableModel(javax.swing.table.DefaultTableModel)

Example 15 with Abbreviation

use of org.jabref.logic.journals.Abbreviation in project jabref by JabRef.

the class UndoableUnabbreviator method unabbreviate.

/**
     * Unabbreviate the journal name of the given entry.
     *
     * @param entry     The entry to be treated.
     * @param fieldName The field name (e.g. "journal")
     * @param ce        If the entry is changed, add an edit to this compound.
     * @return true if the entry was changed, false otherwise.
     */
public boolean unabbreviate(BibDatabase database, BibEntry entry, String fieldName, CompoundEdit ce) {
    if (!entry.hasField(fieldName)) {
        return false;
    }
    String text = entry.getField(fieldName).get();
    String origText = text;
    if (database != null) {
        text = database.resolveForStrings(text);
    }
    if (!journalAbbreviationRepository.isKnownName(text)) {
        // cannot do anything if it is not known
        return false;
    }
    if (!journalAbbreviationRepository.isAbbreviatedName(text)) {
        // cannot unabbreviate unabbreviated name.
        return false;
    }
    // must be here
    Abbreviation abbreviation = journalAbbreviationRepository.getAbbreviation(text).get();
    String newText = abbreviation.getName();
    entry.setField(fieldName, newText);
    ce.addEdit(new UndoableFieldChange(entry, fieldName, origText, newText));
    return true;
}
Also used : Abbreviation(org.jabref.logic.journals.Abbreviation) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange)

Aggregations

Abbreviation (org.jabref.logic.journals.Abbreviation)15 Test (org.junit.Test)9 JournalAbbreviationRepository (org.jabref.logic.journals.JournalAbbreviationRepository)3 DefaultTableModel (javax.swing.table.DefaultTableModel)1 UndoableFieldChange (org.jabref.gui.undo.UndoableFieldChange)1 Defaults (org.jabref.model.Defaults)1 BibDatabase (org.jabref.model.database.BibDatabase)1 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)1 BibEntry (org.jabref.model.entry.BibEntry)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1