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

Journal abbreviations dialog ported to JavaFX #1526

Merged
merged 35 commits into from
Sep 1, 2016
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
46a8f7f
Initial port of the journal abbreviations dialog
boceckts Jun 27, 2016
acdb36f
A file can not be added anymore when it already exists
boceckts Jun 29, 2016
dcd1851
Missing Translation Keys added
boceckts Jun 29, 2016
c2eb198
Changelog entry added
boceckts Jun 29, 2016
a339226
Replaced callbacks with lambda expressions
boceckts Jul 4, 2016
6ecfaba
Now using java nio and changed delete abbreviation icon
boceckts Jul 4, 2016
cebab4e
Code refactoring
boceckts Jul 6, 2016
d8535fe
Added extension filter for file open/save dialogs
boceckts Jul 6, 2016
cd540a7
Changed size and top layout of the dialog
boceckts Jul 6, 2016
d31f6d3
Added missing translation keys and set minimum size for the dialog
boceckts Jul 6, 2016
9406582
Added option to view uneditable built in journal abbreviation lists
boceckts Jul 11, 2016
24f33b2
Removed old journal abbreviations panel class and fixed imports
boceckts Jul 12, 2016
2cd0a3b
Added comments and removed built in lists button
boceckts Jul 18, 2016
56c5b50
Exchanged add button with add icon in table
boceckts Jul 19, 2016
53d85f5
Fixed some bugs
boceckts Jul 19, 2016
48130fa
Adjusted test class for journal abbreviations view model
boceckts Jul 20, 2016
0b5a4da
Fixed failing tests
boceckts Jul 21, 2016
8b24567
More tests and removed unnecessary code
boceckts Jul 21, 2016
f35cb55
Make cells editable
boceckts Aug 1, 2016
e301a22
Added missing translations
boceckts Aug 1, 2016
9ea4f21
Minor code refactoring
boceckts Aug 8, 2016
01da557
Throwing exceptions in test class instead of catching them
boceckts Aug 10, 2016
5d50d47
Addressed first few github comments
boceckts Aug 11, 2016
ac159df
Addressed more github comments
boceckts Aug 11, 2016
b5b9f89
changed newline since it moved from globals to os
boceckts Aug 11, 2016
8da04bb
Fixed import orders
boceckts Aug 11, 2016
7dcd350
refactored bindings
boceckts Aug 13, 2016
57a86a0
More Code refactoring
boceckts Aug 15, 2016
5a3146f
Moved listeners to view model
boceckts Aug 27, 2016
6644587
Moved enable disable logic to the view model
boceckts Aug 27, 2016
2e9418b
Fix pseudoAbbreviation not showing add button
boceckts Aug 27, 2016
1d22ad8
Fixed wrong button tool tips
boceckts Aug 27, 2016
5bca5cc
Fix abbreviation couldn't be edited
boceckts Aug 27, 2016
96cabeb
Refactored view model so less code is needed
boceckts Aug 27, 2016
86a36c4
Saving abbreviations moved to new background thread
boceckts Aug 27, 2016
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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## JavaFX Changes
(to be moved to `##Changed` as soon as JavaFX is integrated in the main branch)
- Add tab which shows the MathSciNet review website if the `MRNumber` field is present.
- Partly switched to new UI technology (JavaFX). Redesigned key bindings dialog.
- Partly switched to new UI technology (JavaFX).
- Redesigned about dialog.
- Redesigned key bindings dialog.
- Redesigned journal abbreviations dialog.


