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

Feature: Support Citation Style Language (CSL) Styles in LibreOffice/OpenOffice #1

Open
wants to merge 4 commits into
base: csl-lo-oo-integration
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- main
- main-release
- csl-lo-oo-integration
- csl-lo-oo-integration-dev
pull_request:
# always run on pull requests
workflow_dispatch:
Expand Down
2 changes: 2 additions & 0 deletions A_TRASH_FILE_TO_OPEN_PR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
It is required that there should be at least one commit to create a PR, that's why we create this file.
All development will be done in `csl-lo-oo-integration-dev`, and we will merge all the intermediate commit to branch `csl-lo-oo-integration` and open PR with it to upstream.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.jabref.gui.openoffice;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import org.jabref.logic.citationstyle.CitationStyle;

Choose a reason for hiding this comment

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

🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck> reported by reviewdog 🐶
'org.jabref.logic.citationstyle.CitationStyle' should be separated from previous imports.

import org.jabref.logic.openoffice.style.OOBibStyle;

Choose a reason for hiding this comment

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

🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck> reported by reviewdog 🐶
Unused import - org.jabref.logic.openoffice.style.OOBibStyle.


public class StyleSelectCslItemViewModel {

private final StringProperty title = new SimpleStringProperty("");
private final StringProperty file = new SimpleStringProperty("");
private final StringProperty source = new SimpleStringProperty("");

private final CitationStyle style;

public StyleSelectCslItemViewModel(CitationStyle style) {
this.title.setValue(style.getTitle());
this.file.setValue(style.getFilePath());
this.source.setValue(style.getSource());
this.style = style;
}

public StringProperty titleProperty() {
return title;
}

public StringProperty fileProperty() {
return file;
}

public StringProperty sourceProperty() {
return source;
}

public CitationStyle getStyle() {
return style;
}
}
96 changes: 67 additions & 29 deletions src/main/java/org/jabref/gui/openoffice/StyleSelectDialog.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,77 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<DialogPane xmlns:fx="http://javafx.com/fxml/1" minHeight="-Infinity" minWidth="-Infinity" prefHeight="470.0"
prefWidth="701.0" xmlns="http://javafx.com/javafx/8.0.171"
fx:controller="org.jabref.gui.openoffice.StyleSelectDialogView">
<content>
<BorderPane>
<top>
<TableView fx:id="tvStyles" prefHeight="208.0" prefWidth="662.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn fx:id="colName" minWidth="100.0" prefWidth="-1.0" text="%Name"/>
<TableColumn fx:id="colJournals" minWidth="100.0" prefWidth="75.0" text="%Journals"/>
<TableColumn fx:id="colFile" minWidth="100.0" prefWidth="-1.0" text="%File"/>
<TableColumn fx:id="colDeleteIcon" minWidth="100.0" prefWidth="-1.0"/>
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY"/>
</columnResizePolicy>
</TableView>
</top>
<right>
<Button fx:id="add" alignment="TOP_RIGHT" mnemonicParsing="false" onAction="#addStyleFile"
text="%Add style file" BorderPane.alignment="CENTER"/>
</right>
<bottom>
<VBox fx:id="vbox" prefHeight="84.0" prefWidth="665.0" BorderPane.alignment="CENTER"/>
</bottom>
</BorderPane>
</content>

<DialogPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="470.0" prefWidth="701.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.openoffice.StyleSelectDialogView">
<buttonTypes>
<ButtonType fx:constant="CANCEL"/>
<ButtonType fx:constant="OK"/>
<ButtonType fx:constant="CANCEL" />
<ButtonType fx:constant="OK" />
</buttonTypes>
<content>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<center>
<TabPane tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<tabs>
<Tab text="JStyle">
<content>
<AnchorPane>
<children>
<BorderPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<right>
<Button fx:id="add" alignment="TOP_RIGHT" mnemonicParsing="false" onAction="#addStyleFile" text="%Add style file" BorderPane.alignment="CENTER" />
</right>
<top>
<TableView fx:id="tvStyles" prefHeight="208.0" prefWidth="662.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn fx:id="colName" minWidth="100.0" prefWidth="-1.0" text="%Name" />
<TableColumn fx:id="colJournals" minWidth="100.0" prefWidth="75.0" text="%Journals" />
<TableColumn fx:id="colFile" minWidth="100.0" prefWidth="-1.0" text="%File" />
<TableColumn fx:id="colDeleteIcon" minWidth="100.0" prefWidth="-1.0" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</top>
</BorderPane>
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="CSL styles">
<content>
<AnchorPane>
<children>
<BorderPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<center>
<TableView fx:id="cslStyles" prefHeight="208.0" prefWidth="662.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn fx:id="colCslTitle" minWidth="200.0" prefWidth="-1.0" text="%Name" />
<TableColumn fx:id="colCslFile" minWidth="100.0" prefWidth="-1.0" text="%File" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</center>
</BorderPane>
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</center>
<bottom>
<VBox fx:id="vbox" prefHeight="84.0" prefWidth="665.0" BorderPane.alignment="CENTER" />
</bottom>
</BorderPane>
</content>
</DialogPane>
25 changes: 25 additions & 0 deletions src/main/java/org/jabref/gui/openoffice/StyleSelectDialogView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.inject.Inject;

