Updated code with propogating lookups and default sorting on size.

This commit is contained in:
Kelly Kelly 2019-04-26 11:32:26 -04:00
parent 849ca42c04
commit bf9c815359
6 changed files with 85 additions and 40 deletions

View File

@ -35,6 +35,7 @@ import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children; import org.openide.nodes.Children;
import org.openide.nodes.Node; import org.openide.nodes.Node;
import org.openide.util.Lookup; import org.openide.util.Lookup;
import org.openide.util.lookup.ProxyLookup;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException; import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
@ -60,7 +61,6 @@ public final class AccountsBrowser extends JPanel implements ExplorerManager.Pro
private final Outline outline; private final Outline outline;
private final ExplorerManager messageBrowserEM = new ExplorerManager();
private final ExplorerManager accountsTableEM = new ExplorerManager(); private final ExplorerManager accountsTableEM = new ExplorerManager();
final RelationshipBrowser relationshipBrowser; final RelationshipBrowser relationshipBrowser;
@ -69,7 +69,7 @@ public final class AccountsBrowser extends JPanel implements ExplorerManager.Pro
* This lookup proxies the selection lookup of both he accounts table and * This lookup proxies the selection lookup of both he accounts table and
* the messages table. * the messages table.
*/ */
private final Lookup lookup; private final ProxyLookup proxyLookup;
public AccountsBrowser() { public AccountsBrowser() {
initComponents(); initComponents();
@ -106,7 +106,8 @@ public final class AccountsBrowser extends JPanel implements ExplorerManager.Pro
} }
}); });
lookup = ExplorerUtils.createLookup(accountsTableEM, getActionMap()); proxyLookup = new ProxyLookup(relationshipBrowser.getLookup(),
ExplorerUtils.createLookup(accountsTableEM, getActionMap()));
} }
private void setColumnWidths() { private void setColumnWidths() {
@ -178,6 +179,6 @@ public final class AccountsBrowser extends JPanel implements ExplorerManager.Pro
@Override @Override
public Lookup getLookup() { public Lookup getLookup() {
return lookup; return proxyLookup;
} }
} }

View File

@ -51,7 +51,7 @@ PinAccountsAction.singularText=Add Selected Account to Visualization
refreshText=Refresh Results refreshText=Refresh Results
ResetAndPinAccountsAction.pluralText=Visualize Only Selected Accounts ResetAndPinAccountsAction.pluralText=Visualize Only Selected Accounts
ResetAndPinAccountsAction.singularText=Visualize Only Selected Account ResetAndPinAccountsAction.singularText=Visualize Only Selected Account
ThumbnailViewer_Name=Thumbnails ThumbnailViewer_Name=Media
UnpinAccountsAction.pluralText=Remove Selected Accounts UnpinAccountsAction.pluralText=Remove Selected Accounts
UnpinAccountsAction.singularText=Remove Selected Account UnpinAccountsAction.singularText=Remove Selected Account
VisalizationPanel.paintingError=Problem painting visualization. VisalizationPanel.paintingError=Problem painting visualization.

View File

