KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > mimelookup > impl > PopupActions


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
21 package org.netbeans.modules.editor.mimelookup.impl;
22
23 import java.io.IOException JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26 import javax.swing.Action JavaDoc;
27 import javax.swing.JSeparator JavaDoc;
28 import org.netbeans.spi.editor.mimelookup.InstanceProvider;
29 import org.openide.cookies.InstanceCookie;
30 import org.openide.filesystems.FileObject;
31 import org.openide.loaders.DataObject;
32 import org.openide.loaders.DataObjectNotFoundException;
33 import org.openide.util.actions.SystemAction;
34
35 /**
36  *
37  * @author Martin Roskanin
38  */

39 public class PopupActions implements InstanceProvider{
40
41     List JavaDoc ordered;
42
43     public PopupActions(){
44     }
45
46     public PopupActions(List JavaDoc ordered){
47         this.ordered = ordered;
48     }
49
50     public List JavaDoc getPopupActions(){
51         List JavaDoc retList = new ArrayList JavaDoc();
52         for (int i = 0; i<ordered.size(); i++){
53             FileObject fo = (FileObject) ordered.get(i);
54             DataObject dob;
55             
56             try {
57                 dob = DataObject.find(fo);
58             } catch (DataObjectNotFoundException dnfe) {
59                 // ignore
60
continue;
61             }
62             
63             InstanceCookie ic = (InstanceCookie)dob.getCookie(InstanceCookie.class);
64             if (ic!=null){
65                 try{
66                     if (String JavaDoc.class.isAssignableFrom(ic.instanceClass()) ||
67                         Action JavaDoc.class.isAssignableFrom(ic.instanceClass()) ||
68                         SystemAction.class.isAssignableFrom(ic.instanceClass()) ||
69                         JSeparator JavaDoc.class.isAssignableFrom(ic.instanceClass())){
70                         Object JavaDoc instance = ic.instanceCreate();
71                         retList.add(instance);
72                     }
73                 }catch(IOException JavaDoc ioe){
74                     ioe.printStackTrace();
75                 }catch(ClassNotFoundException JavaDoc cnfe){
76                     cnfe.printStackTrace();
77                 }
78             } else{
79                 retList.add(dob.getName());
80             }
81         }
82         return retList;
83     }
84
85     public Object JavaDoc createInstance(List JavaDoc ordered) {
86         return new PopupActions(ordered);
87     }
88 }
89
Popular Tags