Skip to content

Commit d0cdae1

Browse files
committed
[API change] Bugfix #603 - added GlobalPreferences.set/getDoNotShowAgain, implemented persistence for decision on keeping/deleting unresolved hosts/jmx connections
1 parent 57ade6a commit d0cdae1

File tree

8 files changed

+117
-31
lines changed

8 files changed

+117
-31
lines changed

visualvm/core/manifest.mf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Manifest-Version: 1.0
2-
AutoUpdate-Show-In-Client: false
3-
AutoUpdate-Essential-Module: true
4-
OpenIDE-Module: com.sun.tools.visualvm.core/0
5-
OpenIDE-Module-Layer: com/sun/tools/visualvm/core/layer.xml
6-
OpenIDE-Module-Localizing-Bundle: com/sun/tools/visualvm/core/Bundle.properties
7-
OpenIDE-Module-Install: com/sun/tools/visualvm/core/Install.class
8-
OpenIDE-Module-Specification-Version: 1.5
9-
1+
Manifest-Version: 1.0
2+
AutoUpdate-Show-In-Client: false
3+
AutoUpdate-Essential-Module: true
4+
OpenIDE-Module: com.sun.tools.visualvm.core/0
5+
OpenIDE-Module-Layer: com/sun/tools/visualvm/core/layer.xml
6+
OpenIDE-Module-Localizing-Bundle: com/sun/tools/visualvm/core/Bundle.properties
7+
OpenIDE-Module-Install: com/sun/tools/visualvm/core/Install.class
8+
OpenIDE-Module-Specification-Version: 1.6
9+

visualvm/core/src/com/sun/tools/visualvm/core/options/GlobalPreferences.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.util.prefs.PreferenceChangeEvent;
4141
import java.util.prefs.PreferenceChangeListener;
4242
import java.util.prefs.Preferences;
43+
import org.netbeans.modules.profiler.api.ProfilerIDESettings;
4344
import org.openide.util.NbPreferences;
4445

4546
/**
@@ -288,4 +289,33 @@ private void setPollingInterval(String property, int value) {
288289
prefs.putInt(property, value);
289290
}
290291
}
292+
293+
294+
/**
295+
* Allows to set or clear persistent do not show again value associated with given notification identified by the
296+
* provided key.
297+
*
298+
* @param key A key that uniquely identifies the notification
299+
* @param value The value that should be used without displaying the notification or null to clear the Do not show
300+
* again (i.e. start displaying the notifications again.
301+
*
302+
* @since VisualVM 1.3.9
303+
*/
304+
public void setDoNotShowAgain(String key, String value) {
305+
ProfilerIDESettings.getInstance().setDoNotShowAgain(key, value);
306+
}
307+
308+
/**
309+
* Allows to get persistent do not show again value associated with given notification identified by the provided key.
310+
*
311+
* @param key A key that uniquely identifies the notification
312+
* @return The value that should be used without displaying the notification or null if the notification should
313+
* be displayed
314+
*
315+
* @since VisualVM 1.3.9
316+
*/
317+
public String getDoNotShowAgain(String key) {
318+
return ProfilerIDESettings.getInstance().getDoNotShowAgain(key);
319+
}
320+
291321
}

visualvm/host/nbproject/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<compile-dependency/>
1313
<run-dependency>
1414
<release-version>0</release-version>
15-
<specification-version>1.4</specification-version>
15+
<specification-version>1.6</specification-version>
1616
</run-dependency>
1717
</dependency>
1818
<dependency>

visualvm/host/src/com/sun/tools/visualvm/host/impl/Bundle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ DESCR_HostProperties=Basic host information
4747
LBL_Resolving=resolving...
4848
LBL_DnsName=DNS name\:
4949
LBL_IpAddress=IP address\:
50+
51+
LBL_RememberAction=&Remember selected action
52+
TTP_RememberAction=Select to perform the action automatically on subsequent sessions. Can be reset using Tools | Options | General | Reset Do Not Show Again confirmations.

