1 19 20 package org.netbeans.modules.websvc.core.jaxws.nodes; 21 22 import java.awt.Image ; 23 import java.beans.BeanInfo ; 24 import java.beans.PropertyChangeEvent ; 25 import java.beans.PropertyChangeListener ; 26 import java.util.Map ; 27 import javax.swing.Action ; 28 import javax.swing.Icon ; 29 import javax.swing.ImageIcon ; 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 { 58 private PropertyEvaluator evaluator; 59 private Project project; 60 private boolean jsr109Supported; 61 private static final Image WEB_SERVICES_BADGE = Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/webservicegroup.png", true ); static Icon folderIconCache; 63 static Icon 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 getIcon( int type ) { 76 return computeIcon( false, type ); 77 } 78 79 public Image getOpenedIcon( int type ) { 80 return computeIcon( true, type ); 81 } 82 83 88 static synchronized Icon getFolderIcon (boolean opened) { 89 if (openedFolderIconCache == null) { 90 Node n = DataFolder.findFolder(Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate(); 91 openedFolderIconCache = new ImageIcon (n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16)); 92 folderIconCache = new ImageIcon (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 computeIcon( boolean opened, int type ) { 103 Icon icon = getFolderIcon(opened); 104 Image image = ((ImageIcon )icon).getImage(); 105 image = Utilities.mergeImages(image, WEB_SERVICES_BADGE, 7, 7 ); 106 return image; 107 } 108 109 public Action [] getActions(boolean context) { 110 return new Action []{ 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 []{ 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 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 properties = wss.getAntProjectHelper().getStandardPropertyEvaluator().getProperties(); 149 String serverInstance = (String )properties.get("j2ee.server.instance"); 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 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 msg = NbBundle.getMessage(JaxWsRootNode.class, "MSG_IncompatibleWSServer"); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE)); 171 } 172 jsr109Supported = newJsr109Supported; 173 } 174 } 175 } 176 } 177 } 178 | Popular Tags |