|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
65 | 65 | import org.graalvm.visualvm.heapviewer.model.HeapViewerNodeFilter;
|
66 | 66 | import org.graalvm.visualvm.heapviewer.truffle.TruffleType;
|
67 | 67 | import org.graalvm.visualvm.heapviewer.ui.TreeTableView;
|
| 68 | +import org.graalvm.visualvm.lib.profiler.api.ProfilerDialogs; |
68 | 69 | import org.openide.util.NbBundle;
|
69 | 70 |
|
70 | 71 | /**
|
|
77 | 78 | "TruffleFilterUtils_FilterResults=Filter results ({0})",
|
78 | 79 | "TruffleFilterUtils_MatchCase=Match case",
|
79 | 80 | "TruffleFilterUtils_Close=Close Filter sidebar ({0})",
|
| 81 | + "TruffleFilterUtils_InvalidRegexp=Entered regular expression is invalid:\n{0}", |
80 | 82 | "TruffleFilterUtils_FilterContains=Contains",
|
81 | 83 | "TruffleFilterUtils_FilterNotContains=Does Not Contain",
|
| 84 | + "TruffleFilterUtils_FilterRegExp=Regular Expression", |
82 | 85 | "TruffleFilterUtils_FilterType=Filter type: {0}",
|
83 | 86 | "TruffleFilterUtils_InsertFilter=Insert Defined Filter"
|
84 | 87 | })
|
@@ -113,61 +116,13 @@ public static boolean filter(TreeTableView view, final GenericFilter textFilter,
|
113 | 116 |
|
114 | 117 | view.setViewFilter(new HeapViewerNodeFilter() {
|
115 | 118 | public boolean passes(HeapViewerNode node, Heap heap) {
|
116 |
| -// if (!(node instanceof ClassNode)) return true; |
117 |
| -// |
118 |
| -// JavaClass javaClass = ((ClassNode)node).getJavaClass(); |
119 |
| - |
120 | 119 | String typeName = HeapViewerNode.getValue(node, TruffleType.TYPE_NAME, heap);
|
121 | 120 | return typeName == null ? true : textFilter.passes(typeName);
|
122 |
| -// if (javaClass == null) return true; |
123 |
| -// if (javaClass.getInstancesCount() == 0) return false; |
124 |
| - |
125 |
| -// String className = javaClass.getName(); |
126 |
| -// if (textFilter.getType() != TextFilter.TYPE_REGEXP) return textFilter.passes(className); |
127 |
| -// else { |
128 |
| -// for (String value : textFilter.getValues()) |
129 |
| -// if (isInstanceOf(javaClass, value)) return true; |
130 |
| -// return false; |
131 |
| -// } |
132 | 121 | }
|
133 |
| - |
134 |
| - |
135 |
| -// private boolean isInstanceOf(JavaClass javaClass, String className) { |
136 |
| -// if (javaClass != null) { |
137 |
| -//// JavaClass superCls = javaClass.getSuperClass(); |
138 |
| -// JavaClass cls = javaClass; |
139 |
| -// for (; cls != null; cls = cls.getSuperClass()) |
140 |
| -// if (cls.getName().equals(className)) return true; |
141 |
| -// } |
142 |
| -// return false; |
143 |
| -// } |
144 | 122 | });
|
145 | 123 | return true;
|
146 | 124 | }
|
147 | 125 |
|
148 |
| -// public static void filterSubclasses(String className, JComponent filterPanel) { |
149 |
| -// Object filterString = filterPanel.getClientProperty("FILTER_STRING"); // NOI18N |
150 |
| -// if (filterString instanceof JTextComponent) { |
151 |
| -// ((JTextComponent)filterString).setText(className); |
152 |
| -// } else { |
153 |
| -// return; |
154 |
| -// } |
155 |
| -// |
156 |
| -// Object filterType = filterPanel.getClientProperty("FILTER_TYPE"); // NOI18N |
157 |
| -// if (filterType instanceof FilterType) { |
158 |
| -// ((FilterType)filterType).filterImpl(TextFilter.TYPE_REGEXP, Icons.getIcon(LanguageIcons.CLASS), FILTER_REGEXP); |
159 |
| -// } else { |
160 |
| -// return; |
161 |
| -// } |
162 |
| -// |
163 |
| -// Object filterAction = filterPanel.getClientProperty("FILTER_ACTION"); // NOI18N |
164 |
| -// if (filterAction instanceof AbstractAction) { |
165 |
| -// ((AbstractAction)filterAction).actionPerformed(null); |
166 |
| -// } else { |
167 |
| -// return; |
168 |
| -// } |
169 |
| -// } |
170 |
| - |
171 | 126 | public static JComponent createFilterPanel(final TreeTableView view) {
|
172 | 127 | return createFilterPanel(view, null);
|
173 | 128 | }
|
@@ -238,9 +193,9 @@ protected void fireActionPerformed(ActionEvent event) {
|
238 | 193 | KeyStroke filterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
|
239 | 194 |
|
240 | 195 | final TextFilter activeFilter = new TextFilter() {
|
241 |
| -// protected void handleInvalidFilter(String invalidValue, RuntimeException e) { |
242 |
| -// ProfilerDialogs.displayError(MessageFormat.format(MSG_INVALID_REGEXP, invalidValue)); |
243 |
| -// } |
| 196 | + protected void handleInvalidFilter(String invalidValue, RuntimeException e) { |
| 197 | + ProfilerDialogs.displayError(Bundle.TruffleFilterUtils_InvalidRegexp(invalidValue)); |
| 198 | + } |
244 | 199 | };
|
245 | 200 | final TextFilter currentFilter = new TextFilter();
|
246 | 201 |
|
@@ -314,23 +269,23 @@ protected void fireActionPerformed(ActionEvent e) {
|
314 | 269 | filterImpl(TextFilter.TYPE_EXCLUSIVE, getIcon(), getText());
|
315 | 270 | }
|
316 | 271 | });
|
317 |
| -// popup.add(new JMenuItem(FILTER_REGEXP, Icons.getIcon(LanguageIcons.CLASS)) { |
318 |
| -// protected void fireActionPerformed(ActionEvent e) { |
319 |
| -// super.fireActionPerformed(e); |
320 |
| -// filterImpl(TextFilter.TYPE_REGEXP, getIcon(), getText()); |
321 |
| -// } |
322 |
| -// }); |
| 272 | + popup.add(new JMenuItem(Bundle.TruffleFilterUtils_FilterRegExp(), Icons.getIcon(GeneralIcons.FILTER_REG_EXP)) { |
| 273 | + protected void fireActionPerformed(ActionEvent e) { |
| 274 | + super.fireActionPerformed(e); |
| 275 | + filterImpl(TextFilter.TYPE_REGEXP, getIcon(), getText()); |
| 276 | + } |
| 277 | + }); |
323 | 278 | }
|
324 | 279 | protected void filterImpl(final int type, final Icon icon, final String name) {
|
325 |
| -// if (type == TextFilter.TYPE_REGEXP) { |
326 |
| -// matchCase.setEnabled(false); |
327 |
| -// matchCase.setSelected(false); |
328 |
| -// } else { |
| 280 | + if (type == TextFilter.TYPE_REGEXP) { |
| 281 | + matchCase.setEnabled(false); |
| 282 | + matchCase.setSelected(false); |
| 283 | + } else { |
329 | 284 | if (!matchCase.isEnabled()) {
|
330 | 285 | matchCase.setSelected(currentFilter.isCaseSensitive());
|
331 | 286 | matchCase.setEnabled(true);
|
332 | 287 | }
|
333 |
| -// } |
| 288 | + } |
334 | 289 | SwingUtilities.invokeLater(new Runnable() {
|
335 | 290 | public void run() {
|
336 | 291 | setIcon(icon);
|
|
0 commit comments