1 19 20 package org.netbeans.modules.editor.options; 21 22 import org.openide.loaders.FolderInstance; 23 import org.openide.cookies.InstanceCookie; 24 import org.openide.loaders.DataFolder; 25 import org.openide.loaders.DataObject; 26 import org.openide.filesystems.FileObject; 27 import org.netbeans.editor.AnnotationType; 28 import java.util.LinkedList ; 29 import javax.swing.Action ; 30 import org.openide.filesystems.Repository; 31 32 37 public class AnnotationTypeActionsFolder extends FolderInstance{ 38 39 40 private static final String FOLDER = "Editors/AnnotationTypes/"; 42 private AnnotationType type; 43 44 45 private AnnotationTypeActionsFolder(AnnotationType type, DataFolder fld) { 46 super(fld); 47 this.type = type; 48 recreate(); 49 instanceFinished(); 50 } 51 52 53 public static boolean readActions(AnnotationType type, String subFolder) { 54 55 FileObject f = Repository.getDefault().getDefaultFileSystem().findResource(FOLDER + subFolder); 56 if (f == null) { 57 return false; 58 } 59 60 try { 61 DataObject d = DataObject.find(f); 62 DataFolder df = (DataFolder)d.getCookie(DataFolder.class); 63 if (df != null) { 64 AnnotationTypeActionsFolder folder; 65 folder = new AnnotationTypeActionsFolder(type, df); 66 return true; 67 } 68 } catch (org.openide.loaders.DataObjectNotFoundException ex) { 69 org.openide.ErrorManager.getDefault().notify(org.openide.ErrorManager.INFORMATIONAL, ex); 70 return false; 71 } 72 return false; 73 } 74 75 76 protected Object createInstance(InstanceCookie[] cookies) throws java.io.IOException , ClassNotFoundException { 77 LinkedList annotationActions = new LinkedList (); 78 79 for (int i = 0; i < cookies.length; i++) { 80 Object o = cookies[i].instanceCreate(); 81 if (o instanceof Action ) { 82 Action action = (Action )o; 83 annotationActions.add(action); 84 } 85 } 86 87 type.setActions((Action [])annotationActions.toArray(new Action [0])); 89 90 return null; 91 } 92 93 } 94 | Popular Tags |