Skip to content

Commit 494f968

Browse files
jisedlacthurka
authored andcommitted
API for customizing context results menu
1 parent 949be7e commit 494f968

File tree

14 files changed

+316
-115
lines changed

14 files changed

+316
-115
lines changed

visualvm/profiler/src/com/sun/tools/visualvm/profiler/ApplicationProfilerView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public void actionPerformed(ActionEvent e) {
265265
// }
266266

267267
private ProfilingResultsSupport.ResultsView getResultsView(boolean cpu) {
268-
return cpu ? new CPULivePanel() : new MemoryLivePanel();
268+
return cpu ? new CPULivePanel(application) : new MemoryLivePanel(application);
269269
}
270270

271271
private void handleCPUProfiling() {

visualvm/profiler/src/com/sun/tools/visualvm/profiler/CPULivePanel.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
*/
2525
package com.sun.tools.visualvm.profiler;
2626

27+
import com.sun.tools.visualvm.application.Application;
28+
import com.sun.tools.visualvm.profiling.actions.ProfilerResultsAction;
2729
import java.awt.BorderLayout;
2830
import java.awt.event.ActionEvent;
2931
import java.awt.event.ItemEvent;
3032
import javax.swing.Icon;
3133
import javax.swing.JButton;
3234
import javax.swing.JLabel;
33-
import javax.swing.JPanel;
3435
import javax.swing.JToggleButton;
3536
import javax.swing.SwingUtilities;
3637
import org.netbeans.lib.profiler.client.ClientUtils;
@@ -80,28 +81,20 @@ class CPULivePanel extends ProfilingResultsSupport.ResultsView {
8081
private ProfilingResultsSupport.ResultsResetter resetter;
8182

8283

83-
CPULivePanel() {
84+
CPULivePanel(Application application) {
8485
setLayout(new BorderLayout());
8586
setOpaque(false);
8687

87-
add(getToolbar().getComponent(), BorderLayout.NORTH);
88-
add(getResultsUI(), BorderLayout.CENTER);
88+
initUI(application);
89+
90+
add(toolbar.getComponent(), BorderLayout.NORTH);
91+
add(cpuView, BorderLayout.CENTER);
8992
}
9093

9194

9295

9396
// --- API implementation --------------------------------------------------
9497

95-
ProfilerToolbar getToolbar() {
96-
if (toolbar == null) initUI();
97-
return toolbar;
98-
}
99-
100-
JPanel getResultsUI() {
101-
if (cpuView == null) initUI();
102-
return cpuView;
103-
}
104-
10598
boolean hasResultsUI() {
10699
return cpuView != null;
107100
}
@@ -162,7 +155,7 @@ void cleanup() {
162155
private JToggleButton[] toggles;
163156

164157

165-
private void initUI() {
158+
private void initUI(Application application) {
166159

167160
assert SwingUtilities.isEventDispatchThread();
168161

@@ -186,6 +179,12 @@ private void initUI() {
186179
protected boolean showSourceSupported() {
187180
return GoToSource.isAvailable();
188181
}
182+
protected boolean profileMethodSupported() {
183+
return false;
184+
}
185+
protected boolean profileClassSupported() {
186+
return false;
187+
}
189188
protected void showSource(ClientUtils.SourceCodeSelection value) {
190189
// Lookup.Provider project = getProject();
191190
Lookup.Provider project = null;
@@ -222,8 +221,8 @@ protected void foundInReverseCalls() {
222221
toggles[2].setSelected(true);
223222
}
224223
};
225-
226224
cpuView.putClientProperty("HelpCtx.Key", "ProfileMethods.HelpCtx"); // NOI18N
225+
cpuView.putClientProperty(ProfilerResultsAction.PROP_APPLICATION, application);
227226

228227
updater = new LiveCPUViewUpdater(cpuView, Profiler.getDefault().getTargetAppRunner().getProfilerClient());
229228
resetter = ProfilingResultsSupport.ResultsResetter.registerView(this);
@@ -424,7 +423,7 @@ void refreshResults() {
424423
try {
425424
refreshData();
426425
} catch (ClientUtils.TargetAppOrVMTerminated ex) {
427-
Exceptions.printStackTrace(ex);
426+
cleanup();
428427
}
429428
}
430429

visualvm/profiler/src/com/sun/tools/visualvm/profiler/MemoryLivePanel.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
*/
2525
package com.sun.tools.visualvm.profiler;
2626

27+
import com.sun.tools.visualvm.application.Application;
28+
import com.sun.tools.visualvm.profiling.actions.ProfilerResultsAction;
2729
import java.awt.BorderLayout;
2830
import java.awt.event.ActionEvent;
2931
import java.awt.event.ItemEvent;
3032
import javax.swing.Icon;
3133
import javax.swing.JButton;
3234
import javax.swing.JLabel;
33-
import javax.swing.JPanel;
3435
import javax.swing.JToggleButton;
3536
import javax.swing.SwingUtilities;
3637
import org.netbeans.lib.profiler.client.ClientUtils;
@@ -70,28 +71,20 @@ class MemoryLivePanel extends ProfilingResultsSupport.ResultsView {
7071
private ProfilingResultsSupport.ResultsResetter resetter;
7172

7273

73-
MemoryLivePanel() {
74+
MemoryLivePanel(Application application) {
7475
setLayout(new BorderLayout());
7576
setOpaque(false);
7677

77-
add(getToolbar().getComponent(), BorderLayout.NORTH);
78-
add(getResultsUI(), BorderLayout.CENTER);
78+
initUI(application);
79+
80+
add(toolbar.getComponent(), BorderLayout.NORTH);
81+
add(memoryView, BorderLayout.CENTER);
7982
}
8083

8184

8285

8386
// --- API implementation --------------------------------------------------
8487

85-
ProfilerToolbar getToolbar() {
86-
if (toolbar == null) initUI();
87-
return toolbar;
88-
}
89-
90-
JPanel getResultsUI() {
91-
if (memoryView == null) initUI();
92-
return memoryView;
93-
}
94-
9588
boolean hasResultsUI() {
9689
return memoryView != null;
9790
}
@@ -152,7 +145,7 @@ void cleanup() {
152145
private boolean popupPause;
153146

154147

155-
private void initUI() {
148+
private void initUI(Application application) {
156149

157150
assert SwingUtilities.isEventDispatchThread();
158151

@@ -165,6 +158,9 @@ private void initUI() {
165158
protected boolean showSourceSupported() {
166159
return GoToSource.isAvailable();
167160
}
161+
protected boolean profileClassSupported() {
162+
return false;
163+
}
168164
protected void showSource(ClientUtils.SourceCodeSelection value) {
169165
Lookup.Provider project = null;
170166
String className = value.getClassName();
@@ -188,8 +184,8 @@ protected void popupHidden() {
188184
}
189185
}
190186
};
191-
192187
memoryView.putClientProperty("HelpCtx.Key", "ProfileObjects.HelpCtx"); // NOI18N
188+
memoryView.putClientProperty(ProfilerResultsAction.PROP_APPLICATION, application);
193189

194190
updater = new LiveMemoryViewUpdater(memoryView, Profiler.getDefault().getTargetAppRunner().getProfilerClient());
195191
resetter = ProfilingResultsSupport.ResultsResetter.registerView(this);
@@ -292,7 +288,7 @@ void refreshResults() {
292288
try {
293289
refreshData();
294290
} catch (ClientUtils.TargetAppOrVMTerminated ex) {
295-
Exceptions.printStackTrace(ex);
291+
cleanup();
296292
}
297293
}
298294

visualvm/profiling/manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ AutoUpdate-Essential-Module: true
55
OpenIDE-Module-Layer: com/sun/tools/visualvm/profiling/resources/layer.xml
66
OpenIDE-Module-Install: com/sun/tools/visualvm/profiling/Installer.class
77
OpenIDE-Module-Localizing-Bundle: com/sun/tools/visualvm/profiling/Bundle.properties
8-
OpenIDE-Module-Specification-Version: 1.3
8+
OpenIDE-Module-Specification-Version: 1.4
99

visualvm/profiling/nbproject/project.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@
6868
<specification-version>1.10.1</specification-version>
6969
</run-dependency>
7070
</dependency>
71+
<dependency>
72+
<code-name-base>org.netbeans.lib.profiler.ui</code-name-base>
73+
<build-prerequisite/>
74+
<compile-dependency/>
75+
<run-dependency>
76+
<release-version>1</release-version>
77+
<specification-version>1.143</specification-version>
78+
</run-dependency>
79+
</dependency>
7180
<dependency>
7281
<code-name-base>org.netbeans.modules.options.api</code-name-base>
7382
<build-prerequisite/>
@@ -83,7 +92,7 @@
8392
<compile-dependency/>
8493
<run-dependency>
8594
<release-version>3</release-version>
86-
<specification-version>3.28</specification-version>
95+
<specification-version>3.29</specification-version>
8796
</run-dependency>
8897
</dependency>
8998
<dependency>
@@ -97,9 +106,11 @@
97106
</dependency>
98107
<dependency>
99108
<code-name-base>org.netbeans.modules.profiler.snaptracer</code-name-base>
109+
<build-prerequisite/>
110+
<compile-dependency/>
100111
<run-dependency>
101112
<release-version>1</release-version>
102-
<specification-version>1.8.1</specification-version>
113+
<specification-version>1.25</specification-version>
103114
</run-dependency>
104115
</dependency>
105116
<dependency>
@@ -179,6 +190,8 @@
179190
<friend>com.sun.tools.visualvm.profiler</friend>
180191
<friend>com.sun.tools.visualvm.profiler.startup</friend>
181192
<friend>com.sun.tools.visualvm.sampler</friend>
193+
<friend>org.graalvm.visualizer.dumpmethod</friend>
194+
<package>com.sun.tools.visualvm.profiling.actions</package>
182195
<package>com.sun.tools.visualvm.profiling.presets</package>
183196
<package>com.sun.tools.visualvm.profiling.snapshot</package>
184197
</friend-packages>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.sun.tools.visualvm.profiling.actions;
26+
27+
import com.sun.tools.visualvm.application.Application;
28+
29+
/**
30+
*
31+
* @author Jiri Sedlacek
32+
*/
33+
public final class ProfiledSourceSelection {
34+
35+
private final Application application;
36+
37+
private final String className;
38+
private final String methodName;
39+
private final String methodSignature;
40+
41+
42+
ProfiledSourceSelection(Application application, String className, String methodName, String methodSignature) {
43+
this.application = application;
44+
45+
this.className = className;
46+
this.methodName = methodName;
47+
this.methodSignature = methodSignature;
48+
}
49+
50+
51+
public final Application getApplication() { return application; }
52+
53+
public final String getClassName() { return className; }
54+
55+
public final String getMethodName() { return methodName; }
56+
57+
public final String getMethodSignature() { return methodSignature; }
58+
59+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.sun.tools.visualvm.profiling.actions;
26+
27+
import com.sun.tools.visualvm.application.Application;
28+
import java.util.ArrayList;
29+
import java.util.Collection;
30+
import java.util.Collections;
31+
import java.util.List;
32+
import javax.swing.JComponent;
33+
import javax.swing.JMenuItem;
34+
import org.netbeans.lib.profiler.client.ClientUtils;
35+
import org.netbeans.lib.profiler.ui.cpu.CPUView;
36+
import org.netbeans.lib.profiler.ui.cpu.LiveCPUView;
37+
import org.netbeans.lib.profiler.ui.memory.LiveMemoryView;
38+
import org.netbeans.lib.profiler.ui.results.DataView;
39+
import org.openide.util.Lookup;
40+
import org.openide.util.lookup.ServiceProvider;
41+
42+
/**
43+
*
44+
* @author Jiri Sedlacek
45+
*/
46+
class ProfilerActionsSupport {
47+
48+
@ServiceProvider(service=DataView.PopupCustomizer.class, position=100)
49+
public static final class ResultsAction extends DataView.PopupCustomizer {
50+
51+
public JMenuItem[] getMenuItems(JComponent invoker, DataView dv, Object value, ClientUtils.SourceCodeSelection scs) {
52+
Collection<? extends ProfilerPopupCustomizer> customizers =
53+
Lookup.getDefault().lookupAll(ProfilerPopupCustomizer.class);
54+
55+
if (customizers.isEmpty()) return null;
56+
57+
ProfilerPopupCustomizer.View view;
58+
ProfilerPopupCustomizer.Mode mode;
59+
60+
if (dv instanceof CPUView) {
61+
view = ProfilerPopupCustomizer.View.CPU;
62+
mode = invoker instanceof LiveCPUView ?
63+
ProfilerPopupCustomizer.Mode.LIVE :
64+
ProfilerPopupCustomizer.Mode.SNAPSHOT;
65+
} else {
66+
view = ProfilerPopupCustomizer.View.MEMORY;
67+
mode = invoker instanceof LiveMemoryView ?
68+
ProfilerPopupCustomizer.Mode.LIVE :
69+
ProfilerPopupCustomizer.Mode.SNAPSHOT;
70+
}
71+
72+
Object _application = invoker.getClientProperty(ProfilerResultsAction.PROP_APPLICATION);
73+
Application application = _application instanceof Application ? (Application)_application : null;
74+
75+
String className = scs == null ? null : scs.getClassName();
76+
String methodName = scs == null ? null : scs.getMethodName();
77+
String methodSignature = scs == null ? null : scs.getMethodSignature();
78+
79+
ProfiledSourceSelection pss = new ProfiledSourceSelection(application, className, methodName, methodSignature);
80+
81+
List<JMenuItem> menuItems = new ArrayList(customizers.size());
82+
83+
for (ProfilerPopupCustomizer customizer : customizers) {
84+
if (customizer.supportsDataView(view, mode)) {
85+
JMenuItem[] items = customizer.getMenuItems(pss, view, mode);
86+
if (items != null) Collections.addAll(menuItems, items);
87+
}
88+
}
89+
90+
return menuItems.isEmpty() ? null : menuItems.toArray(new JMenuItem[0]);
91+
}
92+
93+
}
94+
95+
}

0 commit comments

Comments
 (0)