Skip to content

Commit

Permalink
Oobranch g : add actions (#7792)
Browse files Browse the repository at this point in the history
* step0 : start model/openoffice, logic/openoffice/style

* correction: import order

* add general utilities

* add UNO utilities, move CreationException, NoDocumentException

* Xlint:unchecked model/openoffice/util

* add ootext

* add rangesort

* add compareStartsUnsafe, compareStartsThenEndsUnsafe

* add Tuple3

* add ootext

* add rangesort

* delNamesArray size correction

* rangeSort update

* cleanup

* style additions

* add backend

* add frontend

* add actions

* checkstyle on tests

* add missing message

* add backend

* add frontend

* add actions

* apply oobranch-[DEFG]-update.patch

* not using RangeSet

* use StringUtil.isNullOrEmpty

* no natural sort for ComparableMark

* in response to review

#7788 (review)

- more use of StringUtil.isNullOrEmpty
- private final XTextRangeCompare cmp;
- List<V> partition = partitions.computeIfAbsent(partitionKey, _key -> new ArrayList<>());
- visualSort does not throw WrappedTargetException, NoDocumentException
- set renamed to comparableMarks

* use {@code }, PMD suggestions

* update logic/style from improve-reversibility-rebased-03

* update model/style from improve-reversibility-rebased-03

* replaced single-character names in OOBibStyle.java (in changed part)

* some longer names in OOBibStyleGetCitationMarker.java

* drop normalizePageInfos, use 'preferred' and 'fallback' in getAuthorLastSeparatorInTextWithFallBack

* checkstyle

* use putIfAbsent

* use "{}" with LOGGER

* use Objects.hash and Objects.equals in CitationLookupResult

* simplified CitedKey.getBibEntry

* more use of "{}" in LOGGER

* more use of "{}" in LOGGER

* more use of "{}" in LOGGER

* Citation.lookup: use streams

* Citation.lookup: Optional::get before findFirst

* putIfAbsent returns null for new entry

* What is 52 in Backend52

* apply 2021-08-20-a/oobranch-E-update.patch

Brings oobranch-E up to
89b0968 @ origin/improve-reversibility-rebased-03 Merge remote-tracking branch 'upstream/main' into improve-reversibility-rebased-03

* sync to improve-reversibility-rebased-03 cb13256

commit cb13256 (HEAD -> improve-reversibility-rebased-03, origin/improve-reversibility-rebased-03)
Author: Antal K <antalk2@gmail.com>
Date:   Fri Aug 20 11:39:39 2021 +0200

    align dots

* longer name

* follow some PMD suggestions

* apply suggested changes
  • Loading branch information
antalk2 authored Nov 14, 2021
1 parent 5680d15 commit 5558408
Show file tree
Hide file tree
Showing 6 changed files with 830 additions and 0 deletions.
118 changes: 118 additions & 0 deletions src/main/java/org/jabref/logic/openoffice/action/EditInsert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package org.jabref.logic.openoffice.action;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.jabref.logic.openoffice.frontend.OOFrontend;
import org.jabref.logic.openoffice.frontend.UpdateCitationMarkers;
import org.jabref.logic.openoffice.style.OOBibStyle;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.openoffice.ootext.OOText;
import org.jabref.model.openoffice.style.Citation;
import org.jabref.model.openoffice.style.CitationMarkerEntry;
import org.jabref.model.openoffice.style.CitationType;
import org.jabref.model.openoffice.style.NonUniqueCitationMarker;
import org.jabref.model.openoffice.style.OODataModel;
import org.jabref.model.openoffice.uno.CreationException;
import org.jabref.model.openoffice.uno.NoDocumentException;
import org.jabref.model.openoffice.uno.UnoScreenRefresh;
import org.jabref.model.openoffice.util.OOListUtil;
import org.jabref.model.strings.StringUtil;

import com.sun.star.beans.IllegalTypeException;
import com.sun.star.beans.NotRemoveableException;
import com.sun.star.beans.PropertyVetoException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument;

public class EditInsert {

private EditInsert() {
/**/
}

/**
* In insertEntry we receive BibEntry values from the GUI.
*
* In the document we store citations by their citation key.
*
* If the citation key is missing, the best we can do is to notify the user. Or the programmer,
* that we cannot accept such input.
*
*/
private static String insertEntryGetCitationKey(BibEntry entry) {
Optional<String> key = entry.getCitationKey();
if (key.isEmpty()) {
throw new IllegalArgumentException("insertEntryGetCitationKey: cannot cite entries without citation key");
}
return key.get();
}

/**
* @param cursor Where to insert.
* @param pageInfo A single pageInfo for a list of entries. This is what we get from the GUI.
*/
public static void insertCitationGroup(XTextDocument doc,
OOFrontend frontend,
XTextCursor cursor,
List<BibEntry> entries,
BibDatabase database,
OOBibStyle style,
CitationType citationType,
String pageInfo)
throws
NoDocumentException,
NotRemoveableException,
WrappedTargetException,
PropertyVetoException,
CreationException,
IllegalTypeException {

List<String> citationKeys = OOListUtil.map(entries, EditInsert::insertEntryGetCitationKey);

final int totalEntries = entries.size();
List<Optional<OOText>> pageInfos = OODataModel.fakePageInfos(pageInfo, totalEntries);

List<CitationMarkerEntry> citations = new ArrayList<>(totalEntries);
for (int i = 0; i < totalEntries; i++) {
Citation cit = new Citation(citationKeys.get(i));
cit.lookupInDatabases(Collections.singletonList(database));
cit.setPageInfo(pageInfos.get(i));
citations.add(cit);
}

// The text we insert
OOText citeText = null;
if (style.isNumberEntries()) {
citeText = OOText.fromString("[-]"); // A dash only. Only refresh later.
} else {
citeText = style.createCitationMarker(citations,
citationType.inParenthesis(),
NonUniqueCitationMarker.FORGIVEN);
}

if (StringUtil.isBlank(OOText.toString(citeText))) {
citeText = OOText.fromString("[?]");
}

try {
UnoScreenRefresh.lockControllers(doc);
UpdateCitationMarkers.createAndFillCitationGroup(frontend,
doc,
citationKeys,
pageInfos,
citationType,
citeText,
cursor,
style,
true /* insertSpaceAfter */);
} finally {
UnoScreenRefresh.unlockControllers(doc);
}

}
}
Loading

0 comments on commit 5558408

Please sign in to comment.