-
-
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
Add file description to gui and fix sync bug #3210
Changes from 3 commits
55e3d1d
d985361
23c6ac6
52b5b42
3197713
e05f8b0
f767625
c517843
4cf1a6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
public class FileFieldWriter { | ||
|
||
private FileFieldWriter() { | ||
FileFieldWriter() { | ||
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. Why is this constructor not private anymore? 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. Was a relict from testing. Didn't see that it had static method on the first try |
||
} | ||
|
||
public static String getStringRepresentation(List<LinkedFile> fields) { | ||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -8,6 +8,14 @@ | |||
import java.util.Objects; | ||||
import java.util.Optional; | ||||
|
||||
import javafx.beans.Observable; | ||||
import javafx.beans.property.BooleanProperty; | ||||
import javafx.beans.property.DoubleProperty; | ||||
import javafx.beans.property.SimpleBooleanProperty; | ||||
import javafx.beans.property.SimpleDoubleProperty; | ||||
import javafx.beans.property.SimpleStringProperty; | ||||
import javafx.beans.property.StringProperty; | ||||
|
||||
import org.jabref.model.database.BibDatabaseContext; | ||||
import org.jabref.model.metadata.FileDirectoryPreferences; | ||||
import org.jabref.model.util.FileHelper; | ||||
|
@@ -19,42 +27,49 @@ | |||
public class LinkedFile implements Serializable { | ||||
|
||||
private static final LinkedFile NULL_OBJECT = new LinkedFile("", "", ""); | ||||
private String description; | ||||
private String link; | ||||
private String fileType; | ||||
private final StringProperty description = new SimpleStringProperty(); | ||||
private final StringProperty link = new SimpleStringProperty(); | ||||
private final StringProperty fileType = new SimpleStringProperty(); | ||||
private final DoubleProperty downloadProgress = new SimpleDoubleProperty(-1); | ||||
private final BooleanProperty isAutomaticallyFound = new SimpleBooleanProperty(false); | ||||
|
||||
public LinkedFile(String description, String link, String fileType) { | ||||
this.description = Objects.requireNonNull(description); | ||||
this.link = Objects.requireNonNull(link); | ||||
this.fileType = Objects.requireNonNull(fileType); | ||||
this.description.setValue(Objects.requireNonNull(description)); | ||||
this.link.setValue(Objects.requireNonNull(link)); | ||||
this.fileType.setValue(Objects.requireNonNull(fileType)); | ||||
} | ||||
|
||||
public LinkedFile(String description, URL link, String fileType) { | ||||
this(description, Objects.requireNonNull(link).toString(), fileType); | ||||
} | ||||
|
||||
public String getFileType() { | ||||
return fileType; | ||||
return fileType.get(); | ||||
} | ||||
|
||||
public void setFileType(String fileType) { | ||||
this.fileType = fileType; | ||||
this.fileType.setValue(fileType); | ||||
} | ||||
|
||||
public String getDescription() { | ||||
return description; | ||||
return description.get(); | ||||
} | ||||
|
||||
public void setDescription(String description) { | ||||
this.description = description; | ||||
this.description.setValue(description); | ||||
|
||||
} | ||||
|
||||
public String getLink() { | ||||
return link; | ||||
return link.get(); | ||||
} | ||||
|
||||
public void setLink(String link) { | ||||
this.link = link; | ||||
this.link.setValue(link); | ||||
} | ||||
|
||||
public Observable[] getObservables() { | ||||
return new Observable[] {this.downloadProgress, this.isAutomaticallyFound}; | ||||
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. you need to return The observable tell javafx which properties mark the object as changed, i.e. if
For more details see https://docs.oracle.com/javase/8/javafx/api/javafx/collections/FXCollections.html#observableList-java.util.List-javafx.util.Callback- or https://stackoverflow.com/questions/31687642/callback-and-extractors-for-javafx-observablelist |
||||
} | ||||
|
||||
@Override | ||||
|
@@ -96,7 +111,7 @@ public boolean isEmpty() { | |||
} | ||||
|
||||
public boolean isOnlineLink() { | ||||
return link.startsWith("http://") || link.startsWith("https://") || link.contains("www."); | ||||
return link.get().startsWith("http://") || link.get().startsWith("https://") || link.get().contains("www."); | ||||
} | ||||
|
||||
public Optional<Path> findIn(BibDatabaseContext databaseContext, FileDirectoryPreferences fileDirectoryPreferences) { | ||||
|
@@ -105,11 +120,11 @@ public Optional<Path> findIn(BibDatabaseContext databaseContext, FileDirectoryPr | |||
} | ||||
|
||||
public Optional<Path> findIn(List<Path> directories) { | ||||
Path file = Paths.get(link); | ||||
Path file = Paths.get(link.get()); | ||||
if (file.isAbsolute() || directories.isEmpty()) { | ||||
return Optional.of(file); | ||||
} else { | ||||
return FileHelper.expandFilenameAsPath(link, directories); | ||||
return FileHelper.expandFilenameAsPath(link.get(), directories); | ||||
} | ||||
} | ||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.jabref.model.entry; | ||
|
||
import org.jabref.logic.exporter.BibtexDatabaseWriter; | ||
import org.jabref.logic.exporter.SaveException; | ||
import org.jabref.logic.exporter.SavePreferences; | ||
import org.jabref.logic.exporter.StringSaveSession; | ||
import org.jabref.logic.util.OS; | ||
import org.jabref.model.Defaults; | ||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.metadata.MetaData; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class FileFieldBibEntryTest { | ||
|
||
private BibEntry emptyEntry; | ||
|
||
@Before | ||
public void setUp() { | ||
emptyEntry = new BibEntry(); | ||
emptyEntry.setType("article"); | ||
emptyEntry.setChanged(false); | ||
} | ||
|
||
@Test | ||
public void testFileFieldSerialization() { | ||
LinkedFile file = new LinkedFile("test", "/home/uers/test.pdf", "PDF"); | ||
emptyEntry.addFile(file); | ||
|
||
assertEquals("@article{,\n" + | ||
" file = {test:/home/uers/test.pdf:PDF}\n" + | ||
"}", emptyEntry.toString()); | ||
} | ||
|
||
@Test | ||
public void testFileFieldSerializationDatabase() throws SaveException { | ||
BibDatabase database = new BibDatabase(); | ||
|
||
LinkedFile file = new LinkedFile("test", "/home/uers/test.pdf", "PDF"); | ||
emptyEntry.addFile(file); | ||
database.insertEntries(emptyEntry); | ||
|
||
BibtexDatabaseWriter<StringSaveSession> databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new); | ||
StringSaveSession saveSession = databaseWriter.savePartOfDatabase( | ||
new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(), | ||
new SavePreferences()); | ||
|
||
assertEquals(OS.NEWLINE + | ||
"@Article{," | ||
+ OS.NEWLINE | ||
+ " file = {test:/home/uers/test.pdf:PDF}," | ||
+ OS.NEWLINE | ||
+ "}" + OS.NEWLINE | ||
+ OS.NEWLINE | ||
+ "@Comment{jabref-meta: databaseType:bibtex;}" + OS.NEWLINE, saveSession.getStringValue()); | ||
} | ||
} |
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.
Very minor, but as far as I can see this blank line is unnecessary.