19 package org.sleuthkit.autopsy.centralrepository.optionspanel;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.logging.Level;
24 import javax.swing.JFrame;
25 import javax.swing.JTextField;
26 import javax.swing.event.DocumentEvent;
27 import javax.swing.event.DocumentListener;
28 import org.netbeans.spi.options.OptionsPanelController;
29 import org.openide.util.NbBundle.Messages;
30 import org.openide.windows.WindowManager;
39 @SuppressWarnings(
"PMD.SingularField")
40 class AddNewOrganizationDialog
extends javax.swing.JDialog {
43 private static final long serialVersionUID = 1L;
45 private final Collection<JTextField> textBoxes;
46 private final TextBoxChangedListener textBoxChangedListener;
47 private boolean hasChanged;
54 @Messages({
"AddNewOrganizationDialog.addNewOrg.msg=Add New Organization"})
55 AddNewOrganizationDialog() {
56 super((JFrame) WindowManager.getDefault().getMainWindow(),
57 Bundle.AddNewOrganizationDialog_addNewOrg_msg(),
59 textBoxes =
new ArrayList<>();
60 textBoxChangedListener =
new TextBoxChangedListener();
64 customizeComponents();
65 organizationToEdit = null;
71 super((JFrame) WindowManager.getDefault().getMainWindow(),
72 Bundle.AddNewOrganizationDialog_addNewOrg_msg(),
74 organizationToEdit = orgToEdit;
75 textBoxes =
new ArrayList<>();
76 textBoxChangedListener =
new TextBoxChangedListener();
80 customizeComponents();
81 tfOrganizationName.setText(orgToEdit.
getName());
88 private void display() {
89 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
93 private void customizeComponents() {
94 setTextBoxListeners();
95 enableOkButton(
false);
101 private void setTextBoxListeners() {
102 textBoxes.add(tfOrganizationName);
103 textBoxes.add(tfPocEmail);
104 textBoxes.add(tfPocPhone);
105 textBoxes.add(tfPocName);
106 addDocumentListeners(textBoxes, textBoxChangedListener);
115 private static void addDocumentListeners(Collection<JTextField> textFields, TextBoxChangedListener listener) {
116 textFields.forEach((textField) -> {
117 textField.getDocument().addDocumentListener(listener);
127 private boolean requiredFieldsArePopulated() {
128 return !tfOrganizationName.getText().trim().isEmpty();
136 @Messages({
"AddNewOrganizationDialog.validation.incompleteFields=Organization Name is required."})
137 private boolean checkFields() {
138 boolean result =
true;
140 boolean isPopulated = requiredFieldsArePopulated();
145 lbWarningMsg.setText(Bundle.AddNewOrganizationDialog_validation_incompleteFields());
155 public boolean valid() {
156 lbWarningMsg.setText(
"");
158 return enableOkButton(checkFields());
168 private boolean enableOkButton(Boolean enable) {
169 bnOK.setEnabled(enable);
181 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
187 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
193 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
202 public boolean isChanged() {
211 public CentralRepoOrganization getNewOrg() {
220 @SuppressWarnings(
"unchecked")
222 private
void initComponents() {
224 bnOK =
new javax.swing.JButton();
225 bnCancel =
new javax.swing.JButton();
226 lbOrganizationName =
new javax.swing.JLabel();
227 lbPocHeading =
new javax.swing.JLabel();
228 lbPocName =
new javax.swing.JLabel();
229 lbPocEmail =
new javax.swing.JLabel();
230 lbPocPhone =
new javax.swing.JLabel();
231 tfPocName =
new javax.swing.JTextField();
232 tfPocEmail =
new javax.swing.JTextField();
233 tfPocPhone =
new javax.swing.JTextField();
234 tfOrganizationName =
new javax.swing.JTextField();
235 lbWarningMsg =
new javax.swing.JLabel();
237 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
239 org.openide.awt.Mnemonics.setLocalizedText(bnOK,
org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class,
"AddNewOrganizationDialog.bnOK.text"));
240 bnOK.addActionListener(
new java.awt.event.ActionListener() {
241 public void actionPerformed(java.awt.event.ActionEvent evt) {
242 bnOKActionPerformed(evt);
246 org.openide.awt.Mnemonics.setLocalizedText(bnCancel,
org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class,
"AddNewOrganizationDialog.bnCancel.text"));
247 bnCancel.addActionListener(
new java.awt.event.ActionListener() {
248 public void actionPerformed(java.awt.event.ActionEvent evt) {
249 bnCancelActionPerformed(evt);
253 org.openide.awt.Mnemonics.setLocalizedText(lbOrganizationName,
org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class,
"AddNewOrganizationDialog.lbOrganizationName.text"));
255 org.openide.awt.Mnemonics.setLocalizedText(lbPocHeading,
org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class,
"AddNewOrganizationDialog.lbPocHeading.text"));
257 org.openide.awt.Mnemonics.setLocalizedText(lbPocName,
org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class,
"AddNewOrganizationDialog.lbPocName.text"));
259 org.openide.awt.Mnemonics.setLocalizedText(lbPocEmail,
org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class,
"AddNewOrganizationDialog.lbPocEmail.text"));
261 org.openide.awt.Mnemonics.setLocalizedText(lbPocPhone,
org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class,
"AddNewOrganizationDialog.lbPocPhone.text"));
263 tfPocName.setToolTipText(
org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class,
"AddNewOrganizationDialog.tfName.tooltip"));
265 lbWarningMsg.setFont(lbWarningMsg.getFont().deriveFont(lbWarningMsg.getFont().getStyle() | java.awt.Font.BOLD, lbWarningMsg.getFont().getSize()+1));
266 lbWarningMsg.setForeground(
new java.awt.Color(255, 0, 0));
268 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
269 getContentPane().setLayout(layout);
270 layout.setHorizontalGroup(
271 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
272 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
273 .addContainerGap(258, Short.MAX_VALUE)
276 .addComponent(bnCancel)
278 .addGroup(layout.createSequentialGroup()
280 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
281 .addComponent(lbPocEmail)
282 .addComponent(lbPocName)
283 .addComponent(lbPocPhone))
284 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
285 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
286 .addComponent(tfPocPhone)
287 .addComponent(tfPocName)
288 .addComponent(tfPocEmail))
290 .addGroup(layout.createSequentialGroup()
292 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293 .addGroup(layout.createSequentialGroup()
294 .addComponent(lbOrganizationName)
295 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
296 .addComponent(tfOrganizationName))
297 .addGroup(layout.createSequentialGroup()
298 .addComponent(lbPocHeading)
299 .addGap(0, 0, Short.MAX_VALUE))
300 .addComponent(lbWarningMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
303 layout.setVerticalGroup(
304 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
305 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
307 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
308 .addComponent(lbOrganizationName)
309 .addComponent(tfOrganizationName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
310 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
311 .addComponent(lbPocHeading)
312 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
313 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
314 .addComponent(lbPocName)
315 .addComponent(tfPocName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
316 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
317 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
318 .addComponent(lbPocEmail)
319 .addComponent(tfPocEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
320 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
321 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
322 .addComponent(lbPocPhone)
323 .addComponent(tfPocPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
324 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
325 .addComponent(lbWarningMsg, javax.swing.GroupLayout.DEFAULT_SIZE, 22, Short.MAX_VALUE)
326 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
327 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
329 .addComponent(bnCancel))
336 private void bnCancelActionPerformed(java.awt.event.ActionEvent evt) {
340 @Messages({
"AddNewOrganizationDialog.bnOk.addFailed.text=Failed to add new organization."})
341 private void bnOKActionPerformed(java.awt.event.ActionEvent evt) {
344 CentralRepository dbManager = CentralRepository.getInstance();
345 if (organizationToEdit != null) {
347 newOrg = dbManager.getOrganizationByID(organizationToEdit.
getOrgID());
348 newOrg.
setName(tfOrganizationName.getText());
352 dbManager.updateOrganization(newOrg);
354 newOrg =
new CentralRepoOrganization(
355 tfOrganizationName.getText(),
357 tfPocEmail.getText(),
358 tfPocPhone.getText());
359 newOrg = dbManager.newOrganization(newOrg);
363 }
catch (CentralRepoException ex) {
364 lbWarningMsg.setText(Bundle.AddNewOrganizationDialog_bnOk_addFailed_text());
365 logger.log(Level.SEVERE,
"Failed adding new organization.", ex);
372 private javax.swing.JButton bnCancel;
373 private javax.swing.JButton bnOK;
374 private javax.swing.JLabel lbOrganizationName;
375 private javax.swing.JLabel lbPocEmail;
376 private javax.swing.JLabel lbPocHeading;
377 private javax.swing.JLabel lbPocName;
378 private javax.swing.JLabel lbPocPhone;
379 private javax.swing.JLabel lbWarningMsg;
380 private javax.swing.JTextField tfOrganizationName;
381 private javax.swing.JTextField tfPocEmail;
382 private javax.swing.JTextField tfPocName;
383 private javax.swing.JTextField tfPocPhone;
void insertUpdate(DocumentEvent e)
void setPocPhone(String pocPhone)
void setPocName(String pocName)
void setName(String name)
void removeUpdate(DocumentEvent e)
synchronized static Logger getLogger(String name)
void changedUpdate(DocumentEvent e)
void setPocEmail(String pocEmail)