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.core.jaxws.nodes;
043:
044: import java.awt.Image;
045: import java.beans.BeanInfo;
046: import java.beans.PropertyChangeEvent;
047: import java.beans.PropertyChangeListener;
048: import java.util.Map;
049: import javax.swing.Action;
050: import javax.swing.Icon;
051: import javax.swing.ImageIcon;
052: import org.netbeans.api.project.Project;
053: import org.netbeans.modules.j2ee.common.Util;
054: import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
055: import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
056: import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
057: import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
058: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
059: import org.netbeans.spi.project.ui.support.CommonProjectActions;
060: import org.openide.DialogDisplayer;
061: import org.openide.NotifyDescriptor;
062: import org.openide.actions.FindAction;
063: import org.openide.actions.PasteAction;
064: import org.openide.actions.PropertiesAction;
065: import org.openide.filesystems.FileObject;
066: import org.openide.filesystems.Repository;
067: import org.openide.loaders.DataFolder;
068: import org.openide.nodes.AbstractNode;
069: import org.openide.nodes.Node;
070: import org.openide.util.HelpCtx;
071: import org.openide.util.NbBundle;
072: import org.openide.util.Utilities;
073: import org.openide.util.WeakListeners;
074: import org.openide.util.actions.SystemAction;
075: import org.openide.util.lookup.Lookups;
076:
077: public class JaxWsRootNode extends AbstractNode implements
078: PropertyChangeListener {
079: private PropertyEvaluator evaluator;
080: private Project project;
081: private boolean jsr109Supported;
082: private static final String SERVICES_BADGE = "org/netbeans/modules/websvc/core/webservices/ui/resources/webservicegroup.png"; // NOI18N
083: private Icon folderIconCache;
084: private Icon openedFolderIconCache;
085: private java.awt.Image cachedServicesBadge;
086:
087: public JaxWsRootNode(Project project, JaxWsModel jaxWsModel,
088: FileObject[] srcRoots) {
089: super (new JaxWsRootChildren(jaxWsModel, srcRoots), Lookups
090: .fixed(project));
091: setDisplayName(NbBundle.getBundle(JaxWsRootNode.class)
092: .getString("LBL_WebServices"));
093: this .project = project;
094: if (!Util.isJavaEE5orHigher(project)) {
095: listenToServerChanges();
096: jsr109Supported = isJsr109Supported();
097: }
098: }
099:
100: @Override
101: public Image getIcon(int type) {
102: return computeIcon(false);
103: }
104:
105: @Override
106: public Image getOpenedIcon(int type) {
107: return computeIcon(true);
108: }
109:
110: private java.awt.Image getServicesImage() {
111: if (cachedServicesBadge == null) {
112: cachedServicesBadge = Utilities.loadImage(SERVICES_BADGE);
113: }
114: return cachedServicesBadge;
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: private 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) {
140: Icon icon = getFolderIcon(opened);
141: Image image = ((ImageIcon) icon).getImage();
142: image = Utilities.mergeImages(image, getServicesImage(), 7, 7);
143: return image;
144: }
145:
146: @Override
147: public Action[] getActions(boolean context) {
148: return new Action[] { CommonProjectActions.newFileAction(),
149: null, SystemAction.get(FindAction.class), null,
150: SystemAction.get(PasteAction.class), null,
151: SystemAction.get(PropertiesAction.class) };
152: }
153:
154: @Override
155: public HelpCtx getHelpCtx() {
156: return HelpCtx.DEFAULT_HELP;
157: }
158:
159: private void listenToServerChanges() {
160: JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project
161: .getProjectDirectory());
162: if (wss != null) {
163: evaluator = wss.getAntProjectHelper()
164: .getStandardPropertyEvaluator();
165: PropertyChangeListener pcl = WeakListeners.propertyChange(
166: this , evaluator);
167: evaluator.addPropertyChangeListener(pcl);
168: }
169: }
170:
171: private boolean isJsr109Supported() {
172: JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project
173: .getProjectDirectory());
174: if (wss != null) {
175: return isJsr109Supported(wss);
176: }
177: return false;
178: }
179:
180: private boolean isJsr109Supported(JAXWSSupport wss) {
181: Map properties = wss.getAntProjectHelper()
182: .getStandardPropertyEvaluator().getProperties();
183: String serverInstance = (String) properties
184: .get("j2ee.server.instance"); //NOI18N
185: if (serverInstance != null) {
186: J2eePlatform j2eePlatform = Deployment.getDefault()
187: .getJ2eePlatform(serverInstance);
188: if (j2eePlatform != null) {
189: return j2eePlatform
190: .isToolSupported(J2eePlatform.TOOL_JSR109);
191: }
192: }
193: return false;
194: }
195:
196: public void propertyChange(PropertyChangeEvent evt) {
197: JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project
198: .getProjectDirectory());
199: if (wss != null && wss.getServices().size() > 0) {
200: if ("j2ee.server.instance".equals(evt.getPropertyName())) {
201: boolean newJsr109Supported = isJsr109Supported(wss);
202: if (jsr109Supported != newJsr109Supported) {
203: JaxWsModel jaxWsModel = (JaxWsModel) project
204: .getLookup().lookup(JaxWsModel.class);
205: boolean isJsr109Project = jaxWsModel.getJsr109()
206: .booleanValue();
207: if (isJsr109Project != newJsr109Supported) {
208: String msg = NbBundle.getMessage(
209: JaxWsRootNode.class,
210: "MSG_IncompatibleWSServer"); //NOI18N
211: DialogDisplayer
212: .getDefault()
213: .notify(
214: new NotifyDescriptor.Message(
215: msg,
216: NotifyDescriptor.INFORMATION_MESSAGE));
217: }
218: jsr109Supported = newJsr109Supported;
219: }
220: }
221: }
222: }
223:
224: // the following templates should be available on this node
225: /*
226: private static class WSRecommendedTemplates implements RecommendedTemplates, PrivilegedTemplates {
227: private static final String[] TYPES = new String[] {
228: "web-services", // NOI18N
229: };
230: private static final String[] WS_TEMPLATES = new String[] {
231: "Templates/WebServices/WebService.java", // NOI18N
232: "Templates/WebServices/WebServiceFromWSDL.java", // NOI18N
233: };
234:
235: public String[] getRecommendedTypes() {
236: return TYPES;
237: }
238:
239: public String[] getPrivilegedTemplates() {
240: return WS_TEMPLATES;
241: }
242: }
243: */
244: }
|