-
-
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
[WIP] Add Text File Export for "Find Unlinked Files" #3979
Conversation
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.
Some minor changes, overall good work for your first PR here!
|
||
VerifyingWriter verifyingWriter; | ||
try { | ||
verifyingWriter = new VerifyingWriter(Files.newOutputStream(exportPath.get()), Charset.defaultCharset()); |
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.
Please use Charset utf8
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 you don't need a Veryfying Writer here, a BufferedWriter should be enough:
And you should use the try with resources , which has the advantage that any stream will be closed automatically, also on error.
Example:
try (BufferedWriter writer =
Files.newBufferedWriter(logFile, StandardCharsets.UTF_8,
StandardOpenOption.WRITE)) {
|
||
CheckableTreeNode root = (CheckableTreeNode) treeModel.getRoot(); | ||
|
||
final List<File> fileList = getFileListFromNode(root); |
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.
It would be preferable if you change the return type from File to Path of the method, as the Path-Class is part of the java.nio and therefore the more modern way.
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.
This method is used for the importing which I basically copied and then modified to do the exporting.
return; | ||
} | ||
|
||
threadState.set(true); |
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.
What is the purpose of this variable/method?
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'm not sure exactly. It is a hold over from the import method which I based the export method on. I guessed that it was needed to start the thread.
|
||
threadState.set(true); | ||
JabRefExecutorService.INSTANCE.execute(() -> { | ||
List<String> errors = new LinkedList<>(); |
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.
According to the codacy output, the variable errors is never used. And in 90% the cases a normal ArrayList is sufficient, a LinkedList costs more memory. The benefits of a LinkedList seldom outweigh the memory usage in comparsion to ArrayList
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'll remove it.
I'm not sure it really even needs the progress bar for the exporting because it is so fast, but I left it in for now since the importing has one. One change I didn't make is changing the list of files to Path type from File type. I left a note about that above. Let me know what you think. |
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.
Some very minor code formatting comments. Would be nice if they were integrated.
@@ -527,6 +535,88 @@ public void stateChanged(ChangeEvent e) { | |||
}); | |||
} | |||
|
|||
/** | |||
* This will start the export of all files of all selected nodes in this |
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.
"This starts the export"
* invoked. | ||
*/ | ||
private void startExport() { | ||
|
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.
Remove empty line.
CheckableTreeNode root = (CheckableTreeNode) treeModel.getRoot(); | ||
|
||
final List<File> fileList = getFileListFromNode(root); | ||
|
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.
Please remove empty line
/** | ||
*/ | ||
private void exportFinishedHandler() { | ||
|
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.
Please remove empty line
exportFinishedHandler(); | ||
} | ||
|
||
/** |
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.
Please remove empty comment.
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); | ||
frame.getCurrentBasePanel().markBaseChanged(); | ||
} | ||
|
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.
If you are on it - please remove the method comment 😇 - or add description. The functionality is not exactly clear by the method name.
@jssander Please pull before you continue to work on it. I merged master to fix conflicts due to our release today. |
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.
Thanks for your contribution. The code looks good and I only have a few minor remarks.
|
||
Optional<Path> exportPath = DefaultTaskExecutor | ||
.runInJavaFXThread(() -> ds.showFileSaveDialog(fileDialogConfiguration)); | ||
|
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.
Please add a check if exportPath
is present. If not (i.e. the user clicked cancel), then we should return early.
for (File file : fileList) { | ||
writer.write(file.toString() + "\n"); | ||
counter++; | ||
progressBarImporting.setValue(counter); |
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.
As you say, writing to the external file should be very quick (its below <1k lines in almost every case and usual not more then say 50). Thus the progressbar would only flicker a bit and I would hence propose to perform the export silently without it.
@@ -609,6 +701,8 @@ private void setupActions() { | |||
* selected nodes in this dialogs tree view. <br> | |||
*/ | |||
ActionListener actionListenerImportEntrys = e -> startImport(); | |||
ActionListener actionListenerExportEntrys = e -> startExport(); | |||
buttonExport.addActionListener(actionListenerExportEntrys); |
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 you can simply inline actionListenerExportEntrys
(and the other listener before it too, if its not used somewhere else).
How do I pull correctly? In IDEA when I go to pull I think I'm pulling from my forked master. |
I made some changes, but there is a conflict now in the changelog. I'm not sure how to resolve it. |
@jssander Just keep both lines. I did it for you using the GitHub web ui. Just pull and you are fine at your side, too. |
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.
Since this PR already as a few positive reviews and the code looks good to me as well, I'll merge now.
Thanks again for your contribution and we are looking forward to your next PR!
Great! Thank you so much. |
* upstream/master: Fix statement in changelog [WIP] Add Text File Export for "Find Unlinked Files" (#3979)
* upstream/master: New translations JabRef_en.properties (French) (#4009) Fix Look and Feel related issues (#4002) Fix statement in changelog [WIP] Add Text File Export for "Find Unlinked Files" (#3979) # Conflicts: # src/main/java/org/jabref/JabRefGUI.java # src/main/java/org/jabref/gui/preftabs/AppearancePrefsTab.java # src/main/java/org/jabref/migrations/PreferencesMigrations.java
* upstream/maintable-beta: set look and feel to windows, aqua or nimbus for swing in case fix import remove look and feel New translations JabRef_en.properties (French) (#4009) Fix Look and Feel related issues (#4002) Fix statement in changelog [WIP] Add Text File Export for "Find Unlinked Files" (#3979)
…rsectionnew * upstream/maintable-beta: (88 commits) set look and feel to windows, aqua or nimbus for swing in case fix import remove look and feel New translations JabRef_en.properties (French) (#4009) Fix Look and Feel related issues (#4002) Fix statement in changelog [WIP] Add Text File Export for "Find Unlinked Files" (#3979) Fix IEEE preview does not display month (#3983) Activate context menu on key press (#4004) Improve code layout Fix concurrent modification exception when adding entries to groups Fix build Typo Add fix Rename test Fix #3994 Duplicate unmodifiable list for sorting (#3996) Remove deprecated and unused method (#3993) Improvements around external file types (#3887) Migrate to native gradle test task (#3987) Do not run checkstyle as part of the gradle check task (#3985) ...
…drop * upstream/maintable-beta: (174 commits) Fix ACM fetcher import of entries (#4019) Reimplement tooltips for file and identifier columns (#4011) Add button-icon for union/intersection in the groups side panel (#3954) Update Dependencies (#4012) set look and feel to windows, aqua or nimbus for swing in case fix import remove look and feel New translations JabRef_en.properties (French) (#4009) Fix Look and Feel related issues (#4002) Fix statement in changelog [WIP] Add Text File Export for "Find Unlinked Files" (#3979) Fix IEEE preview does not display month (#3983) Activate context menu on key press (#4004) Improve code layout Fix concurrent modification exception when adding entries to groups Fix build Typo Add fix Rename test Fix #3994 Duplicate unmodifiable list for sorting (#3996) ... # Conflicts: # src/main/java/org/jabref/gui/actions/CleanupAction.java # src/main/java/org/jabref/gui/maintable/MainTable.java
This is to add the feature which allows exporting of the list of files found in "Find Unlinked Files" to a text file.
Closes issue #3341
I'm not sure if it is exactly what you are looking for, but I thought I would give it a shot. Hopefully you will be kind though I welcome constructive feedback of course.