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.apache.commons.lang.StringUtils;
 
   32 import org.openide.util.NbBundle.Messages;
 
   33 import org.openide.windows.WindowManager;
 
   45 @SuppressWarnings(
"PMD.SingularField") 
 
   50     private static final long serialVersionUID = 1L;
 
   60     @Messages({
"PersonaAccountDialog.title.text=Add Account",})
 
   62         super(SwingUtilities.windowForComponent(pdp),
 
   63                 Bundle.PersonaAccountDialog_title_text(),
 
   64                 ModalityType.APPLICATION_MODAL);
 
   68         typeComboBox.setRenderer(TYPE_CHOICE_RENDERER);
 
   73         super(SwingUtilities.windowForComponent(pdp),
 
   74                 Bundle.PersonaAccountDialog_title_text(),
 
   75                 ModalityType.APPLICATION_MODAL);
 
   80         confidenceComboBox.setSelectedItem(acc.confidence);
 
   81         justificationTextField.setText(acc.justification);
 
   82         typeComboBox.setSelectedItem(acc.account.getAccountType());
 
   83         identifierTextField.setText(acc.account.getIdentifier());
 
   85         typeComboBox.setEnabled(
false);
 
   86         identifierTextField.setEnabled(
false);
 
   88         typeComboBox.setRenderer(TYPE_CHOICE_RENDERER);
 
   96     private class TypeChoiceRenderer extends JLabel implements ListCellRenderer<CentralRepoAccountType>, Serializable {
 
   98         private static final long serialVersionUID = 1L;
 
  103                 int index, 
boolean isSelected, 
boolean cellHasFocus) {
 
  110         "PersonaAccountDialog_get_types_exception_Title=Central Repository failure",
 
  111         "PersonaAccountDialog_get_types_exception_msg=Failed to access central repository.",})
 
  113         Collection<CentralRepoAccountType> allAccountTypes;
 
  117             logger.log(Level.SEVERE, 
"Failed to access central repository", e);
 
  118             JOptionPane.showMessageDialog(
this,
 
  119                     Bundle.PersonaAccountDialog_get_types_exception_Title(),
 
  120                     Bundle.PersonaAccountDialog_get_types_exception_msg(),
 
  121                     JOptionPane.ERROR_MESSAGE);
 
  132     @SuppressWarnings(
"unchecked")
 
  134     private 
void initComponents() {
 
  136         settingsPanel = 
new javax.swing.JPanel();
 
  137         identiferLbl = 
new javax.swing.JLabel();
 
  138         identifierTextField = 
new javax.swing.JTextField();
 
  139         typeLbl = 
new javax.swing.JLabel();
 
  140         typeComboBox = 
new javax.swing.JComboBox<>();
 
  141         confidenceLbl = 
new javax.swing.JLabel();
 
  142         confidenceComboBox = 
new javax.swing.JComboBox<>();
 
  143         justificationLbl = 
new javax.swing.JLabel();
 
  144         justificationTextField = 
new javax.swing.JTextField();
 
  145         cancelBtn = 
new javax.swing.JButton();
 
  146         okBtn = 
new javax.swing.JButton();
 
  148         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 
  151         settingsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
 
  153         org.openide.awt.Mnemonics.setLocalizedText(identiferLbl, 
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class, 
"PersonaAccountDialog.identiferLbl.text")); 
 
  155         identifierTextField.setText(
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class, 
"PersonaAccountDialog.identifierTextField.text")); 
 
  156         identifierTextField.addActionListener(
new java.awt.event.ActionListener() {
 
  157             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  158                 identifierTextFieldActionPerformed(evt);
 
  162         org.openide.awt.Mnemonics.setLocalizedText(typeLbl, 
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class, 
"PersonaAccountDialog.typeLbl.text")); 
 
  164         typeComboBox.setModel(
new javax.swing.DefaultComboBoxModel<>(getAllAccountTypes()));
 
  166         org.openide.awt.Mnemonics.setLocalizedText(confidenceLbl, 
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class, 
"PersonaAccountDialog.confidenceLbl.text")); 
 
  170         org.openide.awt.Mnemonics.setLocalizedText(justificationLbl, 
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class, 
"PersonaAccountDialog.justificationLbl.text")); 
 
  172         justificationTextField.setText(
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class, 
"PersonaAccountDialog.justificationTextField.text")); 
 
  174         javax.swing.GroupLayout settingsPanelLayout = 
