19 package org.sleuthkit.autopsy.centralrepository.optionspanel;
21 import java.awt.Color;
22 import java.awt.Cursor;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.logging.Level;
28 import javax.swing.JDialog;
29 import javax.swing.JFileChooser;
30 import javax.swing.JFrame;
31 import javax.swing.JOptionPane;
32 import javax.swing.JTextField;
33 import javax.swing.SwingUtilities;
34 import javax.swing.event.DocumentEvent;
35 import javax.swing.event.DocumentListener;
36 import javax.swing.filechooser.FileFilter;
37 import org.netbeans.spi.options.OptionsPanelController;
38 import org.openide.util.NbBundle.Messages;
39 import org.openide.windows.WindowManager;
52 @SuppressWarnings(
"PMD.SingularField")
56 private static final String CENTRAL_REPO_DB_NAME =
"central_repository";
57 private static final String CENTRAL_REPO_SQLITE_EXT =
".db";
58 private static final long serialVersionUID = 1L;
66 private boolean configurationChanged =
false;
71 @Messages({
"EamDbSettingsDialog.title.text=Central Repository Database Configuration",
72 "EamDbSettingsDialog.lbSingleUserSqLite.text=SQLite should only be used by one examiner at a time.",
73 "EamDbSettingsDialog.lbDatabaseType.text=Database Type :",
74 "EamDbSettingsDialog.fcDatabasePath.title=Select location for central_repository.db"})
77 super((JFrame) WindowManager.getDefault().getMainWindow(),
78 Bundle.EamDbSettingsDialog_title_text(),
81 textBoxes =
new ArrayList<>();
91 fcDatabasePath.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
92 fcDatabasePath.setAcceptAllFileFilterUsed(
false);
93 fcDatabasePath.setDialogTitle(Bundle.EamDbSettingsDialog_fcDatabasePath_title());
94 fcDatabasePath.setFileFilter(
new FileFilter() {
96 public boolean accept(File pathname) {
97 if (pathname.isDirectory()) {
100 return pathname.getName().toLowerCase().equals((CENTRAL_REPO_DB_NAME + CENTRAL_REPO_SQLITE_EXT).toLowerCase());
104 public String getDescription() {
105 return "Directories and Central Repository databases";
108 cbDatabaseType.setSelectedItem(selectedPlatform);
109 customizeComponents();
120 @SuppressWarnings(
"unchecked")
122 private
void initComponents() {
124 bnGrpDatabasePlatforms =
new javax.swing.ButtonGroup();
125 fcDatabasePath =
new javax.swing.JFileChooser();
126 pnButtons =
new javax.swing.JPanel();
127 bnCancel =
new javax.swing.JButton();
128 bnOk =
new javax.swing.JButton();
129 pnSQLiteSettings =
new javax.swing.JPanel();
130 lbDatabasePath =
new javax.swing.JLabel();
131 tfDatabasePath =
new javax.swing.JTextField();
132 bnDatabasePathFileOpen =
new javax.swing.JButton();
133 lbHostName =
new javax.swing.JLabel();
134 tbDbHostname =
new javax.swing.JTextField();
135 lbPort =
new javax.swing.JLabel();
136 tbDbPort =
new javax.swing.JTextField();
137 lbUserName =
new javax.swing.JLabel();
138 tbDbUsername =
new javax.swing.JTextField();
139 lbUserPassword =
new javax.swing.JLabel();
140 jpDbPassword =
new javax.swing.JPasswordField();
141 cbDatabaseType =
new javax.swing.JComboBox<>();
142 lbSingleUserSqLite =
new javax.swing.JLabel();
143 lbDatabaseType =
new javax.swing.JLabel();
144 lbDatabaseDesc =
new javax.swing.JLabel();
145 filler1 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 32767));
146 dataBaseFileScrollPane =
new javax.swing.JScrollPane();
147 dataBaseFileTextArea =
new javax.swing.JTextArea();
149 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
152 org.openide.awt.Mnemonics.setLocalizedText(bnCancel,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnCancel.text"));
153 bnCancel.setMaximumSize(
new java.awt.Dimension(79, 23));
154 bnCancel.setMinimumSize(
new java.awt.Dimension(79, 23));
155 bnCancel.setPreferredSize(
new java.awt.Dimension(79, 23));
156 bnCancel.addActionListener(
new java.awt.event.ActionListener() {
157 public void actionPerformed(java.awt.event.ActionEvent evt) {
158 bnCancelActionPerformed(evt);
162 org.openide.awt.Mnemonics.setLocalizedText(bnOk,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnOk.text"));
163 bnOk.addActionListener(
new java.awt.event.ActionListener() {
164 public void actionPerformed(java.awt.event.ActionEvent evt) {
165 bnOkActionPerformed(evt);
169 javax.swing.GroupLayout pnButtonsLayout =
new javax.swing.GroupLayout(pnButtons);
170 pnButtons.setLayout(pnButtonsLayout);
171 pnButtonsLayout.setHorizontalGroup(
172 pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
173 .addGroup(pnButtonsLayout.createSequentialGroup()
174 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
177 .addComponent(bnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
181 pnButtonsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {bnCancel, bnOk});
183 pnButtonsLayout.setVerticalGroup(
184 pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
185 .addGroup(pnButtonsLayout.createSequentialGroup()
187 .addGroup(pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
189 .addComponent(bnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
193 pnSQLiteSettings.setBorder(javax.swing.BorderFactory.createEtchedBorder());
195 org.openide.awt.Mnemonics.setLocalizedText(lbDatabasePath,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabasePath.text"));
196 lbDatabasePath.setPreferredSize(
new java.awt.Dimension(80, 14));
198 tfDatabasePath.setText(
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.tfDatabasePath.text"));
199 tfDatabasePath.setToolTipText(
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.tfDatabasePath.toolTipText"));
200 tfDatabasePath.setPreferredSize(
new java.awt.Dimension(420, 23));
202 org.openide.awt.Mnemonics.setLocalizedText(bnDatabasePathFileOpen,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnDatabasePathFileOpen.text"));
203 bnDatabasePathFileOpen.addActionListener(
new java.awt.event.ActionListener() {
204 public void actionPerformed(java.awt.event.ActionEvent evt) {
205 bnDatabasePathFileOpenActionPerformed(evt);
209 org.openide.awt.Mnemonics.setLocalizedText(lbHostName,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbHostName.text"));
210 lbHostName.setPreferredSize(
new java.awt.Dimension(80, 14));
212 tbDbHostname.setPreferredSize(
new java.awt.Dimension(509, 20));
214 org.openide.awt.Mnemonics.setLocalizedText(lbPort,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbPort.text"));
215 lbPort.setPreferredSize(
new java.awt.Dimension(80, 14));
217 tbDbPort.setPreferredSize(
new java.awt.Dimension(509, 20));
219 org.openide.awt.Mnemonics.setLocalizedText(lbUserName,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbUserName.text"));
220 lbUserName.setPreferredSize(
new java.awt.Dimension(80, 14));
222 tbDbUsername.setPreferredSize(
new java.awt.Dimension(509, 20));
224 org.openide.awt.Mnemonics.setLocalizedText(lbUserPassword,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbUserPassword.text"));
225 lbUserPassword.setPreferredSize(
new java.awt.Dimension(80, 14));
227 jpDbPassword.setPreferredSize(
new java.awt.Dimension(509, 20));
229 cbDatabaseType.setModel(
new javax.swing.DefaultComboBoxModel<>(
new EamDbPlatformEnum[]{EamDbPlatformEnum.POSTGRESQL, EamDbPlatformEnum.SQLITE}));
230 cbDatabaseType.setPreferredSize(
new java.awt.Dimension(120, 20));
231 cbDatabaseType.addActionListener(
new java.awt.event.ActionListener() {
232 public void actionPerformed(java.awt.event.ActionEvent evt) {
233 cbDatabaseTypeActionPerformed(evt);
237 org.openide.awt.Mnemonics.setLocalizedText(lbSingleUserSqLite,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbSingleUserSqLite.text"));
238 lbSingleUserSqLite.setPreferredSize(
new java.awt.Dimension(381, 14));
240 org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabaseType.text"));
241 lbDatabaseType.setMaximumSize(
new java.awt.Dimension(80, 14));
242 lbDatabaseType.setMinimumSize(
new java.awt.Dimension(80, 14));
243 lbDatabaseType.setPreferredSize(
new java.awt.Dimension(80, 14));
245 org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseDesc,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabaseDesc.text"));
246 lbDatabaseDesc.setPreferredSize(
new java.awt.Dimension(80, 14));
248 dataBaseFileScrollPane.setBorder(null);
250 dataBaseFileTextArea.setEditable(
false);
251 dataBaseFileTextArea.setBackground(
new java.awt.Color(240, 240, 240));
252 dataBaseFileTextArea.setColumns(20);
253 dataBaseFileTextArea.setFont(
new java.awt.Font(
"Tahoma", 0, 11));
254 dataBaseFileTextArea.setLineWrap(
true);
255 dataBaseFileTextArea.setRows(3);
256 dataBaseFileScrollPane.setViewportView(dataBaseFileTextArea);
258 javax.swing.GroupLayout pnSQLiteSettingsLayout =
new javax.swing.GroupLayout(pnSQLiteSettings);
259 pnSQLiteSettings.setLayout(pnSQLiteSettingsLayout);
260 pnSQLiteSettingsLayout.setHorizontalGroup(
261 pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
262 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
264 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
265 .addComponent(lbHostName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
266 .addComponent(lbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
267 .addComponent(lbDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
268 .addComponent(lbUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
269 .addComponent(lbPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
270 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
271 .addComponent(lbDatabaseDesc, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
272 .addComponent(lbUserPassword, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
274 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
275 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
276 .addComponent(tfDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
277 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
278 .addComponent(bnDatabasePathFileOpen))
279 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
280 .addComponent(cbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
281 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
282 .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
283 .addComponent(jpDbPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
284 .addComponent(tbDbUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
285 .addComponent(tbDbPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
286 .addComponent(tbDbHostname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
287 .addComponent(dataBaseFileScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 509, javax.swing.GroupLayout.PREFERRED_SIZE))
289 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
291 .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
292 .addGap(0, 0, Short.MAX_VALUE))
294 pnSQLiteSettingsLayout.setVerticalGroup(
295 pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
296 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
298 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
299 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
300 .addComponent(cbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
301 .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
302 .addComponent(lbDatabaseType, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
303 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
304 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
305 .addComponent(lbDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
306 .addComponent(tfDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
307 .addComponent(bnDatabasePathFileOpen))
308 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
309 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
310 .addComponent(tbDbHostname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
311 .addComponent(lbHostName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
312 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
313 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
314 .addComponent(tbDbPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
315 .addComponent(lbPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
316 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
317 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
318 .addComponent(tbDbUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
319 .addComponent(lbUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
320 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
321 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
322 .addComponent(jpDbPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
323 .addComponent(lbUserPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
324 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
325 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
326 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
327 .addComponent(lbDatabaseDesc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
329 .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
330 .addComponent(dataBaseFileScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
334 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
335 getContentPane().setLayout(layout);
336 layout.setHorizontalGroup(
337 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
338 .addGroup(layout.createSequentialGroup()
340 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
341 .addComponent(pnButtons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
342 .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
345 layout.setVerticalGroup(
346 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
347 .addGroup(layout.createSequentialGroup()
349 .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
350 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
351 .addComponent(pnButtons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
360 setTextBoxListeners();
361 switch (selectedPlatform) {
364 updatePostgresFields(
false);
365 updateSqliteFields(
true);
370 updatePostgresFields(
true);
371 updateSqliteFields(
false);
379 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
383 @Messages({
"EamDbSettingsDialog.chooserPath.failedToGetDbPathMsg=Selected database path is invalid. Try again."})
385 fcDatabasePath.setSelectedFile(
new File(dbSettingsSqlite.
getDbDirectory()));
386 if (fcDatabasePath.showOpenDialog(
this) == JFileChooser.APPROVE_OPTION) {
387 File databaseFile = fcDatabasePath.getSelectedFile();
388 if (databaseFile.isFile()) {
389 databaseFile = fcDatabasePath.getCurrentDirectory();
392 tfDatabasePath.setText(databaseFile.getCanonicalPath());
393 tfDatabasePath.setCaretPosition(tfDatabasePath.getText().length());
395 }
catch (IOException ex) {
396 logger.log(Level.SEVERE,
"Failed to get path of selected database file", ex);
402 switch (selectedPlatform) {
438 @Messages({
"EamDbSettingsDialog.okButton.createDbError.title=Unable to Create Database",
439 "EamDbSettingsDialog.okButton.createSQLiteDbError.message=Unable to create SQLite Database, please ensure location exists and you have write permissions and try again.",
440 "EamDbSettingsDialog.okButton.createPostgresDbError.message=Unable to create Postgres Database, please ensure address, port, and login credentials are correct for Postgres server and try again."})
442 boolean result =
false;
443 boolean dbCreated =
true;
444 switch (selectedPlatform) {
459 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
460 Bundle.EamDbSettingsDialog_okButton_createPostgresDbError_message(),
461 Bundle.EamDbSettingsDialog_okButton_createDbError_title(),
462 JOptionPane.WARNING_MESSAGE);
463 logger.severe(
"Unable to initialize database schema or insert contents into central repository.");
480 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
481 Bundle.EamDbSettingsDialog_okButton_createSQLiteDbError_message(),
482 Bundle.EamDbSettingsDialog_okButton_createDbError_title(),
483 JOptionPane.WARNING_MESSAGE);
484 logger.severe(
"Unable to initialize database schema or insert contents into central repository.");
500 boolean wasConfigurationChanged() {
501 return configurationChanged;
504 @Messages({
"EamDbSettingsDialog.okButton.errorTitle.text=Restart Required.",
505 "EamDbSettingsDialog.okButton.errorMsg.text=Please restart Autopsy to begin using the new database platform.",
506 "EamDbSettingsDialog.okButton.connectionErrorMsg.text=Failed to connect to central repository database.",
507 "EamDbSettingsDialog.okButton.corruptDatabaseExists.title=Error Loading Database",
508 "EamDbSettingsDialog.okButton.corruptDatabaseExists.message=Database exists but is not the right format. Manually delete it or choose a different path (if applicable).",
509 "EamDbSettingsDialog.okButton.createDbDialog.title=Database Does Not Exist",
510 "EamDbSettingsDialog.okButton.createDbDialog.message=Database does not exist, would you like to create it?",
511 "EamDbSettingsDialog.okButton.databaseConnectionFailed.title=Database Connection Failed",
512 "EamDbSettingsDialog.okButton.databaseConnectionFailed.message=Unable to connect to database please check your settings and try again."})
514 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
517 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
518 Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_message(),
519 Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_title(),
520 JOptionPane.WARNING_MESSAGE);
523 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
524 Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_message(),
525 Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_title(),
526 JOptionPane.WARNING_MESSAGE);
529 if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
530 Bundle.EamDbSettingsDialog_okButton_createDbDialog_message(),
531 Bundle.EamDbSettingsDialog_okButton_createDbDialog_title(),
532 JOptionPane.YES_NO_OPTION)) {
538 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
552 if (null != previousDbManager) {
557 logger.log(Level.SEVERE,
"Failed to close database connections in previously selected platform.", ex);
558 SwingUtilities.invokeLater(() -> {
559 JOptionPane.showMessageDialog(
this,
560 Bundle.EamDbSettingsDialog_okButton_errorMsg_text(),
561 Bundle.EamDbSettingsDialog_okButton_errorTitle_text(),
562 JOptionPane.WARNING_MESSAGE);
572 switch (selectedPlatform) {
580 configurationChanged =
true;
582 logger.log(Level.SEVERE, Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), ex);
583 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
595 configurationChanged =
true;
597 logger.log(Level.SEVERE, Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), ex);
598 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
606 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
617 customizeComponents();
621 dataBaseFileTextArea.setText(tfDatabasePath.getText() + File.separator + CENTRAL_REPO_DB_NAME + CENTRAL_REPO_SQLITE_EXT);
622 dataBaseFileTextArea.setCaretPosition(dataBaseFileTextArea.getText().length());
626 lbDatabasePath.setVisible(!isPostgres);
627 tfDatabasePath.setVisible(!isPostgres);
628 lbDatabaseDesc.setVisible(!isPostgres);
629 dataBaseFileTextArea.setVisible(!isPostgres);
630 lbSingleUserSqLite.setVisible(!isPostgres);
631 bnDatabasePathFileOpen.setVisible(!isPostgres);
632 lbHostName.setVisible(isPostgres);
633 tbDbHostname.setVisible(isPostgres);
634 lbPort.setVisible(isPostgres);
635 tbDbPort.setVisible(isPostgres);
636 lbUserName.setVisible(isPostgres);
637 tbDbUsername.setVisible(isPostgres);
638 lbUserPassword.setVisible(isPostgres);
639 jpDbPassword.setVisible(isPostgres);
645 @Messages({
"EamDbSettingsDialog.textPrompt.hostnameOrIP=Hostname or IP Address",
646 "EamDbSettingsDialog.textPrompt.port=Port Number",
647 "EamDbSettingsDialog.textPrompt.dbName=Database Name",
648 "EamDbSettingsDialog.textPrompt.user=Database User",
649 "EamDbSettingsDialog.textPrompt.password=Database User's Password"})
651 Collection<TextPrompt> textPrompts =
new ArrayList<>();
652 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_hostnameOrIP(), tbDbHostname));
653 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_port(), tbDbPort));
654 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_user(), tbDbUsername));
655 configureTextPrompts(textPrompts);
659 tbDbHostname.setText(enabled ? dbSettingsPostgres.
getHost() :
"");
660 tbDbHostname.setEnabled(enabled);
661 tbDbPort.setText(enabled ? Integer.toString(dbSettingsPostgres.
getPort()) :
"");
662 tbDbPort.setEnabled(enabled);
663 tbDbUsername.setText(enabled ? dbSettingsPostgres.
getUserName() :
"");
664 tbDbUsername.setEnabled(enabled);
665 jpDbPassword.setText(enabled ? dbSettingsPostgres.
getPassword() :
"");
666 jpDbPassword.setEnabled(enabled);
676 tfDatabasePath.setText(enabled ? dbSettingsSqlite.
getDbDirectory() :
"");
677 tfDatabasePath.setEnabled(enabled);
678 bnDatabasePathFileOpen.setEnabled(enabled);
685 textBoxes.add(tfDatabasePath);
686 textBoxes.add(tbDbHostname);
687 textBoxes.add(tbDbPort);
689 textBoxes.add(tbDbUsername);
690 textBoxes.add(jpDbPassword);
691 addDocumentListeners(textBoxes, textBoxChangedListener);
703 textPrompt.setForeground(Color.LIGHT_GRAY);
704 textPrompt.changeAlpha(alpha);
715 textFields.forEach((textField) -> {
716 textField.getDocument().addDocumentListener(listener);
726 @Messages({
"EamDbSettingsDialog.validation.incompleteFields=Fill in all values for the selected database."})
728 boolean result =
true;
729 switch (selectedPlatform) {
731 result = !tbDbHostname.getText().trim().isEmpty()
732 && !tbDbPort.getText().trim().isEmpty()
734 && !tbDbUsername.getText().trim().isEmpty()
735 && 0 < jpDbPassword.getPassword().length;
740 result = !tfDatabasePath.getText().trim().isEmpty();
756 return databaseFieldsArePopulated()
757 && databaseSettingsAreValid();
766 boolean result =
true;
767 StringBuilder guidanceText =
new StringBuilder();
769 switch (selectedPlatform) {
772 dbSettingsPostgres.
setHost(tbDbHostname.getText().trim());
774 guidanceText.append(ex.getMessage());
779 dbSettingsPostgres.
setPort(Integer.valueOf(tbDbPort.getText().trim()));
781 guidanceText.append(ex.getMessage());
786 dbSettingsPostgres.
setDbName(CENTRAL_REPO_DB_NAME);
788 guidanceText.append(ex.getMessage());
793 dbSettingsPostgres.
setUserName(tbDbUsername.getText().trim());
795 guidanceText.append(ex.getMessage());
800 dbSettingsPostgres.
setPassword(
new String(jpDbPassword.getPassword()));
802 guidanceText.append(ex.getMessage());
808 File databasePath =
new File(tfDatabasePath.getText());
809 dbSettingsSqlite.
setDbName(CENTRAL_REPO_DB_NAME + CENTRAL_REPO_SQLITE_EXT);
812 guidanceText.append(ex.getMessage());
827 return enableOkButton(checkFields());
836 @Messages({
"EamDbSettingsDialog.validation.finished=Click OK to save your database settings and return to the Options. Or select a different database type."})
839 bnOk.setEnabled(
true);
841 bnOk.setEnabled(
false);
855 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
863 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
871 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
891 private javax.swing.JButton
bnOk;
DatabaseTestResult testingStatus
boolean createDbDirectory()
javax.swing.JPasswordField jpDbPassword
boolean insertDefaultDatabaseContent()
void setHost(String host)
javax.swing.JLabel lbHostName
void shutdownConnections()
void displayDatabaseSettings(boolean isPostgres)
javax.swing.JTextField tbDbUsername
boolean insertDefaultDatabaseContent()
boolean verifyDatabaseSchema()
javax.swing.JTextField tbDbPort
final PostgresEamDbSettings dbSettingsPostgres
javax.swing.JPanel pnButtons
javax.swing.JButton bnCancel
final SqliteEamDbSettings dbSettingsSqlite
void setTextBoxListeners()
void bnDatabasePathFileOpenActionPerformed(java.awt.event.ActionEvent evt)
boolean verifyConnection()
javax.swing.JComboBox< EamDbPlatformEnum > cbDatabaseType
boolean initializeDatabaseSchema()
javax.swing.JLabel lbPort
javax.swing.ButtonGroup bnGrpDatabasePlatforms
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 setPassword(String password)
EamDbPlatformEnum selectedPlatform
javax.swing.JButton bnDatabasePathFileOpen
void bnOkActionPerformed(java.awt.event.ActionEvent evt)
void changedUpdate(DocumentEvent e)
boolean databaseSettingsAreValid()
static EamDb getInstance()
void bnCancelActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JLabel lbDatabaseDesc
javax.swing.Box.Filler filler1
boolean initializeDatabaseSchema()
final Collection< JTextField > textBoxes
boolean verifyDatabaseExists()
static void configureTextPrompts(Collection< TextPrompt > textPrompts)
boolean verifyDatabaseSchema()
javax.swing.JScrollPane dataBaseFileScrollPane
void updateSqliteFields(boolean enabled)
void insertUpdate(DocumentEvent e)
javax.swing.JLabel lbUserPassword
boolean databaseFieldsArePopulated()
boolean verifyConnection()
void setUserName(String userName)
javax.swing.JLabel lbUserName
javax.swing.JLabel lbDatabasePath
void cbDatabaseTypeActionPerformed(java.awt.event.ActionEvent evt)
void setDbName(String dbName)
boolean enableOkButton(boolean isValidInput)
javax.swing.JLabel lbSingleUserSqLite
void setDbName(String dbName)
synchronized static Logger getLogger(String name)
javax.swing.JTextField tbDbHostname
final TextBoxChangedListener textBoxChangedListener
javax.swing.JLabel lbDatabaseType
javax.swing.JTextArea dataBaseFileTextArea
void setDbDirectory(String dbDirectory)
boolean dbDirectoryExists()
javax.swing.JTextField tfDatabasePath
void customizeComponents()