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.netbeans.spi.options.OptionsPanelController;
45 import org.openide.util.NbBundle;
46 import org.openide.util.NbBundle.Messages;
47 import org.openide.windows.WindowManager;
60 @SuppressWarnings(
"PMD.SingularField")
65 private static final long serialVersionUID = 1L;
70 private class DbChoiceRenderer extends JLabel implements ListCellRenderer<CentralRepoDbChoice>, Serializable {
71 private static final long serialVersionUID = 1L;
76 int index,
boolean isSelected,
boolean cellHasFocus) {
81 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);
149 cbDatabaseType.setRenderer(DB_CHOICE_RENDERER);
150 changeDbSelection(toSelect);
161 @NbBundle.Messages({
"EamDbSettingsDialog.okButton.corruptDatabaseExists.title=Error Loading Central Repository Database",
162 "EamDbSettingsDialog.okButton.corruptDatabaseExists.message=Central Repository Database exists but is not the right format. Manually delete it or choose a different path (if applicable).",
163 "EamDbSettingsDialog.okButton.createDbDialog.title=Central Repository Database Does Not Exist",
164 "EamDbSettingsDialog.okButton.createDbDialog.message=Central Repository Database does not exist, would you like to create it?",
165 "EamDbSettingsDialog.okButton.databaseConnectionFailed.title=Central Repository Database Connection Failed",
166 "EamDbSettingsDialog.okButton.databaseConnectionFailed.message=Unable to connect to Central Repository Database. Please check your settings and try again.",
167 "EamDbSettingsDialog.okButton.createSQLiteDbError.message=Unable to create SQLite Central Repository Database, please ensure location exists and you have write permissions and try again.",
168 "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.",
169 "EamDbSettingsDialog.okButton.createDbError.title=Unable to Create Central Repository Database"})
172 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
173 Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_message(),
174 Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_title(),
175 JOptionPane.WARNING_MESSAGE);
178 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
179 Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_message(),
180 Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_title(),
181 JOptionPane.WARNING_MESSAGE);
183 promptCreateDatabase(manager, dialog);
201 if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
202 Bundle.EamDbSettingsDialog_okButton_createDbDialog_message(),
203 Bundle.EamDbSettingsDialog_okButton_createDbDialog_title(),
204 JOptionPane.YES_NO_OPTION)) {
209 onPromptStatusError(manager);
213 if (dialog != null) {
230 String errorMessage =
"";
234 errorMessage = Bundle.EamDbSettingsDialog_okButton_createPostgresDbError_message();
236 errorMessage = Bundle.EamDbSettingsDialog_okButton_createSQLiteDbError_message();
238 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
240 Bundle.EamDbSettingsDialog_okButton_createDbError_title(),
241 JOptionPane.WARNING_MESSAGE);
250 @SuppressWarnings(
"unchecked")
252 private
void initComponents() {
254 fcDatabasePath =
new javax.swing.JFileChooser();
255 pnButtons =
new javax.swing.JPanel();
256 bnCancel =
new javax.swing.JButton();
257 bnOk =
new javax.swing.JButton();
258 pnSQLiteSettings =
new javax.swing.JPanel();
259 lbDatabasePath =
new javax.swing.JLabel();
260 tfDatabasePath =
new javax.swing.JTextField();
261 bnDatabasePathFileOpen =
new javax.swing.JButton();
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 cbDatabaseType =
new javax.swing.JComboBox<>();
271 lbSingleUserSqLite =
new javax.swing.JLabel();
272 lbDatabaseType =
new javax.swing.JLabel();
273 lbDatabaseDesc =
new javax.swing.JLabel();
274 filler1 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 32767));
275 dataBaseFileScrollPane =
new javax.swing.JScrollPane();
276 dataBaseFileTextArea =
new javax.swing.JTextArea();
278 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
281 org.openide.awt.Mnemonics.setLocalizedText(bnCancel,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnCancel.text"));
282 bnCancel.setMaximumSize(
new java.awt.Dimension(79, 23));
283 bnCancel.setMinimumSize(
new java.awt.Dimension(79, 23));
284 bnCancel.setPreferredSize(
new java.awt.Dimension(79, 23));
285 bnCancel.addActionListener(
new java.awt.event.ActionListener() {
286 public void actionPerformed(java.awt.event.ActionEvent evt) {
287 bnCancelActionPerformed(evt);
291 org.openide.awt.Mnemonics.setLocalizedText(bnOk,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnOk.text"));
292 bnOk.addActionListener(
new java.awt.event.ActionListener() {
293 public void actionPerformed(java.awt.event.ActionEvent evt) {
294 bnOkActionPerformed(evt);
298 javax.swing.GroupLayout pnButtonsLayout =
new javax.swing.GroupLayout(pnButtons);
299 pnButtons.setLayout(pnButtonsLayout);
300 pnButtonsLayout.setHorizontalGroup(
301 pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302 .addGroup(pnButtonsLayout.createSequentialGroup()
303 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
306 .addComponent(bnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
310 pnButtonsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {bnCancel, bnOk});
312 pnButtonsLayout.setVerticalGroup(
313 pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
314 .addGroup(pnButtonsLayout.createSequentialGroup()
316 .addGroup(pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
318 .addComponent(bnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
322 pnSQLiteSettings.setBorder(javax.swing.BorderFactory.createEtchedBorder());
324 org.openide.awt.Mnemonics.setLocalizedText(lbDatabasePath,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabasePath.text"));
325 lbDatabasePath.setPreferredSize(
new java.awt.Dimension(80, 14));
327 tfDatabasePath.setText(
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.tfDatabasePath.text"));
328 tfDatabasePath.setToolTipText(
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.tfDatabasePath.toolTipText"));
329 tfDatabasePath.setPreferredSize(
new java.awt.Dimension(420, 23));
331 org.openide.awt.Mnemonics.setLocalizedText(bnDatabasePathFileOpen,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnDatabasePathFileOpen.text"));
332 bnDatabasePathFileOpen.addActionListener(
new java.awt.event.ActionListener() {
333 public void actionPerformed(java.awt.event.ActionEvent evt) {
334 bnDatabasePathFileOpenActionPerformed(evt);
338 org.openide.awt.Mnemonics.setLocalizedText(lbHostName,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbHostName.text"));
339 lbHostName.setPreferredSize(
new java.awt.Dimension(80, 14));
341 tbDbHostname.setPreferredSize(
new java.awt.Dimension(509, 20));
343 org.openide.awt.Mnemonics.setLocalizedText(lbPort,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbPort.text"));
344 lbPort.setPreferredSize(
new java.awt.Dimension(80, 14));
346 tbDbPort.setPreferredSize(
new java.awt.Dimension(509, 20));
348 org.openide.awt.Mnemonics.setLocalizedText(lbUserName,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbUserName.text"));
349 lbUserName.setPreferredSize(
new java.awt.Dimension(80, 14));
351 tbDbUsername.setPreferredSize(
new java.awt.Dimension(509, 20));
353 org.openide.awt.Mnemonics.setLocalizedText(lbUserPassword,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbUserPassword.text"));
354 lbUserPassword.setPreferredSize(
new java.awt.Dimension(80, 14));
356 jpDbPassword.setPreferredSize(
new java.awt.Dimension(509, 20));
359 cbDatabaseType.setPreferredSize(
new java.awt.Dimension(120, 20));
360 cbDatabaseType.addActionListener(
new java.awt.event.ActionListener() {
361 public void actionPerformed(java.awt.event.ActionEvent evt) {
362 cbDatabaseTypeActionPerformed(evt);
366 org.openide.awt.Mnemonics.setLocalizedText(lbSingleUserSqLite,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbSingleUserSqLite.text"));
367 lbSingleUserSqLite.setPreferredSize(
new java.awt.Dimension(381, 14));
369 org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabaseType.text"));
370 lbDatabaseType.setMaximumSize(
new java.awt.Dimension(80, 14));
371 lbDatabaseType.setMinimumSize(
new java.awt.Dimension(80, 14));
372 lbDatabaseType.setPreferredSize(
new java.awt.Dimension(80, 14));
374 org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseDesc,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabaseDesc.text"));
375 lbDatabaseDesc.setPreferredSize(
new java.awt.Dimension(80, 14));
377 dataBaseFileScrollPane.setBorder(null);
379 dataBaseFileTextArea.setEditable(
false);
380 dataBaseFileTextArea.setBackground(
new java.awt.Color(240, 240, 240));
381 dataBaseFileTextArea.setColumns(20);
382 dataBaseFileTextArea.setLineWrap(
true);
383 dataBaseFileTextArea.setRows(3);
384 dataBaseFileScrollPane.setViewportView(dataBaseFileTextArea);
386 javax.swing.GroupLayout pnSQLiteSettingsLayout =
new javax.swing.GroupLayout(pnSQLiteSettings);
387 pnSQLiteSettings.setLayout(pnSQLiteSettingsLayout);
388 pnSQLiteSettingsLayout.setHorizontalGroup(
389 pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
390 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
392 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
393 .addComponent(lbHostName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
394 .addComponent(lbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
395 .addComponent(lbDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
396 .addComponent(lbUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
397 .addComponent(lbPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
398 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
399 .addComponent(lbDatabaseDesc, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
400 .addComponent(lbUserPassword, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
402 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
403 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
404 .addComponent(tfDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
405 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
406 .addComponent(bnDatabasePathFileOpen))
407 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
408 .addComponent(cbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
409 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
410 .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE))
411 .addComponent(jpDbPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
412 .addComponent(tbDbUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
413 .addComponent(tbDbPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
414 .addComponent(tbDbHostname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
415 .addComponent(dataBaseFileScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 509, javax.swing.GroupLayout.PREFERRED_SIZE))
417 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
419 .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
420 .addGap(0, 0, Short.MAX_VALUE))
422 pnSQLiteSettingsLayout.setVerticalGroup(
423 pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
424 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
426 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
427 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
428 .addComponent(cbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
429 .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
430 .addComponent(lbDatabaseType, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
431 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
432 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
433 .addComponent(lbDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
434 .addComponent(tfDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
435 .addComponent(bnDatabasePathFileOpen))
436 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
437 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
438 .addComponent(tbDbHostname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
439 .addComponent(lbHostName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
440 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
441 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
442 .addComponent(tbDbPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
443 .addComponent(lbPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
444 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
445 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
446 .addComponent(tbDbUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
447 .addComponent(lbUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
448 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
449 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
450 .addComponent(jpDbPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
451 .addComponent(lbUserPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
452 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
453 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
454 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
455 .addComponent(lbDatabaseDesc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
457 .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
458 .addComponent(dataBaseFileScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
462 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
463 getContentPane().setLayout(layout);
464 layout.setHorizontalGroup(
465 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
466 .addGroup(layout.createSequentialGroup()
468 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
469 .addComponent(pnButtons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
470 .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
473 layout.setVerticalGroup(
474 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
475 .addGroup(layout.createSequentialGroup()
477 .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
478 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
479 .addComponent(pnButtons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
488 setTextBoxListeners();
491 updatePostgresFields(
false);
492 updateSqliteFields(
true);
495 updatePostgresFields(
true);
496 updateSqliteFields(
false);
499 updatePostgresFields(
false);
500 updateSqliteFields(
false);
507 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
511 @Messages({
"EamDbSettingsDialog.chooserPath.failedToGetDbPathMsg=Selected database path is invalid. Try again."})
514 if (fcDatabasePath.showOpenDialog(
this) == JFileChooser.APPROVE_OPTION) {
515 File databaseFile = fcDatabasePath.getSelectedFile();
516 if (databaseFile.isFile()) {
517 databaseFile = fcDatabasePath.getCurrentDirectory();
520 tfDatabasePath.setText(databaseFile.getCanonicalPath());
521 tfDatabasePath.setCaretPosition(tfDatabasePath.getText().length());
523 }
catch (IOException ex) {
524 logger.log(Level.SEVERE,
"Failed to get path of selected database file", ex);
529 @NbBundle.Messages({
"EamDbSettingsDialog.okButton.errorTitle.text=Restart Required.",
530 "EamDbSettingsDialog.okButton.errorMsg.text=Please restart Autopsy to begin using the new database platform.",
531 "EamDbSettingsDialog.okButton.connectionErrorMsg.text=Failed to connect to central repository database."})
533 if (testStatusAndCreate(
this, manager,
this))
545 return testStatusAndCreate(parent, manager, null);
557 parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
563 boolean testedOk = promptTestStatusWarnings(manager, dialog);
565 parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
573 SwingUtilities.invokeLater(() -> {
574 JOptionPane.showMessageDialog(parent,
575 Bundle.EamDbSettingsDialog_okButton_errorMsg_text(),
576 Bundle.EamDbSettingsDialog_okButton_errorTitle_text(),
577 JOptionPane.WARNING_MESSAGE);
580 parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
584 parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
607 changeDbSelection(selectedItem);
611 if (isDbChoiceSelectable(selectedItem)) {
613 cbDatabaseType.setSelectedItem(selectedItem);
619 customizeComponents();
624 dataBaseFileTextArea.setCaretPosition(dataBaseFileTextArea.getText().length());
631 lbDatabasePath.setVisible(isSqlite);
632 tfDatabasePath.setVisible(isSqlite);
633 lbDatabaseDesc.setVisible(isSqlite);
634 dataBaseFileTextArea.setVisible(isSqlite);
635 lbSingleUserSqLite.setVisible(isSqlite);
636 bnDatabasePathFileOpen.setVisible(isSqlite);
638 lbHostName.setVisible(isPostgres);
639 tbDbHostname.setVisible(isPostgres);
640 lbPort.setVisible(isPostgres);
641 tbDbPort.setVisible(isPostgres);
642 lbUserName.setVisible(isPostgres);
643 tbDbUsername.setVisible(isPostgres);
644 lbUserPassword.setVisible(isPostgres);
645 jpDbPassword.setVisible(isPostgres);
651 @Messages({
"EamDbSettingsDialog.textPrompt.hostnameOrIP=Hostname or IP Address",
652 "EamDbSettingsDialog.textPrompt.port=Port Number",
653 "EamDbSettingsDialog.textPrompt.dbName=Database Name",
654 "EamDbSettingsDialog.textPrompt.user=Database User",
655 "EamDbSettingsDialog.textPrompt.password=Database User's Password"})
657 Collection<TextPrompt> textPrompts =
new ArrayList<>();
658 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_hostnameOrIP(), tbDbHostname));
659 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_port(), tbDbPort));
660 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_user(), tbDbUsername));
661 configureTextPrompts(textPrompts);
666 tbDbHostname.setEnabled(enabled);
668 tbDbPort.setEnabled(enabled);
670 tbDbUsername.setEnabled(enabled);
672 jpDbPassword.setEnabled(enabled);
683 tfDatabasePath.setEnabled(enabled);
684 bnDatabasePathFileOpen.setEnabled(enabled);
691 textBoxes.add(tfDatabasePath);
692 textBoxes.add(tbDbHostname);
693 textBoxes.add(tbDbPort);
695 textBoxes.add(tbDbUsername);
696 textBoxes.add(jpDbPassword);
697 addDocumentListeners(textBoxes, textBoxChangedListener);
709 textPrompt.setForeground(Color.LIGHT_GRAY);
710 textPrompt.changeAlpha(alpha);
721 textFields.forEach((textField) -> {
722 textField.getDocument().addDocumentListener(listener);
732 @Messages({
"EamDbSettingsDialog.validation.incompleteFields=Fill in all values for the selected database."})
734 boolean result =
true;
736 result = !tbDbHostname.getText().trim().isEmpty()
737 && !tbDbPort.getText().trim().isEmpty()
739 && !tbDbUsername.getText().trim().isEmpty()
740 && 0 < jpDbPassword.getPassword().length;
743 result = !tfDatabasePath.getText().trim().isEmpty();
755 return databaseFieldsArePopulated()
756 && databaseSettingsAreValid();
766 return enableOkButton(checkFields());
775 @Messages({
"EamDbSettingsDialog.validation.finished=Click OK to save your database settings and return to the Options. Or select a different database type."})
778 bnOk.setEnabled(
true);
780 bnOk.setEnabled(
false);
796 tbDbHostname.getText().trim(),
797 tbDbPort.getText().trim(),
798 tbDbUsername.getText().trim(),
799 tfDatabasePath.getText().trim(),
800 new String(jpDbPassword.getPassword()));
842 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.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
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()