KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > ui > models > VariablesActionsProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.debugger.jpda.ui.models;
21
22 import javax.swing.Action JavaDoc;
23
24 import org.netbeans.api.debugger.jpda.*;
25 import org.netbeans.spi.debugger.ContextProvider;
26 import org.netbeans.spi.viewmodel.Models;
27 import org.netbeans.spi.viewmodel.NodeActionsProvider;
28 import org.netbeans.spi.viewmodel.TreeModel;
29 import org.netbeans.spi.viewmodel.ModelListener;
30 import org.netbeans.spi.viewmodel.UnknownTypeException;
31
32 import org.netbeans.modules.debugger.jpda.ui.SourcePath;
33
34
35 /**
36  * @author Jan Jancura
37  */

38 public class VariablesActionsProvider implements NodeActionsProvider {
39     
40     
41     private final Action JavaDoc GO_TO_SOURCE_ACTION = Models.createAction (
42         "Go to Source",
43         new Models.ActionPerformer () {
44             public boolean isEnabled (Object JavaDoc node) {
45                 return true;
46             }
47             public void perform (Object JavaDoc[] nodes) {
48                 goToSource ((Field) nodes [0]);
49             }
50         },
51         Models.MULTISELECTION_TYPE_EXACTLY_ONE
52     );
53         
54         
55     private ContextProvider lookupProvider;
56
57     
58     public VariablesActionsProvider (ContextProvider lookupProvider) {
59         this.lookupProvider = lookupProvider;
60     }
61
62     public Action JavaDoc[] getActions (Object JavaDoc node) throws UnknownTypeException {
63         if (node == TreeModel.ROOT)
64             return new Action JavaDoc [0];
65         if (node instanceof Field)
66             return new Action JavaDoc [] {
67                 GO_TO_SOURCE_ACTION
68             };
69         if (node instanceof Variable)
70             return new Action JavaDoc [] {
71             };
72         if (node.toString().startsWith ("SubArray")) // NOI18N
73
return new Action JavaDoc [] {
74             };
75         if (node.equals ("NoInfo")) // NOI18N
76
return new Action JavaDoc [] {
77             };
78         throw new UnknownTypeException (node);
79     }
80     
81     public void performDefaultAction (Object JavaDoc node) throws UnknownTypeException {
82         if (node == TreeModel.ROOT)
83             return;
84         if (node instanceof Field) {
85             goToSource ((Field) node);
86             return;
87         }
88         if (node.toString().startsWith ("SubArray")) // NOI18N
89
return ;
90         if (node.equals ("NoInfo")) // NOI18N
91
return;
92         throw new UnknownTypeException (node);
93     }
94
95     /**
96      *
97      * @param l the listener to add
98      */

99     public void addModelListener (ModelListener l) {
100     }
101
102     /**
103      *
104      * @param l the listener to remove
105      */

106     public void removeModelListener (ModelListener l) {
107     }
108     
109     public void goToSource (Field variable) {
110         SourcePath ectx = (SourcePath) lookupProvider.lookupFirst
111             (null, SourcePath.class);
112         ectx.showSource (variable);
113     }
114
115     private boolean isSourceAvailable (Field v) {
116         SourcePath ectx = (SourcePath) lookupProvider.lookupFirst
117             (null, SourcePath.class);
118         return ectx.sourceAvailable (v);
119     }
120 }
121
Popular Tags