KickJava   Java API By Example, From Geeks To Geeks.

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


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.entity;
21
22 import java.awt.Image JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import org.openide.nodes.AbstractNode;
26 import org.openide.nodes.Children;
27 import javax.swing.Action JavaDoc;
28 import org.openide.actions.DeleteAction;
29 import org.openide.actions.OpenAction;
30 import org.openide.cookies.OpenCookie;
31 import org.openide.util.Utilities;
32 import org.openide.util.actions.SystemAction;
33 import org.openide.util.WeakListeners;
34 import java.io.IOException JavaDoc;
35 import org.netbeans.modules.j2ee.dd.api.ejb.CmrField;
36 import org.netbeans.modules.j2ee.ejbcore.api.methodcontroller.EntityMethodController;
37 import org.openide.filesystems.FileObject;
38
39
40 public class CMRFieldNode extends AbstractNode implements PropertyChangeListener JavaDoc, OpenCookie {
41     
42     private static final String JavaDoc CMR_FIELD_ICON = "org/netbeans/modules/j2ee/ejbcore/resources/CMRFieldIcon.gif"; //NOI18N
43

44     private final CmrField field;
45     private final EntityMethodController controller;
46     private final FileObject ddFile;
47     
48     public CMRFieldNode(CmrField field, EntityMethodController controller, FileObject ddFile) {
49         super(Children.LEAF);
50         this.field = field;
51         this.ddFile = ddFile;
52         this.controller = controller;
53         field.addPropertyChangeListener(WeakListeners.propertyChange(this, field));
54     }
55     
56     public String JavaDoc getDisplayName(){
57         return field.getCmrFieldName();
58     }
59     
60     public Image JavaDoc getIcon(int type) {
61         return Utilities.loadImage(CMR_FIELD_ICON);
62     }
63     
64     public boolean canDestroy(){
65         return true;
66     }
67     
68     public void destroy() throws IOException JavaDoc{
69         controller.deleteField(field, ddFile);
70         super.destroy();
71     }
72     
73     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
74         fireDisplayNameChange(null,null);
75     }
76     
77     public OpenCookie getCookie(Class JavaDoc<OpenCookie> type) {
78         if(OpenCookie.class.equals(type)) {
79             return this;
80         }
81         return super.getCookie(type);
82     }
83     
84     public Action JavaDoc[] getActions(boolean context) {
85         return new SystemAction[] {
86             SystemAction.get(OpenAction.class),
87                     null,
88                     SystemAction.get(DeleteAction.class),
89         };
90     }
91     
92     public Action JavaDoc getPreferredAction() {
93         return SystemAction.get(OpenAction.class);
94     }
95     
96     //implementation of OpenCookie
97
public void open() {
98         //TODO: RETOUCHE
99
// List methods = controller.getMethods(field);
100
// if (!methods.isEmpty()) {
101
// Method getMethod = (Method) methods.get(0);
102
// OpenCookie cookie = (OpenCookie) JMIUtils.getCookie(getMethod, OpenCookie.class);
103
// if(cookie != null){
104
// cookie.open();
105
// }
106
// }
107
}
108 }
Popular Tags