visualvm/host/src/com/sun/tools/visualvm/host/impl/HostProvider.java

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.sun.tools.visualvm.core.explorer.ExplorerSupport;
3939
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptor;
4040
import com.sun.tools.visualvm.core.datasource.descriptor.DataSourceDescriptorFactory;
41+
import com.sun.tools.visualvm.core.options.GlobalPreferences;
4142
import java.awt.BorderLayout;
4243
import java.io.File;
4344
import java.io.FilenameFilter;
@@ -49,6 +50,8 @@
4950
import java.util.concurrent.Semaphore;
5051
import java.util.logging.Level;
5152
import java.util.logging.Logger;
53+
import javax.swing.BorderFactory;
54+
import javax.swing.JCheckBox;
5255
import javax.swing.JLabel;
5356
import javax.swing.JList;
5457
import javax.swing.JPanel;
@@ -58,6 +61,7 @@
5861
import org.netbeans.api.progress.ProgressHandleFactory;
5962
import org.openide.DialogDisplayer;
6063
import org.openide.NotifyDescriptor;
64+
import org.openide.awt.Mnemonics;
6165
import org.openide.util.NbBundle;
6266
import org.openide.util.RequestProcessor;
6367
import org.openide.windows.WindowManager;
@@ -77,6 +81,8 @@ public class HostProvider {
7781
private static final String CURRENT_SNAPSHOT_VERSION = CURRENT_SNAPSHOT_VERSION_MAJOR + SNAPSHOT_VERSION_DIVIDER + CURRENT_SNAPSHOT_VERSION_MINOR;
7882

7983
private static final String PROPERTY_HOSTNAME = "prop_hostname"; // NOI18N
84+
85+
private static final String DNSA_KEY = "HostProvider_NotifyUnresolved"; // NOI18N
8086

8187
private static InetAddress localhostAddress2;
8288

@@ -305,16 +311,35 @@ public boolean accept(File dir, String name) {
305311
private static void notifyUnresolvedHosts(final Set<File> unresolvedHostsF, final Set<String> unresolvedHostsS) {
306312
RequestProcessor.getDefault().post(new Runnable() {
307313
public void run() {
308-
JPanel messagePanel = new JPanel(new BorderLayout(5, 5));
309-
messagePanel.add(new JLabel(NbBundle.getMessage(HostProvider.class, "MSG_Unresolved_Hosts")), BorderLayout.NORTH); // NOI18N
310-
JList list = new JList(unresolvedHostsS.toArray());
311-
list.setVisibleRowCount(4);
312-
messagePanel.add(new JScrollPane(list), BorderLayout.CENTER);
313-
NotifyDescriptor dd = new NotifyDescriptor(
314-
messagePanel, NbBundle.getMessage(HostProvider.class, "Title_Unresolved_Hosts"), // NOI18N
315-
NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.ERROR_MESSAGE,
316-
null, NotifyDescriptor.YES_OPTION);
317-
if (DialogDisplayer.getDefault().notify(dd) == NotifyDescriptor.NO_OPTION)
314+
String s = GlobalPreferences.sharedInstance().getDoNotShowAgain(DNSA_KEY);
315+
Boolean b = s == null ? null : Boolean.parseBoolean(s);
316+
317+
if (b == null) {
318+
JPanel messagePanel = new JPanel(new BorderLayout(5, 5));
319+
messagePanel.add(new JLabel(NbBundle.getMessage(HostProvider.class, "MSG_Unresolved_Hosts")), BorderLayout.NORTH); // NOI18N
320+
JList list = new JList(unresolvedHostsS.toArray());
321+
list.setVisibleRowCount(4);
322+
messagePanel.add(new JScrollPane(list), BorderLayout.CENTER);
323+
JCheckBox dnsa = new JCheckBox();
324+
Mnemonics.setLocalizedText(dnsa, NbBundle.getMessage(HostProvider.class, "LBL_RememberAction")); // NOI18N
325+
dnsa.setToolTipText(NbBundle.getMessage(HostProvider.class, "TTP_RememberAction")); // NOI18N
326+
JPanel p = new JPanel(new BorderLayout());
327+
p.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 20));
328+
p.add(dnsa, BorderLayout.WEST);
329+
messagePanel.add(p, BorderLayout.SOUTH);
330+
NotifyDescriptor dd = new NotifyDescriptor(
331+
messagePanel, NbBundle.getMessage(HostProvider.class, "Title_Unresolved_Hosts"), // NOI18N
332+
NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.ERROR_MESSAGE,
333+
null, NotifyDescriptor.YES_OPTION);
334+
Object ret = DialogDisplayer.getDefault().notify(dd);
335+
336+
if (ret == NotifyDescriptor.NO_OPTION) b = Boolean.FALSE;
337+
else if (ret == NotifyDescriptor.YES_OPTION) b = Boolean.TRUE;
338+
339+
if (dnsa.isSelected() && b != null) GlobalPreferences.sharedInstance().setDoNotShowAgain(DNSA_KEY, b.toString());
340+
}
341+
342+
if (Boolean.FALSE.equals(b))
318343
for (File file : unresolvedHostsF) Utils.delete(file, true);
319344

320345
unresolvedHostsF.clear();

visualvm/jmx/nbproject/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<compile-dependency/>
2222
<run-dependency>
2323
<release-version>0</release-version>
24-
<specification-version>1.4</specification-version>
24+
<specification-version>1.6</specification-version>
2525
</run-dependency>
2626
</dependency>
2727
<dependency>

visualvm/jmx/src/com/sun/tools/visualvm/jmx/impl/Bundle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ MSG_Insecure_SSL=<html><b>The connection to {0}<br>could not be made using SSL.
6969
Note that username and password will be sent in plain text.<html>
7070

7171
Retry_Insecure_SSL=&Do not require SSL for this connection
72+
73+
LBL_RememberAction=&Remember selected action
74+
TTP_RememberAction=Select to perform the action automatically on subsequent sessions. Can be reset using Tools | Options | General | Reset Do Not Show Again confirmations.

visualvm/jmx/src/com/sun/tools/visualvm/jmx/impl/JmxApplicationProvider.java

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.sun.tools.visualvm.core.datasupport.DataChangeListener;
4040
import com.sun.tools.visualvm.core.datasupport.Stateful;
4141
import com.sun.tools.visualvm.core.datasupport.Utils;
42+
import com.sun.tools.visualvm.core.options.GlobalPreferences;
4243
import com.sun.tools.visualvm.jmx.JmxApplicationException;
4344
import com.sun.tools.visualvm.jmx.JmxApplicationsSupport;
4445
import com.sun.tools.visualvm.tools.jmx.JmxModel;
@@ -60,12 +61,15 @@
6061
import java.util.Map;
6162
import java.util.Set;
6263
import javax.management.remote.JMXServiceURL;
64+
import javax.swing.BorderFactory;
65+
import javax.swing.JCheckBox;
6366
import javax.swing.JLabel;
6467
import javax.swing.JList;
6568
import javax.swing.JPanel;
6669
import javax.swing.JScrollPane;
6770
import org.openide.DialogDisplayer;
6871
import org.openide.NotifyDescriptor;
72+
import org.openide.awt.Mnemonics;
6973
import org.openide.util.NbBundle;
7074
import org.openide.util.RequestProcessor;
7175
import org.openide.windows.WindowManager;
@@ -105,6 +109,8 @@ public class JmxApplicationProvider {
105109
private static final String PROPERTIES_FILE = "jmxapplication" + Storage.DEFAULT_PROPERTIES_EXT; // NOI18N
106110
static final String JMX_SUFFIX = ".jmx"; // NOI18N
107111

112+
private static final String DNSA_KEY = "JMXApplicationProvider_NotifyUnresolved"; // NOI18N
113+
108114

109115
private volatile boolean trackingNewHosts;
110116
private Map<String, Set<Storage>> persistedApplications =
@@ -479,16 +485,35 @@ public void run() {
479485
private static void notifyUnresolvedApplications(final Set<String> failedHostsN, final Set<Storage> failedHostsS) {
480486
RequestProcessor.getDefault().post(new Runnable() {
481487
public void run() {
482-
JPanel messagePanel = new JPanel(new BorderLayout(5, 5));
483-
messagePanel.add(new JLabel(NbBundle.getMessage(JmxApplicationProvider.class, "MSG_Unresolved_JMX")), BorderLayout.NORTH); // NOI18N
484-
JList list = new JList(failedHostsN.toArray());
485-
list.setVisibleRowCount(4);
486-
messagePanel.add(new JScrollPane(list), BorderLayout.CENTER);
487-
NotifyDescriptor dd = new NotifyDescriptor(
488-
messagePanel, NbBundle.getMessage(JmxApplicationProvider.class, "Title_Unresolved_JMX"), // NOI18N
489-
NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.ERROR_MESSAGE,
490-
null, NotifyDescriptor.YES_OPTION);
491-
if (DialogDisplayer.getDefault().notify(dd) == NotifyDescriptor.NO_OPTION)
488+
String s = GlobalPreferences.sharedInstance().getDoNotShowAgain(DNSA_KEY);
489+
Boolean b = s == null ? null : Boolean.parseBoolean(s);
490+
491+
if (b == null) {
492+
JPanel messagePanel = new JPanel(new BorderLayout(5, 5));
493+
messagePanel.add(new JLabel(NbBundle.getMessage(JmxApplicationProvider.class, "MSG_Unresolved_JMX")), BorderLayout.NORTH); // NOI18N
494+
JList list = new JList(failedHostsN.toArray());
495+
list.setVisibleRowCount(4);
496+
messagePanel.add(new JScrollPane(list), BorderLayout.CENTER);
497+
JCheckBox dnsa = new JCheckBox();
498+
Mnemonics.setLocalizedText(dnsa, NbBundle.getMessage(JmxApplicationProvider.class, "LBL_RememberAction")); // NOI18N
499+
dnsa.setToolTipText(NbBundle.getMessage(JmxApplicationProvider.class, "TTP_RememberAction")); // NOI18N
500+
JPanel p = new JPanel(new BorderLayout());
501+
p.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 20));
502+
p.add(dnsa, BorderLayout.WEST);
503+
messagePanel.add(p, BorderLayout.SOUTH);
504+
NotifyDescriptor dd = new NotifyDescriptor(
505+
messagePanel, NbBundle.getMessage(JmxApplicationProvider.class, "Title_Unresolved_JMX"), // NOI18N
506+
NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.ERROR_MESSAGE,
507+
null, NotifyDescriptor.YES_OPTION);
508+
Object ret = DialogDisplayer.getDefault().notify(dd);
509+
510+
if (ret == NotifyDescriptor.NO_OPTION) b = Boolean.FALSE;
511+
else if (ret == NotifyDescriptor.YES_OPTION) b = Boolean.TRUE;
512+
513+
if (dnsa.isSelected() && b != null) GlobalPreferences.sharedInstance().setDoNotShowAgain(DNSA_KEY, b.toString());
514+
}
515+
516+
if (Boolean.FALSE.equals(b))
492517
for (Storage storage : failedHostsS) {
493518
File appStorage = storage.getDirectory();
494519
if (appStorage.isDirectory()) Utils.delete(appStorage, true);

0 commit comments

Comments
 (0)