• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / elemental / 982

29 Apr 2025 08:34PM UTC coverage: 56.409% (+0.007%) from 56.402%
982

push

circleci

adamretter
[feature] Improve README.md badges

28451 of 55847 branches covered (50.94%)

Branch coverage included in aggregate %.

77468 of 131924 relevant lines covered (58.72%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/exist-core/src/main/java/org/exist/client/ConnectionDialog.java
1
/*
2
 * Elemental
3
 * Copyright (C) 2024, Evolved Binary Ltd
4
 *
5
 * admin@evolvedbinary.com
6
 * https://www.evolvedbinary.com | https://www.elemental.xyz
7
 *
8
 * Use of this software is governed by the Business Source License 1.1
9
 * included in the LICENSE file and at www.mariadb.com/bsl11.
10
 *
11
 * Change Date: 2028-04-27
12
 *
13
 * On the date above, in accordance with the Business Source License, use
14
 * of this software will be governed by the Apache License, Version 2.0.
15
 *
16
 * Additional Use Grant: Production use of the Licensed Work for a permitted
17
 * purpose. A Permitted Purpose is any purpose other than a Competing Use.
18
 * A Competing Use means making the Software available to others in a commercial
19
 * product or service that: substitutes for the Software; substitutes for any
20
 * other product or service we offer using the Software that exists as of the
21
 * date we make the Software available; or offers the same or substantially
22
 * similar functionality as the Software.
23
 *
24
 * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
25
 *       The original license header is included below.
26
 *
27
 * =====================================================================
28
 *
29
 * eXist-db Open Source Native XML Database
30
 * Copyright (C) 2001 The eXist-db Authors
31
 *
32
 * info@exist-db.org
33
 * http://www.exist-db.org
34
 *
35
 * This library is free software; you can redistribute it and/or
36
 * modify it under the terms of the GNU Lesser General Public
37
 * License as published by the Free Software Foundation; either
38
 * version 2.1 of the License, or (at your option) any later version.
39
 *
40
 * This library is distributed in the hope that it will be useful,
41
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
43
 * Lesser General Public License for more details.
44
 *
45
 * You should have received a copy of the GNU Lesser General Public
46
 * License along with this library; if not, write to the Free Software
47
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
48
 */
49
package org.exist.client;
50

51
import java.awt.Graphics;
52
import java.io.IOException;
53
import java.nio.file.Files;
54
import java.nio.file.Path;
55
import java.nio.file.Paths;
56
import java.util.ArrayList;
57
import java.util.Arrays;
58
import java.util.List;
59
import java.util.prefs.BackingStoreException;
60
import java.util.prefs.InvalidPreferencesFormatException;
61
import javax.swing.ComboBoxModel;
62
import javax.swing.DefaultComboBoxModel;
63
import javax.swing.DefaultListModel;
64
import javax.swing.JFileChooser;
65
import javax.swing.JOptionPane;
66
import javax.swing.ListModel;
67
import javax.swing.SwingUtilities;
68

69
/**
70
 * @author <a href="mailto:adam.retter@googlemail.com">Adam Retter</a>
71
 */
72
public class ConnectionDialog extends javax.swing.JDialog implements DialogWithResponse<Connection> {
73

74
    private static final String PROVIDED_PASSWORD_PLACEHOLDER = "__PROVIDED__PASSWORD__";
75

76
    private ComboBoxModel connectionTypeModel = null;
×
77
    private DefaultListModel favouritesModel = null;
×
78
    private final DefaultConnectionSettings defaultConnectionSettings;
79
    private final boolean disableEmbeddedConnectionType;
80
    private Path config;
81

82
    private final List<DialogCompleteWithResponse<Connection>> dialogCompleteWithResponseCallbacks = new ArrayList<>();
×
83

84
    private enum ConnectionType {
×
85
        Remote,
×
86
        Embedded
×
87
    }
88

89
    /**
90
     *  Creates new form ConnectionForm
91
     * @param parent Parent window.
92
     * @param modal modality flag.
93
     * @param defaultConnectionSettings Default connection settings.
94
     * @param embeddedByDefault Set TRUE to have embedded mode selected by default.
95
     * @param disableEmbeddedConnectionType Set to TRUE to force remote connections only.
96
     */
97
    public ConnectionDialog(final java.awt.Frame parent, final boolean modal, final DefaultConnectionSettings defaultConnectionSettings, final boolean embeddedByDefault, final boolean disableEmbeddedConnectionType) {
98
        super(parent, modal);
×
99
        this.defaultConnectionSettings = defaultConnectionSettings;
×
100
        this.config = Paths.get(defaultConnectionSettings.getConfiguration());
×
101
        this.disableEmbeddedConnectionType = disableEmbeddedConnectionType;
×
102
        this.setIconImage(InteractiveClient.getElementalIcon(getClass()).getImage());
×
103
        initComponents();
×
104

105
        if (disableEmbeddedConnectionType) {
×
106
            cmbConnectionType.removeItem(ConnectionType.Embedded);
×
107
        } else if (embeddedByDefault) {
×
108
            cmbConnectionType.setSelectedItem(ConnectionType.Embedded);
×
109
            toggleRemoteEmbeddedDisplayTab(false);
×
110
        }
111
        txtPassword.addKeyListener(new EnterKeyAdapter(btnConnect));
×
112
        txtPassword.requestFocusInWindow(); //set focus to password field
×
113
    }
×
114

115
    private ComboBoxModel getConnectionTypeModel() {
116
        if (connectionTypeModel == null) {
×
117
            connectionTypeModel = new DefaultComboBoxModel(ConnectionType.values());
×
118
        }
119
        return connectionTypeModel;
×
120
    }
121

122
    private DefaultListModel getFavouritesModel() {
123
        if (favouritesModel == null) {
×
124
            favouritesModel = new DefaultListModel();
×
125
            for (final FavouriteConnection favourite : FavouriteConnections.load()) {
×
126
                favouritesModel.addElement(favourite);
×
127
            }
128
        }
129
        return favouritesModel;
×
130
    }
131

132
    private void storeFavourites(final ListModel model) {
133

134
        final List<FavouriteConnection> favourites = new ArrayList<>();
×
135

136
        // Write a node for each item in model.
137
        for (int i = 0; i < model.getSize(); i++) {
×
138
            favourites.add((FavouriteConnection) model.getElementAt(i));
×
139
        }
140

141
        FavouriteConnections.store(favourites);
×
142
    }
×
143

144
    @Override
145
    public void addDialogCompleteWithResponseCallback(final DialogCompleteWithResponse<Connection> dialogCompleteWithResponseCallback) {
146
        getDialogCompleteWithResponseCallbacks().add(dialogCompleteWithResponseCallback);
×
147
    }
×
148

149
    private List<DialogCompleteWithResponse<Connection>> getDialogCompleteWithResponseCallbacks() {
150
        return dialogCompleteWithResponseCallbacks;
×
151
    }
152

153
    private String getLabelText(final String resourceId) {
154
        return Messages.getString(resourceId) + ":";
×
155
    }
156

157
    private String getLabel(final String resourceId) {
158
        return Messages.getString(resourceId);
×
159
    }
160

161
    public DefaultConnectionSettings getDefaultConnectionSettings() {
162
        return defaultConnectionSettings;
×
163
    }
164

165
    /**
166
     * This method is called from within the constructor to initialize the form.
167
     * WARNING: Do NOT modify this code. The content of this method is always
168
     * regenerated by the Form Editor.
169
     */
170
    @SuppressWarnings("unchecked")
171
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
172
    private void initComponents() {
173

174
        pmFavourites = new javax.swing.JPopupMenu();
×
175
        miRemoveFavourite = new javax.swing.JMenuItem();
×
176
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
×
177
        miImportFavourites = new javax.swing.JMenuItem();
×
178
        miExportFavourites = new javax.swing.JMenuItem();
×
179
        lblExistLogo = new javax.swing.JLabel();
×
180
        lblUsername = new javax.swing.JLabel();
×
181
        lblPassword = new javax.swing.JLabel();
×
182
        lblConnectionType = new javax.swing.JLabel();
×
183
        cmbConnectionType = new javax.swing.JComboBox();
×
184
        txtUsername = new javax.swing.JTextField();
×
185
        txtPassword = new javax.swing.JPasswordField();
×
186
        tpConnectionType = new javax.swing.JTabbedPane();
×
187
        tpConnectionType.setUI(new javax.swing.plaf.basic.BasicTabbedPaneUI() {
×
188

189
            @Override
190
            protected final void paintContentBorder(final java.awt.Graphics g, final int tabPlacement, final int selectedIndex) {
191
                //dont paint tabs!
192
            }
×
193

194
            @Override
195
            protected final void paintContentBorderBottomEdge(final java.awt.Graphics g, final int tabPlacement, final int selectedIndex, final int x, final int y, int w, final int h) {
196
                //dont paint tabs!
197
            }
×
198

199
            @Override
200
            protected final void paintContentBorderLeftEdge(final java.awt.Graphics g, final int tabPlacement, final int selectedIndex, final int x, final int y, int w, final int h) {
201
                //dont paint tabs!
202
            }
×
203

204
            @Override
205
            protected final void paintContentBorderRightEdge(final java.awt.Graphics g, final int tabPlacement, final int selectedIndex, final int x, final int y, int w, final int h) {
206
                //dont paint tabs!
207
            }
×
208

209
            @Override
210
            protected final void paintContentBorderTopEdge(final java.awt.Graphics g, final int tabPlacement, final int selectedIndex, final int x, int y, final int w, final int h) {
211
                //dont paint tabs!
212
            }
×
213

214
            @Override
215
            protected final void paintFocusIndicator(final java.awt.Graphics g, final int tabPlacement, final java.awt.Rectangle[] rects, final int tabIndex, final java.awt.Rectangle iconRect, final java.awt.Rectangle textRect, final boolean isSelected) {
216
                //dont paint tabs!
217
            }
×
218

219
            @Override
220
            protected final void paintTab(final java.awt.Graphics g, final int tabPlacement, final java.awt.Rectangle[] rects, final int tabIndex, final java.awt.Rectangle iconRect, final java.awt.Rectangle textRect) {
221
                //dont paint tabs!
222
            }
×
223

224
            @Override
225
            protected final void paintTabArea(final java.awt.Graphics g, final int tabPlacement, final int selectedIndex) {
226
                //dont paint tabs!
227
            }
×
228

229
            @Override
230
            protected final void paintTabBackground(final Graphics g, final int tabPlacement, final int tabIndex, final int x, final int y, final int w, final int h, final boolean isSelected) {
231
            }
×
232

233
            @Override
234
            protected final void paintTabBorder(final java.awt.Graphics g, final int tabPlacement, final int tabIndex, final int x, final int y, final int w, final int h, final boolean isSelected) {
235
                //dont paint tabs!
236
            }
×
237
        });
238
        panRemote = new javax.swing.JPanel();
×
239
        lblServerUri = new javax.swing.JLabel();
×
240
        txtServerUri = new javax.swing.JTextField();
×
241
        chkSsl = new javax.swing.JCheckBox();
×
242
        panEmbedded = new javax.swing.JPanel();
×
243
        lblConfiguration = new javax.swing.JLabel();
×
244
        txtConfiguration = new javax.swing.JTextField();
×
245
        btnSelectConfiguration = new javax.swing.JButton();
×
246
        panFavourites = new javax.swing.JPanel();
×
247
        jScrollPane1 = new javax.swing.JScrollPane();
×
248
        lstFavourites = new javax.swing.JList();
×
249
        btnSaveToFavourites = new javax.swing.JButton();
×
250
        btnClose = new javax.swing.JButton();
×
251
        btnConnect = new javax.swing.JButton();
×
252
        jSeparator1 = new javax.swing.JSeparator();
×
253

254
        miRemoveFavourite.setText("Remove");
×
255
        miRemoveFavourite.addActionListener(this::miRemoveFavouriteActionPerformed);
×
256
        pmFavourites.add(miRemoveFavourite);
×
257
        pmFavourites.add(jSeparator2);
×
258

259
        miImportFavourites.setText("Import Favourites...");
×
260
        miImportFavourites.addActionListener(this::miImportFavouritesActionPerformed);
×
261
        pmFavourites.add(miImportFavourites);
×
262

263
        miExportFavourites.setText("Export Favourites...");
×
264
        miExportFavourites.addActionListener(this::miExportFavouritesActionPerformed);
×
265
        pmFavourites.add(miExportFavourites);
×
266

267
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
×
268
        setTitle("Database Connection");
×
269

270
        lblExistLogo.setIcon(InteractiveClient.getElementalIcon(getClass()));
×
271

272
        lblUsername.setText(getLabelText("LoginPanel.2"));
×
273

274
        lblPassword.setText(getLabelText("LoginPanel.3"));
×
275

276
        lblConnectionType.setText(getLabelText("LoginPanel.4"));
×
277

278
        cmbConnectionType.setModel(getConnectionTypeModel());
×
279
        cmbConnectionType.addActionListener(this::cmbConnectionTypeActionPerformed);
×
280

281
        txtUsername.setText(getDefaultConnectionSettings().getUsername());
×
282
        if (getDefaultConnectionSettings().getPassword() != null
×
283
                && !getDefaultConnectionSettings().getPassword().isEmpty()) {
×
284
            txtPassword.setText(PROVIDED_PASSWORD_PLACEHOLDER);
×
285
        }
286

287
        tpConnectionType.setTabPlacement(javax.swing.JTabbedPane.RIGHT);
×
288

289
        lblServerUri.setText(getLabelText("LoginPanel.12"));
×
290

291
        txtServerUri.setText(getDefaultConnectionSettings().getUri());
×
292

293
        chkSsl.setSelected(getDefaultConnectionSettings().isSsl());
×
294
        chkSsl.setText(getLabel("LoginPanel.47"));
×
295

296
        javax.swing.GroupLayout panRemoteLayout = new javax.swing.GroupLayout(panRemote);
×
297
        panRemote.setLayout(panRemoteLayout);
×
298
        panRemoteLayout.setHorizontalGroup(
×
299
                panRemoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
300
                        .addGroup(panRemoteLayout.createSequentialGroup()
×
301
                                .addContainerGap()
×
302
                                .addComponent(lblServerUri)
×
303
                                .addGap(63, 63, 63)
×
304
                                .addGroup(panRemoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
305
                                        .addComponent(chkSsl)
×
306
                                        .addComponent(txtServerUri, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE))
×
307
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
×
308
        );
309
        panRemoteLayout.setVerticalGroup(
×
310
                panRemoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
311
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panRemoteLayout.createSequentialGroup()
×
312
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
×
313
                                .addGroup(panRemoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
314
                                        .addComponent(lblServerUri)
×
315
                                        .addComponent(txtServerUri, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
×
316
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
317
                                .addComponent(chkSsl)
×
318
                                .addGap(25, 25, 25))
×
319
        );
320

321
        tpConnectionType.addTab("tab3", panRemote);
×
322

323
        lblConfiguration.setText(getLabelText("LoginPanel.8"));
×
324

325
        txtConfiguration.setEditable(false);
×
326
        txtConfiguration.setText(config.toAbsolutePath().toString());
×
327
        txtConfiguration.setToolTipText(getLabel("LoginPanel.9"));
×
328

329
        btnSelectConfiguration.setText("...");
×
330
        btnSelectConfiguration.setToolTipText(getLabel("LoginPanel.11"));
×
331
        btnSelectConfiguration.addActionListener(this::btnSelectConfigurationActionPerformed);
×
332

333
        javax.swing.GroupLayout panEmbeddedLayout = new javax.swing.GroupLayout(panEmbedded);
×
334
        panEmbedded.setLayout(panEmbeddedLayout);
×
335
        panEmbeddedLayout.setHorizontalGroup(
×
336
                panEmbeddedLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
337
                        .addGroup(panEmbeddedLayout.createSequentialGroup()
×
338
                                .addContainerGap()
×
339
                                .addComponent(lblConfiguration)
×
340
                                .addGap(33, 33, 33)
×
341
                                .addComponent(txtConfiguration, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
×
342
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
343
                                .addComponent(btnSelectConfiguration, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
×
344
                                .addContainerGap())
×
345
        );
346
        panEmbeddedLayout.setVerticalGroup(
×
347
                panEmbeddedLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
348
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panEmbeddedLayout.createSequentialGroup()
×
349
                                .addContainerGap()
×
350
                                .addGroup(panEmbeddedLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
351
                                        .addComponent(lblConfiguration)
×
352
                                        .addComponent(txtConfiguration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
×
353
                                        .addComponent(btnSelectConfiguration, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
×
354
                                .addContainerGap(38, Short.MAX_VALUE))
×
355
        );
356

357
        tpConnectionType.addTab("tab2", panEmbedded);
×
358

359
        panFavourites.setBorder(javax.swing.BorderFactory.createTitledBorder(getLabel("LoginPanel.14")));
×
360

361
        lstFavourites.setModel(getFavouritesModel());
×
362
        lstFavourites.setComponentPopupMenu(pmFavourites);
×
363
        lstFavourites.addMouseListener(new java.awt.event.MouseAdapter() {
×
364
            public void mouseClicked(java.awt.event.MouseEvent evt) {
365
                lstFavouritesMouseClicked(evt);
×
366
            }
×
367
        });
368
        jScrollPane1.setViewportView(lstFavourites);
×
369

370
        btnSaveToFavourites.setText(getLabel("LoginPanel.17"));
×
371
        btnSaveToFavourites.addActionListener(this::btnSaveToFavouritesActionPerformed);
×
372

373
        javax.swing.GroupLayout panFavouritesLayout = new javax.swing.GroupLayout(panFavourites);
×
374
        panFavourites.setLayout(panFavouritesLayout);
×
375
        panFavouritesLayout.setHorizontalGroup(
×
376
                panFavouritesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
377
                        .addGroup(panFavouritesLayout.createSequentialGroup()
×
378
                                .addContainerGap()
×
379
                                .addGroup(panFavouritesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
380
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE)
×
381
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panFavouritesLayout.createSequentialGroup()
×
382
                                                .addGap(0, 0, Short.MAX_VALUE)
×
383
                                                .addComponent(btnSaveToFavourites)))
×
384
                                .addContainerGap())
×
385
        );
386
        panFavouritesLayout.setVerticalGroup(
×
387
                panFavouritesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
388
                        .addGroup(panFavouritesLayout.createSequentialGroup()
×
389
                                .addComponent(btnSaveToFavourites)
×
390
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
391
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
×
392
                                .addContainerGap())
×
393
        );
394

395
        btnClose.setText(getLabel("LoginPanel.51"));
×
396
        btnClose.addActionListener(this::btnCloseActionPerformed);
×
397

398
        btnConnect.setText(getLabel("LoginPanel.50"));
×
399
        btnConnect.addKeyListener(new EnterKeyAdapter());
×
400
        btnConnect.addActionListener(this::btnConnectActionPerformed);
×
401

402
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
×
403
        getContentPane().setLayout(layout);
×
404
        layout.setHorizontalGroup(
×
405
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
406
                        .addGroup(layout.createSequentialGroup()
×
407
                                .addContainerGap()
×
408
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
409
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
×
410
                                                .addGap(0, 0, Short.MAX_VALUE)
×
411
                                                .addComponent(btnClose)
×
412
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
413
                                                .addComponent(btnConnect))
×
414
                                        .addGroup(layout.createSequentialGroup()
×
415
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
416
                                                        .addGroup(layout.createSequentialGroup()
×
417
                                                                .addGap(8, 8, 8)
×
418
                                                                .addComponent(lblExistLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
×
419
                                                                .addGap(18, 18, 18)
×
420
                                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
421
                                                                        .addComponent(panFavourites, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
×
422
                                                                        .addComponent(tpConnectionType, javax.swing.GroupLayout.PREFERRED_SIZE, 527, javax.swing.GroupLayout.PREFERRED_SIZE)
×
423
                                                                        .addGroup(layout.createSequentialGroup()
×
424
                                                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
×
425
                                                                                        .addComponent(lblPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
×
426
                                                                                        .addComponent(lblConnectionType, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
×
427
                                                                                .addGap(6, 6, 6)
×
428
                                                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
429
                                                                                        .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
×
430
                                                                                        .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
×
431
                                                                                        .addComponent(cmbConnectionType, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
×
432
                                                                        .addComponent(lblUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)))
×
433
                                                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 666, javax.swing.GroupLayout.PREFERRED_SIZE))
×
434
                                                .addGap(0, 0, Short.MAX_VALUE)))
×
435
                                .addContainerGap())
×
436
        );
437
        layout.setVerticalGroup(
×
438
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
439
                        .addGroup(layout.createSequentialGroup()
×
440
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
×
441
                                        .addGroup(layout.createSequentialGroup()
×
442
                                                .addGap(14, 14, 14)
×
443
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
444
                                                        .addComponent(lblUsername)
×
445
                                                        .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
×
446
                                                .addGap(18, 18, 18)
×
447
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
448
                                                        .addComponent(lblPassword)
×
449
                                                        .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
×
450
                                                .addGap(26, 26, 26)
×
451
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
452
                                                        .addComponent(lblConnectionType)
×
453
                                                        .addComponent(cmbConnectionType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
×
454
                                        .addGroup(layout.createSequentialGroup()
×
455
                                                .addGap(22, 22, 22)
×
456
                                                .addComponent(lblExistLogo, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)))
×
457
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
458
                                .addComponent(tpConnectionType, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
×
459
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
460
                                .addComponent(panFavourites, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
×
461
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
462
                                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
×
463
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
×
464
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
×
465
                                        .addComponent(btnClose)
×
466
                                        .addComponent(btnConnect))
×
467
                                .addContainerGap(35, Short.MAX_VALUE))
×
468
        );
469

470
        pack();
×
471
    }// </editor-fold>//GEN-END:initComponents
×
472

473
    private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
474

475
        final String password = Arrays.equals(txtPassword.getPassword(), PROVIDED_PASSWORD_PLACEHOLDER.toCharArray()) ? getDefaultConnectionSettings().getPassword() : new String(txtPassword.getPassword());
×
476
        final Connection connection;
477
        if (cmbConnectionType.getSelectedItem() == ConnectionType.Remote) {
×
478
            connection = new Connection(txtUsername.getText(), password, txtServerUri.getText(), chkSsl.isSelected());
×
479
        } else {
×
480
            connection = new Connection(txtUsername.getText(), password, txtConfiguration.getText());
×
481
        }
482

483
        for (final DialogCompleteWithResponse<Connection> callback : getDialogCompleteWithResponseCallbacks()) {
×
484
            callback.complete(connection);
×
485
        }
486

487
        setVisible(false);
×
488
        dispose();
×
489
    }//GEN-LAST:event_btnConnectActionPerformed
×
490

491
    private void cmbConnectionTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbConnectionTypeActionPerformed
492
        final boolean remote = (((ConnectionType) cmbConnectionType.getSelectedItem()) == ConnectionType.Remote);
×
493

494
        toggleRemoteEmbeddedDisplayTab(remote);
×
495
    }//GEN-LAST:event_cmbConnectionTypeActionPerformed
×
496

497
    private void toggleRemoteEmbeddedDisplayTab(final boolean remote) {
498
        //remote controls
499
        lblServerUri.setEnabled(remote);
×
500
        lblServerUri.setVisible(remote);
×
501
        txtServerUri.setEnabled(remote);
×
502
        txtServerUri.setVisible(remote);
×
503
        chkSsl.setEnabled(remote);
×
504
        chkSsl.setVisible(remote);
×
505

506
        //embedded controls
507
        lblConfiguration.setEnabled(!remote);
×
508
        lblConfiguration.setVisible(!remote);
×
509
        txtConfiguration.setEnabled(!remote);
×
510
        txtConfiguration.setVisible(!remote);
×
511
        btnSelectConfiguration.setEnabled(!remote);
×
512
        btnSelectConfiguration.setVisible(!remote);
×
513

514
        if (remote) {
×
515
            tpConnectionType.setSelectedIndex(0);
×
516
            if (txtServerUri.getText().isEmpty()) {
×
517
                txtServerUri.setText(defaultConnectionSettings.getUri());
×
518
                chkSsl.setSelected(defaultConnectionSettings.isSsl());
×
519
            }
520
        } else {
×
521
            tpConnectionType.setSelectedIndex(1);
×
522
            if (txtConfiguration.getText().isEmpty()) {
×
523
                txtConfiguration.setText(defaultConnectionSettings.getConfiguration());
×
524
            }
525
        }
526
    }
×
527

528
    private void btnSelectConfigurationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectConfigurationActionPerformed
529
        final JFileChooser chooser = new JFileChooser();
×
530
        chooser.setMultiSelectionEnabled(false);
×
531
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
×
532
        if (config != null && config.getParent() != null) {
×
533
            chooser.setCurrentDirectory(config.getParent().toFile());
×
534
        }
535
        if (chooser.showDialog(this, Messages.getString("LoginPanel.37")) == JFileChooser.APPROVE_OPTION) {
×
536
            config = chooser.getSelectedFile().toPath();
×
537
            txtConfiguration.setText(config.toAbsolutePath().toString());
×
538
        }
539
    }//GEN-LAST:event_btnSelectConfigurationActionPerformed
×
540

541
    private void btnSaveToFavouritesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveToFavouritesActionPerformed
542
        final String favouriteName = JOptionPane.showInputDialog(this, "Please enter a name for your favourite:", "Save Favourite", JOptionPane.QUESTION_MESSAGE);
×
543

544
        if (favouriteName != null && favouriteName.length() > 0) {
×
545
            for (int i = 0; i < getFavouritesModel().getSize(); i++) {
×
546
                if (getFavouritesModel().elementAt(i).equals(favouriteName)) {
×
547
                    final int result = JOptionPane.showConfirmDialog(this, Messages.getString("LoginPanel.19"), Messages.getString("LoginPanel.20"), JOptionPane.YES_NO_OPTION);
×
548
                    if (result == JOptionPane.NO_OPTION) {
×
549
                        return;
×
550
                    }
551
                    getFavouritesModel().remove(i);
×
552
                    break;
×
553
                }
554
            }
555

556
            final FavouriteConnection favourite;
557
            if (cmbConnectionType.getSelectedItem() == ConnectionType.Remote) {
×
558
                favourite = new FavouriteConnection(
×
559
                        favouriteName,
×
560
                        txtUsername.getText(),
×
561
                        new String(txtPassword.getPassword()),
×
562
                        txtServerUri.getText(),
×
563
                        chkSsl.isSelected()
×
564
                );
565
            } else {
×
566
                favourite = new FavouriteConnection(
×
567
                        favouriteName,
×
568
                        txtUsername.getText(),
×
569
                        new String(txtPassword.getPassword()),
×
570
                        config.toAbsolutePath().toString()
×
571
                );
572
            }
573
            getFavouritesModel().addElement(favourite);
×
574
            storeFavourites(getFavouritesModel());
×
575
        }
576
    }//GEN-LAST:event_btnSaveToFavouritesActionPerformed
×
577

578
    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
579
        setVisible(false);
×
580
        dispose();
×
581
    }//GEN-LAST:event_btnCloseActionPerformed
×
582

583
    private void lstFavouritesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstFavouritesMouseClicked
584

585
        if (SwingUtilities.isRightMouseButton(evt)) {
×
586
            miRemoveFavourite.setEnabled(!lstFavourites.isSelectionEmpty());
×
587
            miExportFavourites.setEnabled(!getFavouritesModel().isEmpty());
×
588
        }
589

590
        if (evt.getClickCount() == 2 && lstFavourites.getSelectedIndex() >= 0) {
×
591
            final FavouriteConnection favourite = (FavouriteConnection) lstFavourites.getSelectedValue();
×
592

593
            final boolean favouriteHasEmbeddedMode = "".equals(favourite.getUri());
×
594

595
            if (disableEmbeddedConnectionType && favouriteHasEmbeddedMode) {
×
596
                JOptionPane.showMessageDialog(this, "The favourite connection '" + favourite.getName() + "' uses an Embedded Connection Type, but Embedded Connections have been disabled at client startup.", "Favourite Selection Error", JOptionPane.ERROR_MESSAGE);
×
597
                lstFavourites.clearSelection();
×
598
            } else {
×
599

600
                txtUsername.setText(favourite.getUsername());
×
601
                txtPassword.setText(favourite.getPassword());
×
602

603
                cmbConnectionType.setSelectedItem(favouriteHasEmbeddedMode ? ConnectionType.Embedded : ConnectionType.Remote);
×
604
                tpConnectionType.setSelectedIndex(cmbConnectionType.getSelectedIndex());
×
605

606
                txtServerUri.setText(favourite.getUri());
×
607
                chkSsl.setSelected(favourite.isSsl());
×
608

609
                txtConfiguration.setText(favourite.getConfiguration());
×
610

611
                txtPassword.requestFocusInWindow(); //set focus to password field
×
612
            }
613
        }
614
    }//GEN-LAST:event_lstFavouritesMouseClicked
×
615

616
    private void miImportFavouritesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miImportFavouritesActionPerformed
617
        final Path file = Paths.get("favourites.xml"); //$NON-NLS-1$
×
618
        final JFileChooser chooser = new JFileChooser();
×
619
        chooser.setSelectedFile(file.toFile());
×
620
        chooser.showOpenDialog(this);
×
621
        final Path selectedImportFile = chooser.getSelectedFile().toPath();
×
622

623
        if (selectedImportFile == null) {
×
624
            JOptionPane.showMessageDialog(this, Messages.getString("LoginPanel.33"), Messages.getString("LoginPanel.34"), JOptionPane.ERROR_MESSAGE);
×
625
            return;
×
626
        }
627

628
        if (!Files.isReadable(selectedImportFile)) {
×
629
            JOptionPane.showMessageDialog(this, Messages.getString("LoginPanel.35"), Messages.getString("LoginPanel.36"), JOptionPane.ERROR_MESSAGE);
×
630
            return;
×
631
        }
632

633
        try {
634
            FavouriteConnections.importFromFile(selectedImportFile);
×
635

636
            //reload the favourites model
637
            getFavouritesModel().removeAllElements();
×
638
            for (final FavouriteConnection favourite : FavouriteConnections.load()) {
×
639
                getFavouritesModel().addElement(favourite);
×
640
            }
641
        } catch (final IOException ioe) {
×
642
            JOptionPane.showMessageDialog(this, "Unable to read preferences file: " + selectedImportFile.toAbsolutePath() + ": " + ioe.getMessage(), "Error Importing Preferences", JOptionPane.ERROR_MESSAGE);
×
643
        } catch (final InvalidPreferencesFormatException ipfe) {
×
644
            JOptionPane.showMessageDialog(this, "Invalid format for preferences file: " + selectedImportFile.toAbsolutePath() + ": " + ipfe.getMessage(), "Error Importing Preferences", JOptionPane.ERROR_MESSAGE);
×
645
        }
646
    }//GEN-LAST:event_miImportFavouritesActionPerformed
×
647

648
    private void miExportFavouritesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miExportFavouritesActionPerformed
649
        final Path file = Paths.get(Messages.getString("LoginPanel.25")); //$NON-NLS-1$
×
650
        final JFileChooser chooser = new JFileChooser();
×
651
        chooser.setSelectedFile(file.toFile());
×
652
        chooser.showSaveDialog(this);
×
653

654
        final Path selectedExportFile = chooser.getSelectedFile().toPath();
×
655

656
        if (selectedExportFile == null) {
×
657
            JOptionPane.showMessageDialog(this, Messages.getString("LoginPanel.26"), Messages.getString("LoginPanel.27"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$ //$NON-NLS-2$
×
658
            return;
×
659
        }
660

661
        if (Files.exists(selectedExportFile) && !Files.isReadable(selectedExportFile)) {
×
662
            JOptionPane.showMessageDialog(this, Messages.getString("LoginPanel.28"), Messages.getString("LoginPanel.29"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$ //$NON-NLS-2$
×
663
            return;
×
664
        }
665

666
        try {
667
            FavouriteConnections.exportToFile(selectedExportFile);
×
668
        } catch (final IOException ioe) {
×
669
            JOptionPane.showMessageDialog(this, "Unable to write preferences file: " + selectedExportFile.toAbsolutePath() + ": " + ioe.getMessage(), "Error Importing Preferences", JOptionPane.ERROR_MESSAGE);
×
670
        } catch (final BackingStoreException bse) {
×
671
            JOptionPane.showMessageDialog(this, "Backing store error for export to file: " + selectedExportFile.toAbsolutePath() + ": " + bse.getMessage(), "Error Importing Preferences", JOptionPane.ERROR_MESSAGE);
×
672
        }
673
    }//GEN-LAST:event_miExportFavouritesActionPerformed
×
674

675
    private void miRemoveFavouriteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miRemoveFavouriteActionPerformed
676
        if (!lstFavourites.isSelectionEmpty()) {
×
677
            getFavouritesModel().remove(lstFavourites.getSelectedIndex());
×
678
            storeFavourites(getFavouritesModel());
×
679
        }
680
    }//GEN-LAST:event_miRemoveFavouriteActionPerformed
×
681

682
    // Variables declaration - do not modify//GEN-BEGIN:variables
683
    private javax.swing.JButton btnClose;
684
    private javax.swing.JButton btnConnect;
685
    private javax.swing.JButton btnSaveToFavourites;
686
    private javax.swing.JButton btnSelectConfiguration;
687
    private javax.swing.JCheckBox chkSsl;
688
    private javax.swing.JComboBox cmbConnectionType;
689
    private javax.swing.JScrollPane jScrollPane1;
690
    private javax.swing.JSeparator jSeparator1;
691
    private javax.swing.JPopupMenu.Separator jSeparator2;
692
    private javax.swing.JLabel lblConfiguration;
693
    private javax.swing.JLabel lblConnectionType;
694
    private javax.swing.JLabel lblExistLogo;
695
    private javax.swing.JLabel lblPassword;
696
    private javax.swing.JLabel lblServerUri;
697
    private javax.swing.JLabel lblUsername;
698
    private javax.swing.JList lstFavourites;
699
    private javax.swing.JMenuItem miExportFavourites;
700
    private javax.swing.JMenuItem miImportFavourites;
701
    private javax.swing.JMenuItem miRemoveFavourite;
702
    private javax.swing.JPanel panEmbedded;
703
    private javax.swing.JPanel panFavourites;
704
    private javax.swing.JPanel panRemote;
705
    private javax.swing.JPopupMenu pmFavourites;
706
    private javax.swing.JTabbedPane tpConnectionType;
707
    private javax.swing.JTextField txtConfiguration;
708
    private javax.swing.JPasswordField txtPassword;
709
    private javax.swing.JTextField txtServerUri;
710
    private javax.swing.JTextField txtUsername;
711
    // End of variables declaration//GEN-END:variables
712
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc