KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > ui > models > SessionsActionsProvider


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.ui.models;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import javax.swing.AbstractAction JavaDoc;
24 import javax.swing.Action JavaDoc;
25
26 import org.netbeans.api.debugger.DebuggerManager;
27 import org.netbeans.api.debugger.Session;
28 import org.netbeans.spi.viewmodel.Models;
29 import org.netbeans.spi.viewmodel.TreeModel;
30 import org.netbeans.spi.viewmodel.NodeActionsProvider;
31 import org.netbeans.spi.viewmodel.ModelListener;
32 import org.netbeans.spi.viewmodel.UnknownTypeException;
33 import org.openide.util.NbBundle;
34
35
36 /**
37  * @author Jan Jancura
38  */

39 public class SessionsActionsProvider implements NodeActionsProvider {
40     
41     private static final Action JavaDoc FINISH_ALL_ACTION = new AbstractAction JavaDoc
42         (NbBundle.getBundle(SessionsActionsProvider.class).getString("CTL_SessionAction_FinishAll_Label")) {
43             public void actionPerformed (ActionEvent JavaDoc e) {
44                 Session[] ss = DebuggerManager.getDebuggerManager ().
45                     getSessions ();
46                 int i, k = ss.length;
47                 for (i = 0; i < k; i++)
48                     ss [i].kill ();
49             }
50     };
51     private Action JavaDoc MAKE_CURRENT_ACTION = Models.createAction (
52         NbBundle.getBundle(SessionsActionsProvider.class).getString("CTL_SessionAction_MakeCurrent_Label"), new Models.ActionPerformer () {
53             public boolean isEnabled (Object JavaDoc node) {
54                 return DebuggerManager.getDebuggerManager ().
55                     getCurrentSession () != node;
56             }
57             
58             public void perform (Object JavaDoc[] nodes) {
59                 DebuggerManager.getDebuggerManager ().setCurrentSession (
60                     (Session) nodes [0]
61                 );
62             }
63         },
64         Models.MULTISELECTION_TYPE_EXACTLY_ONE
65     );
66     private static final Action JavaDoc FINISH_ACTION = Models.createAction (
67         NbBundle.getBundle(SessionsActionsProvider.class).getString("CTL_SessionAction_Finish_Label"),
68         new Models.ActionPerformer () {
69             public boolean isEnabled (Object JavaDoc node) {
70                 return true;
71             }
72             public void perform (Object JavaDoc[] nodes) {
73                 int i, k = nodes.length;
74                 for (i = 0; i < k; i++)
75                     ((Session) nodes [i]).kill ();
76             }
77         },
78         Models.MULTISELECTION_TYPE_ANY
79     );
80     
81     public Action JavaDoc[] getActions (Object JavaDoc node) throws UnknownTypeException {
82         if (node == TreeModel.ROOT)
83             return new Action JavaDoc [] {
84                 FINISH_ALL_ACTION
85             };
86         if (node instanceof Session)
87             return new Action JavaDoc [] {
88                 MAKE_CURRENT_ACTION,
89                 FINISH_ACTION,
90                 null,
91                 FINISH_ALL_ACTION
92             };
93         throw new UnknownTypeException (node);
94     }
95     
96     public void performDefaultAction (Object JavaDoc node) throws UnknownTypeException {
97         if (node == TreeModel.ROOT)
98             return;
99         if (node instanceof Session) {
100             if (DebuggerManager.getDebuggerManager ().getCurrentSession () ==
101                 node
102             ) return;
103             DebuggerManager.getDebuggerManager ().setCurrentSession (
104                 (Session) node
105             );
106             return;
107         }
108         throw new UnknownTypeException (node);
109     }
110
111     public void addModelListener (ModelListener l) {
112     }
113
114     public void removeModelListener (ModelListener l) {
115     }
116 }
117
Popular Tags