mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-12 16:06:15 +00:00
Merge pull request #1377 from sleuthkit/datasourceRefresh
Datasource refresh
This commit is contained in:
commit
f5fe025df1
@ -176,11 +176,7 @@ abstract class AbstractContentChildren<T> extends Keys<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractNode visit(DataSources i) {
|
public AbstractNode visit(DataSources i) {
|
||||||
try {
|
return new DataSourcesNode();
|
||||||
return new DataSourcesNode(Case.getCurrentCase().getDataSources());
|
|
||||||
} catch (TskCoreException ex) {
|
|
||||||
return defaultVisit(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,12 +18,18 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.datamodel;
|
package org.sleuthkit.autopsy.datamodel;
|
||||||
|
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.openide.nodes.Sheet;
|
import org.openide.nodes.Sheet;
|
||||||
import org.openide.util.NbBundle;
|
import org.openide.util.NbBundle;
|
||||||
import org.openide.util.lookup.Lookups;
|
import org.openide.util.lookup.Lookups;
|
||||||
|
import org.sleuthkit.autopsy.casemodule.Case;
|
||||||
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
import org.sleuthkit.datamodel.Content;
|
import org.sleuthkit.datamodel.Content;
|
||||||
|
import org.sleuthkit.datamodel.TskCoreException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nodes for the images
|
* Nodes for the images
|
||||||
@ -32,13 +38,84 @@ public class DataSourcesNode extends DisplayableItemNode {
|
|||||||
|
|
||||||
public static final String NAME = NbBundle.getMessage(DataSourcesNode.class, "DataSourcesNode.name");
|
public static final String NAME = NbBundle.getMessage(DataSourcesNode.class, "DataSourcesNode.name");
|
||||||
|
|
||||||
|
// NOTE: The images passed in via argument will be ignored.
|
||||||
|
@Deprecated
|
||||||
public DataSourcesNode(List<Content> images) {
|
public DataSourcesNode(List<Content> images) {
|
||||||
super(new RootContentChildren(images), Lookups.singleton(NAME));
|
super(new DataSourcesNodeChildren(), Lookups.singleton(NAME));
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataSourcesNode() {
|
||||||
|
super(new DataSourcesNodeChildren(), Lookups.singleton(NAME));
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
setName(NAME);
|
setName(NAME);
|
||||||
setDisplayName(NAME);
|
setDisplayName(NAME);
|
||||||
this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/image.png"); //NON-NLS
|
this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/image.png"); //NON-NLS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Custom Keys implementation that listens for new data sources being added. */
|
||||||
|
// @@@ This can become private once DirectoryTree doesn't want to refresh the entire tree
|
||||||
|
public static class DataSourcesNodeChildren extends AbstractContentChildren<Content> {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(DataSourcesNodeChildren.class.getName());
|
||||||
|
|
||||||
|
List<Content> currentKeys;
|
||||||
|
|
||||||
|
public DataSourcesNodeChildren() {
|
||||||
|
super();
|
||||||
|
this.currentKeys = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final PropertyChangeListener pcl = new PropertyChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
|
String eventType = evt.getPropertyName();
|
||||||
|
if (eventType.equals(Case.Events.DATA_SOURCE_ADDED.toString())) {
|
||||||
|
reloadKeys();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addNotify() {
|
||||||
|
Case.addPropertyChangeListener(pcl);
|
||||||
|
reloadKeys();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void removeNotify() {
|
||||||
|
Case.removePropertyChangeListener(pcl);
|
||||||
|
currentKeys.clear();
|
||||||
|
setKeys(Collections.<Content>emptySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reloadKeys() {
|
||||||
|
try {
|
||||||
|
currentKeys = Case.getCurrentCase().getDataSources();
|
||||||
|
setKeys(currentKeys);
|
||||||
|
} catch (TskCoreException | IllegalStateException ex) {
|
||||||
|
logger.severe("Error getting data sources: " + ex.getMessage()); // NON-NLS
|
||||||
|
setKeys(Collections.<Content>emptySet());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh all content keys
|
||||||
|
* This creates new nodes of keys have changed.
|
||||||
|
*/
|
||||||
|
// I think this goes away once we get more listeners in place
|
||||||
|
// It was added as an interim stage
|
||||||
|
@Deprecated
|
||||||
|
public void refreshContentKeys() {
|
||||||
|
for (Content key : currentKeys) {
|
||||||
|
refreshKey(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLeafTypeNode() {
|
public boolean isLeafTypeNode() {
|
||||||
return false;
|
return false;
|
||||||
|
@ -573,7 +573,8 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
|
|||||||
}
|
}
|
||||||
} // if the image is added to the case
|
} // if the image is added to the case
|
||||||
else if (changed.equals(Case.Events.DATA_SOURCE_ADDED.toString())) {
|
else if (changed.equals(Case.Events.DATA_SOURCE_ADDED.toString())) {
|
||||||
componentOpened();
|
// we don't need to do anything in here.
|
||||||
|
// DataSourcesNode is listening for these events and updates itself
|
||||||
}
|
}
|
||||||
// change in node selection
|
// change in node selection
|
||||||
else if (changed.equals(ExplorerManager.PROP_SELECTED_NODES)) {
|
else if (changed.equals(ExplorerManager.PROP_SELECTED_NODES)) {
|
||||||
@ -778,7 +779,7 @@ public final class DirectoryTreeTopComponent extends TopComponent implements Dat
|
|||||||
|
|
||||||
Node imagesNode = imagesNodeOrig.getNode();
|
Node imagesNode = imagesNodeOrig.getNode();
|
||||||
|
|
||||||
RootContentChildren contentRootChildren = (RootContentChildren) imagesNode.getChildren();
|
DataSourcesNode.DataSourcesNodeChildren contentRootChildren = (DataSourcesNode.DataSourcesNodeChildren) imagesNode.getChildren();
|
||||||
contentRootChildren.refreshContentKeys();
|
contentRootChildren.refreshContentKeys();
|
||||||
|
|
||||||
//final TreeView tree = getTree();
|
//final TreeView tree = getTree();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user