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

Open office refactor finalization (formerly OObranch J cleanup) #7795

Merged
merged 127 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 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
fc534c1
add gui stuff
antalk2 Jun 3, 2021
b660d32
integrate
antalk2 Jun 3, 2021
e12fdb7
cleanup
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
00527f4
add gui stuff
antalk2 Jun 3, 2021
889f3fd
Merge remote-tracking branch 'origin/oobranch-H' into oobranch-H
antalk2 Jun 3, 2021
90078c7
integrate
antalk2 Jun 3, 2021
8deb22b
Merge remote-tracking branch 'origin/oobranch-I' into oobranch-I
antalk2 Jun 3, 2021
3e001c5
cleanup
antalk2 Jun 3, 2021
577de74
Merge remote-tracking branch 'origin/oobranch-J' into oobranch-J
antalk2 Jun 3, 2021
3dd6d09
remove duplicate
antalk2 Jun 3, 2021
e2ddc35
apply oobranch-[DEFGH]-update.patch
antalk2 Jun 19, 2021
e236a81
Merge remote-tracking branch 'upstream/main' into oobranch-H
antalk2 Jun 19, 2021
61fa941
apply oobranch-[DEFGH]-update.patch
antalk2 Jun 19, 2021
6a3d19e
Merge remote-tracking branch 'upstream/main' into oobranch-I
antalk2 Jun 19, 2021
41f1311
not using RangeSet
antalk2 Jun 19, 2021
0f398bd
not using RangeSet
antalk2 Jun 19, 2021
7e6667d
not using RangeSet
antalk2 Jun 19, 2021
00fa0ad
merged
antalk2 Jun 19, 2021
361d3ef
cleanup
antalk2 Jun 3, 2021
614b7f7
remove duplicate
antalk2 Jun 3, 2021
292f351
toString
antalk2 Jun 19, 2021
1ad1d1c
Merge remote-tracking branch 'origin/oobranch-J' into oobranch-J
antalk2 Jun 19, 2021
956992e
add docs/openoffice
antalk2 Jun 29, 2021
982b27a
markdown-lint
antalk2 Jun 29, 2021
ad194e5
use StringUtil.isNullOrEmpty
antalk2 Jun 22, 2021
ff8517b
no natural sort for ComparableMark
antalk2 Jun 22, 2021
7ec1cc2
in response to review
antalk2 Jul 7, 2021
bf94bf5
use {@code }, PMD suggestions
antalk2 Jul 9, 2021
b829590
use StringUtil.isNullOrEmpty
antalk2 Jun 22, 2021
28a019a
no natural sort for ComparableMark
antalk2 Jun 22, 2021
8c7ad3f
in response to review
antalk2 Jul 7, 2021
66d48a2
use {@code }, PMD suggestions
antalk2 Jul 9, 2021
cfaa5f8
Merge remote-tracking branch 'upstream/main' into oobranch-H
antalk2 Jul 13, 2021
d8bae01
Merge remote-tracking branch 'upstream/main' into oobranch-J
antalk2 Jul 13, 2021
6d7b8a1
update logic/style from improve-reversibility-rebased-03
antalk2 Jul 13, 2021
cb0ca45
update model/style from improve-reversibility-rebased-03
antalk2 Jul 13, 2021
a60211b
update logic/style from improve-reversibility-rebased-03
antalk2 Jul 13, 2021
da0ae0a
update model/style from improve-reversibility-rebased-03
antalk2 Jul 13, 2021
f224dc0
replaced single-character names in OOBibStyle.java (in changed part)
antalk2 Jul 18, 2021
ac51403
some longer names in OOBibStyleGetCitationMarker.java
antalk2 Jul 18, 2021
e0151eb
drop normalizePageInfos, use 'preferred' and 'fallback' in getAuthorL…
antalk2 Jul 18, 2021
d7bf2fb
checkstyle
antalk2 Jul 18, 2021
dd6d1c6
use putIfAbsent
antalk2 Jul 18, 2021
7cb166c
use "{}" with LOGGER
antalk2 Jul 18, 2021
e832a10
use Objects.hash and Objects.equals in CitationLookupResult
antalk2 Jul 18, 2021
4ba4e66
simplified CitedKey.getBibEntry
antalk2 Jul 18, 2021
46f7231
replaced single-character names in OOBibStyle.java (in changed part)
antalk2 Jul 18, 2021
55686e3
some longer names in OOBibStyleGetCitationMarker.java
antalk2 Jul 18, 2021
c1491e9
OOBibStyle
antalk2 Jul 18, 2021
e0783df
checkstyle
antalk2 Jul 18, 2021
09748e3
use putIfAbsent
antalk2 Jul 18, 2021
e0fb50d
use "{}" with LOGGER
antalk2 Jul 18, 2021
1268e60
use Objects.hash and Objects.equals in CitationLookupResult
antalk2 Jul 18, 2021
6107f4b
simplified CitedKey.getBibEntry
antalk2 Jul 18, 2021
a87d6b8
drop import StringUtil
antalk2 Jul 18, 2021
6b5055a
drop import ArrayList
antalk2 Jul 18, 2021
8a29981
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
2725b64
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
c7cb442
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
d86eadf
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
fa2b24a
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
a83a3af
more use of "{}" in LOGGER
antalk2 Jul 18, 2021
2224e68
Citation.lookup: use streams
antalk2 Jul 24, 2021
220dcc4
Citation.lookup: use streams
antalk2 Jul 24, 2021
eff50ad
Citation.lookup: Optional::get before findFirst
antalk2 Jul 24, 2021
69c4d6b
Citation.lookup: Optional::get before findFirst
antalk2 Jul 24, 2021
c093d9d
removed catch RuntimeException around UnoCursor.getViewCursor
antalk2 Aug 2, 2021
d579c80
removed catch RuntimeException around UnoCursor.getViewCursor
antalk2 Aug 2, 2021
1d9163d
drop unused message
antalk2 Aug 2, 2021
71bb543
drop unused message
antalk2 Aug 2, 2021
dc590db
Merge remote-tracking branch 'upstream/main' into oobranch-H
antalk2 Aug 2, 2021
8e4b2e5
Merge remote-tracking branch 'upstream/main' into oobranch-J
antalk2 Aug 2, 2021
94cb611
putIfAbsent returns null for new entry
antalk2 Aug 2, 2021
26ae70a
putIfAbsent returns null for new entry
antalk2 Aug 2, 2021
ae22fec
What is 52 in Backend52
antalk2 Aug 3, 2021
26fa1b6
What is 52 in Backend52
antalk2 Aug 3, 2021
f373daf
apply 2021-08-20-a/oobranch-E-update.patch
antalk2 Aug 20, 2021
f33bafa
apply 2021-08-20-a/oobranch-E-update.patch
antalk2 Aug 20, 2021
1fcb009
sync to improve-reversibility-rebased-03 cb132566f32cba17af24b41d0374…
antalk2 Aug 20, 2021
0cea6ae
sync to improve-reversibility-rebased-03 cb132566f32cba17af24b41d0374…
antalk2 Aug 20, 2021
abd8880
Merge remote-tracking branch 'upstream/main' into oobranch-H
antalk2 Aug 23, 2021
a76ae67
Merge remote-tracking branch 'upstream/main' into oobranch-J
antalk2 Aug 23, 2021
ec253d0
longer name
antalk2 Aug 23, 2021
1f6700c
follow some PMD suggestions
antalk2 Aug 23, 2021
f782981
follow some PMD suggestions
antalk2 Aug 23, 2021
70e0ca0
Merge remote-tracking branch 'upstream/main' into oobranch-H
antalk2 Sep 2, 2021
074d662
Merge remote-tracking branch 'upstream/main' into oobranch-J
antalk2 Sep 2, 2021
3fabcc2
Merge remote-tracking branch 'upstream/main' into oobranch-H
antalk2 Nov 9, 2021
fd8584b
apply suggested changes
antalk2 Nov 9, 2021
c1a6d59
Merge remote-tracking branch 'upstream/main' into oobranch-H
calixtus Feb 15, 2022
b275709
Merge remote-tracking branch 'upstream/main' into oobranch-J
calixtus Feb 16, 2022
79c4f0d
Merge branch 'oobranch-H' into oobranch-J
calixtus Feb 16, 2022
059e1d9
fixed merge errors
calixtus Feb 16, 2022
1e37728
reformatted
calixtus Feb 16, 2022
7d391d3
autoreformatted all oo packages, smaller rewordings, few ide suggestions
calixtus Feb 22, 2022
003db88
Merge remote-tracking branch 'antalk2/oobranch-J' into oobranch-J
calixtus Feb 22, 2022
efb0f1c
autoreformatted all oo tests, fixed l10n, applied small ide suggestions
calixtus Feb 22, 2022
f4f5b57
Applied some ide suggestions, reworded some variables, reworded-remov…
calixtus Mar 8, 2022
c881e09
Changed File to Path
calixtus Mar 11, 2022
303e7a6
Merge remote-tracking branch 'upstream/main' into oobranch-J
calixtus Mar 11, 2022
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
8 changes: 7 additions & 1 deletion docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@
* [Readings on Coding](readings-on-coding/README.md)
* [Readings on JavaFX](readings-on-coding/javafx.md)
* [Useful development tooling](readings-on-coding/tools.md)

