-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
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 acdb36f
A file can not be added anymore when it already exists
boceckts dcd1851
Missing Translation Keys added
boceckts c2eb198
Changelog entry added
boceckts a339226
Replaced callbacks with lambda expressions
boceckts 6ecfaba
Now using java nio and changed delete abbreviation icon
boceckts cebab4e
Code refactoring
boceckts d8535fe
Added extension filter for file open/save dialogs
boceckts cd540a7
Changed size and top layout of the dialog
boceckts d31f6d3
Added missing translation keys and set minimum size for the dialog
boceckts 9406582
Added option to view uneditable built in journal abbreviation lists
boceckts 24f33b2
Removed old journal abbreviations panel class and fixed imports
boceckts 2cd0a3b
Added comments and removed built in lists button
boceckts 56c5b50
Exchanged add button with add icon in table
boceckts 53d85f5
Fixed some bugs
boceckts 48130fa
Adjusted test class for journal abbreviations view model
boceckts 0b5a4da
Fixed failing tests
boceckts 8b24567
More tests and removed unnecessary code
boceckts f35cb55
Make cells editable
boceckts e301a22
Added missing translations
boceckts 9ea4f21
Minor code refactoring
boceckts 01da557
Throwing exceptions in test class instead of catching them
boceckts 5d50d47
Addressed first few github comments
boceckts ac159df
Addressed more github comments
boceckts b5b9f89
changed newline since it moved from globals to os
boceckts 8da04bb
Fixed import orders
boceckts 7dcd350
refactored bindings
boceckts 57a86a0
More Code refactoring
boceckts 5a3146f
Moved listeners to view model
boceckts 6644587
Moved enable disable logic to the view model
boceckts 2e9418b
Fix pseudoAbbreviation not showing add button
boceckts 1d22ad8
Fixed wrong button tool tips
boceckts 5bca5cc
Fix abbreviation couldn't be edited
boceckts 96cabeb
Refactored view model so less code is needed
boceckts 86a36c4
Saving abbreviations moved to new background thread
boceckts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/main/java/net/sf/jabref/gui/journals/AbbreviationViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
src/main/java/net/sf/jabref/gui/journals/AbbreviationsFileViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -> { | ||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
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; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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()
.