KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > options > AnnotationTypeActionsFolder


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.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 JavaDoc;
29 import javax.swing.Action JavaDoc;
30 import org.openide.filesystems.Repository;
31
32 /** Processing of folders with annotation types actions.
33  *
34  * @author David Konecny
35  * @since 08/2001
36  */

37 public class AnnotationTypeActionsFolder extends FolderInstance{
38     
39     /** root folder for annotation type actions subfolders */
40     private static final String JavaDoc FOLDER = "Editors/AnnotationTypes/"; // NOI18N
41

42     private AnnotationType type;
43     
44     /** Creates new AnnotationTypesFolder */
45     private AnnotationTypeActionsFolder(AnnotationType type, DataFolder fld) {
46         super(fld);
47         this.type = type;
48         recreate();
49         instanceFinished();
50     }
51
52     /** Factory method for AnnotationTypeActionsFolder instance. */
53     public static boolean readActions(AnnotationType type, String JavaDoc 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     /** Called for each XML file found in FOLDER directory */
76     protected Object JavaDoc createInstance(InstanceCookie[] cookies) throws java.io.IOException JavaDoc, ClassNotFoundException JavaDoc {
77         LinkedList JavaDoc annotationActions = new LinkedList JavaDoc();
78
79         for (int i = 0; i < cookies.length; i++) {
80             Object JavaDoc o = cookies[i].instanceCreate();
81             if (o instanceof Action JavaDoc) {
82                 Action JavaDoc action = (Action JavaDoc)o;
83                 annotationActions.add(action);
84             }
85         }
86         
87         // set all these types to AnnotationType static member
88
type.setActions((Action JavaDoc[])annotationActions.toArray(new Action JavaDoc[0]));
89
90         return null;
91     }
92
93 }
94
Popular Tags