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

Some OO/LO cleanups #1927

Merged
merged 1 commit into from
Sep 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 11 additions & 11 deletions src/main/java/net/sf/jabref/gui/openoffice/OOBibBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ private XDesktop simpleBootstrap(String pathToExecutable)
} catch (Exception e) {
throw new CreationException(e.getMessage());
}
XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, desktop);
XDesktop resultDesktop = UnoRuntime.queryInterface(XDesktop.class, desktop);

UnoRuntime.queryInterface(XComponentLoader.class, desktop);

return xDesktop;
return resultDesktop;
}

private List<XTextDocument> getTextDocuments() throws NoSuchElementException, WrappedTargetException {
Expand Down Expand Up @@ -339,7 +339,7 @@ public void insertEntry(List<BibEntry> entries, BibDatabase database,
}

String keyString = String.join(",",
entries.stream().map(BibEntry::getCiteKey).collect(Collectors.toList()));
entries.stream().map(entry -> entry.getCiteKeyOptional().orElse("")).collect(Collectors.toList()));
// Insert bookmark:
String bName = getUniqueReferenceMarkName(keyString,
withText ? inParenthesis ? OOBibBase.AUTHORYEAR_PAR : OOBibBase.AUTHORYEAR_INTEXT : OOBibBase.INVISIBLE_CIT);
Expand Down Expand Up @@ -525,8 +525,8 @@ private List<String> refreshCiteMarkersInternal(List<BibDatabase> databases, OOB
StringBuilder sb = new StringBuilder();
normCitMarkers[i] = new String[keys.length];
for (int j = 0; j < keys.length; j++) {
normCitMarkers[i][j] = cEntries[j].getCiteKey();
sb.append(cEntries[j].getCiteKey());
normCitMarkers[i][j] = cEntries[j].getCiteKeyOptional().orElse(null);
sb.append(cEntries[j].getCiteKeyOptional().orElse(""));
if (j < (keys.length - 1)) {
sb.append(',');
}
Expand Down Expand Up @@ -583,7 +583,7 @@ private List<String> refreshCiteMarkersInternal(List<BibDatabase> databases, OOB
}
// Update key list to match the new sorting:
for (int j = 0; j < cEntries.length; j++) {
bibtexKeys[i][j] = cEntries[j].getCiteKey();
bibtexKeys[i][j] = cEntries[j].getCiteKeyOptional().orElse(null);
}
}

Expand Down Expand Up @@ -1013,7 +1013,7 @@ private void insertFullReferenceAtCursor(XTextCursor cursor, Map<BibEntry, BibDa
Layout layout = style.getReferenceFormat(entry.getKey().getType());
layout.setPostFormatter(POSTFORMATTER);
OOUtil.insertFullReferenceAtCurrentLocation(text, cursor, layout, parFormat, entry.getKey(),
entry.getValue(), uniquefiers.get(entry.getKey().getCiteKey()));
entry.getValue(), uniquefiers.get(entry.getKey().getCiteKeyOptional().orElse(null)));
}

}
Expand Down Expand Up @@ -1266,8 +1266,8 @@ public void combineCiteMarkers(List<BibDatabase> databases, OOBibStyle style)
}
}
Collections.sort(entries, new FieldComparator(FieldName.YEAR));
String keyString = String.join(",",
entries.stream().map(BibEntry::getCiteKey).collect(Collectors.toList()));
String keyString = String.join(",", entries.stream().map(entry -> entry.getCiteKeyOptional().orElse(""))
.collect(Collectors.toList()));
// Insert bookmark:
String bName = getUniqueReferenceMarkName(keyString, OOBibBase.AUTHORYEAR_PAR);
insertReferenceMark(bName, "tmp", mxDocCursor, true, style);
Expand Down Expand Up @@ -1366,13 +1366,13 @@ public BibDatabase generateDatabase(List<BibDatabase> databases)
BibEntry clonedEntry = (BibEntry) entry.get().clone();
clonedEntry.setId(IdGenerator.next());
// Insert a copy of the entry
resultDatabase.insertEntryWithDuplicationCheck(clonedEntry);
resultDatabase.insertEntry(clonedEntry);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering: Is it save to remove the duplication check here? The documentation of insertEntryWithDuplicationCheck says use insertEntry and DuplicationChecker separately.

The comment also applies to the replacement below.

// Check if the cloned entry has a crossref field
clonedEntry.getField(FieldName.CROSSREF).ifPresent(crossref -> {
// If the crossref entry is not already in the database
if (!resultDatabase.getEntryByKey(crossref).isPresent()) {
// Add it if it is in the current database
loopDatabase.getEntryByKey(crossref).ifPresent(resultDatabase::insertEntryWithDuplicationCheck);
loopDatabase.getEntryByKey(crossref).ifPresent(resultDatabase::insertEntry);
}
});

Expand Down
30 changes: 19 additions & 11 deletions src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ private void showConnectDialog() {

dialogOkPressed = false;
final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true);

// Path fields
final JTextField ooPath = new JTextField(30);
JButton browseOOPath = new JButton(Localization.lang("Browse"));
ooPath.setText(preferences.getOOPath());
Expand Down Expand Up @@ -575,9 +577,9 @@ private void showConnectDialog() {
builder.add(browseOOJars).xy(5, 3);
}
builder.padding("5dlu, 5dlu, 5dlu, 5dlu");
ButtonBarBuilder bb = new ButtonBarBuilder();
JButton ok = new JButton(Localization.lang("OK"));
JButton cancel = new JButton(Localization.lang("Cancel"));

cDiag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);

ActionListener tfListener = e -> {
preferences.updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText());
cDiag.dispose();
Expand All @@ -586,22 +588,28 @@ private void showConnectDialog() {
ooPath.addActionListener(tfListener);
ooExec.addActionListener(tfListener);
ooJars.addActionListener(tfListener);

// Buttons
JButton ok = new JButton(Localization.lang("OK"));
JButton cancel = new JButton(Localization.lang("Cancel"));

ok.addActionListener(e -> {
preferences.updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText());
dialogOkPressed = true;
cDiag.dispose();
});

cancel.addActionListener(e -> cDiag.dispose());

ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
bb.addRelatedGap();
bb.addButton(ok);
bb.addButton(cancel);
bb.addGlue();
bb.padding("5dlu, 5dlu, 5dlu, 5dlu");
cDiag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
cDiag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);

// Finish and show dialog
cDiag.pack();
cDiag.setLocationRelativeTo(frame);
cDiag.setVisible(true);
Expand All @@ -620,15 +628,15 @@ private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addP
Boolean inParenthesis = inParenthesisIn;
String pageInfo = null;
if (addPageInfo) {
AdvancedCiteDialog acd = new AdvancedCiteDialog(frame);
acd.showDialog();
if (acd.canceled()) {
AdvancedCiteDialog citeDialog = new AdvancedCiteDialog(frame);
citeDialog.showDialog();
if (citeDialog.canceled()) {
return;
}
if (!acd.getPageInfo().isEmpty()) {
pageInfo = acd.getPageInfo();
if (!citeDialog.getPageInfo().isEmpty()) {
pageInfo = citeDialog.getPageInfo();
}
inParenthesis = acd.isInParenthesisCite();
inParenthesis = citeDialog.isInParenthesisCite();

}

Expand Down