KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ui > logicalview > ejb > shared > MethodsNode


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.j2ee.ejbcore.ui.logicalview.ejb.shared;
21
22 import javax.swing.Action JavaDoc;
23 import org.netbeans.api.java.classpath.ClassPath;
24 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
25 import org.netbeans.modules.j2ee.dd.api.ejb.EntityAndSession;
26 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.AddActionGroup;
27 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.GoToSourceAction;
28 import org.openide.cookies.OpenCookie;
29 import org.openide.loaders.DataObject;
30 import org.openide.nodes.AbstractNode;
31 import org.openide.nodes.Children;
32 import org.openide.util.NbBundle;
33 import org.openide.util.actions.SystemAction;
34 import org.openide.util.lookup.AbstractLookup;
35 import org.openide.util.lookup.InstanceContent;
36
37 /**
38  * Represents Local/Remote Methods node under Session and Entity nodes
39  * in EJB logical view
40  *
41  * @author Martin Adamek
42  */

43 public class MethodsNode extends AbstractNode implements OpenCookie {
44     
45     private final EjbViewController controller;
46     private EntityAndSession model;
47     private ClassPath srcPath;
48     private boolean local;
49
50     public MethodsNode(EntityAndSession model, EjbJar module, ClassPath srcPath, Children children, boolean local) {
51         this(new InstanceContent(), model, module, srcPath, children, local);
52     }
53     
54     private MethodsNode(InstanceContent content, EntityAndSession model, EjbJar module, ClassPath srcPath, Children children, boolean local) {
55         super(children, new AbstractLookup(content));
56         controller = new EjbViewController(model, module, srcPath);
57         this.model = model;
58         this.srcPath = srcPath;
59         this.local = local;
60         content.add(this);
61         if (controller.getBeanDo() != null) {
62             content.add(controller.getBeanDo());
63         }
64     }
65     
66     public Action JavaDoc[] getActions(boolean context) {
67         return new Action JavaDoc[] {
68                 new GoToSourceAction(srcPath, local ? model.getLocal() : model.getRemote(),
69                         NbBundle.getMessage(MethodsNode.class, "LBL_GoToSourceGroup")),
70             SystemAction.get(AddActionGroup.class),
71         };
72     }
73
74     public Action JavaDoc getPreferredAction() {
75         return new GoToSourceAction(srcPath, local ? model.getLocal() : model.getRemote(),
76                         NbBundle.getMessage(MethodsNode.class, "LBL_GoToSourceGroup"));
77     }
78
79     public void open() {
80         DataObject dataObject = controller.getBeanDo();
81         if (dataObject != null) {
82             OpenCookie cookie = (OpenCookie) dataObject.getCookie(OpenCookie.class);
83             if(cookie != null){
84                 cookie.open();
85             }
86         }
87     }
88     
89     public boolean isLocal() {
90     return local;
91     }
92 }
93
Popular Tags