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

[WIP] Add Text File Export for "Find Unlinked Files" #3979

Merged
merged 7 commits into from
May 2, 2018
Merged

[WIP] Add Text File Export for "Find Unlinked Files" #3979

merged 7 commits into from
May 2, 2018

Conversation

jssander
Copy link
Contributor

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.

Copy link
Member

@Siedlerchr Siedlerchr left a 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());
Copy link
Member

Choose a reason for hiding this comment

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

Please use Charset utf8

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 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);
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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?

Copy link
Contributor Author

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<>();
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove it.

@jssander
Copy link
Contributor Author

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.

Copy link
Member

@koppor koppor left a 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
Copy link
Member

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() {

Copy link
Member

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);

Copy link
Member

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() {

Copy link
Member

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();
}

/**
Copy link
Member

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();
}

Copy link
Member

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.

@koppor
Copy link
Member

koppor commented Apr 26, 2018

@jssander Please pull before you continue to work on it. I merged master to fix conflicts due to our release today.

Copy link
Member

@tobiasdiez tobiasdiez left a 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));

Copy link
Member

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);
Copy link
Member

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);
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 you can simply inline actionListenerExportEntrys (and the other listener before it too, if its not used somewhere else).

@jssander
Copy link
Contributor Author

How do I pull correctly? In IDEA when I go to pull I think I'm pulling from my forked master.

@jssander
Copy link
Contributor Author

jssander commented May 1, 2018

I made some changes, but there is a conflict now in the changelog. I'm not sure how to resolve it.

@koppor
Copy link
Member

koppor commented May 2, 2018

@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.

Copy link
Member

@tobiasdiez tobiasdiez left a 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!

@tobiasdiez tobiasdiez merged commit ed2ff31 into JabRef:master May 2, 2018
@jssander
Copy link
Contributor Author

jssander commented May 2, 2018

Great! Thank you so much.

Siedlerchr added a commit that referenced this pull request May 2, 2018
* upstream/master:
  Fix statement in changelog
  [WIP] Add Text File Export for "Find Unlinked Files" (#3979)
Siedlerchr added a commit that referenced this pull request May 4, 2018
* 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
Siedlerchr added a commit that referenced this pull request May 5, 2018
* 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)
Siedlerchr added a commit that referenced this pull request May 5, 2018
…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)
  ...
Siedlerchr added a commit that referenced this pull request May 10, 2018
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants