768
|
1 |
/*
|
|
2 |
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
package com.sun.hotspot.igv.coordinator;
|
|
25 |
|
|
26 |
import com.sun.hotspot.igv.coordinator.actions.ImportAction;
|
|
27 |
import com.sun.hotspot.igv.coordinator.actions.RemoveAction;
|
|
28 |
import com.sun.hotspot.igv.coordinator.actions.RemoveAllAction;
|
|
29 |
import com.sun.hotspot.igv.coordinator.actions.SaveAllAction;
|
|
30 |
import com.sun.hotspot.igv.coordinator.actions.SaveAsAction;
|
|
31 |
import com.sun.hotspot.igv.coordinator.actions.StructuredViewAction;
|
|
32 |
import com.sun.hotspot.igv.data.GraphDocument;
|
|
33 |
import com.sun.hotspot.igv.data.ChangedListener;
|
|
34 |
import com.sun.hotspot.igv.data.Group;
|
|
35 |
import com.sun.hotspot.igv.data.services.GroupCallback;
|
|
36 |
import com.sun.hotspot.igv.data.services.GroupOrganizer;
|
|
37 |
import com.sun.hotspot.igv.data.services.GroupReceiver;
|
|
38 |
import java.awt.BorderLayout;
|
|
39 |
import java.awt.Component;
|
|
40 |
import java.io.IOException;
|
|
41 |
import java.io.ObjectInput;
|
|
42 |
import java.io.ObjectOutput;
|
|
43 |
import java.io.Serializable;
|
|
44 |
import java.util.ArrayList;
|
|
45 |
import java.util.Collection;
|
|
46 |
import javax.swing.BoxLayout;
|
|
47 |
import javax.swing.JPanel;
|
|
48 |
import javax.swing.UIManager;
|
|
49 |
import javax.swing.border.Border;
|
|
50 |
import org.openide.ErrorManager;
|
|
51 |
import org.openide.awt.Toolbar;
|
|
52 |
import org.openide.awt.ToolbarPool;
|
|
53 |
import org.openide.explorer.ExplorerManager;
|
|
54 |
import org.openide.explorer.ExplorerUtils;
|
|
55 |
import org.openide.explorer.view.BeanTreeView;
|
|
56 |
import org.openide.util.Lookup;
|
|
57 |
import org.openide.util.LookupEvent;
|
|
58 |
import org.openide.util.LookupListener;
|
|
59 |
import org.openide.util.NbBundle;
|
|
60 |
import org.openide.util.actions.NodeAction;
|
|
61 |
import org.openide.windows.TopComponent;
|
|
62 |
import org.openide.windows.WindowManager;
|
|
63 |
|
|
64 |
/**
|
|
65 |
*
|
|
66 |
* @author Thomas Wuerthinger
|
|
67 |
*/
|
|
68 |
public final class OutlineTopComponent extends TopComponent implements ExplorerManager.Provider, LookupListener {
|
|
69 |
|
|
70 |
public static OutlineTopComponent instance;
|
|
71 |
public static final String PREFERRED_ID = "OutlineTopComponent";
|
|
72 |
private ExplorerManager manager;
|
|
73 |
private GraphDocument document;
|
|
74 |
private FolderNode root;
|
|
75 |
private GroupOrganizer organizer;
|
|
76 |
|
|
77 |
private OutlineTopComponent() {
|
|
78 |
initComponents();
|
|
79 |
|
|
80 |
setName(NbBundle.getMessage(OutlineTopComponent.class, "CTL_OutlineTopComponent"));
|
|
81 |
setToolTipText(NbBundle.getMessage(OutlineTopComponent.class, "HINT_OutlineTopComponent"));
|
|
82 |
|
|
83 |
document = new GraphDocument();
|
|
84 |
initListView();
|
|
85 |
initToolbar();
|
|
86 |
initReceivers();
|
|
87 |
}
|
|
88 |
|
|
89 |
private void initListView() {
|
|
90 |
manager = new ExplorerManager();
|
|
91 |
organizer = new StandardGroupOrganizer();
|
|
92 |
root = new FolderNode("", organizer, new ArrayList<String>(), document.getGroups());
|
|
93 |
manager.setRootContext(root);
|
|
94 |
((BeanTreeView) this.jScrollPane1).setRootVisible(false);
|
|
95 |
|
|
96 |
document.getChangedEvent().addListener(new ChangedListener<GraphDocument>() {
|
|
97 |
|
|
98 |
public void changed(GraphDocument document) {
|
|
99 |
updateStructure();
|
|
100 |
}
|
|
101 |
});
|
|
102 |
|
|
103 |
associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
|
|
104 |
}
|
|
105 |
|
|
106 |
private void initToolbar() {
|
|
107 |
|
|
108 |
Toolbar toolbar = new Toolbar();
|
|
109 |
Border b = (Border) UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N
|
|
110 |
toolbar.setBorder(b);
|
|
111 |
this.add(toolbar, BorderLayout.NORTH);
|
|
112 |
|
|
113 |
toolbar.add(ImportAction.get(ImportAction.class));
|
|
114 |
toolbar.add(((NodeAction) RemoveAction.get(RemoveAction.class)).createContextAwareInstance(this.getLookup()));
|
|
115 |
toolbar.add(RemoveAllAction.get(RemoveAllAction.class));
|
|
116 |
|
|
117 |
toolbar.add(((NodeAction) SaveAsAction.get(SaveAsAction.class)).createContextAwareInstance(this.getLookup()));
|
|
118 |
toolbar.add(SaveAllAction.get(SaveAllAction.class));
|
|
119 |
|
|
120 |
toolbar.add(StructuredViewAction.get(StructuredViewAction.class).getToolbarPresenter());
|
|
121 |
|
|
122 |
for (Toolbar tb : ToolbarPool.getDefault().getToolbars()) {
|
|
123 |
tb.setVisible(false);
|
|
124 |
}
|
|
125 |
|
|
126 |
initOrganizers();
|
|
127 |
}
|
|
128 |
|
|
129 |
public void setOrganizer(GroupOrganizer organizer) {
|
|
130 |
this.organizer = organizer;
|
|
131 |
updateStructure();
|
|
132 |
}
|
|
133 |
|
|
134 |
private void initOrganizers() {
|
|
135 |
|
|
136 |
}
|
|
137 |
|
|
138 |
private void initReceivers() {
|
|
139 |
|
|
140 |
final GroupCallback callback = new GroupCallback() {
|
|
141 |
|
|
142 |
public void started(Group g) {
|
|
143 |
getDocument().addGroup(g);
|
|
144 |
}
|
|
145 |
};
|
|
146 |
|
|
147 |
Collection<? extends GroupReceiver> receivers = Lookup.getDefault().lookupAll(GroupReceiver.class);
|
|
148 |
if (receivers.size() > 0) {
|
|
149 |
JPanel panel = new JPanel();
|
|
150 |
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
151 |
|
|
152 |
for (GroupReceiver r : receivers) {
|
|
153 |
Component c = r.init(callback);
|
|
154 |
panel.add(c);
|
|
155 |
}
|
|
156 |
|
|
157 |
jPanel2.add(panel, BorderLayout.PAGE_START);
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
private void updateStructure() {
|
|
162 |
root.init("", organizer, new ArrayList<String>(), document.getGroups());
|
|
163 |
}
|
|
164 |
|
|
165 |
public void clear() {
|
|
166 |
document.clear();
|
|
167 |
}
|
|
168 |
|
|
169 |
public ExplorerManager getExplorerManager() {
|
|
170 |
return manager;
|
|
171 |
}
|
|
172 |
|
|
173 |
public GraphDocument getDocument() {
|
|
174 |
return document;
|
|
175 |
}
|
|
176 |
|
|
177 |
/**
|
|
178 |
* Gets default instance. Do not use directly: reserved for *.settings files only,
|
|
179 |
* i.e. deserialization routines; otherwise you could get a non-deserialized instance.
|
|
180 |
* To obtain the singleton instance, use {@link findInstance}.
|
|
181 |
*/
|
|
182 |
public static synchronized OutlineTopComponent getDefault() {
|
|
183 |
if (instance == null) {
|
|
184 |
instance = new OutlineTopComponent();
|
|
185 |
}
|
|
186 |
return instance;
|
|
187 |
}
|
|
188 |
|
|
189 |
/**
|
|
190 |
* Obtain the OutlineTopComponent instance. Never call {@link #getDefault} directly!
|
|
191 |
*/
|
|
192 |
public static synchronized OutlineTopComponent findInstance() {
|
|
193 |
TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
|
|
194 |
if (win == null) {
|
|
195 |
ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find Outline component. It will not be located properly in the window system.");
|
|
196 |
return getDefault();
|
|
197 |
}
|
|
198 |
if (win instanceof OutlineTopComponent) {
|
|
199 |
return (OutlineTopComponent) win;
|
|
200 |
}
|
|
201 |
ErrorManager.getDefault().log(ErrorManager.WARNING, "There seem to be multiple components with the '" + PREFERRED_ID + "' ID. That is a potential source of errors and unexpected behavior.");
|
|
202 |
return getDefault();
|
|
203 |
}
|
|
204 |
|
|
205 |
@Override
|
|
206 |
public int getPersistenceType() {
|
|
207 |
return TopComponent.PERSISTENCE_ALWAYS;
|
|
208 |
}
|
|
209 |
|
|
210 |
@Override
|
|
211 |
public void componentOpened() {
|
|
212 |
this.requestActive();
|
|
213 |
}
|
|
214 |
|
|
215 |
@Override
|
|
216 |
public void componentClosed() {
|
|
217 |
}
|
|
218 |
|
|
219 |
@Override
|
|
220 |
protected String preferredID() {
|
|
221 |
return PREFERRED_ID;
|
|
222 |
}
|
|
223 |
|
|
224 |
public void resultChanged(LookupEvent lookupEvent) {
|
|
225 |
}
|
|
226 |
|
|
227 |
@Override
|
|
228 |
public void readExternal(ObjectInput objectInput) throws IOException, ClassNotFoundException {
|
|
229 |
// Not called when user starts application for the first time
|
|
230 |
super.readExternal(objectInput);
|
|
231 |
((BeanTreeView) this.jScrollPane1).setRootVisible(false);
|
|
232 |
}
|
|
233 |
|
|
234 |
@Override
|
|
235 |
public void writeExternal(ObjectOutput objectOutput) throws IOException {
|
|
236 |
super.writeExternal(objectOutput);
|
|
237 |
}
|
|
238 |
|
|
239 |
static final class ResolvableHelper implements Serializable {
|
|
240 |
|
|
241 |
private static final long serialVersionUID = 1L;
|
|
242 |
|
|
243 |
public Object readResolve() {
|
|
244 |
return OutlineTopComponent.getDefault();
|
|
245 |
}
|
|
246 |
}
|
|
247 |
|
|
248 |
/** This method is called from within the constructor to
|
|
249 |
* initialize the form.
|
|
250 |
* WARNING: Do NOT modify this code. The content of this method is
|
|
251 |
* always regenerated by the Form Editor.
|
|
252 |
*/
|
|
253 |
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
254 |
private void initComponents() {
|
|
255 |
|
|
256 |
jPanel2 = new javax.swing.JPanel();
|
|
257 |
jScrollPane1 = new BeanTreeView();
|
|
258 |
|
|
259 |
setLayout(new java.awt.BorderLayout());
|
|
260 |
|
|
261 |
jPanel2.setLayout(new java.awt.BorderLayout());
|
|
262 |
jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);
|
|
263 |
|
|
264 |
add(jPanel2, java.awt.BorderLayout.CENTER);
|
|
265 |
}// </editor-fold>//GEN-END:initComponents
|
|
266 |
|
|
267 |
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
268 |
private javax.swing.JPanel jPanel2;
|
|
269 |
private javax.swing.JScrollPane jScrollPane1;
|
|
270 |
// End of variables declaration//GEN-END:variables
|
|
271 |
}
|