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-2006 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: package org.netbeans.modules.websvc.jaxrpc.nodes;
043:
044: import java.awt.Image;
045: import java.beans.BeanInfo;
046: import javax.swing.Action;
047: import javax.swing.Icon;
048: import javax.swing.ImageIcon;
049: import org.openide.filesystems.Repository;
050:
051: import org.openide.nodes.CookieSet;
052: import org.openide.nodes.Children;
053: import org.openide.nodes.Node;
054: import org.openide.nodes.AbstractNode;
055: import org.openide.filesystems.FileObject;
056: import org.openide.loaders.DataFolder;
057: import org.openide.loaders.DataObjectNotFoundException;
058: import org.openide.util.Lookup;
059: import org.openide.util.NbBundle;
060: import org.openide.util.Utilities;
061: import org.openide.util.lookup.Lookups;
062: import org.openide.util.actions.SystemAction;
063: import org.openide.util.actions.NodeAction;
064:
065: /** This is the root node for the graph of web services for which this module
066: * has been client-enabled (e.g. services this module is using.)
067: *
068: * @author Peter Williams
069: */
070: public final class ClientRootNode extends AbstractNode {
071:
072: private static final Image WEB_SERVICES_BADGE = Utilities
073: .loadImage("org/netbeans/modules/websvc/jaxrpc/nodes/resources/webserviceclientgroup.png"); // NOI18N
074: private static Icon folderIconCache;
075: private static Icon openedFolderIconCache;
076: private FileObject wsdlFolder;
077:
078: public ClientRootNode(FileObject wsdlFolder)
079: throws DataObjectNotFoundException {
080: super ((wsdlFolder != null) ? new ClientViewChildren(wsdlFolder)
081: : Children.LEAF, createLookup(wsdlFolder));
082: this .wsdlFolder = wsdlFolder;
083: initialize();
084: }
085:
086: private void initialize() {
087: // !PW add cookies to registered lookup -- see createLookup() below
088: setName("WebServiceReferences"); // NOI18N
089: setDisplayName(NbBundle.getBundle(ClientRootNode.class)
090: .getString("LBL_WebServiceReferences"));
091: }
092:
093: public Image getIcon(int type) {
094: return computeIcon(false, type);
095: }
096:
097: public Image getOpenedIcon(int type) {
098: return computeIcon(true, type);
099: }
100:
101: public Action[] getActions(boolean context) {
102: return new Action[] {
103: org.netbeans.spi.project.ui.support.CommonProjectActions
104: .newFileAction(),
105: null,
106: // org.openide.util.actions.SystemAction.get( org.netbeans.modules.websvc.jaxrpc.actions.RefreshClientsAction.class ),
107: org.openide.util.actions.SystemAction
108: .get(org.openide.actions.FindAction.class),
109: null,
110: org.openide.util.actions.SystemAction
111: .get(org.openide.actions.PasteAction.class),
112: null,
113: org.openide.util.actions.SystemAction
114: .get(org.openide.actions.ToolsAction.class) };
115: }
116:
117: /**
118: * Returns Icon of folder on active platform
119: * @param opened should the icon represent opened folder
120: * @return the folder icon
121: */
122: static synchronized Icon getFolderIcon(boolean opened) {
123: if (openedFolderIconCache == null) {
124: Node n = DataFolder.findFolder(
125: Repository.getDefault().getDefaultFileSystem()
126: .getRoot()).getNodeDelegate();
127: openedFolderIconCache = new ImageIcon(n
128: .getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
129: folderIconCache = new ImageIcon(n
130: .getIcon(BeanInfo.ICON_COLOR_16x16));
131: }
132: if (opened) {
133: return openedFolderIconCache;
134: } else {
135: return folderIconCache;
136: }
137: }
138:
139: private Image computeIcon(boolean opened, int type) {
140: Icon icon = getFolderIcon(opened);
141: Image image = ((ImageIcon) icon).getImage();
142: image = Utilities.mergeImages(image, WEB_SERVICES_BADGE, 7, 7);
143: return image;
144: }
145:
146: private static Lookup createLookup(FileObject wsdlFolder) {
147: // !PW FIXME -- from source -- Remove DataFolder when paste, find and refresh are reimplemented
148: // !PW FIXME implement pathing and add PathFinder to lookup.
149: if (wsdlFolder != null) {
150: DataFolder dataFolder = DataFolder.findFolder(wsdlFolder);
151: return Lookups
152: .fixed(new Object[] { dataFolder /*, new PathFinder( group ) */});
153: } else {
154: return Lookups
155: .fixed(new Object[] { /* new PathFinder( group ) */});
156: }
157: }
158: }
|