001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: /*
042: * SessionBeanNode.java
043: *
044: * Created on May 3, 2004, 6:20 PM
045: */
046:
047: package org.netbeans.modules.visualweb.ejb.nodes;
048:
049: import java.awt.Image;
050: import java.awt.datatransfer.DataFlavor;
051: import java.awt.datatransfer.Transferable;
052: import java.io.IOException;
053: import java.util.logging.Level;
054:
055: import javax.swing.Action;
056:
057: import org.netbeans.modules.visualweb.ejb.datamodel.EjbGroup;
058: import org.netbeans.modules.visualweb.ejb.datamodel.EjbInfo;
059: import org.netbeans.modules.visualweb.ejb.util.Util;
060: import org.openide.ErrorManager;
061: import org.openide.actions.PropertiesAction;
062: import org.openide.nodes.AbstractNode;
063: import org.openide.nodes.Node;
064: import org.openide.nodes.PropertySupport;
065: import org.openide.nodes.Sheet;
066: import org.openide.nodes.Sheet.Set;
067: import org.openide.util.HelpCtx;
068: import org.openide.util.NbBundle;
069: import org.openide.util.Utilities;
070: import org.openide.util.actions.SystemAction;
071: import org.openide.util.datatransfer.ExTransferable;
072:
073: import com.sun.rave.designtime.DisplayItem;
074: import com.sun.rave.designtime.impl.BasicBeanCreateInfo;
075:
076: /**
077: * This node is to represent one session bean
078: *
079: * @author cao
080: */
081: public class SessionBeanNode extends AbstractNode implements
082: Node.Cookie {
083: private EjbGroup ejbGroup;
084:
085: private EjbInfo ejbInfo;
086:
087: // private SessionBeanPaletteItem beanPaletteItem;
088:
089: /** Creates a new instance of SessionBeanNode */
090: public SessionBeanNode(EjbGroup ejbGroup, EjbInfo ejbInfo) {
091: super (new SessionBeanNodeChildren(ejbGroup, ejbInfo));
092:
093: this .ejbGroup = ejbGroup;
094: this .ejbInfo = ejbInfo;
095:
096: // Set FeatureDescriptor stuff:
097: setName(ejbInfo.getJNDIName());
098: setDisplayName(ejbInfo.getJNDIName());
099: setShortDescription(ejbInfo.getCompInterfaceName());
100: }
101:
102: public Image getIcon(int type) {
103: return Utilities
104: .loadImage("org/netbeans/modules/visualweb/ejb/resources/session_bean.png");
105: }
106:
107: public Image getOpenedIcon(int type) {
108: return Utilities
109: .loadImage("org/netbeans/modules/visualweb/ejb/resources/session_bean.png");
110: }
111:
112: // Create the popup menu for the session bean node
113: public Action[] getActions(boolean context) {
114: // todo I don't know what actions to popup from this node yet
115: return new Action[] { SystemAction.get(PropertiesAction.class) };
116: }
117:
118: public HelpCtx getHelpCtx() {
119: return new HelpCtx("projrave_ui_elements_server_nav_ejb_node");
120: }
121:
122: protected SessionBeanNodeChildren getSessionBeanNodeChildren() {
123: return (SessionBeanNodeChildren) getChildren();
124: }
125:
126: public EjbInfo getEjbInfo() {
127: return this .ejbInfo;
128: }
129:
130: // Properties sheet
131: protected Sheet createSheet() {
132: Sheet sheet = super .createSheet();
133: Set ss = sheet.get("ejbInfo"); // NOI18N
134:
135: if (ss == null) {
136: ss = new Set();
137: ss.setName("ejbInfo"); // NOI18N
138: ss.setDisplayName(NbBundle.getMessage(
139: SessionBeanNode.class, "SESSION_BEAN_INFORMATION"));
140: ss.setShortDescription(NbBundle.getMessage(
141: SessionBeanNode.class, "SESSION_BEAN_INFORMATION"));
142: sheet.put(ss);
143: }
144:
145: // EJB type - stateful or stateless
146: ss.put(new PropertySupport.ReadOnly("beanType", // NOI18N
147: String.class, NbBundle.getMessage(EjbGroupNode.class,
148: "EJB_TYPE"), NbBundle.getMessage(
149: EjbGroupNode.class, "EJB_TYPE")) {
150: public Object getValue() {
151: switch (ejbInfo.getBeanType()) {
152: case EjbInfo.STATEFUL_SESSION_BEAN:
153: return NbBundle.getMessage(EjbGroupNode.class,
154: "STATEFUL_EJB");
155: case EjbInfo.STATELESS_SESSION_BEAN:
156: return NbBundle.getMessage(EjbGroupNode.class,
157: "STATELESS_EJB");
158: default:
159: return NbBundle.getMessage(EjbGroupNode.class,
160: "STATELESS_EJB");
161: }
162: }
163: });
164:
165: // JNDI name
166: ss.put(new PropertySupport.ReadOnly("jndiName", // NOI18N
167: String.class, NbBundle.getMessage(EjbGroupNode.class,
168: "JNDI_NAME"), NbBundle.getMessage(
169: EjbGroupNode.class, "JNDI_NAME")) {
170: public Object getValue() {
171: return ejbInfo.getJNDIName();
172: }
173: });
174:
175: // ejb-ref-name
176: ss.put(new PropertySupport.ReadOnly("webEjbRef", // NOI18N
177: String.class, NbBundle.getMessage(EjbGroupNode.class,
178: "WEB_EJB_REF_NAME"), NbBundle.getMessage(
179: EjbGroupNode.class, "WEB_EJB_REF_NAME")) {
180: public Object getValue() {
181: return ejbInfo.getWebEjbRef();
182: }
183: });
184:
185: // Home interface
186: ss.put(new PropertySupport.ReadOnly("homeInterface", // NOI18N
187: String.class, NbBundle.getMessage(EjbGroupNode.class,
188: "HOME_INTERFACE"), NbBundle.getMessage(
189: EjbGroupNode.class, "HOME_INTERFACE")) {
190: public Object getValue() {
191: return ejbInfo.getHomeInterfaceName();
192: }
193: });
194:
195: // Remote interface
196: ss.put(new PropertySupport.ReadOnly("remoteInterface", // NOI18N
197: String.class, NbBundle.getMessage(EjbGroupNode.class,
198: "REMOTE_INTERFACE"), NbBundle.getMessage(
199: EjbGroupNode.class, "REMOTE_INTERFACE")) {
200: public Object getValue() {
201: return ejbInfo.getCompInterfaceName();
202: }
203: });
204:
205: return sheet;
206: }
207:
208: // Methods for Drag and Drop (not used for copy / paste at this point)
209:
210: public boolean canCopy() {
211: return true;
212: }
213:
214: public boolean canCut() {
215: return false;
216: }
217:
218: public Transferable clipboardCopy() {
219:
220: // // If the bean palette item is not initialized, lets create one
221: // if( beanPaletteItem == null ) {
222: // beanPaletteItem = new SessionBeanPaletteItem( ejbGroup, ejbInfo );
223: // }
224: if (ejbGroup == null || ejbInfo == null) {
225: try {
226: return super .clipboardCopy();
227: } catch (IOException ex) {
228: ErrorManager.getDefault().notify(
229: ErrorManager.INFORMATIONAL, ex);
230: }
231: }
232:
233: // Add to, do not replace, the default node copy flavor:
234: try {
235: ExTransferable transferable = ExTransferable.create(super
236: .clipboardCopy());
237: // Now create the transferable
238: transferable.put(
239: // new
240: // ExTransferable.Single(PaletteItemTransferable.FLAVOR_PALETTE_ITEM)
241: // {
242: new ExTransferable.Single(FLAVOR_EJB_DISPLAY_ITEM) {
243: protected Object getData() {
244: // return new SessionBeanPaletteItem( ejbGroup,
245: // ejbInfo );
246: // return beanPaletteItem;
247: return new EjbBeanCreateInfo(ejbGroup,
248: ejbInfo);
249: }
250: });
251: return transferable;
252: } catch (Exception ioe) {
253: Util.getLogger().log(Level.SEVERE,
254: "SessionBeanNode.clipboardCopy: Error", ioe);
255: return null;
256: }
257: }
258:
259: private static final DataFlavor FLAVOR_EJB_DISPLAY_ITEM = new DataFlavor(
260: DataFlavor.javaJVMLocalObjectMimeType + "; class="
261: + DisplayItem.class.getName(), // NOI18N
262: "Ejb Display Item"); // XXX Localize
263:
264: private static class EjbBeanCreateInfo extends BasicBeanCreateInfo {
265:
266: private final EjbGroup ejbGroup;
267:
268: private final EjbInfo ejbInfo;
269:
270: public EjbBeanCreateInfo(EjbGroup ejbGroup, EjbInfo ejbInfo) {
271: this .ejbGroup = ejbGroup;
272: this .ejbInfo = ejbInfo;
273: }
274:
275: public String getBeanClassName() {
276: // XXX This hack causes the jars to be added to the project if the
277: // EJB node is even dragged onto the designer
278: // without dropping
279: try {
280: EjbLibReferenceHelper
281: .addEjbGroupToActiveProject(ejbGroup);
282: } catch (Exception e) {
283: Util.getLogger().log(Level.SEVERE,
284: "Unable to add EJB Set to Project", e);
285: }
286: return ejbInfo.getBeanWrapperName();
287: }
288:
289: public String getDisplayName() {
290: return ejbInfo.getCompInterfaceName();
291: }
292:
293: } // End of EjbBeanCreateInfo
294: }
|