19 package org.sleuthkit.autopsy.contentviewers.artifactviewers;
21 import java.awt.Component;
22 import java.awt.event.ActionListener;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
28 import java.util.concurrent.CancellationException;
29 import java.util.concurrent.ExecutionException;
30 import java.util.logging.Level;
31 import javax.swing.JButton;
32 import javax.swing.SwingWorker;
33 import org.openide.util.NbBundle.Messages;
48 class PersonaAccountFetcher
extends SwingWorker<Map<String, Collection<Persona>>, Void> {
50 private final static Logger logger = Logger.getLogger(PersonaAccountFetcher.class.getName());
52 private final BlackboardArtifact artifact;
53 private final List<AccountPersonaSearcherData> personaSearchDataList;
54 private final Component parentComponent;
63 PersonaAccountFetcher(BlackboardArtifact artifact, List<AccountPersonaSearcherData> personaSearchDataList, Component parentComponent) {
64 this.artifact = artifact;
65 this.personaSearchDataList = personaSearchDataList;
66 this.parentComponent = parentComponent;
70 protected Map<String, Collection<Persona>> doInBackground() throws Exception {
71 Map<String, Collection<Persona>> accountMap =
new HashMap<>();
73 CommunicationsManager commManager = Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager();
75 List<Account> relatedAccountList = commManager.getAccountsRelatedToArtifact(artifact);
77 for (Account account : relatedAccountList) {
80 return new HashMap<>();
83 Collection<PersonaAccount> personaAccountList = PersonaAccount.getPersonaAccountsForAccount(account);
84 Collection<Persona> personaList =
new ArrayList<>();
85 for (PersonaAccount pAccount : personaAccountList) {
86 personaList.add(pAccount.getPersona());
89 accountMap.put(account.getTypeSpecificID(), personaList);
96 protected void done() {
102 Map<String, Collection<Persona>> accountMap =
get();
104 for (AccountPersonaSearcherData searcherData : personaSearchDataList) {
105 Collection<Persona> persona = accountMap.get(searcherData.getAccountIdentifer());
106 updatePersonaControls(searcherData, persona);
109 }
catch (CancellationException ex) {
110 logger.log(Level.INFO,
"Persona searching was canceled.");
111 }
catch (InterruptedException ex) {
112 logger.log(Level.INFO,
"Persona searching was interrupted.");
113 }
catch (ExecutionException ex) {
114 logger.log(Level.SEVERE,
"Fatal error during Persona search.", ex);
117 parentComponent.repaint();
121 "# {0} - Persona count",
122 "PersonaDisplayTask_persona_count_suffix=(1 of {0})"
131 private void updatePersonaControls(AccountPersonaSearcherData personaSearcherData, Collection<Persona> personas) {
133 String personaLabelText = Bundle.CommunicationArtifactViewerHelper_persona_label();
134 String personaButtonText;
135 ActionListener buttonActionListener;
137 if (personas == null || personas.isEmpty()) {
139 personaLabelText += Bundle.CommunicationArtifactViewerHelper_persona_unknown();
142 personaButtonText = Bundle.CommunicationArtifactViewerHelper_persona_button_create();
143 buttonActionListener =
new CreatePersonaButtonListener(parentComponent, personaSearcherData);
145 Persona persona = personas.iterator().next();
146 personaLabelText += persona.getName();
147 if (personas.size() > 1) {
148 personaLabelText += Bundle.PersonaDisplayTask_persona_count_suffix(Integer.toString(personas.size()));
151 personaButtonText = Bundle.CommunicationArtifactViewerHelper_persona_button_view();
152 buttonActionListener =
new ViewPersonaButtonListener(parentComponent, persona);
155 personaSearcherData.getPersonaNameLabel().setText(personaLabelText);
156 personaSearcherData.getPersonaActionButton().setText(personaButtonText);
157 personaSearcherData.getPersonaActionButton().setEnabled(
true);
160 personaSearcherData.getPersonaActionButton().addActionListener(buttonActionListener);
209 private final Component parentComponent;
210 private final AccountPersonaSearcherData personaSearcherData;
212 PersonaCreateCallbackImpl(Component parentComponent, AccountPersonaSearcherData personaSearcherData) {
213 this.parentComponent = parentComponent;
214 this.personaSearcherData = personaSearcherData;
218 public void callback(Persona persona) {
219 JButton personaButton = personaSearcherData.getPersonaActionButton();
220 if (persona != null) {
223 personaSearcherData.getPersonaNameLabel().setText(Bundle.CommunicationArtifactViewerHelper_persona_label() + persona.getName());
224 personaSearcherData.getPersonaActionButton().setText(Bundle.CommunicationArtifactViewerHelper_persona_button_view());
227 for (ActionListener act : personaButton.getActionListeners()) {
228 personaButton.removeActionListener(act);
230 personaButton.addActionListener(
new ViewPersonaButtonListener(parentComponent, persona));
234 personaButton.getParent().revalidate();
241 class PersonaViewCallbackImpl
implements PersonaDetailsDialogCallback {
244 public void callback(Persona persona) {
void actionPerformed(java.awt.event.ActionEvent evt)
final AccountPersonaSearcherData personaSearcherData
final Component parentComponent
final Component parentComponent
void actionPerformed(java.awt.event.ActionEvent evt)