* fix NPE issue

@see http://www.filebot.net/forums/viewtopic.php?f=6&t=1199&p=7243#p7243
This commit is contained in:
Reinhard Pointner 2013-12-23 13:42:56 +00:00
parent f5910f837d
commit 0827fda189
1 changed files with 19 additions and 26 deletions

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot.ui.rename;
import static java.util.Arrays.*;
import static net.sourceforge.filebot.MediaTypes.*;
import static net.sourceforge.filebot.ui.transfer.FileTransferable.*;
@ -20,29 +18,24 @@ import net.sourceforge.filebot.media.MediaDetection;
import net.sourceforge.filebot.ui.transfer.FileTransferablePolicy;
import net.sourceforge.tuned.FastFile;
class FilesListTransferablePolicy extends FileTransferablePolicy {
private final List<File> model;
public FilesListTransferablePolicy(List<File> model) {
this.model = model;
}
@Override
protected boolean accept(List<File> files) {
return true;
}
@Override
protected void clear() {
model.clear();
}
@Override
public void handleTransferable(Transferable tr, TransferAction action) throws Exception {
if (action == TransferAction.LINK) {
@ -55,13 +48,11 @@ class FilesListTransferablePolicy extends FileTransferablePolicy {
}
}
@Override
protected void load(List<File> files) {
load(files, true);
}
protected void load(List<File> files, boolean recursive) {
List<File> entries = new ArrayList<File>();
LinkedList<File> queue = new LinkedList<File>(files);
@ -98,15 +89,17 @@ class FilesListTransferablePolicy extends FileTransferablePolicy {
}
} else if (!recursive || f.isFile() || MediaDetection.isDiskFolder(f)) {
entries.add(f);
} else {
queue.addAll(0, asList(f.listFiles()));
} else if (f.isDirectory()) {
File[] children = f.listFiles();
if (children != null) {
queue.addAll(0, asList(children));
}
}
}
model.addAll(FastFile.foreach(entries));
}
@Override
public String getFileFilterDescription() {
return "files and folders";