### Changed
Expand Down Expand Up @@ -148,7 +151,6 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Added support for several Biblatex-fields through drop-down lists with valid alternatives
- Added integrity checker for an odd number of unescaped '#'
- Implemented [feature request 384](https://sourceforge.net/p/jabref/features/384): The merge entries dialog now show all text and colored differences between the fields
- Partly switched to new UI technology (JavaFX). Redesigned about dialog.
- Implemented [#1233](https://github.com/JabRef/jabref/issues/1233): Group side pane now takes up all the remaining space
- Added integrity check detecting HTML-encoded characters
- Added missing help files
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/sf/jabref/gui/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import javax.swing.Icon;
import javax.swing.ImageIcon;

import javafx.scene.Node;
import javafx.scene.text.Text;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -198,6 +201,12 @@ public FontBasedIcon getSmallIcon() {
return new FontBasedIcon(this.code, this.color, IconTheme.SMALL_SIZE);
}

public Node getGraphicNode() {
Text graphic = new Text(this.code);
graphic.getStyleClass().add("icon");
return graphic;
}

public String getCode() {
return this.code;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public void actionPerformed(ActionEvent e) {
Localization.menuTitle("Unabbreviate journal names"),
Localization.lang("Unabbreviate journal names of the selected entries"),
Globals.getKeyPrefs().getKey(KeyBinding.UNABBREVIATE));
private final AbstractAction manageJournals = new ManageJournalsAction(this);
private final AbstractAction manageJournals = new ManageJournalsAction();
private final AbstractAction databaseProperties = new DatabasePropertiesAction();
private final AbstractAction bibtexKeyPattern = new BibtexKeyPatternAction();
private final AbstractAction errorConsole = new ErrorConsoleAction(this, Globals.getStreamEavesdropper(), GuiAppender.CACHE);
Expand Down
100 changes: 100 additions & 0 deletions src/main/java/net/sf/jabref/gui/journals/AbbreviationViewModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* Copyright (C) 2016 JabRef contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.gui.journals;

import java.util.Objects;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import net.sf.jabref.logic.journals.Abbreviation;

/**
* This class provides a view model for abbreviation objects which can also
* define placeholder objects of abbreviations. This is indicated by using the
* {@code pseudoAbbreviation} property.
*/
public class AbbreviationViewModel {

private final Abbreviation abbreviationObject;
private final StringProperty name = new SimpleStringProperty("");
private final StringProperty abbreviation = new SimpleStringProperty("");
private final BooleanProperty pseudoAbbreviation = new SimpleBooleanProperty();


public AbbreviationViewModel(Abbreviation abbreviation) {
this.abbreviationObject = abbreviation;
pseudoAbbreviation.set(this.abbreviationObject == null);
if (this.abbreviationObject != null) {
this.name.bindBidirectional(this.abbreviationObject.nameProperty());
this.abbreviation.bindBidirectional(this.abbreviationObject.abbreviationProperty());
} else {
this.name.set("Add new Abbreviation");
}
}

public Abbreviation getAbbreviationObject() {
return this.abbreviationObject;
}

public void setName(String name) {
this.name.set(name);
}

public void setAbbreviation(String abbreviation) {
this.abbreviation.set(abbreviation);
}

public String getName() {
return this.name.get();
}

public String getAbbreviation() {
return this.abbreviation.get();
}

public boolean isPseudoAbbreviation() {
return this.pseudoAbbreviation.get();
}

public StringProperty nameProperty() {
return this.name;
}

public StringProperty abbreviationProperty() {
return this.abbreviation;
}

public BooleanProperty isPseudoAbbreviationProperty() {
return this.pseudoAbbreviation;
}

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

@Override
public boolean equals(Object obj) {
if (obj instanceof AbbreviationViewModel) {
return Objects.equals(this.abbreviationObject, ((AbbreviationViewModel) obj).abbreviationObject);
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/* Copyright (C) 2016 JabRef contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.gui.journals;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;

import net.sf.jabref.logic.journals.Abbreviation;
import net.sf.jabref.logic.journals.AbbreviationWriter;
import net.sf.jabref.logic.journals.JournalAbbreviationLoader;

import com.google.common.collect.Lists;

/**
* This class provides a model for abbreviation files.
* It actually doesn't save the files as objects but rather saves
* their paths. This also allows to specify pseudo files as placeholder objects.
*/
public class AbbreviationsFileViewModel {

private final SimpleListProperty<AbbreviationViewModel> abbreviations = new SimpleListProperty<>(
FXCollections.observableArrayList());
private final ReadOnlyBooleanProperty isBuiltInList;
private final String name;
private final Optional<Path> path;


public AbbreviationsFileViewModel(String filePath) {
this.path = Optional.ofNullable(Paths.get(filePath));
this.name = path.get().toAbsolutePath().toString();
this.isBuiltInList = new SimpleBooleanProperty(false);
this.abbreviations.add(new AbbreviationViewModel(null));
}

/**
* This constructor should only be called to create a pseudo abbreviation file for built in lists.
* This means it is a placeholder and it's path will be null meaning it has no place on the filesystem.
* It's isPseudoFile property will therefore be set to true.
*/
public AbbreviationsFileViewModel(List<AbbreviationViewModel> abbreviations, String name) {
this.abbreviations.addAll(abbreviations);
this.name = name;
this.path = Optional.empty();
this.isBuiltInList = new SimpleBooleanProperty(true);
}

public void readAbbreviations() throws FileNotFoundException {
if (path.isPresent()) {
List<Abbreviation> abbreviationList = JournalAbbreviationLoader
.readJournalListFromFile(path.get().toFile());
abbreviationList.forEach(abbreviation -> abbreviations.addAll(new AbbreviationViewModel(abbreviation)));
} else {
throw new FileNotFoundException();
}
}

/**
* This method will write all abbreviations of this abbreviation file to the file on the file system.
* It essentially will check if the current file is a built in list and if not it will call
* {@link AbbreviationWriter#writeOrCreate()}.
*
* @throws IOException
*/
public void writeOrCreate() throws IOException {
if (!isBuiltInList.get()) {
List<Abbreviation> actualAbbreviations = Lists.newArrayList();
abbreviations.forEach(abb -> {
Copy link
Member

Choose a reason for hiding this comment

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

I think the stream interface is more readable here, i.e. something along the lines abbreviations.stream().filter( !isPseudoAbbreviation).map( getAbbreviationObject).collect().

if (!abb.isPseudoAbbreviation()) {
actualAbbreviations.add(abb.getAbbreviationObject());
}
});
AbbreviationWriter.writeOrCreate(path.get(), actualAbbreviations, StandardCharsets.UTF_8);
}
}

public SimpleListProperty<AbbreviationViewModel> abbreviationsProperty() {
return this.abbreviations;
}

public boolean exists() {
return path.isPresent() && Files.exists(path.get());
}

public String getAbsolutePath() {
return path.get().toAbsolutePath().toString();
Copy link
Member

Choose a reason for hiding this comment

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

Be careful. The path may be an empty optional. I would propose to change the return value to Optional and write return path.map(toAbsolutePath().toString());

}

public ReadOnlyBooleanProperty isBuiltInListProperty() {
return this.isBuiltInList;
}

@Override
public String toString() {
return this.name;
}

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

@Override
public boolean equals(Object obj) {
if (obj instanceof AbbreviationsFileViewModel) {
return Objects.equals(this.name, ((AbbreviationsFileViewModel) obj).name);
} else {
return false;
}
}

}
Loading