From 9a902fba3ebbef41626067f82b1cec1ae8458b9c Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sun, 11 Sep 2016 12:04:53 +0200 Subject: [PATCH] Some OO/LO cleanups (#1927) --- .../sf/jabref/gui/openoffice/OOBibBase.java | 22 +++++++------- .../gui/openoffice/OpenOfficePanel.java | 30 ++++++++++++------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/openoffice/OOBibBase.java b/src/main/java/net/sf/jabref/gui/openoffice/OOBibBase.java index 7fd26f2f331e..855abb638964 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OOBibBase.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OOBibBase.java @@ -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 getTextDocuments() throws NoSuchElementException, WrappedTargetException { @@ -339,7 +339,7 @@ public void insertEntry(List 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); @@ -525,8 +525,8 @@ private List refreshCiteMarkersInternal(List 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(','); } @@ -583,7 +583,7 @@ private List refreshCiteMarkersInternal(List 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); } } @@ -1013,7 +1013,7 @@ private void insertFullReferenceAtCursor(XTextCursor cursor, Map 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); @@ -1366,13 +1366,13 @@ public BibDatabase generateDatabase(List databases) BibEntry clonedEntry = (BibEntry) entry.get().clone(); clonedEntry.setId(IdGenerator.next()); // Insert a copy of the entry - resultDatabase.insertEntryWithDuplicationCheck(clonedEntry); + resultDatabase.insertEntry(clonedEntry); // 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); } }); diff --git a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java index d2e5fd9b8d4e..ac70c732dd91 100644 --- a/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java @@ -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()); @@ -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(); @@ -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); @@ -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(); }