19 package org.sleuthkit.autopsy.centralrepository.optionspanel;
21 import java.awt.Color;
22 import java.awt.Component;
23 import java.awt.Cursor;
24 import java.awt.HeadlessException;
26 import java.io.IOException;
27 import java.io.Serializable;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.Collection;
31 import java.util.logging.Level;
32 import javax.swing.JDialog;
33 import javax.swing.JFileChooser;
34 import javax.swing.JFrame;
35 import javax.swing.JLabel;
36 import javax.swing.JList;
37 import javax.swing.JOptionPane;
38 import javax.swing.JTextField;
39 import javax.swing.ListCellRenderer;
40 import javax.swing.SwingUtilities;
41 import javax.swing.event.DocumentEvent;
42 import javax.swing.event.DocumentListener;
43 import javax.swing.filechooser.FileFilter;
44 import org.openide.util.NbBundle;
45 import org.openide.util.NbBundle.Messages;
46 import org.openide.windows.TopComponent;
47 import org.openide.windows.WindowManager;
60 @SuppressWarnings(
"PMD.SingularField")
65 private static final long serialVersionUID = 1L;
71 private class DbChoiceRenderer extends JLabel implements ListCellRenderer<CentralRepoDbChoice>, Serializable {
73 private static final long serialVersionUID = 1L;
78 int index,
boolean isSelected,
boolean cellHasFocus) {
83 setEnabled(isDbChoiceSelectable(value));
104 @Messages({
"EamDbSettingsDialog.title.text=Central Repository Database Configuration",
105 "EamDbSettingsDialog.lbSingleUserSqLite.text=SQLite should only be used by one examiner at a time.",
106 "EamDbSettingsDialog.lbDatabaseType.text=Database Type :",
107 "EamDbSettingsDialog.fcDatabasePath.title=Select location for central_repository.db"})
109 super((JFrame) WindowManager.getDefault().getMainWindow(),
110 Bundle.EamDbSettingsDialog_title_text(),
113 textBoxes =
new ArrayList<>();
117 fcDatabasePath.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
118 fcDatabasePath.setAcceptAllFileFilterUsed(
false);
119 fcDatabasePath.setDialogTitle(Bundle.EamDbSettingsDialog_fcDatabasePath_title());
120 fcDatabasePath.setFileFilter(
new FileFilter() {
122 public boolean accept(File pathname) {
123 if (pathname.isDirectory()) {
130 public String getDescription() {
131 return "Directories and Central Repository databases";
135 setupDbChoice(initialMenuItem);
148 cbDatabaseType.setRenderer(DB_CHOICE_RENDERER);
149 changeDbSelection(toSelect);
163 @NbBundle.Messages({
"EamDbSettingsDialog.okButton.corruptDatabaseExists.title=Error Loading Central Repository Database",
164 "EamDbSettingsDialog.okButton.corruptDatabaseExists.message=Central Repository Database exists but is not the right format. Manually delete it or choose a different path (if applicable).",
165 "EamDbSettingsDialog.okButton.createDbDialog.title=Central Repository Database Does Not Exist",
166 "EamDbSettingsDialog.okButton.createDbDialog.message=Central Repository Database does not exist, would you like to create it?",
167 "EamDbSettingsDialog.okButton.databaseConnectionFailed.title=Central Repository Database Connection Failed",
168 "EamDbSettingsDialog.okButton.databaseConnectionFailed.message=Unable to connect to Central Repository Database. Please check your settings and try again.",
169 "EamDbSettingsDialog.okButton.createSQLiteDbError.message=Unable to create SQLite Central Repository Database, please ensure location exists and you have write permissions and try again.",
170 "EamDbSettingsDialog.okButton.createPostgresDbError.message=Unable to create Postgres Central Repository Database, please ensure address, port, and login credentials are correct for Postgres server and try again.",
171 "EamDbSettingsDialog.okButton.createDbError.title=Unable to Create Central Repository Database"})
174 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
175 Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_message(),
176 Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_title(),
177 JOptionPane.WARNING_MESSAGE);
180 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
181 Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_message(),
182 Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_title(),
183 JOptionPane.WARNING_MESSAGE);
185 promptCreateDatabase(manager, dialog);
203 if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
204 Bundle.EamDbSettingsDialog_okButton_createDbDialog_message(),
205 Bundle.EamDbSettingsDialog_okButton_createDbDialog_title(),
206 JOptionPane.YES_NO_OPTION)) {
211 onPromptStatusError(manager);
215 if (dialog != null) {
234 String errorMessage =
"";
238 errorMessage = Bundle.EamDbSettingsDialog_okButton_createPostgresDbError_message();
240 errorMessage = Bundle.EamDbSettingsDialog_okButton_createSQLiteDbError_message();
242 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
244 Bundle.EamDbSettingsDialog_okButton_createDbError_title(),
245 JOptionPane.WARNING_MESSAGE);
253 @SuppressWarnings(
"unchecked")
255 private
void initComponents() {
256 java.awt.GridBagConstraints gridBagConstraints;
258 fcDatabasePath =
new javax.swing.JFileChooser();
259 pnButtons =
new javax.swing.JPanel();
260 pnSQLiteSettings =
new javax.swing.JPanel();
261 lbDatabasePath =
new javax.swing.JLabel();
262 lbHostName =
new javax.swing.JLabel();
263 tbDbHostname =
new javax.swing.JTextField();
264 lbPort =
new javax.swing.JLabel();
265 tbDbPort =
new javax.swing.JTextField();
266 lbUserName =
new javax.swing.JLabel();
267 tbDbUsername =
new javax.swing.JTextField();
268 lbUserPassword =
new javax.swing.JLabel();
269 jpDbPassword =
new javax.swing.JPasswordField();
270 lbDatabaseType =
new javax.swing.JLabel();
271 lbDatabaseDesc =
new javax.swing.JLabel();
272 filler1 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 32767));
273 dataBaseFileScrollPane =
new javax.swing.JScrollPane();
274 dataBaseFileTextArea =
new javax.swing.JTextArea();
275 pathPanel =
new javax.swing.JPanel();
276 tfDatabasePath =
new javax.swing.JTextField();
277 bnDatabasePathFileOpen =
new javax.swing.JButton();
278 typePanel =
new javax.swing.JPanel();
279 lbSingleUserSqLite =
new javax.swing.JLabel();
280 cbDatabaseType =
new javax.swing.JComboBox<>();
281 bnCancel =
new javax.swing.JButton();
282 bnOk =
new javax.swing.JButton();
284 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
287 javax.swing.GroupLayout pnButtonsLayout =
new javax.swing.GroupLayout(pnButtons);
288 pnButtons.setLayout(pnButtonsLayout);
289 pnButtonsLayout.setHorizontalGroup(
290 pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
291 .addGap(0, 0, Short.MAX_VALUE)
293 pnButtonsLayout.setVerticalGroup(
294 pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
295 .addGap(0, 25, Short.MAX_VALUE)
298 pnSQLiteSettings.setBorder(javax.swing.BorderFactory.createEtchedBorder());
299 pnSQLiteSettings.setLayout(
new java.awt.GridBagLayout());
301 org.openide.awt.Mnemonics.setLocalizedText(lbDatabasePath,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabasePath.text"));
302 lbDatabasePath.setMaximumSize(
new java.awt.Dimension(191, 16));
303 lbDatabasePath.setPreferredSize(
new java.awt.Dimension(100, 14));
304 gridBagConstraints =
new java.awt.GridBagConstraints();
305 gridBagConstraints.gridx = 0;
306 gridBagConstraints.gridy = 1;
307 gridBagConstraints.gridwidth = 2;
308 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
309 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
310 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
311 pnSQLiteSettings.add(lbDatabasePath, gridBagConstraints);
313 org.openide.awt.Mnemonics.setLocalizedText(lbHostName,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbHostName.text"));
314 lbHostName.setMaximumSize(
new java.awt.Dimension(195, 16));
315 lbHostName.setPreferredSize(
new java.awt.Dimension(110, 14));
316 gridBagConstraints =
new java.awt.GridBagConstraints();
317 gridBagConstraints.gridx = 0;
318 gridBagConstraints.gridy = 3;
319 gridBagConstraints.gridwidth = 2;
320 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
321 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
322 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
323 pnSQLiteSettings.add(lbHostName, gridBagConstraints);
325 tbDbHostname.setPreferredSize(
new java.awt.Dimension(519, 20));
326 gridBagConstraints =
new java.awt.GridBagConstraints();
327 gridBagConstraints.gridx = 2;
328 gridBagConstraints.gridy = 3;
329 gridBagConstraints.gridheight = 2;
330 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
331 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
332 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 0, 6);
333 pnSQLiteSettings.add(tbDbHostname, gridBagConstraints);
335 org.openide.awt.Mnemonics.setLocalizedText(lbPort,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbPort.text"));
336 lbPort.setMaximumSize(
new java.awt.Dimension(132, 16));
337 lbPort.setPreferredSize(
new java.awt.Dimension(90, 14));
338 gridBagConstraints =
new java.awt.GridBagConstraints();
339 gridBagConstraints.gridx = 0;
340 gridBagConstraints.gridy = 5;
341 gridBagConstraints.gridwidth = 2;
342 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
343 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
344 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
345 pnSQLiteSettings.add(lbPort, gridBagConstraints);
347 tbDbPort.setPreferredSize(
new java.awt.Dimension(519, 20));
348 gridBagConstraints =
new java.awt.GridBagConstraints();
349 gridBagConstraints.gridx = 2;
350 gridBagConstraints.gridy = 5;
351 gridBagConstraints.gridheight = 2;
352 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
353 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
354 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 0, 6);
355 pnSQLiteSettings.add(tbDbPort, gridBagConstraints);
357 org.openide.awt.Mnemonics.setLocalizedText(lbUserName,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbUserName.text"));
358 lbUserName.setMaximumSize(
new java.awt.Dimension(172, 16));
359 lbUserName.setPreferredSize(
new java.awt.Dimension(100, 14));
360 gridBagConstraints =
new java.awt.GridBagConstraints();
361 gridBagConstraints.gridx = 0;
362 gridBagConstraints.gridy = 7;
363 gridBagConstraints.gridwidth = 2;
364 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
365 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
366 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
367 pnSQLiteSettings.add(lbUserName, gridBagConstraints);
369 tbDbUsername.setPreferredSize(
new java.awt.Dimension(519, 20));
370 gridBagConstraints =
new java.awt.GridBagConstraints();
371 gridBagConstraints.gridx = 2;
372 gridBagConstraints.gridy = 7;
373 gridBagConstraints.gridheight = 2;
374 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
375 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
376 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 0, 6);
377 pnSQLiteSettings.add(tbDbUsername, gridBagConstraints);
379 org.openide.awt.Mnemonics.setLocalizedText(lbUserPassword,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbUserPassword.text"));
380 lbUserPassword.setMaximumSize(
new java.awt.Dimension(194, 16));
381 lbUserPassword.setPreferredSize(
new java.awt.Dimension(110, 14));
382 gridBagConstraints =
new java.awt.GridBagConstraints();
383 gridBagConstraints.gridx = 0;
384 gridBagConstraints.gridy = 9;
385 gridBagConstraints.gridwidth = 2;
386 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
387 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
388 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
389 pnSQLiteSettings.add(lbUserPassword, gridBagConstraints);
391 jpDbPassword.setPreferredSize(
new java.awt.Dimension(519, 20));
392 gridBagConstraints =
new java.awt.GridBagConstraints();
393 gridBagConstraints.gridx = 2;
394 gridBagConstraints.gridy = 9;
395 gridBagConstraints.gridheight = 2;
396 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
397 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
398 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 0, 6);
399 pnSQLiteSettings.add(jpDbPassword, gridBagConstraints);
401 org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabaseType.text"));
402 lbDatabaseType.setMaximumSize(
new java.awt.Dimension(180, 14));
403 lbDatabaseType.setMinimumSize(
new java.awt.Dimension(80, 14));
404 lbDatabaseType.setPreferredSize(
new java.awt.Dimension(100, 14));
405 gridBagConstraints =
new java.awt.GridBagConstraints();
406 gridBagConstraints.gridx = 0;
407 gridBagConstraints.gridy = 0;
408 gridBagConstraints.gridwidth = 2;
409 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
410 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
411 gridBagConstraints.insets =
new java.awt.Insets(12, 14, 0, 0);
412 pnSQLiteSettings.add(lbDatabaseType, gridBagConstraints);
414 org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseDesc,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabaseDesc.text"));
415 lbDatabaseDesc.setMaximumSize(
new java.awt.Dimension(182, 16));
416 lbDatabaseDesc.setPreferredSize(
new java.awt.Dimension(100, 14));
417 gridBagConstraints =
new java.awt.GridBagConstraints();
418 gridBagConstraints.gridx = 0;
419 gridBagConstraints.gridy = 11;
420 gridBagConstraints.gridwidth = 2;
421 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
422 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
423 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
424 pnSQLiteSettings.add(lbDatabaseDesc, gridBagConstraints);
425 gridBagConstraints =
new java.awt.GridBagConstraints();
426 gridBagConstraints.gridx = 0;
427 gridBagConstraints.gridy = 12;
428 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
429 pnSQLiteSettings.add(filler1, gridBagConstraints);
431 dataBaseFileScrollPane.setBorder(null);
433 dataBaseFileTextArea.setEditable(
false);
434 dataBaseFileTextArea.setBackground(
new java.awt.Color(240, 240, 240));
435 dataBaseFileTextArea.setColumns(20);
436 dataBaseFileTextArea.setLineWrap(
true);
437 dataBaseFileTextArea.setRows(3);
438 dataBaseFileScrollPane.setViewportView(dataBaseFileTextArea);
440 gridBagConstraints =
new java.awt.GridBagConstraints();
441 gridBagConstraints.gridx = 2;
442 gridBagConstraints.gridy = 11;
443 gridBagConstraints.gridheight = 3;
444 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
445 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
446 gridBagConstraints.weightx = 1.0;
447 gridBagConstraints.weighty = 1.0;
448 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 15, 6);
449 pnSQLiteSettings.add(dataBaseFileScrollPane, gridBagConstraints);
451 tfDatabasePath.setText(
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.tfDatabasePath.text"));
452 tfDatabasePath.setToolTipText(
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.tfDatabasePath.toolTipText"));
453 tfDatabasePath.setPreferredSize(
new java.awt.Dimension(420, 23));
455 org.openide.awt.Mnemonics.setLocalizedText(bnDatabasePathFileOpen,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnDatabasePathFileOpen.text"));
456 bnDatabasePathFileOpen.addActionListener(
new java.awt.event.ActionListener() {
457 public void actionPerformed(java.awt.event.ActionEvent evt) {
458 bnDatabasePathFileOpenActionPerformed(evt);
462 javax.swing.GroupLayout pathPanelLayout =
new javax.swing.GroupLayout(pathPanel);
463 pathPanel.setLayout(pathPanelLayout);
464 pathPanelLayout.setHorizontalGroup(
465 pathPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
466 .addGroup(pathPanelLayout.createSequentialGroup()
468 .addComponent(tfDatabasePath, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
469 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
470 .addComponent(bnDatabasePathFileOpen)
473 pathPanelLayout.setVerticalGroup(
474 pathPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
475 .addGroup(pathPanelLayout.createSequentialGroup()
477 .addGroup(pathPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
478 .addComponent(tfDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
479 .addComponent(bnDatabasePathFileOpen))
483 gridBagConstraints =
new java.awt.GridBagConstraints();
484 gridBagConstraints.gridx = 2;
485 gridBagConstraints.gridy = 1;
486 gridBagConstraints.gridheight = 2;
487 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
488 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
489 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 0, 6);
490 pnSQLiteSettings.add(pathPanel, gridBagConstraints);
492 org.openide.awt.Mnemonics.setLocalizedText(lbSingleUserSqLite,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbSingleUserSqLite.text"));
493 lbSingleUserSqLite.setPreferredSize(
new java.awt.Dimension(381, 14));
496 cbDatabaseType.setPreferredSize(
new java.awt.Dimension(120, 20));
497 cbDatabaseType.addActionListener(
new java.awt.event.ActionListener() {
498 public void actionPerformed(java.awt.event.ActionEvent evt) {
499 cbDatabaseTypeActionPerformed(evt);
503 javax.swing.GroupLayout typePanelLayout =
new javax.swing.GroupLayout(typePanel);
504 typePanel.setLayout(typePanelLayout);
505 typePanelLayout.setHorizontalGroup(
506 typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
507 .addGroup(typePanelLayout.createSequentialGroup()
509 .addComponent(cbDatabaseType, 0, 210, Short.MAX_VALUE)
510 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
511 .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
514 typePanelLayout.setVerticalGroup(
515 typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
516 .addGroup(typePanelLayout.createSequentialGroup()
518 .addGroup(typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
519 .addComponent(cbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
520 .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
524 gridBagConstraints =
new java.awt.GridBagConstraints();
525 gridBagConstraints.gridx = 2;
526 gridBagConstraints.gridy = 0;
527 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
528 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
529 gridBagConstraints.insets =
new java.awt.Insets(12, 10, 2, 0);
530 pnSQLiteSettings.add(typePanel, gridBagConstraints);
532 org.openide.awt.Mnemonics.setLocalizedText(bnCancel,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnCancel.text"));
533 bnCancel.setMaximumSize(
new java.awt.Dimension(79, 23));
534 bnCancel.setMinimumSize(
new java.awt.Dimension(79, 23));
535 bnCancel.setPreferredSize(
new java.awt.Dimension(79, 23));
536 bnCancel.addActionListener(
new java.awt.event.ActionListener() {
537 public void actionPerformed(java.awt.event.ActionEvent evt) {
538 bnCancelActionPerformed(evt);
542 org.openide.awt.Mnemonics.setLocalizedText(bnOk,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnOk.text"));
543 bnOk.addActionListener(
new java.awt.event.ActionListener() {
544 public void actionPerformed(java.awt.event.ActionEvent evt) {
545 bnOkActionPerformed(evt);
549 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
550 getContentPane().setLayout(layout);
551 layout.setHorizontalGroup(
552 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
553 .addGroup(layout.createSequentialGroup()
555 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
556 .addGroup(layout.createSequentialGroup()
557 .addComponent(pnButtons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
558 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
561 .addComponent(bnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
562 .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE))
566 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {bnCancel, bnOk});
568 layout.setVerticalGroup(
569 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
570 .addGroup(layout.createSequentialGroup()
572 .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
573 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
574 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
575 .addComponent(pnButtons, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
576 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
578 .addComponent(bnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
587 setTextBoxListeners();
590 updatePostgresFields(
false);
591 updateSqliteFields(
true);
593 updatePostgresFields(
true);
594 updateSqliteFields(
false);
596 updatePostgresFields(
false);
597 updateSqliteFields(
false);
604 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
608 @Messages({
"EamDbSettingsDialog.chooserPath.failedToGetDbPathMsg=Selected database path is invalid. Try again."})
611 if (fcDatabasePath.showOpenDialog(
this) == JFileChooser.APPROVE_OPTION) {
612 File databaseFile = fcDatabasePath.getSelectedFile();
613 if (databaseFile.isFile()) {
614 databaseFile = fcDatabasePath.getCurrentDirectory();
617 tfDatabasePath.setText(databaseFile.getCanonicalPath());
618 tfDatabasePath.setCaretPosition(tfDatabasePath.getText().length());
620 }
catch (IOException ex) {
621 logger.log(Level.SEVERE,
"Failed to get path of selected database file", ex);
626 @NbBundle.Messages({
"EamDbSettingsDialog.okButton.errorTitle.text=Restart Required.",
627 "EamDbSettingsDialog.okButton.errorMsg.text=Please restart Autopsy to begin using the new database platform.",
628 "EamDbSettingsDialog.okButton.connectionErrorMsg.text=Failed to connect to central repository database."})
630 if (testStatusAndCreate(
this, manager,
this)) {
647 return testStatusAndCreate(parent, manager, null);
664 closePersonasTopComponent();
666 parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
669 if (dialog != null) {
673 boolean testedOk = promptTestStatusWarnings(manager, dialog);
675 parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
682 SwingUtilities.invokeLater(() -> {
683 JOptionPane.showMessageDialog(parent,
684 Bundle.EamDbSettingsDialog_okButton_errorMsg_text(),
685 Bundle.EamDbSettingsDialog_okButton_errorTitle_text(),
686 JOptionPane.WARNING_MESSAGE);
689 parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
693 parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
703 SwingUtilities.invokeLater(() -> {
704 TopComponent personasWindow = WindowManager.getDefault().findTopComponent(
"PersonasTopComponent");
705 if (personasWindow != null && personasWindow.isOpened()) {
706 personasWindow.close();
730 changeDbSelection(selectedItem);
734 if (isDbChoiceSelectable(selectedItem)) {
736 cbDatabaseType.setSelectedItem(selectedItem);
741 customizeComponents();
746 dataBaseFileTextArea.setCaretPosition(dataBaseFileTextArea.getText().length());
753 lbDatabasePath.setVisible(isSqlite);
754 tfDatabasePath.setVisible(isSqlite);
755 lbDatabaseDesc.setVisible(isSqlite);
756 dataBaseFileTextArea.setVisible(isSqlite);
757 lbSingleUserSqLite.setVisible(isSqlite);
758 bnDatabasePathFileOpen.setVisible(isSqlite);
760 lbHostName.setVisible(isPostgres);
761 tbDbHostname.setVisible(isPostgres);
762 lbPort.setVisible(isPostgres);
763 tbDbPort.setVisible(isPostgres);
764 lbUserName.setVisible(isPostgres);
765 tbDbUsername.setVisible(isPostgres);
766 lbUserPassword.setVisible(isPostgres);
767 jpDbPassword.setVisible(isPostgres);
773 @Messages({
"EamDbSettingsDialog.textPrompt.hostnameOrIP=Hostname or IP Address",
774 "EamDbSettingsDialog.textPrompt.port=Port Number",
775 "EamDbSettingsDialog.textPrompt.dbName=Database Name",
776 "EamDbSettingsDialog.textPrompt.user=Database User",
777 "EamDbSettingsDialog.textPrompt.password=Database User's Password"})
779 Collection<TextPrompt> textPrompts =
new ArrayList<>();
780 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_hostnameOrIP(), tbDbHostname));
781 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_port(), tbDbPort));
782 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_user(), tbDbUsername));
783 configureTextPrompts(textPrompts);
788 tbDbHostname.setEnabled(enabled);
790 tbDbPort.setEnabled(enabled);
792 tbDbUsername.setEnabled(enabled);
794 jpDbPassword.setEnabled(enabled);
805 tfDatabasePath.setEnabled(enabled);
806 bnDatabasePathFileOpen.setEnabled(enabled);
813 textBoxes.add(tfDatabasePath);
814 textBoxes.add(tbDbHostname);
815 textBoxes.add(tbDbPort);
817 textBoxes.add(tbDbUsername);
818 textBoxes.add(jpDbPassword);
819 addDocumentListeners(textBoxes, textBoxChangedListener);
831 textPrompt.setForeground(Color.LIGHT_GRAY);
832 textPrompt.changeAlpha(alpha);
843 textFields.forEach((textField) -> {
844 textField.getDocument().addDocumentListener(listener);
854 @Messages({
"EamDbSettingsDialog.validation.incompleteFields=Fill in all values for the selected database."})
856 boolean result =
true;
858 result = !tbDbHostname.getText().trim().isEmpty()
859 && !tbDbPort.getText().trim().isEmpty()
861 && !tbDbUsername.getText().trim().isEmpty()
862 && 0 < jpDbPassword.getPassword().length;
864 result = !tfDatabasePath.getText().trim().isEmpty();
876 return databaseFieldsArePopulated()
877 && databaseSettingsAreValid();
886 return enableOkButton(checkFields());
895 @Messages({
"EamDbSettingsDialog.validation.finished=Click OK to save your database settings and return to the Options. Or select a different database type."})
898 bnOk.setEnabled(
true);
900 bnOk.setEnabled(
false);
914 tbDbHostname.getText().trim(),
915 tbDbPort.getText().trim(),
916 tbDbUsername.getText().trim(),
917 tfDatabasePath.getText().trim(),
918 new String(jpDbPassword.getPassword()));
959 private javax.swing.JButton
bnOk;
void setupDbChoice(CentralRepoDbChoice initialMenuItem)
CentralRepoPlatforms getDbPlatform()
DatabaseTestResult getStatus()
DatabaseTestResult testStatus()
javax.swing.JPasswordField jpDbPassword
boolean isDbChoiceSelectable(CentralRepoDbChoice item)
static void onPromptStatusError(CentralRepoDbManager manager1)
javax.swing.JLabel lbHostName
staticfinal CentralRepoDbChoice[] DB_CHOICES
SqliteCentralRepoSettings getDbSettingsSqlite()
javax.swing.JTextField tbDbUsername
javax.swing.JTextField tbDbPort
javax.swing.JPanel pnButtons
javax.swing.JButton bnCancel
static boolean testStatusAndCreate(Component parent, CentralRepoDbManager manager, EamDbSettingsDialog dialog)
void displayDatabaseSettings(CentralRepoDbChoice choice)
void setTextBoxListeners()
void bnDatabasePathFileOpenActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JLabel lbPort
Component getListCellRendererComponent(JList<?extends CentralRepoDbChoice > list, CentralRepoDbChoice value, int index, boolean isSelected, boolean cellHasFocus)
static boolean isPostgresMultiuserAllowed()
javax.swing.JFileChooser fcDatabasePath
javax.swing.JPanel pnSQLiteSettings
void removeUpdate(DocumentEvent e)
static void addDocumentListeners(Collection< JTextField > textFields, TextBoxChangedListener listener)
void updatePostgresFields(boolean enabled)
void saveNewCentralRepo()
static boolean promptTestStatusWarnings(CentralRepoDbManager manager, EamDbSettingsDialog dialog)
javax.swing.JButton bnDatabasePathFileOpen
EamDbSettingsDialog(CentralRepoDbChoice initialMenuItem)
void bnOkActionPerformed(java.awt.event.ActionEvent evt)
void changedUpdate(DocumentEvent e)
boolean databaseSettingsAreValid()
boolean testDatabaseSettingsAreValid(String tbDbHostname, String tbDbPort, String tbDbUsername, String tfDatabasePath, String jpDbPassword)
void bnCancelActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JPanel pathPanel
javax.swing.JLabel lbDatabaseDesc
javax.swing.Box.Filler filler1
final Collection< JTextField > textBoxes
static void configureTextPrompts(Collection< TextPrompt > textPrompts)
static void closePersonasTopComponent()
javax.swing.JScrollPane dataBaseFileScrollPane
void updateSqliteFields(boolean enabled)
CentralRepoDbChoice getSelectedDbChoice()
void insertUpdate(DocumentEvent e)
javax.swing.JLabel lbUserPassword
PostgresCentralRepoSettings getDbSettingsPostgres()
boolean wasConfigurationChanged()
boolean databaseFieldsArePopulated()
javax.swing.JLabel lbUserName
javax.swing.JLabel lbDatabasePath
void cbDatabaseTypeActionPerformed(java.awt.event.ActionEvent evt)
boolean enableOkButton(boolean isValidInput)
javax.swing.JLabel lbSingleUserSqLite
static boolean promptCreateDatabase(CentralRepoDbManager manager, EamDbSettingsDialog dialog)
synchronized static Logger getLogger(String name)
javax.swing.JTextField tbDbHostname
javax.swing.JPanel typePanel
static boolean testStatusAndCreate(Component parent, CentralRepoDbManager manager)
final TextBoxChangedListener textBoxChangedListener
javax.swing.JComboBox< org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbChoice > cbDatabaseType
static final String DEFAULT_DBNAME
void setSelctedDbChoice(CentralRepoDbChoice newSelected)
boolean wasConfigurationChanged()
javax.swing.JLabel lbDatabaseType
javax.swing.JTextArea dataBaseFileTextArea
void changeDbSelection(CentralRepoDbChoice selectedItem)
javax.swing.JTextField tfDatabasePath
void customizeComponents()