mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-13 00:16:16 +00:00
Created Keys class for DataSource to update more cleanly when new data sources are added
This commit is contained in:
parent
23e17c3a77
commit
820135d772
@ -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,27 +18,79 @@
|
|||||||
*/
|
*/
|
||||||
package org.sleuthkit.autopsy.datamodel;
|
package org.sleuthkit.autopsy.datamodel;
|
||||||
|
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
|
import java.beans.PropertyChangeListener;
|
||||||
|
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
|
||||||
*/
|
*/
|
||||||
public class DataSourcesNode extends DisplayableItemNode {
|
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. */
|
||||||
|
private static class DataSourcesNodeChildren extends AbstractContentChildren<Content> {
|
||||||
|
private static final Logger logger = Logger.getLogger(DataSourcesNodeChildren.class.getName());
|
||||||
|
|
||||||
|
public DataSourcesNodeChildren() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
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())) {
|
||||||
|
addNotify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addNotify() {
|
||||||
|
Case.addPropertyChangeListener(pcl);
|
||||||
|
try {
|
||||||
|
setKeys(Case.getCurrentCase().getDataSources());
|
||||||
|
} catch (TskCoreException | IllegalStateException ex) {
|
||||||
|
logger.severe("Error getting data sources: " + ex.getMessage()); // NON-NLS
|
||||||
|
setKeys(Collections.EMPTY_SET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void removeNotify() {
|
||||||
|
Case.removePropertyChangeListener(pcl);
|
||||||
|
setKeys(Collections.EMPTY_SET);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@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)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user