2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.debugger.ui.views;
44
import java.beans.Customizer;
45
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
47
import java.util.ArrayList;
48
import java.util.Iterator;
49
import java.util.List;
50
import javax.swing.JComponent;
52
import org.netbeans.api.debugger.DebuggerEngine;
53
import org.netbeans.api.debugger.DebuggerManager;
54
import org.netbeans.api.debugger.DebuggerManagerAdapter;
55
import org.netbeans.spi.viewmodel.Model;
56
import org.netbeans.spi.viewmodel.Models;
57
import org.netbeans.spi.viewmodel.ColumnModel;
58
import org.netbeans.spi.viewmodel.TableModelFilter;
59
import org.netbeans.spi.viewmodel.NodeActionsProvider;
60
import org.netbeans.spi.viewmodel.NodeActionsProviderFilter;
61
import org.netbeans.spi.viewmodel.NodeModel;
62
import org.netbeans.spi.viewmodel.NodeModelFilter;
63
import org.netbeans.spi.viewmodel.TableModel;
64
import org.netbeans.spi.viewmodel.TreeExpansionModel;
65
import org.netbeans.spi.viewmodel.TreeModel;
66
import org.netbeans.spi.viewmodel.TreeModelFilter;
67
import org.netbeans.spi.viewmodel.ModelListener;
68
import org.netbeans.spi.viewmodel.UnknownTypeException;
69
import org.openide.util.RequestProcessor;
73
* This delegating CompoundModelImpl loads all models from DebuggerManager.
74
* getDefault ().getCurrentEngine ().lookup (viewType, ..) lookup.
77
* This class is identical to org.netbeans.modules.debugger.jpda.ui.views.ViewModelListener.
81
public class ViewModelListener extends DebuggerManagerAdapter {
83
private String viewType;
84
private JComponent view;
85
private List models = new ArrayList(11);
87
private List treeModels;
88
private List treeModelFilters;
89
private List treeExpansionModels;
90
private List nodeModels;
91
private List nodeModelFilters;
92
private List tableModels;
93
private List tableModelFilters;
94
private List nodeActionsProviders;
95
private List nodeActionsProviderFilters;
96
private List columnModels;
100
// Store the propertiesHelpID to pass to the Model object that is
101
// used in generating the nodes for the view
102
private String propertiesHelpID = null;
107
String propertiesHelpID
109
this.viewType = viewType;
111
this.propertiesHelpID = propertiesHelpID;
120
this.viewType = viewType;
126
DebuggerManager.getDebuggerManager ().addDebuggerListener (
127
DebuggerManager.PROP_CURRENT_ENGINE,
133
synchronized void destroy () {
134
DebuggerManager.getDebuggerManager ().removeDebuggerListener (
135
DebuggerManager.PROP_CURRENT_ENGINE,
140
treeModelFilters = null;
141
treeExpansionModels = null;
143
nodeModelFilters = null;
145
tableModelFilters = null;
146
nodeActionsProviders = null;
147
nodeActionsProviderFilters = null;
150
Models.setModelsToView (
156
public void propertyChange (PropertyChangeEvent e) {
160
private List joinLookups(DebuggerEngine e, DebuggerManager dm, Class service) {
161
List es = e.lookup (viewType, service);
162
List ms = dm.lookup(viewType, service);
168
private synchronized void updateModel () {
169
DebuggerManager dm = DebuggerManager.getDebuggerManager ();
170
DebuggerEngine e = dm.getCurrentEngine ();
173
treeModels = joinLookups(e, dm, TreeModel.class);
174
treeModelFilters = joinLookups(e, dm, TreeModelFilter.class);
175
treeExpansionModels = joinLookups(e, dm, TreeExpansionModel.class);
176
nodeModels = joinLookups(e, dm, NodeModel.class);
177
nodeModelFilters = joinLookups(e, dm, NodeModelFilter.class);
178
tableModels = joinLookups(e, dm, TableModel.class);
179
tableModelFilters = joinLookups(e, dm, TableModelFilter.class);
180
nodeActionsProviders = joinLookups(e, dm, NodeActionsProvider.class);
181
nodeActionsProviderFilters = joinLookups(e, dm, NodeActionsProviderFilter.class);
182
columnModels = joinLookups(e, dm, ColumnModel.class);
183
mm = joinLookups(e, dm, Model.class);
185
treeModels = dm.lookup (viewType, TreeModel.class);
186
treeModelFilters = dm.lookup (viewType, TreeModelFilter.class);
187
treeExpansionModels = dm.lookup (viewType, TreeExpansionModel.class);
188
nodeModels = dm.lookup (viewType, NodeModel.class);
189
nodeModelFilters = dm.lookup (viewType, NodeModelFilter.class);
190
tableModels = dm.lookup (viewType, TableModel.class);
191
tableModelFilters = dm.lookup (viewType, TableModelFilter.class);
192
nodeActionsProviders = dm.lookup (viewType, NodeActionsProvider.class);
193
nodeActionsProviderFilters = dm.lookup (viewType, NodeActionsProviderFilter.class);
194
columnModels = dm.lookup (viewType, ColumnModel.class);
195
mm = dm.lookup (viewType, Model.class);
198
ModelsChangeRefresher mcr = new ModelsChangeRefresher();
199
Customizer[] modelListCustomizers = new Customizer[] {
200
(Customizer) treeModels,
201
(Customizer) treeModelFilters,
202
(Customizer) treeExpansionModels,
203
(Customizer) nodeModels,
204
(Customizer) nodeModelFilters,
205
(Customizer) tableModels,
206
(Customizer) tableModelFilters,
207
(Customizer) nodeActionsProviders,
208
(Customizer) nodeActionsProviderFilters,
209
(Customizer) columnModels,
212
for (int i = 0; i < modelListCustomizers.length; i++) {
213
Customizer c = modelListCustomizers[i];
214
if (c != null) { // Can be null when debugger is finishing
215
c.addPropertyChangeListener(mcr);
216
c.setObject("load first"); // NOI18N
217
c.setObject("unload last"); // NOI18N
224
private synchronized void refreshModel() {
226
synchronized (treeModels) {
227
models.add(new ArrayList(treeModels));
229
synchronized (treeModelFilters) {
230
models.add(new ArrayList(treeModelFilters));
232
synchronized (treeExpansionModels) {
233
models.add(new ArrayList(treeExpansionModels));
235
synchronized (nodeModels) {
236
models.add(new ArrayList(nodeModels));
238
synchronized (nodeModelFilters) {
239
models.add(new ArrayList(nodeModelFilters));
241
synchronized (tableModels) {
242
models.add(new ArrayList(tableModels));
244
synchronized (tableModelFilters) {
245
models.add(new ArrayList(tableModelFilters));
247
synchronized (nodeActionsProviders) {
248
models.add(new ArrayList(nodeActionsProviders));
250
synchronized (nodeActionsProviderFilters) {
251
models.add(new ArrayList(nodeActionsProviderFilters));
253
synchronized (columnModels) {
254
models.add(new ArrayList(columnModels));
257
models.add(new ArrayList(mm));
261
// Store the propertiesHelpID in the tree model to be retrieved later
262
// by the TreeModelNode objects
263
// Models.setModelsToView (
265
// Models.createCompoundModel (models)
268
Models.CompoundModel newModel = Models.createCompoundModel (models, propertiesHelpID);
270
Models.setModelsToView (
278
// innerclasses ............................................................
280
private static class EmptyModel implements NodeModel {
281
public EmptyModel () {
284
public String getDisplayName (Object node) throws UnknownTypeException {
285
if (node == TreeModel.ROOT) {
286
return "Name"; // TODO: Localized ???
288
throw new UnknownTypeException (node);
291
public String getIconBase (Object node) throws UnknownTypeException {
292
if (node == TreeModel.ROOT) {
293
return "org/netbeans/modules/debugger/resources/DebuggerTab";
295
throw new UnknownTypeException (node);
298
public String getShortDescription (Object node)
299
throws UnknownTypeException {
300
throw new UnknownTypeException (node);
303
public void addModelListener (ModelListener l) {}
304
public void removeModelListener (ModelListener l) {}
307
private class ModelsChangeRefresher implements PropertyChangeListener, Runnable {
309
private RequestProcessor.Task task;
311
public synchronized void propertyChange(PropertyChangeEvent evt) {
313
task = new RequestProcessor(ModelsChangeRefresher.class.getName(), 1).create(this);