KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > jaxws > nodes > JaxWsRootNode


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.websvc.core.jaxws.nodes;
21
22 import java.awt.Image JavaDoc;
23 import java.beans.BeanInfo JavaDoc;
24 import java.beans.PropertyChangeEvent JavaDoc;
25 import java.beans.PropertyChangeListener JavaDoc;
26 import java.util.Map JavaDoc;
27 import javax.swing.Action JavaDoc;
28 import javax.swing.Icon JavaDoc;
29 import javax.swing.ImageIcon JavaDoc;
30 import org.netbeans.api.project.FileOwnerQuery;
31 import org.netbeans.api.project.Project;
32 import org.netbeans.modules.j2ee.common.Util;
33 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
34 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
35 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
36 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
37 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
38 import org.netbeans.spi.project.ui.support.CommonProjectActions;
39 import org.openide.DialogDisplayer;
40 import org.openide.NotifyDescriptor;
41 import org.openide.actions.FindAction;
42 import org.openide.actions.PasteAction;
43 import org.openide.actions.ToolsAction;
44 import org.openide.filesystems.FileObject;
45 import org.openide.filesystems.Repository;
46 import org.openide.loaders.DataFolder;
47 import org.openide.nodes.AbstractNode;
48 import org.openide.nodes.Node;
49 import org.openide.util.HelpCtx;
50 import org.openide.util.Lookup;
51 import org.openide.util.NbBundle;
52 import org.openide.util.Utilities;
53 import org.openide.util.WeakListeners;
54 import org.openide.util.actions.SystemAction;
55 import org.openide.util.lookup.Lookups;
56
57 public class JaxWsRootNode extends AbstractNode implements PropertyChangeListener JavaDoc{
58     private PropertyEvaluator evaluator;
59     private Project project;
60     private boolean jsr109Supported;
61     private static final Image JavaDoc WEB_SERVICES_BADGE = Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/webservicegroup.png", true ); // NOI18N
62
static Icon JavaDoc folderIconCache;
63     static Icon JavaDoc openedFolderIconCache;
64     
65     public JaxWsRootNode(Project project, JaxWsModel jaxWsModel, FileObject[] srcRoots) {
66         super(new JaxWsRootChildren(jaxWsModel,srcRoots));
67         setDisplayName(NbBundle.getBundle(JaxWsRootNode.class).getString("LBL_WebServices"));
68         this.project=project;
69         if(!Util.isJavaEE5orHigher(project)){
70             listenToServerChanges();
71             jsr109Supported = isJsr109Supported();
72         }
73     }
74     
75     public Image JavaDoc getIcon( int type ) {
76         return computeIcon( false, type );
77     }
78     
79     public Image JavaDoc getOpenedIcon( int type ) {
80         return computeIcon( true, type );
81     }
82     
83     /**
84      * Returns Icon of folder on active platform
85      * @param opened should the icon represent opened folder
86      * @return the folder icon
87      */

88     static synchronized Icon JavaDoc getFolderIcon (boolean opened) {
89         if (openedFolderIconCache == null) {
90             Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate();
91             openedFolderIconCache = new ImageIcon JavaDoc(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
92             folderIconCache = new ImageIcon JavaDoc(n.getIcon(BeanInfo.ICON_COLOR_16x16));
93         }
94         if (opened) {
95             return openedFolderIconCache;
96         }
97         else {
98             return folderIconCache;
99         }
100     }
101
102     private Image JavaDoc computeIcon( boolean opened, int type ) {
103         Icon JavaDoc icon = getFolderIcon(opened);
104         Image JavaDoc image = ((ImageIcon JavaDoc)icon).getImage();
105         image = Utilities.mergeImages(image, WEB_SERVICES_BADGE, 7, 7 );
106         return image;
107     }
108
109     public Action JavaDoc[] getActions(boolean context) {
110         return new Action JavaDoc[]{
111             CommonProjectActions.newFileAction(),
112             null,
113             SystemAction.get(FindAction.class),
114             null,
115             SystemAction.get(PasteAction.class),
116             null,
117             SystemAction.get(ToolsAction.class)
118         };
119     }
120     
121     public HelpCtx getHelpCtx() {
122         return HelpCtx.DEFAULT_HELP;
123     }
124     
125     private static Lookup createLookup(final FileObject srcRoot) {
126         Project owner = FileOwnerQuery.getOwner(srcRoot);
127         return (owner != null) ? Lookups.fixed(new Object JavaDoc[]{ owner }) : null;
128     }
129     
130     private void listenToServerChanges(){
131         JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory());
132         if (wss != null) {
133             evaluator = wss.getAntProjectHelper().getStandardPropertyEvaluator();
134             PropertyChangeListener JavaDoc pcl = WeakListeners.propertyChange(this, evaluator);
135             evaluator.addPropertyChangeListener(pcl);
136         }
137     }
138     
139     private boolean isJsr109Supported() {
140         JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory());
141         if (wss != null) {
142             return isJsr109Supported(wss);
143         }
144         return false;
145     }
146     
147     private boolean isJsr109Supported(JAXWSSupport wss) {
148         Map JavaDoc properties = wss.getAntProjectHelper().getStandardPropertyEvaluator().getProperties();
149         String JavaDoc serverInstance = (String JavaDoc)properties.get("j2ee.server.instance"); //NOI18N
150
if (serverInstance != null) {
151             J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstance);
152             if (j2eePlatform != null) {
153                 return j2eePlatform.isToolSupported(J2eePlatform.TOOL_JSR109);
154             }
155         }
156         return false;
157     }
158     
159     
160     public void propertyChange(PropertyChangeEvent JavaDoc evt){
161         JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory());
162         if (wss!=null && wss.getServices().size()>0) {
163             if ("j2ee.server.instance".equals(evt.getPropertyName())){
164                 boolean newJsr109Supported = isJsr109Supported(wss);
165                 if(jsr109Supported != newJsr109Supported) {
166                     JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class);
167                     boolean isJsr109Project = jaxWsModel.getJsr109().booleanValue();
168                     if(isJsr109Project != newJsr109Supported){
169                         String JavaDoc msg = NbBundle.getMessage(JaxWsRootNode.class, "MSG_IncompatibleWSServer"); //NOI18N
170
DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE));
171                     }
172                     jsr109Supported = newJsr109Supported;
173                 }
174             }
175         }
176     }
177 }
178
Popular Tags