From 18aba35fcf77fad95577e3213e1eb66f5256cf42 Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 25 Jan 2019 16:36:16 +0100 Subject: [PATCH] Convert OO/LO SidePanel to javafx (#4341) * Convert OO/LO SidePanel to javafx First attempt at converting the OpenOffice side panel * rework first part of select style dialog * add icon to delete style add edit function implement rest of logic * store settings, show path load last selected style subscribe preview panel to changes * update from scence builder * fix ok button wrap preview panel in vbox * add title for canceable progess dialog rework manual connect rework settings popup initialize oo prefs to avoid NPE remove old style dialog * formatting * Create custom dialog which returns a dialog object fix preference storage fix manual path select * pass keybinding repo as dependency * add new dialog for advanced cite todo: find out how to change the values * reload preferences in connect fix passing of prefs fix advanced cite dialog * fix checkstyle add some dialog basics for manage citatiosn * further implement viewModel * implement viewModel fix l10n parts TODO: editing of extra info does not yet work * remove submodule * Display Manage citations as TextFlow in the table Allow editing of page info directly in the table Replace html bold with Text-Bold style * fix checkstyle * rework page info remove old dialog fix l10n set titles add tooltips * use flowpane instead of textflow to prevent table row height increasing * cleanup and fix codacy issues * rework dialogs rework future handling in detect OO installation * rework constructor and rename to CitationEntryViewModel move gui getText to view * fix checkstyle and l10n issues * fix order * fix style file select layout and inline variable' * Add Book as preview as well * change mac default settings to LO path * checkstyle * fix merge error * first part of refactoring * refactor and remove/fix obsolete tests put visible/managed bindings in fxml * Fixes #4576 Store show/hide info of panel in preferences * use progessbar from fxdialogs TODO: Fix execution in fx thread * Fix autodetecting open office paths in background thread Fix saving of settings after auto connect Add notification when connections are cleared remove custom dialog hack * fix checkstyle --- .../java/org/jabref/gui/DialogService.java | 8 +- .../java/org/jabref/gui/FXDialogService.java | 14 +- .../java/org/jabref/gui/SidePaneManager.java | 4 +- .../gui/openoffice/AdvancedCiteDialog.fxml | 30 + .../gui/openoffice/AdvancedCiteDialog.java | 113 --- .../openoffice/AdvancedCiteDialogView.java | 46 + .../AdvancedCiteDialogViewModel.java | 25 + .../openoffice/BibEntryNotFoundException.java | 1 - .../openoffice/CitationEntryViewModel.java | 40 + .../gui/openoffice/CitationManager.java | 237 ------ .../DetectOpenOfficeInstallation.java | 86 +- .../gui/openoffice/ManageCitationsDialog.fxml | 21 + .../openoffice/ManageCitationsDialogView.java | 95 +++ .../ManageCitationsDialogViewModel.java | 73 ++ .../gui/openoffice/ManualConnectDialog.fxml | 43 + .../openoffice/ManualConnectDialogView.java | 90 ++ .../ManualConnectDialogViewModel.java | 79 ++ .../org/jabref/gui/openoffice/OOBibBase.java | 140 ++-- .../gui/openoffice/OpenOfficePanel.java | 786 ++++++++---------- .../gui/openoffice/OpenOfficeSidePanel.java | 24 +- .../gui/openoffice/StyleSelectDialog.fxml | 39 + .../gui/openoffice/StyleSelectDialog.java | 538 ------------ .../gui/openoffice/StyleSelectDialogView.java | 145 ++++ .../StyleSelectDialogViewModel.java | 137 +++ .../openoffice/StyleSelectItemViewModel.java | 59 ++ .../UndefinedCharacterFormatException.java | 1 - .../logic/openoffice/CitationEntry.java | 27 +- .../jabref/logic/openoffice/OOBibStyle.java | 7 +- .../openoffice/OpenOfficePreferences.java | 39 +- .../java/org/jabref/logic/util/TestEntry.java | 13 + .../jabref/preferences/JabRefPreferences.java | 3 + .../preferences/PreferencesService.java | 8 + src/main/resources/l10n/JabRef_en.properties | 11 +- .../logic/openoffice/CitationEntryTest.java | 32 +- 34 files changed, 1443 insertions(+), 1571 deletions(-) create mode 100644 src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.fxml delete mode 100644 src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java create mode 100644 src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialogView.java create mode 100644 src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialogViewModel.java create mode 100644 src/main/java/org/jabref/gui/openoffice/CitationEntryViewModel.java delete mode 100644 src/main/java/org/jabref/gui/openoffice/CitationManager.java create mode 100644 src/main/java/org/jabref/gui/openoffice/ManageCitationsDialog.fxml create mode 100644 src/main/java/org/jabref/gui/openoffice/ManageCitationsDialogView.java create mode 100644 src/main/java/org/jabref/gui/openoffice/ManageCitationsDialogViewModel.java create mode 100644 src/main/java/org/jabref/gui/openoffice/ManualConnectDialog.fxml create mode 100644 src/main/java/org/jabref/gui/openoffice/ManualConnectDialogView.java create mode 100644 src/main/java/org/jabref/gui/openoffice/ManualConnectDialogViewModel.java create mode 100644 src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.fxml delete mode 100644 src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.java create mode 100644 src/main/java/org/jabref/gui/openoffice/StyleSelectDialogView.java create mode 100644 src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java create mode 100644 src/main/java/org/jabref/gui/openoffice/StyleSelectItemViewModel.java diff --git a/src/main/java/org/jabref/gui/DialogService.java b/src/main/java/org/jabref/gui/DialogService.java index 947fa1c66a0..2e105481d1d 100644 --- a/src/main/java/org/jabref/gui/DialogService.java +++ b/src/main/java/org/jabref/gui/DialogService.java @@ -140,7 +140,7 @@ default void showErrorDialogAndWait(Exception exception) { * @return true if the use clicked "YES" otherwise false */ boolean showConfirmationDialogWithOptOutAndWait(String title, String content, - String optOutMessage, Consumer optOutAction); + String optOutMessage, Consumer optOutAction); /** * Create and display a new confirmation dialog. @@ -152,8 +152,8 @@ boolean showConfirmationDialogWithOptOutAndWait(String title, String content, * @return true if the use clicked "YES" otherwise false */ boolean showConfirmationDialogWithOptOutAndWait(String title, String content, - String okButtonLabel, String cancelButtonLabel, - String optOutMessage, Consumer optOutAction); + String okButtonLabel, String cancelButtonLabel, + String optOutMessage, Consumer optOutAction); /** * This will create and display a new dialog of the specified @@ -163,7 +163,7 @@ boolean showConfirmationDialogWithOptOutAndWait(String title, String content, * @return Optional with the pressed Button as ButtonType */ Optional showCustomButtonDialogAndWait(Alert.AlertType type, String title, String content, - ButtonType... buttonTypes); + ButtonType... buttonTypes); /** * This will create and display a new dialog showing a custom {@link DialogPane} diff --git a/src/main/java/org/jabref/gui/FXDialogService.java b/src/main/java/org/jabref/gui/FXDialogService.java index 93470689c79..0d6bc1fecd0 100644 --- a/src/main/java/org/jabref/gui/FXDialogService.java +++ b/src/main/java/org/jabref/gui/FXDialogService.java @@ -74,7 +74,7 @@ private static FXDialog createDialog(AlertType type, String title, String conten } private static FXDialog createDialogWithOptOut(AlertType type, String title, String content, - String optOutMessage, Consumer optOutAction) { + String optOutMessage, Consumer optOutAction) { FXDialog alert = new FXDialog(type, title, true); // Need to force the alert to layout in order to grab the graphic as we are replacing the dialog pane with a custom pane alert.getDialogPane().applyCss(); @@ -180,7 +180,7 @@ public boolean showConfirmationDialogAndWait(String title, String content, Strin @Override public boolean showConfirmationDialogAndWait(String title, String content, - String okButtonLabel, String cancelButtonLabel) { + String okButtonLabel, String cancelButtonLabel) { FXDialog alert = createDialog(AlertType.CONFIRMATION, title, content); ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE); ButtonType cancelButtonType = new ButtonType(cancelButtonLabel, ButtonBar.ButtonData.NO); @@ -190,7 +190,7 @@ public boolean showConfirmationDialogAndWait(String title, String content, @Override public boolean showConfirmationDialogWithOptOutAndWait(String title, String content, - String optOutMessage, Consumer optOutAction) { + String optOutMessage, Consumer optOutAction) { FXDialog alert = createDialogWithOptOut(AlertType.CONFIRMATION, title, content, optOutMessage, optOutAction); alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO); return alert.showAndWait().filter(buttonType -> buttonType == ButtonType.YES).isPresent(); @@ -198,8 +198,8 @@ public boolean showConfirmationDialogWithOptOutAndWait(String title, String cont @Override public boolean showConfirmationDialogWithOptOutAndWait(String title, String content, - String okButtonLabel, String cancelButtonLabel, - String optOutMessage, Consumer optOutAction) { + String okButtonLabel, String cancelButtonLabel, + String optOutMessage, Consumer optOutAction) { FXDialog alert = createDialogWithOptOut(AlertType.CONFIRMATION, title, content, optOutMessage, optOutAction); ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.YES); ButtonType cancelButtonType = new ButtonType(cancelButtonLabel, ButtonBar.ButtonData.NO); @@ -209,7 +209,7 @@ public boolean showConfirmationDialogWithOptOutAndWait(String title, String cont @Override public Optional showCustomButtonDialogAndWait(AlertType type, String title, String content, - ButtonType... buttonTypes) { + ButtonType... buttonTypes) { FXDialog alert = createDialog(type, title, content); alert.getButtonTypes().setAll(buttonTypes); return alert.showAndWait(); @@ -217,7 +217,7 @@ public Optional showCustomButtonDialogAndWait(AlertType type, String @Override public Optional showCustomDialogAndWait(String title, DialogPane contentPane, - ButtonType... buttonTypes) { + ButtonType... buttonTypes) { FXDialog alert = new FXDialog(AlertType.NONE, title); alert.setDialogPane(contentPane); alert.getButtonTypes().setAll(buttonTypes); diff --git a/src/main/java/org/jabref/gui/SidePaneManager.java b/src/main/java/org/jabref/gui/SidePaneManager.java index 5a09bdcd1ab..eef7f01098b 100644 --- a/src/main/java/org/jabref/gui/SidePaneManager.java +++ b/src/main/java/org/jabref/gui/SidePaneManager.java @@ -33,8 +33,8 @@ public SidePaneManager(JabRefPreferences preferences, JabRefFrame frame) { Stream.of( new FileUpdatePanel(this), new GroupSidePane(this, preferences, frame.getDialogService()), - new WebSearchPane(this, preferences, frame), - new OpenOfficeSidePanel(this, openOfficePreferences, frame)) + new WebSearchPane(this, preferences, frame), + new OpenOfficeSidePanel(this, preferences, frame)) .forEach(pane -> components.put(pane.getType(), pane)); if (preferences.getBoolean(JabRefPreferences.GROUP_SIDEPANE_VISIBLE)) { diff --git a/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.fxml b/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.fxml new file mode 100644 index 00000000000..1127c2e08d7 --- /dev/null +++ b/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.fxml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java b/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java deleted file mode 100644 index 2a2d48ef26e..00000000000 --- a/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialog.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.jabref.gui.openoffice; - -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JRadioButton; -import javax.swing.JTextField; - -import org.jabref.Globals; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.logic.l10n.Localization; - -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; - -/** - * Dialog for adding citation with page number info. - */ -class AdvancedCiteDialog { - - private static boolean defaultInPar = true; - private boolean okPressed; - private final JDialog diag; - private final JTextField pageInfo = new JTextField(15); - - - public AdvancedCiteDialog(JabRefFrame parent) { - diag = new JDialog((JFrame) null, Localization.lang("Cite special"), true); - ButtonGroup bg = new ButtonGroup(); - JRadioButton inPar = new JRadioButton(Localization.lang("Cite selected entries between parenthesis")); - JRadioButton inText = new JRadioButton(Localization.lang("Cite selected entries with in-text citation")); - bg.add(inPar); - bg.add(inText); - if (defaultInPar) { - inPar.setSelected(true); - } else { - inText.setSelected(true); - } - - inPar.addChangeListener(changeEvent -> defaultInPar = inPar.isSelected()); - - FormBuilder builder = FormBuilder.create() - .layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref, 4dlu, pref")); - builder.add(inPar).xyw(1, 1, 3); - builder.add(inText).xyw(1, 3, 3); - builder.add(Localization.lang("Extra information (e.g. page number)") + ":").xy(1, 5); - builder.add(pageInfo).xy(3, 5); - builder.padding("10dlu, 10dlu, 10dlu, 10dlu"); - diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER); - - ButtonBarBuilder bb = new ButtonBarBuilder(); - bb.addGlue(); - JButton ok = new JButton(Localization.lang("OK")); - JButton cancel = new JButton(Localization.lang("Cancel")); - bb.addButton(ok); - bb.addButton(cancel); - bb.addGlue(); - bb.padding("5dlu, 5dlu, 5dlu, 5dlu"); - diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH); - - diag.pack(); - - ActionListener okAction = actionEvent -> { - okPressed = true; - diag.dispose(); - }; - - ok.addActionListener(okAction); - pageInfo.addActionListener(okAction); - inPar.addActionListener(okAction); - inText.addActionListener(okAction); - Action cancelAction = new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent actionEvent) { - okPressed = false; - diag.dispose(); - } - }; - cancel.addActionListener(cancelAction); - builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) - .put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close"); - builder.getPanel().getActionMap().put("close", cancelAction); - - } - - public void showDialog() { - diag.setLocationRelativeTo(diag.getParent()); - diag.setVisible(true); - } - - public boolean canceled() { - return !okPressed; - } - - public String getPageInfo() { - return pageInfo.getText().trim(); - } - - public boolean isInParenthesisCite() { - return defaultInPar; - } -} diff --git a/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialogView.java b/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialogView.java new file mode 100644 index 00000000000..f12e34fcdbe --- /dev/null +++ b/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialogView.java @@ -0,0 +1,46 @@ +package org.jabref.gui.openoffice; + +import javafx.fxml.FXML; +import javafx.scene.control.ButtonType; +import javafx.scene.control.RadioButton; +import javafx.scene.control.TextField; +import javafx.scene.control.ToggleGroup; + +import org.jabref.gui.util.BaseDialog; +import org.jabref.logic.l10n.Localization; + +import com.airhacks.afterburner.views.ViewLoader; + +public class AdvancedCiteDialogView extends BaseDialog { + + @FXML private TextField pageInfo; + @FXML private RadioButton inPar; + @FXML private RadioButton inText; + @FXML private ToggleGroup citeToggleGroup; + private AdvancedCiteDialogViewModel viewModel; + + public AdvancedCiteDialogView() { + + ViewLoader.view(this) + .load() + .setAsDialogPane(this); + setResultConverter(btn -> { + if (btn == ButtonType.OK) { + return viewModel; + } + return null; + }); + + setTitle(Localization.lang("Cite special")); + } + + @FXML + private void initialize() { + viewModel = new AdvancedCiteDialogViewModel(); + + inPar.selectedProperty().bindBidirectional(viewModel.citeInParProperty()); + inText.selectedProperty().bindBidirectional(viewModel.citeInTextProperty()); + pageInfo.textProperty().bindBidirectional(viewModel.pageInfoProperty()); + + } +} diff --git a/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialogViewModel.java b/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialogViewModel.java new file mode 100644 index 00000000000..c62abfeccec --- /dev/null +++ b/src/main/java/org/jabref/gui/openoffice/AdvancedCiteDialogViewModel.java @@ -0,0 +1,25 @@ +package org.jabref.gui.openoffice; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +public class AdvancedCiteDialogViewModel { + + private final StringProperty pageInfo = new SimpleStringProperty(""); + private final BooleanProperty citeInPar = new SimpleBooleanProperty(); + private final BooleanProperty citeInText = new SimpleBooleanProperty(); + + public StringProperty pageInfoProperty() { + return pageInfo; + } + + public BooleanProperty citeInParProperty() { + return citeInPar; + } + + public BooleanProperty citeInTextProperty() { + return citeInText; + } +} diff --git a/src/main/java/org/jabref/gui/openoffice/BibEntryNotFoundException.java b/src/main/java/org/jabref/gui/openoffice/BibEntryNotFoundException.java index 15dde84a5fb..3a83f8c7177 100644 --- a/src/main/java/org/jabref/gui/openoffice/BibEntryNotFoundException.java +++ b/src/main/java/org/jabref/gui/openoffice/BibEntryNotFoundException.java @@ -4,7 +4,6 @@ class BibEntryNotFoundException extends Exception { private final String bibtexKey; - public BibEntryNotFoundException(String bibtexKey, String message) { super(message); diff --git a/src/main/java/org/jabref/gui/openoffice/CitationEntryViewModel.java b/src/main/java/org/jabref/gui/openoffice/CitationEntryViewModel.java new file mode 100644 index 00000000000..58ac9f04ecd --- /dev/null +++ b/src/main/java/org/jabref/gui/openoffice/CitationEntryViewModel.java @@ -0,0 +1,40 @@ +package org.jabref.gui.openoffice; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +import org.jabref.logic.openoffice.CitationEntry; + +public class CitationEntryViewModel { + + private final StringProperty citation = new SimpleStringProperty(""); + private final StringProperty extraInformation = new SimpleStringProperty(""); + private final String refMarkName; + + public CitationEntryViewModel(String refMarkName, String citation, String extraInfo) { + this.refMarkName = refMarkName; + this.citation.setValue(citation); + this.extraInformation.setValue(extraInfo); + } + + public CitationEntryViewModel(CitationEntry citationEntry) { + this(citationEntry.getRefMarkName(), citationEntry.getContext(), citationEntry.getPageInfo().orElse("")); + } + + public CitationEntry toCitationEntry() { + return new CitationEntry(refMarkName, citation.getValue(), extraInformation.getValue()); + } + + public StringProperty citationProperty() { + return citation; + } + + public StringProperty extraInformationProperty() { + return extraInformation; + } + + public void setExtraInfo(String extraInfo) { + extraInformation.setValue(extraInfo); + } + +} diff --git a/src/main/java/org/jabref/gui/openoffice/CitationManager.java b/src/main/java/org/jabref/gui/openoffice/CitationManager.java deleted file mode 100644 index ae75d693d95..00000000000 --- a/src/main/java/org/jabref/gui/openoffice/CitationManager.java +++ /dev/null @@ -1,237 +0,0 @@ -package org.jabref.gui.openoffice; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.List; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextField; - -import org.jabref.Globals; -import org.jabref.gui.DialogService; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.openoffice.CitationEntry; - -import ca.odell.glazedlists.BasicEventList; -import ca.odell.glazedlists.EventList; -import ca.odell.glazedlists.gui.TableFormat; -import ca.odell.glazedlists.swing.DefaultEventTableModel; -import com.jgoodies.forms.builder.ButtonBarBuilder; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import com.sun.star.beans.IllegalTypeException; -import com.sun.star.beans.NotRemoveableException; -import com.sun.star.beans.PropertyExistException; -import com.sun.star.beans.UnknownPropertyException; -import com.sun.star.container.NoSuchElementException; -import com.sun.star.container.XNameAccess; -import com.sun.star.lang.IllegalArgumentException; -import com.sun.star.lang.WrappedTargetException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Dialog for modifying existing citations. - */ -class CitationManager { - - private static final Logger LOGGER = LoggerFactory.getLogger(CitationManager.class); - private final OOBibBase ooBase; - private final JDialog diag; - private final EventList list; - private final JTable table; - - private final DefaultEventTableModel tableModel; - - public CitationManager(OOBibBase ooBase, DialogService dialogService) - throws NoSuchElementException, WrappedTargetException, UnknownPropertyException { - diag = new JDialog((JFrame) null, Localization.lang("Manage citations"), true); - this.ooBase = ooBase; - - list = new BasicEventList<>(); - XNameAccess nameAccess = ooBase.getReferenceMarks(); - List names = ooBase.getJabRefReferenceMarks(nameAccess); - for (String name : names) { - list.add(new CitationEntry(name, - "..." + ooBase.getCitationContext(nameAccess, name, 30, 30, true) + "...", - ooBase.getCustomProperty(name))); - } - tableModel = new DefaultEventTableModel<>(list, new CitationEntryFormat()); - table = new JTable(tableModel); - - diag.add(new JScrollPane(table), BorderLayout.CENTER); - - ButtonBarBuilder bb = new ButtonBarBuilder(); - bb.addGlue(); - JButton ok = new JButton(Localization.lang("OK")); - bb.addButton(ok); - JButton cancel = new JButton(Localization.lang("Cancel")); - bb.addButton(cancel); - bb.addGlue(); - bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - diag.add(bb.getPanel(), BorderLayout.SOUTH); - - diag.pack(); - diag.setSize(700, 400); - - ok.addActionListener(e -> { - try { - storeSettings(); - } catch (UnknownPropertyException | NotRemoveableException | PropertyExistException | IllegalTypeException | - IllegalArgumentException ex) { - LOGGER.warn("Problem modifying citation", ex); - dialogService.showErrorDialogAndWait(Localization.lang("Problem modifying citation"), ex); - } - diag.dispose(); - }); - - Action cancelAction = new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent actionEvent) { - diag.dispose(); - } - }; - cancel.addActionListener(cancelAction); - - bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put - (Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close"); - bb.getPanel().getActionMap().put("close", cancelAction); - - table.getColumnModel().getColumn(0).setPreferredWidth(580); - table.getColumnModel().getColumn(1).setPreferredWidth(110); - table.setPreferredScrollableViewportSize(new Dimension(700, 500)); - table.addMouseListener(new TableClickListener()); - } - - private void storeSettings() throws UnknownPropertyException, NotRemoveableException, PropertyExistException, - IllegalTypeException, IllegalArgumentException { - for (CitationEntry entry : list) { - Optional pageInfo = entry.getPageInfo(); - if (entry.pageInfoChanged() && pageInfo.isPresent()) { - ooBase.setCustomProperty(entry.getRefMarkName(), pageInfo.get()); - } - } - } - - public void showDialog() { - diag.setLocationRelativeTo(diag.getParent()); - diag.setVisible(true); - } - - private static class CitationEntryFormat implements TableFormat { - - @Override - public int getColumnCount() { - return 2; - } - - @Override - public String getColumnName(int i) { - if (i == 0) { - return Localization.lang("Citation"); - } else { - return Localization.lang("Extra information"); - } - } - - @Override - public Object getColumnValue(CitationEntry citEntry, int i) { - if (i == 0) { - return citEntry.getContext(); - } else { - return citEntry.getPageInfo().orElse(""); - } - } - } - - private class TableClickListener extends MouseAdapter { - - @Override - public void mouseClicked(MouseEvent e) { - if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2)) { - int row = table.rowAtPoint(e.getPoint()); - if (row >= 0) { - SingleCitationDialog scd = new SingleCitationDialog(list.get(row)); - scd.showDialog(); - } - } - } - } - - class SingleCitationDialog { - - private final JDialog singleCiteDialog; - private final JTextField pageInfo = new JTextField(20); - private final JButton okButton = new JButton(Localization.lang("OK")); - private final JButton cancelButton = new JButton(Localization.lang("Cancel")); - private final CitationEntry entry; - - - public SingleCitationDialog(CitationEntry citEntry) { - this.entry = citEntry; - pageInfo.setText(entry.getPageInfo().orElse("")); - - singleCiteDialog = new JDialog(CitationManager.this.diag, Localization.lang("Citation"), true); - - FormBuilder builder = FormBuilder.create() - .layout(new FormLayout("left:pref, 4dlu, fill:150dlu:grow", "pref, 4dlu, pref")); - builder.add(entry.getContext()).xyw(1, 1, 3); - builder.add(Localization.lang("Extra information (e.g. page number)")).xy(1, 3); - builder.add(pageInfo).xy(3, 3); - builder.padding("10dlu, 10dlu, 10dlu, 10dlu"); - singleCiteDialog.getContentPane().add(builder.getPanel(), BorderLayout.CENTER); - - ButtonBarBuilder bb = new ButtonBarBuilder(); - bb.addGlue(); - bb.addButton(okButton); - bb.addButton(cancelButton); - bb.addGlue(); - bb.padding("5dlu, 5dlu, 5dlu, 5dlu"); - singleCiteDialog.add(bb.getPanel(), BorderLayout.SOUTH); - - okButton.addActionListener(e -> { - if (pageInfo.getText().trim().isEmpty()) { - entry.setPageInfo(null); - } else { - entry.setPageInfo(pageInfo.getText().trim()); - } - tableModel.fireTableDataChanged(); - singleCiteDialog.dispose(); - }); - - Action cancelAction = new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent actionEvent) { - singleCiteDialog.dispose(); - } - }; - cancelButton.addActionListener(cancelAction); - - builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put - (Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close"); - builder.getPanel().getActionMap().put("close", cancelAction); - - } - - public void showDialog() { - singleCiteDialog.pack(); - singleCiteDialog.setLocationRelativeTo(singleCiteDialog.getParent()); - singleCiteDialog.setVisible(true); - } - } -} diff --git a/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java b/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java index 55853091840..1f4a892f14a 100644 --- a/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java +++ b/src/main/java/org/jabref/gui/openoffice/DetectOpenOfficeInstallation.java @@ -1,83 +1,57 @@ package org.jabref.gui.openoffice; -import java.awt.BorderLayout; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; -import javax.swing.BorderFactory; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JProgressBar; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; - -import org.jabref.Globals; import org.jabref.gui.DialogService; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.desktop.os.NativeDesktop; -import org.jabref.gui.util.BackgroundTask; -import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.DirectoryDialogConfiguration; import org.jabref.logic.l10n.Localization; import org.jabref.logic.openoffice.OpenOfficeFileSearch; import org.jabref.logic.openoffice.OpenOfficePreferences; import org.jabref.logic.util.OS; import org.jabref.logic.util.io.FileUtil; +import org.jabref.model.strings.StringUtil; +import org.jabref.preferences.JabRefPreferences; /** * Tools for automatically detecting OpenOffice or LibreOffice installations. */ public class DetectOpenOfficeInstallation { - private final OpenOfficePreferences preferences; - private final JDialog parent; + private final OpenOfficePreferences ooPrefs; private final DialogService dialogService; + private final JabRefPreferences preferences; - private JDialog progressDialog; - - public DetectOpenOfficeInstallation(JDialog parent, OpenOfficePreferences preferences, DialogService dialogService) { - this.parent = parent; + public DetectOpenOfficeInstallation(JabRefPreferences preferences, DialogService dialogService) { this.preferences = preferences; this.dialogService = dialogService; + this.ooPrefs = preferences.getOpenOfficePreferences(); } - public Future isInstalled() { - CompletableFuture future = new CompletableFuture<>(); - if (this.checkAutoDetectedPaths(preferences)) { - future.complete(true); - } else { - init(); - BackgroundTask.wrap(() -> future.complete(autoDetectPaths())) - .onSuccess(x -> SwingUtilities.invokeLater(progressDialog::dispose)) - .executeWith(Globals.TASK_EXECUTOR); - } - return future; + public boolean isInstalled() { + return autoDetectPaths(); } - public void init() { - progressDialog = showProgressDialog(parent, Localization.lang("Autodetecting paths..."), - Localization.lang("Please wait...")); + public boolean isExecutablePathDefined() { + return checkAutoDetectedPaths(ooPrefs); } private Optional selectInstallationPath() { final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop(); - Optional path = DefaultTaskExecutor.runInJavaFXThread(() -> { - dialogService.showInformationDialogAndWait(Localization.lang("Could not find OpenOffice/LibreOffice installation"), - Localization.lang("Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually.")); - DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(nativeDesktop.getApplicationDirectory()) - .build(); - return dialogService.showDirectorySelectionDialog(dirDialogConfiguration); - }); + dialogService.showInformationDialogAndWait(Localization.lang("Could not find OpenOffice/LibreOffice installation"), + Localization.lang("Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually.")); + DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() + .withInitialDirectory(nativeDesktop.getApplicationDirectory()) + .build(); + return dialogService.showDirectorySelectionDialog(dirDialogConfiguration); - return path; } private boolean autoDetectPaths() { @@ -102,7 +76,7 @@ private boolean autoDetectPaths() { */ private boolean checkAutoDetectedPaths(OpenOfficePreferences openOfficePreferences) { String executablePath = openOfficePreferences.getExecutablePath(); - return ((executablePath != null) && Files.exists(Paths.get(executablePath))); + return !StringUtil.isNullOrEmpty(executablePath) && Files.exists(Paths.get(executablePath)); } private boolean setOpenOfficePreferences(Path installDir) { @@ -119,9 +93,10 @@ private boolean setOpenOfficePreferences(Path installDir) { Optional jarFilePath = FileUtil.find(OpenOfficePreferences.OO_JARS.get(0), installDir); if (execPath.isPresent() && jarFilePath.isPresent()) { - preferences.setInstallationPath(installDir.toString()); - preferences.setExecutablePath(execPath.get().toString()); - preferences.setJarsPath(jarFilePath.get().getParent().toString()); + ooPrefs.setInstallationPath(installDir.toString()); + ooPrefs.setExecutablePath(execPath.get().toString()); + ooPrefs.setJarsPath(jarFilePath.get().getParent().toString()); + preferences.setOpenOfficePreferences(ooPrefs); return true; } @@ -138,25 +113,12 @@ private Optional chooseAmongInstallations(List installDirs) { } String content = Localization.lang("Found more than one OpenOffice/LibreOffice executable.") - + "\n" + Localization.lang("Please choose which one to connect to:"); + + "\n" + Localization.lang("Please choose which one to connect to:"); - Optional selectedPath = DefaultTaskExecutor.runInJavaFXThread(() -> dialogService.showChoiceDialogAndWait( - Localization.lang("Choose OpenOffice/LibreOffice executable"), - content, Localization.lang("Use selected instance"), installDirs)); + Optional selectedPath = dialogService.showChoiceDialogAndWait(Localization.lang("Choose OpenOffice/LibreOffice executable"), + content, Localization.lang("Use selected instance"), installDirs); return selectedPath; } - public JDialog showProgressDialog(JDialog progressParent, String title, String message) { - JProgressBar bar = new JProgressBar(SwingConstants.HORIZONTAL); - final JDialog progressDialog = new JDialog(progressParent, title, false); - bar.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - bar.setIndeterminate(true); - progressDialog.add(new JLabel(message), BorderLayout.NORTH); - progressDialog.add(bar, BorderLayout.CENTER); - progressDialog.pack(); - progressDialog.setLocationRelativeTo(null); - progressDialog.setVisible(true); - return progressDialog; - } } diff --git a/src/main/java/org/jabref/gui/openoffice/ManageCitationsDialog.fxml b/src/main/java/org/jabref/gui/openoffice/ManageCitationsDialog.fxml new file mode 100644 index 00000000000..bde42841ce5 --- /dev/null +++ b/src/main/java/org/jabref/gui/openoffice/ManageCitationsDialog.fxml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/jabref/gui/openoffice/ManageCitationsDialogView.java b/src/main/java/org/jabref/gui/openoffice/ManageCitationsDialogView.java new file mode 100644 index 00000000000..1f50783e89f --- /dev/null +++ b/src/main/java/org/jabref/gui/openoffice/ManageCitationsDialogView.java @@ -0,0 +1,95 @@ +package org.jabref.gui.openoffice; + +import javax.inject.Inject; + +import javafx.fxml.FXML; +import javafx.scene.Node; +import javafx.scene.control.ButtonType; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableColumn.CellEditEvent; +import javafx.scene.control.TableView; +import javafx.scene.control.cell.TextFieldTableCell; +import javafx.scene.layout.FlowPane; +import javafx.scene.text.Text; + +import org.jabref.gui.DialogService; +import org.jabref.gui.util.BaseDialog; +import org.jabref.gui.util.ValueTableCellFactory; +import org.jabref.logic.l10n.Localization; +import org.jabref.model.strings.StringUtil; + +import com.airhacks.afterburner.views.ViewLoader; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.lang.WrappedTargetException; + +public class ManageCitationsDialogView extends BaseDialog { + + private static final String HTML_BOLD_END_TAG = ""; + private static final String HTML_BOLD_START_TAG = ""; + + private final OOBibBase ooBase; + + @FXML private TableView citationsTableView; + @FXML private TableColumn citation; + @FXML private TableColumn extraInfo; + + @Inject private DialogService dialogService; + + private ManageCitationsDialogViewModel viewModel; + + public ManageCitationsDialogView(OOBibBase ooBase) { + this.ooBase = ooBase; + + + ViewLoader.view(this) + .load() + .setAsDialogPane(this); + + setResultConverter(btn -> { + if (btn == ButtonType.OK) { + viewModel.storeSettings(); + } + return null; + }); + + setTitle(Localization.lang("Manage citations")); + } + + @FXML + private void initialize() throws NoSuchElementException, WrappedTargetException, UnknownPropertyException { + + viewModel = new ManageCitationsDialogViewModel(ooBase, dialogService); + + citation.setCellValueFactory(cellData -> cellData.getValue().citationProperty()); + new ValueTableCellFactory().withGraphic(this::getText).install(citation); + + extraInfo.setCellValueFactory(cellData -> cellData.getValue().extraInformationProperty()); + extraInfo.setEditable(true); + + citationsTableView.setEditable(true); + + citationsTableView.itemsProperty().bindBidirectional(viewModel.citationsProperty()); + + extraInfo.setOnEditCommit((CellEditEvent cell) -> { + cell.getRowValue().setExtraInfo(cell.getNewValue()); + }); + extraInfo.setCellFactory(TextFieldTableCell.forTableColumn()); + + } + + private Node getText(String citationContext) { + + String inBetween = StringUtil.substringBetween(citationContext, HTML_BOLD_START_TAG, HTML_BOLD_END_TAG); + String start = citationContext.substring(0, citationContext.indexOf(HTML_BOLD_START_TAG)); + String end = citationContext.substring(citationContext.lastIndexOf(HTML_BOLD_END_TAG) + HTML_BOLD_END_TAG.length(), citationContext.length()); + + Text startText = new Text(start); + Text inBetweenText = new Text(inBetween); + inBetweenText.setStyle("-fx-font-weight: bold"); + Text endText = new Text(end); + + FlowPane flow = new FlowPane(startText, inBetweenText, endText); + return flow; + } +} diff --git a/src/main/java/org/jabref/gui/openoffice/ManageCitationsDialogViewModel.java b/src/main/java/org/jabref/gui/openoffice/ManageCitationsDialogViewModel.java new file mode 100644 index 00000000000..e928f5ee673 --- /dev/null +++ b/src/main/java/org/jabref/gui/openoffice/ManageCitationsDialogViewModel.java @@ -0,0 +1,73 @@ +package org.jabref.gui.openoffice; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import javafx.beans.property.ListProperty; +import javafx.beans.property.SimpleListProperty; +import javafx.collections.FXCollections; + +import org.jabref.gui.DialogService; +import org.jabref.logic.l10n.Localization; +import org.jabref.logic.openoffice.CitationEntry; + +import com.sun.star.beans.IllegalTypeException; +import com.sun.star.beans.NotRemoveableException; +import com.sun.star.beans.PropertyExistException; +import com.sun.star.beans.UnknownPropertyException; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.container.XNameAccess; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.lang.WrappedTargetException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ManageCitationsDialogViewModel { + + private static final Logger LOGGER = LoggerFactory.getLogger(ManageCitationsDialogViewModel.class); + + private final ListProperty citations = new SimpleListProperty<>(FXCollections.observableArrayList()); + private final OOBibBase ooBase; + private final DialogService dialogService; + + public ManageCitationsDialogViewModel(OOBibBase ooBase, DialogService dialogService) throws NoSuchElementException, WrappedTargetException, UnknownPropertyException { + this.ooBase = ooBase; + this.dialogService = dialogService; + + XNameAccess nameAccess = ooBase.getReferenceMarks(); + List names = ooBase.getJabRefReferenceMarks(nameAccess); + for (String name : names) { + + CitationEntry entry = new CitationEntry(name, + ooBase.getCitationContext(nameAccess, name, 30, 30, true), + ooBase.getCustomProperty(name)); + + CitationEntryViewModel itemViewModelEntry = new CitationEntryViewModel(entry); + citations.add(itemViewModelEntry); + } + + } + + public void storeSettings() { + List ciationEntries = citations.stream().map(CitationEntryViewModel::toCitationEntry).collect(Collectors.toList()); + try { + for (CitationEntry entry : ciationEntries) { + Optional pageInfo = entry.getPageInfo(); + if (pageInfo.isPresent()) { + ooBase.setCustomProperty(entry.getRefMarkName(), pageInfo.get()); + } + } + } catch (UnknownPropertyException | NotRemoveableException | PropertyExistException | IllegalTypeException | + IllegalArgumentException ex) { + LOGGER.warn("Problem modifying citation", ex); + dialogService.showErrorDialogAndWait(Localization.lang("Problem modifying citation"), ex); + } + } + + public ListProperty citationsProperty() { + return citations; + } + +} + diff --git a/src/main/java/org/jabref/gui/openoffice/ManualConnectDialog.fxml b/src/main/java/org/jabref/gui/openoffice/ManualConnectDialog.fxml new file mode 100644 index 00000000000..751462763d6 --- /dev/null +++ b/src/main/java/org/jabref/gui/openoffice/ManualConnectDialog.fxml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +