19 package org.sleuthkit.autopsy.communications;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.concurrent.ExecutionException;
25 import java.util.logging.Level;
26 import javax.swing.Action;
27 import org.openide.nodes.AbstractNode;
28 import org.openide.nodes.Children;
29 import org.openide.nodes.Sheet;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
32 import org.openide.util.lookup.Lookups;
40 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME;
48 final class AccountDeviceInstanceNode
extends AbstractNode {
50 private static final Logger logger = Logger.getLogger(AccountDeviceInstanceNode.class.getName());
52 private final AccountDeviceInstanceKey accountDeviceInstanceKey;
53 private final CommunicationsManager commsManager;
54 private final Account account;
56 private static final BlackboardAttribute.Type NAME_ATTRIBUTE =
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.fromID(TSK_NAME.getTypeID()));
58 AccountDeviceInstanceNode(AccountDeviceInstanceKey accountDeviceInstanceKey, CommunicationsManager commsManager) {
59 super(Children.LEAF, Lookups.fixed(accountDeviceInstanceKey, commsManager));
60 this.accountDeviceInstanceKey = accountDeviceInstanceKey;
61 this.commsManager = commsManager;
62 this.account = accountDeviceInstanceKey.getAccountDeviceInstance().getAccount();
63 setName(account.getTypeSpecificID());
64 setDisplayName(getName());
65 String iconPath = Utils.getIconFilePath(account.getAccountType());
66 this.setIconBaseWithExtension(iconPath != null && iconPath.charAt(0) ==
'/' ? iconPath.substring(1) : iconPath);
69 AccountDeviceInstance getAccountDeviceInstance() {
70 return accountDeviceInstanceKey.getAccountDeviceInstance();
73 AccountDeviceInstanceKey getAccountDeviceInstanceKey() {
74 return accountDeviceInstanceKey;
77 CommunicationsManager getCommsManager() {
81 long getMessageCount() {
82 return accountDeviceInstanceKey.getMessageCount();
85 CommunicationsFilter getFilter() {
86 return accountDeviceInstanceKey.getCommunicationsFilter();
90 @NbBundle.Messages(value = {
"AccountNode.device=Device",
"AccountNode.accountName=Account",
"AccountNode.accountType=Type",
"AccountNode.messageCount=Items"})
91 protected Sheet createSheet() {
92 Sheet sheet = super.createSheet();
93 Sheet.Set properties = sheet.get(Sheet.PROPERTIES);
94 if (properties == null) {
95 properties = Sheet.createPropertiesSet();
96 sheet.put(properties);
98 properties.put(
new NodeProperty<>(
"type",
99 Bundle.AccountNode_accountType(),
101 account.getAccountType().getDisplayName()));
102 properties.put(
new NodeProperty<>(
"count",
103 Bundle.AccountNode_messageCount(),
105 accountDeviceInstanceKey.getMessageCount()));
106 properties.put(
new NodeProperty<>(
"device",
107 Bundle.AccountNode_device(),
109 accountDeviceInstanceKey.getDataSourceName()));
114 public Action[] getActions(
boolean context) {
115 ArrayList<Action> actions =
new ArrayList<>(Arrays.asList(super.getActions(context)));
116 actions.add(PinAccountsAction.getInstance());
117 actions.add(ResetAndPinAccountsAction.getInstance());
118 return actions.toArray(
new Action[actions.size()]);
122 "# {0} - Contact Name",
123 "# {1} - Persona Name",
124 "AccountInstanceNode_Tooltip_Template=Contact: {0} - Persona: {1}",
125 "# {0} - PersonaAccount count",
126 "AccountInstanceNode_Tooltip_suffix=(1 of {0})"
129 public String getShortDescription() {
130 List<PersonaAccount> personaList;
131 List<BlackboardArtifact> contactArtifactList;
133 personaList = CVTPersonaCache.getPersonaAccounts(account);
134 contactArtifactList = ContactCache.getContacts(account);
135 }
catch (ExecutionException ex) {
136 logger.log(Level.WARNING,
"Failed to retrieve Persona details for node.", ex);
137 return getDisplayName();
141 if (personaList != null && !personaList.isEmpty()) {
142 personaName = personaList.get(0).getPersona().getName();
143 if (personaList.size() > 1) {
144 personaName += Bundle.AccountInstanceNode_Tooltip_suffix(Integer.toString(personaList.size()));
147 personaName =
"None";
150 String contactName = getDisplayName();
151 if (contactArtifactList != null && !contactArtifactList.isEmpty()) {
153 BlackboardArtifact contactArtifact = contactArtifactList.get(0);
154 BlackboardAttribute attribute = contactArtifact.getAttribute(NAME_ATTRIBUTE);
155 if (attribute != null) {
156 contactName = attribute.getValueString();
158 }
catch (TskCoreException ex) {
159 logger.log(Level.WARNING,
"Failed to retrive name attribute from contact artifact.", ex);
163 return Bundle.AccountInstanceNode_Tooltip_Template(contactName, personaName);