* [The OpenOffice/LibreOffice panel](openoffice/README.md)
* [Overview](openoffice/overview.md)
* [Order of appearance of citation groups](openoffice/order-of-appearance.md)
* [Problems](openoffice/problems.md)
* [Code reorganization](openoffice/code-reorganization.md)
* [About `OOError`, `OOResult` and `OOVoidResult`](openoffice/ooresult-ooerror.md)
* [Alternatives to using OOResult and OOVoidResult in OOBibBase](openoffice/ooresult-alternatives.md)
1 change: 1 addition & 0 deletions docs/openoffice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# OpenOffice/LibreOffice integration
188 changes: 188 additions & 0 deletions docs/openoffice/code-reorganization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@

# Code reorganization

Why

- Separate backend
- Separate GUI code (dialogs) and logic
- Data is now organized around `Citation`, `CitationGroup` instead of arrays for citation group
fields, and arrays of arrays for citation fields.
Also take `citationKey` as the central data unit, this is what we start with: unresolved `citationKeys`
do not stop processing. Although we cannot sort them by author and year, we can still emit a marker
that acts as a placeholder and shows the user the problematic key.

## Result

### Layers

![Layers](layers-v1.svg)

### By directories

- `model`
- `util` : general utilities
- (`OOPair`, `OOTuple3`) collect two or three objects without creating a new class
- `OOResult` : while an Optional.empty can comunicate failure, it cannot provide details.
`OOResult` allows an arbitrary error object to be provided in case of failure.
- `OOVoidResult` : for functions returning no result on success, only diagnostics on failure.
- `OOListUtil`: some utilities working on List
- `uno` : helpers for various tasks via UNO.
These are conceptually independent of JabRef code and logic.
- `ootext` : to separate decisions on the format of references and citation marks from
the actual insertion into the document, the earlier method
[OOUtil.insertOOFormattedTextAtCurrentLocation](https://github.com/JabRef/jabref/blob/475b2989ffa8ec61c3327c62ed8f694149f83220/src/main/java/org/jabref/logic/openoffice/OOUtil.java#L112)
was extended to handle new tags that describe actions earlier done in code.
- This became [OOTextIntoOO.write](https://github.com/antalk2/jabref/blob/122d5133fa6c7b44245c5ba5600d398775718664/src/main/java/org/jabref/model/openoffice/ootext/OOTextIntoOO.java#L149)
- `(change)` Now all output to the document goes through this, not only those from Layout. This allows the citation markers and `jstyle:Title` to use these tags.
- This allows some backward-compatible extensions to jstyle.
`(change)` [Added](https://github.com/antalk2/jabref/blob/122d5133fa6c7b44245c5ba5600d398775718664/src/main/java/org/jabref/logic/openoffice/style/OOBibStyle.java#L92)
some extra keywords, in `{prefix}_MARKUP_BEFORE`, `{prefix}_MARKUP_AFTER` pairs to allow bracketing some parts of citation marks with text and/or open/close tag pairs.
- [OOFormat](https://github.com/antalk2/jabref/blob/improve-reversibility-rebased-03/src/main/java/org/jabref/model/openoffice/ootext/OOFormat.java)
contains helpers to create the appropriate tags
- [OOText](https://github.com/antalk2/jabref/blob/improve-reversibility-rebased-03/src/main/java/org/jabref/model/openoffice/ootext/OOText.java) formalizes
the distinction from `String`. I did not change `String` to `OOText` in old code, (in particular in OOStyle).
- `rangesort` : ordering objects that have an `XTextRange`, optionally with an extra integer to break ties.
- `RangeSort.partitionAndSortRanges` : since `XTextRangeCompare` can only compare `XTextRange` values in
the same `XText`, we partition them accordingly and only sort within each partiion.
- `RangeSortable` (interface), `RangeSortEntry` (implements) :
When we replace `XTextRange` of citation marks in footnotes with the range of the footnote mark,
multiple citation marks may be mapped to the same location. To preserve the order between these,
`RangeSortable` allows this order to be indicated by returning appropriate indices from `getIndexInPosition`
- `RangeSortVisual` : sort in top-to-bottom left-to-right order.
Needs a functional `XTextViewCursor`.
Works on `RangeSortable` values.
- `FunctionalTextViewCursor` : helper to get a functional `XTextViewCursor` (cannot always)
- `RangeOverlapWithin` : check for overlaps within a set of `XTextRange` values. Probably O(n*log(n)). Used for all-to-all check of protected ranges.
- `RangeOverlapBetween` : check for overlaps between two sets of `XTextRange` values. Assumes one set is small. O(n*k).
Used for checking if the cursor is in a protected range.
- `backend` : interfaces to be provided by backends.
May change as new backends may need different APIs.
- `style` : data structures and interfaces used while going from ordered list of citation groups
to formatted citation markers and bibliography. Does not communicate with the document. Too long to fit here, starting a new section.

## model/style

At the core,

- we have `Citation` values
- represented in the document by their `citationKey`
- each may have a `pageInfo`
- A citation group (`CitationGroup`) has
- a list of citations (`citationsInStorageOrder`)
- an identifier `CitationGroupId cgid`
- this allows to refer to the group
- also used to associate the group to its citation markers location (outside the style part,
in [Backend](https://github.com/antalk2/jabref/blob/fed0952cbdaf7a76bcb09b3db5ac48f34f5ca388/src/main/java/org/jabref/logic/openoffice/backend/Backend52.java#L46))
- `OODataModel dataModel` is here, in order to handle old (Jabref5.2) structure where pageInfo belonged to
CitationGroup not Citation
- `referenceMarkNameForLinking` is optional: can be used to crosslink to the citation marker
from the bibliography.
- `CitationGroups` represents the collection of citation groups.
Processing starts with creating a `CitationGroups` instance from the data stored in the document.

- `CitedKey` represents a cited source, with ordered backreferences (using `CitationPath`) to the correponding
citations.

- `CitedKeys` is just an order-preserving collection of `CitedKeys` that also supports lookup by
`citationKey`. While producing citation markers, we also create a corresponding `CitedKeys`
instance, and store it in `CitationGroups.bibliography`. This is already sorted, its entries have
`uniqueLetter` or `number` assigned, but not converted to markup yet.

Common processing steps:

- We need `globalOrder` for the citation groups (provided externally)
`CitationGroups.setGlobalOrder()`
- We need to look up each citationKey in the bibliography databases:
- `CitationGroups.lookupCitations` collects the cited keys,
looks up each, then distributes the results to the citations.
Uses a temporary `CitedKeys` instance, based on unsorted citations and citation groups.
- `CitationGroups.imposeLocalOrder` fills `localOrder` in each `CitationGroup`

- Now we have order of appearance for the citations (`globalOrder` and `localOrder`).
We can create a `CitedKeys` instance (`bibliography`) according to this order.

- For citations numbered in order of first appearance we number the sources and distribute the numbers
to the corresponding citations.
- For citations numbered in order of bibliography, we sort the bibliography, number, distribute.

- For author-year citations we have to decide on the letters `uniqueLetter` used to distinguish
sources. This needs order of first appearance of the sources and recognizing clashing citation markers.
This is done in logic, in [`OOProcessAuthorYearMarkers.createUniqueLetters()`](https://github.com/antalk2/jabref/blob/122d5133fa6c7b44245c5ba5600d398775718664/src/main/java/org/jabref/logic/openoffice/style/OOProcessAuthorYearMarkers.java#L49)
- We also mark first appearance of each source ([`setIsFirstAppearanceOfSourceInCitations`](https://github.com/antalk2/jabref/blob/fed0952cbdaf7a76bcb09b3db5ac48f34f5ca388/src/main/java/org/jabref/logic/openoffice/style/OOProcessAuthorYearMarkers.java#L146))

The entry point for this processing is: [`OOProcess.produceCitationMarkers`](https://github.com/antalk2/jabref/blob/fed0952cbdaf7a76bcb09b3db5ac48f34f5ca388/src/main/java/org/jabref/logic/openoffice/style/OOProcess.java#L69).
It fills

- each `CitationGroup.citationMarker`
- `CitationGroups.bibliography`
- From bibliography `OOFormatBibliography.formatBibliography()` creates an `OOText`
ready to be written to the document.


## logic/style

- `StyleLoader` : not changed (knows about default styles) Used by GUI
- `OOPreFormatter` : LaTeX code to unicode and OOText tags. (not changed)
- `OOBibStyle` : is mostly concerned by loading/parsing jstyle files and presenting its pieces
to the rest. Originally it also contains code to format numeric and author-year citation markers.
- Details of their new implementations are in
[`OOBibStyleGetNumCitationMarker`](https://github.com/antalk2/jabref/blob/improve-reversibility-rebased-03/src/main/java/org/jabref/logic/openoffice/style/OOBibStyleGetNumCitationMarker.java) and
[`OOBibStyleGetCitationMarker`](https://github.com/antalk2/jabref/blob/improve-reversibility-rebased-03/src/main/java/org/jabref/logic/openoffice/style/OOBibStyleGetCitationMarker.java)
- The new implementations
- support pageInfo for each citation
- support unresolved citations
- instead of `List<Integer>` and (`List<BibEntry>` plus arrays and database) they expect
more self-contained entries `List<CitationMarkerNumericEntry>`, `List<CitationMarkerEntry>`.
- We have distinct methods for `getNormalizedCitationMarker(CitationMarkerNormEntry)` and
`getNumCitationMarkerForBibliography(CitationMarkerNumericBibEntry)`.
- The corresponding interfaces in model/style:
- `CitationMarkerNumericEntry`
- `CitationMarkerEntry`
- `CitationMarkerNumericBibEntry`
- `CitationMarkerNormEntry`
describe their expected input entries.
- [`OOProcess.produceCitationMarkers`](https://github.com/antalk2/jabref/blob/fed0952cbdaf7a76bcb09b3db5ac48f34f5ca388/src/main/java/org/jabref/logic/openoffice/style/OOProcess.java#L69)
is the main entry point for style application. Calls to specific implementations
in `OOProcessCitationKeyMarkers`, `OOProcessNumericMarkers` and `OOProcessAuthorYearMarkers`
according to jstyle flags.

## logic/backend

Details of encoding and retrieving data stored in a document as well as
the citation maker locations. Also contains dataModel-dependent code
(which could probably be moved out once the datamodel is settled).

Creating and finding the bibliography (providing a cursor to write at) should be here too.
These are currently in `UpdateBibliography`

## logic/frontend

- `OOFrontend` : has a `Backend` and `CitationGroups`
- Its constructor creates a backend, reads data from the document and creates a CitationGroups instance.
- provides functionality that requires both access to the document and the CitationGroups instance
- `RangeForOverlapCheck` used in `OOFrontend`
- `UpdateBibliography` : Create, find and update the bibliography in the document using output from
`produceCitationMarkers()`
- `UpdateCitationMarkers` create `CitationGroup`, update citation markers using output from
`produceCitationMarkers()`


## logic/action

GUI-independent part of implementations of GUI actions.

## gui

- `OOError` : common error messages and dialog titles
- adds `title` to `Jabrefexception`
- converts from some common exception types using type-specific message
- contains some dialog messages that do not correspond to exceptions

- `OOBibBase2` : most activity was moved out from here to parts discussed above.
- connecting / selecting a document moved to `OOBibBaseConnect`
- the rest connects higher parts of the GUI to actions in logic
- does argument and precondition checking
- catches all exceptions
- shows error and warning dialogs
- adds `enterUndoContext`, `leaveUndoContext` around action code

Loading