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.EnumSet;
26 import java.util.List;
27 import java.util.Observable;
28 import java.util.Observer;
30 import java.util.logging.Level;
31 import org.openide.nodes.AbstractNode;
32 import org.openide.nodes.ChildFactory;
33 import org.openide.nodes.Children;
34 import org.openide.nodes.Node;
35 import org.openide.nodes.Sheet;
36 import org.openide.util.NbBundle;
37 import org.openide.util.lookup.Lookups;
77 this.displayName = displayName;
90 return this.displayName;
95 return visitor.
visit(
this);
103 public FileSize(SleuthkitCase skCase,
long dsObjId) {
105 this.filteringDSObjId = dsObjId;
110 return visitor.
visit(
this);
117 long filteringDataSourceObjId() {
126 private static final String
NAME = NbBundle.getMessage(
FileSize.class,
"FileSize.fileSizeRootNode.name");
129 super(Children.create(
new FileSizeRootChildren(skCase, datasourceObjId),
true), Lookups.singleton(NAME));
131 super.setDisplayName(NAME);
132 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file-size-16.png");
142 return visitor.
visit(
this);
147 Sheet sheet = super.createSheet();
148 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
149 if (sheetSet == null) {
150 sheetSet = Sheet.createPropertiesSet();
154 sheetSet.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.name.name"),
155 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.name.displayName"),
156 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.name.desc"),
163 return getClass().getName();
170 public static class FileSizeRootChildren extends ChildFactory<org.sleuthkit.autopsy.datamodel.FileSize.FileSizeFilter> {
205 private final PropertyChangeListener
pcl = (PropertyChangeEvent evt) -> {
206 String eventType = evt.getPropertyName();
244 if (evt.getNewValue() == null) {
264 return new FileSizeNode(skCase, key, notifier, datasourceObjId);
278 super(Children.create(
new FileSizeChildren(filter, skCase, null, datasourceObjId),
true), Lookups.singleton(filter.
getDisplayName()));
294 super(Children.create(
new FileSizeChildren(filter, skCase, o, datasourceObjId),
true), Lookups.singleton(filter.
getDisplayName()));
298 o.addObserver(
new FileSizeNodeObserver());
302 super.setName(filter.
getName());
305 this.setShortDescription(tooltip);
306 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/file-size-16.png");
324 public void update(Observable o, Object arg) {
330 final long numVisibleChildren = FileSizeChildren.calculateItems(skCase, filter, datasourceObjId);
331 super.setDisplayName(filter.
getDisplayName() +
" (" + numVisibleChildren +
")");
336 return visitor.
visit(
this);
341 Sheet sheet = super.createSheet();
342 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
343 if (sheetSet == null) {
344 sheetSet = Sheet.createPropertiesSet();
348 sheetSet.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.filterType.name"),
349 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.filterType.displayName"),
350 NbBundle.getMessage(
this.getClass(),
"FileSize.createSheet.filterType.desc"),
368 private final SleuthkitCase
skCase;
380 FileSizeChildren(
FileSizeFilter filter, SleuthkitCase skCase, Observable o,
long dsObjId) {
381 super(filter.
getName(),
new ViewsKnownAndSlackFilter<>());
383 this.filter = filter;
385 this.datasourceObjId = dsObjId;
390 protected void onAdd() {
391 if (notifier != null) {
392 notifier.addObserver(observer);
397 protected void onRemove() {
398 if (notifier != null) {
399 notifier.deleteObserver(observer);
403 private final Observer observer =
new FileSizeChildrenObserver();
406 protected List<AbstractFile> makeKeys() {
414 public void update(Observable o, Object arg) {
419 private static String makeQuery(
FileSizeFilter filter,
long filteringDSObjId) {
423 query =
"(size >= 50000000 AND size < 200000000)";
426 query =
"(size >= 200000000 AND size < 1000000000)";
430 query =
"(size >= 1000000000)";
434 throw new IllegalArgumentException(
"Unsupported filter type to get files by size: " + filter);
438 query = query +
" AND (type != " + TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS.getFileType() +
")";
441 if (filteringDSObjId > 0) {
448 private List<AbstractFile> runFsQuery() {
449 List<AbstractFile> ret =
new ArrayList<>();
452 String query = makeQuery(filter, datasourceObjId);
454 ret = skCase.findAllFilesWhere(query);
455 }
catch (Exception e) {
456 logger.log(Level.SEVERE,
"Error getting files for the file size view: " + e.getMessage());
467 static long calculateItems(SleuthkitCase sleuthkitCase, FileSizeFilter filter,
long datasourceObjId) {
469 return sleuthkitCase.countFilesWhere(makeQuery(filter, datasourceObjId));
470 }
catch (TskCoreException ex) {
471 logger.log(Level.SEVERE,
"Error getting files by size search view count", ex);
478 return key.accept(
new ContentVisitor.Default<AbstractNode>() {
479 public FileNode visit(AbstractFile f) {
480 return new FileNode(f, false);
483 public FileNode visit(FsContent f) {
484 return new FileNode(f,
false);
488 public FileNode visit(LayoutFile f) {
489 return new FileNode(f,
false);
493 public FileNode visit(File f) {
494 return new FileNode(f,
false);
498 public FileNode visit(Directory f) {
499 return new FileNode(f,
false);
503 public FileNode visit(LocalFile f) {
504 return new FileNode(f,
false);
508 public FileNode visit(DerivedFile f) {
509 return new FileNode(f,
false);
513 public FileNode visit(VirtualDirectory f) {
514 return new FileNode(f,
false);
518 public FileNode visit(SlackFile f) {
519 return new FileNode(f,
false);
523 protected AbstractNode defaultVisit(Content di) {
524 throw new UnsupportedOperationException(
525 NbBundle.getMessage(
this.getClass(),
526 "FileSize.exception.notSupported.msg",
void update(Observable o, Object arg)
FileSize(SleuthkitCase skCase)
void removeIngestModuleEventListener(final PropertyChangeListener listener)
SleuthkitCase getSleuthkitCase()
static synchronized IngestManager getInstance()
FileSizeRootChildren(SleuthkitCase skCase, long datasourceObjId)
final long filteringDSObjId
static final Set< IngestManager.IngestModuleEvent > INGEST_MODULE_EVENTS_OF_INTEREST
void removeIngestJobEventListener(final PropertyChangeListener listener)
static final Set< IngestManager.IngestJobEvent > INGEST_JOB_EVENTS_OF_INTEREST
boolean createKeys(List< FileSizeFilter > list)
Node createNodeForKey(FileSizeFilter key)
final PropertyChangeListener pcl
void addIngestJobEventListener(final PropertyChangeListener listener)
final long datasourceObjId
final long datasourceObjId
final FileSizeFilter filter
T visit(DataSourceFilesNode in)
FileSize(SleuthkitCase skCase, long dsObjId)
FileSizeFilter(int id, String name, String displayName)
void addIngestModuleEventListener(final PropertyChangeListener listener)
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static void addEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
void update(Observable o, Object arg)
public< T > T accept(AutopsyItemVisitor< T > visitor)
static void removeEventTypeSubscriber(Set< Events > eventTypes, PropertyChangeListener subscriber)
static final Set< Case.Events > CASE_EVENTS_OF_INTEREST