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 lbFullDbPath =
new javax.swing.JLabel();
146 filler1 =
new javax.swing.Box.Filler(
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 0),
new java.awt.Dimension(0, 32767));
148 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
150 org.openide.awt.Mnemonics.setLocalizedText(bnCancel,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnCancel.text"));
151 bnCancel.addActionListener(
new java.awt.event.ActionListener() {
152 public void actionPerformed(java.awt.event.ActionEvent evt) {
153 bnCancelActionPerformed(evt);
157 org.openide.awt.Mnemonics.setLocalizedText(bnOk,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnOk.text"));
158 bnOk.addActionListener(
new java.awt.event.ActionListener() {
159 public void actionPerformed(java.awt.event.ActionEvent evt) {
160 bnOkActionPerformed(evt);
164 javax.swing.GroupLayout pnButtonsLayout =
new javax.swing.GroupLayout(pnButtons);
165 pnButtons.setLayout(pnButtonsLayout);
166 pnButtonsLayout.setHorizontalGroup(
167 pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
168 .addGroup(pnButtonsLayout.createSequentialGroup()
169 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
172 .addComponent(bnCancel)
175 pnButtonsLayout.setVerticalGroup(
176 pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
177 .addGroup(pnButtonsLayout.createSequentialGroup()
179 .addGroup(pnButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
181 .addComponent(bnCancel))
185 pnSQLiteSettings.setBorder(javax.swing.BorderFactory.createEtchedBorder());
187 org.openide.awt.Mnemonics.setLocalizedText(lbDatabasePath,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabasePath.text"));
189 tfDatabasePath.setText(
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.tfDatabasePath.text"));
190 tfDatabasePath.setToolTipText(
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.tfDatabasePath.toolTipText"));
192 org.openide.awt.Mnemonics.setLocalizedText(bnDatabasePathFileOpen,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.bnDatabasePathFileOpen.text"));
193 bnDatabasePathFileOpen.addActionListener(
new java.awt.event.ActionListener() {
194 public void actionPerformed(java.awt.event.ActionEvent evt) {
195 bnDatabasePathFileOpenActionPerformed(evt);
199 org.openide.awt.Mnemonics.setLocalizedText(lbHostName,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbHostName.text"));
201 org.openide.awt.Mnemonics.setLocalizedText(lbPort,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbPort.text"));
203 org.openide.awt.Mnemonics.setLocalizedText(lbUserName,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbUserName.text"));
205 org.openide.awt.Mnemonics.setLocalizedText(lbUserPassword,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbUserPassword.text"));
207 cbDatabaseType.setModel(
new javax.swing.DefaultComboBoxModel<>(
new EamDbPlatformEnum[]{EamDbPlatformEnum.POSTGRESQL, EamDbPlatformEnum.SQLITE}));
208 cbDatabaseType.addActionListener(
new java.awt.event.ActionListener() {
209 public void actionPerformed(java.awt.event.ActionEvent evt) {
210 cbDatabaseTypeActionPerformed(evt);
214 org.openide.awt.Mnemonics.setLocalizedText(lbSingleUserSqLite,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbSingleUserSqLite.text"));
216 org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseType,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabaseType.text"));
218 org.openide.awt.Mnemonics.setLocalizedText(lbDatabaseDesc,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbDatabaseDesc.text"));
220 org.openide.awt.Mnemonics.setLocalizedText(lbFullDbPath,
org.openide.util.NbBundle.getMessage(
EamDbSettingsDialog.class,
"EamDbSettingsDialog.lbFullDbPath.text"));
222 javax.swing.GroupLayout pnSQLiteSettingsLayout =
new javax.swing.GroupLayout(pnSQLiteSettings);
223 pnSQLiteSettings.setLayout(pnSQLiteSettingsLayout);
224 pnSQLiteSettingsLayout.setHorizontalGroup(
225 pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
228 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
229 .addComponent(lbHostName)
230 .addComponent(lbPort)
231 .addComponent(lbUserName)
232 .addComponent(lbDatabaseType)
233 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
234 .addComponent(lbDatabasePath, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
235 .addComponent(lbUserPassword, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
236 .addComponent(lbDatabaseDesc))
238 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
239 .addComponent(lbFullDbPath, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
240 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
241 .addComponent(cbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
242 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
243 .addComponent(lbSingleUserSqLite, javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
245 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
246 .addComponent(tfDatabasePath)
247 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
248 .addComponent(bnDatabasePathFileOpen)
250 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnSQLiteSettingsLayout.createSequentialGroup()
251 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
252 .addComponent(tbDbHostname, javax.swing.GroupLayout.Alignment.LEADING)
253 .addComponent(jpDbPassword, javax.swing.GroupLayout.Alignment.LEADING)
254 .addComponent(tbDbUsername)
255 .addComponent(tbDbPort, javax.swing.GroupLayout.Alignment.LEADING))
256 .addGap(10, 10, 10))))
257 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
259 .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
260 .addGap(0, 0, Short.MAX_VALUE))
262 pnSQLiteSettingsLayout.setVerticalGroup(
263 pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
264 .addGroup(pnSQLiteSettingsLayout.createSequentialGroup()
266 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
267 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
268 .addComponent(cbDatabaseType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
269 .addComponent(lbSingleUserSqLite))
270 .addComponent(lbDatabaseType, javax.swing.GroupLayout.Alignment.TRAILING))
271 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
272 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
273 .addComponent(lbDatabasePath)
274 .addComponent(tfDatabasePath, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
275 .addComponent(bnDatabasePathFileOpen))
276 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
277 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
278 .addComponent(tbDbHostname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
279 .addComponent(lbHostName))
280 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
281 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
282 .addComponent(tbDbPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
283 .addComponent(lbPort))
284 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
285 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
286 .addComponent(tbDbUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
287 .addComponent(lbUserName))
288 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
289 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
290 .addComponent(jpDbPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
291 .addComponent(lbUserPassword))
292 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
293 .addGroup(pnSQLiteSettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
294 .addComponent(lbFullDbPath, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
295 .addComponent(lbDatabaseDesc, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
296 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
297 .addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
301 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
302 getContentPane().setLayout(layout);
303 layout.setHorizontalGroup(
304 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
305 .addGroup(layout.createSequentialGroup()
307 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308 .addComponent(pnButtons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
309 .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
312 layout.setVerticalGroup(
313 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
314 .addGroup(layout.createSequentialGroup()
316 .addComponent(pnSQLiteSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
317 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
318 .addComponent(pnButtons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
327 setTextBoxListeners();
328 switch (selectedPlatform) {
331 updatePostgresFields(
false);
332 updateSqliteFields(
true);
337 updatePostgresFields(
true);
338 updateSqliteFields(
false);
346 this.setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
350 @Messages({
"EamDbSettingsDialog.chooserPath.failedToGetDbPathMsg=Selected database path is invalid. Try again."})
352 fcDatabasePath.setSelectedFile(
new File(dbSettingsSqlite.
getDbDirectory()));
353 if (fcDatabasePath.showOpenDialog(
this) == JFileChooser.APPROVE_OPTION) {
354 File databaseFile = fcDatabasePath.getSelectedFile();
355 if (databaseFile.isFile()) {
356 databaseFile = fcDatabasePath.getCurrentDirectory();
359 tfDatabasePath.setText(databaseFile.getCanonicalPath());
361 }
catch (IOException ex) {
362 logger.log(Level.SEVERE,
"Failed to get path of selected database file", ex);
368 switch (selectedPlatform) {
404 @Messages({
"EamDbSettingsDialog.okButton.createDbError.title=Unable to Create Database",
405 "EamDbSettingsDialog.okButton.createSQLiteDbError.message=Unable to create SQLite Database, please ensure location exists and you have write permissions and try again.",
406 "EamDbSettingsDialog.okButton.createPostgresDbError.message=Unable to create Postgres Database, please ensure address, port, and login credentials are correct for Postgres server and try again."})
408 boolean result =
false;
409 boolean dbCreated =
true;
410 switch (selectedPlatform) {
425 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
426 Bundle.EamDbSettingsDialog_okButton_createPostgresDbError_message(),
427 Bundle.EamDbSettingsDialog_okButton_createDbError_title(),
428 JOptionPane.WARNING_MESSAGE);
429 logger.severe(
"Unable to initialize database schema or insert contents into central repository.");
446 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
447 Bundle.EamDbSettingsDialog_okButton_createSQLiteDbError_message(),
448 Bundle.EamDbSettingsDialog_okButton_createDbError_title(),
449 JOptionPane.WARNING_MESSAGE);
450 logger.severe(
"Unable to initialize database schema or insert contents into central repository.");
463 boolean wasConfigurationChanged() {
464 return configurationChanged;
467 @Messages({
"EamDbSettingsDialog.okButton.errorTitle.text=Restart Required.",
468 "EamDbSettingsDialog.okButton.errorMsg.text=Please restart Autopsy to begin using the new database platform.",
469 "EamDbSettingsDialog.okButton.connectionErrorMsg.text=Failed to connect to central repository database.",
470 "EamDbSettingsDialog.okButton.corruptDatabaseExists.title=Error Loading Database",
471 "EamDbSettingsDialog.okButton.corruptDatabaseExists.message=Database exists but is not the right format. Manually delete it or choose a different path (if applicable).",
472 "EamDbSettingsDialog.okButton.createDbDialog.title=Database Does Not Exist",
473 "EamDbSettingsDialog.okButton.createDbDialog.message=Database does not exist, would you like to create it?",
474 "EamDbSettingsDialog.okButton.databaseConnectionFailed.title=Database Connection Failed",
475 "EamDbSettingsDialog.okButton.databaseConnectionFailed.message=Unable to connect to database please check your settings and try again."})
477 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
480 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
481 Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_message(),
482 Bundle.EamDbSettingsDialog_okButton_databaseConnectionFailed_title(),
483 JOptionPane.WARNING_MESSAGE);
486 JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(),
487 Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_message(),
488 Bundle.EamDbSettingsDialog_okButton_corruptDatabaseExists_title(),
489 JOptionPane.WARNING_MESSAGE);
492 if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
493 Bundle.EamDbSettingsDialog_okButton_createDbDialog_message(),
494 Bundle.EamDbSettingsDialog_okButton_createDbDialog_title(),
495 JOptionPane.YES_NO_OPTION)) {
501 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
515 if (null != previousDbManager) {
520 logger.log(Level.SEVERE,
"Failed to close database connections in previously selected platform.", ex);
521 SwingUtilities.invokeLater(() -> {
522 JOptionPane.showMessageDialog(
this,
523 Bundle.EamDbSettingsDialog_okButton_errorMsg_text(),
524 Bundle.EamDbSettingsDialog_okButton_errorTitle_text(),
525 JOptionPane.WARNING_MESSAGE);
535 switch (selectedPlatform) {
543 configurationChanged =
true;
545 logger.log(Level.SEVERE, Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), ex);
546 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
558 configurationChanged =
true;
560 logger.log(Level.SEVERE, Bundle.EamDbSettingsDialog_okButton_connectionErrorMsg_text(), ex);
561 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
569 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
580 customizeComponents();
584 lbFullDbPath.setText(tfDatabasePath.getText() + File.separator + CENTRAL_REPO_DB_NAME + CENTRAL_REPO_SQLITE_EXT);
588 lbDatabasePath.setVisible(!isPostgres);
589 tfDatabasePath.setVisible(!isPostgres);
590 lbDatabaseDesc.setVisible(!isPostgres);
591 lbFullDbPath.setVisible(!isPostgres);
592 lbSingleUserSqLite.setVisible(!isPostgres);
593 bnDatabasePathFileOpen.setVisible(!isPostgres);
594 lbHostName.setVisible(isPostgres);
595 tbDbHostname.setVisible(isPostgres);
596 lbPort.setVisible(isPostgres);
597 tbDbPort.setVisible(isPostgres);
598 lbUserName.setVisible(isPostgres);
599 tbDbUsername.setVisible(isPostgres);
600 lbUserPassword.setVisible(isPostgres);
601 jpDbPassword.setVisible(isPostgres);
607 @Messages({
"EamDbSettingsDialog.textPrompt.hostnameOrIP=Hostname or IP Address",
608 "EamDbSettingsDialog.textPrompt.port=Port Number",
609 "EamDbSettingsDialog.textPrompt.dbName=Database Name",
610 "EamDbSettingsDialog.textPrompt.user=Database User",
611 "EamDbSettingsDialog.textPrompt.password=Database User's Password"})
613 Collection<TextPrompt> textPrompts =
new ArrayList<>();
614 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_hostnameOrIP(), tbDbHostname));
615 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_port(), tbDbPort));
616 textPrompts.add(
new TextPrompt(Bundle.EamDbSettingsDialog_textPrompt_user(), tbDbUsername));
617 configureTextPrompts(textPrompts);
621 tbDbHostname.setText(enabled ? dbSettingsPostgres.
getHost() :
"");
622 tbDbHostname.setEnabled(enabled);
623 tbDbPort.setText(enabled ? Integer.toString(dbSettingsPostgres.
getPort()) :
"");
624 tbDbPort.setEnabled(enabled);
625 tbDbUsername.setText(enabled ? dbSettingsPostgres.
getUserName() :
"");
626 tbDbUsername.setEnabled(enabled);
627 jpDbPassword.setText(enabled ? dbSettingsPostgres.
getPassword() :
"");
628 jpDbPassword.setEnabled(enabled);
638 tfDatabasePath.setText(enabled ? dbSettingsSqlite.
getDbDirectory() :
"");
639 tfDatabasePath.setEnabled(enabled);
640 bnDatabasePathFileOpen.setEnabled(enabled);
647 textBoxes.add(tfDatabasePath);
648 textBoxes.add(tbDbHostname);
649 textBoxes.add(tbDbPort);
651 textBoxes.add(tbDbUsername);
652 textBoxes.add(jpDbPassword);
653 addDocumentListeners(textBoxes, textBoxChangedListener);
665 textPrompt.setForeground(Color.LIGHT_GRAY);
666 textPrompt.changeAlpha(alpha);
677 textFields.forEach((textField) -> {
678 textField.getDocument().addDocumentListener(listener);
688 @Messages({
"EamDbSettingsDialog.validation.incompleteFields=Fill in all values for the selected database."})
690 boolean result =
true;
691 switch (selectedPlatform) {
693 result = !tbDbHostname.getText().trim().isEmpty()
694 && !tbDbPort.getText().trim().isEmpty()
696 && !tbDbUsername.getText().trim().isEmpty()
697 && 0 < jpDbPassword.getPassword().length;
702 result = !tfDatabasePath.getText().trim().isEmpty();
718 return databaseFieldsArePopulated()
719 && databaseSettingsAreValid();
728 boolean result =
true;
729 StringBuilder guidanceText =
new StringBuilder();
731 switch (selectedPlatform) {
734 dbSettingsPostgres.
setHost(tbDbHostname.getText().trim());
736 guidanceText.append(ex.getMessage());
741 dbSettingsPostgres.
setPort(Integer.valueOf(tbDbPort.getText().trim()));
743 guidanceText.append(ex.getMessage());
748 dbSettingsPostgres.
setDbName(CENTRAL_REPO_DB_NAME);
750 guidanceText.append(ex.getMessage());
755 dbSettingsPostgres.
setUserName(tbDbUsername.getText().trim());
757 guidanceText.append(ex.getMessage());
762 dbSettingsPostgres.
setPassword(
new String(jpDbPassword.getPassword()));
764 guidanceText.append(ex.getMessage());
770 File databasePath =
new File(tfDatabasePath.getText());
771 dbSettingsSqlite.
setDbName(CENTRAL_REPO_DB_NAME + CENTRAL_REPO_SQLITE_EXT);
774 guidanceText.append(ex.getMessage());
789 return enableOkButton(checkFields());
798 @Messages({
"EamDbSettingsDialog.validation.finished=Click OK to save your database settings and return to the Options. Or select a different database type."})
801 bnOk.setEnabled(
true);
803 bnOk.setEnabled(
false);
817 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
825 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
833 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
853 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.JLabel lbFullDbPath
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()
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
void setDbDirectory(String dbDirectory)
boolean dbDirectoryExists()
javax.swing.JTextField tfDatabasePath
void customizeComponents()