Skip to content

Commit

Permalink
Basic ui support for CSL in OO/LO
Browse files Browse the repository at this point in the history
  • Loading branch information
cnwangjihe committed Jul 14, 2022
1 parent 458de5b commit 9d40be2
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 29 deletions.
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;
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;

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

0 comments on commit 9d40be2

Please sign in to comment.