43
43
import java .awt .Insets ;
44
44
import java .awt .event .ActionEvent ;
45
45
import java .awt .event .ActionListener ;
46
+ import java .awt .event .ItemEvent ;
46
47
import java .net .MalformedURLException ;
47
48
import java .net .URL ;
48
49
import java .util .Set ;
49
50
import javax .swing .BorderFactory ;
51
+ import javax .swing .Box ;
52
+ import javax .swing .BoxLayout ;
50
53
import javax .swing .JCheckBox ;
51
54
import javax .swing .JLabel ;
55
+ import javax .swing .JPanel ;
52
56
import javax .swing .JPasswordField ;
53
57
import javax .swing .JTextField ;
54
58
import javax .swing .SwingUtilities ;
55
59
import javax .swing .UIManager ;
56
60
import javax .swing .border .Border ;
57
61
import javax .swing .event .DocumentEvent ;
58
62
import javax .swing .event .DocumentListener ;
63
+ import org .graalvm .visualvm .core .options .UISupport ;
59
64
import org .openide .awt .Mnemonics ;
60
65
import org .openide .util .NbBundle ;
66
+ import org .openide .util .NbPreferences ;
61
67
62
68
/**
63
69
* JmxConnectionCustomizer providing the default JMX Connection dialog to enter
66
72
* @author Jiri Sedlacek
67
73
*/
68
74
public class DefaultCustomizer extends JmxConnectionCustomizer {
75
+
76
+ private static final String PROP_CONNECT_IMMEDIATELY = "DefaultJMXCustomizer_prop_connect_immediately" ; // NOI18N
77
+ private static final String PROP_CONNECT_AUTOMATICALLY = "DefaultJMXCustomizer_prop_connect_automatically" ; // NOI18N
78
+
79
+ private static final boolean DEFAULT_CONNECT_IMMEDIATELY = true ;
80
+ private static final boolean DEFAULT_CONNECT_AUTOMATICALLY = true ;
81
+
69
82
70
83
DefaultCustomizer () {
71
84
super (NbBundle .getMessage (DefaultCustomizer .class , "LBL_Default_jmx_connection_name" ), // NOI18N
@@ -97,9 +110,14 @@ public Setup getConnectionSetup(PropertiesPanel customizerPanel) {
97
110
panel .getUsername (), panel .getPassword (), panel .getSaveCredentials ());
98
111
boolean persistent = true ;
99
112
boolean allowInsecure = panel .allowsInsecureConnection ();
113
+
114
+ boolean connectImmediately = panel .isConnectImmediately ();
115
+ NbPreferences .forModule (DefaultCustomizer .class ).putBoolean (PROP_CONNECT_IMMEDIATELY , connectImmediately );
116
+ boolean autoConnect = panel .isConnectAutomatically ();
117
+ NbPreferences .forModule (DefaultCustomizer .class ).putBoolean (PROP_CONNECT_AUTOMATICALLY , autoConnect );
100
118
101
- return new JmxConnectionCustomizer .Setup (connectionString , displayName ,
102
- provider , persistent , allowInsecure );
119
+ return new JmxConnectionCustomizer .Setup (connectionString , displayName , provider , persistent ,
120
+ allowInsecure , connectImmediately , autoConnect );
103
121
}
104
122
105
123
@@ -242,6 +260,14 @@ public final boolean getSaveCredentials() {
242
260
public final boolean allowsInsecureConnection () {
243
261
return noSSLCheckbox .isSelected ();
244
262
}
263
+
264
+ public final boolean isConnectImmediately () {
265
+ return connectImmediatelyChoice .isSelected ();
266
+ }
267
+
268
+ public final boolean isConnectAutomatically () {
269
+ return autoConnectChoice .isSelected ();
270
+ }
245
271
246
272
247
273
private void initDefaults () {
@@ -380,6 +406,16 @@ public void changedUpdate(DocumentEvent e) {
380
406
constraints .anchor = GridBagConstraints .WEST ;
381
407
constraints .insets = new Insets (8 , 5 , 0 , 0 );
382
408
add (displaynameField , constraints );
409
+
410
+ constraints = new GridBagConstraints ();
411
+ constraints .gridx = 0 ;
412
+ constraints .gridy = 3 ;
413
+ constraints .weightx = 1 ;
414
+ constraints .gridwidth = GridBagConstraints .REMAINDER ;
415
+ constraints .fill = GridBagConstraints .HORIZONTAL ;
416
+ constraints .anchor = GridBagConstraints .NORTHWEST ;
417
+ constraints .insets = new Insets (20 , 0 , 0 , 0 );
418
+ add (UISupport .createSectionSeparator (NbBundle .getMessage (DefaultCustomizer .class , "LBL_Caption_Security" )), constraints ); // NOI18N
383
419
384
420
// securityCheckbox
385
421
securityCheckbox = new JCheckBox ();
@@ -392,11 +428,11 @@ public void actionPerformed(ActionEvent e) {
392
428
});
393
429
constraints = new GridBagConstraints ();
394
430
constraints .gridx = 0 ;
395
- constraints .gridy = 3 ;
431
+ constraints .gridy = 4 ;
396
432
constraints .gridwidth = GridBagConstraints .REMAINDER ;
397
433
constraints .fill = GridBagConstraints .NONE ;
398
434
constraints .anchor = GridBagConstraints .WEST ;
399
- constraints .insets = new Insets (15 , 0 , 0 , 0 );
435
+ constraints .insets = new Insets (8 , 0 , 0 , 0 );
400
436
add (securityCheckbox , constraints );
401
437
402
438
// usernameLabel
@@ -405,7 +441,7 @@ public void actionPerformed(ActionEvent e) {
405
441
DefaultCustomizer .class , "LBL_Username" )); // NOI18N
406
442
constraints = new GridBagConstraints ();
407
443
constraints .gridx = 0 ;
408
- constraints .gridy = 4 ;
444
+ constraints .gridy = 5 ;
409
445
constraints .gridwidth = 1 ;
410
446
constraints .fill = GridBagConstraints .NONE ;
411
447
constraints .anchor = GridBagConstraints .EAST ;
@@ -430,7 +466,7 @@ public void changedUpdate(DocumentEvent e) {
430
466
});
431
467
constraints = new GridBagConstraints ();
432
468
constraints .gridx = 1 ;
433
- constraints .gridy = 4 ;
469
+ constraints .gridy = 5 ;
434
470
constraints .gridwidth = GridBagConstraints .REMAINDER ;
435
471
constraints .fill = GridBagConstraints .HORIZONTAL ;
436
472
constraints .anchor = GridBagConstraints .WEST ;
@@ -443,7 +479,7 @@ public void changedUpdate(DocumentEvent e) {
443
479
DefaultCustomizer .class , "LBL_Password" )); // NOI18N
444
480
constraints = new GridBagConstraints ();
445
481
constraints .gridx = 0 ;
446
- constraints .gridy = 5 ;
482
+ constraints .gridy = 6 ;
447
483
constraints .gridwidth = 1 ;
448
484
constraints .fill = GridBagConstraints .NONE ;
449
485
constraints .anchor = GridBagConstraints .EAST ;
@@ -468,7 +504,7 @@ public void changedUpdate(DocumentEvent e) {
468
504
});
469
505
constraints = new GridBagConstraints ();
470
506
constraints .gridx = 1 ;
471
- constraints .gridy = 5 ;
507
+ constraints .gridy = 6 ;
472
508
constraints .gridwidth = GridBagConstraints .REMAINDER ;
473
509
constraints .fill = GridBagConstraints .HORIZONTAL ;
474
510
constraints .anchor = GridBagConstraints .WEST ;
@@ -486,7 +522,7 @@ public void actionPerformed(ActionEvent e) {
486
522
});
487
523
constraints = new GridBagConstraints ();
488
524
constraints .gridx = 0 ;
489
- constraints .gridy = 6 ;
525
+ constraints .gridy = 7 ;
490
526
constraints .gridwidth = GridBagConstraints .REMAINDER ;
491
527
constraints .fill = GridBagConstraints .HORIZONTAL ;
492
528
constraints .anchor = GridBagConstraints .EAST ;
@@ -504,17 +540,68 @@ public void actionPerformed(ActionEvent e) {
504
540
});
505
541
constraints = new GridBagConstraints ();
506
542
constraints .gridx = 0 ;
507
- constraints .gridy = 7 ;
543
+ constraints .gridy = 8 ;
508
544
constraints .gridwidth = GridBagConstraints .REMAINDER ;
509
545
constraints .fill = GridBagConstraints .HORIZONTAL ;
510
546
constraints .anchor = GridBagConstraints .WEST ;
511
547
constraints .insets = new Insets (15 , 0 , 0 , 0 );
512
548
add (noSSLCheckbox , constraints );
549
+
550
+ // --- connection options ------------------------------------------
551
+ constraints = new GridBagConstraints ();
552
+ constraints .gridx = 0 ;
553
+ constraints .gridy = 9 ;
554
+ constraints .weightx = 1 ;
555
+ constraints .gridwidth = GridBagConstraints .REMAINDER ;
556
+ constraints .fill = GridBagConstraints .HORIZONTAL ;
557
+ constraints .anchor = GridBagConstraints .NORTHWEST ;
558
+ constraints .insets = new Insets (20 , 0 , 0 , 0 );
559
+ add (UISupport .createSectionSeparator (NbBundle .getMessage (DefaultCustomizer .class , "LBL_Caption_Connection" )), constraints ); // NOI18N
560
+
561
+ JPanel connectOptions = new JPanel (null );
562
+ connectOptions .setLayout (new BoxLayout (connectOptions , BoxLayout .LINE_AXIS ));
563
+ constraints = new GridBagConstraints ();
564
+ constraints .gridx = 0 ;
565
+ constraints .gridy = 10 ;
566
+ constraints .gridwidth = GridBagConstraints .REMAINDER ;
567
+ constraints .fill = GridBagConstraints .HORIZONTAL ;
568
+ constraints .anchor = GridBagConstraints .WEST ;
569
+ constraints .insets = new Insets (8 , 0 , 0 , 0 );
570
+ add (connectOptions , constraints );
571
+
572
+ connectImmediatelyChoice = new JCheckBox () {
573
+ protected void fireItemStateChanged (ItemEvent e ) {
574
+ super .fireItemStateChanged (e );
575
+ if (autoConnectChoice != null ) {
576
+ autoConnectChoice .setEnabled (isSelected ());
577
+ }
578
+ }
579
+ };
580
+ Mnemonics .setLocalizedText (connectImmediatelyChoice , NbBundle .getMessage (DefaultCustomizer .class , "LBL_Connect_Immediately" )); // NOI18N
581
+ connectImmediatelyChoice .setToolTipText (NbBundle .getMessage (DefaultCustomizer .class , "TTP_Connect_Immediately" )); // NOI18N
582
+ connectOptions .add (connectImmediatelyChoice );
583
+
584
+ connectOptions .add (Box .createHorizontalStrut (8 ));
585
+
586
+ autoConnectChoice = new JCheckBox () {
587
+ public void setEnabled (boolean enabled ) {
588
+ super .setEnabled (enabled );
589
+ if (!enabled ) setSelected (false );
590
+ }
591
+ };
592
+ Mnemonics .setLocalizedText (autoConnectChoice , NbBundle .getMessage (DefaultCustomizer .class , "LBL_Auto_Connect" )); // NOI18N
593
+ autoConnectChoice .setToolTipText (NbBundle .getMessage (DefaultCustomizer .class , "TTP_Auto_Connect" )); // NOI18N
594
+ connectOptions .add (autoConnectChoice );
595
+
596
+ connectImmediatelyChoice .setSelected (NbPreferences .forModule (DefaultCustomizer .class ).getBoolean (PROP_CONNECT_IMMEDIATELY , DEFAULT_CONNECT_IMMEDIATELY ));
597
+ if (connectImmediatelyChoice .isSelected ()) autoConnectChoice .setSelected (NbPreferences .forModule (DefaultCustomizer .class ).getBoolean (PROP_CONNECT_AUTOMATICALLY , DEFAULT_CONNECT_AUTOMATICALLY ));
598
+ else autoConnectChoice .setEnabled (false );
599
+ // -----------------------------------------------------------------
513
600
514
601
// spacer
515
602
constraints = new GridBagConstraints ();
516
603
constraints .gridx = 0 ;
517
- constraints .gridy = 8 ;
604
+ constraints .gridy = 11 ;
518
605
constraints .weightx = 1 ;
519
606
constraints .weighty = 1 ;
520
607
constraints .gridwidth = GridBagConstraints .REMAINDER ;
@@ -553,6 +640,8 @@ public void actionPerformed(ActionEvent e) {
553
640
private JPasswordField passwordField ;
554
641
private JCheckBox saveCheckbox ;
555
642
private JCheckBox noSSLCheckbox ;
643
+ private JCheckBox connectImmediatelyChoice ;
644
+ private JCheckBox autoConnectChoice ;
556
645
}
557
646
558
647
0 commit comments