19 package org.sleuthkit.autopsy.centralrepository.persona;
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;
43 @SuppressWarnings(
"PMD.SingularField")
48 private static final long serialVersionUID = 1L;
58 @Messages({
"PersonaAccountDialog.title.text=Add Account",})
60 super(SwingUtilities.windowForComponent(pdp),
61 Bundle.PersonaAccountDialog_title_text(),
62 ModalityType.APPLICATION_MODAL);
66 typeComboBox.setRenderer(TYPE_CHOICE_RENDERER);
71 super(SwingUtilities.windowForComponent(pdp),
72 Bundle.PersonaAccountDialog_title_text(),
73 ModalityType.APPLICATION_MODAL);
78 confidenceComboBox.setSelectedItem(acc.confidence);
79 justificationTextField.setText(acc.justification);
80 typeComboBox.setSelectedItem(acc.account.getAccountType());
81 identifierTextField.setText(acc.account.getIdentifier());
83 typeComboBox.setEnabled(
false);
84 identifierTextField.setEnabled(
false);
86 typeComboBox.setRenderer(TYPE_CHOICE_RENDERER);
94 private class TypeChoiceRenderer extends JLabel implements ListCellRenderer<CentralRepoAccountType>, Serializable {
96 private static final long serialVersionUID = 1L;
101 int index,
boolean isSelected,
boolean cellHasFocus) {
108 "PersonaAccountDialog_get_types_exception_Title=Central Repository failure",
109 "PersonaAccountDialog_get_types_exception_msg=Failed to access central repository.",})
111 Collection<CentralRepoAccountType> allAccountTypes;
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);
130 @SuppressWarnings(
"unchecked")
132 private
void initComponents() {
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();
146 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
149 settingsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
151 org.openide.awt.Mnemonics.setLocalizedText(identiferLbl,
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class,
"PersonaAccountDialog.identiferLbl.text"));
153 identifierTextField.setText(
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class,
"PersonaAccountDialog.identifierTextField.text"));
154 identifierTextField.addActionListener(
new java.awt.event.ActionListener() {
155 public void actionPerformed(java.awt.event.ActionEvent evt) {
156 identifierTextFieldActionPerformed(evt);
160 org.openide.awt.Mnemonics.setLocalizedText(typeLbl,
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class,
"PersonaAccountDialog.typeLbl.text"));
162 typeComboBox.setModel(
new javax.swing.DefaultComboBoxModel<>(getAllAccountTypes()));
164 org.openide.awt.Mnemonics.setLocalizedText(confidenceLbl,
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class,
"PersonaAccountDialog.confidenceLbl.text"));
168 org.openide.awt.Mnemonics.setLocalizedText(justificationLbl,
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class,
"PersonaAccountDialog.justificationLbl.text"));
170 justificationTextField.setText(
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class,
"PersonaAccountDialog.justificationTextField.text"));
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()
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)))
197 settingsPanelLayout.setVerticalGroup(
198 settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
199 .addGroup(settingsPanelLayout.createSequentialGroup()
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))
219 org.openide.awt.Mnemonics.setLocalizedText(cancelBtn,
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class,
"PersonaAccountDialog.cancelBtn.text"));
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);
229 org.openide.awt.Mnemonics.setLocalizedText(okBtn,
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class,
"PersonaAccountDialog.okBtn.text"));
230 okBtn.addActionListener(
new java.awt.event.ActionListener() {
231 public void actionPerformed(java.awt.event.ActionEvent evt) {
232 okBtnActionPerformed(evt);
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)
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)
246 .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
249 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelBtn, okBtn});
251 layout.setVerticalGroup(
252 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
253 .addGroup(layout.createSequentialGroup()
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))
267 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
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.",})
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);
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);
295 Collection<CentralRepoAccount> candidates;
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);
306 if (candidates.isEmpty()) {
307 JOptionPane.showMessageDialog(
this,
308 Bundle.PersonaAccountDialog_search_empty_msg(),
309 Bundle.PersonaAccountDialog_search_empty_Title(),
310 JOptionPane.ERROR_MESSAGE);
315 if (cand.getAccountType().getAcctType().equals(
321 if (result == null) {
322 JOptionPane.showMessageDialog(
this,
323 Bundle.PersonaAccountDialog_search_empty_msg(),
324 Bundle.PersonaAccountDialog_search_empty_Title(),
325 JOptionPane.ERROR_MESSAGE);
330 String justification = justificationTextField.getText();
332 if (currentAccount != null) {
333 currentAccount.confidence = confidence;
334 currentAccount.justification = justification;
337 if (pdp.addAccount(result, justification, confidence)) {
340 JOptionPane.showMessageDialog(
this,
341 Bundle.PersonaAccountDialog_dup_msg(),
342 Bundle.PersonaAccountDialog_dup_Title(),
343 JOptionPane.ERROR_MESSAGE);
javax.swing.JTextField justificationTextField
javax.swing.JButton okBtn
final PersonaDetailsPanel pdp
Collection< CentralRepoAccountType > getAllAccountTypes()
javax.swing.JLabel identiferLbl
javax.swing.JTextField identifierTextField
javax.swing.JLabel confidenceLbl
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
void cancelBtnActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JPanel settingsPanel
static Collection< CentralRepoAccount > getAccountsWithIdentifier(String accountIdentifier)
javax.swing.JComboBox< org.sleuthkit.autopsy.centralrepository.datamodel.Persona.Confidence > confidenceComboBox
javax.swing.JLabel typeLbl
void identifierTextFieldActionPerformed(java.awt.event.ActionEvent evt)
CentralRepoAccountType[] getAllAccountTypes()
javax.swing.JButton cancelBtn
PersonaAccountDialog(PersonaDetailsPanel pdp)
javax.swing.JLabel justificationLbl
synchronized static Logger getLogger(String name)
void okBtnActionPerformed(java.awt.event.ActionEvent evt)
static CentralRepository getInstance()
Account.Type getAcctType()