import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
Expand All @@ -19,6 +20,7 @@
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.ValueTableCellFactory;
import org.jabref.gui.util.ViewModelTableRowFactory;
import org.jabref.logic.citationstyle.CitationStyle;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.layout.TextBasedPreviewLayout;
import org.jabref.logic.openoffice.style.OOBibStyle;
Expand All @@ -31,6 +33,8 @@
import com.airhacks.afterburner.views.ViewLoader;
import com.tobiasdiez.easybind.EasyBind;

import java.util.stream.Collectors;

Choose a reason for hiding this comment

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

🚫 [reviewdog] <com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck> reported by reviewdog 🐶
Wrong order for 'java.util.stream.Collectors' import.


public class StyleSelectDialogView extends BaseDialog<OOBibStyle> {

private final MenuItem edit = new MenuItem(Localization.lang("Edit"));
Expand All @@ -43,6 +47,9 @@ public class StyleSelectDialogView extends BaseDialog<OOBibStyle> {
@FXML private TableColumn<StyleSelectItemViewModel, String> colFile;
@FXML private TableColumn<StyleSelectItemViewModel, Boolean> colDeleteIcon;
@FXML private Button add;
@FXML private TableView<StyleSelectCslItemViewModel> cslStyles;
@FXML private TableColumn<StyleSelectCslItemViewModel, String> colCslTitle;
@FXML private TableColumn<StyleSelectCslItemViewModel, String> colCslFile;
@FXML private VBox vbox;

@Inject private PreferencesService preferencesService;
Expand Down Expand Up @@ -88,6 +95,9 @@ private void initialize() {
colFile.setCellValueFactory(cellData -> cellData.getValue().fileProperty());
colDeleteIcon.setCellValueFactory(cellData -> cellData.getValue().internalStyleProperty());

colCslTitle.setCellValueFactory(cellData -> cellData.getValue().titleProperty());
colCslFile.setCellValueFactory(cellData -> cellData.getValue().fileProperty());

new ValueTableCellFactory<StyleSelectItemViewModel, Boolean>()
.withGraphic(internalStyle -> {
if (!internalStyle) {
Expand Down Expand Up @@ -127,6 +137,21 @@ private void initialize() {
previewArticle.setLayout(new TextBasedPreviewLayout(style.getStyle().getReferenceFormat(StandardEntryType.Article)));
previewBook.setLayout(new TextBasedPreviewLayout(style.getStyle().getReferenceFormat(StandardEntryType.Book)));
});

cslStyles.setItems(
CitationStyle.discoverCitationStyles()
.stream()
.map(StyleSelectCslItemViewModel::new)
.collect(Collectors.toCollection(FXCollections::observableArrayList))
);

new ViewModelTableRowFactory<StyleSelectCslItemViewModel>()
.withOnMouseClickedEvent((item, event) -> {
if (event.getClickCount() == 2) {
viewModel.viewCslStyle(item);
}
})
.install(cslStyles);
}

private ContextMenu createContextMenu() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,26 @@ public void viewStyle(StyleSelectItemViewModel item) {
dialogService.showCustomDialogAndWait(item.getStyle().getName(), pane, ButtonType.OK);
}

public void viewCslStyle(StyleSelectCslItemViewModel item) {
DialogPane pane = new DialogPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);
TextArea styleView = new TextArea(item.sourceProperty().getValue());
styleView.setEditable(false);
scrollPane.setContent(styleView);
pane.setContent(scrollPane);
dialogService.showCustomDialogAndWait(item.titleProperty().getValue(), pane, ButtonType.OK);
}

public ObjectProperty<StyleSelectItemViewModel> selectedItemProperty() {
return selectedItem;
}

public void storePrefs() {
List<String> externalStyles = styles.stream().map(this::toOOBibStyle).filter(style -> !style.isInternalStyle()).map(OOBibStyle::getPath).collect(Collectors.toList());
preferences.setExternalStyles(externalStyles);
// TODO: Fit CSL into preferences style
preferences.setCurrentStyle(selectedItem.getValue().getStylePath());
preferencesService.setOpenOfficePreferences(preferences);
}
Expand Down