Skip to content

Commit

Permalink
further implement viewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
Siedlerchr committed Oct 27, 2018
1 parent 3a7ef14 commit df6d717
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
19 changes: 8 additions & 11 deletions src/main/java/org/jabref/gui/openoffice/CitationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CitationManager {
private final DefaultEventTableModel<CitationEntry> tableModel;

public CitationManager(OOBibBase ooBase, DialogService dialogService)
throws NoSuchElementException, WrappedTargetException, UnknownPropertyException {
throws NoSuchElementException, WrappedTargetException, UnknownPropertyException {
diag = new JDialog((JFrame) null, Localization.lang("Manage citations"), true);
this.ooBase = ooBase;

Expand All @@ -66,8 +66,8 @@ public CitationManager(OOBibBase ooBase, DialogService dialogService)
List<String> names = ooBase.getJabRefReferenceMarks(nameAccess);
for (String name : names) {
list.add(new CitationEntry(name,
"<html>..." + ooBase.getCitationContext(nameAccess, name, 30, 30, true) + "...</html>",
ooBase.getCustomProperty(name)));
"<html>..." + ooBase.getCitationContext(nameAccess, name, 30, 30, true) + "...</html>",
ooBase.getCustomProperty(name)));
}
tableModel = new DefaultEventTableModel<>(list, new CitationEntryFormat());
table = new JTable(tableModel);
Expand All @@ -91,7 +91,7 @@ public CitationManager(OOBibBase ooBase, DialogService dialogService)
try {
storeSettings();
} catch (UnknownPropertyException | NotRemoveableException | PropertyExistException | IllegalTypeException |
IllegalArgumentException ex) {
IllegalArgumentException ex) {
LOGGER.warn("Problem modifying citation", ex);
dialogService.showErrorDialogAndWait(Localization.lang("Problem modifying citation"), ex);
}
Expand All @@ -107,8 +107,7 @@ public void actionPerformed(ActionEvent actionEvent) {
};
cancel.addActionListener(cancelAction);

bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put
(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close");
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);
Expand All @@ -118,7 +117,7 @@ public void actionPerformed(ActionEvent actionEvent) {
}

private void storeSettings() throws UnknownPropertyException, NotRemoveableException, PropertyExistException,
IllegalTypeException, IllegalArgumentException {
IllegalTypeException, IllegalArgumentException {
for (CitationEntry entry : list) {
Optional<String> pageInfo = entry.getPageInfo();
if (entry.pageInfoChanged() && pageInfo.isPresent()) {
Expand Down Expand Up @@ -180,15 +179,14 @@ class SingleCitationDialog {
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"));
.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);
Expand Down Expand Up @@ -222,8 +220,7 @@ public void actionPerformed(ActionEvent actionEvent) {
};
cancelButton.addActionListener(cancelAction);

builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put
(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close");
builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close");
builder.getPanel().getActionMap().put("close", cancelAction);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.TableView;

import org.jabref.gui.DialogService;
Expand Down Expand Up @@ -40,6 +41,10 @@ private void initialize() throws NoSuchElementException, WrappedTargetException,

colCitation.setCellValueFactory(cellData -> cellData.getValue().citationProperty());
colExtraInfo.setCellValueFactory(cellData -> cellData.getValue().extraInformationProperty());
colExtraInfo.setEditable(true);

colExtraInfo.setOnEditCommit((CellEditEvent<ManageCitationsItemViewModel, String> cell) -> {
cell.getRowValue().setExtraInfo(cell.getNewValue());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import java.util.List;

import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;

import org.jabref.gui.DialogService;
import org.jabref.logic.openoffice.CitationEntry;

Expand All @@ -12,12 +16,15 @@

public class ManageCitationsDialogViewModel {

private final ListProperty<ManageCitationsItemViewModel> citations = new SimpleListProperty<>(FXCollections.observableArrayList());

public ManageCitationsDialogViewModel(OOBibBase ooBase, DialogService dialogService) throws NoSuchElementException, WrappedTargetException, UnknownPropertyException {

XNameAccess nameAccess = ooBase.getReferenceMarks();
List<String> names = ooBase.getJabRefReferenceMarks(nameAccess);
for (String name : names) {
new CitationEntry(name,
"<html>..." + ooBase.getCitationContext(nameAccess, name, 30, 30, true) + "...</html>",
"<html>..." + ooBase.getCitationContext(nameAccess, name, 30, 30, true) + "...</html>",
ooBase.getCustomProperty(name));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import org.jabref.logic.openoffice.CitationEntry;

public class ManageCitationsItemViewModel {

private final StringProperty citation = new SimpleStringProperty("");
private final StringProperty extraInformation = new SimpleStringProperty("");
private final String refMarkName;

public ManageCitationsItemViewModel(String refMarkName, String citation, String extraInfo) {
this.refMarkName = refMarkName;
this.citation.setValue(citation);
this.extraInformation.setValue(extraInfo);
}

public ManageCitationsItemViewModel fromCitationEntry(CitationEntry citationEntry) {
return new ManageCitationsItemViewModel(citationEntry.getRefMarkName(), citationEntry.getContext(), citationEntry.getPageInfo().orElse(""));
}

public CitationEntry toCitationEntry() {
return new CitationEntry(refMarkName, citation.getValue(), extraInformation.getValue());
}

public StringProperty citationProperty() {
return citation;
Expand All @@ -16,4 +33,8 @@ public StringProperty extraInformationProperty() {
return extraInformation;
}

public void setExtraInfo(String extraInfo) {
extraInformation.setValue(extraInfo);
}

}
5 changes: 3 additions & 2 deletions src/main/java/org/jabref/logic/openoffice/CitationEntry.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.logic.openoffice;

import java.util.Objects;
import java.util.Optional;

public class CitationEntry implements Comparable<CitationEntry> {
Expand Down Expand Up @@ -59,14 +60,14 @@ public boolean equals(Object o) {
}
if (o instanceof CitationEntry) {
CitationEntry other = (CitationEntry) o;
return this.refMarkName.equals(other.refMarkName);
return Objects.equals(this.refMarkName, other.refMarkName);
}
return false;
}

@Override
public int hashCode() {
return this.refMarkName.hashCode();
return Objects.hash(refMarkName);
}

public String getContext() {
Expand Down

0 comments on commit df6d717

Please sign in to comment.