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.WindowManager;
59 @SuppressWarnings(
"PMD.SingularField")
64 private static final long serialVersionUID = 1L;
70 private class DbChoiceRenderer extends JLabel implements ListCellRenderer<CentralRepoDbChoice>, Serializable {
72 private static final long serialVersionUID = 1L;
77 int index,
boolean isSelected,
boolean cellHasFocus) {
82 setEnabled(isDbChoiceSelectable(value));
103 @Messages({
"EamDbSettingsDialog.title.text=Central Repository Database Configuration",
104 "EamDbSettingsDialog.lbSingleUserSqLite.text=SQLite should only be used by one examiner at a time.",
105 "EamDbSettingsDialog.lbDatabaseType.text=Database Type :",
106 "EamDbSettingsDialog.fcDatabasePath.title=Select location for central_repository.db"})
108 super((JFrame) WindowManager.getDefault().getMainWindow(),
109 Bundle.EamDbSettingsDialog_title_text(),
112 textBoxes =
new ArrayList<>();
116 fcDatabasePath.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
117 fcDatabasePath.setAcceptAllFileFilterUsed(
false);
118 fcDatabasePath.setDialogTitle(Bundle.EamDbSettingsDialog_fcDatabasePath_title());
119 fcDatabasePath.setFileFilter(
new FileFilter() {
121 public boolean accept(File pathname) {
122 if (pathname.isDirectory()) {
129 public String getDescription() {
130 return "Directories and Central Repository databases";
134 setupDbChoice(initialMenuItem);
147 cbDatabaseType.setRenderer(DB_CHOICE_RENDERER);
148 changeDbSelection(toSelect);
162 @NbBundle.Messages({
"EamDbSettingsDialog.okButton.corruptDatabaseExists.title=Error Loading Central Repository Database",
163 "EamDbSettingsDialog.okButton.corruptDatabaseExists.message=Central Repository Database exists but is not the right format. Manually delete it or choose a different path (if applicable).",
164 "EamDbSettingsDialog.okButton.createDbDialog.title=Central Repository Database Does Not Exist",
165 "EamDbSettingsDialog.okButton.createDbDialog.message=Central Repository Database does not exist, would you like to create it?",
166 "EamDbSettingsDialog.okButton.databaseConnectionFailed.title=Central Repository Database Connection Failed",
167 "EamDbSettingsDialog.okButton.databaseConnectionFailed.message=Unable to connect to Central Repository Database. Please check your settings and try again.",
168 "EamDbSettingsDialog.okButton.createSQLiteDbError.message=Unable to create SQLite Central Repository Database, please ensure location exists and you have write permissions and try again.",
169 "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.",
170 "EamDbSettingsDialog.okButton.createDbError.title=Unable to Create Central Repository Database"})
173 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
174 Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_message(),
175 Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_title(),
176 JOptionPane.WARNING_MESSAGE);
179 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
180 Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_message(),
181 Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_title(),
182 JOptionPane.WARNING_MESSAGE);
184 promptCreateDatabase(manager, dialog);
202 if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
203 Bundle.EamDbSettingsDialog_okButton_createDbDialog_message(),
204 Bundle.EamDbSettingsDialog_okButton_createDbDialog_title(),
205 JOptionPane.YES_NO_OPTION)) {
210 onPromptStatusError(manager);
214 if (dialog != null) {
233 String errorMessage =
"";
237 errorMessage = Bundle.EamDbSettingsDialog_okButton_createPostgresDbError_message();
239 errorMessage = Bundle.EamDbSettingsDialog_okButton_createSQLiteDbError_message();
241 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
243 Bundle.EamDbSettingsDialog_okButton_createDbError_title(),
244 JOptionPane.WARNING_MESSAGE);
252 @SuppressWarnings(
"unchecked")
254 private
void initComponents() {
255 java.awt.GridBagConstraints gridBagConstraints;
257 fcDatabasePath =
new javax.swing.JFileChooser();
258 pnButtons =
new javax.swing.JPanel();
259 pnSQLiteSettings =
new javax.swing.JPanel();
260 lbDatabasePath =
new javax.swing.JLabel();
261 lbHostName =
new javax.swing.JLabel();
262 tbDbHostname =
new javax.swing.JTextField();
263 lbPort =
new javax.swing.JLabel();
264 tbDbPort =
new javax.swing.JTextField();
265 lbUserName =
new javax.swing.JLabel();
266 tbDbUsername =
new javax.swing.JTextField();
267 lbUserPassword =
new javax.swing.JLabel();
268 jpDbPassword =
new javax.swing.JPasswordField();
269 lbDatabaseType =
new javax.swing.JLabel();
270 lbDatabaseDesc =
new javax.swing.JLabel();
271 filler1 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 32767));
272 dataBaseFileScrollPane =
new javax.swing.JScrollPane();
273 dataBaseFileTextArea =
new javax.swing.JTextArea();
274 pathPanel =
new javax.swing.JPanel();
275 tfDatabasePath =
new javax.swing.JTextField();
276 bnDatabasePathFileOpen =
new javax.swing.JButton();
277 typePanel =
new javax.swing.JPanel();
278 lbSingleUserSqLite =
new javax.swing.JLabel();
279 cbDatabaseType =
new javax.swing.JComboBox<>();
280 bnCancel =
new javax.swing.JButton();
281 bnOk =
new javax.swing.JButton();
283 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
286 javax.swing.GroupLayout pnButtonsLayout =
new javax.swing.GroupLayout(pnButtons);
287 pnButtons.setLayout(pnButtonsLayout);
288 pnButtonsLayout.setHorizontalGroup(
289 pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
290 .addGap(0, 0, Short.MAX_VALUE)
292 pnButtonsLayout.setVerticalGroup(
293 pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
294 .addGap(0, 25, Short.MAX_VALUE)
297 pnSQLiteSettings.setBorder(javax.swing.BorderFactory.createEtchedBorder());
298 pnSQLiteSettings.setLayout(
new java.awt.GridBagLayout());
300 org.openide.awt.Mnemonics.setLocalizedText(lbDatabasePath,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabasePath.text"));
301 lbDatabasePath.setMaximumSize(
new java.awt.Dimension(191, 16));
302 lbDatabasePath.setPreferredSize(
new java.awt.Dimension(100, 14));
303 gridBagConstraints =
new java.awt.GridBagConstraints();
304 gridBagConstraints.gridx = 0;
305 gridBagConstraints.gridy = 1;
306 gridBagConstraints.gridwidth = 2;
307 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
308 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
309 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
310 pnSQLiteSettings.add(lbDatabasePath, gridBagConstraints);
312 org.openide.awt.Mnemonics.setLocalizedText(lbHostName,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbHostName.text"));
313 lbHostName.setMaximumSize(
new java.awt.Dimension(195, 16));
314 lbHostName.setPreferredSize(
new java.awt.Dimension(110, 14));
315 gridBagConstraints =
new java.awt.GridBagConstraints();
316 gridBagConstraints.gridx = 0;
317 gridBagConstraints.gridy = 3;
318 gridBagConstraints.gridwidth = 2;
319 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
320 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
321 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
322 pnSQLiteSettings.add(lbHostName, gridBagConstraints);
324 tbDbHostname.setPreferredSize(
new java.awt.Dimension(519, 20));
325 gridBagConstraints =
new java.awt.GridBagConstraints();
326 gridBagConstraints.gridx = 2;
327 gridBagConstraints.gridy = 3;
328 gridBagConstraints.gridheight = 2;
329 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
330 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
331 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 0, 6);
332 pnSQLiteSettings.add(tbDbHostname, gridBagConstraints);
334 org.openide.awt.Mnemonics.setLocalizedText(lbPort,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbPort.text"));
335 lbPort.setMaximumSize(
new java.awt.Dimension(132, 16));
336 lbPort.setPreferredSize(
new java.awt.Dimension(90, 14));
337 gridBagConstraints =
new java.awt.GridBagConstraints();
338 gridBagConstraints.gridx = 0;
339 gridBagConstraints.gridy = 5;
340 gridBagConstraints.gridwidth = 2;
341 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
342 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
343 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
344 pnSQLiteSettings.add(lbPort, gridBagConstraints);
346 tbDbPort.setPreferredSize(
new java.awt.Dimension(519, 20));
347 gridBagConstraints =
new java.awt.GridBagConstraints();
348 gridBagConstraints.gridx = 2;
349 gridBagConstraints.gridy = 5;
350 gridBagConstraints.gridheight = 2;
351 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
352 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
353 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 0, 6);
354 pnSQLiteSettings.add(tbDbPort, gridBagConstraints);
356 org.openide.awt.Mnemonics.setLocalizedText(lbUserName,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbUserName.text"));
357 lbUserName.setMaximumSize(
new java.awt.Dimension(172, 16));
358 lbUserName.setPreferredSize(
new java.awt.Dimension(100, 14));
359 gridBagConstraints =
new java.awt.GridBagConstraints();
360 gridBagConstraints.gridx = 0;
361 gridBagConstraints.gridy = 7;
362 gridBagConstraints.gridwidth = 2;
363 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
364 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
365 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
366 pnSQLiteSettings.add(lbUserName, gridBagConstraints);
368 tbDbUsername.setPreferredSize(
new java.awt.Dimension(519, 20));
369 gridBagConstraints =
new java.awt.GridBagConstraints();
370 gridBagConstraints.gridx = 2;
371 gridBagConstraints.gridy = 7;
372 gridBagConstraints.gridheight = 2;
373 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
374 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
375 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 0, 6);
376 pnSQLiteSettings.add(tbDbUsername, gridBagConstraints);
378 org.openide.awt.Mnemonics.setLocalizedText(lbUserPassword,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbUserPassword.text"));
379 lbUserPassword.setMaximumSize(
new java.awt.Dimension(194, 16));
380 lbUserPassword.setPreferredSize(
new java.awt.Dimension(110, 14));
381 gridBagConstraints =
new java.awt.GridBagConstraints();
382 gridBagConstraints.gridx = 0;
383 gridBagConstraints.gridy = 9;
384 gridBagConstraints.gridwidth = 2;
385 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
386 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
387 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
388 pnSQLiteSettings.add(lbUserPassword, gridBagConstraints);
390 jpDbPassword.setPreferredSize(
new java.awt.Dimension(519, 20));
391 gridBagConstraints =
new java.awt.GridBagConstraints();
392 gridBagConstraints.gridx = 2;
393 gridBagConstraints.gridy = 9;
394 gridBagConstraints.gridheight = 2;
395 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
396 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
397 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 0, 6);
398 pnSQLiteSettings.add(jpDbPassword, gridBagConstraints);
400 org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabaseType.text"));
401 lbDatabaseType.setMaximumSize(
new java.awt.Dimension(180, 14));
402 lbDatabaseType.setMinimumSize(
new java.awt.Dimension(80, 14));
403 lbDatabaseType.setPreferredSize(
new java.awt.Dimension(100, 14));
404 gridBagConstraints =
new java.awt.GridBagConstraints();
405 gridBagConstraints.gridx = 0;
406 gridBagConstraints.gridy = 0;
407 gridBagConstraints.gridwidth = 2;
408 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
409 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
410 gridBagConstraints.insets =
new java.awt.Insets(12, 14, 0, 0);
411 pnSQLiteSettings.add(lbDatabaseType, gridBagConstraints);
413 org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseDesc,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabaseDesc.text"));
414 lbDatabaseDesc.setMaximumSize(
new java.awt.Dimension(182, 16));
415 lbDatabaseDesc.setPreferredSize(
new java.awt.Dimension(100, 14));
416 gridBagConstraints =
new java.awt.GridBagConstraints();
417 gridBagConstraints.gridx = 0;
418 gridBagConstraints.gridy = 11;
419 gridBagConstraints.gridwidth = 2;
420 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
421 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
422 gridBagConstraints.insets =
new java.awt.Insets(7, 14, 0, 0);
423 pnSQLiteSettings.add(lbDatabaseDesc, gridBagConstraints);
424 gridBagConstraints =
new java.awt.GridBagConstraints();
425 gridBagConstraints.gridx = 0;
426 gridBagConstraints.gridy = 12;
427 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
428 pnSQLiteSettings.add(filler1, gridBagConstraints);
430 dataBaseFileScrollPane.setBorder(null);
432 dataBaseFileTextArea.setEditable(
false);
433 dataBaseFileTextArea.setBackground(
new java.awt.Color(240, 240, 240));
434 dataBaseFileTextArea.setColumns(20);
435 dataBaseFileTextArea.setLineWrap(
true);
436 dataBaseFileTextArea.setRows(3);
437 dataBaseFileScrollPane.setViewportView(dataBaseFileTextArea);
439 gridBagConstraints =
new java.awt.GridBagConstraints();
440 gridBagConstraints.gridx = 2;
441 gridBagConstraints.gridy = 11;
442 gridBagConstraints.gridheight = 3;
443 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
444 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
445 gridBagConstraints.weightx = 1.0;
446 gridBagConstraints.weighty = 1.0;
447 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 15, 6);
448 pnSQLiteSettings.add(dataBaseFileScrollPane, gridBagConstraints);
450 tfDatabasePath.setText(
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.tfDatabasePath.text"));
451 tfDatabasePath.setToolTipText(
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.tfDatabasePath.toolTipText"));
452 tfDatabasePath.setPreferredSize(
new java.awt.Dimension(420, 23));
454 org.openide.awt.Mnemonics.setLocalizedText(bnDatabasePathFileOpen,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnDatabasePathFileOpen.text"));
455 bnDatabasePathFileOpen.addActionListener(
new java.awt.event.ActionListener() {
456 public void actionPerformed(java.awt.event.ActionEvent evt) {
457 bnDatabasePathFileOpenActionPerformed(evt);
461 javax.swing.GroupLayout pathPanelLayout =
new javax.swing.GroupLayout(pathPanel);
462 pathPanel.setLayout(pathPanelLayout);
463 pathPanelLayout.setHorizontalGroup(
464 pathPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
465 .addGroup(pathPanelLayout.createSequentialGroup()
467 .addComponent(tfDatabasePath, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
468 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
469 .addComponent(bnDatabasePathFileOpen)
472 pathPanelLayout.setVerticalGroup(
473 pathPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
474 .addGroup(pathPanelLayout.createSequentialGroup()
476 .addGroup(pathPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
477 .addComponent(tfDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
478 .addComponent(bnDatabasePathFileOpen))
482 gridBagConstraints =
new java.awt.GridBagConstraints();
483 gridBagConstraints.gridx = 2;
484 gridBagConstraints.gridy = 1;
485 gridBagConstraints.gridheight = 2;
486 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
487 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
488 gridBagConstraints.insets =
new java.awt.Insets(7, 10, 0, 6);
489 pnSQLiteSettings.add(pathPanel, gridBagConstraints);
491 org.openide.awt.Mnemonics.setLocalizedText(lbSingleUserSqLite,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbSingleUserSqLite.text"));
492 lbSingleUserSqLite.setPreferredSize(
new java.awt.Dimension(381, 14));
495 cbDatabaseType.setPreferredSize(
new java.awt.Dimension(120, 20));
496 cbDatabaseType.addActionListener(
new java.awt.event.ActionListener() {
497 public void actionPerformed(java.awt.event.ActionEvent evt) {
498 cbDatabaseTypeActionPerformed(evt);
502 javax.swing.GroupLayout typePanelLayout =
new javax.swing.GroupLayout(typePanel);
503 typePanel.setLayout(typePanelLayout);
504 typePanelLayout.setHorizontalGroup(
505 typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
506 .addGroup(typePanelLayout.createSequentialGroup()
508 .addComponent(cbDatabaseType, 0, 210, Short.MAX_VALUE)
509 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
510 .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE)
513 typePanelLayout.setVerticalGroup(
514 typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
515 .addGroup(typePanelLayout.createSequentialGroup()
517 .addGroup(typePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
518 .addComponent(cbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
519 .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
523 gridBagConstraints =
new java.awt.GridBagConstraints();
524 gridBagConstraints.gridx = 2;
525 gridBagConstraints.gridy = 0;
526 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
527 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
528 gridBagConstraints.insets =
new java.awt.Insets(12, 10, 2, 0);
529 pnSQLiteSettings.add(typePanel, gridBagConstraints);
531 org.openide.awt.Mnemonics.setLocalizedText(bnCancel,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnCancel.text"));
532 bnCancel.setMaximumSize(
new java.awt.Dimension(79, 23));
533 bnCancel.setMinimumSize(
new java.awt.Dimension(79, 23));
534 bnCancel.setPreferredSize(
new java.awt.Dimension(79, 23));
535 bnCancel.addActionListener(
new java.awt.event.ActionListener() {
536 public void actionPerformed(java.awt.event.ActionEvent evt) {
537 bnCancelActionPerformed(evt);
541 org.openide.awt.Mnemonics.setLocalizedText(bnOk,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnOk.text"));
542 bnOk.addActionListener(
new java.awt.event.ActionListener() {
543 public void actionPerformed(java.awt.event.ActionEvent evt) {
544 bnOkActionPerformed(evt);
548 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
549 getContentPane().setLayout(layout);
550 layout.setHorizontalGroup(
551 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
552 .addGroup(layout.createSequentialGroup()
554 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
555 .addGroup(layout.createSequentialGroup()
556 .addComponent(pnButtons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
557 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
560 .addComponent(bnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
561 .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE))
565 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {bnCancel, bnOk});
567 layout.setVerticalGroup(
568 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
569 .addGroup(layout.createSequentialGroup()
571 .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
572 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
573 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
574 .addComponent(pnButtons, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
575 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
577 .addComponent(bnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
586 setTextBoxListeners();
589 updatePostgresFields(
false);
590 updateSqliteFields(
true);
592 updatePostgresFields(
true);
593 updateSqliteFields(
false);
595 updatePostgresFields(
false);
596 updateSqliteFields(
false);
603 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
607 @Messages({
"EamDbSettingsDialog.chooserPath.failedToGetDbPathMsg=Selected database path is invalid. Try again."})
610 if (fcDatabasePath.showOpenDialog(
this) == JFileChooser.APPROVE_OPTION) {
611 File databaseFile = fcDatabasePath.getSelectedFile();
612 if (databaseFile.isFile()) {
613 databaseFile = fcDatabasePath.getCurrentDirectory();
616 tfDatabasePath.setText(databaseFile.getCanonicalPath());
617 tfDatabasePath.setCaretPosition(tfDatabasePath.getText().length());
619 }
catch (IOException ex) {
620 logger.log(Level.SEVERE,
"Failed to get path of selected database file", ex);
625 @NbBundle.Messages({
"EamDbSettingsDialog.okButton.errorTitle.text=Restart Required.",
626 "EamDbSettingsDialog.okButton.errorMsg.text=Please restart Autopsy to begin using the new database platform.",
627 "EamDbSettingsDialog.okButton.connectionErrorMsg.text=Failed to connect to central repository database."})
629 if (testStatusAndCreate(
this, manager,
this)) {
646 return testStatusAndCreate(parent, manager, null);
663 parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
666 if (dialog != null) {
670 boolean testedOk = promptTestStatusWarnings(manager, dialog);
672 parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
679 SwingUtilities.invokeLater(() -> {
680 JOptionPane.showMessageDialog(parent,
681 Bundle.EamDbSettingsDialog_okButton_errorMsg_text(),
682 Bundle.EamDbSettingsDialog_okButton_errorTitle_text(),
683 JOptionPane.WARNING_MESSAGE);
686 parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
690 parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
712 changeDbSelection(selectedItem);
716 if (isDbChoiceSelectable(selectedItem)) {
718 cbDatabaseType.setSelectedItem(selectedItem);
723 customizeComponents();
728 dataBaseFileTextArea.setCaretPosition(dataBaseFileTextArea.getText().length());
735 lbDatabasePath.setVisible(isSqlite);
736 tfDatabasePath.setVisible(isSqlite);
737 lbDatabaseDesc.setVisible(isSqlite);
738 dataBaseFileTextArea.setVisible(isSqlite);
739 lbSingleUserSqLite.setVisible(isSqlite);
740 bnDatabasePathFileOpen.setVisible(isSqlite);
742 lbHostName.setVisible(isPostgres);
743 tbDbHostname.setVisible(isPostgres);
744 lbPort.setVisible(isPostgres);
745 tbDbPort.setVisible(isPostgres);
746 lbUserName.setVisible(isPostgres);
747 tbDbUsername.setVisible(isPostgres);
748 lbUserPassword.setVisible(isPostgres);
749 jpDbPassword.setVisible(isPostgres);
755 @Messages({
"EamDbSettingsDialog.textPrompt.hostnameOrIP=Hostname or IP Address",
756 "EamDbSettingsDialog.textPrompt.port=Port Number",
757 "EamDbSettingsDialog.textPrompt.dbName=Database Name",
758 "EamDbSettingsDialog.textPrompt.user=Database User",
759 "EamDbSettingsDialog.textPrompt.password=Database User's Password"})
761 Collection<TextPrompt> textPrompts =
new ArrayList<>();
762 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_hostnameOrIP(), tbDbHostname));
763 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_port(), tbDbPort));
764 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_user(), tbDbUsername));
765 configureTextPrompts(textPrompts);
770 tbDbHostname.setEnabled(enabled);
772 tbDbPort.setEnabled(enabled);
774 tbDbUsername.setEnabled(enabled);
776 jpDbPassword.setEnabled(enabled);
787 tfDatabasePath.setEnabled(enabled);
788 bnDatabasePathFileOpen.setEnabled(enabled);
795 textBoxes.add(tfDatabasePath);
796 textBoxes.add(tbDbHostname);
797 textBoxes.add(tbDbPort);
799 textBoxes.add(tbDbUsername);
800 textBoxes.add(jpDbPassword);
801 addDocumentListeners(textBoxes, textBoxChangedListener);
813 textPrompt.setForeground(Color.LIGHT_GRAY);
814 textPrompt.changeAlpha(alpha);
825 textFields.forEach((textField) -> {
826 textField.getDocument().addDocumentListener(listener);
836 @Messages({
"EamDbSettingsDialog.validation.incompleteFields=Fill in all values for the selected database."})
838 boolean result =
true;
840 result = !tbDbHostname.getText().trim().isEmpty()
841 && !tbDbPort.getText().trim().isEmpty()
843 && !tbDbUsername.getText().trim().isEmpty()
844 && 0 < jpDbPassword.getPassword().length;
846 result = !tfDatabasePath.getText().trim().isEmpty();
858 return databaseFieldsArePopulated()
859 && databaseSettingsAreValid();
868 return enableOkButton(checkFields());
877 @Messages({
"EamDbSettingsDialog.validation.finished=Click OK to save your database settings and return to the Options. Or select a different database type."})
880 bnOk.setEnabled(
true);
882 bnOk.setEnabled(
false);
896 tbDbHostname.getText().trim(),
897 tbDbPort.getText().trim(),
898 tbDbUsername.getText().trim(),
899 tfDatabasePath.getText().trim(),
900 new String(jpDbPassword.getPassword()));
941 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)
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()