@ -18,33 +18,42 @@
*/ */
package org.sleuthkit.autopsy.communications; package org.sleuthkit.autopsy.communications;
import java.awt.Component;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.openide.util.Lookup;
import org.openide.util.lookup.ProxyLookup;
/** /**
* Displays the Relationship information for the currently selected accounts. * Displays the Relationship information for the currently selected accounts.
* *
*/ */
final class RelationshipBrowser extends JPanel { final class RelationshipBrowser extends JPanel implements Lookup.Provider {
private SelectionInfo currentSelection; private SelectionInfo currentSelection;
private final MessagesViewer messagesViewer; private final MessagesViewer messagesViewer;
private final ContactsViewer contactsViewer; private final ContactsViewer contactsViewer;
private final ThumbnailViewer thumbnailViewer; private final ThumbnailViewer thumbnailsViewer;
private final ModifiableProxyLookup proxyLookup;
/** /**
* Creates new form RelationshipBrowser * Creates new form RelationshipBrowser
*/ */
public RelationshipBrowser() { public RelationshipBrowser() {
initComponents();
messagesViewer = new MessagesViewer(); messagesViewer = new MessagesViewer();
contactsViewer = new ContactsViewer(); contactsViewer = new ContactsViewer();
thumbnailViewer = new ThumbnailViewer(); thumbnailsViewer = new ThumbnailViewer();
proxyLookup = new ModifiableProxyLookup(messagesViewer.getLookup());
initComponents();
tabPane.add(messagesViewer.getDisplayName(), messagesViewer); tabPane.add(messagesViewer.getDisplayName(), messagesViewer);
tabPane.add(contactsViewer.getDisplayName(), contactsViewer); tabPane.add(contactsViewer.getDisplayName(), contactsViewer);
tabPane.add(thumbnailViewer.getDisplayName(), thumbnailViewer); tabPane.add(thumbnailsViewer.getDisplayName(), thumbnailsViewer);
} }
/** /**
@ -99,6 +108,12 @@ final class RelationshipBrowser extends JPanel {
if(currentSelection != null) { if(currentSelection != null) {
((RelationshipsViewer) tabPane.getSelectedComponent()).setSelectionInfo(currentSelection); ((RelationshipsViewer) tabPane.getSelectedComponent()).setSelectionInfo(currentSelection);
} }
Component selectedComponent = tabPane.getSelectedComponent();
if(selectedComponent instanceof Lookup.Provider) {
Lookup lookup = ((Lookup.Provider)selectedComponent).getLookup();
proxyLookup.setNewLookups(lookup);
}
}//GEN-LAST:event_tabPaneStateChanged }//GEN-LAST:event_tabPaneStateChanged
@ -106,4 +121,9 @@ final class RelationshipBrowser extends JPanel {
private javax.swing.JScrollPane scrollPane; private javax.swing.JScrollPane scrollPane;
private javax.swing.JTabbedPane tabPane; private javax.swing.JTabbedPane tabPane;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
@Override
public Lookup getLookup() {
return proxyLookup;
}
} }

View File

@ -19,11 +19,12 @@
package org.sleuthkit.autopsy.communications; package org.sleuthkit.autopsy.communications;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.openide.util.Lookup;
/** /**
* Interface for Controls wishing to appear in the RelationshipBrowser tabPane. * Interface for Controls wishing to appear in the RelationshipBrowser tabPane.
*/ */
public interface RelationshipsViewer { public interface RelationshipsViewer extends Lookup.Provider {
/** /**
* Returns the value to be displayed on the "tab" * Returns the value to be displayed on the "tab"

View File

@ -21,6 +21,7 @@ package org.sleuthkit.autopsy.communications;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level; import java.util.logging.Level;
import org.openide.nodes.Children; import org.openide.nodes.Children;
import org.openide.nodes.Node; import org.openide.nodes.Node;
@ -38,32 +39,48 @@ import org.sleuthkit.datamodel.TskCoreException;
/** /**
* Factory for creating thumbnail children nodes. * Factory for creating thumbnail children nodes.
* *
* Given the current way that DataResultViewerThumbnail works this class must
* extend Children.Keys not ChildNodeFactory. When a ChildNodeFactory is used
* the addNotify function in ThumbnailChildNode ends up wtih a list containing
* just the wait node and the thumbanils never appear.
*/ */
public class ThumbnailChildren extends Children.Keys<AbstractFile> { final class ThumbnailChildren extends Children.Keys<AbstractFile> {
private static final Logger logger = Logger.getLogger(ThumbnailChildren.class.getName()); private static final Logger logger = Logger.getLogger(ThumbnailChildren.class.getName());
private final Set<AbstractFile> thumbnails; private final Set<AbstractFile> thumbnails;
/* /*
* Creates the list of thumbnails from the given list of BlackboardArtifacts. * Creates the list of thumbnails from the given list of
* BlackboardArtifacts.
*
* The thumbnails will be initialls sorted by size, then name so that they
* appear sorted by size by default.
*/ */
ThumbnailChildren(Set<BlackboardArtifact> artifacts) { ThumbnailChildren(Set<BlackboardArtifact> artifacts) {
super(false); super(false);
thumbnails = new HashSet<>(); thumbnails = new TreeSet<>((AbstractFile file1, AbstractFile file2) -> {
int result = Long.compare(file1.getSize(), file2.getSize());
if (result == 0) {
result = file1.getName().compareTo(file2.getName());
}
return result;
});
artifacts.forEach((bba) -> { artifacts.forEach((bba) -> {
try{ try {
for(Content childContent: bba.getChildren()) { for (Content childContent : bba.getChildren()) {
if(childContent instanceof AbstractFile && ImageUtils.thumbnailSupported((AbstractFile)childContent)) { if (childContent instanceof AbstractFile && ImageUtils.thumbnailSupported((AbstractFile) childContent)) {
thumbnails.add((AbstractFile)childContent); thumbnails.add((AbstractFile) childContent);
} }
} }
} catch(TskCoreException ex) { } catch (TskCoreException ex) {
logger.log(Level.WARNING, "Unable to get children from artifact.", ex); //NON-NLS logger.log(Level.WARNING, "Unable to get children from artifact.", ex); //NON-NLS
} }
}); });
} }
@Override @Override
protected Node[] createNodes(AbstractFile t) { protected Node[] createNodes(AbstractFile t) {
return new Node[]{new ThumbnailNode(t)}; return new Node[]{new ThumbnailNode(t)};
@ -74,13 +91,13 @@ public class ThumbnailChildren extends Children.Keys<AbstractFile> {
super.addNotify(); super.addNotify();
setKeys(thumbnails); setKeys(thumbnails);
} }
/** /**
* A node for representing a thumbnail. * A node for representing a thumbnail.
*/ */
private static class ThumbnailNode extends FileNode { static class ThumbnailNode extends FileNode {
ThumbnailNode(AbstractFile file) { ThumbnailNode(AbstractFile file) {
super(file, false); super(file, false);
} }
@ -88,18 +105,18 @@ public class ThumbnailChildren extends Children.Keys<AbstractFile> {
protected Sheet createSheet() { protected Sheet createSheet() {
Sheet sheet = super.createSheet(); Sheet sheet = super.createSheet();
Set<String> keepProps = new HashSet<>(Arrays.asList( Set<String> keepProps = new HashSet<>(Arrays.asList(
NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.nameColLbl"), NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.nameColLbl"),
NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.score.name"), NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.score.name"),
NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.comment.name"), NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.comment.name"),
NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.count.name"), NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.createSheet.count.name"),
NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.sizeColLbl"), NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.sizeColLbl"),
NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.mimeType"), NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.mimeType"),
NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.knownColLbl"))); NbBundle.getMessage(AbstractAbstractFileNode.class, "AbstractAbstractFileNode.knownColLbl")));
//Remove all other props except for the ones above //Remove all other props except for the ones above
Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES); Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
for(Node.Property<?> p : sheetSet.getProperties()) { for (Node.Property<?> p : sheetSet.getProperties()) {
if(!keepProps.contains(p.getName())){ if (!keepProps.contains(p.getName())) {
sheetSet.remove(p.getName()); sheetSet.remove(p.getName());
} }
} }

View File

@ -58,7 +58,7 @@ public class ThumbnailViewer extends JPanel implements RelationshipsViewer, Expl
private final ModifiableProxyLookup proxyLookup; private final ModifiableProxyLookup proxyLookup;
@Messages({ @Messages({
"ThumbnailViewer_Name=Thumbnails" "ThumbnailViewer_Name=Media"
}) })
/** /**
* Creates new form ThumbnailViewer * Creates new form ThumbnailViewer
@ -93,6 +93,8 @@ public class ThumbnailViewer extends JPanel implements RelationshipsViewer, Expl
handleNodeSelectionChange(); handleNodeSelectionChange();
} }
}); });
thumbnailViewer.resetComponent();
} }
@Override @Override
@ -121,7 +123,11 @@ public class ThumbnailViewer extends JPanel implements RelationshipsViewer, Expl
}); });
} catch (TskCoreException | NoCurrentCaseException ex) { } catch (TskCoreException | NoCurrentCaseException ex) {
logger.log(Level.WARNING, "Unable to update selection." , ex);
}
if(artifactList.size() == 0) {
thumbnailViewer.resetComponent();
} }
thumbnailViewer.setNode(new TableFilterNode(new DataResultFilterNode(new AbstractNode(new ThumbnailChildren(artifactList)), tableEM), true)); thumbnailViewer.setNode(new TableFilterNode(new DataResultFilterNode(new AbstractNode(new ThumbnailChildren(artifactList)), tableEM), true));