Autopsy  4.4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddNewOrganizationDialog.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2015-2017 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.centralrepository.optionspanel;
20 
21 import java.awt.Dimension;
22 import java.awt.Toolkit;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.logging.Level;
26 import javax.swing.JFrame;
27 import javax.swing.JTextField;
28 import javax.swing.event.DocumentEvent;
29 import javax.swing.event.DocumentListener;
30 import org.netbeans.spi.options.OptionsPanelController;
31 import org.openide.util.NbBundle.Messages;
32 import org.openide.windows.WindowManager;
37 
41 public class AddNewOrganizationDialog extends javax.swing.JDialog {
42 
43  private static final Logger LOGGER = Logger.getLogger(AddNewOrganizationDialog.class.getName());
44 
45  private final Collection<JTextField> textBoxes;
47  private boolean hasChanged;
48 
52  @Messages({"AddNewOrganizationDialog.addNewOrg.msg=Add New Organization"})
54  super((JFrame) WindowManager.getDefault().getMainWindow(),
55  Bundle.AddNewOrganizationDialog_addNewOrg_msg(),
56  true); // NON-NLS
57  textBoxes = new ArrayList<>();
58  textBoxChangedListener = new TextBoxChangedListener();
59  hasChanged = false;
62  display();
63  }
64 
65  private void display() {
66  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
67  setLocation((screenDimension.width - getSize().width) / 2, (screenDimension.height - getSize().height) / 2);
68  setVisible(true);
69  }
70 
71  private void customizeComponents() {
73  enableOkButton(false);
74  }
75 
79  private void setTextBoxListeners() {
80  textBoxes.add(tfOrganizationName);
81  textBoxes.add(tfPocEmail);
82  textBoxes.add(tfPocPhone);
83  textBoxes.add(tfPocName);
84  addDocumentListeners(textBoxes, textBoxChangedListener);
85  }
86 
93  private static void addDocumentListeners(Collection<JTextField> textFields, TextBoxChangedListener listener) {
94  textFields.forEach((textField) -> {
95  textField.getDocument().addDocumentListener(listener);
96  });
97  }
98 
105  private boolean requiredFieldsArePopulated() {
106  return !tfOrganizationName.getText().trim().isEmpty();
107  }
108 
114  @Messages({"AddNewOrganizationDialog.validation.incompleteFields=Organization Name is required."})
115  private boolean checkFields() {
116  boolean result = true;
117 
118  boolean isPopulated = requiredFieldsArePopulated();
119 
120  if (!isPopulated) {
121  // We don't even have everything filled out
122  result = false;
123  lbWarningMsg.setText(Bundle.AddNewOrganizationDialog_validation_incompleteFields());
124  }
125  return result;
126  }
127 
133  public boolean valid() {
134  lbWarningMsg.setText("");
135 
136  return enableOkButton(checkFields());
137  }
138 
146  private boolean enableOkButton(Boolean enable) {
147  bnOK.setEnabled(enable);
148  return enable;
149  }
150 
155  private class TextBoxChangedListener implements DocumentListener {
156 
157  @Override
158  public void changedUpdate(DocumentEvent e) {
159  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
160  valid();
161  }
162 
163  @Override
164  public void insertUpdate(DocumentEvent e) {
165  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
166  valid();
167  }
168 
169  @Override
170  public void removeUpdate(DocumentEvent e) {
171  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
172  valid();
173  }
174  }
175 
176  public boolean isChanged() {
177  return hasChanged;
178  }
179 
185  @SuppressWarnings("unchecked")
186  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
187  private void initComponents() {
188 
189  bnOK = new javax.swing.JButton();
190  bnCancel = new javax.swing.JButton();
191  lbOrganizationName = new javax.swing.JLabel();
192  lbPocHeading = new javax.swing.JLabel();
193  lbPocName = new javax.swing.JLabel();
194  lbPocEmail = new javax.swing.JLabel();
195  lbPocPhone = new javax.swing.JLabel();
196  tfPocName = new javax.swing.JTextField();
197  tfPocEmail = new javax.swing.JTextField();
198  tfPocPhone = new javax.swing.JTextField();
199  tfOrganizationName = new javax.swing.JTextField();
200  lbWarningMsg = new javax.swing.JLabel();
201 
202  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
203 
204  org.openide.awt.Mnemonics.setLocalizedText(bnOK, org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class, "AddNewOrganizationDialog.bnOK.text")); // NOI18N
205  bnOK.addActionListener(new java.awt.event.ActionListener() {
206  public void actionPerformed(java.awt.event.ActionEvent evt) {
207  bnOKActionPerformed(evt);
208  }
209  });
210 
211  org.openide.awt.Mnemonics.setLocalizedText(bnCancel, org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class, "AddNewOrganizationDialog.bnCancel.text")); // NOI18N
212  bnCancel.addActionListener(new java.awt.event.ActionListener() {
213  public void actionPerformed(java.awt.event.ActionEvent evt) {
215  }
216  });
217 
218  org.openide.awt.Mnemonics.setLocalizedText(lbOrganizationName, org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class, "AddNewOrganizationDialog.lbOrganizationName.text")); // NOI18N
219 
220  org.openide.awt.Mnemonics.setLocalizedText(lbPocHeading, org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class, "AddNewOrganizationDialog.lbPocHeading.text")); // NOI18N
221 
222  org.openide.awt.Mnemonics.setLocalizedText(lbPocName, org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class, "AddNewOrganizationDialog.lbPocName.text")); // NOI18N
223 
224  org.openide.awt.Mnemonics.setLocalizedText(lbPocEmail, org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class, "AddNewOrganizationDialog.lbPocEmail.text")); // NOI18N
225 
226  org.openide.awt.Mnemonics.setLocalizedText(lbPocPhone, org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class, "AddNewOrganizationDialog.lbPocPhone.text")); // NOI18N
227 
228  tfPocName.setToolTipText(org.openide.util.NbBundle.getMessage(AddNewOrganizationDialog.class, "AddNewOrganizationDialog.tfName.tooltip")); // NOI18N
229 
230  lbWarningMsg.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
231  lbWarningMsg.setForeground(new java.awt.Color(255, 0, 0));
232 
233  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
234  getContentPane().setLayout(layout);
235  layout.setHorizontalGroup(
236  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
237  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
238  .addContainerGap(258, Short.MAX_VALUE)
239  .addComponent(bnOK)
240  .addGap(18, 18, 18)
241  .addComponent(bnCancel)
242  .addGap(12, 12, 12))
243  .addGroup(layout.createSequentialGroup()
244  .addGap(39, 39, 39)
245  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246  .addComponent(lbPocEmail)
247  .addComponent(lbPocName)
248  .addComponent(lbPocPhone))
249  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
250  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
251  .addComponent(tfPocPhone)
252  .addComponent(tfPocName)
253  .addComponent(tfPocEmail))
254  .addContainerGap())
255  .addGroup(layout.createSequentialGroup()
256  .addGap(18, 18, 18)
257  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
258  .addGroup(layout.createSequentialGroup()
259  .addComponent(lbOrganizationName, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
260  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
261  .addComponent(tfOrganizationName))
262  .addGroup(layout.createSequentialGroup()
263  .addComponent(lbPocHeading)
264  .addGap(0, 0, Short.MAX_VALUE))
265  .addComponent(lbWarningMsg, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
266  .addContainerGap())
267  );
268  layout.setVerticalGroup(
269  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
270  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
271  .addContainerGap()
272  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
273  .addComponent(lbOrganizationName, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
274  .addComponent(tfOrganizationName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
275  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
276  .addComponent(lbPocHeading)
277  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
278  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
279  .addComponent(lbPocName)
280  .addComponent(tfPocName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
281  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
282  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
283  .addComponent(lbPocEmail)
284  .addComponent(tfPocEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
285  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
286  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
287  .addComponent(lbPocPhone)
288  .addComponent(tfPocPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
289  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
290  .addComponent(lbWarningMsg, javax.swing.GroupLayout.DEFAULT_SIZE, 22, Short.MAX_VALUE)
291  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
292  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
293  .addComponent(bnOK)
294  .addComponent(bnCancel))
295  .addContainerGap())
296  );
297 
298  pack();
299  }// </editor-fold>//GEN-END:initComponents
300 
301  private void bnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnCancelActionPerformed
302  dispose();
303  }//GEN-LAST:event_bnCancelActionPerformed
304 
305  @Messages({"AddNewOrganizationDialog.bnOk.addFailed.text=Failed to add new organization."})
306  private void bnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnOKActionPerformed
307  EamOrganization newOrg = new EamOrganization(
308  tfOrganizationName.getText(),
309  tfPocName.getText(),
310  tfPocEmail.getText(),
311  tfPocPhone.getText());
312  try {
313  EamDb dbManager = EamDb.getInstance();
314  dbManager.newOrganization(newOrg);
315  hasChanged = true;
316  dispose();
317  } catch (EamDbException ex) {
318  lbWarningMsg.setText(Bundle.AddNewOrganizationDialog_bnOk_addFailed_text());
319  LOGGER.log(Level.SEVERE, "Failed adding new organization.", ex);
320  }
321  }//GEN-LAST:event_bnOKActionPerformed
322 
323 
324  // Variables declaration - do not modify//GEN-BEGIN:variables
325  private javax.swing.JButton bnCancel;
326  private javax.swing.JButton bnOK;
327  private javax.swing.JLabel lbOrganizationName;
328  private javax.swing.JLabel lbPocEmail;
329  private javax.swing.JLabel lbPocHeading;
330  private javax.swing.JLabel lbPocName;
331  private javax.swing.JLabel lbPocPhone;
332  private javax.swing.JLabel lbWarningMsg;
333  private javax.swing.JTextField tfOrganizationName;
334  private javax.swing.JTextField tfPocEmail;
335  private javax.swing.JTextField tfPocName;
336  private javax.swing.JTextField tfPocPhone;
337  // End of variables declaration//GEN-END:variables
338 }
static void addDocumentListeners(Collection< JTextField > textFields, TextBoxChangedListener listener)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Fri Sep 29 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.