Skip to content

Commit

Permalink
Rework
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed Aug 8, 2017
1 parent 690def5 commit 3156930
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 223 deletions.
7 changes: 6 additions & 1 deletion src/main/java/org/jabref/gui/AbstractView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui;

import java.util.Optional;
import java.util.function.Function;

import javafx.scene.Parent;
import javafx.stage.Stage;
Expand All @@ -11,7 +12,11 @@

public class AbstractView extends FXMLView {
public AbstractView() {
super();
this(f -> null);
}

public AbstractView(Function<String, Object> injectionContext) {
super(injectionContext);

// Set resource bundle to internal localizations
bundle = Localization.getMessages();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private void addTabs(String lastTabName) {
tabs.add(new MathSciNetTab(entry));
FileAnnotationCache annotationCache = panel.getAnnotationCache();
tabs.add(new FileAnnotationTab(entry, this, annotationCache));
tabs.add(new FxFileAnnotationTab(frame, panel, this, annotationCache));
tabs.add(new FxFileAnnotationTab(this, annotationCache));
tabs.add(new RelatedArticlesTab(entry));

// Source tab
Expand Down

This file was deleted.

31 changes: 31 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/FileAnnotationTab.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import org.controlsfx.control.MasterDetailPane?>
<ScrollPane xmlns:fx="http://javafx.com/fxml/1" fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER"
styleClass="fileAnnotationTab" xmlns="http://javafx.com/javafx/8.0.112"
fx:controller="org.jabref.gui.entryeditor.FileAnnotationTabController">
<MasterDetailPane prefHeight="581.0" prefWidth="488.0">
<masterNode>
<BorderPane>
<top>
<HBox>
<Label text="%Filename"/>
<ComboBox fx:id="files" maxWidth="Infinity" HBox.hgrow="ALWAYS"/>
</HBox>
</top>
<center>
<ListView fx:id="annotationList"/>
</center>
</BorderPane>
</masterNode>
<detailNode>

</detailNode>
</MasterDetailPane>
</ScrollPane>
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.jabref.gui.entryeditor;

import javax.inject.Inject;

import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.SelectionMode;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;

import org.jabref.gui.AbstractController;
import org.jabref.gui.util.ViewModelListCellFactory;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.pdf.FileAnnotationCache;
import org.jabref.model.entry.BibEntry;

public class FileAnnotationTabController extends AbstractController<FileAnnotationTabViewModel> {

@FXML ComboBox<String> files;
@FXML ListView<FileAnnotationViewModel> annotationList;

@Inject private FileAnnotationCache fileAnnotationCache;
@Inject private BibEntry entry;

@FXML
public void initialize() {
viewModel = new FileAnnotationTabViewModel(fileAnnotationCache, entry);

// Set-up files list
files.getItems().setAll(viewModel.filesProperty().get());
files.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> viewModel.notifyNewSelectedFile(newValue));
files.getSelectionModel().selectFirst();

// Set-up annotation list
annotationList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
annotationList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> viewModel.notifyNewSelectedAnnotation(newValue));
ViewModelListCellFactory<FileAnnotationViewModel> cellFactory = new ViewModelListCellFactory<FileAnnotationViewModel>()
.withTooltip(FileAnnotationViewModel::getDescription)
.withGraphic(annotation -> {
VBox node = new VBox();

Text text = new Text();
text.setText(annotation.getContent());
text.getStyleClass().setAll("text");

HBox details = new HBox();
details.getStyleClass().setAll("details");
Text page = new Text();
page.setText(Localization.lang("Page: ") + Integer.toString(annotation.getPage()));
Text author = new Text();
author.setText(Localization.lang("Author: ") + annotation.getAuthor());
details.getChildren().addAll(page, author);

node.getChildren().addAll(text, details);
node.setMaxWidth(Control.USE_PREF_SIZE);
return node;
});
annotationList.setCellFactory(cellFactory);
annotationList.setPlaceholder(new Label(Localization.lang("File has no attached annotations")));
Bindings.bindContent(annotationList.itemsProperty().get(), viewModel.annotationsProperty());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.jabref.gui.entryeditor;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

import org.jabref.gui.AbstractView;
import org.jabref.logic.pdf.FileAnnotationCache;
import org.jabref.model.entry.BibEntry;

public class FileAnnotationTabView extends AbstractView {

public FileAnnotationTabView(BibEntry entry, FileAnnotationCache fileAnnotationCache) {
super(createContext(entry, fileAnnotationCache));
}

private static Function<String, Object> createContext(BibEntry entry, FileAnnotationCache fileAnnotationCache) {
Map<String, Object> context = new HashMap<>();
context.put("entry", entry);
context.put("fileAnnotationCache", fileAnnotationCache);
return context::get;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.jabref.gui.entryeditor;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;

import org.jabref.gui.AbstractViewModel;
import org.jabref.logic.pdf.FileAnnotationCache;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.pdf.FileAnnotation;

public class FileAnnotationTabViewModel extends AbstractViewModel {

private final ListProperty<FileAnnotationViewModel> annotations = new SimpleListProperty<>(FXCollections.observableArrayList());
private final ListProperty<String> files = new SimpleListProperty<>(FXCollections.observableArrayList());
private Map<String, List<FileAnnotation>> fileAnnotations;
private StringProperty currentAuthor = new SimpleStringProperty();
private StringProperty currentPage = new SimpleStringProperty();
private StringProperty currentDate = new SimpleStringProperty();
private StringProperty currentContent = new SimpleStringProperty();
private StringProperty currentMarking = new SimpleStringProperty();

public FileAnnotationTabViewModel(FileAnnotationCache cache, BibEntry entry) {
fileAnnotations = cache.getFromCache(entry);
files.addAll(fileAnnotations.keySet());
}

public ListProperty<FileAnnotationViewModel> annotationsProperty() {
return annotations;
}

public ListProperty<String> filesProperty() {
return files;
}

public void notifyNewSelectedAnnotation(FileAnnotationViewModel newAnnotation) {
/*
currentAuthor.setValue(newValue.getAuthor());
currentPage.setValue(newValue.getPage());
currentDate.setValue(newValue.getTimeModified().toString());
currentContent.setValue(getContentOrNA(newValue.getContent()));
currentMarking.setValue(getMarking(newValue));
*/
}

private GridPane setupRightSide() {
GridPane rightSide = new GridPane();


rightSide.addRow(0, new Label("Author"));

Text annotationAuthor = new Text();
annotationAuthor.textProperty().bind(currentAuthor);
rightSide.addColumn(1, annotationAuthor);

rightSide.addRow(1, new Label("Page"));
Text annotationPage = new Text();
annotationPage.textProperty().bind(currentPage);

rightSide.addColumn(1, annotationPage);

rightSide.addRow(2, new Label("Date"));
Text annotationDate = new Text();
annotationDate.textProperty().bind(currentDate);

rightSide.addColumn(1, annotationDate);

rightSide.addRow(3, new Label("Content"));
TextArea annotationContent = new TextArea();

annotationContent.textProperty().bind(currentContent);
annotationContent.setEditable(false);
annotationContent.setWrapText(true);
rightSide.addColumn(1, annotationContent);

rightSide.addRow(4, new Label("Marking"));
TextArea markingArea = new TextArea();
markingArea.textProperty().bind(currentMarking);
markingArea.setEditable(false);
markingArea.setWrapText(true);
rightSide.addColumn(1, markingArea);
return rightSide;
}

public void notifyNewSelectedFile(String newFile) {
Comparator<FileAnnotation> byPage = Comparator.comparingInt(FileAnnotation::getPage);

List<FileAnnotationViewModel> newAnnotations = fileAnnotations.getOrDefault(newFile, new ArrayList<>())
.stream()
.filter(annotation -> (null != annotation.getContent()))
.sorted(byPage)
.map(FileAnnotationViewModel::new)
.collect(Collectors.toList());
annotations.setAll(newAnnotations);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,22 @@ public String toString() {

return super.toString();
}

public String getDescription() {
return null;
}

private String getMarking(FileAnnotation annotation) {
if (annotation.hasLinkedAnnotation()) {
return getContentOrNA(annotation.getLinkedFileAnnotation().getContent());
}
return "N/A";
}

private String getContentOrNA(String content) {
if (content.isEmpty()) {
return "N/A";
}
return content;
}
}
Loading

0 comments on commit 3156930

Please sign in to comment.