From fecfc8df709b96b27af6d089059d2f5e90c9a7ec Mon Sep 17 00:00:00 2001 From: Andrew Ziehl Date: Thu, 7 Jun 2018 08:56:33 -0700 Subject: [PATCH] Wrapper Child factory in callable to further delay execution. Still doesn't make Search lazy since DataResultFilterNode will gather all children and do lookups which triggers the children queries. --- .../sleuthkit/autopsy/datamodel/Md5Node.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/Md5Node.java b/Core/src/org/sleuthkit/autopsy/datamodel/Md5Node.java index 96de7eba36..38a3f78b64 100644 --- a/Core/src/org/sleuthkit/autopsy/datamodel/Md5Node.java +++ b/Core/src/org/sleuthkit/autopsy/datamodel/Md5Node.java @@ -22,6 +22,7 @@ package org.sleuthkit.autopsy.datamodel; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; import java.util.logging.Level; import org.openide.nodes.ChildFactory; import org.openide.nodes.Children; @@ -53,16 +54,33 @@ public class Md5Node extends DisplayableItemNode { private final String dataSources; public Md5Node(Md5Metadata data) { - super(Children.create( - new FileInstanceNodeFactory(data), true), - Lookups.singleton(data.getMd5())); - + super(Children.createLazy(new Md5ChildCallable(data)), Lookups.singleton(data.getMd5())); this.commonFileCount = data.size(); this.dataSources = String.join(", ", data.getDataSources()); this.md5Hash = data.getMd5(); this.setDisplayName(this.md5Hash); } + + private static class Md5ChildCallable implements Callable { + private final Md5Metadata key; + private Md5ChildCallable(Md5Metadata key) { + this.key = key; + } + @Override + public Children call() throws Exception { + //Check, somehow, that your key has children, + //e.g., create "hasChildren" on the object + //to look in the database to see whether + //the object has children; + //if it doesn't have children, return a leaf: + if (key.getMetadata().isEmpty()) { + return Children.LEAF; + } else { + return Children.create(new FileInstanceNodeFactory(key), true); + } + } + } int getCommonFileCount() { return this.commonFileCount;