Autopsy  4.19.3
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 
229  PersonaDetailsMode getMode() {
230  return mode;
231  }
232 
236  class PAccount {
237 
238  CentralRepoAccount account;
239  String justification;
240  Persona.Confidence confidence;
241 
242  PAccount(CentralRepoAccount account, String justification, Persona.Confidence confidence) {
243  this.account = account;
244  this.justification = justification;
245  this.confidence = confidence;
246  }
247  }
248 
249  boolean accountExists(CentralRepoAccount account) {
250  for (PersonaAccount acc : currentAccounts) {
251  if (acc.getAccount().getId() == account.getId()) {
252  return true;
253  }
254  }
255  for (PAccount acc : accountsToAdd) {
256  if (acc.account.getId() == account.getId()) {
257  return true;
258  }
259  }
260  return false;
261  }
262 
263  public boolean addAccount(CentralRepoAccount account, String justification, Persona.Confidence confidence) {
264  if (!accountExists(account)) {
265  accountsToAdd.add(new PAccount(account, justification, confidence));
266  updateAccountsTable();
267  return true;
268  }
269  return false;
270  }
271 
275  class PMetadata {
276 
277  String name;
278  String value;
279  String justification;
280  Persona.Confidence confidence;
281 
282  PMetadata(String name, String value, String justification, Persona.Confidence confidence) {
283  this.name = name;
284  this.value = value;
285  this.justification = justification;
286  this.confidence = confidence;
287  }
288  }
289 
290  boolean metadataExists(String name) {
291  for (PersonaMetadata pm : currentMetadata) {
292  if (pm.getName().equals(name)) {
293  return true;
294  }
295  }
296  for (PMetadata pm : metadataToAdd) {
297  if (pm.name.equals(name)) {
298  return true;
299  }
300  }
301  return false;
302  }
303 
304  boolean addMetadata(String name, String value, String justification, Persona.Confidence confidence) {
305  if (!metadataExists(name)) {
306  metadataToAdd.add(new PMetadata(name, value, justification, confidence));
307  updateMetadataTable();
308  return true;
309  }
310  return false;
311  }
312 
316  class PAlias {
317 
318  String alias;
319  String justification;
320  Persona.Confidence confidence;
321 
322  PAlias(String alias, String justification, Persona.Confidence confidence) {
323  this.alias = alias;
324  this.justification = justification;
325  this.confidence = confidence;
326  }
327  }
328 
329  boolean aliasExists(String alias) {
330  for (PersonaAlias pa : currentAliases) {
331  if (pa.getAlias().equals(alias)) {
332  return true;
333  }
334  }
335  for (PAlias pa : aliasesToAdd) {
336  if (pa.alias.equals(alias)) {
337  return true;
338  }
339  }
340  return false;
341  }
342 
343  boolean addAlias(String alias, String justification, Persona.Confidence confidence) {
344  if (!aliasExists(alias)) {
345  aliasesToAdd.add(new PAlias(alias, justification, confidence));
346  updateAliasesTable();
347  return true;
348  }
349  return false;
350  }
351 
357  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
358  private void initComponents() {
359 
360  detailsPanel = new javax.swing.JPanel();
361  examinerLbl = new javax.swing.JLabel();
362  examinerField = new javax.swing.JTextField();
363  creationDateLbl = new javax.swing.JLabel();
364  creationDateField = new javax.swing.JTextField();
365  commentLbl = new javax.swing.JLabel();
366  commentField = new javax.swing.JTextField();
367  nameLbl = new javax.swing.JLabel();
368  nameField = new javax.swing.JTextField();
369  accountsLbl = new javax.swing.JLabel();
370  accountsTablePane = new javax.swing.JScrollPane();
371  accountsTable = new javax.swing.JTable();
372  addAccountBtn = new javax.swing.JButton();
373  editAccountBtn = new javax.swing.JButton();
374  deleteAccountBtn = new javax.swing.JButton();
375  metadataLabel = new javax.swing.JLabel();
376  metadataTablePane = new javax.swing.JScrollPane();
377  metadataTable = new javax.swing.JTable();
378  addMetadataBtn = new javax.swing.JButton();
379  editMetadataBtn = new javax.swing.JButton();
380  deleteMetadataBtn = new javax.swing.JButton();
381  aliasesLabel = new javax.swing.JLabel();
382  aliasesTablePane = new javax.swing.JScrollPane();
383  aliasesTable = new javax.swing.JTable();
384  addAliasBtn = new javax.swing.JButton();
385  editAliasBtn = new javax.swing.JButton();
386  deleteAliasBtn = new javax.swing.JButton();
387  casesLbl = new javax.swing.JLabel();
388  casesTablePane = new javax.swing.JScrollPane();
389  casesTable = new javax.swing.JTable();
390 
391  addComponentListener(new java.awt.event.ComponentAdapter() {
392  public void componentShown(java.awt.event.ComponentEvent evt) {
393  formComponentShown(evt);
394  }
395  });
396 
397  org.openide.awt.Mnemonics.setLocalizedText(examinerLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.examinerLbl.text")); // NOI18N
398 
399  examinerField.setEditable(false);
400  examinerField.setText(org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.examinerField.text")); // NOI18N
401 
402  org.openide.awt.Mnemonics.setLocalizedText(creationDateLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.creationDateLbl.text")); // NOI18N
403 
404  creationDateField.setEditable(false);
405  creationDateField.setText(org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.creationDateField.text")); // NOI18N
406 
407  org.openide.awt.Mnemonics.setLocalizedText(commentLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.commentLbl.text")); // NOI18N
408 
409  commentField.setEditable(false);
410  commentField.setText(org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.commentField.text")); // NOI18N
411 
412  nameLbl.setFont(nameLbl.getFont().deriveFont(nameLbl.getFont().getStyle() | java.awt.Font.BOLD));
413  org.openide.awt.Mnemonics.setLocalizedText(nameLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.nameLbl.text")); // NOI18N
414 
415  nameField.setEditable(false);
416  nameField.setText(org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.nameField.text")); // NOI18N
417 
418  accountsLbl.setFont(accountsLbl.getFont().deriveFont(accountsLbl.getFont().getStyle() | java.awt.Font.BOLD));
419  org.openide.awt.Mnemonics.setLocalizedText(accountsLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.accountsLbl.text")); // NOI18N
420 
421  accountsTable.setModel(new javax.swing.table.DefaultTableModel(
422  new Object [][] {
423  {},
424  {},
425  {},
426  {}
427  },
428  new String [] {
429 
430  }
431  ));
432  accountsTablePane.setViewportView(accountsTable);
433 
434  org.openide.awt.Mnemonics.setLocalizedText(addAccountBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.addAccountBtn.text")); // NOI18N
435  addAccountBtn.setEnabled(false);
436 
437  org.openide.awt.Mnemonics.setLocalizedText(editAccountBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.editAccountBtn.text")); // NOI18N
438  editAccountBtn.setEnabled(false);
439 
440  org.openide.awt.Mnemonics.setLocalizedText(deleteAccountBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.deleteAccountBtn.text")); // NOI18N
441  deleteAccountBtn.setEnabled(false);
442 
443  metadataLabel.setFont(metadataLabel.getFont().deriveFont(metadataLabel.getFont().getStyle() | java.awt.Font.BOLD));
444  org.openide.awt.Mnemonics.setLocalizedText(metadataLabel, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.metadataLabel.text")); // NOI18N
445 
446  metadataTable.setModel(new javax.swing.table.DefaultTableModel(
447  new Object [][] {
448  {},
449  {},
450  {},
451  {}
452  },
453  new String [] {
454 
455  }
456  ));
457  metadataTablePane.setViewportView(metadataTable);
458 
459  org.openide.awt.Mnemonics.setLocalizedText(addMetadataBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.addMetadataBtn.text")); // NOI18N
460  addMetadataBtn.setEnabled(false);
461 
462  org.openide.awt.Mnemonics.setLocalizedText(editMetadataBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.editMetadataBtn.text")); // NOI18N
463  editMetadataBtn.setEnabled(false);
464 
465  org.openide.awt.Mnemonics.setLocalizedText(deleteMetadataBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.deleteMetadataBtn.text")); // NOI18N
466  deleteMetadataBtn.setEnabled(false);
467 
468  aliasesLabel.setFont(aliasesLabel.getFont().deriveFont(aliasesLabel.getFont().getStyle() | java.awt.Font.BOLD));
469  org.openide.awt.Mnemonics.setLocalizedText(aliasesLabel, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.aliasesLabel.text")); // NOI18N
470 
471  aliasesTable.setModel(new javax.swing.table.DefaultTableModel(
472  new Object [][] {
473  {},
474  {},
475  {},
476  {}
477  },
478  new String [] {
479 
480  }
481  ));
482  aliasesTablePane.setViewportView(aliasesTable);
483 
484  org.openide.awt.Mnemonics.setLocalizedText(addAliasBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.addAliasBtn.text")); // NOI18N
485  addAliasBtn.setEnabled(false);
486 
487  org.openide.awt.Mnemonics.setLocalizedText(editAliasBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.editAliasBtn.text")); // NOI18N
488  editAliasBtn.setEnabled(false);
489 
490  org.openide.awt.Mnemonics.setLocalizedText(deleteAliasBtn, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.deleteAliasBtn.text")); // NOI18N
491  deleteAliasBtn.setEnabled(false);
492 
493  casesLbl.setFont(casesLbl.getFont().deriveFont(casesLbl.getFont().getStyle() | java.awt.Font.BOLD));
494  org.openide.awt.Mnemonics.setLocalizedText(casesLbl, org.openide.util.NbBundle.getMessage(PersonaDetailsPanel.class, "PersonaDetailsPanel.casesLbl.text")); // NOI18N
495 
496  casesTable.setModel(new javax.swing.table.DefaultTableModel(
497  new Object [][] {
498  {},
499  {},
500  {},
501  {}
502  },
503  new String [] {
504 
505  }
506  ));
507  casesTablePane.setViewportView(casesTable);
508 
509  javax.swing.GroupLayout detailsPanelLayout = new javax.swing.GroupLayout(detailsPanel);
510  detailsPanel.setLayout(detailsPanelLayout);
511  detailsPanelLayout.setHorizontalGroup(
512  detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
513  .addGroup(detailsPanelLayout.createSequentialGroup()
514  .addContainerGap()
515  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
516  .addComponent(accountsLbl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
517  .addComponent(metadataLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
518  .addComponent(aliasesLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
519  .addComponent(casesLbl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
520  .addGroup(detailsPanelLayout.createSequentialGroup()
521  .addComponent(nameLbl)
522  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
523  .addComponent(nameField))
524  .addGroup(detailsPanelLayout.createSequentialGroup()
525  .addComponent(examinerLbl)
526  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
527  .addComponent(examinerField, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
528  .addGap(18, 18, 18)
529  .addComponent(creationDateLbl)
530  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
531  .addComponent(creationDateField))
532  .addGroup(detailsPanelLayout.createSequentialGroup()
533  .addComponent(commentLbl)
534  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
535  .addComponent(commentField))
536  .addGroup(detailsPanelLayout.createSequentialGroup()
537  .addGap(10, 10, 10)
538  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
539  .addComponent(aliasesTablePane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 595, Short.MAX_VALUE)
540  .addComponent(metadataTablePane, javax.swing.GroupLayout.Alignment.TRAILING)
541  .addComponent(accountsTablePane, javax.swing.GroupLayout.Alignment.TRAILING)
542  .addGroup(detailsPanelLayout.createSequentialGroup()
543  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
544  .addGroup(detailsPanelLayout.createSequentialGroup()
545  .addComponent(addAliasBtn)
546  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
547  .addComponent(editAliasBtn)
548  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
549  .addComponent(deleteAliasBtn))
550  .addGroup(detailsPanelLayout.createSequentialGroup()
551  .addComponent(addMetadataBtn)
552  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
553  .addComponent(editMetadataBtn)
554  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
555  .addComponent(deleteMetadataBtn))
556  .addGroup(detailsPanelLayout.createSequentialGroup()
557  .addComponent(addAccountBtn)
558  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
559  .addComponent(editAccountBtn)
560  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
561  .addComponent(deleteAccountBtn)))
562  .addGap(0, 0, Short.MAX_VALUE))
563  .addComponent(casesTablePane))))
564  .addContainerGap())
565  );
566  detailsPanelLayout.setVerticalGroup(
567  detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
568  .addGroup(detailsPanelLayout.createSequentialGroup()
569  .addContainerGap()
570  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
571  .addComponent(nameLbl)
572  .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
573  .addGap(18, 18, 18)
574  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
575  .addComponent(examinerLbl)
576  .addComponent(examinerField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
577  .addComponent(creationDateLbl)
578  .addComponent(creationDateField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
579  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
580  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
581  .addComponent(commentField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
582  .addComponent(commentLbl))
583  .addGap(18, 18, 18)
584  .addComponent(accountsLbl)
585  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
586  .addComponent(accountsTablePane, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
587  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
588  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
589  .addComponent(addAccountBtn)
590  .addComponent(deleteAccountBtn)
591  .addComponent(editAccountBtn))
592  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
593  .addComponent(metadataLabel)
594  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
595  .addComponent(metadataTablePane, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
596  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
597  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
598  .addComponent(addMetadataBtn)
599  .addComponent(deleteMetadataBtn)
600  .addComponent(editMetadataBtn))
601  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
602  .addComponent(aliasesLabel)
603  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
604  .addComponent(aliasesTablePane, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
605  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
606  .addGroup(detailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
607  .addComponent(addAliasBtn)
608  .addComponent(deleteAliasBtn)
609  .addComponent(editAliasBtn))
610  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
611  .addComponent(casesLbl)
612  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
613  .addComponent(casesTablePane, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
614  .addContainerGap())
615  );
616 
617  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
618  this.setLayout(layout);
619  layout.setHorizontalGroup(
620  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
621  .addComponent(detailsPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
622  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
623  .addGap(0, 617, Short.MAX_VALUE))
624  );
625  layout.setVerticalGroup(
626  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
627  .addGap(0, 583, Short.MAX_VALUE)
628  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
629  .addGroup(layout.createSequentialGroup()
630  .addComponent(detailsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
631  .addGap(0, 0, Short.MAX_VALUE)))
632  );
633  }// </editor-fold>//GEN-END:initComponents
634 
635  private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
636 
637  }//GEN-LAST:event_formComponentShown
638 
639  // Variables declaration - do not modify//GEN-BEGIN:variables
640  private javax.swing.JLabel accountsLbl;
641  private javax.swing.JTable accountsTable;
642  private javax.swing.JScrollPane accountsTablePane;
643  private javax.swing.JButton addAccountBtn;
644  private javax.swing.JButton addAliasBtn;
645  private javax.swing.JButton addMetadataBtn;
646  private javax.swing.JLabel aliasesLabel;
647  private javax.swing.JTable aliasesTable;
648  private javax.swing.JScrollPane aliasesTablePane;
649  private javax.swing.JLabel casesLbl;
650  private javax.swing.JTable casesTable;
651  private javax.swing.JScrollPane casesTablePane;
652  private javax.swing.JTextField commentField;
653  private javax.swing.JLabel commentLbl;
654  private javax.swing.JTextField creationDateField;
655  private javax.swing.JLabel creationDateLbl;
656  private javax.swing.JButton deleteAccountBtn;
657  private javax.swing.JButton deleteAliasBtn;
658  private javax.swing.JButton deleteMetadataBtn;
659  private javax.swing.JPanel detailsPanel;
660  private javax.swing.JButton editAccountBtn;
661  private javax.swing.JButton editAliasBtn;
662  private javax.swing.JButton editMetadataBtn;
663  private javax.swing.JTextField examinerField;
664  private javax.swing.JLabel examinerLbl;
665  private javax.swing.JLabel metadataLabel;
666  private javax.swing.JTable metadataTable;
667  private javax.swing.JScrollPane metadataTablePane;
668  private javax.swing.JTextField nameField;
669  private javax.swing.JLabel nameLbl;
670  // End of variables declaration//GEN-END:variables
671 
672  @Messages({
673  "PersonaDetailsPanel_load_exception_Title=Initialization failure",
674  "PersonaDetailsPanel_load_exception_msg=Failed to load persona.",})
675  private void loadPersona(Component parent, Persona persona) {
676  String examiner;
677  String creationDate;
678  String comment;
679  String name;
680  Collection<PersonaAccount> accounts;
681  Collection<PersonaMetadata> metadata;
682  Collection<PersonaAlias> aliases;
683  Collection<CorrelationCase> cases;
684  try {
685  examiner = persona.getExaminer().getLoginName();
686 
687  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
688  Date cDate = new Date(persona.getCreatedDate());
689  creationDate = dateFormat.format(cDate);
690 
691  comment = persona.getComment();
692  name = persona.getName();
693  accounts = persona.getPersonaAccounts();
694  metadata = persona.getMetadata();
695  aliases = persona.getAliases();
696  cases = persona.getCases();
697  } catch (CentralRepoException ex) {
698  logger.log(Level.SEVERE, "Failed to load persona", ex);
699  JOptionPane.showMessageDialog(parent,
700  Bundle.PersonaDetailsPanel_load_exception_Title(),
701  Bundle.PersonaDetailsPanel_load_exception_msg(),
702  JOptionPane.ERROR_MESSAGE);
703  return;
704  }
705  this.currentPersona = persona;
706  this.examinerField.setText(examiner);
707  this.creationDateField.setText(creationDate);
708  this.commentField.setText(comment);
709  this.nameField.setText(name);
710  this.currentAccounts.addAll(accounts);
711  this.currentMetadata.addAll(metadata);
712  this.currentAliases.addAll(aliases);
713  this.currentCases.addAll(cases);
714  }
715 
716  void clear() {
717  currentPersona = null;
718  examinerField.setText("");
719  creationDateField.setText("");
720  commentField.setText("");
721  nameField.setText(mode == PersonaDetailsMode.CREATE ? Persona.getDefaultName() : "");
722  currentAccounts = new ArrayList<>();
723  currentMetadata = new ArrayList<>();
724  currentAliases = new ArrayList<>();
725  currentCases = new ArrayList<>();
726  accountsToAdd.clear();
727  metadataToAdd.clear();
728  aliasesToAdd.clear();
729  nameField.setEditable(false);
730  commentField.setEditable(false);
731 
732  initializeFields();
733 
734  addAccountBtn.setEnabled(false);
735  addMetadataBtn.setEnabled(false);
736  addAliasBtn.setEnabled(false);
737  deleteAccountBtn.setEnabled(false);
738  deleteMetadataBtn.setEnabled(false);
739  deleteAliasBtn.setEnabled(false);
740  editAccountBtn.setEnabled(false);
741  editMetadataBtn.setEnabled(false);
742  editAliasBtn.setEnabled(false);
743  }
744 
748  final class PersonaDetailsTableModel extends DefaultTableModel {
749 
750  private static final long serialVersionUID = 1L;
751 
752  PersonaDetailsTableModel(Object[][] rows, String[] colNames) {
753  super(rows, colNames);
754  }
755 
756  @Override
757  public boolean isCellEditable(int row, int column) {
758  return false;
759  }
760  }
761 
762  private void updateAccountsTable() {
763  Object[][] rows = new Object[currentAccounts.size() + accountsToAdd.size()][2];
764  int i = 0;
765  for (PersonaAccount acc : currentAccounts) {
766  rows[i] = new Object[]{
767  acc.getAccount().getAccountType().getAcctType().getDisplayName(),
768  acc.getAccount().getIdentifier()
769  };
770  i++;
771  }
772  for (PAccount acc : accountsToAdd) {
773  rows[i] = new Object[]{
774  acc.account.getAccountType().getAcctType().getDisplayName(),
775  acc.account.getIdentifier()
776  };
777  i++;
778  }
779  accountsModel = new PersonaDetailsTableModel(
780  rows,
781  new String[]{"Type", "Identifier"}
782  );
783  accountsTable.setModel(accountsModel);
784 
785  // Formatting
786  accountsTable.getColumnModel().getColumn(0).setMaxWidth(100);
787  accountsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
788  }
789 
790  private void updateMetadataTable() {
791  Object[][] rows = new Object[currentMetadata.size() + metadataToAdd.size()][2];
792  int i = 0;
793  for (PersonaMetadata md : currentMetadata) {
794  rows[i] = new Object[]{md.getName(), md.getValue()};
795  i++;
796  }
797  for (PMetadata md : metadataToAdd) {
798  rows[i] = new Object[]{md.name, md.value};
799  i++;
800  }
801  metadataModel = new PersonaDetailsTableModel(
802  rows,
803  new String[]{"Name", "Value"}
804  );
805  metadataTable.setModel(metadataModel);
806  }
807 
808  private void updateAliasesTable() {
809  Object[][] rows = new Object[currentAliases.size() + aliasesToAdd.size()][1];
810  int i = 0;
811  for (PersonaAlias alias : currentAliases) {
812  rows[i] = new Object[]{alias.getAlias()};
813  i++;
814  }
815  for (PAlias alias : aliasesToAdd) {
816  rows[i] = new Object[]{alias.alias};
817  i++;
818  }
819  aliasesModel = new PersonaDetailsTableModel(
820  rows,
821  new String[]{"Alias"}
822  );
823  aliasesTable.setModel(aliasesModel);
824  }
825 
826  private void updateCasesTable() {
827  Object[][] rows = new Object[currentCases.size()][1];
828  int i = 0;
829  for (CorrelationCase c : currentCases) {
830  rows[i] = new Object[]{c.getDisplayName()};
831  i++;
832  }
833  casesModel = new PersonaDetailsTableModel(
834  rows,
835  new String[]{"Case"}
836  );
837  casesTable.setModel(casesModel);
838  }
839 
840  void configureEditComponents(boolean enabled) {
841  commentField.setEditable(enabled);
842  nameField.setEditable(enabled);
843  addAccountBtn.setEnabled(enabled);
844  addMetadataBtn.setEnabled(enabled);
845  addAliasBtn.setEnabled(enabled);
846 
847  addAccountBtn.setVisible(enabled);
848  editAccountBtn.setVisible(enabled);
849  deleteAccountBtn.setVisible(enabled);
850  addMetadataBtn.setVisible(enabled);
851  editMetadataBtn.setVisible(enabled);
852  deleteMetadataBtn.setVisible(enabled);
853  addAliasBtn.setVisible(enabled);
854  editAliasBtn.setVisible(enabled);
855  deleteAliasBtn.setVisible(enabled);
856  }
857 
858  void initializeFields() {
859  if (mode == PersonaDetailsMode.CREATE) {
860  try {
861  CentralRepoExaminer examiner = CentralRepository.getInstance().getOrInsertExaminer(System.getProperty("user.name"));
862  examinerField.setText(examiner.getLoginName());
863  } catch (CentralRepoException e) {
864  logger.log(Level.SEVERE, "Failed to access central repository", e);
865  JOptionPane.showMessageDialog(this,
866  Bundle.PersonaDetailsPanel_CentralRepoErr_msg(),
867  Bundle.PersonaDetailsPanel_CentralRepoErr_Title(),
868  JOptionPane.ERROR_MESSAGE);
869  }
870  }
871  updateAccountsTable();
872  updateMetadataTable();
873  updateAliasesTable();
874  updateCasesTable();
875  }
876 
877  void setMode(Component parent, PersonaDetailsMode mode, Persona persona) {
878  clear();
879  this.mode = mode;
880  switch (mode) {
881  case CREATE:
882  configureEditComponents(true);
883  break;
884  case EDIT:
885  loadPersona(parent, persona);
886  configureEditComponents(true);
887  break;
888  case VIEW:
889  loadPersona(parent, persona);
890  configureEditComponents(false);
891  break;
892  default:
893  logger.log(Level.WARNING, "Unsupported mode: {0}", mode);
894  break;
895  }
896  initializeFields();
897  }
898 
899  @Messages({
900  "PersonaDetailsPanel_NotEnoughAccounts_msg=A persona needs at least one account.",
901  "PersonaDetailsPanel_NotEnoughAccounts_Title=Missing account",
902  "PersonaDetailsPanel_CentralRepoErr_msg=Failure to write to Central Repository.",
903  "PersonaDetailsPanel_CentralRepoErr_Title=Central Repository failure",
904  "PersonaDetailsPanel_EmptyName_msg=Persona name cannot be empty.",
905  "PersonaDetailsPanel_EmptyName_Title=Empty persona name",
906  "PersonaDetailsPanel_EmptyComment_msg=Persona comment cannot be empty.",
907  "PersonaDetailsPanel_EmptyComment_Title=Empty persona comment",})
908  Persona okHandler() {
909  if (accountsToAdd.size() + currentAccounts.size() < 1) {
910  JOptionPane.showMessageDialog(this,
911  Bundle.PersonaDetailsPanel_NotEnoughAccounts_msg(),
912  Bundle.PersonaDetailsPanel_NotEnoughAccounts_Title(),
913  JOptionPane.ERROR_MESSAGE);
914  return null;
915 
916  }
917  if (StringUtils.isBlank(commentField.getText())) {
918  JOptionPane.showMessageDialog(this,
919  Bundle.PersonaDetailsPanel_EmptyComment_msg(),
920  Bundle.PersonaDetailsPanel_EmptyComment_Title(),
921  JOptionPane.ERROR_MESSAGE);
922  return null;
923  }
924  if (StringUtils.isBlank(nameField.getText())) {
925  JOptionPane.showMessageDialog(this,
926  Bundle.PersonaDetailsPanel_EmptyName_msg(),
927  Bundle.PersonaDetailsPanel_EmptyName_Title(),
928  JOptionPane.ERROR_MESSAGE);
929  return null;
930  }
931 
932  Persona ret = null;
933  switch (mode) {
934  case CREATE:
935  try {
936  PAccount firstAccount = accountsToAdd.get(0);
937  ret = Persona.createPersonaForAccount(nameField.getText(),
938  commentField.getText(), Persona.PersonaStatus.ACTIVE, firstAccount.account,
939  firstAccount.justification, firstAccount.confidence);
940  for (int i = 1; i < accountsToAdd.size(); i++) {
941  ret.addAccount(accountsToAdd.get(i).account,
942  accountsToAdd.get(i).justification,
943  accountsToAdd.get(i).confidence);
944  }
945  for (PMetadata md : metadataToAdd) {
946  ret.addMetadata(md.name, md.value, md.justification, md.confidence);
947  }
948  for (PAlias pa : aliasesToAdd) {
949  ret.addAlias(pa.alias, pa.justification, pa.confidence);
950  }
951  } catch (CentralRepoException e) {
952  logger.log(Level.SEVERE, "Failed to access central repository", e);
953  JOptionPane.showMessageDialog(this,
954  Bundle.PersonaDetailsPanel_CentralRepoErr_msg(),
955  Bundle.PersonaDetailsPanel_CentralRepoErr_Title(),
956  JOptionPane.ERROR_MESSAGE);
957  break;
958  }
959  break;
960  case EDIT:
961  try {
962  ret = currentPersona;
963  currentPersona.setComment(commentField.getText());
964  currentPersona.setName(nameField.getText());
965  for (PAccount acc : accountsToAdd) {
966  ret.addAccount(acc.account, acc.justification, acc.confidence);
967  }
968  for (PersonaAccount acc : accountsToRemove) {
969  ret.removeAccount(acc);
970  }
971  for (HashMap.Entry<PersonaAccount, PAccount> entry : accountsToEdit.entrySet()) {
972  ret.modifyAccount(entry.getKey(), entry.getValue().confidence, entry.getValue().justification);
973  }
974  for (PMetadata md : metadataToAdd) {
975  ret.addMetadata(md.name, md.value, md.justification, md.confidence);
976  }
977  for (PersonaMetadata md : metadataToRemove) {
978  ret.removeMetadata(md);
979  }
980  for (HashMap.Entry<PersonaMetadata, PMetadata> entry : metadataToEdit.entrySet()) {
981  ret.modifyMetadata(entry.getKey(), entry.getValue().confidence, entry.getValue().justification);
982  }
983  for (PAlias pa : aliasesToAdd) {
984  ret.addAlias(pa.alias, pa.justification, pa.confidence);
985  }
986  for (PersonaAlias pa : aliasesToRemove) {
987  ret.removeAlias(pa);
988  }
989  for (HashMap.Entry<PersonaAlias, PAlias> entry : aliasesToEdit.entrySet()) {
990  ret.modifyAlias(entry.getKey(), entry.getValue().confidence, entry.getValue().justification);
991  }
992  } catch (CentralRepoException e) {
993  logger.log(Level.SEVERE, "Failed to access central repository", e);
994  JOptionPane.showMessageDialog(this,
995  Bundle.PersonaDetailsPanel_CentralRepoErr_msg(),
996  Bundle.PersonaDetailsPanel_CentralRepoErr_Title(),
997  JOptionPane.ERROR_MESSAGE);
998  break;
999  }
1000  break;
1001  case VIEW:
1002  ret = currentPersona;
1003  break;
1004  default:
1005  logger.log(Level.SEVERE, "Unsupported mode: {0}", mode);
1006  }
1007  return ret;
1008  }
1009 
1015  public void setPersonaName(String name) {
1016  nameField.setText(name);
1017  }
1018 
1019 }
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-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.