KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ui > logicalview > ejb > mdb > MessageNode


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.mdb;
22
23 import javax.swing.Action JavaDoc;
24 import org.netbeans.api.java.classpath.ClassPath;
25 import org.openide.actions.*;
26 import org.openide.loaders.DataObject;
27 import org.openide.nodes.*;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.actions.SystemAction;
30 import java.beans.PropertyChangeEvent JavaDoc;
31 import java.beans.PropertyChangeListener JavaDoc;
32
33 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
34 import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven;
35 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.DeleteEJBDialog;
36 import org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.shared.EjbViewController;
37 import org.openide.cookies.OpenCookie;
38 import org.openide.util.WeakListeners;
39 import org.openide.util.lookup.AbstractLookup;
40 import org.openide.util.lookup.InstanceContent;
41
42 /**
43  * @author Chris Webster
44  * @author Ludovic Champenois
45  * @author Martin Adamek
46  */

47 public class MessageNode extends AbstractNode implements OpenCookie {
48     
49     private final PropertyChangeListener JavaDoc nameChangeListener;
50     private final EjbViewController controller;
51     
52     public MessageNode(MessageDriven model, EjbJar module, ClassPath srcPath) {
53         this(new InstanceContent(), model, module, srcPath);
54     }
55     
56     private MessageNode(InstanceContent content, MessageDriven model, EjbJar module, ClassPath srcPath) {
57         super(Children.LEAF, new AbstractLookup(content));
58         setIconBaseWithExtension("org/netbeans/modules/j2ee/ejbcore/ui/logicalview/ejb/mdb/MessageNodeIcon.gif");
59         setName(model.getEjbName()+"");
60         controller = new EjbViewController(model, module, srcPath);
61         setDisplayName();
62         nameChangeListener = new PropertyChangeListener JavaDoc() {
63             public void propertyChange(PropertyChangeEvent JavaDoc pce) {
64                 setDisplayName();
65             }
66         };
67         model.addPropertyChangeListener(
68             WeakListeners.propertyChange(nameChangeListener,model));
69         content.add(this);
70         content.add(controller.getBeanClass());
71         if (controller.getBeanDo() != null) {
72             content.add(controller.getBeanDo());
73         }
74     }
75     
76     private void setDisplayName() {
77         setDisplayName(controller.getDisplayName());
78     }
79     
80     public Action JavaDoc[] getActions(boolean context) {
81         return new SystemAction[] {
82             SystemAction.get(OpenAction.class),
83             null,
84             SystemAction.get(DeleteAction.class)
85         };
86     }
87     
88     public HelpCtx getHelpCtx() {
89         return HelpCtx.DEFAULT_HELP;
90         // TODO
91
// return new HelpCtx(SessionNode.class);
92
}
93     
94     public boolean canDestroy() {
95         return true;
96     }
97     
98     public void destroy() throws java.io.IOException JavaDoc {
99         String JavaDoc deleteOptions = DeleteEJBDialog.open(controller.getDisplayName());
100         if (!deleteOptions.equals(DeleteEJBDialog.DELETE_NOTHING)) {
101             if (deleteOptions.equals(DeleteEJBDialog.DELETE_ONLY_DD)) {
102                 controller.delete(false);
103             } else {
104                 controller.delete(true);
105             }
106         }
107     }
108     
109     public boolean canCopy() {
110         return false;
111     }
112     
113     public boolean canCut() {
114         return false;
115     }
116     
117     public void open() {
118         DataObject dataObject = controller.getBeanDo();
119         if (dataObject != null) {
120             OpenCookie cookie = (OpenCookie) dataObject.getCookie(OpenCookie.class);
121             if(cookie != null){
122                 cookie.open();
123             }
124         }
125     }
126
127     public Action JavaDoc getPreferredAction() {
128         return SystemAction.get(OpenAction.class);
129     }
130
131     /**
132      * Adds possibility to display custom delete dialog
133      */

134     public Object JavaDoc getValue(String JavaDoc attributeName) {
135         Object JavaDoc retValue;
136         if (attributeName.equals("customDelete")) {
137             retValue = Boolean.TRUE;
138         } else {
139             retValue = super.getValue(attributeName);
140         }
141         return retValue;
142     }
143
144 }
145
Popular Tags