19 package org.sleuthkit.autopsy.datamodel;
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.Observable;
27 import java.util.Observer;
28 import java.util.logging.Level;
29 import org.openide.nodes.AbstractNode;
30 import org.openide.nodes.ChildFactory;
31 import org.openide.nodes.Children;
32 import org.openide.nodes.Node;
33 import org.openide.nodes.Sheet;
34 import org.openide.util.NbBundle;
35 import org.openide.util.lookup.Lookups;
56 public class FileSize implements AutopsyVisitableItem {
72 this.displayName = displayName;
85 return this.displayName;
89 public <T> T
accept(AutopsyItemVisitor<T> v) {
99 public <T> T accept(AutopsyItemVisitor<T> v) {
100 return v.visit(
this);
110 private static final String
NAME = NbBundle.getMessage(
FileSize.class,
"FileSize.fileSizeRootNode.name");
115 super.setDisplayName(NAME);
116 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file-size-16.png");
126 return v.
visit(
this);
131 Sheet s = super.createSheet();
132 Sheet.Set ss = s.get(Sheet.PROPERTIES);
134 ss = Sheet.createPropertiesSet();
138 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.name.name"),
139 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.name.displayName"),
140 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.name.desc"),
147 public static class FileSizeRootChildren extends ChildFactory<org.sleuthkit.autopsy.datamodel.FileSize.FileSizeFilter> {
176 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
178 public void propertyChange(PropertyChangeEvent evt) {
179 String eventType = evt.getPropertyName();
192 if (evt.getNewValue() == null) {
224 super(Children.create(
new FileSizeChildren(filter, skCase, null),
true), Lookups.singleton(filter.
getDisplayName()));
236 super(Children.create(
new FileSizeChildren(filter, skCase, o),
true), Lookups.singleton(filter.
getDisplayName()));
239 o.addObserver(
new FileSizeNodeObserver());
243 super.setName(filter.
getName());
246 this.setShortDescription(tooltip);
247 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file-size-16.png");
256 public void update(Observable o, Object arg) {
262 final long count = FileSizeChildren.calculateItems(skCase, filter);
263 super.setDisplayName(filter.
getDisplayName() +
" (" + count +
")");
268 return v.
visit(
this);
273 Sheet s = super.createSheet();
274 Sheet.Set ss = s.get(Sheet.PROPERTIES);
276 ss = Sheet.createPropertiesSet();
280 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.filterType.name"),
281 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.filterType.displayName"),
282 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.filterType.desc"),
295 static class FileSizeChildren
extends ChildFactory.Detachable<AbstractFile> {
310 this.filter = filter;
315 protected void addNotify() {
316 if (notifier != null) {
317 notifier.addObserver(observer);
322 protected void removeNotify() {
323 if (notifier != null) {
324 notifier.deleteObserver(observer);
328 private final Observer observer =
new FileSizeChildrenObserver();
334 public void update(Observable o, Object arg) {
340 protected boolean createKeys(List<AbstractFile> list) {
341 List<AbstractFile> l = runFsQuery();
349 private static String makeQuery(FileSizeFilter filter) {
353 query =
"(size >= 50000000 AND size < 200000000)";
356 query =
"(size >= 200000000 AND size < 1000000000)";
360 query =
"(size >= 1000000000)";
364 logger.log(Level.SEVERE,
"Unsupported filter type to get files by size: {0}", filter);
368 query = query +
" AND (type != " + TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS.getFileType() +
")";
373 private List<AbstractFile> runFsQuery() {
374 List<AbstractFile> ret =
new ArrayList<>();
376 String query = makeQuery(filter);
383 }
catch (TskCoreException e) {
384 logger.log(Level.SEVERE,
"Error getting files for the file size view using: " + query, e);
396 static long calculateItems(SleuthkitCase sleuthkitCase, FileSizeFilter filter) {
398 return sleuthkitCase.countFilesWhere(makeQuery(filter));
399 }
catch (TskCoreException ex) {
400 logger.log(Level.SEVERE,
"Error getting files by size search view count", ex);
407 return key.accept(
new ContentVisitor.Default<AbstractNode>() {
408 public FileNode visit(AbstractFile f) {
409 return new FileNode(f, false);
412 public FileNode visit(FsContent f) {
413 return new FileNode(f,
false);
417 public FileNode visit(LayoutFile f) {
418 return new FileNode(f,
false);
422 public FileNode visit(File f) {
423 return new FileNode(f,
false);
427 public FileNode visit(Directory f) {
428 return new FileNode(f,
false);
432 public FileNode visit(LocalFile f) {
433 return new FileNode(f,
false);
437 public FileNode visit(DerivedFile f) {
438 return new FileNode(f,
false);
442 public FileNode visit(VirtualDirectory f) {
443 return new FileNode(f,
false);
447 protected AbstractNode defaultVisit(Content di) {
448 throw new UnsupportedOperationException(
449 NbBundle.getMessage(
this.getClass(),
450 "FileSize.exception.notSupported.msg",
void update(Observable o, Object arg)
FileSize(SleuthkitCase skCase)
public< T > T accept(AutopsyItemVisitor< T > v)
void removeIngestModuleEventListener(final PropertyChangeListener listener)
SleuthkitCase getSleuthkitCase()
static synchronized IngestManager getInstance()
T visit(DataSourcesNode in)
void removeIngestJobEventListener(final PropertyChangeListener listener)
boolean createKeys(List< FileSizeFilter > list)
Node createNodeForKey(FileSizeFilter key)
final PropertyChangeListener pcl
void addIngestJobEventListener(final PropertyChangeListener listener)
static synchronized void removePropertyChangeListener(PropertyChangeListener listener)
FileSizeFilter(int id, String name, String displayName)
void addIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized void addPropertyChangeListener(PropertyChangeListener listener)
List< AbstractFile > findAllFilesWhere(String sqlWhereClause)
void update(Observable o, Object arg)
FileSizeRootChildren(SleuthkitCase skCase)
static Logger getLogger(String name)