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;
72 this.displayName = displayName;
85 return this.displayName;
100 return v.
visit(
this);
112 private static final String
NAME = NbBundle.getMessage(
FileSize.class,
"FileSize.fileSizeRootNode.name");
117 super.setDisplayName(NAME);
118 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file-size-16.png");
128 return v.
visit(
this);
133 Sheet s = super.createSheet();
134 Sheet.Set ss = s.get(Sheet.PROPERTIES);
136 ss = Sheet.createPropertiesSet();
140 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.name.name"),
141 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.name.displayName"),
142 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.name.desc"),
161 public static class FileSizeRootChildren extends ChildFactory<org.sleuthkit.autopsy.datamodel.FileSize.FileSizeFilter> {
190 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
192 public void propertyChange(PropertyChangeEvent evt) {
193 String eventType = evt.getPropertyName();
207 }
catch (IllegalStateException notUsed) {
224 }
catch (IllegalStateException notUsed) {
231 if (evt.getNewValue() == null) {
265 super(Children.create(
new FileSizeChildren(filter, skCase, null),
true), Lookups.singleton(filter.
getDisplayName()));
278 super(Children.create(
new FileSizeChildren(filter, skCase, o),
true), Lookups.singleton(filter.
getDisplayName()));
281 o.addObserver(
new FileSizeNodeObserver());
285 super.setName(filter.
getName());
288 this.setShortDescription(tooltip);
289 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file-size-16.png");
308 public void update(Observable o, Object arg) {
314 final long count = FileSizeChildren.calculateItems(skCase, filter);
315 super.setDisplayName(filter.
getDisplayName() +
" (" + count +
")");
320 return v.
visit(
this);
325 Sheet s = super.createSheet();
326 Sheet.Set ss = s.get(Sheet.PROPERTIES);
328 ss = Sheet.createPropertiesSet();
332 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.filterType.name"),
333 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.filterType.displayName"),
334 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.filterType.desc"),
349 static class FileSizeChildren
extends ChildFactory.Detachable<AbstractFile> {
351 private final SleuthkitCase
skCase;
363 FileSizeChildren(
FileSizeFilter filter, SleuthkitCase skCase, Observable o) {
365 this.filter = filter;
370 protected void addNotify() {
371 if (notifier != null) {
372 notifier.addObserver(observer);
377 protected void removeNotify() {
378 if (notifier != null) {
379 notifier.deleteObserver(observer);
383 private final Observer observer =
new FileSizeChildrenObserver();
389 public void update(Observable o, Object arg) {
395 protected boolean createKeys(List<AbstractFile> list) {
396 list.addAll(runFsQuery());
404 query =
"(size >= 50000000 AND size < 200000000)";
407 query =
"(size >= 200000000 AND size < 1000000000)";
411 query =
"(size >= 1000000000)";
415 throw new IllegalArgumentException(
"Unsupported filter type to get files by size: " + filter);
418 query = query +
" AND (type != " + TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS.getFileType() +
")";
423 private List<AbstractFile> runFsQuery() {
424 List<AbstractFile> ret =
new ArrayList<>();
427 String query = makeQuery(filter);
429 ret = skCase.findAllFilesWhere(query);
430 }
catch (Exception e) {
431 logger.log(Level.SEVERE,
"Error getting files for the file size view: " + e.getMessage());
442 static long calculateItems(SleuthkitCase sleuthkitCase, FileSizeFilter filter) {
444 return sleuthkitCase.countFilesWhere(makeQuery(filter));
445 }
catch (TskCoreException ex) {
446 logger.log(Level.SEVERE,
"Error getting files by size search view count", ex);
453 return key.accept(
new ContentVisitor.Default<AbstractNode>() {
454 public FileNode visit(AbstractFile f) {
455 return new FileNode(f, false);
458 public FileNode visit(FsContent f) {
459 return new FileNode(f,
false);
463 public FileNode visit(LayoutFile f) {
464 return new FileNode(f,
false);
468 public FileNode visit(File f) {
469 return new FileNode(f,
false);
473 public FileNode visit(Directory f) {
474 return new FileNode(f,
false);
478 public FileNode visit(LocalFile f) {
479 return new FileNode(f,
false);
483 public FileNode visit(DerivedFile f) {
484 return new FileNode(f,
false);
488 public FileNode visit(VirtualDirectory f) {
489 return new FileNode(f,
false);
493 protected AbstractNode defaultVisit(Content di) {
494 throw new UnsupportedOperationException(
495 NbBundle.getMessage(
this.getClass(),
496 "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()
static void removePropertyChangeListener(PropertyChangeListener listener)
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 void addPropertyChangeListener(PropertyChangeListener listener)
FileSizeFilter(int id, String name, String displayName)
void addIngestModuleEventListener(final PropertyChangeListener listener)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
void update(Observable o, Object arg)
FileSizeRootChildren(SleuthkitCase skCase)