|
| 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 | + |
| 26 | +package com.sun.tools.visualvm.heapviewer.options; |
| 27 | + |
| 28 | +import com.sun.tools.visualvm.core.options.UISupport; |
| 29 | +import com.sun.tools.visualvm.heapviewer.oql.CustomOQLQueries; |
| 30 | +import java.beans.PropertyChangeListener; |
| 31 | +import java.util.List; |
| 32 | +import java.util.Objects; |
| 33 | +import javax.swing.JComponent; |
| 34 | +import javax.swing.SwingUtilities; |
| 35 | +import org.netbeans.modules.profiler.heapwalk.OQLSupport; |
| 36 | +import org.netbeans.spi.options.OptionsPanelController; |
| 37 | +import org.openide.util.HelpCtx; |
| 38 | +import org.openide.util.Lookup; |
| 39 | +import org.openide.util.RequestProcessor; |
| 40 | + |
| 41 | +/** |
| 42 | + * |
| 43 | + * @author Jiri Sedlacek |
| 44 | + */ |
| 45 | +@OptionsPanelController.TopLevelRegistration( |
| 46 | + id = "HeapViewerOptions", |
| 47 | + categoryName = "#HeapViewerOptionsCategory_Name", |
| 48 | + iconBase = "com/sun/tools/visualvm/heapviewer/options/heapViewer32.png", |
| 49 | + position = 1525) |
| 50 | +@org.openide.util.NbBundle.Messages({ |
| 51 | + "HeapViewerOptionsCategory_Name=Heap Viewer" |
| 52 | +}) |
| 53 | +public final class HeapViewerOptionsCategory extends OptionsPanelController { |
| 54 | + |
| 55 | + private static final HelpCtx HELP_CTX = null; |
| 56 | +// private static final HelpCtx HELP_CTX = new HelpCtx("HeapViewerOptions.Help"); // NOI18N |
| 57 | + |
| 58 | + public static final String OPTIONS_HANDLE = "HeapViewerOptions"; // NOI18N |
| 59 | + |
| 60 | + private HeapViewerOptionsPanel settingsPanel; |
| 61 | + private JComponent settingsComponent; |
| 62 | + |
| 63 | + |
| 64 | + private HeapViewerOptionsPanel getPanel() { |
| 65 | + if (settingsPanel == null) settingsPanel = new HeapViewerOptionsPanel(); |
| 66 | + return settingsPanel; |
| 67 | + } |
| 68 | + |
| 69 | + public JComponent getComponent(Lookup lookup) { |
| 70 | + if (settingsComponent == null) settingsComponent = UISupport.createScrollableContainer(getPanel()); |
| 71 | + return settingsComponent; |
| 72 | + } |
| 73 | + |
| 74 | + public HelpCtx getHelpCtx() { |
| 75 | + return HELP_CTX; |
| 76 | + } |
| 77 | + |
| 78 | + public boolean isChanged() { |
| 79 | + if (settingsPanel == null) return false; |
| 80 | + |
| 81 | + List<OQLSupport.Query> master = CustomOQLQueries.instance().list(); |
| 82 | + List<OQLSupport.Query> edited = getPanel().getQueries(); |
| 83 | + |
| 84 | + if (master.size() != edited.size()) return true; |
| 85 | + |
| 86 | + for (int i = 0; i < master.size(); i++) |
| 87 | + if (!sameQuery(master.get(i), edited.get(i))) return true; |
| 88 | + |
| 89 | + return false; |
| 90 | + } |
| 91 | + |
| 92 | + public boolean isValid() { |
| 93 | + return true; |
| 94 | + } |
| 95 | + |
| 96 | + public void applyChanges() { |
| 97 | + if (settingsPanel == null) return; |
| 98 | + CustomOQLQueries.instance().set(getPanel().getQueries()); |
| 99 | + } |
| 100 | + |
| 101 | + public void cancel() { |
| 102 | + } |
| 103 | + |
| 104 | + public void update() { |
| 105 | + new RequestProcessor("OQL Scripts Loader").post(new Runnable() { // NOI18N |
| 106 | + public void run() { |
| 107 | + final List<OQLSupport.Query> queries = CustomOQLQueries.instance().list(); |
| 108 | + SwingUtilities.invokeLater(new Runnable() { |
| 109 | + public void run() { |
| 110 | + getPanel().setQueries(queries); |
| 111 | + } |
| 112 | + }); |
| 113 | + } |
| 114 | + }); |
| 115 | + } |
| 116 | + |
| 117 | + public void addPropertyChangeListener(PropertyChangeListener l) { |
| 118 | + } |
| 119 | + |
| 120 | + public void removePropertyChangeListener(PropertyChangeListener l) { |
| 121 | + } |
| 122 | + |
| 123 | + |
| 124 | + private static boolean sameQuery(OQLSupport.Query query1, OQLSupport.Query query2) { |
| 125 | + if (!Objects.equals(query1.getName(), query2.getName())) return false; |
| 126 | + if (!Objects.equals(query1.getDescription(), query2.getDescription())) return false; |
| 127 | + return true; |
| 128 | + } |
| 129 | + |
| 130 | +} |
0 commit comments