KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ui > logicalview > ejb > entity > EntityNode


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
21 package org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.entity;
22 import javax.swing.Action JavaDoc;
23 import org.netbeans.api.java.classpath.ClassPath;
24 import org.netbeans.modules.j2ee.api.ejbjar.EjbReference;
25 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.AddActionGroup;
26 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.GenerateDTOAction;
27 import org.openide.cookies.OpenCookie;
28 import org.openide.loaders.DataObject;
29 import org.openide.util.HelpCtx;
30 import org.openide.util.actions.SystemAction;
31 import java.awt.datatransfer.Transferable JavaDoc;
32 import java.beans.PropertyChangeEvent JavaDoc;
33 import java.beans.PropertyChangeListener JavaDoc;
34 import java.io.IOException JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.Collection JavaDoc;
37 import java.util.List JavaDoc;
38 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
39 import org.netbeans.modules.j2ee.dd.api.ejb.Entity;
40 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.shared.EjbTransferable;
41 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.shared.EjbViewController;
42 import org.openide.util.WeakListeners;
43 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.DeleteEJBDialog;
44 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.GoToSourceActionGroup;
45 import org.openide.actions.DeleteAction;
46 import org.openide.actions.OpenAction;
47 import org.openide.filesystems.FileObject;
48 import org.openide.nodes.AbstractNode;
49 import org.openide.nodes.Node;
50 import org.openide.util.Lookup;
51 import org.openide.util.Utilities;
52 import org.openide.util.lookup.AbstractLookup;
53 import org.openide.util.lookup.InstanceContent;
54
55
56 /**
57  * @author Chris Webster
58  * @author Ludovic Champenois
59  * @author Martin Adamek
60  */

61 public class EntityNode extends AbstractNode implements OpenCookie{
62     
63     private final PropertyChangeListener JavaDoc nameChangeListener;
64     private final EjbViewController controller;
65     
66     public EntityNode(Entity model, EjbJar module, ClassPath srcPath, FileObject ddFile) {
67         this(new InstanceContent(), model, module, srcPath, ddFile);
68     }
69
70     private EntityNode(InstanceContent content, Entity model, EjbJar module, ClassPath srcPath, FileObject ddFile) {
71         super(new EntityChildren(model, srcPath, module, ddFile), new AbstractLookup(content));
72         setIconBaseWithExtension("org/netbeans/modules/j2ee/ejbcore/ui/logicalview/ejb/entity/EntityNodeIcon.gif");
73         setName(model.getEjbName()+"");
74         controller = new EjbViewController(model, module, srcPath);
75         setDisplayName();
76         nameChangeListener = new PropertyChangeListener JavaDoc() {
77             public void propertyChange(PropertyChangeEvent JavaDoc pce) {
78                 setDisplayName();
79             }
80         };
81         model.addPropertyChangeListener(
82             WeakListeners.propertyChange(nameChangeListener,model));
83         content.add(this);
84         content.add(controller.getBeanClass());
85         if (controller.getBeanDo() != null) {
86             content.add(controller.getBeanDo());
87         }
88         EjbReference ejbReference = controller.createEjbReference();
89         if (ejbReference != null) {
90             content.add(controller.createEjbReference());
91         }
92     }
93     
94     private void setDisplayName() {
95         setDisplayName(controller.getDisplayName());
96     }
97     
98     // Create the popup menu:
99
public Action JavaDoc[] getActions(boolean context) {
100         Collection JavaDoc<? extends Node> nodes = Utilities.actionsGlobalContext().lookup(new Lookup.Template<Node>(Node.class)).allInstances();
101         List JavaDoc<SystemAction> list = new ArrayList JavaDoc<SystemAction>();
102         list.add(SystemAction.get(OpenAction.class));
103         list.add(null);
104         list.add(SystemAction.get(DeleteAction.class));
105         if (nodes.size() == 1) {
106             list.add(SystemAction.get(AddActionGroup.class));
107             list.add(null);
108             list.add(SystemAction.get(GoToSourceActionGroup.class));
109             list.add(SystemAction.get(GenerateDTOAction.class));
110         }
111         return list.toArray(new SystemAction[0]);
112     }
113     
114     public HelpCtx getHelpCtx() {
115         return HelpCtx.DEFAULT_HELP;
116         // TODO
117
// return new HelpCtx(EntityNode.class);
118
}
119     
120     public boolean canDestroy() {
121         return true;
122     }
123     
124     public void destroy() throws java.io.IOException JavaDoc {
125         String JavaDoc deleteOptions = DeleteEJBDialog.open(controller.getDisplayName());
126         if (!deleteOptions.equals(DeleteEJBDialog.DELETE_NOTHING)) {
127             if (deleteOptions.equals(DeleteEJBDialog.DELETE_ONLY_DD)) {
128                 controller.delete(false);
129             } else {
130                 controller.delete(true);
131             }
132         }
133     }
134     
135     public boolean canCopy() {
136         return true;
137     }
138     
139     public boolean canCut() {
140         return true;
141     }
142     
143     public Transferable JavaDoc clipboardCopy() throws IOException JavaDoc {
144         EjbReference ejbRef = controller.createEjbReference();
145         StringBuilder JavaDoc ejbRefString = new StringBuilder JavaDoc("");
146         if (ejbRef.supportsRemoteInvocation()) {
147             ejbRefString.append(controller.getRemoteStringRepresentation("Entity"));
148         }
149         if (ejbRef.supportsLocalInvocation()) {
150             ejbRefString.append(controller.getLocalStringRepresentation("Entity"));
151         }
152         return new EjbTransferable(ejbRefString.toString(), ejbRef);
153     }
154     
155     public Transferable JavaDoc clipboardCut() throws IOException JavaDoc {
156         return clipboardCopy();
157     }
158     
159     public void open() {
160         DataObject dataObject = controller.getBeanDo();
161         if (dataObject != null) {
162             OpenCookie cookie = dataObject.getCookie(OpenCookie.class);
163             if(cookie != null){
164                 cookie.open();
165             }
166         }
167     }
168     
169     public Action JavaDoc getPreferredAction() {
170         return SystemAction.get(OpenAction.class);
171     }
172
173     /**
174      * Adds possibility to display custom delete dialog
175      */

176     public Object JavaDoc getValue(String JavaDoc attributeName) {
177         Object JavaDoc retValue;
178         if ("customDelete".equals(attributeName)) {
179             retValue = Boolean.TRUE;
180         } else {
181             retValue = super.getValue(attributeName);
182         }
183         return retValue;
184     }
185
186 }
187
Popular Tags