View Javadoc
1   /*
2    * Copyright (c) 2003, 2007, 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.
8    *
9    * This code is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12   * version 2 for more details (a copy is included in the LICENSE file that
13   * accompanied this code).
14   *
15   * You should have received a copy of the GNU General Public License version
16   * 2 along with this work; if not, write to the Free Software Foundation,
17   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18   *
19   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20   * or visit www.oracle.com if you need additional information or have any
21   * questions.
22   *
23   */
24  
25  package sun.jvm.hotspot.ui;
26  
27  import java.awt.*;
28  import java.awt.event.*;
29  import java.util.*;
30  import javax.swing.*;
31  import javax.swing.event.*;
32  import sun.jvm.hotspot.debugger.*;
33  import sun.jvm.hotspot.oops.*;
34  import sun.jvm.hotspot.runtime.*;
35  import sun.jvm.hotspot.ui.tree.*;
36  import sun.jvm.hotspot.utilities.soql.*;
37  
38  public class FindByQueryPanel extends SAPanel {
39     private JTextArea           queryEditor;
40     private JEditorPane         objectsEditor;
41     private SOQLEngine          queryEngine;
42  
43     public FindByQueryPanel() {
44        queryEngine = SOQLEngine.getEngine();
45        HyperlinkListener hyperListener = new HyperlinkListener() {
46                           public void hyperlinkUpdate(HyperlinkEvent e) {
47                              if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
48                                 VM vm = VM.getVM();
49                                 OopHandle handle = vm.getDebugger().parseAddress(e.getDescription()).addOffsetToAsOopHandle(0);
50                                 showInspector(vm.getObjectHeap().newOop(handle));
51                              }
52                           }
53                        };
54  
55        objectsEditor = new JEditorPane();
56        objectsEditor.setContentType("text/html");
57        objectsEditor.setEditable(false);
58        objectsEditor.addHyperlinkListener(hyperListener);
59  
60        queryEditor = new JTextArea();
61        JButton queryButton = new JButton("Execute");
62        queryButton.addActionListener(new ActionListener() {
63                                         public void actionPerformed(ActionEvent ae) {
64                                            final StringBuffer buf = new StringBuffer();
65                                            buf.append("<html><body>");
66                                            try {
67                                               queryEngine.executeQuery(queryEditor.getText(),
68                                                          new ObjectVisitor() {
69                                                             public void visit(Object o) {
70                                                                if (o != null && o instanceof JSJavaObject) {
71                                                                   String oopAddr = ((JSJavaObject)o).getOop().getHandle().toString();
72                                                                   buf.append("<a href='");
73                                                                   buf.append(oopAddr);
74                                                                   buf.append("'>");
75                                                                   buf.append(oopAddr);
76                                                                   buf.append("</a>");
77                                                                } else {
78                                                                   buf.append((o == null)? "null" : o.toString());
79                                                                }
80                                                                buf.append("<br>");
81                                                             }
82                                                          });
83  
84                                            } catch (Exception e) {
85                                               e.printStackTrace();
86                                               buf.append("<b>");
87                                               buf.append(e.getMessage());
88                                               buf.append("</b>");
89                                            }
90                                            buf.append("</body></html>");
91                                            objectsEditor.setText(buf.toString());
92                                         }
93                                     });
94  
95        JPanel topPanel = new JPanel();
96        topPanel.setLayout(new BorderLayout());
97        topPanel.add(new JLabel("SOQL Query :"), BorderLayout.WEST);
98        topPanel.add(new JScrollPane(queryEditor), BorderLayout.CENTER);
99        topPanel.add(queryButton, BorderLayout.EAST);
100 
101       JPanel bottomPanel = new JPanel();
102       bottomPanel.setLayout(new BorderLayout());
103       bottomPanel.add(new JScrollPane(objectsEditor), BorderLayout.CENTER);
104 
105       JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, bottomPanel);
106       splitPane.setDividerLocation(0.3);
107 
108       setLayout(new BorderLayout());
109       add(splitPane, BorderLayout.CENTER);
110    }
111 }