Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PersonaAccountDialog.java
Go to the documentation of this file.
1 /*
2  * Central Repository
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.io.Serializable;
23 import java.util.Collection;
24 import java.util.logging.Level;
25 import javax.swing.JDialog;
26 import javax.swing.JLabel;
27 import javax.swing.JList;
28 import javax.swing.JOptionPane;
29 import javax.swing.ListCellRenderer;
30 import javax.swing.SwingUtilities;
31 import org.openide.util.NbBundle.Messages;
32 import org.openide.windows.WindowManager;
39 
43 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
44 public class PersonaAccountDialog extends JDialog {
45 
46  private static final Logger logger = Logger.getLogger(PersonaAccountDialog.class.getName());
47 
48  private static final long serialVersionUID = 1L;
49 
50  private final TypeChoiceRenderer TYPE_CHOICE_RENDERER = new TypeChoiceRenderer();
51  private final PersonaDetailsPanel pdp;
52 
53  private PersonaDetailsPanel.PAccount currentAccount = null;
54 
58  @Messages({"PersonaAccountDialog.title.text=Add Account",})
60  super(SwingUtilities.windowForComponent(pdp),
61  Bundle.PersonaAccountDialog_title_text(),
62  ModalityType.APPLICATION_MODAL);
63  this.pdp = pdp;
64 
65  initComponents();
66  typeComboBox.setRenderer(TYPE_CHOICE_RENDERER);
67  display();
68  }
69 
71  super(SwingUtilities.windowForComponent(pdp),
72  Bundle.PersonaAccountDialog_title_text(),
73  ModalityType.APPLICATION_MODAL);
74  this.pdp = pdp;
75 
76  initComponents();
77  currentAccount = acc;
78  confidenceComboBox.setSelectedItem(acc.confidence);
79  justificationTextField.setText(acc.justification);
80  typeComboBox.setSelectedItem(acc.account.getAccountType());
81  identifierTextField.setText(acc.account.getIdentifier());
82 
83  typeComboBox.setEnabled(false);
84  identifierTextField.setEnabled(false);
85 
86  typeComboBox.setRenderer(TYPE_CHOICE_RENDERER);
87  display();
88  }
89 
94  private class TypeChoiceRenderer extends JLabel implements ListCellRenderer<CentralRepoAccountType>, Serializable {
95 
96  private static final long serialVersionUID = 1L;
97 
98  @Override
99  public Component getListCellRendererComponent(
100  JList<? extends CentralRepoAccountType> list, CentralRepoAccountType value,
101  int index, boolean isSelected, boolean cellHasFocus) {
102  setText(value.getAcctType().getDisplayName());
103  return this;
104  }
105  }
106 
107  @Messages({
108  "PersonaAccountDialog_get_types_exception_Title=Central Repository failure",
109  "PersonaAccountDialog_get_types_exception_msg=Failed to access central repository.",})
111  Collection<CentralRepoAccountType> allAccountTypes;
112  try {
113  allAccountTypes = CentralRepository.getInstance().getAllAccountTypes();
114  } catch (CentralRepoException e) {
115  logger.log(Level.SEVERE, "Failed to access central repository", e);
116  JOptionPane.showMessageDialog(this,
117  Bundle.PersonaAccountDialog_get_types_exception_Title(),
118  Bundle.PersonaAccountDialog_get_types_exception_msg(),
119  JOptionPane.ERROR_MESSAGE);
120  return new CentralRepoAccountType[0];
121  }
122  return allAccountTypes.toArray(new CentralRepoAccountType[0]);
123  }
124 
130  @SuppressWarnings("unchecked")
131  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
132  private void initComponents() {
133 
134  settingsPanel = new javax.swing.JPanel();
135  identiferLbl = new javax.swing.JLabel();
136  identifierTextField = new javax.swing.JTextField();
137  typeLbl = new javax.swing.JLabel();
138  typeComboBox = new javax.swing.JComboBox<>();
139  confidenceLbl = new javax.swing.JLabel();
140  confidenceComboBox = new javax.swing.JComboBox<>();
141  justificationLbl = new javax.swing.JLabel();
142  justificationTextField = new javax.swing.JTextField();
143  cancelBtn = new javax.swing.JButton();
144  okBtn = new javax.swing.JButton();
145 
146  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
147  setResizable(false);
148 
149  settingsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
150 
151  org.openide.awt.Mnemonics.setLocalizedText(identiferLbl, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.identiferLbl.text")); // NOI18N
152 
153  identifierTextField.setText(org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.identifierTextField.text")); // NOI18N
154  identifierTextField.addActionListener(new java.awt.event.ActionListener() {
155  public void actionPerformed(java.awt.event.ActionEvent evt) {
156  identifierTextFieldActionPerformed(evt);
157  }
158  });
159 
160  org.openide.awt.Mnemonics.setLocalizedText(typeLbl, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.typeLbl.text")); // NOI18N
161 
162  typeComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(getAllAccountTypes()));
163 
164  org.openide.awt.Mnemonics.setLocalizedText(confidenceLbl, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.confidenceLbl.text")); // NOI18N
165 
166  confidenceComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(org.sleuthkit.autopsy.centralrepository.datamodel.Persona.Confidence.values()));
167 
168  org.openide.awt.Mnemonics.setLocalizedText(justificationLbl, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.justificationLbl.text")); // NOI18N
169 
170  justificationTextField.setText(org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.justificationTextField.text")); // NOI18N
171 
172  javax.swing.GroupLayout settingsPanelLayout = new javax.swing.GroupLayout(settingsPanel);
173  settingsPanel.setLayout(settingsPanelLayout);
174  settingsPanelLayout.setHorizontalGroup(
175  settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
176  .addGroup(settingsPanelLayout.createSequentialGroup()
177  .addContainerGap()
178  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
179  .addGroup(settingsPanelLayout.createSequentialGroup()
180  .addComponent(typeLbl)
181  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
182  .addComponent(typeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
183  .addGroup(settingsPanelLayout.createSequentialGroup()
184  .addComponent(identiferLbl)
185  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
186  .addComponent(identifierTextField))
187  .addGroup(settingsPanelLayout.createSequentialGroup()
188  .addComponent(confidenceLbl)
189  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
190  .addComponent(confidenceComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
191  .addGroup(settingsPanelLayout.createSequentialGroup()
192  .addComponent(justificationLbl)
193  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
194  .addComponent(justificationTextField)))
195  .addContainerGap())
196  );
197  settingsPanelLayout.setVerticalGroup(
198  settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
199  .addGroup(settingsPanelLayout.createSequentialGroup()
200  .addContainerGap()
201  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
202  .addComponent(identiferLbl)
203  .addComponent(identifierTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
204  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
205  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
206  .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
207  .addComponent(typeLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE))
208  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
209  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
210  .addComponent(confidenceLbl)
211  .addComponent(confidenceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
212  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
213  .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
214  .addComponent(justificationLbl)
215  .addComponent(justificationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
216  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
217  );
218 
219  org.openide.awt.Mnemonics.setLocalizedText(cancelBtn, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.cancelBtn.text")); // NOI18N
220  cancelBtn.setMaximumSize(new java.awt.Dimension(79, 23));
221  cancelBtn.setMinimumSize(new java.awt.Dimension(79, 23));
222  cancelBtn.setPreferredSize(new java.awt.Dimension(79, 23));
223  cancelBtn.addActionListener(new java.awt.event.ActionListener() {
224  public void actionPerformed(java.awt.event.ActionEvent evt) {
225  cancelBtnActionPerformed(evt);
226  }
227  });
228 
229  org.openide.awt.Mnemonics.setLocalizedText(okBtn, org.openide.util.NbBundle.getMessage(PersonaAccountDialog.class, "PersonaAccountDialog.okBtn.text")); // NOI18N
230  okBtn.addActionListener(new java.awt.event.ActionListener() {
231  public void actionPerformed(java.awt.event.ActionEvent evt) {
232  okBtnActionPerformed(evt);
233  }
234  });
235 
236  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
237  getContentPane().setLayout(layout);
238  layout.setHorizontalGroup(
239  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
240  .addGroup(layout.createSequentialGroup()
241  .addContainerGap(194, Short.MAX_VALUE)
242  .addComponent(okBtn)
243  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
244  .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
245  .addContainerGap())
246  .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
247  );
248 
249  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelBtn, okBtn});
250 
251  layout.setVerticalGroup(
252  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
253  .addGroup(layout.createSequentialGroup()
254  .addContainerGap()
255  .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
256  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
257  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
258  .addComponent(okBtn, javax.swing.GroupLayout.Alignment.TRAILING)
259  .addComponent(cancelBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
260  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
261  );
262 
263  pack();
264  }// </editor-fold>//GEN-END:initComponents
265 
266  private void display() {
267  this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
268  setVisible(true);
269  }
270 
271  @Messages({
272  "PersonaAccountDialog_dup_Title=Account add failure",
273  "PersonaAccountDialog_dup_msg=This account is already added to the persona.",
274  "PersonaAccountDialog_identifier_empty_Title=Empty identifier",
275  "PersonaAccountDialog_identifier_empty_msg=The identifier field cannot be empty.",
276  "PersonaAccountDialog_search_failure_Title=Account add failure",
277  "PersonaAccountDialog_search_failure_msg=Central Repository account search failed.",
278  "PersonaAccountDialog_search_empty_Title=Account not found",
279  "PersonaAccountDialog_search_empty_msg=Account not found for given identifier and type.",})
280  private void okBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnActionPerformed
281  if (identifierTextField.getText().isEmpty()) {
282  JOptionPane.showMessageDialog(this,
283  Bundle.PersonaAccountDialog_identifier_empty_msg(),
284  Bundle.PersonaAccountDialog_identifier_empty_Title(),
285  JOptionPane.ERROR_MESSAGE);
286  return;
287  }
288  if (justificationTextField.getText().isEmpty()) {
289  JOptionPane.showMessageDialog(this,
290  Bundle.PersonaDetailsPanel_empty_justification_msg(),
291  Bundle.PersonaDetailsPanel_empty_justification_Title(),
292  JOptionPane.ERROR_MESSAGE);
293  return;
294  }
295  Collection<CentralRepoAccount> candidates;
296  try {
297  candidates = CentralRepoAccount.getAccountsWithIdentifier(identifierTextField.getText());
298  } catch (CentralRepoException e) {
299  logger.log(Level.SEVERE, "Failed to access central repository", e);
300  JOptionPane.showMessageDialog(this,
301  Bundle.PersonaAccountDialog_search_failure_msg(),
302  Bundle.PersonaAccountDialog_search_failure_Title(),
303  JOptionPane.ERROR_MESSAGE);
304  return;
305  }
306  if (candidates.isEmpty()) {
307  JOptionPane.showMessageDialog(this,
308  Bundle.PersonaAccountDialog_search_empty_msg(),
309  Bundle.PersonaAccountDialog_search_empty_Title(),
310  JOptionPane.ERROR_MESSAGE);
311  return;
312  }
313  CentralRepoAccount result = null;
314  for (CentralRepoAccount cand : candidates) {
315  if (cand.getAccountType().getAcctType().equals(
316  ((CentralRepoAccountType) typeComboBox.getSelectedItem()).getAcctType())) {
317  result = cand;
318  break;
319  }
320  }
321  if (result == null) {
322  JOptionPane.showMessageDialog(this,
323  Bundle.PersonaAccountDialog_search_empty_msg(),
324  Bundle.PersonaAccountDialog_search_empty_Title(),
325  JOptionPane.ERROR_MESSAGE);
326  return;
327  }
328 
329  Persona.Confidence confidence = (Persona.Confidence) confidenceComboBox.getSelectedItem();
330  String justification = justificationTextField.getText();
331 
332  if (currentAccount != null) {
333  currentAccount.confidence = confidence;
334  currentAccount.justification = justification;
335  dispose();
336  } else {
337  if (pdp.addAccount(result, justification, confidence)) {
338  dispose();
339  } else {
340  JOptionPane.showMessageDialog(this,
341  Bundle.PersonaAccountDialog_dup_msg(),
342  Bundle.PersonaAccountDialog_dup_Title(),
343  JOptionPane.ERROR_MESSAGE);
344  }
345  }
346  }//GEN-LAST:event_okBtnActionPerformed
347 
348  private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
349  dispose();
350  }//GEN-LAST:event_cancelBtnActionPerformed
351 
352  private void identifierTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_identifierTextFieldActionPerformed
353  // TODO add your handling code here:
354  }//GEN-LAST:event_identifierTextFieldActionPerformed
355 
356  // Variables declaration - do not modify//GEN-BEGIN:variables
357  private javax.swing.JButton cancelBtn;
359  private javax.swing.JLabel confidenceLbl;
360  private javax.swing.JLabel identiferLbl;
361  private javax.swing.JTextField identifierTextField;
362  private javax.swing.JLabel justificationLbl;
363  private javax.swing.JTextField justificationTextField;
364  private javax.swing.JButton okBtn;
365  private javax.swing.JPanel settingsPanel;
367  private javax.swing.JLabel typeLbl;
368  // End of variables declaration//GEN-END:variables
369 }
Component getListCellRendererComponent(JList<?extends CentralRepoAccountType > list, CentralRepoAccountType value, int index, boolean isSelected, boolean cellHasFocus)
javax.swing.JComboBox< org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoAccount.CentralRepoAccountType > typeComboBox
static Collection< CentralRepoAccount > getAccountsWithIdentifier(String accountIdentifier)
javax.swing.JComboBox< org.sleuthkit.autopsy.centralrepository.datamodel.Persona.Confidence > confidenceComboBox
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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