# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: C:\work\sun\visualweb\cvsworkspaces\visualweb\apisupport\project # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: src/org/netbeans/modules/apisupport/project/layers/Bundle.properties *** C:\work\sun\visualweb\cvsworkspaces\visualweb\apisupport\project\src\org\netbeans\modules\apisupport\project\layers\Bundle.properties Base (1.5) --- C:\work\sun\visualweb\cvsworkspaces\visualweb\apisupport\project\src\org\netbeans\modules\apisupport\project\layers\Bundle.properties Locally Modified (Based On 1.5) *************** *** 38,40 **** --- 38,43 ---- # PickIconAction LBL_pick_icon=Pick Icon... + + # OpenLayerFilesAction + LBL_open_layer_files_action=Open layer files Index: src/org/netbeans/modules/apisupport/project/layers/LayerNode.java *** C:\work\sun\visualweb\cvsworkspaces\visualweb\apisupport\project\src\org\netbeans\modules\apisupport\project\layers\LayerNode.java Base (1.21) --- C:\work\sun\visualweb\cvsworkspaces\visualweb\apisupport\project\src\org\netbeans\modules\apisupport\project\layers\LayerNode.java Locally Modified (Based On 1.21) *************** *** 245,250 **** --- 245,251 ---- return new SystemAction[] { SystemAction.get(PickNameAction.class), SystemAction.get(PickIconAction.class), + SystemAction.get(OpenLayerFilesAction.class), }; } } Index: src/org/netbeans/modules/apisupport/project/layers/OpenLayerFilesAction.java *** C:\work\sun\visualweb\cvsworkspaces\visualweb\apisupport\project\src\org\netbeans\modules\apisupport\project\layers\OpenLayerFilesAction.java No Base Revision --- C:\work\sun\visualweb\cvsworkspaces\visualweb\apisupport\project\src\org\netbeans\modules\apisupport\project\layers\OpenLayerFilesAction.java Locally New *************** *** 1,0 **** --- 1,168 ---- + /* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ + + package org.netbeans.modules.apisupport.project.layers; + + import java.awt.Toolkit; + import java.lang.reflect.InvocationTargetException; + import java.lang.reflect.Method; + import java.net.URL; + import org.openide.cookies.EditCookie; + import org.openide.filesystems.FileObject; + import org.openide.filesystems.FileStateInvalidException; + import org.openide.filesystems.FileSystem; + import org.openide.filesystems.MultiFileSystem; + import org.openide.filesystems.MultiFileSystem; + import org.openide.filesystems.URLMapper; + import org.openide.filesystems.XMLFileSystem; + import org.openide.loaders.DataObject; + import org.openide.loaders.DataObjectNotFoundException; + import org.openide.nodes.Node; + import org.openide.util.Exceptions; + import org.openide.util.HelpCtx; + import org.openide.util.NbBundle; + import org.openide.util.actions.CookieAction; + import org.xml.sax.SAXException; + + /** + * Open the layer file(s) declaring the SFS node. + * + * @author Sandip Chitale + */ + public class OpenLayerFilesAction extends CookieAction { + + // HACK Tunnel through the MultiFileSystem to get to the delegates + private static Method getDelegatesMethod; + static { + try { + getDelegatesMethod = MultiFileSystem.class.getDeclaredMethod("getDelegates"); + getDelegatesMethod.setAccessible(true); + } catch (NoSuchMethodException ex) { + Exceptions.printStackTrace(ex); + } catch (SecurityException ex) { + Exceptions.printStackTrace(ex); + } + } + + protected void performAction(Node[] activatedNodes) { + if (getDelegatesMethod == null) { + Toolkit.getDefaultToolkit().beep(); + return; + } + try { + FileObject f = ((DataObject) activatedNodes[0].getCookie(DataObject.class)).getPrimaryFile(); + FileSystem fs = f.getFileSystem(); + while (fs instanceof MultiFileSystem) { + try { + FileSystem[] delegates = (FileSystem[]) getDelegatesMethod.invoke(fs); + if (delegates != null && delegates.length > 0) { + fs = delegates[0]; + if (fs instanceof MultiFileSystem) { + // keep going + continue; + } else if (fs instanceof WritableXMLFileSystem) { + // try current module project's layer file. + FileObject originalF = fs.findResource(f.getPath()); + if (originalF != null) { + URL url = (URL) f.getAttribute("WritableXMLFileSystem.location"); // NOI18N + FileObject layerFileObject = URLMapper.findFileObject(url); + if (layerFileObject != null) { + try { + DataObject layerDataObject = DataObject.find(layerFileObject); + EditCookie editCookie = layerDataObject.getCookie(EditCookie.class); + if (editCookie != null) { + editCookie.edit(); + } + } catch (DataObjectNotFoundException ex) { + Exceptions.printStackTrace(ex); + } + } + } + // Now, try other layer files visible to the module project + for (int i = 1; i < delegates.length; i++) { + XMLFileSystem xMLFileSystem = (XMLFileSystem) delegates[i]; + + // Have to use deprecated API to get all the Xml URLs + URL[] urls = xMLFileSystem.getXmlUrls(); + for (URL url : urls) { + try { + // Build an XML FS for the given URL + XMLFileSystem aXMLFileSystem = new XMLFileSystem(url); + + // Find the resource usiung the file path + originalF = aXMLFileSystem.findResource(f.getPath()); + + // Found? + if (originalF != null) { + // locate the layer's file object and open it + FileObject layerFileObject = URLMapper.findFileObject(url); + if (layerFileObject != null) { + try { + DataObject layerDataObject = DataObject.find(layerFileObject); + EditCookie editCookie = layerDataObject.getCookie(EditCookie.class); + if (editCookie != null) { + editCookie.edit(); + } + } catch (DataObjectNotFoundException ex) { + Exceptions.printStackTrace(ex); + } + } + } + }catch (SAXException ex) { + Exceptions.printStackTrace(ex); + } + } + } + } + } + }catch (IllegalAccessException ex) { + Exceptions.printStackTrace(ex); + } catch (IllegalArgumentException ex) { + Exceptions.printStackTrace(ex); + } catch (InvocationTargetException ex) { + Exceptions.printStackTrace(ex); + } + } + } catch (FileStateInvalidException ex) { + Exceptions.printStackTrace(ex); + } + } + + public String getName() { + return NbBundle.getMessage(OpenLayerFilesAction.class, "LBL_open_layer_files_action"); + } + + protected Class[] cookieClasses() { + return new Class[] {DataObject.class}; + } + + protected int mode() { + return MODE_EXACTLY_ONE; + } + + public HelpCtx getHelpCtx() { + return null; + } + + @Override + protected boolean asynchronous() { + return false; + } + + }