19 package org.sleuthkit.autopsy.communications;
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.openide.nodes.AbstractNode;
26 import org.openide.nodes.ChildFactory;
27 import org.openide.nodes.Children;
28 import org.openide.nodes.Node;
29 import org.openide.nodes.Sheet;
30 import org.openide.util.NbBundle;
31 import org.openide.util.lookup.Lookups;
42 class AccountsRootChildren
extends ChildFactory<AccountDeviceInstanceKey> {
44 private static final Logger logger = Logger.getLogger(AccountsRootChildren.class.getName());
46 private final CommunicationsManager commsManager;
47 private final CommunicationsFilter commsFilter;
49 AccountsRootChildren(CommunicationsManager commsManager, CommunicationsFilter commsFilter) {
51 this.commsManager = commsManager;
52 this.commsFilter = commsFilter;
56 protected boolean createKeys(List<AccountDeviceInstanceKey> list) {
57 List<AccountDeviceInstanceKey> accountDeviceInstanceKeys =
new ArrayList<>();
59 for (AccountDeviceInstance accountDeviceInstance : commsManager.getAccountDeviceInstancesWithRelationships(commsFilter)) {
60 long communicationsCount = commsManager.getRelationshipSourcesCount(accountDeviceInstance, commsFilter);
61 String dataSourceName = getDataSourceName(accountDeviceInstance);
62 accountDeviceInstanceKeys.add(
new AccountDeviceInstanceKey(accountDeviceInstance, commsFilter, communicationsCount, dataSourceName));
64 }
catch (TskCoreException tskCoreException) {
65 logger.log(Level.SEVERE,
"Error getting filtered account device instances", tskCoreException);
67 list.addAll(accountDeviceInstanceKeys);
73 protected Node createNodeForKey(AccountDeviceInstanceKey key) {
74 return new AccountDeviceInstanceNode(key, commsManager);
77 private String getDataSourceName(AccountDeviceInstance accountDeviceInstance) {
79 final SleuthkitCase sleuthkitCase = Case.getCurrentCase().getSleuthkitCase();
80 for (DataSource dataSource : sleuthkitCase.getDataSources()) {
81 if (dataSource.getDeviceId().equals(accountDeviceInstance.getDeviceId())) {
82 return sleuthkitCase.getContentById(dataSource.getId()).getName();
85 }
catch (TskCoreException ex) {
86 logger.log(Level.SEVERE,
"Error getting datasource name, falling back on device ID.", ex);
88 return accountDeviceInstance.getDeviceId();
94 static class AccountDeviceInstanceNode
extends AbstractNode {
96 private final AccountDeviceInstanceKey accountDeviceInstanceKey;
97 private final CommunicationsManager commsManager;
98 private final Account account;
100 private AccountDeviceInstanceNode(AccountDeviceInstanceKey accountDeviceInstanceKey, CommunicationsManager commsManager) {
101 super(Children.LEAF, Lookups.fixed(accountDeviceInstanceKey, commsManager));
102 this.accountDeviceInstanceKey = accountDeviceInstanceKey;
103 this.commsManager = commsManager;
104 this.account = accountDeviceInstanceKey.getAccountDeviceInstance().getAccount();
105 setName(account.getTypeSpecificID());
106 setIconBaseWithExtension(
"org/sleuthkit/autopsy/communications/images/" + Utils.getIconFileName(account.getAccountType()));
109 public AccountDeviceInstance getAccountDeviceInstance() {
110 return accountDeviceInstanceKey.getAccountDeviceInstance();
113 public CommunicationsManager getCommsManager() {
117 public CommunicationsFilter getFilter() {
118 return accountDeviceInstanceKey.getCommunicationsFilter();
122 @NbBundle.Messages(value = {
"AccountNode.device=Device",
123 "AccountNode.accountName=Account",
124 "AccountNode.accountType=Type",
125 "AccountNode.messageCount=Msgs"})
126 protected Sheet createSheet() {
127 Sheet s = super.createSheet();
128 Sheet.Set properties = s.get(Sheet.PROPERTIES);
129 if (properties == null) {
130 properties = Sheet.createPropertiesSet();
134 properties.put(
new NodeProperty<>(
"type", Bundle.AccountNode_accountType(),
"type",
135 account.getAccountType().getDisplayName()));
136 properties.put(
new NodeProperty<>(
"count", Bundle.AccountNode_messageCount(),
"count",
137 accountDeviceInstanceKey.getMessageCount()));
138 properties.put(
new NodeProperty<>(
"device", Bundle.AccountNode_device(),
"device",
139 accountDeviceInstanceKey.getDataSourceName()));