19 package org.sleuthkit.autopsy.contentviewers.artifactviewers;
21 import java.awt.Dimension;
22 import java.awt.Toolkit;
23 import java.awt.datatransfer.StringSelection;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.awt.event.MouseAdapter;
27 import java.awt.event.MouseEvent;
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.List;
31 import java.util.concurrent.CancellationException;
32 import java.util.concurrent.ExecutionException;
33 import java.util.logging.Level;
34 import javax.swing.GroupLayout;
35 import javax.swing.GroupLayout.Alignment;
36 import javax.swing.GroupLayout.ParallelGroup;
37 import javax.swing.GroupLayout.SequentialGroup;
38 import javax.swing.JButton;
39 import javax.swing.JLabel;
40 import javax.swing.JMenuItem;
41 import javax.swing.JPanel;
42 import javax.swing.JPopupMenu;
43 import javax.swing.JTextPane;
44 import javax.swing.LayoutStyle.ComponentPlacement;
45 import javax.swing.SwingUtilities;
46 import javax.swing.SwingWorker;
47 import org.openide.util.NbBundle;
48 import org.openide.util.NbBundle.Messages;
65 import org.
sleuthkit.datamodel.InvalidAccountIDException;
73 final class MessageAccountPanel
extends JPanel {
75 private static final long serialVersionUID = 1L;
76 private final static Logger logger = Logger.getLogger(MessageAccountPanel.class.getName());
78 private AccountFetcher currentFetcher = null;
87 void setArtifact(BlackboardArtifact artifact) {
92 if (artifact == null) {
96 if (currentFetcher != null && !currentFetcher.isDone()) {
97 currentFetcher.cancel(
true);
100 currentFetcher =
new AccountFetcher(artifact);
101 currentFetcher.execute();
107 class AccountFetcher
extends SwingWorker<List<AccountContainer>, Void> {
109 private final BlackboardArtifact artifact;
116 AccountFetcher(BlackboardArtifact artifact) {
117 this.artifact = artifact;
121 protected List<AccountContainer> doInBackground() throws Exception {
122 List<AccountContainer> dataList =
new ArrayList<>();
124 CommunicationsManager commManager = Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager();
125 List<Account> accountList = commManager.getAccountsRelatedToArtifact(artifact);
126 for (Account account : accountList) {
128 return new ArrayList<>();
131 if (!((DataSource) (artifact.getDataSource())).getDeviceId().equals(account.getTypeSpecificID())) {
132 List<BlackboardArtifact> contactList = ContactCache.getContacts(account);
133 BlackboardArtifact contact = null;
135 if (contactList != null && !contactList.isEmpty()) {
136 contact = contactList.get(0);
139 if (CentralRepository.isEnabled()) {
140 Collection<PersonaAccount> personAccounts = PersonaAccount.getPersonaAccountsForAccount(account);
141 if (personAccounts != null && !personAccounts.isEmpty()) {
142 for (PersonaAccount personaAccount : PersonaAccount.getPersonaAccountsForAccount(account)) {
143 dataList.add(
new AccountContainer(account, personaAccount, contact));
146 dataList.add(
new AccountContainer(account, null, contact));
149 dataList.add(
new AccountContainer(account, null, contact));
158 "MessageAccountPanel_no_matches=No matches found.",})
160 protected void done() {
162 List<AccountContainer> dataList =
get();
164 if (!dataList.isEmpty()) {
165 dataList.forEach(container -> {
166 container.initalizeSwingControls();
169 GroupLayout layout =
new GroupLayout(MessageAccountPanel.this);
170 layout.setHorizontalGroup(
171 layout.createParallelGroup(Alignment.LEADING)
172 .addGroup(layout.createSequentialGroup()
174 .addGroup(getMainHorizontalGroup(layout, dataList))
175 .addContainerGap(158, Short.MAX_VALUE)));
177 layout.setVerticalGroup(getMainVerticalGroup(layout, dataList));
182 JPanel messagePanel =
new javax.swing.JPanel();
183 JLabel messageLabel =
new javax.swing.JLabel();
185 messagePanel.setLayout(
new java.awt.BorderLayout());
187 messageLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
188 messageLabel.setText(Bundle.MessageAccountPanel_no_matches());
189 messageLabel.setEnabled(
false);
190 messagePanel.add(messageLabel, java.awt.BorderLayout.CENTER);
192 setLayout(
new javax.swing.OverlayLayout(MessageAccountPanel.this));
197 }
catch (CancellationException ex) {
198 logger.log(Level.INFO,
"MessageAccoutPanel thread cancelled", ex);
199 }
catch (InterruptedException | ExecutionException ex) {
200 logger.log(Level.WARNING,
"Failed to get account list for MessageAccountPanel", ex);
210 private ParallelGroup getMainHorizontalGroup(GroupLayout layout, List<AccountContainer> data) {
211 ParallelGroup group = layout.createParallelGroup(Alignment.LEADING);
212 for (AccountContainer o : data) {
213 group.addComponent(o.getAccountLabel());
215 group.addGroup(getPersonaHorizontalGroup(layout, data));
224 private ParallelGroup getMainVerticalGroup(GroupLayout layout, List<AccountContainer> data) {
225 SequentialGroup group = layout.createSequentialGroup();
226 for (AccountContainer o : data) {
228 .addComponent(o.getAccountLabel())
229 .addGroup(o.getContactLineVerticalGroup(layout))
230 .addGroup(o.getPersonLineVerticalGroup(layout));
233 group.addContainerGap(83, Short.MAX_VALUE);
235 return layout.createParallelGroup().addGroup(group);
245 private ParallelGroup getButtonGroup(GroupLayout layout, List<AccountContainer> data) {
246 ParallelGroup group = layout.createParallelGroup(Alignment.LEADING);
247 for (AccountContainer o : data) {
248 group.addComponent(o.getButton());
259 private SequentialGroup getPersonaHorizontalGroup(GroupLayout layout, List<AccountContainer> data) {
260 SequentialGroup group = layout.createSequentialGroup();
261 ParallelGroup pgroup = layout.createParallelGroup(Alignment.LEADING);
263 for (AccountContainer o : data) {
264 pgroup.addGroup(o.getPersonaSequentialGroup(layout));
265 pgroup.addGroup(o.getContactSequentialGroup(layout));
269 .addPreferredGap(ComponentPlacement.RELATED)
270 .addGroup(getButtonGroup(layout, data));
297 JPopupMenu contactPopupMenu =
new JPopupMenu();
298 JPopupMenu personaPopupMenu =
new JPopupMenu();
299 JPopupMenu accountPopupMenu =
new JPopupMenu();
308 if (contactArtifact != null && contactArtifact.getArtifactTypeID() != BlackboardArtifact.ARTIFACT_TYPE.TSK_CONTACT.getTypeID()) {
309 throw new IllegalArgumentException(
"Failed to create AccountContainer object, passed in artifact was not a TSK_CONTACT");
313 this.persona = personaAccount != null ? personaAccount.getPersona() : null;
318 "MessageAccountPanel_persona_label=Persona:",
319 "MessageAccountPanel_unknown_label=Unknown",
320 "MessageAccountPanel_button_view_label=View",
321 "MessageAccountPanel_button_create_label=Create",
322 "MessageAccountPanel_contact_label=Contact:",
323 "MessageAccountPanel_copy_label=Copy"
329 accountLabel =
new JTextPane();
330 accountLabel.setEditable(
false);
331 accountLabel.setOpaque(
false);
332 personaHeader =
new JLabel(Bundle.MessageAccountPanel_persona_label());
333 contactHeader =
new JLabel(Bundle.MessageAccountPanel_contact_label());
334 personaDisplayName =
new JTextPane();
335 personaDisplayName.setOpaque(
false);
336 personaDisplayName.setEditable(
false);
337 personaDisplayName.setPreferredSize(
new Dimension(100, 26));
338 personaDisplayName.setMaximumSize(
new Dimension(100, 26));
339 contactDisplayName =
new JTextPane();
340 contactDisplayName.setOpaque(
false);
341 contactDisplayName.setEditable(
false);
342 contactDisplayName.setPreferredSize(
new Dimension(100, 26));
343 button =
new JButton();
346 accountLabel.setText(account.getTypeSpecificID());
347 contactDisplayName.setText(contactName);
348 personaDisplayName.setText(persona != null ? persona.
getName() : Bundle.MessageAccountPanel_unknown_label());
351 personaDisplayName.setMaximumSize((
new JLabel(personaDisplayName.getText()).getMaximumSize()));
352 contactDisplayName.setMaximumSize((
new JLabel(contactDisplayName.getText()).getMaximumSize()));
353 accountLabel.setMaximumSize((
new JLabel(accountLabel.getText()).getMaximumSize()));
355 button.setText(persona != null ? Bundle.MessageAccountPanel_button_view_label() : Bundle.MessageAccountPanel_button_create_label());
364 contactCopyMenuItem =
new JMenuItem(Bundle.MessageAccountPanel_copy_label());
365 personaCopyMenuItem =
new JMenuItem(Bundle.MessageAccountPanel_copy_label());
366 accountCopyMenuItem =
new JMenuItem(Bundle.MessageAccountPanel_copy_label());
367 personaPopupMenu.add(personaCopyMenuItem);
368 contactPopupMenu.add(contactCopyMenuItem);
369 accountPopupMenu.add(accountCopyMenuItem);
371 personaDisplayName.addMouseListener(
new MouseAdapter() {
373 public void mouseClicked(MouseEvent evt) {
374 if (SwingUtilities.isRightMouseButton(evt)) {
375 personaPopupMenu.show(personaDisplayName, evt.getX(), evt.getY());
380 personaCopyMenuItem.addActionListener(
new ActionListener() {
382 public void actionPerformed(ActionEvent e) {
383 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
new StringSelection(personaDisplayName.getText()), null);
387 contactDisplayName.addMouseListener(
new MouseAdapter() {
389 public void mouseClicked(MouseEvent evt) {
390 if (SwingUtilities.isRightMouseButton(evt)) {
391 contactPopupMenu.show(contactDisplayName, evt.getX(), evt.getY());
396 contactCopyMenuItem.addActionListener(
new ActionListener() {
398 public void actionPerformed(ActionEvent e) {
399 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
new StringSelection(contactDisplayName.getText()), null);
403 accountLabel.addMouseListener(
new MouseAdapter() {
405 public void mouseClicked(MouseEvent evt) {
406 if (SwingUtilities.isRightMouseButton(evt)) {
407 accountPopupMenu.show(accountLabel, evt.getX(), evt.getY());
412 accountCopyMenuItem.addActionListener(
new ActionListener() {
414 public void actionPerformed(ActionEvent e) {
415 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
new StringSelection(accountLabel.getText()), null);
422 if (contactArtifact != null) {
423 BlackboardAttribute attribute = contactArtifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME));
424 if (attribute != null) {
425 return attribute.getValueString();
429 return Bundle.MessageAccountPanel_unknown_label();
441 SwingUtilities.invokeLater(
new Runnable() {
444 personaDisplayName.setText(persona != null ? persona.
getName() : Bundle.MessageAccountPanel_unknown_label());
445 button.setText(persona != null ? Bundle.MessageAccountPanel_button_view_label() : Bundle.MessageAccountPanel_button_create_label());
448 personaDisplayName.setMaximumSize((
new JLabel(personaDisplayName.getText()).getMaximumSize()));
499 SequentialGroup group = layout.createSequentialGroup();
502 .addComponent(personaHeader)
503 .addPreferredGap(ComponentPlacement.RELATED)
504 .addComponent(personaDisplayName);
510 SequentialGroup group = layout.createSequentialGroup();
513 .addComponent(contactHeader)
514 .addPreferredGap(ComponentPlacement.RELATED)
515 .addComponent(contactDisplayName);
528 return layout.createParallelGroup(Alignment.CENTER)
529 .addComponent(personaHeader)
530 .addComponent(personaDisplayName)
531 .addComponent(button);
542 return layout.createParallelGroup(Alignment.CENTER)
543 .addComponent(contactHeader)
544 .addComponent(contactDisplayName);
565 "MessageAccountPanel.account.justification=Account found in Message artifact",
566 "# {0} - accountIdentifer",
567 "MessageAccountPanel_id_not_found_in_cr=Unable to find an account with identifier {0} in the Central Repository."
572 if (persona == null) {
574 MessageAccountPanel.this,
589 boolean showErrorMessage =
true;
595 if (account != null) {
597 showErrorMessage =
false;
599 }
catch (InvalidAccountIDException ex2) {
603 if(showErrorMessage) {
607 logger.log(Level.SEVERE,
"Error looking up account types in the central repository", ex);
boolean addAccount(CentralRepoAccount account, String justification, Persona.Confidence confidence)
String getNameFromContactArtifact(BlackboardArtifact contactArtifact)
void callback(Persona persona)
void setStartupPopupMessage(String message)
JMenuItem contactCopyMenuItem
JMenuItem accountCopyMenuItem
CentralRepoAccount getAccount(CentralRepoAccount.CentralRepoAccountType crAccountType, String accountUniqueID)
PersonaDetailsPanel getDetailsPanel()
Collection< CentralRepoAccountType > getAllAccountTypes()
JTextPane getAccountLabel()
JMenuItem personaCopyMenuItem
SequentialGroup getPersonaSequentialGroup(GroupLayout layout)
void actionPerformed(ActionEvent e)
void initalizeSwingControls()
JTextPane contactDisplayName
SequentialGroup getContactSequentialGroup(GroupLayout layout)
final AccountContainer accountContainer
void initalizePopupMenus()
JTextPane personaDisplayName
void setPersonaName(String name)
ParallelGroup getContactLineVerticalGroup(GroupLayout layout)
final AccountContainer accountContainer
ParallelGroup getPersonLineVerticalGroup(GroupLayout layout)
void setPersona(Persona persona)
static CentralRepository getInstance()