new javax.swing.GroupLayout(settingsPanel);
 
  175         settingsPanel.setLayout(settingsPanelLayout);
 
  176         settingsPanelLayout.setHorizontalGroup(
 
  177             settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  178             .addGroup(settingsPanelLayout.createSequentialGroup()
 
  180                 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  181                     .addGroup(settingsPanelLayout.createSequentialGroup()
 
  182                         .addComponent(typeLbl)
 
  183                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  184                         .addComponent(typeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  185                     .addGroup(settingsPanelLayout.createSequentialGroup()
 
  186                         .addComponent(identiferLbl)
 
  187                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  188                         .addComponent(identifierTextField))
 
  189                     .addGroup(settingsPanelLayout.createSequentialGroup()
 
  190                         .addComponent(confidenceLbl)
 
  191                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  192                         .addComponent(confidenceComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  193                     .addGroup(settingsPanelLayout.createSequentialGroup()
 
  194                         .addComponent(justificationLbl)
 
  195                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  196                         .addComponent(justificationTextField)))
 
  199         settingsPanelLayout.setVerticalGroup(
 
  200             settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  201             .addGroup(settingsPanelLayout.createSequentialGroup()
 
  203                 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  204                     .addComponent(identiferLbl)
 
  205                     .addComponent(identifierTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  206                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  207                 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  208                     .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  209                     .addComponent(typeLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  210                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  211                 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  212                     .addComponent(confidenceLbl)
 
  213                     .addComponent(confidenceComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  214                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  215                 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  216                     .addComponent(justificationLbl)
 
  217                     .addComponent(justificationTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  218                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  221         org.openide.awt.Mnemonics.setLocalizedText(cancelBtn, 
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class, 
"PersonaAccountDialog.cancelBtn.text")); 
 
  222         cancelBtn.setMaximumSize(
new java.awt.Dimension(79, 23));
 
  223         cancelBtn.setMinimumSize(
new java.awt.Dimension(79, 23));
 
  224         cancelBtn.setPreferredSize(
new java.awt.Dimension(79, 23));
 
  225         cancelBtn.addActionListener(
new java.awt.event.ActionListener() {
 
  226             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  227                 cancelBtnActionPerformed(evt);
 
  231         org.openide.awt.Mnemonics.setLocalizedText(okBtn, 
org.openide.util.NbBundle.getMessage(
PersonaAccountDialog.class, 
"PersonaAccountDialog.okBtn.text")); 
 
  232         okBtn.addActionListener(
new java.awt.event.ActionListener() {
 
  233             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  234                 okBtnActionPerformed(evt);
 
  238         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(getContentPane());
 
  239         getContentPane().setLayout(layout);
 
  240         layout.setHorizontalGroup(
 
  241             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  242             .addGroup(layout.createSequentialGroup()
 
  243                 .addContainerGap(194, Short.MAX_VALUE)
 
  245                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  246                 .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  248             .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 
  251         layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, 
new java.awt.Component[] {cancelBtn, okBtn});
 
  253         layout.setVerticalGroup(
 
  254             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  255             .addGroup(layout.createSequentialGroup()
 
  257                 .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  258                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  259                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  260                     .addComponent(okBtn, javax.swing.GroupLayout.Alignment.TRAILING)
 
  261                     .addComponent(cancelBtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  262                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  269         this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
 
  274         "PersonaAccountDialog_dup_Title=Account add failure",
 
  275         "PersonaAccountDialog_dup_msg=This account is already added to the persona.",
 
  276         "PersonaAccountDialog_identifier_empty_Title=Empty identifier",
 
  277         "PersonaAccountDialog_identifier_empty_msg=The identifier field cannot be empty.",
 
  278         "PersonaAccountDialog_search_failure_Title=Account add failure",
 
  279         "PersonaAccountDialog_search_failure_msg=Central Repository account search failed.",
 
  280         "PersonaAccountDialog_search_empty_Title=Account not found",
 
  281         "PersonaAccountDialog_search_empty_msg=Account not found for given identifier and type.",
 
  282         "PersonaAccountDialog_invalid_account_Title=Invalid account identifier",
 
  283         "PersonaAccountDialog_invalid_account_msg=Account identifier is not valid.",
 
  286         if (StringUtils.isBlank(identifierTextField.getText())) {
 
  287             JOptionPane.showMessageDialog(
this,
 
  288                     Bundle.PersonaAccountDialog_identifier_empty_msg(),
 
  289                     Bundle.PersonaAccountDialog_identifier_empty_Title(),
 
  290                     JOptionPane.ERROR_MESSAGE);
 
  293         if (StringUtils.isBlank(justificationTextField.getText())) {
 
  294             JOptionPane.showMessageDialog(
this,
 
  295                     Bundle.PersonaDetailsPanel_empty_justification_msg(),
 
  296                     Bundle.PersonaDetailsPanel_empty_justification_Title(),
 
  297                     JOptionPane.ERROR_MESSAGE);
 
  300         Collection<CentralRepoAccount> candidates;
 
  304             logger.log(Level.SEVERE, 
"Failed to access central repository", e);
 
  305             JOptionPane.showMessageDialog(
this,
 
  306                     Bundle.PersonaAccountDialog_search_failure_msg(),
 
  307                     Bundle.PersonaAccountDialog_search_failure_Title(),
 
  308                     JOptionPane.ERROR_MESSAGE);
 
  312             logger.log(Level.SEVERE, 
"Invalid account identifier", e);
 
  313             JOptionPane.showMessageDialog(
this,
 
  314                     Bundle.PersonaAccountDialog_invalid_account_msg(),
 
  315                     Bundle.PersonaAccountDialog_invalid_account_Title(),
 
  316                     JOptionPane.ERROR_MESSAGE);
 
  319         if (candidates.isEmpty()) {
 
  320             JOptionPane.showMessageDialog(
this,
 
  321                     Bundle.PersonaAccountDialog_search_empty_msg(),
 
  322                     Bundle.PersonaAccountDialog_search_empty_Title(),
 
  323                     JOptionPane.ERROR_MESSAGE);
 
  328             if (cand.getAccountType().getAcctType().equals(
 
  334         if (result == null) {
 
  335             JOptionPane.showMessageDialog(
this,
 
  336                     Bundle.PersonaAccountDialog_search_empty_msg(),
 
  337                     Bundle.PersonaAccountDialog_search_empty_Title(),
 
  338                     JOptionPane.ERROR_MESSAGE);
 
  343         String justification = justificationTextField.getText();
 
  345         if (currentAccount != null) {
 
  346             currentAccount.confidence = confidence;
 
  347             currentAccount.justification = justification;
 
  350             if (pdp.addAccount(result, justification, confidence)) {
 
  353                 JOptionPane.showMessageDialog(
this,
 
  354                         Bundle.PersonaAccountDialog_dup_msg(),
 
  355                         Bundle.PersonaAccountDialog_dup_Title(),
 
  356                         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()