Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PersonaDetailsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.centralrepository.persona;
20 
21 import java.awt.Component;
22 import java.awt.event.ActionEvent;
23 import java.text.SimpleDateFormat;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.HashMap;
27 import java.util.Date;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.logging.Level;
31 import javax.swing.JButton;
32 import javax.swing.JOptionPane;
33 import javax.swing.JTable;
34 import javax.swing.ListSelectionModel;
35 import javax.swing.event.ListSelectionEvent;
36 import javax.swing.table.DefaultTableModel;
37 import org.apache.commons.lang.StringUtils;
38 import org.openide.windows.TopComponent;
39 import org.openide.util.NbBundle.Messages;
40 import org.openide.windows.RetainLocation;
51 
55 @TopComponent.Description(preferredID = "PersonaDetailsTopComponent", persistenceType = TopComponent.PERSISTENCE_NEVER)
56 @TopComponent.Registration(mode = "personadetails", openAtStartup = false)
57 @RetainLocation("personadetails")
58 @SuppressWarnings("PMD.SingularField")
59 public final class PersonaDetailsPanel extends javax.swing.JPanel {
60 
61  private static final long serialVersionUID = 1L;
62 
63  private static final Logger logger = Logger.getLogger(PersonaDetailsPanel.class.getName());
64 
66 
67  private final List<PAccount> accountsToAdd = new ArrayList<>();
68  private final List<PMetadata> metadataToAdd = new ArrayList<>();
69  private final List<PAlias> aliasesToAdd = new ArrayList<>();
70 
71  private final List<PersonaAccount> accountsToRemove = new ArrayList<>();
72  private final List<PersonaMetadata> metadataToRemove = new ArrayList<>();
73  private final List<PersonaAlias> aliasesToRemove = new ArrayList<>();
74 
75  private final Map<PersonaAccount, PAccount> accountsToEdit = new HashMap<>();
76  private final Map<PersonaMetadata, PMetadata> metadataToEdit = new HashMap<>();
77  private final Map<PersonaAlias, PAlias> aliasesToEdit = new HashMap<>();
78 
80  private List<PersonaAccount> currentAccounts = new ArrayList<>();
81  private List<PersonaMetadata> currentMetadata = new ArrayList<>();
82  private List<PersonaAlias> currentAliases = new ArrayList<>();
83  private List<CorrelationCase> currentCases = new ArrayList<>();
84 
85  private PersonaDetailsTableModel accountsModel;
86  private PersonaDetailsTableModel metadataModel;
87  private PersonaDetailsTableModel aliasesModel;
88  private PersonaDetailsTableModel casesModel;
89 
90  @Messages({
91  "PersonaDetailsPanel_empty_justification_Title=Empty justification",
92  "PersonaDetailsPanel_empty_justification_msg=The justification field cannot be empty",})
94  initComponents();
95  clear();
96 
97  // Accounts
98  addAccountBtn.addActionListener((ActionEvent e) -> {
99  new PersonaAccountDialog(this);
100  });
101  editAccountBtn.addActionListener((ActionEvent e) -> {
102  int selectedRow = accountsTable.getSelectedRow();
103  if (selectedRow != -1) {
104  if (selectedRow >= currentAccounts.size()) {
105  PAccount acc = accountsToAdd.get(selectedRow - currentAccounts.size());
106  new PersonaAccountDialog(this, acc);
107  } else {
108  PersonaAccount personaAccount = currentAccounts.get(selectedRow);
109  accountsToEdit.putIfAbsent(personaAccount, new PAccount(personaAccount.getAccount(), personaAccount.getJustification(), personaAccount.getConfidence()));
110  new PersonaAccountDialog(this, accountsToEdit.get(personaAccount));
111  }
112  }
113  });
114  deleteAccountBtn.addActionListener((ActionEvent e) -> {
115  int selectedRow = accountsTable.getSelectedRow();
116  if (selectedRow != -1) {
117  // We're keeping accounts in two separate data structures
118  if (selectedRow >= currentAccounts.size()) {
119  accountsToAdd.remove(selectedRow - currentAccounts.size());
120  } else {
121  PersonaAccount toRemove = currentAccounts.get(selectedRow);
122  accountsToEdit.remove(toRemove);
123  accountsToRemove.add(toRemove);
124  currentAccounts.remove(toRemove);
125  }
126  updateAccountsTable();
127  }
128  });
129  accountsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
130  accountsTable.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
131  handleSelectionChange(e, editAccountBtn, deleteAccountBtn, accountsTable);
132  });
133 
134  // Metadata
135  addMetadataBtn.addActionListener((ActionEvent e) -> {
136  new PersonaMetadataDialog(this);
137  });
138  editMetadataBtn.addActionListener((ActionEvent e) -> {
139  int selectedRow = metadataTable.getSelectedRow();
140  if (selectedRow != -1) {
141  if (selectedRow >= currentMetadata.size()) {
142  PMetadata md = metadataToAdd.get(selectedRow - currentMetadata.size());
143  new PersonaMetadataDialog(this, md);
144  } else {
145  PersonaMetadata personaMetadata = currentMetadata.get(selectedRow);
146  metadataToEdit.putIfAbsent(personaMetadata, new PMetadata(personaMetadata.getName(), personaMetadata.getValue(), personaMetadata.getJustification(), personaMetadata.getConfidence()));
147  new PersonaMetadataDialog(this, metadataToEdit.get(personaMetadata));
148  }
149  }
150  });
151  deleteMetadataBtn.addActionListener((ActionEvent e) -> {
152  int selectedRow = metadataTable.getSelectedRow();
153  if (selectedRow != -1) {
154  // We're keeping metadata in two separate data structures
155  if (selectedRow >= currentMetadata.size()) {
156  metadataToAdd.remove(selectedRow - currentMetadata.size());
157  } else {
158  PersonaMetadata toRemove = currentMetadata.get(selectedRow);
159  metadataToEdit.remove(toRemove);
160  metadataToRemove.add(toRemove);
161  currentMetadata.remove(toRemove);
162  }
163  updateMetadataTable();
164  }
165  });
166  metadataTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
167  metadataTable.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
168  handleSelectionChange(e, editMetadataBtn, deleteMetadataBtn, metadataTable);
169  });
170 
171  // Aliases
172  addAliasBtn.addActionListener((ActionEvent e) -> {
173  new PersonaAliasDialog(this);
174  });
175  editAliasBtn.addActionListener((ActionEvent e) -> {
176  int selectedRow = aliasesTable.getSelectedRow();
177  if (selectedRow != -1) {
178  if (selectedRow >= currentAliases.size()) {
179  PAlias pa = aliasesToAdd.get(selectedRow - currentAliases.size());
180  new PersonaAliasDialog(this, pa);
181  } else {
182  PersonaAlias personaAlias = currentAliases.get(selectedRow);
183  aliasesToEdit.putIfAbsent(personaAlias, new PAlias(personaAlias.getAlias(), personaAlias.getJustification(), personaAlias.getConfidence()));
184  new PersonaAliasDialog(this, aliasesToEdit.get(personaAlias));
185  }
186  }
187  });
188  deleteAliasBtn.addActionListener((ActionEvent e) -> {
189  int selectedRow = aliasesTable.getSelectedRow();
190  if (selectedRow != -1) {
191  // We're keeping aliases in two separate data structures
192  if (selectedRow >= currentAliases.size()) {
193  aliasesToAdd.remove(selectedRow - currentAliases.size());
194  } else {
195  PersonaAlias toRemove = currentAliases.get(selectedRow);
196  aliasesToEdit.remove(toRemove);
197  aliasesToRemove.add(toRemove);
198  currentAliases.remove(toRemove);
199  }
200  updateAliasesTable();
201  }
202  });
203  aliasesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
204  aliasesTable.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
205  handleSelectionChange(e, editAliasBtn, deleteAliasBtn, aliasesTable);
206  });
207  }
208 
209  private void handleSelectionChange(ListSelectionEvent e, JButton editBtn, JButton deleteBtn, JTable table) {
210  if (e.getValueIsAdjusting()) {
211  return;
212  }
213  editBtn.setEnabled(mode != PersonaDetailsMode.VIEW && table.getSelectedRow() != -1);
214  deleteBtn.setEnabled(mode != PersonaDetailsMode.VIEW && table.getSelectedRow() != -1);
215  }
216 
217  void addEditExistingAccount(PersonaAccount account, String justification, Persona.Confidence confidence) {
218  accountsToEdit.put(account, new PAccount(account.getAccount(), justification, confidence));
219  }
220 
221  void addEditExistingMetadata(PersonaMetadata metadata, String justification, Persona.Confidence confidence) {
222  metadataToEdit.put(metadata, new PMetadata(metadata.getName(), metadata.getValue(), justification, confidence));
223  }
224 
225  void addEditExistingAlias(PersonaAlias alias, String justification, Persona.Confidence confidence) {
226  aliasesToEdit.put(alias, new PAlias(alias.getAlias(), justification, confidence));
227  }
228 
232  class PAccount {
233 
234  CentralRepoAccount account;
235  String justification;
236  Persona.Confidence confidence;
237 
238  PAccount(CentralRepoAccount account, String justification, Persona.Confidence confidence) {
239  this.account = account;
240  this.justification = justification;
241  this.confidence = confidence;
242  }
243  }
244 
245  boolean accountExists(CentralRepoAccount account) {
246  for (PersonaAccount acc : currentAccounts) {
247  if (acc.getAccount().getId() == account.getId()) {
248  return true;
249  }
250  }
251  for (PAccount acc : accountsToAdd) {
252  if (acc.account.getId() == account.getId()) {
253  return true;
254  }
255  }
256  return false;
257  }
258 
259  public boolean addAccount(CentralRepoAccount account, String justification, Persona.Confidence confidence) {
260  if (!accountExists(account)) {
261  accountsToAdd.add(new PAccount(account, justification, confidence));
262  updateAccountsTable();
263  return true;
264  }
265  return false;
266  }
267 
271  class PMetadata {
272 
273  String name;
274  String value;
275  String justification;
276  Persona.Confidence confidence;
277 
278  PMetadata(String name, String value, String justification, Persona.Confidence confidence) {
279  this.name = name;
280  this.value = value;
281  this.justification = justification;
282  this.confidence = confidence;
283  }
284  }
285 
286  boolean metadataExists(String name) {
287  for (PersonaMetadata pm : currentMetadata) {
288  if (pm.getName().equals(name)) {
289  return true;
290  }
291  }
292  for (PMetadata pm : metadataToAdd) {
293  if (pm.name.equals(name)) {
294  return true;
295  }
296  }
297  return false;
298  }
299 
300  boolean addMetadata(String name, String value, String justification, Persona.Confidence confidence) {
301  if (!metadataExists(name)) {
302  metadataToAdd.add(new PMetadata(name, value, justification, confidence));
303  updateMetadataTable();
304  return true;
305  }
306  return false;
307  }
308 
312  class PAlias {
313 
314  String alias;
315  String justification;
316  Persona.Confidence confidence;
317 
318  PAlias(String alias, String justification, Persona.Confidence confidence) {
319  this.alias = alias;
320  this.justification = justification;
321  this.confidence = confidence;
322  }
323  }
324 
325  boolean aliasExists(String alias) {
326  for (PersonaAlias pa : currentAliases) {
327  if (pa.getAlias().equals(alias)) {
328  return true;
329  }
330  }
331  for (PAlias pa : aliasesToAdd) {
332  if (pa.alias.equals(alias)) {
333  return true;
334  }
335  }
336  return false;
337  }
338 
339  boolean addAlias(String alias, String justification, Persona.Confidence confidence) {
340  if (!aliasExists(alias)) {
341  aliasesToAdd.add(new PAlias(alias, justification, confidence));
342  updateAliasesTable();
343  return true;
344  }
345  return false;
346  }
347 
353  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
354  private void initComponents() {
355 
356  detailsPanel = new javax.swing.JPanel();
357  examinerLbl = new javax.swing.JLabel();
358  examinerField = new javax.swing.JTextField();
359  creationDateLbl = new javax.swing.JLabel();
360  creationDateField = new javax.swing.JTextField();
361  commentLbl = new javax.swing.JLabel();
362  commentField = new javax.swing.JTextField();
363  nameLbl = new javax.swing.JLabel();
364  nameField = new javax.swing.JTextField();
365  accountsLbl = new javax.swing.JLabel();
366  accountsTablePane = new javax.swing.JScrollPane();
367  accountsTable = new javax.swing.JTable();
368  addAccountBtn = new javax.swing.JButton();
369  editAccountBtn = new javax.swing.JButton();
370  deleteAccountBtn = new javax.swing.JButton();
371  metadataLabel = new javax.swing.JLabel();
372  metadataTablePane = new javax.swing.JScrollPane();
373  metadataTable = new javax.swing.JTable();
374  addMetadataBtn = new javax.swing.JButton();
375  editMetadataBtn = new javax.swing.JButton();
376  deleteMetadataBtn = new javax.swing.JButton();
377  aliasesLabel = new javax.swing.JLabel();
378  aliasesTablePane = new javax.swing.JScrollPane();
379  aliasesTable = new javax.swing.JTable();
380  addAliasBtn = new javax.swing.JButton();
381  editAliasBtn = new javax.swing.JButton();
382  deleteAliasBtn = new javax.swing.JButton();
383  casesLbl = new javax.swing.JLabel();
384  casesTablePane = new javax.swing.JScrollPane();
385  casesTable = new javax.swing.JTable();
386 
387  org.openide.awt.Mnemonics.setLocalizedText(examinerLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.examinerLbl.text")); // NOI18N
388 
389  examinerField.setEditable(false);
390  examinerField.setText(org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.examinerField.text")); // NOI18N
391 
392  org.openide.awt.Mnemonics.setLocalizedText(creationDateLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.creationDateLbl.text")); // NOI18N
393 
394  creationDateField.setEditable(false);
395  creationDateField.setText(org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.creationDateField.text")); // NOI18N
396 
397  org.openide.awt.Mnemonics.setLocalizedText(commentLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.commentLbl.text")); // NOI18N
398 
399  commentField.setEditable(false);
400  commentField.setText(org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.commentField.text")); // NOI18N
401 
402  nameLbl.setFont(nameLbl.getFont().deriveFont(nameLbl.getFont().getStyle() | java.awt.Font.BOLD));
403  org.openide.awt.Mnemonics.setLocalizedText(nameLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.nameLbl.text")); // NOI18N
404 
405  nameField.setEditable(false);
406  nameField.setText(org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.nameField.text")); // NOI18N
407 
408  accountsLbl.setFont(accountsLbl.getFont().deriveFont(accountsLbl.getFont().getStyle() | java.awt.Font.BOLD));
409  org.openide.awt.Mnemonics.setLocalizedText(accountsLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.accountsLbl.text")); // NOI18N
410 
411  accountsTable.setModel(new javax.swing.table.DefaultTableModel(
412  new Object [][] {
413  {},
414  {},
415  {},
416  {}
417  },
418  new String [] {
419 
420  }
421  ));
422  accountsTablePane.setViewportView(accountsTable);
423 
424  org.openide.awt.Mnemonics.setLocalizedText(addAccountBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.addAccountBtn.text")); // NOI18N
425  addAccountBtn.setEnabled(false);
426 
427  org.openide.awt.Mnemonics.setLocalizedText(editAccountBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.editAccountBtn.text")); // NOI18N
428  editAccountBtn.setEnabled(false);
429 
430  org.openide.awt.Mnemonics.setLocalizedText(deleteAccountBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.deleteAccountBtn.text")); // NOI18N
431  deleteAccountBtn.setEnabled(false);
432 
433  metadataLabel.setFont(metadataLabel.getFont().deriveFont(metadataLabel.getFont().getStyle() | java.awt.Font.BOLD));
434  org.openide.awt.Mnemonics.setLocalizedText(metadataLabel, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.metadataLabel.text")); // NOI18N
435 
436  metadataTable.setModel(new javax.swing.table.DefaultTableModel(
437  new Object [][] {
438  {},
439  {},
440  {},
441  {}
442  },
443  new String [] {
444 
445  }
446  ));
447  metadataTablePane.setViewportView(metadataTable);
448 
449  org.openide.awt.Mnemonics.setLocalizedText(addMetadataBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.addMetadataBtn.text")); // NOI18N
450  addMetadataBtn.setEnabled(false);
451 
452  org.openide.awt.Mnemonics.setLocalizedText(editMetadataBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.editMetadataBtn.text")); // NOI18N
453  editMetadataBtn.setEnabled(false);
454 
455  org.openide.awt.Mnemonics.setLocalizedText(deleteMetadataBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.deleteMetadataBtn.text")); // NOI18N
456  deleteMetadataBtn.setEnabled(false);
457 
458  aliasesLabel.setFont(aliasesLabel.getFont().deriveFont(aliasesLabel.getFont().getStyle() | java.awt.Font.BOLD));
459  org.openide.awt.Mnemonics.setLocalizedText(aliasesLabel, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.aliasesLabel.text")); // NOI18N
460 
461  aliasesTable.setModel(new javax.swing.table.DefaultTableModel(
462  new Object [][] {
463  {},
464  {},
465  {},
466  {}
467  },
468  new String [] {
469 
470  }
471  ));
472  aliasesTablePane.setViewportView(aliasesTable);
473 
474  org.openide.awt.Mnemonics.setLocalizedText(addAliasBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.addAliasBtn.text")); // NOI18N
475  addAliasBtn.setEnabled(false);
476 
477  org.openide.awt.Mnemonics.setLocalizedText(editAliasBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.editAliasBtn.text")); // NOI18N
478  editAliasBtn.setEnabled(false);
479 
480  org.openide.awt.Mnemonics.setLocalizedText(deleteAliasBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.deleteAliasBtn.text")); // NOI18N
481  deleteAliasBtn.setEnabled(false);
482 
483  casesLbl.setFont(casesLbl.getFont().deriveFont(casesLbl.getFont().getStyle() | java.awt.Font.BOLD));
484  org.openide.awt.Mnemonics.setLocalizedText(casesLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.casesLbl.text")); // NOI18N
485 
486  casesTable.setModel(new javax.swing.table.DefaultTableModel(
487  new Object [][] {
488  {},
489  {},
490  {},
491  {}
492  },
493  new String [] {
494 
495  }
496  ));
497  casesTablePane.setViewportView(casesTable);
498 
499  javax.swing.GroupLayout detailsPanelLayout = new javax.swing.GroupLayout(detailsPanel);
500  detailsPanel.setLayout(detailsPanelLayout);
501  detailsPanelLayout.setHorizontalGroup(
502  detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
503  .addGroup(detailsPanelLayout.createSequentialGroup()
504  .addContainerGap()
505  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
506  .addComponent(accountsLbl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
507  .addComponent(metadataLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
508  .addComponent(aliasesLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
509  .addComponent(casesLbl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
510  .addGroup(detailsPanelLayout.createSequentialGroup()
511  .addComponent(nameLbl)
512  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
513  .addComponent(nameField))
514  .addGroup(detailsPanelLayout.createSequentialGroup()
515  .addComponent(examinerLbl)
516  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
517  .addComponent(examinerField, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
518  .addGap(18, 18, 18)
519  .addComponent(creationDateLbl)
520  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
521  .addComponent(creationDateField))
522  .addGroup(detailsPanelLayout.createSequentialGroup()
523  .addComponent(commentLbl)
524  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
525  .addComponent(commentField))
526  .addGroup(detailsPanelLayout.createSequentialGroup()
527  .addGap(10, 10, 10)
528  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
529  .addComponent(aliasesTablePane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 595, Short.MAX_VALUE)
530  .addComponent(metadataTablePane, javax.swing.GroupLayout.Alignment.TRAILING)
531  .addComponent(accountsTablePane, javax.swing.GroupLayout.Alignment.TRAILING)
532  .addGroup(detailsPanelLayout.createSequentialGroup()
533  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
534  .addGroup(detailsPanelLayout.createSequentialGroup()
535  .addComponent(addAliasBtn)
536  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
537  .addComponent(editAliasBtn)
538  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
539  .addComponent(deleteAliasBtn))
540  .addGroup(detailsPanelLayout.createSequentialGroup()
541  .addComponent(addMetadataBtn)
542  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
543  .addComponent(editMetadataBtn)
544  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
545  .addComponent(deleteMetadataBtn))
546  .addGroup(detailsPanelLayout.createSequentialGroup()
547  .addComponent(addAccountBtn)
548  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
549  .addComponent(editAccountBtn)
550  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
551  .addComponent(deleteAccountBtn)))
552  .addGap(0, 0, Short.MAX_VALUE))
553  .addComponent(casesTablePane))))
554  .addContainerGap())
555  );
556  detailsPanelLayout.setVerticalGroup(
557  detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
558  .addGroup(detailsPanelLayout.createSequentialGroup()
559  .addContainerGap()
560  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
561  .addComponent(nameLbl)
562  .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
563  .addGap(18, 18, 18)
564  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
565  .addComponent(examinerLbl)
566  .addComponent(examinerField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
567  .addComponent(creationDateLbl)
568  .addComponent(creationDateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
569  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
570  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
571  .addComponent(commentField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
572  .addComponent(commentLbl))
573  .addGap(18, 18, 18)
574  .addComponent(accountsLbl)
575  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
576  .addComponent(accountsTablePane, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
577  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
578  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
579  .addComponent(addAccountBtn)
580  .addComponent(deleteAccountBtn)
581  .addComponent(editAccountBtn))
582  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
583  .addComponent(metadataLabel)
584  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
585  .addComponent(metadataTablePane, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
586  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
587  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
588  .addComponent(addMetadataBtn)
589  .addComponent(deleteMetadataBtn)
590  .addComponent(editMetadataBtn))
591  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
592  .addComponent(aliasesLabel)
593  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
594  .addComponent(aliasesTablePane, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
595  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
596  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
597  .addComponent(addAliasBtn)
598  .addComponent(deleteAliasBtn)
599  .addComponent(editAliasBtn))
600  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
601  .addComponent(casesLbl)
602  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
603  .addComponent(casesTablePane, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
604  .addContainerGap())
605  );
606 
607  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
608  this.setLayout(layout);
609  layout.setHorizontalGroup(
610  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
611  .addComponent(detailsPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
612  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
613  .addGap(0, 617, Short.MAX_VALUE))
614  );
615  layout.setVerticalGroup(
616  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
617  .addGap(0, 583, Short.MAX_VALUE)
618  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
619  .addGroup(layout.createSequentialGroup()
620  .addComponent(detailsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
621  .addGap(0, 0, Short.MAX_VALUE)))
622  );
623  }// </editor-fold>//GEN-END:initComponents
624 
625  // Variables declaration - do not modify//GEN-BEGIN:variables
626  private javax.swing.JLabel accountsLbl;
627  private javax.swing.JTable accountsTable;
628  private javax.swing.JScrollPane accountsTablePane;
629  private javax.swing.JButton addAccountBtn;
630  private javax.swing.JButton addAliasBtn;
631  private javax.swing.JButton addMetadataBtn;
632  private javax.swing.JLabel aliasesLabel;
633  private javax.swing.JTable aliasesTable;
634  private javax.swing.JScrollPane aliasesTablePane;
635  private javax.swing.JLabel casesLbl;
636  private javax.swing.JTable casesTable;
637  private javax.swing.JScrollPane casesTablePane;
638  private javax.swing.JTextField commentField;
639  private javax.swing.JLabel commentLbl;
640  private javax.swing.JTextField creationDateField;
641  private javax.swing.JLabel creationDateLbl;
642  private javax.swing.JButton deleteAccountBtn;
643  private javax.swing.JButton deleteAliasBtn;
644  private javax.swing.JButton deleteMetadataBtn;
645  private javax.swing.JPanel detailsPanel;
646  private javax.swing.JButton editAccountBtn;
647  private javax.swing.JButton editAliasBtn;
648  private javax.swing.JButton editMetadataBtn;
649  private javax.swing.JTextField examinerField;
650  private javax.swing.JLabel examinerLbl;
651  private javax.swing.JLabel metadataLabel;
652  private javax.swing.JTable metadataTable;
653  private javax.swing.JScrollPane metadataTablePane;
654  private javax.swing.JTextField nameField;
655  private javax.swing.JLabel nameLbl;
656  // End of variables declaration//GEN-END:variables
657 
658  @Messages({
659  "PersonaDetailsPanel_load_exception_Title=Initialization failure",
660  "PersonaDetailsPanel_load_exception_msg=Failed to load persona.",})
661  private void loadPersona(Component parent, Persona persona) {
662  String examiner;
663  String creationDate;
664  String comment;
665  String name;
666  Collection<PersonaAccount> accounts;
667  Collection<PersonaMetadata> metadata;
668  Collection<PersonaAlias> aliases;
669  Collection<CorrelationCase> cases;
670  try {
671  examiner = persona.getExaminer().getLoginName();
672 
673  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
674  Date cDate = new Date(persona.getCreatedDate());
675  creationDate = dateFormat.format(cDate);
676 
677  comment = persona.getComment();
678  name = persona.getName();
679  accounts = persona.getPersonaAccounts();
680  metadata = persona.getMetadata();
681  aliases = persona.getAliases();
682  cases = persona.getCases();
683  } catch (CentralRepoException ex) {
684  logger.log(Level.SEVERE, "Failed to load persona", ex);
685  JOptionPane.showMessageDialog(parent,
686  Bundle.PersonaDetailsPanel_load_exception_Title(),
687  Bundle.PersonaDetailsPanel_load_exception_msg(),
688  JOptionPane.ERROR_MESSAGE);
689  return;
690  }
691  this.currentPersona = persona;
692  this.examinerField.setText(examiner);
693  this.creationDateField.setText(creationDate);
694  this.commentField.setText(comment);
695  this.nameField.setText(name);
696  this.currentAccounts.addAll(accounts);
697  this.currentMetadata.addAll(metadata);
698  this.currentAliases.addAll(aliases);
699  this.currentCases.addAll(cases);
700  }
701 
702  void clear() {
703  currentPersona = null;
704  examinerField.setText("");
705  creationDateField.setText("");
706  commentField.setText("");
707  nameField.setText(mode == PersonaDetailsMode.CREATE ? Persona.getDefaultName() : "");
708  currentAccounts = new ArrayList<>();
709  currentMetadata = new ArrayList<>();
710  currentAliases = new ArrayList<>();
711  currentCases = new ArrayList<>();
712  accountsToAdd.clear();
713  metadataToAdd.clear();
714  aliasesToAdd.clear();
715  nameField.setEditable(false);
716  commentField.setEditable(false);
717 
718  initializeFields();
719 
720  addAccountBtn.setEnabled(false);
721  addMetadataBtn.setEnabled(false);
722  addAliasBtn.setEnabled(false);
723  deleteAccountBtn.setEnabled(false);
724  deleteMetadataBtn.setEnabled(false);
725  deleteAliasBtn.setEnabled(false);
726  editAccountBtn.setEnabled(false);
727  editMetadataBtn.setEnabled(false);
728  editAliasBtn.setEnabled(false);
729  }
730 
734  final class PersonaDetailsTableModel extends DefaultTableModel {
735 
736  private static final long serialVersionUID = 1L;
737 
738  PersonaDetailsTableModel(Object[][] rows, String[] colNames) {
739  super(rows, colNames);
740  }
741 
742  @Override
743  public boolean isCellEditable(int row, int column) {
744  return false;
745  }
746  }
747 
748  private void updateAccountsTable() {
749  Object[][] rows = new Object[currentAccounts.size() + accountsToAdd.size()][2];
750  int i = 0;
751  for (PersonaAccount acc : currentAccounts) {
752  rows[i] = new Object[]{
753  acc.getAccount().getAccountType().getAcctType().getDisplayName(),
754  acc.getAccount().getIdentifier()
755  };
756  i++;
757  }
758  for (PAccount acc : accountsToAdd) {
759  rows[i] = new Object[]{
760  acc.account.getAccountType().getAcctType().getDisplayName(),
761  acc.account.getIdentifier()
762  };
763  i++;
764  }
765  accountsModel = new PersonaDetailsTableModel(
766  rows,
767  new String[]{"Type", "Identifier"}
768  );
769  accountsTable.setModel(accountsModel);
770 
771  // Formatting
772  accountsTable.getColumnModel().getColumn(0).setMaxWidth(100);
773  accountsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
774  }
775 
776  private void updateMetadataTable() {
777  Object[][] rows = new Object[currentMetadata.size() + metadataToAdd.size()][2];
778  int i = 0;
779  for (PersonaMetadata md : currentMetadata) {
780  rows[i] = new Object[]{md.getName(), md.getValue()};
781  i++;
782  }
783  for (PMetadata md : metadataToAdd) {
784  rows[i] = new Object[]{md.name, md.value};
785  i++;
786  }
787  metadataModel = new PersonaDetailsTableModel(
788  rows,
789  new String[]{"Name", "Value"}
790  );
791  metadataTable.setModel(metadataModel);
792  }
793 
794  private void updateAliasesTable() {
795  Object[][] rows = new Object[currentAliases.size() + aliasesToAdd.size()][1];
796  int i = 0;
797  for (PersonaAlias alias : currentAliases) {
798  rows[i] = new Object[]{alias.getAlias()};
799  i++;
800  }
801  for (PAlias alias : aliasesToAdd) {
802  rows[i] = new Object[]{alias.alias};
803  i++;
804  }
805  aliasesModel = new PersonaDetailsTableModel(
806  rows,
807  new String[]{"Alias"}
808  );
809  aliasesTable.setModel(aliasesModel);
810  }
811 
812  private void updateCasesTable() {
813  Object[][] rows = new Object[currentCases.size()][1];
814  int i = 0;
815  for (CorrelationCase c : currentCases) {
816  rows[i] = new Object[]{c.getDisplayName()};
817  i++;
818  }
819  casesModel = new PersonaDetailsTableModel(
820  rows,
821  new String[]{"Case"}
822  );
823  casesTable.setModel(casesModel);
824  }
825 
826  void configureEditComponents(boolean enabled) {
827  commentField.setEditable(enabled);
828  nameField.setEditable(enabled);
829  addAccountBtn.setEnabled(enabled);
830  addMetadataBtn.setEnabled(enabled);
831  addAliasBtn.setEnabled(enabled);
832 
833  addAccountBtn.setVisible(enabled);
834  editAccountBtn.setVisible(enabled);
835  deleteAccountBtn.setVisible(enabled);
836  addMetadataBtn.setVisible(enabled);
837  editMetadataBtn.setVisible(enabled);
838  deleteMetadataBtn.setVisible(enabled);
839  addAliasBtn.setVisible(enabled);
840  editAliasBtn.setVisible(enabled);
841  deleteAliasBtn.setVisible(enabled);
842  }
843 
844  void initializeFields() {
845  if (mode == PersonaDetailsMode.CREATE) {
846  try {
847  CentralRepoExaminer examiner = CentralRepository.getInstance().getOrInsertExaminer(System.getProperty("user.name"));
848  examinerField.setText(examiner.getLoginName());
849  } catch (CentralRepoException e) {
850  logger.log(Level.SEVERE, "Failed to access central repository", e);
851  JOptionPane.showMessageDialog(this,
852  Bundle.PersonaDetailsPanel_CentralRepoErr_msg(),
853  Bundle.PersonaDetailsPanel_CentralRepoErr_Title(),
854  JOptionPane.ERROR_MESSAGE);
855  }
856  }
857  updateAccountsTable();
858  updateMetadataTable();
859  updateAliasesTable();
860  updateCasesTable();
861  }
862 
863  void setMode(Component parent, PersonaDetailsMode mode, Persona persona) {
864  clear();
865  this.mode = mode;
866  switch (mode) {
867  case CREATE:
868  configureEditComponents(true);
869  break;
870  case EDIT:
871  loadPersona(parent, persona);
872  configureEditComponents(true);
873  break;
874  case VIEW:
875  loadPersona(parent, persona);
876  configureEditComponents(false);
877  break;
878  default:
879  logger.log(Level.WARNING, "Unsupported mode: {0}", mode);
880  break;
881  }
882  initializeFields();
883  }
884 
885  @Messages({
886  "PersonaDetailsPanel_NotEnoughAccounts_msg=A persona needs at least one account.",
887  "PersonaDetailsPanel_NotEnoughAccounts_Title=Missing account",
888  "PersonaDetailsPanel_CentralRepoErr_msg=Failure to write to Central Repository.",
889  "PersonaDetailsPanel_CentralRepoErr_Title=Central Repository failure",
890  "PersonaDetailsPanel_EmptyName_msg=Persona name cannot be empty.",
891  "PersonaDetailsPanel_EmptyName_Title=Empty persona name",
892  "PersonaDetailsPanel_EmptyComment_msg=Persona comment cannot be empty.",
893  "PersonaDetailsPanel_EmptyComment_Title=Empty persona comment",})
894  Persona okHandler() {
895  if (accountsToAdd.size() + currentAccounts.size() < 1) {
896  JOptionPane.showMessageDialog(this,
897  Bundle.PersonaDetailsPanel_NotEnoughAccounts_msg(),
898  Bundle.PersonaDetailsPanel_NotEnoughAccounts_Title(),
899  JOptionPane.ERROR_MESSAGE);
900  return null;
901 
902  }
903  if (StringUtils.isBlank(commentField.getText())) {
904  JOptionPane.showMessageDialog(this,
905  Bundle.PersonaDetailsPanel_EmptyComment_msg(),
906  Bundle.PersonaDetailsPanel_EmptyComment_Title(),
907  JOptionPane.ERROR_MESSAGE);
908  return null;
909  }
910  if (StringUtils.isBlank(nameField.getText())) {
911  JOptionPane.showMessageDialog(this,
912  Bundle.PersonaDetailsPanel_EmptyName_msg(),
913  Bundle.PersonaDetailsPanel_EmptyName_Title(),
914  JOptionPane.ERROR_MESSAGE);
915  return null;
916  }
917 
918  Persona ret = null;
919  switch (mode) {
920  case CREATE:
921  try {
922  PAccount firstAccount = accountsToAdd.get(0);
923  ret = Persona.createPersonaForAccount(nameField.getText(),
924  commentField.getText(), Persona.PersonaStatus.ACTIVE, firstAccount.account,
925  firstAccount.justification, firstAccount.confidence);
926  for (int i = 1; i < accountsToAdd.size(); i++) {
927  ret.addAccount(accountsToAdd.get(i).account,
928  accountsToAdd.get(i).justification,
929  accountsToAdd.get(i).confidence);
930  }
931  for (PMetadata md : metadataToAdd) {
932  ret.addMetadata(md.name, md.value, md.justification, md.confidence);
933  }
934  for (PAlias pa : aliasesToAdd) {
935  ret.addAlias(pa.alias, pa.justification, pa.confidence);
936  }
937  } catch (CentralRepoException e) {
938  logger.log(Level.SEVERE, "Failed to access central repository", e);
939  JOptionPane.showMessageDialog(this,
940  Bundle.PersonaDetailsPanel_CentralRepoErr_msg(),
941  Bundle.PersonaDetailsPanel_CentralRepoErr_Title(),
942  JOptionPane.ERROR_MESSAGE);
943  break;
944  }
945  break;
946  case EDIT:
947  try {
948  ret = currentPersona;
949  currentPersona.setComment(commentField.getText());
950  currentPersona.setName(nameField.getText());
951  for (PAccount acc : accountsToAdd) {
952  ret.addAccount(acc.account, acc.justification, acc.confidence);
953  }
954  for (PersonaAccount acc : accountsToRemove) {
955  ret.removeAccount(acc);
956  }
957  for (HashMap.Entry<PersonaAccount, PAccount> entry : accountsToEdit.entrySet()) {
958  ret.modifyAccount(entry.getKey(), entry.getValue().confidence, entry.getValue().justification);
959  }
960  for (PMetadata md : metadataToAdd) {
961  ret.addMetadata(md.name, md.value, md.justification, md.confidence);
962  }
963  for (PersonaMetadata md : metadataToRemove) {
964  ret.removeMetadata(md);
965  }
966  for (HashMap.Entry<PersonaMetadata, PMetadata> entry : metadataToEdit.entrySet()) {
967  ret.modifyMetadata(entry.getKey(), entry.getValue().confidence, entry.getValue().justification);
968  }
969  for (PAlias pa : aliasesToAdd) {
970  ret.addAlias(pa.alias, pa.justification, pa.confidence);
971  }
972  for (PersonaAlias pa : aliasesToRemove) {
973  ret.removeAlias(pa);
974  }
975  for (HashMap.Entry<PersonaAlias, PAlias> entry : aliasesToEdit.entrySet()) {
976  ret.modifyAlias(entry.getKey(), entry.getValue().confidence, entry.getValue().justification);
977  }
978  } catch (CentralRepoException e) {
979  logger.log(Level.SEVERE, "Failed to access central repository", e);
980  JOptionPane.showMessageDialog(this,
981  Bundle.PersonaDetailsPanel_CentralRepoErr_msg(),
982  Bundle.PersonaDetailsPanel_CentralRepoErr_Title(),
983  JOptionPane.ERROR_MESSAGE);
984  break;
985  }
986  break;
987  case VIEW:
988  ret = currentPersona;
989  break;
990  default:
991  logger.log(Level.SEVERE, "Unsupported mode: {0}", mode);
992  }
993  return ret;
994  }
995 
1001  public void setPersonaName(String name) {
1002  nameField.setText(name);
1003  }
1004 
1005 }
boolean addAccount(CentralRepoAccount account, String justification, Persona.Confidence confidence)
CentralRepoExaminer getOrInsertExaminer(String examinerLoginName)
void handleSelectionChange(ListSelectionEvent e, JButton editBtn, JButton deleteBtn, JTable table)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.