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;
42 @SuppressWarnings(
"PMD.SingularField")
47 private static final long serialVersionUID = 1L;
54 @Messages({
"CreatePersonaAccountDialog.title.text=Create Account",})
56 super(SwingUtilities.windowForComponent(pdp),
57 Bundle.PersonaAccountDialog_title_text(),
58 ModalityType.APPLICATION_MODAL);
61 typeComboBox.setRenderer(TYPE_CHOICE_RENDERER);
69 private class TypeChoiceRenderer extends JLabel implements ListCellRenderer<CentralRepoAccountType>, Serializable {
71 private static final long serialVersionUID = 1L;
76 int index,
boolean isSelected,
boolean cellHasFocus) {
83 Collection<CentralRepoAccountType> allAccountTypes;
87 logger.log(Level.SEVERE,
"Failed to access central repository", e);
88 JOptionPane.showMessageDialog(
this,
89 Bundle.PersonaAccountDialog_get_types_exception_Title(),
90 Bundle.PersonaAccountDialog_get_types_exception_msg(),
91 JOptionPane.ERROR_MESSAGE);
102 @SuppressWarnings(
"unchecked")
104 private
void initComponents() {
106 settingsPanel =
new javax.swing.JPanel();
107 identiferLbl =
new javax.swing.JLabel();
108 identifierTextField =
new javax.swing.JTextField();
109 typeLbl =
new javax.swing.JLabel();
110 typeComboBox =
new javax.swing.JComboBox<>();
111 cancelBtn =
new javax.swing.JButton();
112 okBtn =
new javax.swing.JButton();
114 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
117 settingsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
119 org.openide.awt.Mnemonics.setLocalizedText(identiferLbl,
org.openide.util.NbBundle.getMessage(
CreatePersonaAccountDialog.class,
"CreatePersonaAccountDialog.identiferLbl.text"));
121 identifierTextField.setText(
org.openide.util.NbBundle.getMessage(
CreatePersonaAccountDialog.class,
"CreatePersonaAccountDialog.identifierTextField.text"));
122 identifierTextField.addActionListener(
new java.awt.event.ActionListener() {
123 public void actionPerformed(java.awt.event.ActionEvent evt) {
124 identifierTextFieldActionPerformed(evt);
128 org.openide.awt.Mnemonics.setLocalizedText(typeLbl,
org.openide.util.NbBundle.getMessage(
CreatePersonaAccountDialog.class,
"CreatePersonaAccountDialog.typeLbl.text"));
130 typeComboBox.setModel(
new javax.swing.DefaultComboBoxModel<>(getAllAccountTypes()));
132 javax.swing.GroupLayout settingsPanelLayout =
new javax.swing.GroupLayout(settingsPanel);
133 settingsPanel.setLayout(settingsPanelLayout);
134 settingsPanelLayout.setHorizontalGroup(
135 settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
136 .addGroup(settingsPanelLayout.createSequentialGroup()
138 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
139 .addGroup(settingsPanelLayout.createSequentialGroup()
140 .addComponent(typeLbl)
141 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
142 .addComponent(typeComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
143 .addGroup(settingsPanelLayout.createSequentialGroup()
144 .addComponent(identiferLbl)
145 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
146 .addComponent(identifierTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)))
149 settingsPanelLayout.setVerticalGroup(
150 settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
151 .addGroup(settingsPanelLayout.createSequentialGroup()
153 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
154 .addComponent(identiferLbl)
155 .addComponent(identifierTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
156 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
157 .addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
158 .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
159 .addComponent(typeLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE))
160 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
163 org.openide.awt.Mnemonics.setLocalizedText(cancelBtn,
org.openide.util.NbBundle.getMessage(
CreatePersonaAccountDialog.class,
"CreatePersonaAccountDialog.cancelBtn.text"));
164 cancelBtn.setMaximumSize(
new java.awt.Dimension(79, 23));
165 cancelBtn.setMinimumSize(
new java.awt.Dimension(79, 23));
166 cancelBtn.setPreferredSize(
new java.awt.Dimension(79, 23));
167 cancelBtn.addActionListener(
new java.awt.event.ActionListener() {
168 public void actionPerformed(java.awt.event.ActionEvent evt) {
169 cancelBtnActionPerformed(evt);
173 org.openide.awt.Mnemonics.setLocalizedText(okBtn,
org.openide.util.NbBundle.getMessage(
CreatePersonaAccountDialog.class,
"CreatePersonaAccountDialog.okBtn.text"));
174 okBtn.addActionListener(
new java.awt.event.ActionListener() {
175 public void actionPerformed(java.awt.event.ActionEvent evt) {
176 okBtnActionPerformed(evt);
180 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
181 getContentPane().setLayout(layout);
182 layout.setHorizontalGroup(
183 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
184 .addGroup(layout.createSequentialGroup()
185 .addContainerGap(194, Short.MAX_VALUE)
187 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
188 .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
190 .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
193 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelBtn, okBtn});
195 layout.setVerticalGroup(
196 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
197 .addGroup(layout.createSequentialGroup()
199 .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
200 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
201 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
203 .addComponent(cancelBtn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
204 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
211 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
216 "CreatePersonaAccountDialog_error_title=Account failure",
217 "CreatePersonaAccountDialog_error_msg=Failed to create account.",
227 logger.log(Level.SEVERE,
"Failed to create account", e);
228 JOptionPane.showMessageDialog(
this,
229 Bundle.CreatePersonaAccountDialog_error_title(),
230 Bundle.CreatePersonaAccountDialog_error_msg(),
231 JOptionPane.ERROR_MESSAGE);
237 "CreatePersonaAccountDialog_success_title=Account added",
238 "CreatePersonaAccountDialog_success_msg=Account added.",
241 if (identifierTextField.getText().isEmpty()) {
242 JOptionPane.showMessageDialog(
this,
243 Bundle.PersonaAccountDialog_identifier_empty_msg(),
244 Bundle.PersonaAccountDialog_identifier_empty_Title(),
245 JOptionPane.ERROR_MESSAGE);
251 String identifier = identifierTextField.getText();
253 if (createAccount(type, identifier) != null) {
255 JOptionPane.showMessageDialog(
this,
256 Bundle.CreatePersonaAccountDialog_success_msg(),
257 Bundle.CreatePersonaAccountDialog_success_title(),
258 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()