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.lang3.StringUtils;
 
   32 import org.openide.util.NbBundle.Messages;
 
   33 import org.openide.windows.WindowManager;
 
   44 @SuppressWarnings(
"PMD.SingularField") 
 
   49     private static final long serialVersionUID = 1L;
 
   56     @Messages({
"CreatePersonaAccountDialog.title.text=Create Account",})
 
   58         super(SwingUtilities.windowForComponent(pdp),
 
   59                 Bundle.PersonaAccountDialog_title_text(),
 
   60                 ModalityType.APPLICATION_MODAL);
 
   63         typeComboBox.setRenderer(TYPE_CHOICE_RENDERER);
 
   71     private class TypeChoiceRenderer extends JLabel implements ListCellRenderer<CentralRepoAccountType>, Serializable {
 
   73         private static final long serialVersionUID = 1L;
 
   78                 int index, 
boolean isSelected, 
boolean cellHasFocus) {
 
   85         Collection<CentralRepoAccountType> allAccountTypes;
 
   89             logger.log(Level.SEVERE, 
"Failed to access central repository", e);
 
   90             JOptionPane.showMessageDialog(
this,
 
   91                     Bundle.PersonaAccountDialog_get_types_exception_Title(),
 
   92                     Bundle.PersonaAccountDialog_get_types_exception_msg(),
 
   93                     JOptionPane.ERROR_MESSAGE);
 
  104     @SuppressWarnings(
"unchecked")
 
  106     private 
void initComponents() {
 
  108         settingsPanel = 
new javax.swing.JPanel();
 
  109         identiferLbl = 
new javax.swing.JLabel();
 
  110         identifierTextField = 
new javax.swing.JTextField();
 
  111         typeLbl = 
new javax.swing.JLabel();
 
  112         typeComboBox = 
new javax.swing.JComboBox<>();
 
  113         cancelBtn = 
new javax.swing.JButton();
 
  114         okBtn = 
new javax.swing.JButton();
 
  116         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 
  119         settingsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
 
  121         org.openide.awt.Mnemonics.setLocalizedText(identiferLbl, 
org.openide.util.NbBundle.getMessage(
CreatePersonaAccountDialog.class, 
"CreatePersonaAccountDialog.identiferLbl.text")); 
 
  123         identifierTextField.setText(
org.openide.util.NbBundle.getMessage(
CreatePersonaAccountDialog.class, 
"CreatePersonaAccountDialog.identifierTextField.text")); 
 
  124         identifierTextField.addActionListener(
new java.awt.event.ActionListener() {
 
  125             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  126                 identifierTextFieldActionPerformed(evt);
 
  130         org.openide.awt.Mnemonics.setLocalizedText(typeLbl, 
org.openide.util.NbBundle.getMessage(
CreatePersonaAccountDialog.class, 
"CreatePersonaAccountDialog.typeLbl.text")); 
 
  132         typeComboBox.setModel(
new javax.swing.DefaultComboBoxModel<>(getAllAccountTypes()));
 
  134         javax.swing.GroupLayout settingsPanelLayout = 
new javax.swing.GroupLayout(settingsPanel);
 
  135         settingsPanel.setLayout(settingsPanelLayout);
 
  136         settingsPanelLayout.setHorizontalGroup(
 
  137             settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  138             .addGroup(settingsPanelLayout.createSequentialGroup()
 
  140                 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  141                     .addGroup(settingsPanelLayout.createSequentialGroup()
 
  142                         .addComponent(typeLbl)
 
  143                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  144                         .addComponent(typeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  145                     .addGroup(settingsPanelLayout.createSequentialGroup()
 
  146                         .addComponent(identiferLbl)
 
  147                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  148                         .addComponent(identifierTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)))
 
  151         settingsPanelLayout.setVerticalGroup(
 
  152             settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  153             .addGroup(settingsPanelLayout.createSequentialGroup()
 
  155                 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  156                     .addComponent(identiferLbl)
 
  157                     .addComponent(identifierTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  158                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  159                 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  160                     .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  161                     .addComponent(typeLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  162                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  165         org.openide.awt.Mnemonics.setLocalizedText(cancelBtn, 
org.openide.util.NbBundle.getMessage(
CreatePersonaAccountDialog.class, 
"CreatePersonaAccountDialog.cancelBtn.text")); 
 
  166         cancelBtn.setMaximumSize(
new java.awt.Dimension(79, 23));
 
  167         cancelBtn.setMinimumSize(
new java.awt.Dimension(79, 23));
 
  168         cancelBtn.setPreferredSize(
new java.awt.Dimension(79, 23));
 
  169         cancelBtn.addActionListener(
new java.awt.event.ActionListener() {
 
  170             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  171                 cancelBtnActionPerformed(evt);
 
  175         org.openide.awt.Mnemonics.setLocalizedText(okBtn, 
org.openide.util.NbBundle.getMessage(
CreatePersonaAccountDialog.class, 
"CreatePersonaAccountDialog.okBtn.text")); 
 
  176         okBtn.addActionListener(
new java.awt.event.ActionListener() {
 
  177             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  178                 okBtnActionPerformed(evt);
 
  182         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(getContentPane());
 
  183         getContentPane().setLayout(layout);
 
  184         layout.setHorizontalGroup(
 
  185             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  186             .addGroup(layout.createSequentialGroup()
 
  187                 .addContainerGap(194, Short.MAX_VALUE)
 
  189                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  190                 .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  192             .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 
  195         layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, 
new java.awt.Component[] {cancelBtn, okBtn});
 
  197         layout.setVerticalGroup(
 
  198             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  199             .addGroup(layout.createSequentialGroup()
 
  201                 .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  202                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  203                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  205                     .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  206                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  213         this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
 
  218         "CreatePersonaAccountDialog_error_title=Account failure",
 
  219         "CreatePersonaAccountDialog_error_msg=Failed to create account.",
 
  220         "CreatePersonaAccountDialog_invalid_account_Title=Invalid account identifier",
 
  221         "CreatePersonaAccountDialog_invalid_account_msg=Account identifier is not valid.",})
 
  230             logger.log(Level.SEVERE, 
"Failed to create account", e);
 
  231             JOptionPane.showMessageDialog(
this,
 
  232                     Bundle.CreatePersonaAccountDialog_error_msg(),
 
  233                     Bundle.CreatePersonaAccountDialog_error_title(),
 
  234                     JOptionPane.ERROR_MESSAGE);
 
  236             logger.log(Level.WARNING, 
"Invalid account identifier", e);
 
  237             JOptionPane.showMessageDialog(
this,
 
  238                     Bundle.CreatePersonaAccountDialog_invalid_account_msg(),
 
  239                     Bundle.CreatePersonaAccountDialog_invalid_account_Title(),
 
  240                     JOptionPane.ERROR_MESSAGE);
 
  246         "CreatePersonaAccountDialog_success_title=Account added",
 
  247         "CreatePersonaAccountDialog_success_msg=Account added.",
 
  250         if (StringUtils.isBlank(identifierTextField.getText())) {
 
  251             JOptionPane.showMessageDialog(
this,
 
  252                     Bundle.PersonaAccountDialog_identifier_empty_msg(),
 
  253                     Bundle.PersonaAccountDialog_identifier_empty_Title(),
 
  254                     JOptionPane.ERROR_MESSAGE);
 
  260         String identifier = identifierTextField.getText();
 
  262         if (createAccount(type, identifier) != null) {
 
  264             JOptionPane.showMessageDialog(
this,
 
  265                     Bundle.CreatePersonaAccountDialog_success_msg(),
 
  266                     Bundle.CreatePersonaAccountDialog_success_title(),
 
  267                     JOptionPane.INFORMATION_MESSAGE);
 
CentralRepoAccountType[] getAllAccountTypes()
void okBtnActionPerformed(java.awt.event.ActionEvent evt)
void identifierTextFieldActionPerformed(java.awt.event.ActionEvent evt)
CreatePersonaAccountDialog(PersonaDetailsPanel pdp)
Collection< CentralRepoAccountType > getAllAccountTypes()
javax.swing.JLabel identiferLbl
javax.swing.JTextField identifierTextField
void cancelBtnActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JButton okBtn
Component getListCellRendererComponent(JList<?extends CentralRepoAccountType > list, CentralRepoAccountType value, int index, boolean isSelected, boolean cellHasFocus)
javax.swing.JButton cancelBtn
javax.swing.JPanel settingsPanel
synchronized static Logger getLogger(String name)
javax.swing.JLabel typeLbl
static CentralRepository getInstance()
javax.swing.JComboBox< org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoAccount.CentralRepoAccountType > typeComboBox
CentralRepoAccount createAccount(CentralRepoAccount.CentralRepoAccountType type, String identifier)
CentralRepoAccount getOrCreateAccount(CentralRepoAccount.CentralRepoAccountType crAccountType, String accountUniqueID)
Account.Type getAcctType()