1 19 20 package org.netbeans.modules.languages.dataobject; 21 22 import org.openide.ErrorManager; 23 import org.openide.cookies.InstanceCookie; 24 import org.openide.filesystems.FileObject; 25 import org.openide.filesystems.Repository; 26 import org.openide.loaders.DataFolder; 27 import org.openide.loaders.DataNode; 28 import org.openide.loaders.DataObject; 29 import org.openide.nodes.Children; 30 31 import javax.swing.*; 32 import java.io.IOException ; 33 import java.util.ArrayList ; 34 import java.util.HashMap ; 35 import java.util.List ; 36 import java.util.Map ; 37 38 39 public class LanguagesDataNode extends DataNode { 40 41 public LanguagesDataNode(LanguagesDataObject obj) { 42 super(obj, Children.LEAF); 43 String mimeType = obj.getPrimaryFile ().getMIMEType (); 44 FileObject fo = Repository.getDefault ().getDefaultFileSystem (). 45 findResource ("Editors/" + mimeType + "/language.nbs"); 46 String icon = (String ) fo.getAttribute ("icon"); 47 if (icon == null) 48 icon = "org/netbeans/modules/languages/resources/defaultIcon.jpg"; 49 setIconBaseWithExtension (icon); 50 } 51 52 64 private Map <String ,Action[]> mimeTypeToActions = new HashMap <String ,Action[]> (); 65 66 70 public Action[] getActions (boolean context) { 71 String mimeType = getDataObject ().getPrimaryFile ().getMIMEType (); 72 if (!mimeTypeToActions.containsKey (mimeType)) { 73 List <Action> actions = new ArrayList <Action> (); 74 try { 75 FileObject fo = Repository.getDefault ().getDefaultFileSystem (). 76 findResource ("Loaders/" + mimeType + "/Actions"); 77 if (fo != null) { 78 DataFolder df = DataFolder.findFolder (fo); 79 DataObject[] dob = df.getChildren (); 80 int i, k = dob.length; 81 for (i = 0; i < k; i++) { 82 InstanceCookie ic = (InstanceCookie) dob [i].getCookie 83 (InstanceCookie.class); 84 Class clazz = ic.instanceClass (); 85 if (JSeparator.class.isAssignableFrom (clazz)) 86 actions.add (null); 87 else 88 actions.add ((Action) ic.instanceCreate ()); 89 } 90 } 91 } catch (ClassNotFoundException ex) { 92 ErrorManager.getDefault ().notify (ex); 93 } catch (IOException ex) { 94 ErrorManager.getDefault ().notify (ex); 95 } 96 if (!actions.isEmpty ()) 97 mimeTypeToActions.put (mimeType, actions.toArray (new Action [actions.size ()])); 98 else 99 mimeTypeToActions.put (mimeType, super.getActions (context)); 100 } 101 return (Action[]) mimeTypeToActions.get (mimeType); 102 } 103 } 104 105 106 107 108 | Popular Tags |