Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oobranch g : add actions #7792

Merged
merged 61 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a50cc79
step0 : start model/openoffice, logic/openoffice/style
antalk2 May 27, 2021
d93bd56
correction: import order
antalk2 May 27, 2021
c9b72e9
add general utilities
antalk2 May 27, 2021
381a549
add UNO utilities, move CreationException, NoDocumentException
antalk2 May 27, 2021
f94c1f6
Xlint:unchecked model/openoffice/util
antalk2 May 28, 2021
f9a8176
add ootext
antalk2 May 28, 2021
6d013f1
add rangesort
antalk2 May 28, 2021
0434579
add compareStartsUnsafe, compareStartsThenEndsUnsafe
antalk2 Jun 3, 2021
3c45a8a
add Tuple3
antalk2 Jun 3, 2021
32f7a43
add ootext
antalk2 May 28, 2021
6bae6b4
add rangesort
antalk2 May 28, 2021
314902c
delNamesArray size correction
antalk2 Jun 3, 2021
dfe18bc
rangeSort update
antalk2 Jun 3, 2021
c9f4e57
Merge remote-tracking branch 'origin/oobranch-C' into oobranch-C
antalk2 Jun 3, 2021
6e4c7c2
cleanup
antalk2 Jun 3, 2021
9388b2a
style additions
antalk2 Jun 3, 2021
d2a53c7
add backend
antalk2 Jun 3, 2021
0fed618
add frontend
antalk2 Jun 3, 2021
3632d00
add actions
antalk2 Jun 3, 2021
88cab9c
checkstyle on tests
antalk2 Jun 3, 2021
b7aaf2a
add missing message
antalk2 Jun 3, 2021
0fa9a4c
add backend
antalk2 Jun 3, 2021
946242f
Merge remote-tracking branch 'origin/oobranch-E' into oobranch-E
antalk2 Jun 3, 2021
a5b7a05
add frontend
antalk2 Jun 3, 2021
765f570
Merge remote-tracking branch 'origin/oobranch-F' into oobranch-F
antalk2 Jun 3, 2021
c50c458
add actions
antalk2 Jun 3, 2021
da39254
Merge remote-tracking branch 'origin/oobranch-G' into oobranch-G
antalk2 Jun 3, 2021
18ef070
apply oobranch-[DEFG]-update.patch
antalk2 Jun 19, 2021
46232ad
Merge remote-tracking branch 'upstream/main' into oobranch-G
antalk2 Jun 19, 2021
b9491d8
not using RangeSet
antalk2 Jun 19, 2021
23200de
use StringUtil.isNullOrEmpty
antalk2 Jun 22, 2021
9a849dd
no natural sort for ComparableMark
antalk2 Jun 22, 2021
2d4d5fb
in response to review
antalk2 Jul 7, 2021
63a7c0b
use {@code }, PMD suggestions
antalk2 Jul 9, 2021
3896ab8
Merge remote-tracking branch 'upstream/main' into oobranch-G
antalk2 Jul 13, 2021
d5e6de8
update logic/style from improve-reversibility-rebased-03
antalk2 Jul 13, 2021
8b46a70
update model/style from improve-reversibility-rebased-03
antalk2 Jul 13, 2021
665ac66
replaced single-character names in OOBibStyle.java (in changed part)
antalk2 Jul 18, 2021
890fd2a
some longer names in OOBibStyleGetCitationMarker.java
antalk2 Jul 18, 2021
0a267e5
drop normalizePageInfos, use 'preferred' and 'fallback' in getAuthorL…
antalk2 Jul 18, 2021
5be1e74
checkstyle
antalk2 Jul 18, 2021
f9c0415
use putIfAbsent
antalk2 Jul 18, 2021
843b7ac
use "{}" with LOGGER
antalk2 Jul 18, 2021
09f5503
use Objects.hash and Objects.equals in CitationLookupResult
antalk2 Jul 18, 2021
d6a22be
simplified CitedKey.getBibEntry
antalk2 Jul 18, 2021
8395e0c
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
0343d81
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
9890320
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
b34803f
Citation.lookup: use streams
antalk2 Jul 24, 2021
0490547
Citation.lookup: Optional::get before findFirst
antalk2 Jul 24, 2021
fa87623
Merge remote-tracking branch 'upstream/main' into oobranch-G
antalk2 Aug 2, 2021
dd0c039
putIfAbsent returns null for new entry
antalk2 Aug 2, 2021
2f36705
What is 52 in Backend52
antalk2 Aug 3, 2021
d2cf373
apply 2021-08-20-a/oobranch-E-update.patch
antalk2 Aug 20, 2021
952f08b
sync to improve-reversibility-rebased-03 cb132566f32cba17af24b41d0374…
antalk2 Aug 20, 2021
1663189
Merge remote-tracking branch 'upstream/main' into oobranch-G
antalk2 Aug 23, 2021
bf1a990
longer name
antalk2 Aug 23, 2021
2e80351
follow some PMD suggestions
antalk2 Aug 23, 2021
79734fb
Merge remote-tracking branch 'upstream/main' into oobranch-G
antalk2 Sep 2, 2021
9fedc96
Merge remote-tracking branch 'upstream/main' into oobranch-G
antalk2 Nov 9, 2021
5272e98
apply suggested changes
antalk2 Nov 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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